2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * IPv4 FIB: lookup engine and maintenance routines.
8 * Version: $Id: fib_hash.c,v 1.1.1.1 2005/04/29 01:44:08 echo Exp $
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
18 #include <linux/config.h>
19 #include <asm/uaccess.h>
20 #include <asm/system.h>
21 #include <asm/bitops.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
26 #include <linux/string.h>
27 #include <linux/socket.h>
28 #include <linux/sockios.h>
29 #include <linux/errno.h>
31 #include <linux/inet.h>
32 #include <linux/netdevice.h>
33 #include <linux/if_arp.h>
34 #include <linux/proc_fs.h>
35 #include <linux/skbuff.h>
36 #include <linux/netlink.h>
37 #include <linux/init.h>
40 #include <net/protocol.h>
41 #include <net/route.h>
44 #include <net/ip_fib.h>
51 static kmem_cache_t * fn_hash_kmem;
54 These bizarre types are just to force strict type checking.
55 When I reversed order of bytes and changed to natural mask lengths,
56 I forgot to make fixes in several places. Now I am lazy to return
70 struct fib_node *fn_next;
71 struct fib_info *fn_info;
72 #define FIB_INFO(f) ((f)->fn_info)
81 #define FN_S_ACCESSED 2
83 static int fib_hash_zombies;
87 struct fn_zone *fz_next; /* Next not empty zone */
88 struct fib_node **fz_hash; /* Hash table pointer */
89 int fz_nent; /* Number of entries */
91 int fz_divisor; /* Hash divisor */
92 u32 fz_hashmask; /* (fz_divisor - 1) */
93 #define FZ_HASHMASK(fz) ((fz)->fz_hashmask)
95 int fz_order; /* Zone order */
97 #define FZ_MASK(fz) ((fz)->fz_mask)
100 /* NOTE. On fast computers evaluation of fz_hashmask and fz_mask
101 can be cheaper than memory lookup, so that FZ_* macros are used.
106 struct fn_zone *fn_zones[33];
107 struct fn_zone *fn_zone_list;
110 static __inline__ fn_hash_idx_t fn_hash(fn_key_t key, struct fn_zone *fz)
112 u32 h = ntohl(key.datum)>>(32 - fz->fz_order);
116 h &= FZ_HASHMASK(fz);
117 return *(fn_hash_idx_t*)&h;
120 #define fz_key_0(key) ((key).datum = 0)
121 #define fz_prefix(key,fz) ((key).datum)
123 static __inline__ fn_key_t fz_key(u32 dst, struct fn_zone *fz)
126 k.datum = dst & FZ_MASK(fz);
130 static __inline__ struct fib_node ** fz_chain_p(fn_key_t key, struct fn_zone *fz)
132 return &fz->fz_hash[fn_hash(key, fz).datum];
135 static __inline__ struct fib_node * fz_chain(fn_key_t key, struct fn_zone *fz)
137 return fz->fz_hash[fn_hash(key, fz).datum];
140 static __inline__ int fn_key_eq(fn_key_t a, fn_key_t b)
142 return a.datum == b.datum;
145 static __inline__ int fn_key_leq(fn_key_t a, fn_key_t b)
147 return a.datum <= b.datum;
150 static rwlock_t fib_hash_lock = RW_LOCK_UNLOCKED;
152 #define FZ_MAX_DIVISOR ((PAGE_SIZE<<MAX_ORDER) / sizeof(struct fib_node *))
154 static struct fib_node **fz_hash_alloc(int divisor)
156 unsigned long size = divisor * sizeof(struct fib_node *);
158 if (divisor <= 1024) {
159 return kmalloc(size, GFP_KERNEL);
161 return (struct fib_node **)
162 __get_free_pages(GFP_KERNEL, get_order(size));
166 /* The fib hash lock must be held when this is called. */
167 static __inline__ void fn_rebuild_zone(struct fn_zone *fz,
168 struct fib_node **old_ht,
172 struct fib_node *f, **fp, *next;
174 for (i=0; i<old_divisor; i++) {
175 for (f=old_ht[i]; f; f=next) {
177 for (fp = fz_chain_p(f->fn_key, fz);
178 *fp && fn_key_leq((*fp)->fn_key, f->fn_key);
179 fp = &(*fp)->fn_next)
187 static void fz_hash_free(struct fib_node **hash, int divisor)
192 free_pages((unsigned long) hash,
193 get_order(divisor * sizeof(struct fib_node *)));
196 static void fn_rehash_zone(struct fn_zone *fz)
198 struct fib_node **ht, **old_ht;
199 int old_divisor, new_divisor;
202 old_divisor = fz->fz_divisor;
204 switch (old_divisor) {
212 if ((old_divisor << 1) > FZ_MAX_DIVISOR) {
213 printk(KERN_CRIT "route.c: bad divisor %d!\n", old_divisor);
216 new_divisor = (old_divisor << 1);
220 new_hashmask = (new_divisor - 1);
222 #if RT_CACHE_DEBUG >= 2
223 printk("fn_rehash_zone: hash for zone %d grows from %d\n", fz->fz_order, old_divisor);
226 ht = fz_hash_alloc(new_divisor);
229 memset(ht, 0, new_divisor*sizeof(struct fib_node*));
231 write_lock_bh(&fib_hash_lock);
232 old_ht = fz->fz_hash;
234 fz->fz_hashmask = new_hashmask;
235 fz->fz_divisor = new_divisor;
236 fn_rebuild_zone(fz, old_ht, old_divisor);
237 write_unlock_bh(&fib_hash_lock);
239 fz_hash_free(old_ht, old_divisor);
243 static void fn_free_node(struct fib_node * f)
245 fib_release_info(FIB_INFO(f));
246 kmem_cache_free(fn_hash_kmem, f);
250 static struct fn_zone *
251 fn_new_zone(struct fn_hash *table, int z)
254 struct fn_zone *fz = kmalloc(sizeof(struct fn_zone), GFP_KERNEL);
259 memset(fz, 0, sizeof(struct fn_zone));
265 fz->fz_hashmask = (fz->fz_divisor - 1);
266 fz->fz_hash = fz_hash_alloc(fz->fz_divisor);
271 memset(fz->fz_hash, 0, fz->fz_divisor*sizeof(struct fib_node*));
273 fz->fz_mask = inet_make_mask(z);
275 /* Find the first not empty zone with more specific mask */
276 for (i=z+1; i<=32; i++)
277 if (table->fn_zones[i])
280 write_lock_bh(&fib_hash_lock);
282 /* No more specific masks, we are the first. */
283 fz->fz_next = table->fn_zone_list;
284 table->fn_zone_list = fz;
286 fz->fz_next = table->fn_zones[i]->fz_next;
287 table->fn_zones[i]->fz_next = fz;
289 table->fn_zones[z] = fz;
290 write_unlock_bh(&fib_hash_lock);
295 fn_hash_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result *res)
299 struct fn_hash *t = (struct fn_hash*)tb->tb_data;
301 read_lock(&fib_hash_lock);
302 for (fz = t->fn_zone_list; fz; fz = fz->fz_next) {
304 fn_key_t k = fz_key(flp->fl4_dst, fz);
306 for (f = fz_chain(k, fz); f; f = f->fn_next) {
307 if (!fn_key_eq(k, f->fn_key)) {
308 if (fn_key_leq(k, f->fn_key))
313 #ifdef CONFIG_IP_ROUTE_TOS
314 if (f->fn_tos && f->fn_tos != flp->fl4_tos)
317 f->fn_state |= FN_S_ACCESSED;
319 if (f->fn_state&FN_S_ZOMBIE)
321 if (f->fn_scope < flp->fl4_scope)
324 err = fib_semantic_match(f->fn_type, FIB_INFO(f), flp, res);
326 res->type = f->fn_type;
327 res->scope = f->fn_scope;
328 res->prefixlen = fz->fz_order;
337 read_unlock(&fib_hash_lock);
341 static int fn_hash_last_dflt=-1;
343 static int fib_detect_death(struct fib_info *fi, int order,
344 struct fib_info **last_resort, int *last_idx)
347 int state = NUD_NONE;
349 n = neigh_lookup(&arp_tbl, &fi->fib_nh[0].nh_gw, fi->fib_dev);
351 state = n->nud_state;
354 if (state==NUD_REACHABLE)
356 if ((state&NUD_VALID) && order != fn_hash_last_dflt)
358 if ((state&NUD_VALID) ||
359 (*last_idx<0 && order > fn_hash_last_dflt)) {
367 fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib_result *res)
371 struct fib_info *fi = NULL;
372 struct fib_info *last_resort;
373 struct fn_hash *t = (struct fn_hash*)tb->tb_data;
374 struct fn_zone *fz = t->fn_zones[0];
383 read_lock(&fib_hash_lock);
384 for (f = fz->fz_hash[0]; f; f = f->fn_next) {
385 struct fib_info *next_fi = FIB_INFO(f);
387 if ((f->fn_state&FN_S_ZOMBIE) ||
388 f->fn_scope != res->scope ||
389 f->fn_type != RTN_UNICAST)
392 if (next_fi->fib_priority > res->fi->fib_priority)
394 if (!next_fi->fib_nh[0].nh_gw || next_fi->fib_nh[0].nh_scope != RT_SCOPE_LINK)
396 f->fn_state |= FN_S_ACCESSED;
399 if (next_fi != res->fi)
401 } else if (!fib_detect_death(fi, order, &last_resort, &last_idx)) {
403 fib_info_put(res->fi);
405 atomic_inc(&fi->fib_clntref);
406 fn_hash_last_dflt = order;
413 if (order<=0 || fi==NULL) {
414 fn_hash_last_dflt = -1;
418 if (!fib_detect_death(fi, order, &last_resort, &last_idx)) {
420 fib_info_put(res->fi);
422 atomic_inc(&fi->fib_clntref);
423 fn_hash_last_dflt = order;
429 fib_info_put(res->fi);
430 res->fi = last_resort;
432 atomic_inc(&last_resort->fib_clntref);
434 fn_hash_last_dflt = last_idx;
436 read_unlock(&fib_hash_lock);
439 #define FIB_SCAN(f, fp) \
440 for ( ; ((f) = *(fp)) != NULL; (fp) = &(f)->fn_next)
442 #define FIB_SCAN_KEY(f, fp, key) \
443 for ( ; ((f) = *(fp)) != NULL && fn_key_eq((f)->fn_key, (key)); (fp) = &(f)->fn_next)
445 #ifndef CONFIG_IP_ROUTE_TOS
446 #define FIB_SCAN_TOS(f, fp, key, tos) FIB_SCAN_KEY(f, fp, key)
448 #define FIB_SCAN_TOS(f, fp, key, tos) \
449 for ( ; ((f) = *(fp)) != NULL && fn_key_eq((f)->fn_key, (key)) && \
450 (f)->fn_tos == (tos) ; (fp) = &(f)->fn_next)
454 static void rtmsg_fib(int, struct fib_node*, int, int,
456 struct netlink_skb_parms *);
459 fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
460 struct nlmsghdr *n, struct netlink_skb_parms *req)
462 struct fn_hash *table = (struct fn_hash*)tb->tb_data;
463 struct fib_node *new_f, *f, **fp, **del_fp;
467 int z = r->rtm_dst_len;
468 int type = r->rtm_type;
469 #ifdef CONFIG_IP_ROUTE_TOS
475 FTprint("tb(%d)_insert: %d %08x/%d %d %08x\n", tb->tb_id, r->rtm_type, rta->rta_dst ?
476 *(u32*)rta->rta_dst : 0, z, rta->rta_oif ? *rta->rta_oif : -1,
477 rta->rta_prefsrc ? *(u32*)rta->rta_prefsrc : 0);
481 fz = table->fn_zones[z];
482 if (!fz && !(fz = fn_new_zone(table, z)))
488 memcpy(&dst, rta->rta_dst, 4);
489 if (dst & ~FZ_MASK(fz))
491 key = fz_key(dst, fz);
494 if ((fi = fib_create_info(r, rta, n, &err)) == NULL)
497 if (fz->fz_nent > (fz->fz_divisor<<1) &&
498 fz->fz_divisor < FZ_MAX_DIVISOR &&
499 (z==32 || (1<<z) > fz->fz_divisor))
502 fp = fz_chain_p(key, fz);
506 * Scan list to find the first route with the same destination
509 if (fn_key_leq(key,f->fn_key))
513 #ifdef CONFIG_IP_ROUTE_TOS
515 * Find route with the same destination and tos.
517 FIB_SCAN_KEY(f, fp, key) {
518 if (f->fn_tos <= tos)
525 if (f && (f->fn_state&FN_S_ZOMBIE) &&
526 #ifdef CONFIG_IP_ROUTE_TOS
529 fn_key_eq(f->fn_key, key)) {
536 FIB_SCAN_TOS(f, fp, key, tos) {
537 if (fi->fib_priority <= FIB_INFO(f)->fib_priority)
541 /* Now f==*fp points to the first node with the same
542 keys [prefix,tos,priority], if such key already
543 exists or to the node, before which we will insert new one.
547 #ifdef CONFIG_IP_ROUTE_TOS
550 fn_key_eq(f->fn_key, key) &&
551 fi->fib_priority == FIB_INFO(f)->fib_priority) {
552 struct fib_node **ins_fp;
555 if (n->nlmsg_flags&NLM_F_EXCL)
558 if (n->nlmsg_flags&NLM_F_REPLACE) {
568 FIB_SCAN_TOS(f, fp, key, tos) {
569 if (fi->fib_priority != FIB_INFO(f)->fib_priority)
571 if (f->fn_type == type && f->fn_scope == r->rtm_scope
572 && FIB_INFO(f) == fi)
576 if (!(n->nlmsg_flags&NLM_F_APPEND)) {
584 if (!(n->nlmsg_flags&NLM_F_CREATE))
589 new_f = kmem_cache_alloc(fn_hash_kmem, SLAB_KERNEL);
593 memset(new_f, 0, sizeof(struct fib_node));
596 #ifdef CONFIG_IP_ROUTE_TOS
599 new_f->fn_type = type;
600 new_f->fn_scope = r->rtm_scope;
601 FIB_INFO(new_f) = fi;
604 * Insert new entry to the list.
608 write_lock_bh(&fib_hash_lock);
610 write_unlock_bh(&fib_hash_lock);
615 /* Unlink replaced node */
616 write_lock_bh(&fib_hash_lock);
617 *del_fp = f->fn_next;
618 write_unlock_bh(&fib_hash_lock);
620 if (!(f->fn_state&FN_S_ZOMBIE))
621 rtmsg_fib(RTM_DELROUTE, f, z, tb->tb_id, n, req);
622 if (f->fn_state&FN_S_ACCESSED)
629 rtmsg_fib(RTM_NEWROUTE, new_f, z, tb->tb_id, n, req);
633 fib_release_info(fi);
639 fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
640 struct nlmsghdr *n, struct netlink_skb_parms *req)
642 struct fn_hash *table = (struct fn_hash*)tb->tb_data;
643 struct fib_node **fp, **del_fp, *f;
644 int z = r->rtm_dst_len;
648 #ifdef CONFIG_IP_ROUTE_TOS
652 FTprint("tb(%d)_delete: %d %08x/%d %d\n", tb->tb_id, r->rtm_type, rta->rta_dst ?
653 *(u32*)rta->rta_dst : 0, z, rta->rta_oif ? *rta->rta_oif : -1);
657 if ((fz = table->fn_zones[z]) == NULL)
663 memcpy(&dst, rta->rta_dst, 4);
664 if (dst & ~FZ_MASK(fz))
666 key = fz_key(dst, fz);
669 fp = fz_chain_p(key, fz);
673 if (fn_key_eq(f->fn_key, key))
675 if (fn_key_leq(key, f->fn_key)) {
679 #ifdef CONFIG_IP_ROUTE_TOS
680 FIB_SCAN_KEY(f, fp, key) {
681 if (f->fn_tos == tos)
688 FIB_SCAN_TOS(f, fp, key, tos) {
689 struct fib_info * fi = FIB_INFO(f);
691 if (f->fn_state&FN_S_ZOMBIE) {
696 if (del_fp == NULL &&
697 (!r->rtm_type || f->fn_type == r->rtm_type) &&
698 (r->rtm_scope == RT_SCOPE_NOWHERE || f->fn_scope == r->rtm_scope) &&
699 (!r->rtm_protocol || fi->fib_protocol == r->rtm_protocol) &&
700 fib_nh_match(r, n, rta, fi) == 0)
706 rtmsg_fib(RTM_DELROUTE, f, z, tb->tb_id, n, req);
709 write_lock_bh(&fib_hash_lock);
710 *del_fp = f->fn_next;
711 write_unlock_bh(&fib_hash_lock);
713 if (f->fn_state&FN_S_ACCESSED)
718 f->fn_state |= FN_S_ZOMBIE;
719 if (f->fn_state&FN_S_ACCESSED) {
720 f->fn_state &= ~FN_S_ACCESSED;
723 if (++fib_hash_zombies > 128)
732 static __inline__ int
733 fn_flush_list(struct fib_node ** fp, int z, struct fn_hash *table)
738 while ((f = *fp) != NULL) {
739 struct fib_info *fi = FIB_INFO(f);
741 if (fi && ((f->fn_state&FN_S_ZOMBIE) || (fi->fib_flags&RTNH_F_DEAD))) {
742 write_lock_bh(&fib_hash_lock);
744 write_unlock_bh(&fib_hash_lock);
755 static int fn_hash_flush(struct fib_table *tb)
757 struct fn_hash *table = (struct fn_hash*)tb->tb_data;
761 fib_hash_zombies = 0;
762 for (fz = table->fn_zone_list; fz; fz = fz->fz_next) {
765 for (i=fz->fz_divisor-1; i>=0; i--)
766 tmp += fn_flush_list(&fz->fz_hash[i], fz->fz_order, table);
774 static __inline__ int
775 fn_hash_dump_bucket(struct sk_buff *skb, struct netlink_callback *cb,
776 struct fib_table *tb,
783 for (i=0; f; i++, f=f->fn_next) {
784 if (i < s_i) continue;
785 if (f->fn_state&FN_S_ZOMBIE) continue;
786 if (fib_dump_info(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
788 tb->tb_id, (f->fn_state&FN_S_ZOMBIE) ? 0 : f->fn_type, f->fn_scope,
789 &f->fn_key, fz->fz_order, f->fn_tos,
799 static __inline__ int
800 fn_hash_dump_zone(struct sk_buff *skb, struct netlink_callback *cb,
801 struct fib_table *tb,
807 for (h=0; h < fz->fz_divisor; h++) {
808 if (h < s_h) continue;
810 memset(&cb->args[3], 0, sizeof(cb->args) - 3*sizeof(cb->args[0]));
811 if (fz->fz_hash == NULL || fz->fz_hash[h] == NULL)
813 if (fn_hash_dump_bucket(skb, cb, tb, fz, fz->fz_hash[h]) < 0) {
822 static int fn_hash_dump(struct fib_table *tb, struct sk_buff *skb, struct netlink_callback *cb)
826 struct fn_hash *table = (struct fn_hash*)tb->tb_data;
829 read_lock(&fib_hash_lock);
830 for (fz = table->fn_zone_list, m=0; fz; fz = fz->fz_next, m++) {
831 if (m < s_m) continue;
833 memset(&cb->args[2], 0, sizeof(cb->args) - 2*sizeof(cb->args[0]));
834 if (fn_hash_dump_zone(skb, cb, tb, fz) < 0) {
836 read_unlock(&fib_hash_lock);
840 read_unlock(&fib_hash_lock);
845 static void rtmsg_fib(int event, struct fib_node* f, int z, int tb_id,
846 struct nlmsghdr *n, struct netlink_skb_parms *req)
849 u32 pid = req ? req->pid : 0;
850 int size = NLMSG_SPACE(sizeof(struct rtmsg)+256);
852 skb = alloc_skb(size, GFP_KERNEL);
856 if (fib_dump_info(skb, pid, n->nlmsg_seq, event, tb_id,
857 f->fn_type, f->fn_scope, &f->fn_key, z, f->fn_tos,
862 NETLINK_CB(skb).dst_groups = RTMGRP_IPV4_ROUTE;
863 if (n->nlmsg_flags&NLM_F_ECHO)
864 atomic_inc(&skb->users);
865 netlink_broadcast(rtnl, skb, pid, RTMGRP_IPV4_ROUTE, GFP_KERNEL);
866 if (n->nlmsg_flags&NLM_F_ECHO)
867 netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
870 #ifdef CONFIG_IP_MULTIPLE_TABLES
871 struct fib_table * fib_hash_init(int id)
873 struct fib_table * __init fib_hash_init(int id)
876 struct fib_table *tb;
878 if (fn_hash_kmem == NULL)
879 fn_hash_kmem = kmem_cache_create("ip_fib_hash",
880 sizeof(struct fib_node),
881 0, SLAB_HWCACHE_ALIGN,
884 tb = kmalloc(sizeof(struct fib_table) + sizeof(struct fn_hash), GFP_KERNEL);
889 tb->tb_lookup = fn_hash_lookup;
890 tb->tb_insert = fn_hash_insert;
891 tb->tb_delete = fn_hash_delete;
892 tb->tb_flush = fn_hash_flush;
893 tb->tb_select_default = fn_hash_select_default;
894 tb->tb_dump = fn_hash_dump;
895 memset(tb->tb_data, 0, sizeof(struct fn_hash));
899 /* ------------------------------------------------------------------------ */
900 #ifdef CONFIG_PROC_FS
902 struct fib_iter_state {
903 struct fn_zone *zone;
905 struct fib_node **hash;
906 struct fib_node *node;
909 static __inline__ struct fib_node *fib_get_first(struct seq_file *seq)
911 struct fib_iter_state* iter = seq->private;
912 struct fn_hash *table = (struct fn_hash *)ip_fib_main_table->tb_data;
918 for (iter->zone = table->fn_zone_list; iter->zone;
919 iter->zone = iter->zone->fz_next) {
922 if (!iter->zone->fz_next)
926 iter->hash = iter->zone->fz_hash;
927 maxslot = iter->zone->fz_divisor;
929 for (iter->bucket = 0; iter->bucket < maxslot;
930 ++iter->bucket, ++iter->hash) {
931 iter->node = *iter->hash;
940 static __inline__ struct fib_node *fib_get_next(struct seq_file *seq)
942 struct fib_iter_state* iter = seq->private;
945 iter->node = iter->node->fn_next;
956 maxslot = iter->zone->fz_divisor;
958 while (++iter->bucket < maxslot) {
959 iter->node = *++iter->hash;
965 iter->zone = iter->zone->fz_next;
970 iter->hash = iter->zone->fz_hash;
972 iter->node = *iter->hash;
980 static void *fib_seq_start(struct seq_file *seq, loff_t *pos)
984 read_lock(&fib_hash_lock);
985 if (ip_fib_main_table)
986 v = *pos ? fib_get_next(seq) : SEQ_START_TOKEN;
990 static void *fib_seq_next(struct seq_file *seq, void *v, loff_t *pos)
993 return v == SEQ_START_TOKEN ? fib_get_first(seq) : fib_get_next(seq);
996 static void fib_seq_stop(struct seq_file *seq, void *v)
998 read_unlock(&fib_hash_lock);
1001 static unsigned fib_flag_trans(int type, int dead, u32 mask, struct fib_info *fi)
1003 static unsigned type2flags[RTN_MAX + 1] = {
1004 [7] = RTF_REJECT, [8] = RTF_REJECT,
1006 unsigned flags = type2flags[type];
1008 if (fi && fi->fib_nh->nh_gw)
1009 flags |= RTF_GATEWAY;
1010 if (mask == 0xFFFFFFFF)
1018 * This outputs /proc/net/route.
1020 * It always works in backward compatibility mode.
1021 * The format of the file is not supposed to be changed.
1023 static int fib_seq_show(struct seq_file *seq, void *v)
1025 struct fib_iter_state* iter;
1030 struct fib_info *fi;
1032 if (v == SEQ_START_TOKEN) {
1033 seq_printf(seq, "%-127s\n", "Iface\tDestination\tGateway "
1034 "\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU"
1041 iter = seq->private;
1042 prefix = fz_prefix(f->fn_key, iter->zone);
1043 mask = FZ_MASK(iter->zone);
1044 flags = fib_flag_trans(f->fn_type, f->fn_state & FN_S_ZOMBIE,
1047 snprintf(bf, sizeof(bf),
1048 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
1049 fi->fib_dev ? fi->fib_dev->name : "*", prefix,
1050 fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority,
1051 mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0),
1055 snprintf(bf, sizeof(bf),
1056 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
1057 prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0);
1058 seq_printf(seq, "%-127s\n", bf);
1063 static struct seq_operations fib_seq_ops = {
1064 .start = fib_seq_start,
1065 .next = fib_seq_next,
1066 .stop = fib_seq_stop,
1067 .show = fib_seq_show,
1070 static int fib_seq_open(struct inode *inode, struct file *file)
1072 struct seq_file *seq;
1074 struct fib_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
1079 rc = seq_open(file, &fib_seq_ops);
1083 seq = file->private_data;
1085 memset(s, 0, sizeof(*s));
1093 static struct file_operations fib_seq_fops = {
1094 .owner = THIS_MODULE,
1095 .open = fib_seq_open,
1097 .llseek = seq_lseek,
1098 .release = seq_release_private,
1101 int __init fib_proc_init(void)
1103 if (!proc_net_fops_create("route", S_IRUGO, &fib_seq_fops))
1108 void __init fib_proc_exit(void)
1110 proc_net_remove("route");
1112 #endif /* CONFIG_PROC_FS */