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 Forwarding Information Base: FIB frontend.
8 * Version: $Id: fib_frontend.c,v 1.26 2001/10/31 21:55:54 davem 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/module.h>
19 #include <asm/uaccess.h>
20 #include <asm/system.h>
21 #include <linux/bitops.h>
22 #include <linux/capability.h>
23 #include <linux/types.h>
24 #include <linux/kernel.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/inetdevice.h>
33 #include <linux/netdevice.h>
34 #include <linux/if_addr.h>
35 #include <linux/if_arp.h>
36 #include <linux/skbuff.h>
37 #include <linux/init.h>
38 #include <linux/list.h>
41 #include <net/protocol.h>
42 #include <net/route.h>
47 #include <net/ip_fib.h>
48 #include <net/rtnetlink.h>
50 #define FFprint(a...) printk(KERN_DEBUG a)
52 static struct sock *fibnl;
53 struct hlist_head fib_table_hash[FIB_TABLE_HASHSZ];
55 #ifndef CONFIG_IP_MULTIPLE_TABLES
57 static int __net_init fib4_rules_init(struct net *net)
59 struct fib_table *local_table, *main_table;
61 local_table = fib_hash_init(RT_TABLE_LOCAL);
62 if (local_table == NULL)
65 main_table = fib_hash_init(RT_TABLE_MAIN);
66 if (main_table == NULL)
69 hlist_add_head_rcu(&local_table->tb_hlist,
70 &fib_table_hash[TABLE_LOCAL_INDEX]);
71 hlist_add_head_rcu(&main_table->tb_hlist,
72 &fib_table_hash[TABLE_MAIN_INDEX]);
81 struct fib_table *fib_new_table(u32 id)
88 tb = fib_get_table(id);
91 tb = fib_hash_init(id);
94 h = id & (FIB_TABLE_HASHSZ - 1);
95 hlist_add_head_rcu(&tb->tb_hlist, &fib_table_hash[h]);
99 struct fib_table *fib_get_table(u32 id)
101 struct fib_table *tb;
102 struct hlist_node *node;
107 h = id & (FIB_TABLE_HASHSZ - 1);
109 hlist_for_each_entry_rcu(tb, node, &fib_table_hash[h], tb_hlist) {
110 if (tb->tb_id == id) {
118 #endif /* CONFIG_IP_MULTIPLE_TABLES */
120 static void fib_flush(void)
123 struct fib_table *tb;
124 struct hlist_node *node;
127 for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
128 hlist_for_each_entry(tb, node, &fib_table_hash[h], tb_hlist)
129 flushed += tb->tb_flush(tb);
137 * Find the first device with a given source address.
140 struct net_device * ip_dev_find(__be32 addr)
142 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
143 struct fib_result res;
144 struct net_device *dev = NULL;
145 struct fib_table *local_table;
147 #ifdef CONFIG_IP_MULTIPLE_TABLES
151 local_table = fib_get_table(RT_TABLE_LOCAL);
152 if (!local_table || local_table->tb_lookup(local_table, &fl, &res))
154 if (res.type != RTN_LOCAL)
156 dev = FIB_RES_DEV(res);
166 * Find address type as if only "dev" was present in the system. If
167 * on_dev is NULL then all interfaces are taken into consideration.
169 static inline unsigned __inet_dev_addr_type(const struct net_device *dev,
172 struct flowi fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
173 struct fib_result res;
174 unsigned ret = RTN_BROADCAST;
175 struct fib_table *local_table;
177 if (ipv4_is_zeronet(addr) || ipv4_is_badclass(addr))
178 return RTN_BROADCAST;
179 if (ipv4_is_multicast(addr))
180 return RTN_MULTICAST;
182 #ifdef CONFIG_IP_MULTIPLE_TABLES
186 local_table = fib_get_table(RT_TABLE_LOCAL);
189 if (!local_table->tb_lookup(local_table, &fl, &res)) {
190 if (!dev || dev == res.fi->fib_dev)
198 unsigned int inet_addr_type(__be32 addr)
200 return __inet_dev_addr_type(NULL, addr);
203 unsigned int inet_dev_addr_type(const struct net_device *dev, __be32 addr)
205 return __inet_dev_addr_type(dev, addr);
208 /* Given (packet source, input interface) and optional (dst, oif, tos):
209 - (main) check, that source is valid i.e. not broadcast or our local
211 - figure out what "logical" interface this packet arrived
212 and calculate "specific destination" address.
213 - check, that packet arrived from expected physical interface.
216 int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
217 struct net_device *dev, __be32 *spec_dst, u32 *itag)
219 struct in_device *in_dev;
220 struct flowi fl = { .nl_u = { .ip4_u =
225 struct fib_result res;
231 in_dev = __in_dev_get_rcu(dev);
233 no_addr = in_dev->ifa_list == NULL;
234 rpf = IN_DEV_RPFILTER(in_dev);
241 if (fib_lookup(&fl, &res))
243 if (res.type != RTN_UNICAST)
245 *spec_dst = FIB_RES_PREFSRC(res);
246 fib_combine_itag(itag, &res);
247 #ifdef CONFIG_IP_ROUTE_MULTIPATH
248 if (FIB_RES_DEV(res) == dev || res.fi->fib_nhs > 1)
250 if (FIB_RES_DEV(res) == dev)
253 ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
262 fl.oif = dev->ifindex;
265 if (fib_lookup(&fl, &res) == 0) {
266 if (res.type == RTN_UNICAST) {
267 *spec_dst = FIB_RES_PREFSRC(res);
268 ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
277 *spec_dst = inet_select_addr(dev, 0, RT_SCOPE_UNIVERSE);
287 static inline __be32 sk_extract_addr(struct sockaddr *addr)
289 return ((struct sockaddr_in *) addr)->sin_addr.s_addr;
292 static int put_rtax(struct nlattr *mx, int len, int type, u32 value)
296 nla = (struct nlattr *) ((char *) mx + len);
297 nla->nla_type = type;
298 nla->nla_len = nla_attr_size(4);
299 *(u32 *) nla_data(nla) = value;
301 return len + nla_total_size(4);
304 static int rtentry_to_fib_config(int cmd, struct rtentry *rt,
305 struct fib_config *cfg)
310 memset(cfg, 0, sizeof(*cfg));
312 if (rt->rt_dst.sa_family != AF_INET)
313 return -EAFNOSUPPORT;
316 * Check mask for validity:
317 * a) it must be contiguous.
318 * b) destination must have all host bits clear.
319 * c) if application forgot to set correct family (AF_INET),
320 * reject request unless it is absolutely clear i.e.
321 * both family and mask are zero.
324 addr = sk_extract_addr(&rt->rt_dst);
325 if (!(rt->rt_flags & RTF_HOST)) {
326 __be32 mask = sk_extract_addr(&rt->rt_genmask);
328 if (rt->rt_genmask.sa_family != AF_INET) {
329 if (mask || rt->rt_genmask.sa_family)
330 return -EAFNOSUPPORT;
333 if (bad_mask(mask, addr))
336 plen = inet_mask_len(mask);
339 cfg->fc_dst_len = plen;
342 if (cmd != SIOCDELRT) {
343 cfg->fc_nlflags = NLM_F_CREATE;
344 cfg->fc_protocol = RTPROT_BOOT;
348 cfg->fc_priority = rt->rt_metric - 1;
350 if (rt->rt_flags & RTF_REJECT) {
351 cfg->fc_scope = RT_SCOPE_HOST;
352 cfg->fc_type = RTN_UNREACHABLE;
356 cfg->fc_scope = RT_SCOPE_NOWHERE;
357 cfg->fc_type = RTN_UNICAST;
361 struct net_device *dev;
362 char devname[IFNAMSIZ];
364 if (copy_from_user(devname, rt->rt_dev, IFNAMSIZ-1))
367 devname[IFNAMSIZ-1] = 0;
368 colon = strchr(devname, ':');
371 dev = __dev_get_by_name(&init_net, devname);
374 cfg->fc_oif = dev->ifindex;
376 struct in_ifaddr *ifa;
377 struct in_device *in_dev = __in_dev_get_rtnl(dev);
381 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next)
382 if (strcmp(ifa->ifa_label, devname) == 0)
386 cfg->fc_prefsrc = ifa->ifa_local;
390 addr = sk_extract_addr(&rt->rt_gateway);
391 if (rt->rt_gateway.sa_family == AF_INET && addr) {
393 if (rt->rt_flags & RTF_GATEWAY &&
394 inet_addr_type(addr) == RTN_UNICAST)
395 cfg->fc_scope = RT_SCOPE_UNIVERSE;
398 if (cmd == SIOCDELRT)
401 if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw)
404 if (cfg->fc_scope == RT_SCOPE_NOWHERE)
405 cfg->fc_scope = RT_SCOPE_LINK;
407 if (rt->rt_flags & (RTF_MTU | RTF_WINDOW | RTF_IRTT)) {
411 mx = kzalloc(3 * nla_total_size(4), GFP_KERNEL);
415 if (rt->rt_flags & RTF_MTU)
416 len = put_rtax(mx, len, RTAX_ADVMSS, rt->rt_mtu - 40);
418 if (rt->rt_flags & RTF_WINDOW)
419 len = put_rtax(mx, len, RTAX_WINDOW, rt->rt_window);
421 if (rt->rt_flags & RTF_IRTT)
422 len = put_rtax(mx, len, RTAX_RTT, rt->rt_irtt << 3);
425 cfg->fc_mx_len = len;
432 * Handle IP routing ioctl calls. These are used to manipulate the routing tables
435 int ip_rt_ioctl(unsigned int cmd, void __user *arg)
437 struct fib_config cfg;
442 case SIOCADDRT: /* Add a route */
443 case SIOCDELRT: /* Delete a route */
444 if (!capable(CAP_NET_ADMIN))
447 if (copy_from_user(&rt, arg, sizeof(rt)))
451 err = rtentry_to_fib_config(cmd, &rt, &cfg);
453 struct fib_table *tb;
455 if (cmd == SIOCDELRT) {
456 tb = fib_get_table(cfg.fc_table);
458 err = tb->tb_delete(tb, &cfg);
462 tb = fib_new_table(cfg.fc_table);
464 err = tb->tb_insert(tb, &cfg);
469 /* allocated by rtentry_to_fib_config() */
478 const struct nla_policy rtm_ipv4_policy[RTA_MAX+1] = {
479 [RTA_DST] = { .type = NLA_U32 },
480 [RTA_SRC] = { .type = NLA_U32 },
481 [RTA_IIF] = { .type = NLA_U32 },
482 [RTA_OIF] = { .type = NLA_U32 },
483 [RTA_GATEWAY] = { .type = NLA_U32 },
484 [RTA_PRIORITY] = { .type = NLA_U32 },
485 [RTA_PREFSRC] = { .type = NLA_U32 },
486 [RTA_METRICS] = { .type = NLA_NESTED },
487 [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
488 [RTA_PROTOINFO] = { .type = NLA_U32 },
489 [RTA_FLOW] = { .type = NLA_U32 },
492 static int rtm_to_fib_config(struct sk_buff *skb, struct nlmsghdr *nlh,
493 struct fib_config *cfg)
499 err = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipv4_policy);
503 memset(cfg, 0, sizeof(*cfg));
505 rtm = nlmsg_data(nlh);
506 cfg->fc_dst_len = rtm->rtm_dst_len;
507 cfg->fc_tos = rtm->rtm_tos;
508 cfg->fc_table = rtm->rtm_table;
509 cfg->fc_protocol = rtm->rtm_protocol;
510 cfg->fc_scope = rtm->rtm_scope;
511 cfg->fc_type = rtm->rtm_type;
512 cfg->fc_flags = rtm->rtm_flags;
513 cfg->fc_nlflags = nlh->nlmsg_flags;
515 cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
516 cfg->fc_nlinfo.nlh = nlh;
518 if (cfg->fc_type > RTN_MAX) {
523 nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), remaining) {
524 switch (nla_type(attr)) {
526 cfg->fc_dst = nla_get_be32(attr);
529 cfg->fc_oif = nla_get_u32(attr);
532 cfg->fc_gw = nla_get_be32(attr);
535 cfg->fc_priority = nla_get_u32(attr);
538 cfg->fc_prefsrc = nla_get_be32(attr);
541 cfg->fc_mx = nla_data(attr);
542 cfg->fc_mx_len = nla_len(attr);
545 cfg->fc_mp = nla_data(attr);
546 cfg->fc_mp_len = nla_len(attr);
549 cfg->fc_flow = nla_get_u32(attr);
552 cfg->fc_table = nla_get_u32(attr);
562 static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
564 struct net *net = skb->sk->sk_net;
565 struct fib_config cfg;
566 struct fib_table *tb;
569 if (net != &init_net)
572 err = rtm_to_fib_config(skb, nlh, &cfg);
576 tb = fib_get_table(cfg.fc_table);
582 err = tb->tb_delete(tb, &cfg);
587 static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
589 struct net *net = skb->sk->sk_net;
590 struct fib_config cfg;
591 struct fib_table *tb;
594 if (net != &init_net)
597 err = rtm_to_fib_config(skb, nlh, &cfg);
601 tb = fib_new_table(cfg.fc_table);
607 err = tb->tb_insert(tb, &cfg);
612 static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
614 struct net *net = skb->sk->sk_net;
616 unsigned int e = 0, s_e;
617 struct fib_table *tb;
618 struct hlist_node *node;
621 if (net != &init_net)
624 if (nlmsg_len(cb->nlh) >= sizeof(struct rtmsg) &&
625 ((struct rtmsg *) nlmsg_data(cb->nlh))->rtm_flags & RTM_F_CLONED)
626 return ip_rt_dump(skb, cb);
631 for (h = s_h; h < FIB_TABLE_HASHSZ; h++, s_e = 0) {
633 hlist_for_each_entry(tb, node, &fib_table_hash[h], tb_hlist) {
637 memset(&cb->args[2], 0, sizeof(cb->args) -
638 2 * sizeof(cb->args[0]));
639 if (tb->tb_dump(tb, skb, cb) < 0)
653 /* Prepare and feed intra-kernel routing request.
654 Really, it should be netlink message, but :-( netlink
655 can be not configured, so that we feed it directly
656 to fib engine. It is legal, because all events occur
657 only when netlink is already locked.
660 static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifaddr *ifa)
662 struct fib_table *tb;
663 struct fib_config cfg = {
664 .fc_protocol = RTPROT_KERNEL,
667 .fc_dst_len = dst_len,
668 .fc_prefsrc = ifa->ifa_local,
669 .fc_oif = ifa->ifa_dev->dev->ifindex,
670 .fc_nlflags = NLM_F_CREATE | NLM_F_APPEND,
673 if (type == RTN_UNICAST)
674 tb = fib_new_table(RT_TABLE_MAIN);
676 tb = fib_new_table(RT_TABLE_LOCAL);
681 cfg.fc_table = tb->tb_id;
683 if (type != RTN_LOCAL)
684 cfg.fc_scope = RT_SCOPE_LINK;
686 cfg.fc_scope = RT_SCOPE_HOST;
688 if (cmd == RTM_NEWROUTE)
689 tb->tb_insert(tb, &cfg);
691 tb->tb_delete(tb, &cfg);
694 void fib_add_ifaddr(struct in_ifaddr *ifa)
696 struct in_device *in_dev = ifa->ifa_dev;
697 struct net_device *dev = in_dev->dev;
698 struct in_ifaddr *prim = ifa;
699 __be32 mask = ifa->ifa_mask;
700 __be32 addr = ifa->ifa_local;
701 __be32 prefix = ifa->ifa_address&mask;
703 if (ifa->ifa_flags&IFA_F_SECONDARY) {
704 prim = inet_ifa_byprefix(in_dev, prefix, mask);
706 printk(KERN_DEBUG "fib_add_ifaddr: bug: prim == NULL\n");
711 fib_magic(RTM_NEWROUTE, RTN_LOCAL, addr, 32, prim);
713 if (!(dev->flags&IFF_UP))
716 /* Add broadcast address, if it is explicitly assigned. */
717 if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
718 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
720 if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags&IFA_F_SECONDARY) &&
721 (prefix != addr || ifa->ifa_prefixlen < 32)) {
722 fib_magic(RTM_NEWROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL :
723 RTN_UNICAST, prefix, ifa->ifa_prefixlen, prim);
725 /* Add network specific broadcasts, when it takes a sense */
726 if (ifa->ifa_prefixlen < 31) {
727 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix, 32, prim);
728 fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix|~mask, 32, prim);
733 static void fib_del_ifaddr(struct in_ifaddr *ifa)
735 struct in_device *in_dev = ifa->ifa_dev;
736 struct net_device *dev = in_dev->dev;
737 struct in_ifaddr *ifa1;
738 struct in_ifaddr *prim = ifa;
739 __be32 brd = ifa->ifa_address|~ifa->ifa_mask;
740 __be32 any = ifa->ifa_address&ifa->ifa_mask;
747 if (!(ifa->ifa_flags&IFA_F_SECONDARY))
748 fib_magic(RTM_DELROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL :
749 RTN_UNICAST, any, ifa->ifa_prefixlen, prim);
751 prim = inet_ifa_byprefix(in_dev, any, ifa->ifa_mask);
753 printk(KERN_DEBUG "fib_del_ifaddr: bug: prim == NULL\n");
758 /* Deletion is more complicated than add.
759 We should take care of not to delete too much :-)
761 Scan address list to be sure that addresses are really gone.
764 for (ifa1 = in_dev->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
765 if (ifa->ifa_local == ifa1->ifa_local)
767 if (ifa->ifa_broadcast == ifa1->ifa_broadcast)
769 if (brd == ifa1->ifa_broadcast)
771 if (any == ifa1->ifa_broadcast)
776 fib_magic(RTM_DELROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
778 fib_magic(RTM_DELROUTE, RTN_BROADCAST, brd, 32, prim);
780 fib_magic(RTM_DELROUTE, RTN_BROADCAST, any, 32, prim);
781 if (!(ok&LOCAL_OK)) {
782 fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 32, prim);
784 /* Check, that this local address finally disappeared. */
785 if (inet_addr_type(ifa->ifa_local) != RTN_LOCAL) {
786 /* And the last, but not the least thing.
787 We must flush stray FIB entries.
789 First of all, we scan fib_info list searching
790 for stray nexthop entries, then ignite fib_flush.
792 if (fib_sync_down(ifa->ifa_local, NULL, 0))
802 static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb )
805 struct fib_result res;
806 struct flowi fl = { .mark = frn->fl_mark,
807 .nl_u = { .ip4_u = { .daddr = frn->fl_addr,
809 .scope = frn->fl_scope } } };
811 #ifdef CONFIG_IP_MULTIPLE_TABLES
819 frn->tb_id = tb->tb_id;
820 frn->err = tb->tb_lookup(tb, &fl, &res);
823 frn->prefixlen = res.prefixlen;
824 frn->nh_sel = res.nh_sel;
825 frn->type = res.type;
826 frn->scope = res.scope;
833 static void nl_fib_input(struct sk_buff *skb)
835 struct fib_result_nl *frn;
836 struct nlmsghdr *nlh;
837 struct fib_table *tb;
840 nlh = nlmsg_hdr(skb);
841 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
842 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn)))
845 skb = skb_clone(skb, GFP_KERNEL);
848 nlh = nlmsg_hdr(skb);
850 frn = (struct fib_result_nl *) NLMSG_DATA(nlh);
851 tb = fib_get_table(frn->tb_id_in);
853 nl_fib_lookup(frn, tb);
855 pid = NETLINK_CB(skb).pid; /* pid of sending process */
856 NETLINK_CB(skb).pid = 0; /* from kernel */
857 NETLINK_CB(skb).dst_group = 0; /* unicast */
858 netlink_unicast(fibnl, skb, pid, MSG_DONTWAIT);
861 static int nl_fib_lookup_init(struct net *net)
863 fibnl = netlink_kernel_create(net, NETLINK_FIB_LOOKUP, 0,
864 nl_fib_input, NULL, THIS_MODULE);
866 return -EAFNOSUPPORT;
870 static void nl_fib_lookup_exit(struct net *net)
875 static void fib_disable_ip(struct net_device *dev, int force)
877 if (fib_sync_down(0, dev, force))
883 static int fib_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
885 struct in_ifaddr *ifa = (struct in_ifaddr*)ptr;
890 #ifdef CONFIG_IP_ROUTE_MULTIPATH
891 fib_sync_up(ifa->ifa_dev->dev);
897 if (ifa->ifa_dev->ifa_list == NULL) {
898 /* Last address was deleted from this interface.
901 fib_disable_ip(ifa->ifa_dev->dev, 1);
910 static int fib_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
912 struct net_device *dev = ptr;
913 struct in_device *in_dev = __in_dev_get_rtnl(dev);
915 if (dev->nd_net != &init_net)
918 if (event == NETDEV_UNREGISTER) {
919 fib_disable_ip(dev, 2);
930 } endfor_ifa(in_dev);
931 #ifdef CONFIG_IP_ROUTE_MULTIPATH
937 fib_disable_ip(dev, 0);
939 case NETDEV_CHANGEMTU:
947 static struct notifier_block fib_inetaddr_notifier = {
948 .notifier_call =fib_inetaddr_event,
951 static struct notifier_block fib_netdev_notifier = {
952 .notifier_call =fib_netdev_event,
955 static int __net_init ip_fib_net_init(struct net *net)
959 for (i = 0; i < FIB_TABLE_HASHSZ; i++)
960 INIT_HLIST_HEAD(&fib_table_hash[i]);
962 return fib4_rules_init(net);
965 static void __net_exit ip_fib_net_exit(struct net *net)
969 #ifdef CONFIG_IP_MULTIPLE_TABLES
970 fib4_rules_exit(net);
973 for (i = 0; i < FIB_TABLE_HASHSZ; i++) {
974 struct fib_table *tb;
975 struct hlist_head *head;
976 struct hlist_node *node, *tmp;
978 head = &fib_table_hash[i];
979 hlist_for_each_entry_safe(tb, node, tmp, head, tb_hlist) {
987 static int __net_init fib_net_init(struct net *net)
992 if (net != &init_net)
995 error = ip_fib_net_init(net);
998 error = nl_fib_lookup_init(net);
1001 error = fib_proc_init(net);
1008 nl_fib_lookup_exit(net);
1010 ip_fib_net_exit(net);
1014 static void __net_exit fib_net_exit(struct net *net)
1017 nl_fib_lookup_exit(net);
1018 ip_fib_net_exit(net);
1021 static struct pernet_operations fib_net_ops = {
1022 .init = fib_net_init,
1023 .exit = fib_net_exit,
1026 void __init ip_fib_init(void)
1028 rtnl_register(PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL);
1029 rtnl_register(PF_INET, RTM_DELROUTE, inet_rtm_delroute, NULL);
1030 rtnl_register(PF_INET, RTM_GETROUTE, NULL, inet_dump_fib);
1032 register_pernet_subsys(&fib_net_ops);
1033 register_netdevice_notifier(&fib_netdev_notifier);
1034 register_inetaddr_notifier(&fib_inetaddr_notifier);
1037 EXPORT_SYMBOL(inet_addr_type);
1038 EXPORT_SYMBOL(inet_dev_addr_type);
1039 EXPORT_SYMBOL(ip_dev_find);