]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv4/fib_hash.c
Merge branch 'master' into upstream-fixes
[linux-2.6-omap-h63xx.git] / net / ipv4 / fib_hash.c
index 88133b383dc586cc95ee0c482cc019f8db4730b4..527a6e0af5b60eb48b9e15459e8877db10c29db8 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/string.h>
 #include <linux/socket.h>
@@ -36,6 +35,7 @@
 #include <linux/netlink.h>
 #include <linux/init.h>
 
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <net/route.h>
 
 #include "fib_lookup.h"
 
-static kmem_cache_t *fn_hash_kmem __read_mostly;
-static kmem_cache_t *fn_alias_kmem __read_mostly;
+static struct kmem_cache *fn_hash_kmem __read_mostly;
+static struct kmem_cache *fn_alias_kmem __read_mostly;
 
 struct fib_node {
        struct hlist_node       fn_hash;
        struct list_head        fn_alias;
-       u32                     fn_key;
+       __be32                  fn_key;
 };
 
 struct fn_zone {
@@ -64,7 +64,7 @@ struct fn_zone {
 #define FZ_HASHMASK(fz)                ((fz)->fz_hashmask)
 
        int                     fz_order;       /* Zone order           */
-       u32                     fz_mask;
+       __be32                  fz_mask;
 #define FZ_MASK(fz)            ((fz)->fz_mask)
 };
 
@@ -77,7 +77,7 @@ struct fn_hash {
        struct fn_zone  *fn_zone_list;
 };
 
-static inline u32 fn_hash(u32 key, struct fn_zone *fz)
+static inline u32 fn_hash(__be32 key, struct fn_zone *fz)
 {
        u32 h = ntohl(key)>>(32 - fz->fz_order);
        h ^= (h>>20);
@@ -87,7 +87,7 @@ static inline u32 fn_hash(u32 key, struct fn_zone *fz)
        return h;
 }
 
-static inline u32 fz_key(u32 dst, struct fn_zone *fz)
+static inline __be32 fz_key(__be32 dst, struct fn_zone *fz)
 {
        return dst & FZ_MASK(fz);
 }
@@ -146,7 +146,7 @@ static void fn_rehash_zone(struct fn_zone *fz)
        struct hlist_head *ht, *old_ht;
        int old_divisor, new_divisor;
        u32 new_hashmask;
-               
+
        old_divisor = fz->fz_divisor;
 
        switch (old_divisor) {
@@ -254,7 +254,7 @@ fn_hash_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result
                struct hlist_head *head;
                struct hlist_node *node;
                struct fib_node *f;
-               u32 k = fz_key(flp->fl4_dst, fz);
+               __be32 k = fz_key(flp->fl4_dst, fz);
 
                head = &fz->fz_hash[fn_hash(k, fz)];
                hlist_for_each_entry(f, node, head, fn_hash) {
@@ -365,7 +365,7 @@ static inline void fib_insert_node(struct fn_zone *fz, struct fib_node *f)
 }
 
 /* Return the node in FZ matching KEY. */
-static struct fib_node *fib_find_node(struct fn_zone *fz, u32 key)
+static struct fib_node *fib_find_node(struct fn_zone *fz, __be32 key)
 {
        struct hlist_head *head = &fz->fz_hash[fn_hash(key, fz)];
        struct hlist_node *node;
@@ -387,7 +387,7 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
        struct fn_zone *fz;
        struct fib_info *fi;
        u8 tos = cfg->fc_tos;
-       u32 key;
+       __be32 key;
        int err;
 
        if (cfg->fc_dst_len > 32)
@@ -457,6 +457,8 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
                        fib_release_info(fi_drop);
                        if (state & FA_S_ACCESSED)
                                rt_cache_flush(-1);
+                       rtmsg_fib(RTM_NEWROUTE, key, fa, cfg->fc_dst_len, tb->tb_id,
+                                 &cfg->fc_nlinfo, NLM_F_REPLACE);
                        return 0;
                }
 
@@ -485,13 +487,13 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
                goto out;
 
        err = -ENOBUFS;
-       new_fa = kmem_cache_alloc(fn_alias_kmem, SLAB_KERNEL);
+       new_fa = kmem_cache_alloc(fn_alias_kmem, GFP_KERNEL);
        if (new_fa == NULL)
                goto out;
 
        new_f = NULL;
        if (!f) {
-               new_f = kmem_cache_alloc(fn_hash_kmem, SLAB_KERNEL);
+               new_f = kmem_cache_alloc(fn_hash_kmem, GFP_KERNEL);
                if (new_f == NULL)
                        goto out_free_new_fa;
 
@@ -524,7 +526,7 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
        rt_cache_flush(-1);
 
        rtmsg_fib(RTM_NEWROUTE, key, new_fa, cfg->fc_dst_len, tb->tb_id,
-                 &cfg->fc_nlinfo);
+                 &cfg->fc_nlinfo, 0);
        return 0;
 
 out_free_new_fa:
@@ -541,7 +543,7 @@ static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
        struct fib_node *f;
        struct fib_alias *fa, *fa_to_delete;
        struct fn_zone *fz;
-       u32 key;
+       __be32 key;
 
        if (cfg->fc_dst_len > 32)
                return -EINVAL;
@@ -590,7 +592,7 @@ static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
 
                fa = fa_to_delete;
                rtmsg_fib(RTM_DELROUTE, key, fa, cfg->fc_dst_len,
-                         tb->tb_id, &cfg->fc_nlinfo);
+                         tb->tb_id, &cfg->fc_nlinfo, 0);
 
                kill_fn = 0;
                write_lock_bh(&fib_hash_lock);
@@ -770,13 +772,13 @@ struct fib_table * __init fib_hash_init(u32 id)
                fn_hash_kmem = kmem_cache_create("ip_fib_hash",
                                                 sizeof(struct fib_node),
                                                 0, SLAB_HWCACHE_ALIGN,
-                                                NULL, NULL);
+                                                NULL);
 
        if (fn_alias_kmem == NULL)
                fn_alias_kmem = kmem_cache_create("ip_fib_alias",
                                                  sizeof(struct fib_alias),
                                                  0, SLAB_HWCACHE_ALIGN,
-                                                 NULL, NULL);
+                                                 NULL);
 
        tb = kmalloc(sizeof(struct fib_table) + sizeof(struct fn_hash),
                     GFP_KERNEL);
@@ -911,7 +913,7 @@ static struct fib_alias *fib_get_next(struct seq_file *seq)
 
                if (!iter->zone)
                        goto out;
-               
+
                iter->bucket = 0;
                iter->hash_head = iter->zone->fz_hash;
 
@@ -932,7 +934,7 @@ static struct fib_alias *fib_get_idx(struct seq_file *seq, loff_t pos)
 {
        struct fib_iter_state *iter = seq->private;
        struct fib_alias *fa;
-       
+
        if (iter->valid && pos >= iter->pos && iter->genid == fib_hash_genid) {
                fa   = iter->fa;
                pos -= iter->pos;
@@ -966,7 +968,7 @@ static void fib_seq_stop(struct seq_file *seq, void *v)
        read_unlock(&fib_hash_lock);
 }
 
-static unsigned fib_flag_trans(int type, u32 mask, struct fib_info *fi)
+static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
 {
        static const unsigned type2flags[RTN_MAX + 1] = {
                [7] = RTF_REJECT, [8] = RTF_REJECT,
@@ -975,13 +977,13 @@ static unsigned fib_flag_trans(int type, u32 mask, struct fib_info *fi)
 
        if (fi && fi->fib_nh->nh_gw)
                flags |= RTF_GATEWAY;
-       if (mask == 0xFFFFFFFF)
+       if (mask == htonl(0xFFFFFFFF))
                flags |= RTF_HOST;
        flags |= RTF_UP;
        return flags;
 }
 
-/* 
+/*
  *     This outputs /proc/net/route.
  *
  *     It always works in backward compatibility mode.
@@ -991,7 +993,7 @@ static int fib_seq_show(struct seq_file *seq, void *v)
 {
        struct fib_iter_state *iter;
        char bf[128];
-       u32 prefix, mask;
+       __be32 prefix, mask;
        unsigned flags;
        struct fib_node *f;
        struct fib_alias *fa;
@@ -1028,7 +1030,7 @@ out:
        return 0;
 }
 
-static struct seq_operations fib_seq_ops = {
+static const struct seq_operations fib_seq_ops = {
        .start  = fib_seq_start,
        .next   = fib_seq_next,
        .stop   = fib_seq_stop,
@@ -1037,27 +1039,11 @@ static struct seq_operations fib_seq_ops = {
 
 static int fib_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct fib_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
-       
-       if (!s)
-               goto out;
-
-       rc = seq_open(file, &fib_seq_ops);
-       if (rc)
-               goto out_kfree;
-
-       seq          = file->private_data;
-       seq->private = s;
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
+       return seq_open_private(file, &fib_seq_ops,
+                       sizeof(struct fib_iter_state));
 }
 
-static struct file_operations fib_seq_fops = {
+static const struct file_operations fib_seq_fops = {
        .owner          = THIS_MODULE,
        .open           = fib_seq_open,
        .read           = seq_read,
@@ -1067,13 +1053,13 @@ static struct file_operations fib_seq_fops = {
 
 int __init fib_proc_init(void)
 {
-       if (!proc_net_fops_create("route", S_IRUGO, &fib_seq_fops))
+       if (!proc_net_fops_create(&init_net, "route", S_IRUGO, &fib_seq_fops))
                return -ENOMEM;
        return 0;
 }
 
 void __init fib_proc_exit(void)
 {
-       proc_net_remove("route");
+       proc_net_remove(&init_net, "route");
 }
 #endif /* CONFIG_PROC_FS */