Skip to content

Commit 6ef94cf

Browse files
wertarbytedavem330
authored andcommitted
fib_rules: add route suppression based on ifgroup
This change adds the ability to suppress a routing decision based upon the interface group the selected interface belongs to. This allows it to exclude specific devices from a routing decision. Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d1c53c8 commit 6ef94cf

5 files changed

Lines changed: 43 additions & 10 deletions

File tree

‎include/net/fib_rules.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct fib_rule {
1818
u32 pref;
1919
u32 flags;
2020
u32 table;
21+
int suppress_ifgroup;
2122
u8 table_prefixlen_min;
2223
u8 action;
2324
u32 target;
@@ -84,6 +85,7 @@ struct fib_rules_ops {
8485
[FRA_FWMASK] = { .type = NLA_U32 }, \
8586
[FRA_TABLE] = { .type = NLA_U32 }, \
8687
[FRA_TABLE_PREFIXLEN_MIN] = { .type = NLA_U8 }, \
88+
[FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \
8789
[FRA_GOTO] = { .type = NLA_U32 }
8890

8991
static inline void fib_rule_get(struct fib_rule *rule)

‎include/uapi/linux/fib_rules.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum {
4444
FRA_FWMARK, /* mark */
4545
FRA_FLOW, /* flow/class id */
4646
FRA_UNUSED6,
47-
FRA_UNUSED7,
47+
FRA_SUPPRESS_IFGROUP,
4848
FRA_TABLE_PREFIXLEN_MIN,
4949
FRA_TABLE, /* Extended table id */
5050
FRA_FWMASK, /* mask for netfilter mark */

‎net/core/fib_rules.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
343343
if (tb[FRA_TABLE_PREFIXLEN_MIN])
344344
rule->table_prefixlen_min = nla_get_u8(tb[FRA_TABLE_PREFIXLEN_MIN]);
345345

346+
if (tb[FRA_SUPPRESS_IFGROUP])
347+
rule->suppress_ifgroup = nla_get_u32(tb[FRA_SUPPRESS_IFGROUP]);
348+
346349
if (!tb[FRA_PRIORITY] && ops->default_pref)
347350
rule->pref = ops->default_pref(ops);
348351

@@ -529,6 +532,7 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
529532
+ nla_total_size(4) /* FRA_PRIORITY */
530533
+ nla_total_size(4) /* FRA_TABLE */
531534
+ nla_total_size(1) /* FRA_TABLE_PREFIXLEN_MIN */
535+
+ nla_total_size(4) /* FRA_SUPPRESS_IFGROUP */
532536
+ nla_total_size(4) /* FRA_FWMARK */
533537
+ nla_total_size(4); /* FRA_FWMASK */
534538

@@ -588,6 +592,12 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
588592
(rule->target &&
589593
nla_put_u32(skb, FRA_GOTO, rule->target)))
590594
goto nla_put_failure;
595+
596+
if (rule->suppress_ifgroup != -1) {
597+
if (nla_put_u32(skb, FRA_SUPPRESS_IFGROUP, rule->suppress_ifgroup))
598+
goto nla_put_failure;
599+
}
600+
591601
if (ops->fill(rule, skb, frh) < 0)
592602
goto nla_put_failure;
593603

‎net/ipv4/fib_rules.c‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,27 @@ static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp,
103103

104104
static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
105105
{
106+
struct fib_result *result = (struct fib_result *) arg->result;
107+
struct net_device *dev = result->fi->fib_dev;
108+
106109
/* do not accept result if the route does
107110
* not meet the required prefix length
108111
*/
109-
struct fib_result *result = (struct fib_result *) arg->result;
110-
if (result->prefixlen < rule->table_prefixlen_min) {
111-
if (!(arg->flags & FIB_LOOKUP_NOREF))
112-
fib_info_put(result->fi);
113-
return true;
114-
}
112+
if (result->prefixlen < rule->table_prefixlen_min)
113+
goto suppress_route;
114+
115+
/* do not accept result if the route uses a device
116+
* belonging to a forbidden interface group
117+
*/
118+
if (rule->suppress_ifgroup != -1 && dev && dev->group == rule->suppress_ifgroup)
119+
goto suppress_route;
120+
115121
return false;
122+
123+
suppress_route:
124+
if (!(arg->flags & FIB_LOOKUP_NOREF))
125+
fib_info_put(result->fi);
126+
return true;
116127
}
117128

118129
static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)

‎net/ipv6/fib6_rules.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,24 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
122122
static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
123123
{
124124
struct rt6_info *rt = (struct rt6_info *) arg->result;
125+
struct net_device *dev = rt->rt6i_idev->dev;
125126
/* do not accept result if the route does
126127
* not meet the required prefix length
127128
*/
128-
if (rt->rt6i_dst.plen < rule->table_prefixlen_min) {
129+
if (rt->rt6i_dst.plen < rule->table_prefixlen_min)
130+
goto suppress_route;
131+
132+
/* do not accept result if the route uses a device
133+
* belonging to a forbidden interface group
134+
*/
135+
if (rule->suppress_ifgroup != -1 && dev && dev->group == rule->suppress_ifgroup)
136+
goto suppress_route;
137+
138+
return false;
139+
140+
suppress_route:
129141
ip6_rt_put(rt);
130142
return true;
131-
}
132-
return false;
133143
}
134144

135145
static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)

0 commit comments

Comments
 (0)