示例#1
0
static bool
string_mt(const struct sk_buff *skb, struct xt_action_param *par)
{
	const struct xt_string_info *conf = par->matchinfo;
	struct ts_state state;
	bool invert;

	invert = conf->u.v1.flags & XT_STRING_FLAG_INVERT;

	return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
			     conf->to_offset, conf->config, &state)
			     != UINT_MAX) ^ invert;
}
示例#2
0
static bool
wildstring_mt(const struct sk_buff *skb, const struct xt_match_param *par)
{
	const struct xt_wildstring_info *conf = par->matchinfo;
	struct ts_state state;
	int invert;
	unsigned int skb_find = 0;

	memset(&state, 0, sizeof(struct ts_state));

	invert = (par->match->revision == 0 ? conf->u.v0.invert :
		  conf->u.v1.flags & XT_WILDSTRING_FLAG_INVERT);

	/* Eye burns, but this is example, so i willn't rewrite to list usage */
	skb_find = skb_find_text((struct sk_buff *)skb, conf->from_offset,
				 conf->to_offset, conf->config_part1, &state);
	if (skb_find == UINT_MAX)
		return false;

	if (!conf->pattern_part2)
		return true;

	memset(&state, 0, sizeof(struct ts_state));
	skb_find = skb_find_text((struct sk_buff *)skb, skb_find,
				 conf->to_offset, conf->config_part2, &state);
	if (skb_find == UINT_MAX)
		return false;

	if (!conf->pattern_part3)
		return true;

	memset(&state, 0, sizeof(struct ts_state));
	skb_find = skb_find_text((struct sk_buff *)skb, skb_find,
				 conf->to_offset, conf->config_part3, &state);
	if (skb_find == UINT_MAX)
		return false;

	return true;
}
示例#3
0
文件: xt_string.c 项目: 274914765/C
static bool
string_mt(const struct sk_buff *skb, const struct net_device *in,
          const struct net_device *out, const struct xt_match *match,
          const void *matchinfo, int offset, unsigned int protoff,
          bool *hotdrop)
{
    const struct xt_string_info *conf = matchinfo;
    struct ts_state state;

    memset(&state, 0, sizeof(struct ts_state));

    return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
                 conf->to_offset, conf->config, &state)
                 != UINT_MAX) ^ conf->invert;
}
示例#4
0
文件: em_text.c 项目: 274914765/C
static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
                         struct tcf_pkt_info *info)
{
    struct text_match *tm = EM_TEXT_PRIV(m);
    int from, to;
    struct ts_state state;

    from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
    from += tm->from_offset;

    to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
    to += tm->to_offset;

    return skb_find_text(skb, from, to, tm->config, &state) != UINT_MAX;
}
示例#5
0
文件: xt_string.c 项目: Arakmar/G3MOD
static bool
string_mt(const struct sk_buff *skb, const struct xt_action_param *par)
{
	const struct xt_string_info *conf = par->matchinfo;
	struct ts_state state;
	int invert;

	memset(&state, 0, sizeof(struct ts_state));

	invert = (par->match->revision == 0 ? conf->u.v0.invert :
				    conf->u.v1.flags & XT_STRING_FLAG_INVERT);

	return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
			     conf->to_offset, conf->config, &state)
			     != UINT_MAX) ^ invert;
}
示例#6
0
static int help(struct sk_buff **pskb,
                struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
{
	struct ts_state ts;
	struct ip_conntrack_expect *exp;
	unsigned int dataoff, start, stop, off, i;
	char pbuf[sizeof("65535")], *tmp;
	u_int16_t port, len;
	int ret = NF_ACCEPT;

	/* Only look at packets from the Amanda server */
	if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
		return NF_ACCEPT;

	/* increase the UDP timeout of the master connection as replies from
	 * Amanda clients to the server can be quite delayed */
	ip_ct_refresh(ct, *pskb, master_timeout * HZ);

	/* No data? */
	dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
	if (dataoff >= (*pskb)->len) {
		if (net_ratelimit())
			printk("amanda_help: skblen = %u\n", (*pskb)->len);
		return NF_ACCEPT;
	}

	memset(&ts, 0, sizeof(ts));
	start = skb_find_text(*pskb, dataoff, (*pskb)->len,
			      search[SEARCH_CONNECT].ts, &ts);
	if (start == UINT_MAX)
		goto out;
	start += dataoff + search[SEARCH_CONNECT].len;

	memset(&ts, 0, sizeof(ts));
	stop = skb_find_text(*pskb, start, (*pskb)->len,
			     search[SEARCH_NEWLINE].ts, &ts);
	if (stop == UINT_MAX)
		goto out;
	stop += start;

	for (i = SEARCH_DATA; i <= SEARCH_INDEX; i++) {
		memset(&ts, 0, sizeof(ts));
		off = skb_find_text(*pskb, start, stop, search[i].ts, &ts);
		if (off == UINT_MAX)
			continue;
		off += start + search[i].len;

		len = min_t(unsigned int, sizeof(pbuf) - 1, stop - off);
		if (skb_copy_bits(*pskb, off, pbuf, len))
			break;
		pbuf[len] = '\0';

		port = simple_strtoul(pbuf, &tmp, 10);
		len = tmp - pbuf;
		if (port == 0 || len > 5)
			break;

		exp = ip_conntrack_expect_alloc(ct);
		if (exp == NULL) {
			ret = NF_DROP;
			goto out;
		}

		exp->expectfn = NULL;
		exp->flags = 0;

		exp->tuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
		exp->tuple.src.u.tcp.port = 0;
		exp->tuple.dst.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
		exp->tuple.dst.protonum = IPPROTO_TCP;
		exp->tuple.dst.u.tcp.port = htons(port);

		exp->mask.src.ip = htonl(0xFFFFFFFF);
		exp->mask.src.u.tcp.port = 0;
		exp->mask.dst.ip = htonl(0xFFFFFFFF);
		exp->mask.dst.protonum = 0xFF;
		exp->mask.dst.u.tcp.port = htons(0xFFFF);

		if (ip_nat_amanda_hook)
			ret = ip_nat_amanda_hook(pskb, ctinfo, off - dataoff,
						 len, exp);
		else if (ip_conntrack_expect_related(exp) != 0)
			ret = NF_DROP;
		ip_conntrack_expect_put(exp);
	}

out:
	return ret;
}