Skip to content

Commit cac5620

Browse files
donaldsharpdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent af9090c commit cac5620

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

drivers/net/vrf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ static int vrf_fib_rule(const struct net_device *dev, __u8 family, bool add_it)
11741174
memset(frh, 0, sizeof(*frh));
11751175
frh->family = family;
11761176
frh->action = FR_ACT_TO_TBL;
1177+
frh->proto = RTPROT_KERNEL;
11771178

11781179
if (nla_put_u8(skb, FRA_L3MDEV, 1))
11791180
goto nla_put_failure;

include/net/fib_rules.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct fib_rule {
2626
u32 table;
2727
u8 action;
2828
u8 l3mdev;
29-
/* 2 bytes hole, try to use */
29+
u8 proto;
30+
/* 1 byte hole, try to use */
3031
u32 target;
3132
__be64 tun_id;
3233
struct fib_rule __rcu *ctarget;

include/uapi/linux/fib_rules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct fib_rule_hdr {
2323
__u8 tos;
2424

2525
__u8 table;
26+
__u8 proto;
2627
__u8 res1; /* reserved */
27-
__u8 res2; /* reserved */
2828
__u8 action;
2929

3030
__u32 flags;

net/core/fib_rules.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
5151
r->pref = pref;
5252
r->table = table;
5353
r->flags = flags;
54+
r->proto = RTPROT_KERNEL;
5455
r->fr_net = ops->fro_net;
5556
r->uid_range = fib_kuid_range_unset;
5657

@@ -465,6 +466,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
465466
}
466467
refcount_set(&rule->refcnt, 1);
467468
rule->fr_net = net;
469+
rule->proto = frh->proto;
468470

469471
rule->pref = tb[FRA_PRIORITY] ? nla_get_u32(tb[FRA_PRIORITY])
470472
: fib_default_rule_pref(ops);
@@ -664,6 +666,9 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
664666
}
665667

666668
list_for_each_entry(rule, &ops->rules_list, list) {
669+
if (frh->proto && (frh->proto != rule->proto))
670+
continue;
671+
667672
if (frh->action && (frh->action != rule->action))
668673
continue;
669674

@@ -808,9 +813,9 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
808813
if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen))
809814
goto nla_put_failure;
810815
frh->res1 = 0;
811-
frh->res2 = 0;
812816
frh->action = rule->action;
813817
frh->flags = rule->flags;
818+
frh->proto = rule->proto;
814819

815820
if (rule->action == FR_ACT_GOTO &&
816821
rcu_access_pointer(rule->ctarget) == NULL)

0 commit comments

Comments
 (0)