net: No dst refcounting in ip_queue_xmit()
[safe/jmp/linux-2.6] / net / ipv6 / fib6_rules.c
index cac5807..8e44f8f 100644 (file)
@@ -84,17 +84,11 @@ 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;
-                       unsigned int srcprefs = 0;
 
-                       if (flags & RT6_LOOKUP_F_SRCPREF_TMP)
-                               srcprefs |= IPV6_PREFER_SRC_TMP;
-                       if (flags & RT6_LOOKUP_F_SRCPREF_PUBLIC)
-                               srcprefs |= IPV6_PREFER_SRC_PUBLIC;
-                       if (flags & RT6_LOOKUP_F_SRCPREF_COA)
-                               srcprefs |= IPV6_PREFER_SRC_COA;
-
-                       if (ipv6_dev_get_saddr(ip6_dst_idev(&rt->u.dst)->dev,
-                                              &flp->fl6_dst, srcprefs,
+                       if (ipv6_dev_get_saddr(net,
+                                              ip6_dst_idev(&rt->u.dst)->dev,
+                                              &flp->fl6_dst,
+                                              rt6_flags2srcprefs(flags),
                                               &saddr))
                                goto again;
                        if (!ipv6_prefix_equal(&saddr, &r->src.addr,
@@ -150,7 +144,7 @@ static const struct nla_policy fib6_rule_policy[FRA_MAX+1] = {
 };
 
 static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
-                              struct nlmsghdr *nlh, struct fib_rule_hdr *frh,
+                              struct fib_rule_hdr *frh,
                               struct nlattr **tb)
 {
        int err = -EINVAL;
@@ -210,11 +204,10 @@ static int fib6_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
 }
 
 static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
-                         struct nlmsghdr *nlh, struct fib_rule_hdr *frh)
+                         struct fib_rule_hdr *frh)
 {
        struct fib6_rule *rule6 = (struct fib6_rule *) rule;
 
-       frh->family = AF_INET6;
        frh->dst_len = rule6->dst.plen;
        frh->src_len = rule6->src.plen;
        frh->tos = rule6->tclass;
@@ -244,7 +237,7 @@ static size_t fib6_rule_nlmsg_payload(struct fib_rule *rule)
               + nla_total_size(16); /* src */
 }
 
-static struct fib_rules_ops fib6_rules_ops_template = {
+static const struct fib_rules_ops __net_initdata fib6_rules_ops_template = {
        .family                 = AF_INET6,
        .rule_size              = sizeof(struct fib6_rule),
        .addr_size              = sizeof(struct in6_addr),
@@ -261,46 +254,38 @@ static struct fib_rules_ops fib6_rules_ops_template = {
        .fro_net                = &init_net,
 };
 
-static int fib6_rules_net_init(struct net *net)
+static int __net_init fib6_rules_net_init(struct net *net)
 {
+       struct fib_rules_ops *ops;
        int err = -ENOMEM;
 
-       net->ipv6.fib6_rules_ops = kmemdup(&fib6_rules_ops_template,
-                                          sizeof(*net->ipv6.fib6_rules_ops),
-                                          GFP_KERNEL);
-       if (!net->ipv6.fib6_rules_ops)
-               goto out;
+       ops = fib_rules_register(&fib6_rules_ops_template, net);
+       if (IS_ERR(ops))
+               return PTR_ERR(ops);
+       net->ipv6.fib6_rules_ops = ops;
 
-       net->ipv6.fib6_rules_ops->fro_net = net;
-       INIT_LIST_HEAD(&net->ipv6.fib6_rules_ops->rules_list);
 
        err = fib_default_rule_add(net->ipv6.fib6_rules_ops, 0,
-                                  RT6_TABLE_LOCAL, FIB_RULE_PERMANENT);
+                                  RT6_TABLE_LOCAL, 0);
        if (err)
                goto out_fib6_rules_ops;
 
        err = fib_default_rule_add(net->ipv6.fib6_rules_ops,
                                   0x7FFE, RT6_TABLE_MAIN, 0);
        if (err)
-               goto out_fib6_default_rule_add;
+               goto out_fib6_rules_ops;
 
-       err = fib_rules_register(net->ipv6.fib6_rules_ops);
-       if (err)
-               goto out_fib6_default_rule_add;
 out:
        return err;
 
-out_fib6_default_rule_add:
-       fib_rules_cleanup_ops(net->ipv6.fib6_rules_ops);
 out_fib6_rules_ops:
-       kfree(net->ipv6.fib6_rules_ops);
+       fib_rules_unregister(ops);
        goto out;
 }
 
-static void fib6_rules_net_exit(struct net *net)
+static void __net_exit fib6_rules_net_exit(struct net *net)
 {
        fib_rules_unregister(net->ipv6.fib6_rules_ops);
-       kfree(net->ipv6.fib6_rules_ops);
 }
 
 static struct pernet_operations fib6_rules_net_ops = {
@@ -316,5 +301,5 @@ int __init fib6_rules_init(void)
 
 void fib6_rules_cleanup(void)
 {
-       return unregister_pernet_subsys(&fib6_rules_net_ops);
+       unregister_pernet_subsys(&fib6_rules_net_ops);
 }