aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorDavid Ahern <dsa@cumulusnetworks.com>2016-06-08 13:55:39 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-08 14:36:02 -0400
commit96c63fa7393d0a346acfe5a91e0c7d4c7782641b (patch)
tree0dcc6d3f3e5ccb788347399c9a63059f8ad8b5df /net/core
parent6278e03dc667b611cc9ebbd8f455d859f18f8e11 (diff)
net: Add l3mdev rule
Currently, VRFs require 1 oif and 1 iif rule per address family per VRF. As the number of VRF devices increases it brings scalability issues with the increasing rule list. All of the VRF rules have the same format with the exception of the specific table id to direct the lookup. Since the table id is available from the oif or iif in the loopup, the VRF rules can be consolidated to a single rule that pulls the table from the VRF device. This patch introduces a new rule attribute l3mdev. The l3mdev rule means the table id used for the lookup is pulled from the L3 master device (e.g., VRF) rather than being statically defined. With the l3mdev rule all of the basic VRF FIB rules are reduced to 1 l3mdev rule per address family (IPv4 and IPv6). If an admin wishes to insert higher priority rules for specific VRFs those rules will co-exist with the l3mdev rule. This capability means current VRF scripts will co-exist with this new simpler implementation. Currently, the rules list for both ipv4 and ipv6 look like this: $ ip ru ls 1000: from all oif vrf1 lookup 1001 1000: from all iif vrf1 lookup 1001 1000: from all oif vrf2 lookup 1002 1000: from all iif vrf2 lookup 1002 1000: from all oif vrf3 lookup 1003 1000: from all iif vrf3 lookup 1003 1000: from all oif vrf4 lookup 1004 1000: from all iif vrf4 lookup 1004 1000: from all oif vrf5 lookup 1005 1000: from all iif vrf5 lookup 1005 1000: from all oif vrf6 lookup 1006 1000: from all iif vrf6 lookup 1006 1000: from all oif vrf7 lookup 1007 1000: from all iif vrf7 lookup 1007 1000: from all oif vrf8 lookup 1008 1000: from all iif vrf8 lookup 1008 ... 32765: from all lookup local 32766: from all lookup main 32767: from all lookup default With the l3mdev rule the list is just the following regardless of the number of VRFs: $ ip ru ls 1000: from all lookup [l3mdev table] 32765: from all lookup local 32766: from all lookup main 32767: from all lookup default (Note: the above pretty print of the rule is based on an iproute2 prototype. Actual verbage may change) Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/fib_rules.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 840acebbb80c..98298b11f534 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -173,7 +173,8 @@ void fib_rules_unregister(struct fib_rules_ops *ops)
173EXPORT_SYMBOL_GPL(fib_rules_unregister); 173EXPORT_SYMBOL_GPL(fib_rules_unregister);
174 174
175static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops, 175static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
176 struct flowi *fl, int flags) 176 struct flowi *fl, int flags,
177 struct fib_lookup_arg *arg)
177{ 178{
178 int ret = 0; 179 int ret = 0;
179 180
@@ -189,6 +190,9 @@ static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
189 if (rule->tun_id && (rule->tun_id != fl->flowi_tun_key.tun_id)) 190 if (rule->tun_id && (rule->tun_id != fl->flowi_tun_key.tun_id))
190 goto out; 191 goto out;
191 192
193 if (rule->l3mdev && !l3mdev_fib_rule_match(rule->fr_net, fl, arg))
194 goto out;
195
192 ret = ops->match(rule, fl, flags); 196 ret = ops->match(rule, fl, flags);
193out: 197out:
194 return (rule->flags & FIB_RULE_INVERT) ? !ret : ret; 198 return (rule->flags & FIB_RULE_INVERT) ? !ret : ret;
@@ -204,7 +208,7 @@ int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
204 208
205 list_for_each_entry_rcu(rule, &ops->rules_list, list) { 209 list_for_each_entry_rcu(rule, &ops->rules_list, list) {
206jumped: 210jumped:
207 if (!fib_rule_match(rule, ops, fl, flags)) 211 if (!fib_rule_match(rule, ops, fl, flags, arg))
208 continue; 212 continue;
209 213
210 if (rule->action == FR_ACT_GOTO) { 214 if (rule->action == FR_ACT_GOTO) {
@@ -265,7 +269,7 @@ errout:
265 return err; 269 return err;
266} 270}
267 271
268static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh) 272int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh)
269{ 273{
270 struct net *net = sock_net(skb->sk); 274 struct net *net = sock_net(skb->sk);
271 struct fib_rule_hdr *frh = nlmsg_data(nlh); 275 struct fib_rule_hdr *frh = nlmsg_data(nlh);
@@ -336,6 +340,14 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
336 if (tb[FRA_TUN_ID]) 340 if (tb[FRA_TUN_ID])
337 rule->tun_id = nla_get_be64(tb[FRA_TUN_ID]); 341 rule->tun_id = nla_get_be64(tb[FRA_TUN_ID]);
338 342
343 if (tb[FRA_L3MDEV]) {
344#ifdef CONFIG_NET_L3_MASTER_DEV
345 rule->l3mdev = nla_get_u8(tb[FRA_L3MDEV]);
346 if (rule->l3mdev != 1)
347#endif
348 goto errout_free;
349 }
350
339 rule->action = frh->action; 351 rule->action = frh->action;
340 rule->flags = frh->flags; 352 rule->flags = frh->flags;
341 rule->table = frh_get_table(frh, tb); 353 rule->table = frh_get_table(frh, tb);
@@ -371,6 +383,9 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
371 } else if (rule->action == FR_ACT_GOTO) 383 } else if (rule->action == FR_ACT_GOTO)
372 goto errout_free; 384 goto errout_free;
373 385
386 if (rule->l3mdev && rule->table)
387 goto errout_free;
388
374 err = ops->configure(rule, skb, frh, tb); 389 err = ops->configure(rule, skb, frh, tb);
375 if (err < 0) 390 if (err < 0)
376 goto errout_free; 391 goto errout_free;
@@ -424,8 +439,9 @@ errout:
424 rules_ops_put(ops); 439 rules_ops_put(ops);
425 return err; 440 return err;
426} 441}
442EXPORT_SYMBOL_GPL(fib_nl_newrule);
427 443
428static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh) 444int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh)
429{ 445{
430 struct net *net = sock_net(skb->sk); 446 struct net *net = sock_net(skb->sk);
431 struct fib_rule_hdr *frh = nlmsg_data(nlh); 447 struct fib_rule_hdr *frh = nlmsg_data(nlh);
@@ -483,6 +499,10 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh)
483 (rule->tun_id != nla_get_be64(tb[FRA_TUN_ID]))) 499 (rule->tun_id != nla_get_be64(tb[FRA_TUN_ID])))
484 continue; 500 continue;
485 501
502 if (tb[FRA_L3MDEV] &&
503 (rule->l3mdev != nla_get_u8(tb[FRA_L3MDEV])))
504 continue;
505
486 if (!ops->compare(rule, frh, tb)) 506 if (!ops->compare(rule, frh, tb))
487 continue; 507 continue;
488 508
@@ -536,6 +556,7 @@ errout:
536 rules_ops_put(ops); 556 rules_ops_put(ops);
537 return err; 557 return err;
538} 558}
559EXPORT_SYMBOL_GPL(fib_nl_delrule);
539 560
540static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops, 561static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
541 struct fib_rule *rule) 562 struct fib_rule *rule)
@@ -607,7 +628,9 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
607 (rule->target && 628 (rule->target &&
608 nla_put_u32(skb, FRA_GOTO, rule->target)) || 629 nla_put_u32(skb, FRA_GOTO, rule->target)) ||
609 (rule->tun_id && 630 (rule->tun_id &&
610 nla_put_be64(skb, FRA_TUN_ID, rule->tun_id, FRA_PAD))) 631 nla_put_be64(skb, FRA_TUN_ID, rule->tun_id, FRA_PAD)) ||
632 (rule->l3mdev &&
633 nla_put_u8(skb, FRA_L3MDEV, rule->l3mdev)))
611 goto nla_put_failure; 634 goto nla_put_failure;
612 635
613 if (rule->suppress_ifgroup != -1) { 636 if (rule->suppress_ifgroup != -1) {