]> Pileus Git - ~andy/linux/blobdiff - net/ipv6/fib6_rules.c
[NETNS][IPV6] ip6_fib - make it per network namespace
[~andy/linux] / net / ipv6 / fib6_rules.c
index 53b3998a486ced67d9eae000cff6c9a1269ecf66..03ad23a5fd3cadd9ea16a9f7d60e298f7b399906 100644 (file)
@@ -31,29 +31,8 @@ struct fib6_rule
 
 static struct fib_rules_ops fib6_rules_ops;
 
-static struct fib6_rule main_rule = {
-       .common = {
-               .refcnt =       ATOMIC_INIT(2),
-               .pref =         0x7FFE,
-               .action =       FR_ACT_TO_TBL,
-               .table =        RT6_TABLE_MAIN,
-       },
-};
-
-static struct fib6_rule local_rule = {
-       .common = {
-               .refcnt =       ATOMIC_INIT(2),
-               .pref =         0,
-               .action =       FR_ACT_TO_TBL,
-               .table =        RT6_TABLE_LOCAL,
-               .flags =        FIB_RULE_PERMANENT,
-       },
-};
-
-static LIST_HEAD(fib6_rules);
-
-struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
-                                  pol_lookup_t lookup)
+struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi *fl,
+                                  int flags, pol_lookup_t lookup)
 {
        struct fib_lookup_arg arg = {
                .lookup_ptr = lookup,
@@ -92,7 +71,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
                goto discard_pkt;
        }
 
-       table = fib6_get_table(rule->table);
+       table = fib6_get_table(&init_net, rule->table);
        if (table)
                rt = lookup(table, flp, flags);
 
@@ -106,8 +85,8 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
                if ((rule->flags & FIB_RULE_FIND_SADDR) &&
                    r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
                        struct in6_addr saddr;
-                       if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
-                                          &saddr))
+                       if (ipv6_dev_get_saddr(ip6_dst_idev(&rt->u.dst)->dev,
+                                              &flp->fl6_dst, &saddr))
                                goto again;
                        if (!ipv6_prefix_equal(&saddr, &r->src.addr,
                                               r->src.plen))
@@ -172,7 +151,7 @@ static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
                if (rule->table == RT6_TABLE_UNSPEC)
                        goto errout;
 
-               if (fib6_new_table(rule->table) == NULL) {
+               if (fib6_new_table(&init_net, rule->table) == NULL) {
                        err = -ENOBUFS;
                        goto errout;
                }
@@ -244,7 +223,7 @@ nla_put_failure:
        return -ENOBUFS;
 }
 
-static u32 fib6_rule_default_pref(void)
+static u32 fib6_rule_default_pref(struct fib_rules_ops *ops)
 {
        return 0x3FFF;
 }
@@ -268,16 +247,42 @@ static struct fib_rules_ops fib6_rules_ops = {
        .nlmsg_payload          = fib6_rule_nlmsg_payload,
        .nlgroup                = RTNLGRP_IPV6_RULE,
        .policy                 = fib6_rule_policy,
-       .rules_list             = &fib6_rules,
+       .rules_list             = LIST_HEAD_INIT(fib6_rules_ops.rules_list),
        .owner                  = THIS_MODULE,
+       .fro_net                = &init_net,
 };
 
-void __init fib6_rules_init(void)
+static int __init fib6_default_rules_init(void)
+{
+       int err;
+
+       err = fib_default_rule_add(&fib6_rules_ops, 0,
+                                  RT6_TABLE_LOCAL, FIB_RULE_PERMANENT);
+       if (err < 0)
+               return err;
+       err = fib_default_rule_add(&fib6_rules_ops, 0x7FFE, RT6_TABLE_MAIN, 0);
+       if (err < 0)
+               return err;
+       return 0;
+}
+
+int __init fib6_rules_init(void)
 {
-       list_add_tail(&local_rule.common.list, &fib6_rules);
-       list_add_tail(&main_rule.common.list, &fib6_rules);
+       int ret;
+
+       ret = fib6_default_rules_init();
+       if (ret)
+               goto out;
 
-       fib_rules_register(&fib6_rules_ops);
+       ret = fib_rules_register(&fib6_rules_ops);
+       if (ret)
+               goto out_default_rules_init;
+out:
+       return ret;
+
+out_default_rules_init:
+       fib_rules_cleanup_ops(&fib6_rules_ops);
+       goto out;
 }
 
 void fib6_rules_cleanup(void)