Skip to content

Commit 73f5698

Browse files
wertarbytedavem330
authored andcommitted
fib_rules: fix suppressor names and default values
This change brings the suppressor attribute names into line; it also changes the data types to provide a more consistent interface. While -1 indicates that the suppressor is not enabled, values >= 0 for suppress_prefixlen or suppress_ifgroup reject routing decisions violating the constraint. This changes the previously presented behaviour of suppress_prefixlen, where a prefix length _less_ than the attribute value was rejected. After this change, a prefix length less than *or* equal to the value is considered a violation of the rule constraint. It also changes the default values for default and newly added rules (disabling any suppression for those). Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0c0667a commit 73f5698

5 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎include/net/fib_rules.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct fib_rule {
1919
u32 flags;
2020
u32 table;
2121
int suppress_ifgroup;
22-
u8 table_prefixlen_min;
22+
int suppress_prefixlen;
2323
u8 action;
2424
u32 target;
2525
struct fib_rule __rcu *ctarget;
@@ -84,7 +84,7 @@ struct fib_rules_ops {
8484
[FRA_FWMARK] = { .type = NLA_U32 }, \
8585
[FRA_FWMASK] = { .type = NLA_U32 }, \
8686
[FRA_TABLE] = { .type = NLA_U32 }, \
87-
[FRA_TABLE_PREFIXLEN_MIN] = { .type = NLA_U8 }, \
87+
[FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \
8888
[FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \
8989
[FRA_GOTO] = { .type = NLA_U32 }
9090

‎include/uapi/linux/fib_rules.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum {
4545
FRA_FLOW, /* flow/class id */
4646
FRA_UNUSED6,
4747
FRA_SUPPRESS_IFGROUP,
48-
FRA_TABLE_PREFIXLEN_MIN,
48+
FRA_SUPPRESS_PREFIXLEN,
4949
FRA_TABLE, /* Extended table id */
5050
FRA_FWMASK, /* mask for netfilter mark */
5151
FRA_OIFNAME,

‎net/core/fib_rules.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
3333
r->flags = flags;
3434
r->fr_net = hold_net(ops->fro_net);
3535

36+
r->suppress_prefixlen = -1;
37+
r->suppress_ifgroup = -1;
38+
3639
/* The lock is not required here, the list in unreacheable
3740
* at the moment this function is called */
3841
list_add_tail(&r->list, &ops->rules_list);
@@ -340,11 +343,15 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
340343
rule->action = frh->action;
341344
rule->flags = frh->flags;
342345
rule->table = frh_get_table(frh, tb);
343-
if (tb[FRA_TABLE_PREFIXLEN_MIN])
344-
rule->table_prefixlen_min = nla_get_u8(tb[FRA_TABLE_PREFIXLEN_MIN]);
346+
if (tb[FRA_SUPPRESS_PREFIXLEN])
347+
rule->suppress_prefixlen = nla_get_u32(tb[FRA_SUPPRESS_PREFIXLEN]);
348+
else
349+
rule->suppress_prefixlen = -1;
345350

346351
if (tb[FRA_SUPPRESS_IFGROUP])
347352
rule->suppress_ifgroup = nla_get_u32(tb[FRA_SUPPRESS_IFGROUP]);
353+
else
354+
rule->suppress_ifgroup = -1;
348355

349356
if (!tb[FRA_PRIORITY] && ops->default_pref)
350357
rule->pref = ops->default_pref(ops);
@@ -531,7 +538,7 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
531538
+ nla_total_size(IFNAMSIZ) /* FRA_OIFNAME */
532539
+ nla_total_size(4) /* FRA_PRIORITY */
533540
+ nla_total_size(4) /* FRA_TABLE */
534-
+ nla_total_size(1) /* FRA_TABLE_PREFIXLEN_MIN */
541+
+ nla_total_size(4) /* FRA_SUPPRESS_PREFIXLEN */
535542
+ nla_total_size(4) /* FRA_SUPPRESS_IFGROUP */
536543
+ nla_total_size(4) /* FRA_FWMARK */
537544
+ nla_total_size(4); /* FRA_FWMASK */
@@ -558,7 +565,7 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
558565
frh->table = rule->table;
559566
if (nla_put_u32(skb, FRA_TABLE, rule->table))
560567
goto nla_put_failure;
561-
if (nla_put_u8(skb, FRA_TABLE_PREFIXLEN_MIN, rule->table_prefixlen_min))
568+
if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen))
562569
goto nla_put_failure;
563570
frh->res1 = 0;
564571
frh->res2 = 0;

‎net/ipv4/fib_rules.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg
109109
/* do not accept result if the route does
110110
* not meet the required prefix length
111111
*/
112-
if (result->prefixlen < rule->table_prefixlen_min)
112+
if (result->prefixlen <= rule->suppress_prefixlen)
113113
goto suppress_route;
114114

115115
/* do not accept result if the route uses a device

‎net/ipv6/fib6_rules.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg
126126
/* do not accept result if the route does
127127
* not meet the required prefix length
128128
*/
129-
if (rt->rt6i_dst.plen < rule->table_prefixlen_min)
129+
if (rt->rt6i_dst.plen <= rule->suppress_prefixlen)
130130
goto suppress_route;
131131

132132
/* do not accept result if the route uses a device

0 commit comments

Comments
 (0)