forked from mirrors/linux
		
	net: Allow a rule to track originating protocol
Allow a rule that is being added/deleted/modified or dumped to contain the originating protocol's id. The protocol is handled just like a routes originating protocol is. This is especially useful because there is starting to be a plethora of different user space programs adding rules. Allow the vrf device to specify that the kernel is the originator of the rule created for this device. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									af9090c237
								
							
						
					
					
						commit
						cac56209a6
					
				
					 4 changed files with 10 additions and 3 deletions
				
			
		|  | @ -1174,6 +1174,7 @@ static int vrf_fib_rule(const struct net_device *dev, __u8 family, bool add_it) | ||||||
| 	memset(frh, 0, sizeof(*frh)); | 	memset(frh, 0, sizeof(*frh)); | ||||||
| 	frh->family = family; | 	frh->family = family; | ||||||
| 	frh->action = FR_ACT_TO_TBL; | 	frh->action = FR_ACT_TO_TBL; | ||||||
|  | 	frh->proto = RTPROT_KERNEL; | ||||||
| 
 | 
 | ||||||
| 	if (nla_put_u8(skb, FRA_L3MDEV, 1)) | 	if (nla_put_u8(skb, FRA_L3MDEV, 1)) | ||||||
| 		goto nla_put_failure; | 		goto nla_put_failure; | ||||||
|  |  | ||||||
|  | @ -26,7 +26,8 @@ struct fib_rule { | ||||||
| 	u32			table; | 	u32			table; | ||||||
| 	u8			action; | 	u8			action; | ||||||
| 	u8			l3mdev; | 	u8			l3mdev; | ||||||
| 	/* 2 bytes hole, try to use */ | 	u8                      proto; | ||||||
|  | 	/* 1 byte hole, try to use */ | ||||||
| 	u32			target; | 	u32			target; | ||||||
| 	__be64			tun_id; | 	__be64			tun_id; | ||||||
| 	struct fib_rule __rcu	*ctarget; | 	struct fib_rule __rcu	*ctarget; | ||||||
|  |  | ||||||
|  | @ -23,8 +23,8 @@ struct fib_rule_hdr { | ||||||
| 	__u8		tos; | 	__u8		tos; | ||||||
| 
 | 
 | ||||||
| 	__u8		table; | 	__u8		table; | ||||||
|  | 	__u8		proto; | ||||||
| 	__u8		res1;	/* reserved */ | 	__u8		res1;	/* reserved */ | ||||||
| 	__u8		res2;	/* reserved */ |  | ||||||
| 	__u8		action; | 	__u8		action; | ||||||
| 
 | 
 | ||||||
| 	__u32		flags; | 	__u32		flags; | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ int fib_default_rule_add(struct fib_rules_ops *ops, | ||||||
| 	r->pref = pref; | 	r->pref = pref; | ||||||
| 	r->table = table; | 	r->table = table; | ||||||
| 	r->flags = flags; | 	r->flags = flags; | ||||||
|  | 	r->proto = RTPROT_KERNEL; | ||||||
| 	r->fr_net = ops->fro_net; | 	r->fr_net = ops->fro_net; | ||||||
| 	r->uid_range = fib_kuid_range_unset; | 	r->uid_range = fib_kuid_range_unset; | ||||||
| 
 | 
 | ||||||
|  | @ -465,6 +466,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, | ||||||
| 	} | 	} | ||||||
| 	refcount_set(&rule->refcnt, 1); | 	refcount_set(&rule->refcnt, 1); | ||||||
| 	rule->fr_net = net; | 	rule->fr_net = net; | ||||||
|  | 	rule->proto = frh->proto; | ||||||
| 
 | 
 | ||||||
| 	rule->pref = tb[FRA_PRIORITY] ? nla_get_u32(tb[FRA_PRIORITY]) | 	rule->pref = tb[FRA_PRIORITY] ? nla_get_u32(tb[FRA_PRIORITY]) | ||||||
| 	                              : fib_default_rule_pref(ops); | 	                              : fib_default_rule_pref(ops); | ||||||
|  | @ -664,6 +666,9 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	list_for_each_entry(rule, &ops->rules_list, list) { | 	list_for_each_entry(rule, &ops->rules_list, list) { | ||||||
|  | 		if (frh->proto && (frh->proto != rule->proto)) | ||||||
|  | 			continue; | ||||||
|  | 
 | ||||||
| 		if (frh->action && (frh->action != rule->action)) | 		if (frh->action && (frh->action != rule->action)) | ||||||
| 			continue; | 			continue; | ||||||
| 
 | 
 | ||||||
|  | @ -808,9 +813,9 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule, | ||||||
| 	if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen)) | 	if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen)) | ||||||
| 		goto nla_put_failure; | 		goto nla_put_failure; | ||||||
| 	frh->res1 = 0; | 	frh->res1 = 0; | ||||||
| 	frh->res2 = 0; |  | ||||||
| 	frh->action = rule->action; | 	frh->action = rule->action; | ||||||
| 	frh->flags = rule->flags; | 	frh->flags = rule->flags; | ||||||
|  | 	frh->proto = rule->proto; | ||||||
| 
 | 
 | ||||||
| 	if (rule->action == FR_ACT_GOTO && | 	if (rule->action == FR_ACT_GOTO && | ||||||
| 	    rcu_access_pointer(rule->ctarget) == NULL) | 	    rcu_access_pointer(rule->ctarget) == NULL) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Donald Sharp
						Donald Sharp