]> err.no Git - linux-2.6/blobdiff - net/core/fib_rules.c
[ARM] 5117/1: pxafb: fix __devinit/exit annotations
[linux-2.6] / net / core / fib_rules.c
index c5f78fed6885b25ea428f49306f2b840b32e0245..e3e9ab0f74e33caf9e0df3a8d0829359f86eefe7 100644 (file)
@@ -29,6 +29,7 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
        r->pref = pref;
        r->table = table;
        r->flags = flags;
+       r->fr_net = hold_net(ops->fro_net);
 
        /* The lock is not required here, the list in unreacheable
         * at the moment this function is called */
@@ -37,8 +38,7 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
 }
 EXPORT_SYMBOL(fib_default_rule_add);
 
-static void notify_rule_change(struct net *net, int event,
-                              struct fib_rule *rule,
+static void notify_rule_change(int event, struct fib_rule *rule,
                               struct fib_rules_ops *ops, struct nlmsghdr *nlh,
                               u32 pid);
 
@@ -72,10 +72,13 @@ static void flush_route_cache(struct fib_rules_ops *ops)
                ops->flush_cache();
 }
 
-int fib_rules_register(struct net *net, struct fib_rules_ops *ops)
+int fib_rules_register(struct fib_rules_ops *ops)
 {
        int err = -EEXIST;
        struct fib_rules_ops *o;
+       struct net *net;
+
+       net = ops->fro_net;
 
        if (ops->rule_size < sizeof(struct fib_rule))
                return -EINVAL;
@@ -112,29 +115,17 @@ void fib_rules_cleanup_ops(struct fib_rules_ops *ops)
 }
 EXPORT_SYMBOL_GPL(fib_rules_cleanup_ops);
 
-int fib_rules_unregister(struct net *net, struct fib_rules_ops *ops)
+void fib_rules_unregister(struct fib_rules_ops *ops)
 {
-       int err = 0;
-       struct fib_rules_ops *o;
+       struct net *net = ops->fro_net;
 
        spin_lock(&net->rules_mod_lock);
-       list_for_each_entry(o, &net->rules_ops, list) {
-               if (o == ops) {
-                       list_del_rcu(&o->list);
-                       fib_rules_cleanup_ops(ops);
-                       goto out;
-               }
-       }
-
-       err = -ENOENT;
-out:
+       list_del_rcu(&ops->list);
+       fib_rules_cleanup_ops(ops);
        spin_unlock(&net->rules_mod_lock);
 
        synchronize_rcu();
-       if (!err)
-               release_net(net);
-
-       return err;
+       release_net(net);
 }
 
 EXPORT_SYMBOL_GPL(fib_rules_unregister);
@@ -223,7 +214,7 @@ errout:
 
 static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        struct fib_rule_hdr *frh = nlmsg_data(nlh);
        struct fib_rules_ops *ops = NULL;
        struct fib_rule *rule, *r, *last = NULL;
@@ -252,6 +243,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
                err = -ENOMEM;
                goto errout;
        }
+       rule->fr_net = hold_net(net);
 
        if (tb[FRA_PRIORITY])
                rule->pref = nla_get_u32(tb[FRA_PRIORITY]);
@@ -346,12 +338,13 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
        else
                list_add_rcu(&rule->list, &ops->rules_list);
 
-       notify_rule_change(net, RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
+       notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
        flush_route_cache(ops);
        rules_ops_put(ops);
        return 0;
 
 errout_free:
+       release_net(rule->fr_net);
        kfree(rule);
 errout:
        rules_ops_put(ops);
@@ -360,7 +353,7 @@ errout:
 
 static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        struct fib_rule_hdr *frh = nlmsg_data(nlh);
        struct fib_rules_ops *ops = NULL;
        struct fib_rule *rule, *tmp;
@@ -436,7 +429,7 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
                }
 
                synchronize_rcu();
-               notify_rule_change(net, RTM_DELRULE, rule, ops, nlh,
+               notify_rule_change(RTM_DELRULE, rule, ops, nlh,
                                   NETLINK_CB(skb).pid);
                fib_rule_put(rule);
                flush_route_cache(ops);
@@ -542,7 +535,7 @@ skip:
 
 static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        struct fib_rules_ops *ops;
        int idx = 0, family;
 
@@ -574,13 +567,15 @@ static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
        return skb->len;
 }
 
-static void notify_rule_change(struct net *net, int event, struct fib_rule *rule,
+static void notify_rule_change(int event, struct fib_rule *rule,
                               struct fib_rules_ops *ops, struct nlmsghdr *nlh,
                               u32 pid)
 {
+       struct net *net;
        struct sk_buff *skb;
        int err = -ENOBUFS;
 
+       net = ops->fro_net;
        skb = nlmsg_new(fib_rule_nlmsg_size(ops, rule), GFP_KERNEL);
        if (skb == NULL)
                goto errout;
@@ -592,6 +587,7 @@ static void notify_rule_change(struct net *net, int event, struct fib_rule *rule
                kfree_skb(skb);
                goto errout;
        }
+
        err = rtnl_notify(skb, net, pid, ops->nlgroup, nlh, GFP_KERNEL);
 errout:
        if (err < 0)
@@ -623,7 +619,7 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event,
                            void *ptr)
 {
        struct net_device *dev = ptr;
-       struct net *net = dev->nd_net;
+       struct net *net = dev_net(dev);
        struct fib_rules_ops *ops;
 
        ASSERT_RTNL();