diff options
Diffstat (limited to 'net/sched/cls_u32.c')
| -rw-r--r-- | net/sched/cls_u32.c | 191 | 
1 files changed, 106 insertions, 85 deletions
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index b0c2a82178a..70c0be8d012 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -38,18 +38,18 @@  #include <linux/errno.h>  #include <linux/rtnetlink.h>  #include <linux/skbuff.h> +#include <linux/bitmap.h>  #include <net/netlink.h>  #include <net/act_api.h>  #include <net/pkt_cls.h> -struct tc_u_knode -{ +struct tc_u_knode {  	struct tc_u_knode	*next;  	u32			handle;  	struct tc_u_hnode	*ht_up;  	struct tcf_exts		exts;  #ifdef CONFIG_NET_CLS_IND -	char                     indev[IFNAMSIZ]; +	int			ifindex;  #endif  	u8			fshift;  	struct tcf_result	res; @@ -63,45 +63,40 @@ struct tc_u_knode  	struct tc_u32_sel	sel;  }; -struct tc_u_hnode -{ +struct tc_u_hnode {  	struct tc_u_hnode	*next;  	u32			handle;  	u32			prio;  	struct tc_u_common	*tp_c;  	int			refcnt; -	unsigned		divisor; +	unsigned int		divisor;  	struct tc_u_knode	*ht[1];  }; -struct tc_u_common -{ +struct tc_u_common {  	struct tc_u_hnode	*hlist;  	struct Qdisc		*q;  	int			refcnt;  	u32			hgenerator;  }; -static const struct tcf_ext_map u32_ext_map = { -	.action = TCA_U32_ACT, -	.police = TCA_U32_POLICE -}; - -static __inline__ unsigned u32_hash_fold(__be32 key, struct tc_u32_sel *sel, u8 fshift) +static inline unsigned int u32_hash_fold(__be32 key, +					 const struct tc_u32_sel *sel, +					 u8 fshift)  { -	unsigned h = ntohl(key & sel->hmask)>>fshift; +	unsigned int h = ntohl(key & sel->hmask) >> fshift;  	return h;  } -static int u32_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_result *res) +static int u32_classify(struct sk_buff *skb, const struct tcf_proto *tp, struct tcf_result *res)  {  	struct {  		struct tc_u_knode *knode;  		unsigned int	  off;  	} stack[TC_U32_MAXDEPTH]; -	struct tc_u_hnode *ht = (struct tc_u_hnode*)tp->root; +	struct tc_u_hnode *ht = tp->root;  	unsigned int off = skb_network_offset(skb);  	struct tc_u_knode *n;  	int sdepth = 0; @@ -120,7 +115,7 @@ next_knode:  		struct tc_u32_key *key = n->sel.keys;  #ifdef CONFIG_CLS_U32_PERF -		n->pf->rcnt +=1; +		n->pf->rcnt += 1;  		j = 0;  #endif @@ -133,14 +128,14 @@ next_knode:  		}  #endif -		for (i = n->sel.nkeys; i>0; i--, key++) { +		for (i = n->sel.nkeys; i > 0; i--, key++) {  			int toff = off + key->off + (off2 & key->offmask); -			__be32 *data, _data; +			__be32 *data, hdata;  			if (skb_headroom(skb) + toff > INT_MAX)  				goto out; -			data = skb_header_pointer(skb, toff, 4, &_data); +			data = skb_header_pointer(skb, toff, 4, &hdata);  			if (!data)  				goto out;  			if ((*data ^ key->val) & key->mask) { @@ -148,23 +143,23 @@ next_knode:  				goto next_knode;  			}  #ifdef CONFIG_CLS_U32_PERF -			n->pf->kcnts[j] +=1; +			n->pf->kcnts[j] += 1;  			j++;  #endif  		}  		if (n->ht_down == NULL) {  check_terminal: -			if (n->sel.flags&TC_U32_TERMINAL) { +			if (n->sel.flags & TC_U32_TERMINAL) {  				*res = n->res;  #ifdef CONFIG_NET_CLS_IND -				if (!tcf_match_indev(skb, n->indev)) { +				if (!tcf_match_indev(skb, n->ifindex)) {  					n = n->next;  					goto next_knode;  				}  #endif  #ifdef CONFIG_CLS_U32_PERF -				n->pf->rhit +=1; +				n->pf->rhit += 1;  #endif  				r = tcf_exts_exec(skb, &n->exts, res);  				if (r < 0) { @@ -188,26 +183,26 @@ check_terminal:  		ht = n->ht_down;  		sel = 0;  		if (ht->divisor) { -			__be32 *data, _data; +			__be32 *data, hdata;  			data = skb_header_pointer(skb, off + n->sel.hoff, 4, -						  &_data); +						  &hdata);  			if (!data)  				goto out;  			sel = ht->divisor & u32_hash_fold(*data, &n->sel,  							  n->fshift);  		} -		if (!(n->sel.flags&(TC_U32_VAROFFSET|TC_U32_OFFSET|TC_U32_EAT))) +		if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))  			goto next_ht; -		if (n->sel.flags&(TC_U32_OFFSET|TC_U32_VAROFFSET)) { +		if (n->sel.flags & (TC_U32_OFFSET | TC_U32_VAROFFSET)) {  			off2 = n->sel.off + 3;  			if (n->sel.flags & TC_U32_VAROFFSET) { -				__be16 *data, _data; +				__be16 *data, hdata;  				data = skb_header_pointer(skb,  							  off + n->sel.offoff, -							  2, &_data); +							  2, &hdata);  				if (!data)  					goto out;  				off2 += ntohs(n->sel.offmask & *data) >> @@ -215,7 +210,7 @@ check_terminal:  			}  			off2 &= ~3;  		} -		if (n->sel.flags&TC_U32_EAT) { +		if (n->sel.flags & TC_U32_EAT) {  			off += off2;  			off2 = 0;  		} @@ -235,12 +230,11 @@ out:  	return -1;  deadloop: -	if (net_ratelimit()) -		printk(KERN_WARNING "cls_u32: dead loop\n"); +	net_warn_ratelimited("cls_u32: dead loop\n");  	return -1;  } -static __inline__ struct tc_u_hnode * +static struct tc_u_hnode *  u32_lookup_ht(struct tc_u_common *tp_c, u32 handle)  {  	struct tc_u_hnode *ht; @@ -252,10 +246,10 @@ u32_lookup_ht(struct tc_u_common *tp_c, u32 handle)  	return ht;  } -static __inline__ struct tc_u_knode * +static struct tc_u_knode *  u32_lookup_key(struct tc_u_hnode *ht, u32 handle)  { -	unsigned sel; +	unsigned int sel;  	struct tc_u_knode *n = NULL;  	sel = TC_U32_HASH(handle); @@ -300,7 +294,7 @@ static u32 gen_new_htid(struct tc_u_common *tp_c)  	do {  		if (++tp_c->hgenerator == 0x7FF)  			tp_c->hgenerator = 1; -	} while (--i>0 && u32_lookup_ht(tp_c, (tp_c->hgenerator|0x800)<<20)); +	} while (--i > 0 && u32_lookup_ht(tp_c, (tp_c->hgenerator|0x800)<<20));  	return i > 0 ? (tp_c->hgenerator|0x800)<<20 : 0;  } @@ -354,7 +348,7 @@ static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)  	return 0;  } -static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode* key) +static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key)  {  	struct tc_u_knode **kp;  	struct tc_u_hnode *ht = key->ht_up; @@ -378,9 +372,9 @@ static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode* key)  static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)  {  	struct tc_u_knode *n; -	unsigned h; +	unsigned int h; -	for (h=0; h<=ht->divisor; h++) { +	for (h = 0; h <= ht->divisor; h++) {  		while ((n = ht->ht[h]) != NULL) {  			ht->ht[h] = n->next; @@ -446,13 +440,13 @@ static void u32_destroy(struct tcf_proto *tp)  static int u32_delete(struct tcf_proto *tp, unsigned long arg)  { -	struct tc_u_hnode *ht = (struct tc_u_hnode*)arg; +	struct tc_u_hnode *ht = (struct tc_u_hnode *)arg;  	if (ht == NULL)  		return 0;  	if (TC_U32_KEY(ht->handle)) -		return u32_delete_key(tp, (struct tc_u_knode*)ht); +		return u32_delete_key(tp, (struct tc_u_knode *)ht);  	if (tp->root == ht)  		return -EINVAL; @@ -467,17 +461,25 @@ static int u32_delete(struct tcf_proto *tp, unsigned long arg)  	return 0;  } +#define NR_U32_NODE (1<<12)  static u32 gen_new_kid(struct tc_u_hnode *ht, u32 handle)  {  	struct tc_u_knode *n; -	unsigned i = 0x7FF; +	unsigned long i; +	unsigned long *bitmap = kzalloc(BITS_TO_LONGS(NR_U32_NODE) * sizeof(unsigned long), +					GFP_KERNEL); +	if (!bitmap) +		return handle | 0xFFF; + +	for (n = ht->ht[TC_U32_HASH(handle)]; n; n = n->next) +		set_bit(TC_U32_NODE(n->handle), bitmap); -	for (n=ht->ht[TC_U32_HASH(handle)]; n; n = n->next) -		if (i < TC_U32_NODE(n->handle)) -			i = TC_U32_NODE(n->handle); -	i++; +	i = find_next_zero_bit(bitmap, NR_U32_NODE, 0x800); +	if (i >= NR_U32_NODE) +		i = find_next_zero_bit(bitmap, NR_U32_NODE, 1); -	return handle|(i>0xFFF ? 0xFFF : i); +	kfree(bitmap); +	return handle | (i >= NR_U32_NODE ? 0xFFF : i);  }  static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = { @@ -490,15 +492,16 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = {  	[TCA_U32_MARK]		= { .len = sizeof(struct tc_u32_mark) },  }; -static int u32_set_parms(struct tcf_proto *tp, unsigned long base, -			 struct tc_u_hnode *ht, +static int u32_set_parms(struct net *net, struct tcf_proto *tp, +			 unsigned long base, struct tc_u_hnode *ht,  			 struct tc_u_knode *n, struct nlattr **tb, -			 struct nlattr *est) +			 struct nlattr *est, bool ovr)  {  	int err;  	struct tcf_exts e; -	err = tcf_exts_validate(tp, tb, est, &e, &u32_ext_map); +	tcf_exts_init(&e, TCA_U32_ACT, TCA_U32_POLICE); +	err = tcf_exts_validate(net, tp, tb, est, &e, ovr);  	if (err < 0)  		return err; @@ -533,9 +536,11 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,  #ifdef CONFIG_NET_CLS_IND  	if (tb[TCA_U32_INDEV]) { -		err = tcf_change_indev(tp, n->indev, tb[TCA_U32_INDEV]); -		if (err < 0) +		int ret; +		ret = tcf_change_indev(net, tb[TCA_U32_INDEV]); +		if (ret < 0)  			goto errout; +		n->ifindex = ret;  	}  #endif  	tcf_exts_change(tp, &n->exts, &e); @@ -546,9 +551,10 @@ errout:  	return err;  } -static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle, +static int u32_change(struct net *net, struct sk_buff *in_skb, +		      struct tcf_proto *tp, unsigned long base, u32 handle,  		      struct nlattr **tca, -		      unsigned long *arg) +		      unsigned long *arg, bool ovr)  {  	struct tc_u_common *tp_c = tp->data;  	struct tc_u_hnode *ht; @@ -566,15 +572,17 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,  	if (err < 0)  		return err; -	if ((n = (struct tc_u_knode*)*arg) != NULL) { +	n = (struct tc_u_knode *)*arg; +	if (n) {  		if (TC_U32_KEY(n->handle) == 0)  			return -EINVAL; -		return u32_set_parms(tp, base, n->ht_up, n, tb, tca[TCA_RATE]); +		return u32_set_parms(net, tp, base, n->ht_up, n, tb, +				     tca[TCA_RATE], ovr);  	}  	if (tb[TCA_U32_DIVISOR]) { -		unsigned divisor = nla_get_u32(tb[TCA_U32_DIVISOR]); +		unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]);  		if (--divisor > 0x100)  			return -EINVAL; @@ -585,7 +593,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,  			if (handle == 0)  				return -ENOMEM;  		} -		ht = kzalloc(sizeof(*ht) + divisor*sizeof(void*), GFP_KERNEL); +		ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);  		if (ht == NULL)  			return -ENOBUFS;  		ht->tp_c = tp_c; @@ -645,6 +653,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,  	n->ht_up = ht;  	n->handle = handle;  	n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0; +	tcf_exts_init(&n->exts, TCA_U32_ACT, TCA_U32_POLICE);  #ifdef CONFIG_CLS_U32_MARK  	if (tb[TCA_U32_MARK]) { @@ -656,7 +665,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,  	}  #endif -	err = u32_set_parms(tp, base, ht, n, tb, tca[TCA_RATE]); +	err = u32_set_parms(net, tp, base, ht, n, tb, tca[TCA_RATE], ovr);  	if (err == 0) {  		struct tc_u_knode **ins;  		for (ins = &ht->ht[TC_U32_HASH(handle)]; *ins; ins = &(*ins)->next) @@ -683,7 +692,7 @@ static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)  	struct tc_u_common *tp_c = tp->data;  	struct tc_u_hnode *ht;  	struct tc_u_knode *n; -	unsigned h; +	unsigned int h;  	if (arg->stop)  		return; @@ -714,10 +723,10 @@ static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)  	}  } -static int u32_dump(struct tcf_proto *tp, unsigned long fh, +static int u32_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,  		     struct sk_buff *skb, struct tcmsg *t)  { -	struct tc_u_knode *n = (struct tc_u_knode*)fh; +	struct tc_u_knode *n = (struct tc_u_knode *)fh;  	struct nlattr *nest;  	if (n == NULL) @@ -730,45 +739,57 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,  		goto nla_put_failure;  	if (TC_U32_KEY(n->handle) == 0) { -		struct tc_u_hnode *ht = (struct tc_u_hnode*)fh; -		u32 divisor = ht->divisor+1; -		NLA_PUT_U32(skb, TCA_U32_DIVISOR, divisor); +		struct tc_u_hnode *ht = (struct tc_u_hnode *)fh; +		u32 divisor = ht->divisor + 1; + +		if (nla_put_u32(skb, TCA_U32_DIVISOR, divisor)) +			goto nla_put_failure;  	} else { -		NLA_PUT(skb, TCA_U32_SEL, -			sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key), -			&n->sel); +		if (nla_put(skb, TCA_U32_SEL, +			    sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key), +			    &n->sel)) +			goto nla_put_failure;  		if (n->ht_up) {  			u32 htid = n->handle & 0xFFFFF000; -			NLA_PUT_U32(skb, TCA_U32_HASH, htid); +			if (nla_put_u32(skb, TCA_U32_HASH, htid)) +				goto nla_put_failure;  		} -		if (n->res.classid) -			NLA_PUT_U32(skb, TCA_U32_CLASSID, n->res.classid); -		if (n->ht_down) -			NLA_PUT_U32(skb, TCA_U32_LINK, n->ht_down->handle); +		if (n->res.classid && +		    nla_put_u32(skb, TCA_U32_CLASSID, n->res.classid)) +			goto nla_put_failure; +		if (n->ht_down && +		    nla_put_u32(skb, TCA_U32_LINK, n->ht_down->handle)) +			goto nla_put_failure;  #ifdef CONFIG_CLS_U32_MARK -		if (n->mark.val || n->mark.mask) -			NLA_PUT(skb, TCA_U32_MARK, sizeof(n->mark), &n->mark); +		if ((n->mark.val || n->mark.mask) && +		    nla_put(skb, TCA_U32_MARK, sizeof(n->mark), &n->mark)) +			goto nla_put_failure;  #endif -		if (tcf_exts_dump(skb, &n->exts, &u32_ext_map) < 0) +		if (tcf_exts_dump(skb, &n->exts) < 0)  			goto nla_put_failure;  #ifdef CONFIG_NET_CLS_IND -		if(strlen(n->indev)) -			NLA_PUT_STRING(skb, TCA_U32_INDEV, n->indev); +		if (n->ifindex) { +			struct net_device *dev; +			dev = __dev_get_by_index(net, n->ifindex); +			if (dev && nla_put_string(skb, TCA_U32_INDEV, dev->name)) +				goto nla_put_failure; +		}  #endif  #ifdef CONFIG_CLS_U32_PERF -		NLA_PUT(skb, TCA_U32_PCNT, -		sizeof(struct tc_u32_pcnt) + n->sel.nkeys*sizeof(u64), -			n->pf); +		if (nla_put(skb, TCA_U32_PCNT, +			    sizeof(struct tc_u32_pcnt) + n->sel.nkeys*sizeof(u64), +			    n->pf)) +			goto nla_put_failure;  #endif  	}  	nla_nest_end(skb, nest);  	if (TC_U32_KEY(n->handle)) -		if (tcf_exts_dump_stats(skb, &n->exts, &u32_ext_map) < 0) +		if (tcf_exts_dump_stats(skb, &n->exts) < 0)  			goto nla_put_failure;  	return skb->len;  | 
