]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/core/fib_rules.c
net: fib_rules: consolidate IPv4 and DECnet ->default_pref() functions.
[net-next-2.6.git] / net / core / fib_rules.c
index 9a24377146bf0dc25163e96bfb3c9b6c0701ab40..1eb32276be773c61c4dbb83ba0752ded6dac8ead 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/slab.h>
 #include <linux/list.h>
 #include <net/net_namespace.h>
 #include <net/sock.h>
@@ -38,6 +39,24 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
 }
 EXPORT_SYMBOL(fib_default_rule_add);
 
+u32 fib_default_rule_pref(struct fib_rules_ops *ops)
+{
+       struct list_head *pos;
+       struct fib_rule *rule;
+
+       if (!list_empty(&ops->rules_list)) {
+               pos = ops->rules_list.next;
+               if (pos->next != &ops->rules_list) {
+                       rule = list_entry(pos->next, struct fib_rule, list);
+                       if (rule->pref)
+                               return rule->pref - 1;
+               }
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(fib_default_rule_pref);
+
 static void notify_rule_change(int event, struct fib_rule *rule,
                               struct fib_rules_ops *ops, struct nlmsghdr *nlh,
                               u32 pid);
@@ -108,7 +127,7 @@ fib_rules_register(struct fib_rules_ops *tmpl, struct net *net)
        struct fib_rules_ops *ops;
        int err;
 
-       ops = kmemdup(tmpl, sizeof (*ops), GFP_KERNEL);
+       ops = kmemdup(tmpl, sizeof(*ops), GFP_KERNEL);
        if (ops == NULL)
                return ERR_PTR(-ENOMEM);
 
@@ -123,7 +142,6 @@ fib_rules_register(struct fib_rules_ops *tmpl, struct net *net)
 
        return ops;
 }
-
 EXPORT_SYMBOL_GPL(fib_rules_register);
 
 void fib_rules_cleanup_ops(struct fib_rules_ops *ops)
@@ -157,7 +175,6 @@ void fib_rules_unregister(struct fib_rules_ops *ops)
 
        call_rcu(&ops->rcu, fib_rules_put_rcu);
 }
-
 EXPORT_SYMBOL_GPL(fib_rules_unregister);
 
 static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
@@ -220,7 +237,6 @@ out:
 
        return err;
 }
-
 EXPORT_SYMBOL_GPL(fib_rules_lookup);
 
 static int validate_rulemsg(struct fib_rule_hdr *frh, struct nlattr **tb,
@@ -613,7 +629,7 @@ static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
                        break;
 
                cb->args[1] = 0;
-       skip:
+skip:
                idx++;
        }
        rcu_read_unlock();
@@ -685,7 +701,6 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event,
        struct fib_rules_ops *ops;
 
        ASSERT_RTNL();
-       rcu_read_lock();
 
        switch (event) {
        case NETDEV_REGISTER:
@@ -699,8 +714,6 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event,
                break;
        }
 
-       rcu_read_unlock();
-
        return NOTIFY_DONE;
 }