gss_krb5: add remaining pieces to enable AES encryption support
[safe/jmp/linux-2.6] / net / ipv4 / fib_hash.c
index 648f47c..4ed7e0d 100644 (file)
@@ -5,8 +5,6 @@
  *
  *             IPv4 FIB: lookup engine and maintenance routines.
  *
- * Version:    $Id: fib_hash.c,v 1.13 2001/10/31 21:55:54 davem Exp $
- *
  * Authors:    Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  *
  *             This program is free software; you can redistribute it and/or
@@ -20,7 +18,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>
@@ -35,7 +32,9 @@
 #include <linux/skbuff.h>
 #include <linux/netlink.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <net/route.h>
@@ -52,6 +51,7 @@ struct fib_node {
        struct hlist_node       fn_hash;
        struct list_head        fn_alias;
        __be32                  fn_key;
+       struct fib_alias        fn_embedded_alias;
 };
 
 struct fn_zone {
@@ -102,10 +102,10 @@ static struct hlist_head *fz_hash_alloc(int divisor)
        unsigned long size = divisor * sizeof(struct hlist_head);
 
        if (size <= PAGE_SIZE) {
-               return kmalloc(size, GFP_KERNEL);
+               return kzalloc(size, GFP_KERNEL);
        } else {
                return (struct hlist_head *)
-                       __get_free_pages(GFP_KERNEL, get_order(size));
+                       __get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(size));
        }
 }
 
@@ -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) {
@@ -168,14 +168,13 @@ static void fn_rehash_zone(struct fn_zone *fz)
        new_hashmask = (new_divisor - 1);
 
 #if RT_CACHE_DEBUG >= 2
-       printk("fn_rehash_zone: hash for zone %d grows from %d\n", fz->fz_order, old_divisor);
+       printk(KERN_DEBUG "fn_rehash_zone: hash for zone %d grows from %d\n",
+              fz->fz_order, old_divisor);
 #endif
 
        ht = fz_hash_alloc(new_divisor);
 
        if (ht) {
-               memset(ht, 0, new_divisor * sizeof(struct hlist_head));
-
                write_lock_bh(&fib_hash_lock);
                old_ht = fz->fz_hash;
                fz->fz_hash = ht;
@@ -194,10 +193,13 @@ static inline void fn_free_node(struct fib_node * f)
        kmem_cache_free(fn_hash_kmem, f);
 }
 
-static inline void fn_free_alias(struct fib_alias *fa)
+static inline void fn_free_alias(struct fib_alias *fa, struct fib_node *f)
 {
        fib_release_info(fa->fa_info);
-       kmem_cache_free(fn_alias_kmem, fa);
+       if (fa == &f->fn_embedded_alias)
+               fa->fa_info = NULL;
+       else
+               kmem_cache_free(fn_alias_kmem, fa);
 }
 
 static struct fn_zone *
@@ -219,7 +221,6 @@ fn_new_zone(struct fn_hash *table, int z)
                kfree(fz);
                return NULL;
        }
-       memset(fz->fz_hash, 0, fz->fz_divisor * sizeof(struct hlist_head *));
        fz->fz_order = z;
        fz->fz_mask = inet_make_mask(z);
 
@@ -242,12 +243,12 @@ fn_new_zone(struct fn_hash *table, int z)
        return fz;
 }
 
-static int
-fn_hash_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result *res)
+int fib_table_lookup(struct fib_table *tb,
+                    const struct flowi *flp, struct fib_result *res)
 {
        int err;
        struct fn_zone *fz;
-       struct fn_hash *t = (struct fn_hash*)tb->tb_data;
+       struct fn_hash *t = (struct fn_hash *)tb->tb_data;
 
        read_lock(&fib_hash_lock);
        for (fz = t->fn_zone_list; fz; fz = fz->fz_next) {
@@ -263,7 +264,6 @@ fn_hash_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result
 
                        err = fib_semantic_match(&f->fn_alias,
                                                 flp, res,
-                                                f->fn_key, fz->fz_mask,
                                                 fz->fz_order);
                        if (err <= 0)
                                goto out;
@@ -275,17 +275,15 @@ out:
        return err;
 }
 
-static int fn_hash_last_dflt=-1;
-
-static void
-fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib_result *res)
+void fib_table_select_default(struct fib_table *tb,
+                             const struct flowi *flp, struct fib_result *res)
 {
        int order, last_idx;
        struct hlist_node *node;
        struct fib_node *f;
        struct fib_info *fi = NULL;
        struct fib_info *last_resort;
-       struct fn_hash *t = (struct fn_hash*)tb->tb_data;
+       struct fn_hash *t = (struct fn_hash *)tb->tb_data;
        struct fn_zone *fz = t->fn_zones[0];
 
        if (fz == NULL)
@@ -317,12 +315,9 @@ fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
                                if (next_fi != res->fi)
                                        break;
                        } else if (!fib_detect_death(fi, order, &last_resort,
-                                                    &last_idx, &fn_hash_last_dflt)) {
-                               if (res->fi)
-                                       fib_info_put(res->fi);
-                               res->fi = fi;
-                               atomic_inc(&fi->fib_clntref);
-                               fn_hash_last_dflt = order;
+                                               &last_idx, tb->tb_default)) {
+                               fib_result_assign(res, fi);
+                               tb->tb_default = order;
                                goto out;
                        }
                        fi = next_fi;
@@ -331,27 +326,20 @@ fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
        }
 
        if (order <= 0 || fi == NULL) {
-               fn_hash_last_dflt = -1;
+               tb->tb_default = -1;
                goto out;
        }
 
-       if (!fib_detect_death(fi, order, &last_resort, &last_idx, &fn_hash_last_dflt)) {
-               if (res->fi)
-                       fib_info_put(res->fi);
-               res->fi = fi;
-               atomic_inc(&fi->fib_clntref);
-               fn_hash_last_dflt = order;
+       if (!fib_detect_death(fi, order, &last_resort, &last_idx,
+                               tb->tb_default)) {
+               fib_result_assign(res, fi);
+               tb->tb_default = order;
                goto out;
        }
 
-       if (last_idx >= 0) {
-               if (res->fi)
-                       fib_info_put(res->fi);
-               res->fi = last_resort;
-               if (last_resort)
-                       atomic_inc(&last_resort->fib_clntref);
-       }
-       fn_hash_last_dflt = last_idx;
+       if (last_idx >= 0)
+               fib_result_assign(res, last_resort);
+       tb->tb_default = last_idx;
 out:
        read_unlock(&fib_hash_lock);
 }
@@ -379,10 +367,11 @@ static struct fib_node *fib_find_node(struct fn_zone *fz, __be32 key)
        return NULL;
 }
 
-static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
+int fib_table_insert(struct fib_table *tb, struct fib_config *cfg)
 {
        struct fn_hash *table = (struct fn_hash *) tb->tb_data;
-       struct fib_node *new_f, *f;
+       struct fib_node *new_f = NULL;
+       struct fib_node *f;
        struct fib_alias *fa, *new_fa;
        struct fn_zone *fz;
        struct fib_info *fi;
@@ -434,16 +423,43 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
 
        if (fa && fa->fa_tos == tos &&
            fa->fa_info->fib_priority == fi->fib_priority) {
-               struct fib_alias *fa_orig;
+               struct fib_alias *fa_first, *fa_match;
 
                err = -EEXIST;
                if (cfg->fc_nlflags & NLM_F_EXCL)
                        goto out;
 
+               /* We have 2 goals:
+                * 1. Find exact match for type, scope, fib_info to avoid
+                * duplicate routes
+                * 2. Find next 'fa' (or head), NLM_F_APPEND inserts before it
+                */
+               fa_match = NULL;
+               fa_first = fa;
+               fa = list_entry(fa->fa_list.prev, struct fib_alias, fa_list);
+               list_for_each_entry_continue(fa, &f->fn_alias, fa_list) {
+                       if (fa->fa_tos != tos)
+                               break;
+                       if (fa->fa_info->fib_priority != fi->fib_priority)
+                               break;
+                       if (fa->fa_type == cfg->fc_type &&
+                           fa->fa_scope == cfg->fc_scope &&
+                           fa->fa_info == fi) {
+                               fa_match = fa;
+                               break;
+                       }
+               }
+
                if (cfg->fc_nlflags & NLM_F_REPLACE) {
                        struct fib_info *fi_drop;
                        u8 state;
 
+                       fa = fa_first;
+                       if (fa_match) {
+                               if (fa == fa_match)
+                                       err = 0;
+                               goto out;
+                       }
                        write_lock_bh(&fib_hash_lock);
                        fi_drop = fa->fa_info;
                        fa->fa_info = fi;
@@ -456,7 +472,9 @@ 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);
+                               rt_cache_flush(cfg->fc_nlinfo.nl_net, -1);
+                       rtmsg_fib(RTM_NEWROUTE, key, fa, cfg->fc_dst_len, tb->tb_id,
+                                 &cfg->fc_nlinfo, NLM_F_REPLACE);
                        return 0;
                }
 
@@ -464,20 +482,11 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
                 * uses the same scope, type, and nexthop
                 * information.
                 */
-               fa_orig = fa;
-               fa = list_entry(fa->fa_list.prev, struct fib_alias, fa_list);
-               list_for_each_entry_continue(fa, &f->fn_alias, fa_list) {
-                       if (fa->fa_tos != tos)
-                               break;
-                       if (fa->fa_info->fib_priority != fi->fib_priority)
-                               break;
-                       if (fa->fa_type == cfg->fc_type &&
-                           fa->fa_scope == cfg->fc_scope &&
-                           fa->fa_info == fi)
-                               goto out;
-               }
+               if (fa_match)
+                       goto out;
+
                if (!(cfg->fc_nlflags & NLM_F_APPEND))
-                       fa = fa_orig;
+                       fa = fa_first;
        }
 
        err = -ENOENT;
@@ -485,15 +494,11 @@ 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, GFP_KERNEL);
-       if (new_fa == NULL)
-               goto out;
 
-       new_f = NULL;
        if (!f) {
-               new_f = kmem_cache_alloc(fn_hash_kmem, GFP_KERNEL);
+               new_f = kmem_cache_zalloc(fn_hash_kmem, GFP_KERNEL);
                if (new_f == NULL)
-                       goto out_free_new_fa;
+                       goto out;
 
                INIT_HLIST_NODE(&new_f->fn_hash);
                INIT_LIST_HEAD(&new_f->fn_alias);
@@ -501,6 +506,12 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
                f = new_f;
        }
 
+       new_fa = &f->fn_embedded_alias;
+       if (new_fa->fa_info != NULL) {
+               new_fa = kmem_cache_alloc(fn_alias_kmem, GFP_KERNEL);
+               if (new_fa == NULL)
+                       goto out;
+       }
        new_fa->fa_info = fi;
        new_fa->fa_tos = tos;
        new_fa->fa_type = cfg->fc_type;
@@ -521,23 +532,22 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
 
        if (new_f)
                fz->fz_nent++;
-       rt_cache_flush(-1);
+       rt_cache_flush(cfg->fc_nlinfo.nl_net, -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:
-       kmem_cache_free(fn_alias_kmem, new_fa);
 out:
+       if (new_f)
+               kmem_cache_free(fn_hash_kmem, new_f);
        fib_release_info(fi);
        return err;
 }
 
-
-static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
+int fib_table_delete(struct fib_table *tb, struct fib_config *cfg)
 {
-       struct fn_hash *table = (struct fn_hash*)tb->tb_data;
+       struct fn_hash *table = (struct fn_hash *)tb->tb_data;
        struct fib_node *f;
        struct fib_alias *fa, *fa_to_delete;
        struct fn_zone *fz;
@@ -590,7 +600,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);
@@ -603,8 +613,8 @@ static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
                write_unlock_bh(&fib_hash_lock);
 
                if (fa->fa_state & FA_S_ACCESSED)
-                       rt_cache_flush(-1);
-               fn_free_alias(fa);
+                       rt_cache_flush(cfg->fc_nlinfo.nl_net, -1);
+               fn_free_alias(fa, f);
                if (kill_fn) {
                        fn_free_node(f);
                        fz->fz_nent--;
@@ -640,7 +650,7 @@ static int fn_flush_list(struct fn_zone *fz, int idx)
                                fib_hash_genid++;
                                write_unlock_bh(&fib_hash_lock);
 
-                               fn_free_alias(fa);
+                               fn_free_alias(fa, f);
                                found++;
                        }
                }
@@ -652,7 +662,7 @@ static int fn_flush_list(struct fn_zone *fz, int idx)
        return found;
 }
 
-static int fn_hash_flush(struct fib_table *tb)
+int fib_table_flush(struct fib_table *tb)
 {
        struct fn_hash *table = (struct fn_hash *) tb->tb_data;
        struct fn_zone *fz;
@@ -716,67 +726,60 @@ fn_hash_dump_zone(struct sk_buff *skb, struct netlink_callback *cb,
 {
        int h, s_h;
 
+       if (fz->fz_hash == NULL)
+               return skb->len;
        s_h = cb->args[3];
-       for (h=0; h < fz->fz_divisor; h++) {
-               if (h < s_h) continue;
-               if (h > s_h)
-                       memset(&cb->args[4], 0,
-                              sizeof(cb->args) - 4*sizeof(cb->args[0]));
-               if (fz->fz_hash == NULL ||
-                   hlist_empty(&fz->fz_hash[h]))
+       for (h = s_h; h < fz->fz_divisor; h++) {
+               if (hlist_empty(&fz->fz_hash[h]))
                        continue;
-               if (fn_hash_dump_bucket(skb, cb, tb, fz, &fz->fz_hash[h])<0) {
+               if (fn_hash_dump_bucket(skb, cb, tb, fz, &fz->fz_hash[h]) < 0) {
                        cb->args[3] = h;
                        return -1;
                }
+               memset(&cb->args[4], 0,
+                      sizeof(cb->args) - 4*sizeof(cb->args[0]));
        }
        cb->args[3] = h;
        return skb->len;
 }
 
-static int fn_hash_dump(struct fib_table *tb, struct sk_buff *skb, struct netlink_callback *cb)
+int fib_table_dump(struct fib_table *tb, struct sk_buff *skb,
+                  struct netlink_callback *cb)
 {
        int m, s_m;
        struct fn_zone *fz;
-       struct fn_hash *table = (struct fn_hash*)tb->tb_data;
+       struct fn_hash *table = (struct fn_hash *)tb->tb_data;
 
        s_m = cb->args[2];
        read_lock(&fib_hash_lock);
        for (fz = table->fn_zone_list, m=0; fz; fz = fz->fz_next, m++) {
                if (m < s_m) continue;
-               if (m > s_m)
-                       memset(&cb->args[3], 0,
-                              sizeof(cb->args) - 3*sizeof(cb->args[0]));
                if (fn_hash_dump_zone(skb, cb, tb, fz) < 0) {
                        cb->args[2] = m;
                        read_unlock(&fib_hash_lock);
                        return -1;
                }
+               memset(&cb->args[3], 0,
+                      sizeof(cb->args) - 3*sizeof(cb->args[0]));
        }
        read_unlock(&fib_hash_lock);
        cb->args[2] = m;
        return skb->len;
 }
 
-#ifdef CONFIG_IP_MULTIPLE_TABLES
-struct fib_table * fib_hash_init(u32 id)
-#else
-struct fib_table * __init fib_hash_init(u32 id)
-#endif
+void __init fib_hash_init(void)
 {
-       struct fib_table *tb;
+       fn_hash_kmem = kmem_cache_create("ip_fib_hash", sizeof(struct fib_node),
+                                        0, SLAB_PANIC, NULL);
 
-       if (fn_hash_kmem == NULL)
-               fn_hash_kmem = kmem_cache_create("ip_fib_hash",
-                                                sizeof(struct fib_node),
-                                                0, SLAB_HWCACHE_ALIGN,
-                                                NULL, NULL);
+       fn_alias_kmem = kmem_cache_create("ip_fib_alias", sizeof(struct fib_alias),
+                                         0, SLAB_PANIC, 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);
+}
+
+struct fib_table *fib_hash_table(u32 id)
+{
+       struct fib_table *tb;
 
        tb = kmalloc(sizeof(struct fib_table) + sizeof(struct fn_hash),
                     GFP_KERNEL);
@@ -784,12 +787,8 @@ struct fib_table * __init fib_hash_init(u32 id)
                return NULL;
 
        tb->tb_id = id;
-       tb->tb_lookup = fn_hash_lookup;
-       tb->tb_insert = fn_hash_insert;
-       tb->tb_delete = fn_hash_delete;
-       tb->tb_flush = fn_hash_flush;
-       tb->tb_select_default = fn_hash_select_default;
-       tb->tb_dump = fn_hash_dump;
+       tb->tb_default = -1;
+
        memset(tb->tb_data, 0, sizeof(struct fn_hash));
        return tb;
 }
@@ -798,6 +797,7 @@ struct fib_table * __init fib_hash_init(u32 id)
 #ifdef CONFIG_PROC_FS
 
 struct fib_iter_state {
+       struct seq_net_private p;
        struct fn_zone  *zone;
        int             bucket;
        struct hlist_head *hash_head;
@@ -811,7 +811,11 @@ struct fib_iter_state {
 static struct fib_alias *fib_get_first(struct seq_file *seq)
 {
        struct fib_iter_state *iter = seq->private;
-       struct fn_hash *table = (struct fn_hash *) ip_fib_main_table->tb_data;
+       struct fib_table *main_table;
+       struct fn_hash *table;
+
+       main_table = fib_get_table(seq_file_net(seq), RT_TABLE_MAIN);
+       table = (struct fn_hash *)main_table->tb_data;
 
        iter->bucket    = 0;
        iter->hash_head = NULL;
@@ -836,10 +840,10 @@ static struct fib_alias *fib_get_first(struct seq_file *seq)
                        struct hlist_node *node;
                        struct fib_node *fn;
 
-                       hlist_for_each_entry(fn,node,iter->hash_head,fn_hash) {
+                       hlist_for_each_entry(fn, node, iter->hash_head, fn_hash) {
                                struct fib_alias *fa;
 
-                               list_for_each_entry(fa,&fn->fn_alias,fa_list) {
+                               list_for_each_entry(fa, &fn->fn_alias, fa_list) {
                                        iter->fn = fn;
                                        iter->fa = fa;
                                        goto out;
@@ -911,7 +915,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 +936,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;
@@ -946,11 +950,12 @@ static struct fib_alias *fib_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 static void *fib_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(fib_hash_lock)
 {
        void *v = NULL;
 
        read_lock(&fib_hash_lock);
-       if (ip_fib_main_table)
+       if (fib_get_table(seq_file_net(seq), RT_TABLE_MAIN))
                v = *pos ? fib_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
        return v;
 }
@@ -962,6 +967,7 @@ static void *fib_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void fib_seq_stop(struct seq_file *seq, void *v)
+       __releases(fib_hash_lock)
 {
        read_unlock(&fib_hash_lock);
 }
@@ -981,7 +987,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
        return flags;
 }
 
-/* 
+/*
  *     This outputs /proc/net/route.
  *
  *     It always works in backward compatibility mode.
@@ -990,7 +996,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
 static int fib_seq_show(struct seq_file *seq, void *v)
 {
        struct fib_iter_state *iter;
-       char bf[128];
+       int len;
        __be32 prefix, mask;
        unsigned flags;
        struct fib_node *f;
@@ -1012,23 +1018,24 @@ static int fib_seq_show(struct seq_file *seq, void *v)
        mask    = FZ_MASK(iter->zone);
        flags   = fib_flag_trans(fa->fa_type, mask, fi);
        if (fi)
-               snprintf(bf, sizeof(bf),
-                        "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
+               seq_printf(seq,
+                        "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
                         fi->fib_dev ? fi->fib_dev->name : "*", prefix,
                         fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority,
                         mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0),
                         fi->fib_window,
-                        fi->fib_rtt >> 3);
+                        fi->fib_rtt >> 3, &len);
        else
-               snprintf(bf, sizeof(bf),
-                        "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
-                        prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0);
-       seq_printf(seq, "%-127s\n", bf);
+               seq_printf(seq,
+                        "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
+                        prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0, &len);
+
+       seq_printf(seq, "%*s\n", 127 - len, "");
 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,43 +1044,27 @@ 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_net(inode, 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,
        .llseek         = seq_lseek,
-       .release        = seq_release_private,
+       .release        = seq_release_net,
 };
 
-int __init fib_proc_init(void)
+int __net_init fib_proc_init(struct net *net)
 {
-       if (!proc_net_fops_create("route", S_IRUGO, &fib_seq_fops))
+       if (!proc_net_fops_create(net, "route", S_IRUGO, &fib_seq_fops))
                return -ENOMEM;
        return 0;
 }
 
-void __init fib_proc_exit(void)
+void __net_exit fib_proc_exit(struct net *net)
 {
-       proc_net_remove("route");
+       proc_net_remove(net, "route");
 }
 #endif /* CONFIG_PROC_FS */