Skip to content

Commit 1b71af6

Browse files
donaldsharpdavem330
authored andcommitted
net: fib_rules: Add new attribute to set protocol
For ages iproute2 has used `struct rtmsg` as the ancillary header for FIB rules and in the process set the protocol value to RTPROT_BOOT. Until ca56209a66 ("net: Allow a rule to track originating protocol") the kernel rules code ignored the protocol value sent from userspace and always returned 0 in notifications. To avoid incompatibility with existing iproute2, send the protocol as a new attribute. Fixes: cac5620 ("net: Allow a rule to track originating protocol") Signed-off-by: Donald Sharp <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cc30c93 commit 1b71af6

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

drivers/net/vrf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ static inline size_t vrf_fib_rule_nl_size(void)
11451145
sz = NLMSG_ALIGN(sizeof(struct fib_rule_hdr));
11461146
sz += nla_total_size(sizeof(u8)); /* FRA_L3MDEV */
11471147
sz += nla_total_size(sizeof(u32)); /* FRA_PRIORITY */
1148+
sz += nla_total_size(sizeof(u8)); /* FRA_PROTOCOL */
11481149

11491150
return sz;
11501151
}
@@ -1174,7 +1175,9 @@ static int vrf_fib_rule(const struct net_device *dev, __u8 family, bool add_it)
11741175
memset(frh, 0, sizeof(*frh));
11751176
frh->family = family;
11761177
frh->action = FR_ACT_TO_TBL;
1177-
frh->proto = RTPROT_KERNEL;
1178+
1179+
if (nla_put_u8(skb, FRA_PROTOCOL, RTPROT_KERNEL))
1180+
goto nla_put_failure;
11781181

11791182
if (nla_put_u8(skb, FRA_L3MDEV, 1))
11801183
goto nla_put_failure;

include/net/fib_rules.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ struct fib_rule_notifier_info {
109109
[FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \
110110
[FRA_GOTO] = { .type = NLA_U32 }, \
111111
[FRA_L3MDEV] = { .type = NLA_U8 }, \
112-
[FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }
112+
[FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }, \
113+
[FRA_PROTOCOL] = { .type = NLA_U8 }
113114

114115
static inline void fib_rule_get(struct fib_rule *rule)
115116
{

include/uapi/linux/fib_rules.h

Lines changed: 3 additions & 2 deletions
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;
27-
__u8 res1; /* reserved */
26+
__u8 res1; /* reserved */
27+
__u8 res2; /* reserved */
2828
__u8 action;
2929

3030
__u32 flags;
@@ -58,6 +58,7 @@ enum {
5858
FRA_PAD,
5959
FRA_L3MDEV, /* iif or oif is l3mdev goto its table */
6060
FRA_UID_RANGE, /* UID range */
61+
FRA_PROTOCOL, /* Originator of the rule */
6162
__FRA_MAX
6263
};
6364

net/core/fib_rules.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,13 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
466466
}
467467
refcount_set(&rule->refcnt, 1);
468468
rule->fr_net = net;
469-
rule->proto = frh->proto;
470469

471470
rule->pref = tb[FRA_PRIORITY] ? nla_get_u32(tb[FRA_PRIORITY])
472471
: fib_default_rule_pref(ops);
473472

473+
rule->proto = tb[FRA_PROTOCOL] ?
474+
nla_get_u8(tb[FRA_PROTOCOL]) : RTPROT_UNSPEC;
475+
474476
if (tb[FRA_IIFNAME]) {
475477
struct net_device *dev;
476478

@@ -666,7 +668,8 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
666668
}
667669

668670
list_for_each_entry(rule, &ops->rules_list, list) {
669-
if (frh->proto && (frh->proto != rule->proto))
671+
if (tb[FRA_PROTOCOL] &&
672+
(rule->proto != nla_get_u8(tb[FRA_PROTOCOL])))
670673
continue;
671674

672675
if (frh->action && (frh->action != rule->action))
@@ -786,7 +789,8 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
786789
+ nla_total_size(4) /* FRA_FWMARK */
787790
+ nla_total_size(4) /* FRA_FWMASK */
788791
+ nla_total_size_64bit(8) /* FRA_TUN_ID */
789-
+ nla_total_size(sizeof(struct fib_kuid_range));
792+
+ nla_total_size(sizeof(struct fib_kuid_range))
793+
+ nla_total_size(1); /* FRA_PROTOCOL */
790794

791795
if (ops->nlmsg_payload)
792796
payload += ops->nlmsg_payload(rule);
@@ -813,9 +817,12 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
813817
if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen))
814818
goto nla_put_failure;
815819
frh->res1 = 0;
820+
frh->res2 = 0;
816821
frh->action = rule->action;
817822
frh->flags = rule->flags;
818-
frh->proto = rule->proto;
823+
824+
if (nla_put_u8(skb, FRA_PROTOCOL, rule->proto))
825+
goto nla_put_failure;
819826

820827
if (rule->action == FR_ACT_GOTO &&
821828
rcu_access_pointer(rule->ctarget) == NULL)

0 commit comments

Comments
 (0)