fib_frontend.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  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.
  5. *
  6. * IPv4 Forwarding Information Base: FIB frontend.
  7. *
  8. * Version: $Id: fib_frontend.c,v 1.26 2001/10/31 21:55:54 davem Exp $
  9. *
  10. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  11. *
  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.
  16. */
  17. #include <linux/config.h>
  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>
  25. #include <linux/sched.h>
  26. #include <linux/mm.h>
  27. #include <linux/string.h>
  28. #include <linux/socket.h>
  29. #include <linux/sockios.h>
  30. #include <linux/errno.h>
  31. #include <linux/in.h>
  32. #include <linux/inet.h>
  33. #include <linux/inetdevice.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/if_arp.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netlink.h>
  38. #include <linux/init.h>
  39. #include <net/ip.h>
  40. #include <net/protocol.h>
  41. #include <net/route.h>
  42. #include <net/tcp.h>
  43. #include <net/sock.h>
  44. #include <net/icmp.h>
  45. #include <net/arp.h>
  46. #include <net/ip_fib.h>
  47. #define FFprint(a...) printk(KERN_DEBUG a)
  48. #ifndef CONFIG_IP_MULTIPLE_TABLES
  49. #define RT_TABLE_MIN RT_TABLE_MAIN
  50. struct fib_table *ip_fib_local_table;
  51. struct fib_table *ip_fib_main_table;
  52. #else
  53. #define RT_TABLE_MIN 1
  54. struct fib_table *fib_tables[RT_TABLE_MAX+1];
  55. struct fib_table *__fib_new_table(int id)
  56. {
  57. struct fib_table *tb;
  58. tb = fib_hash_init(id);
  59. if (!tb)
  60. return NULL;
  61. fib_tables[id] = tb;
  62. return tb;
  63. }
  64. #endif /* CONFIG_IP_MULTIPLE_TABLES */
  65. static void fib_flush(void)
  66. {
  67. int flushed = 0;
  68. #ifdef CONFIG_IP_MULTIPLE_TABLES
  69. struct fib_table *tb;
  70. int id;
  71. for (id = RT_TABLE_MAX; id>0; id--) {
  72. if ((tb = fib_get_table(id))==NULL)
  73. continue;
  74. flushed += tb->tb_flush(tb);
  75. }
  76. #else /* CONFIG_IP_MULTIPLE_TABLES */
  77. flushed += ip_fib_main_table->tb_flush(ip_fib_main_table);
  78. flushed += ip_fib_local_table->tb_flush(ip_fib_local_table);
  79. #endif /* CONFIG_IP_MULTIPLE_TABLES */
  80. if (flushed)
  81. rt_cache_flush(-1);
  82. }
  83. /*
  84. * Find the first device with a given source address.
  85. */
  86. struct net_device * ip_dev_find(u32 addr)
  87. {
  88. struct flowi fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
  89. struct fib_result res;
  90. struct net_device *dev = NULL;
  91. #ifdef CONFIG_IP_MULTIPLE_TABLES
  92. res.r = NULL;
  93. #endif
  94. if (!ip_fib_local_table ||
  95. ip_fib_local_table->tb_lookup(ip_fib_local_table, &fl, &res))
  96. return NULL;
  97. if (res.type != RTN_LOCAL)
  98. goto out;
  99. dev = FIB_RES_DEV(res);
  100. if (dev)
  101. dev_hold(dev);
  102. out:
  103. fib_res_put(&res);
  104. return dev;
  105. }
  106. unsigned inet_addr_type(u32 addr)
  107. {
  108. struct flowi fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
  109. struct fib_result res;
  110. unsigned ret = RTN_BROADCAST;
  111. if (ZERONET(addr) || BADCLASS(addr))
  112. return RTN_BROADCAST;
  113. if (MULTICAST(addr))
  114. return RTN_MULTICAST;
  115. #ifdef CONFIG_IP_MULTIPLE_TABLES
  116. res.r = NULL;
  117. #endif
  118. if (ip_fib_local_table) {
  119. ret = RTN_UNICAST;
  120. if (!ip_fib_local_table->tb_lookup(ip_fib_local_table,
  121. &fl, &res)) {
  122. ret = res.type;
  123. fib_res_put(&res);
  124. }
  125. }
  126. return ret;
  127. }
  128. /* Given (packet source, input interface) and optional (dst, oif, tos):
  129. - (main) check, that source is valid i.e. not broadcast or our local
  130. address.
  131. - figure out what "logical" interface this packet arrived
  132. and calculate "specific destination" address.
  133. - check, that packet arrived from expected physical interface.
  134. */
  135. int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
  136. struct net_device *dev, u32 *spec_dst, u32 *itag)
  137. {
  138. struct in_device *in_dev;
  139. struct flowi fl = { .nl_u = { .ip4_u =
  140. { .daddr = src,
  141. .saddr = dst,
  142. .tos = tos } },
  143. .iif = oif };
  144. struct fib_result res;
  145. int no_addr, rpf;
  146. int ret;
  147. no_addr = rpf = 0;
  148. rcu_read_lock();
  149. in_dev = __in_dev_get_rcu(dev);
  150. if (in_dev) {
  151. no_addr = in_dev->ifa_list == NULL;
  152. rpf = IN_DEV_RPFILTER(in_dev);
  153. }
  154. rcu_read_unlock();
  155. if (in_dev == NULL)
  156. goto e_inval;
  157. if (fib_lookup(&fl, &res))
  158. goto last_resort;
  159. if (res.type != RTN_UNICAST)
  160. goto e_inval_res;
  161. *spec_dst = FIB_RES_PREFSRC(res);
  162. fib_combine_itag(itag, &res);
  163. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  164. if (FIB_RES_DEV(res) == dev || res.fi->fib_nhs > 1)
  165. #else
  166. if (FIB_RES_DEV(res) == dev)
  167. #endif
  168. {
  169. ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
  170. fib_res_put(&res);
  171. return ret;
  172. }
  173. fib_res_put(&res);
  174. if (no_addr)
  175. goto last_resort;
  176. if (rpf)
  177. goto e_inval;
  178. fl.oif = dev->ifindex;
  179. ret = 0;
  180. if (fib_lookup(&fl, &res) == 0) {
  181. if (res.type == RTN_UNICAST) {
  182. *spec_dst = FIB_RES_PREFSRC(res);
  183. ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
  184. }
  185. fib_res_put(&res);
  186. }
  187. return ret;
  188. last_resort:
  189. if (rpf)
  190. goto e_inval;
  191. *spec_dst = inet_select_addr(dev, 0, RT_SCOPE_UNIVERSE);
  192. *itag = 0;
  193. return 0;
  194. e_inval_res:
  195. fib_res_put(&res);
  196. e_inval:
  197. return -EINVAL;
  198. }
  199. #ifndef CONFIG_IP_NOSIOCRT
  200. /*
  201. * Handle IP routing ioctl calls. These are used to manipulate the routing tables
  202. */
  203. int ip_rt_ioctl(unsigned int cmd, void __user *arg)
  204. {
  205. int err;
  206. struct kern_rta rta;
  207. struct rtentry r;
  208. struct {
  209. struct nlmsghdr nlh;
  210. struct rtmsg rtm;
  211. } req;
  212. switch (cmd) {
  213. case SIOCADDRT: /* Add a route */
  214. case SIOCDELRT: /* Delete a route */
  215. if (!capable(CAP_NET_ADMIN))
  216. return -EPERM;
  217. if (copy_from_user(&r, arg, sizeof(struct rtentry)))
  218. return -EFAULT;
  219. rtnl_lock();
  220. err = fib_convert_rtentry(cmd, &req.nlh, &req.rtm, &rta, &r);
  221. if (err == 0) {
  222. if (cmd == SIOCDELRT) {
  223. struct fib_table *tb = fib_get_table(req.rtm.rtm_table);
  224. err = -ESRCH;
  225. if (tb)
  226. err = tb->tb_delete(tb, &req.rtm, &rta, &req.nlh, NULL);
  227. } else {
  228. struct fib_table *tb = fib_new_table(req.rtm.rtm_table);
  229. err = -ENOBUFS;
  230. if (tb)
  231. err = tb->tb_insert(tb, &req.rtm, &rta, &req.nlh, NULL);
  232. }
  233. kfree(rta.rta_mx);
  234. }
  235. rtnl_unlock();
  236. return err;
  237. }
  238. return -EINVAL;
  239. }
  240. #else
  241. int ip_rt_ioctl(unsigned int cmd, void *arg)
  242. {
  243. return -EINVAL;
  244. }
  245. #endif
  246. static int inet_check_attr(struct rtmsg *r, struct rtattr **rta)
  247. {
  248. int i;
  249. for (i=1; i<=RTA_MAX; i++, rta++) {
  250. struct rtattr *attr = *rta;
  251. if (attr) {
  252. if (RTA_PAYLOAD(attr) < 4)
  253. return -EINVAL;
  254. if (i != RTA_MULTIPATH && i != RTA_METRICS)
  255. *rta = (struct rtattr*)RTA_DATA(attr);
  256. }
  257. }
  258. return 0;
  259. }
  260. int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
  261. {
  262. struct fib_table * tb;
  263. struct rtattr **rta = arg;
  264. struct rtmsg *r = NLMSG_DATA(nlh);
  265. if (inet_check_attr(r, rta))
  266. return -EINVAL;
  267. tb = fib_get_table(r->rtm_table);
  268. if (tb)
  269. return tb->tb_delete(tb, r, (struct kern_rta*)rta, nlh, &NETLINK_CB(skb));
  270. return -ESRCH;
  271. }
  272. int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
  273. {
  274. struct fib_table * tb;
  275. struct rtattr **rta = arg;
  276. struct rtmsg *r = NLMSG_DATA(nlh);
  277. if (inet_check_attr(r, rta))
  278. return -EINVAL;
  279. tb = fib_new_table(r->rtm_table);
  280. if (tb)
  281. return tb->tb_insert(tb, r, (struct kern_rta*)rta, nlh, &NETLINK_CB(skb));
  282. return -ENOBUFS;
  283. }
  284. int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
  285. {
  286. int t;
  287. int s_t;
  288. struct fib_table *tb;
  289. if (NLMSG_PAYLOAD(cb->nlh, 0) >= sizeof(struct rtmsg) &&
  290. ((struct rtmsg*)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED)
  291. return ip_rt_dump(skb, cb);
  292. s_t = cb->args[0];
  293. if (s_t == 0)
  294. s_t = cb->args[0] = RT_TABLE_MIN;
  295. for (t=s_t; t<=RT_TABLE_MAX; t++) {
  296. if (t < s_t) continue;
  297. if (t > s_t)
  298. memset(&cb->args[1], 0, sizeof(cb->args)-sizeof(cb->args[0]));
  299. if ((tb = fib_get_table(t))==NULL)
  300. continue;
  301. if (tb->tb_dump(tb, skb, cb) < 0)
  302. break;
  303. }
  304. cb->args[0] = t;
  305. return skb->len;
  306. }
  307. /* Prepare and feed intra-kernel routing request.
  308. Really, it should be netlink message, but :-( netlink
  309. can be not configured, so that we feed it directly
  310. to fib engine. It is legal, because all events occur
  311. only when netlink is already locked.
  312. */
  313. static void fib_magic(int cmd, int type, u32 dst, int dst_len, struct in_ifaddr *ifa)
  314. {
  315. struct fib_table * tb;
  316. struct {
  317. struct nlmsghdr nlh;
  318. struct rtmsg rtm;
  319. } req;
  320. struct kern_rta rta;
  321. memset(&req.rtm, 0, sizeof(req.rtm));
  322. memset(&rta, 0, sizeof(rta));
  323. if (type == RTN_UNICAST)
  324. tb = fib_new_table(RT_TABLE_MAIN);
  325. else
  326. tb = fib_new_table(RT_TABLE_LOCAL);
  327. if (tb == NULL)
  328. return;
  329. req.nlh.nlmsg_len = sizeof(req);
  330. req.nlh.nlmsg_type = cmd;
  331. req.nlh.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_APPEND;
  332. req.nlh.nlmsg_pid = 0;
  333. req.nlh.nlmsg_seq = 0;
  334. req.rtm.rtm_dst_len = dst_len;
  335. req.rtm.rtm_table = tb->tb_id;
  336. req.rtm.rtm_protocol = RTPROT_KERNEL;
  337. req.rtm.rtm_scope = (type != RTN_LOCAL ? RT_SCOPE_LINK : RT_SCOPE_HOST);
  338. req.rtm.rtm_type = type;
  339. rta.rta_dst = &dst;
  340. rta.rta_prefsrc = &ifa->ifa_local;
  341. rta.rta_oif = &ifa->ifa_dev->dev->ifindex;
  342. if (cmd == RTM_NEWROUTE)
  343. tb->tb_insert(tb, &req.rtm, &rta, &req.nlh, NULL);
  344. else
  345. tb->tb_delete(tb, &req.rtm, &rta, &req.nlh, NULL);
  346. }
  347. void fib_add_ifaddr(struct in_ifaddr *ifa)
  348. {
  349. struct in_device *in_dev = ifa->ifa_dev;
  350. struct net_device *dev = in_dev->dev;
  351. struct in_ifaddr *prim = ifa;
  352. u32 mask = ifa->ifa_mask;
  353. u32 addr = ifa->ifa_local;
  354. u32 prefix = ifa->ifa_address&mask;
  355. if (ifa->ifa_flags&IFA_F_SECONDARY) {
  356. prim = inet_ifa_byprefix(in_dev, prefix, mask);
  357. if (prim == NULL) {
  358. printk(KERN_DEBUG "fib_add_ifaddr: bug: prim == NULL\n");
  359. return;
  360. }
  361. }
  362. fib_magic(RTM_NEWROUTE, RTN_LOCAL, addr, 32, prim);
  363. if (!(dev->flags&IFF_UP))
  364. return;
  365. /* Add broadcast address, if it is explicitly assigned. */
  366. if (ifa->ifa_broadcast && ifa->ifa_broadcast != 0xFFFFFFFF)
  367. fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
  368. if (!ZERONET(prefix) && !(ifa->ifa_flags&IFA_F_SECONDARY) &&
  369. (prefix != addr || ifa->ifa_prefixlen < 32)) {
  370. fib_magic(RTM_NEWROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL :
  371. RTN_UNICAST, prefix, ifa->ifa_prefixlen, prim);
  372. /* Add network specific broadcasts, when it takes a sense */
  373. if (ifa->ifa_prefixlen < 31) {
  374. fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix, 32, prim);
  375. fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix|~mask, 32, prim);
  376. }
  377. }
  378. }
  379. static void fib_del_ifaddr(struct in_ifaddr *ifa)
  380. {
  381. struct in_device *in_dev = ifa->ifa_dev;
  382. struct net_device *dev = in_dev->dev;
  383. struct in_ifaddr *ifa1;
  384. struct in_ifaddr *prim = ifa;
  385. u32 brd = ifa->ifa_address|~ifa->ifa_mask;
  386. u32 any = ifa->ifa_address&ifa->ifa_mask;
  387. #define LOCAL_OK 1
  388. #define BRD_OK 2
  389. #define BRD0_OK 4
  390. #define BRD1_OK 8
  391. unsigned ok = 0;
  392. if (!(ifa->ifa_flags&IFA_F_SECONDARY))
  393. fib_magic(RTM_DELROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL :
  394. RTN_UNICAST, any, ifa->ifa_prefixlen, prim);
  395. else {
  396. prim = inet_ifa_byprefix(in_dev, any, ifa->ifa_mask);
  397. if (prim == NULL) {
  398. printk(KERN_DEBUG "fib_del_ifaddr: bug: prim == NULL\n");
  399. return;
  400. }
  401. }
  402. /* Deletion is more complicated than add.
  403. We should take care of not to delete too much :-)
  404. Scan address list to be sure that addresses are really gone.
  405. */
  406. for (ifa1 = in_dev->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
  407. if (ifa->ifa_local == ifa1->ifa_local)
  408. ok |= LOCAL_OK;
  409. if (ifa->ifa_broadcast == ifa1->ifa_broadcast)
  410. ok |= BRD_OK;
  411. if (brd == ifa1->ifa_broadcast)
  412. ok |= BRD1_OK;
  413. if (any == ifa1->ifa_broadcast)
  414. ok |= BRD0_OK;
  415. }
  416. if (!(ok&BRD_OK))
  417. fib_magic(RTM_DELROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
  418. if (!(ok&BRD1_OK))
  419. fib_magic(RTM_DELROUTE, RTN_BROADCAST, brd, 32, prim);
  420. if (!(ok&BRD0_OK))
  421. fib_magic(RTM_DELROUTE, RTN_BROADCAST, any, 32, prim);
  422. if (!(ok&LOCAL_OK)) {
  423. fib_magic(RTM_DELROUTE, RTN_LOCAL, ifa->ifa_local, 32, prim);
  424. /* Check, that this local address finally disappeared. */
  425. if (inet_addr_type(ifa->ifa_local) != RTN_LOCAL) {
  426. /* And the last, but not the least thing.
  427. We must flush stray FIB entries.
  428. First of all, we scan fib_info list searching
  429. for stray nexthop entries, then ignite fib_flush.
  430. */
  431. if (fib_sync_down(ifa->ifa_local, NULL, 0))
  432. fib_flush();
  433. }
  434. }
  435. #undef LOCAL_OK
  436. #undef BRD_OK
  437. #undef BRD0_OK
  438. #undef BRD1_OK
  439. }
  440. static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb )
  441. {
  442. struct fib_result res;
  443. struct flowi fl = { .nl_u = { .ip4_u = { .daddr = frn->fl_addr,
  444. .fwmark = frn->fl_fwmark,
  445. .tos = frn->fl_tos,
  446. .scope = frn->fl_scope } } };
  447. if (tb) {
  448. local_bh_disable();
  449. frn->tb_id = tb->tb_id;
  450. frn->err = tb->tb_lookup(tb, &fl, &res);
  451. if (!frn->err) {
  452. frn->prefixlen = res.prefixlen;
  453. frn->nh_sel = res.nh_sel;
  454. frn->type = res.type;
  455. frn->scope = res.scope;
  456. }
  457. local_bh_enable();
  458. }
  459. }
  460. static void nl_fib_input(struct sock *sk, int len)
  461. {
  462. struct sk_buff *skb = NULL;
  463. struct nlmsghdr *nlh = NULL;
  464. struct fib_result_nl *frn;
  465. u32 pid;
  466. struct fib_table *tb;
  467. skb = skb_dequeue(&sk->sk_receive_queue);
  468. nlh = (struct nlmsghdr *)skb->data;
  469. if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
  470. nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) {
  471. kfree_skb(skb);
  472. return;
  473. }
  474. frn = (struct fib_result_nl *) NLMSG_DATA(nlh);
  475. tb = fib_get_table(frn->tb_id_in);
  476. nl_fib_lookup(frn, tb);
  477. pid = nlh->nlmsg_pid; /*pid of sending process */
  478. NETLINK_CB(skb).pid = 0; /* from kernel */
  479. NETLINK_CB(skb).dst_pid = pid;
  480. NETLINK_CB(skb).dst_group = 0; /* unicast */
  481. netlink_unicast(sk, skb, pid, MSG_DONTWAIT);
  482. }
  483. static void nl_fib_lookup_init(void)
  484. {
  485. netlink_kernel_create(NETLINK_FIB_LOOKUP, 0, nl_fib_input, THIS_MODULE);
  486. }
  487. static void fib_disable_ip(struct net_device *dev, int force)
  488. {
  489. if (fib_sync_down(0, dev, force))
  490. fib_flush();
  491. rt_cache_flush(0);
  492. arp_ifdown(dev);
  493. }
  494. static int fib_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
  495. {
  496. struct in_ifaddr *ifa = (struct in_ifaddr*)ptr;
  497. switch (event) {
  498. case NETDEV_UP:
  499. fib_add_ifaddr(ifa);
  500. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  501. fib_sync_up(ifa->ifa_dev->dev);
  502. #endif
  503. rt_cache_flush(-1);
  504. break;
  505. case NETDEV_DOWN:
  506. fib_del_ifaddr(ifa);
  507. if (ifa->ifa_dev->ifa_list == NULL) {
  508. /* Last address was deleted from this interface.
  509. Disable IP.
  510. */
  511. fib_disable_ip(ifa->ifa_dev->dev, 1);
  512. } else {
  513. rt_cache_flush(-1);
  514. }
  515. break;
  516. }
  517. return NOTIFY_DONE;
  518. }
  519. static int fib_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
  520. {
  521. struct net_device *dev = ptr;
  522. struct in_device *in_dev = __in_dev_get_rtnl(dev);
  523. if (event == NETDEV_UNREGISTER) {
  524. fib_disable_ip(dev, 2);
  525. return NOTIFY_DONE;
  526. }
  527. if (!in_dev)
  528. return NOTIFY_DONE;
  529. switch (event) {
  530. case NETDEV_UP:
  531. for_ifa(in_dev) {
  532. fib_add_ifaddr(ifa);
  533. } endfor_ifa(in_dev);
  534. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  535. fib_sync_up(dev);
  536. #endif
  537. rt_cache_flush(-1);
  538. break;
  539. case NETDEV_DOWN:
  540. fib_disable_ip(dev, 0);
  541. break;
  542. case NETDEV_CHANGEMTU:
  543. case NETDEV_CHANGE:
  544. rt_cache_flush(0);
  545. break;
  546. }
  547. return NOTIFY_DONE;
  548. }
  549. static struct notifier_block fib_inetaddr_notifier = {
  550. .notifier_call =fib_inetaddr_event,
  551. };
  552. static struct notifier_block fib_netdev_notifier = {
  553. .notifier_call =fib_netdev_event,
  554. };
  555. void __init ip_fib_init(void)
  556. {
  557. #ifndef CONFIG_IP_MULTIPLE_TABLES
  558. ip_fib_local_table = fib_hash_init(RT_TABLE_LOCAL);
  559. ip_fib_main_table = fib_hash_init(RT_TABLE_MAIN);
  560. #else
  561. fib_rules_init();
  562. #endif
  563. register_netdevice_notifier(&fib_netdev_notifier);
  564. register_inetaddr_notifier(&fib_inetaddr_notifier);
  565. nl_fib_lookup_init();
  566. }
  567. EXPORT_SYMBOL(inet_addr_type);
  568. EXPORT_SYMBOL(ip_rt_ioctl);