aboutsummaryrefslogtreecommitdiffstats
path: root/net/decnet
diff options
context:
space:
mode:
Diffstat (limited to 'net/decnet')
-rw-r--r--net/decnet/Kconfig1
-rw-r--r--net/decnet/af_decnet.c1
-rw-r--r--net/decnet/dn_dev.c29
-rw-r--r--net/decnet/dn_fib.c76
-rw-r--r--net/decnet/dn_nsp_in.c2
-rw-r--r--net/decnet/dn_route.c19
-rw-r--r--net/decnet/dn_rules.c511
-rw-r--r--net/decnet/dn_table.c163
8 files changed, 353 insertions, 449 deletions
diff --git a/net/decnet/Kconfig b/net/decnet/Kconfig
index 92f2ec46fd22..36e72cb145b0 100644
--- a/net/decnet/Kconfig
+++ b/net/decnet/Kconfig
@@ -27,6 +27,7 @@ config DECNET
27config DECNET_ROUTER 27config DECNET_ROUTER
28 bool "DECnet: router support (EXPERIMENTAL)" 28 bool "DECnet: router support (EXPERIMENTAL)"
29 depends on DECNET && EXPERIMENTAL 29 depends on DECNET && EXPERIMENTAL
30 select FIB_RULES
30 ---help--- 31 ---help---
31 Add support for turning your DECnet Endnode into a level 1 or 2 32 Add support for turning your DECnet Endnode into a level 1 or 2
32 router. This is an experimental, but functional option. If you 33 router. This is an experimental, but functional option. If you
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 5486247735f6..70e027375682 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -130,6 +130,7 @@ Version 0.0.6 2.1.110 07-aug-98 Eduardo Marcelo Serrat
130#include <linux/poll.h> 130#include <linux/poll.h>
131#include <net/neighbour.h> 131#include <net/neighbour.h>
132#include <net/dst.h> 132#include <net/dst.h>
133#include <net/fib_rules.h>
133#include <net/dn.h> 134#include <net/dn.h>
134#include <net/dn_nsp.h> 135#include <net/dn_nsp.h>
135#include <net/dn_dev.h> 136#include <net/dn_dev.h>
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 476455fbdb03..01861feb608d 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -34,6 +34,7 @@
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/timer.h> 35#include <linux/timer.h>
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/if_addr.h>
37#include <linux/if_arp.h> 38#include <linux/if_arp.h>
38#include <linux/if_ether.h> 39#include <linux/if_ether.h>
39#include <linux/skbuff.h> 40#include <linux/skbuff.h>
@@ -45,6 +46,7 @@
45#include <net/neighbour.h> 46#include <net/neighbour.h>
46#include <net/dst.h> 47#include <net/dst.h>
47#include <net/flow.h> 48#include <net/flow.h>
49#include <net/fib_rules.h>
48#include <net/dn.h> 50#include <net/dn.h>
49#include <net/dn_dev.h> 51#include <net/dn_dev.h>
50#include <net/dn_route.h> 52#include <net/dn_route.h>
@@ -744,20 +746,23 @@ rtattr_failure:
744static void rtmsg_ifa(int event, struct dn_ifaddr *ifa) 746static void rtmsg_ifa(int event, struct dn_ifaddr *ifa)
745{ 747{
746 struct sk_buff *skb; 748 struct sk_buff *skb;
747 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg)+128); 749 int payload = sizeof(struct ifaddrmsg) + 128;
750 int err = -ENOBUFS;
748 751
749 skb = alloc_skb(size, GFP_KERNEL); 752 skb = alloc_skb(nlmsg_total_size(payload), GFP_KERNEL);
750 if (!skb) { 753 if (skb == NULL)
751 netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, ENOBUFS); 754 goto errout;
752 return; 755
753 } 756 err = dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0);
754 if (dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) { 757 if (err < 0) {
755 kfree_skb(skb); 758 kfree_skb(skb);
756 netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, EINVAL); 759 goto errout;
757 return;
758 } 760 }
759 NETLINK_CB(skb).dst_group = RTNLGRP_DECnet_IFADDR; 761
760 netlink_broadcast(rtnl, skb, 0, RTNLGRP_DECnet_IFADDR, GFP_KERNEL); 762 err = rtnl_notify(skb, 0, RTNLGRP_DECnet_IFADDR, NULL, GFP_KERNEL);
763errout:
764 if (err < 0)
765 rtnl_set_sk_err(RTNLGRP_DECnet_IFADDR, err);
761} 766}
762 767
763static int dn_dev_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) 768static int dn_dev_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
@@ -1417,8 +1422,6 @@ static struct rtnetlink_link dnet_rtnetlink_table[RTM_NR_MSGTYPES] =
1417 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, }, 1422 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, },
1418 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute, 1423 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1419 .dumpit = dn_fib_dump, }, 1424 .dumpit = dn_fib_dump, },
1420 [RTM_NEWRULE - RTM_BASE] = { .doit = dn_fib_rtm_newrule, },
1421 [RTM_DELRULE - RTM_BASE] = { .doit = dn_fib_rtm_delrule, },
1422 [RTM_GETRULE - RTM_BASE] = { .dumpit = dn_fib_dump_rules, }, 1425 [RTM_GETRULE - RTM_BASE] = { .dumpit = dn_fib_dump_rules, },
1423#else 1426#else
1424 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute, 1427 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index fa20e2efcfc1..1cf010124ec5 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -34,6 +34,7 @@
34#include <net/neighbour.h> 34#include <net/neighbour.h>
35#include <net/dst.h> 35#include <net/dst.h>
36#include <net/flow.h> 36#include <net/flow.h>
37#include <net/fib_rules.h>
37#include <net/dn.h> 38#include <net/dn.h>
38#include <net/dn_route.h> 39#include <net/dn_route.h>
39#include <net/dn_fib.h> 40#include <net/dn_fib.h>
@@ -54,11 +55,9 @@
54 55
55#define endfor_nexthops(fi) } 56#define endfor_nexthops(fi) }
56 57
57extern int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb);
58
59static DEFINE_SPINLOCK(dn_fib_multipath_lock); 58static DEFINE_SPINLOCK(dn_fib_multipath_lock);
60static struct dn_fib_info *dn_fib_info_list; 59static struct dn_fib_info *dn_fib_info_list;
61static DEFINE_RWLOCK(dn_fib_info_lock); 60static DEFINE_SPINLOCK(dn_fib_info_lock);
62 61
63static struct 62static struct
64{ 63{
@@ -79,6 +78,9 @@ static struct
79 [RTN_XRESOLVE] = { .error = -EINVAL, .scope = RT_SCOPE_NOWHERE }, 78 [RTN_XRESOLVE] = { .error = -EINVAL, .scope = RT_SCOPE_NOWHERE },
80}; 79};
81 80
81static int dn_fib_sync_down(__le16 local, struct net_device *dev, int force);
82static int dn_fib_sync_up(struct net_device *dev);
83
82void dn_fib_free_info(struct dn_fib_info *fi) 84void dn_fib_free_info(struct dn_fib_info *fi)
83{ 85{
84 if (fi->fib_dead == 0) { 86 if (fi->fib_dead == 0) {
@@ -96,7 +98,7 @@ void dn_fib_free_info(struct dn_fib_info *fi)
96 98
97void dn_fib_release_info(struct dn_fib_info *fi) 99void dn_fib_release_info(struct dn_fib_info *fi)
98{ 100{
99 write_lock(&dn_fib_info_lock); 101 spin_lock(&dn_fib_info_lock);
100 if (fi && --fi->fib_treeref == 0) { 102 if (fi && --fi->fib_treeref == 0) {
101 if (fi->fib_next) 103 if (fi->fib_next)
102 fi->fib_next->fib_prev = fi->fib_prev; 104 fi->fib_next->fib_prev = fi->fib_prev;
@@ -107,7 +109,7 @@ void dn_fib_release_info(struct dn_fib_info *fi)
107 fi->fib_dead = 1; 109 fi->fib_dead = 1;
108 dn_fib_info_put(fi); 110 dn_fib_info_put(fi);
109 } 111 }
110 write_unlock(&dn_fib_info_lock); 112 spin_unlock(&dn_fib_info_lock);
111} 113}
112 114
113static inline int dn_fib_nh_comp(const struct dn_fib_info *fi, const struct dn_fib_info *ofi) 115static inline int dn_fib_nh_comp(const struct dn_fib_info *fi, const struct dn_fib_info *ofi)
@@ -378,13 +380,13 @@ link_it:
378 380
379 fi->fib_treeref++; 381 fi->fib_treeref++;
380 atomic_inc(&fi->fib_clntref); 382 atomic_inc(&fi->fib_clntref);
381 write_lock(&dn_fib_info_lock); 383 spin_lock(&dn_fib_info_lock);
382 fi->fib_next = dn_fib_info_list; 384 fi->fib_next = dn_fib_info_list;
383 fi->fib_prev = NULL; 385 fi->fib_prev = NULL;
384 if (dn_fib_info_list) 386 if (dn_fib_info_list)
385 dn_fib_info_list->fib_prev = fi; 387 dn_fib_info_list->fib_prev = fi;
386 dn_fib_info_list = fi; 388 dn_fib_info_list = fi;
387 write_unlock(&dn_fib_info_lock); 389 spin_unlock(&dn_fib_info_lock);
388 return fi; 390 return fi;
389 391
390err_inval: 392err_inval:
@@ -490,7 +492,8 @@ static int dn_fib_check_attr(struct rtmsg *r, struct rtattr **rta)
490 if (attr) { 492 if (attr) {
491 if (RTA_PAYLOAD(attr) < 4 && RTA_PAYLOAD(attr) != 2) 493 if (RTA_PAYLOAD(attr) < 4 && RTA_PAYLOAD(attr) != 2)
492 return -EINVAL; 494 return -EINVAL;
493 if (i != RTA_MULTIPATH && i != RTA_METRICS) 495 if (i != RTA_MULTIPATH && i != RTA_METRICS &&
496 i != RTA_TABLE)
494 rta[i-1] = (struct rtattr *)RTA_DATA(attr); 497 rta[i-1] = (struct rtattr *)RTA_DATA(attr);
495 } 498 }
496 } 499 }
@@ -507,7 +510,7 @@ int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
507 if (dn_fib_check_attr(r, rta)) 510 if (dn_fib_check_attr(r, rta))
508 return -EINVAL; 511 return -EINVAL;
509 512
510 tb = dn_fib_get_table(r->rtm_table, 0); 513 tb = dn_fib_get_table(rtm_get_table(rta, r->rtm_table), 0);
511 if (tb) 514 if (tb)
512 return tb->delete(tb, r, (struct dn_kern_rta *)rta, nlh, &NETLINK_CB(skb)); 515 return tb->delete(tb, r, (struct dn_kern_rta *)rta, nlh, &NETLINK_CB(skb));
513 516
@@ -523,46 +526,13 @@ int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
523 if (dn_fib_check_attr(r, rta)) 526 if (dn_fib_check_attr(r, rta))
524 return -EINVAL; 527 return -EINVAL;
525 528
526 tb = dn_fib_get_table(r->rtm_table, 1); 529 tb = dn_fib_get_table(rtm_get_table(rta, r->rtm_table), 1);
527 if (tb) 530 if (tb)
528 return tb->insert(tb, r, (struct dn_kern_rta *)rta, nlh, &NETLINK_CB(skb)); 531 return tb->insert(tb, r, (struct dn_kern_rta *)rta, nlh, &NETLINK_CB(skb));
529 532
530 return -ENOBUFS; 533 return -ENOBUFS;
531} 534}
532 535
533
534int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb)
535{
536 int t;
537 int s_t;
538 struct dn_fib_table *tb;
539
540 if (NLMSG_PAYLOAD(cb->nlh, 0) >= sizeof(struct rtmsg) &&
541 ((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED)
542 return dn_cache_dump(skb, cb);
543
544 s_t = cb->args[0];
545 if (s_t == 0)
546 s_t = cb->args[0] = RT_MIN_TABLE;
547
548 for(t = s_t; t <= RT_TABLE_MAX; t++) {
549 if (t < s_t)
550 continue;
551 if (t > s_t)
552 memset(&cb->args[1], 0,
553 sizeof(cb->args) - sizeof(cb->args[0]));
554 tb = dn_fib_get_table(t, 0);
555 if (tb == NULL)
556 continue;
557 if (tb->dump(tb, skb, cb) < 0)
558 break;
559 }
560
561 cb->args[0] = t;
562
563 return skb->len;
564}
565
566static void fib_magic(int cmd, int type, __le16 dst, int dst_len, struct dn_ifaddr *ifa) 536static void fib_magic(int cmd, int type, __le16 dst, int dst_len, struct dn_ifaddr *ifa)
567{ 537{
568 struct dn_fib_table *tb; 538 struct dn_fib_table *tb;
@@ -682,7 +652,7 @@ static int dn_fib_dnaddr_event(struct notifier_block *this, unsigned long event,
682 return NOTIFY_DONE; 652 return NOTIFY_DONE;
683} 653}
684 654
685int dn_fib_sync_down(__le16 local, struct net_device *dev, int force) 655static int dn_fib_sync_down(__le16 local, struct net_device *dev, int force)
686{ 656{
687 int ret = 0; 657 int ret = 0;
688 int scope = RT_SCOPE_NOWHERE; 658 int scope = RT_SCOPE_NOWHERE;
@@ -726,7 +696,7 @@ int dn_fib_sync_down(__le16 local, struct net_device *dev, int force)
726} 696}
727 697
728 698
729int dn_fib_sync_up(struct net_device *dev) 699static int dn_fib_sync_up(struct net_device *dev)
730{ 700{
731 int ret = 0; 701 int ret = 0;
732 702
@@ -760,22 +730,6 @@ int dn_fib_sync_up(struct net_device *dev)
760 return ret; 730 return ret;
761} 731}
762 732
763void dn_fib_flush(void)
764{
765 int flushed = 0;
766 struct dn_fib_table *tb;
767 int id;
768
769 for(id = RT_TABLE_MAX; id > 0; id--) {
770 if ((tb = dn_fib_get_table(id, 0)) == NULL)
771 continue;
772 flushed += tb->flush(tb);
773 }
774
775 if (flushed)
776 dn_rt_cache_flush(-1);
777}
778
779static struct notifier_block dn_fib_dnaddr_notifier = { 733static struct notifier_block dn_fib_dnaddr_notifier = {
780 .notifier_call = dn_fib_dnaddr_event, 734 .notifier_call = dn_fib_dnaddr_event,
781}; 735};
diff --git a/net/decnet/dn_nsp_in.c b/net/decnet/dn_nsp_in.c
index 86f7f3b28e70..72ecc6e62ec4 100644
--- a/net/decnet/dn_nsp_in.c
+++ b/net/decnet/dn_nsp_in.c
@@ -586,7 +586,7 @@ static __inline__ int dn_queue_skb(struct sock *sk, struct sk_buff *skb, int sig
586 goto out; 586 goto out;
587 } 587 }
588 588
589 err = sk_filter(sk, skb, 0); 589 err = sk_filter(sk, skb);
590 if (err) 590 if (err)
591 goto out; 591 goto out;
592 592
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 743e9fcf7c5a..dd0761e3d280 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -80,6 +80,7 @@
80#include <net/neighbour.h> 80#include <net/neighbour.h>
81#include <net/dst.h> 81#include <net/dst.h>
82#include <net/flow.h> 82#include <net/flow.h>
83#include <net/fib_rules.h>
83#include <net/dn.h> 84#include <net/dn.h>
84#include <net/dn_dev.h> 85#include <net/dn_dev.h>
85#include <net/dn_nsp.h> 86#include <net/dn_nsp.h>
@@ -1284,7 +1285,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
1284 dev_hold(out_dev); 1285 dev_hold(out_dev);
1285 1286
1286 if (res.r) 1287 if (res.r)
1287 src_map = dn_fib_rules_policy(fl.fld_src, &res, &flags); 1288 src_map = fl.fld_src; /* no NAT support for now */
1288 1289
1289 gateway = DN_FIB_RES_GW(res); 1290 gateway = DN_FIB_RES_GW(res);
1290 if (res.type == RTN_NAT) { 1291 if (res.type == RTN_NAT) {
@@ -1485,6 +1486,7 @@ static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1485 r->rtm_src_len = 0; 1486 r->rtm_src_len = 0;
1486 r->rtm_tos = 0; 1487 r->rtm_tos = 0;
1487 r->rtm_table = RT_TABLE_MAIN; 1488 r->rtm_table = RT_TABLE_MAIN;
1489 RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
1488 r->rtm_type = rt->rt_type; 1490 r->rtm_type = rt->rt_type;
1489 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED; 1491 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1490 r->rtm_scope = RT_SCOPE_UNIVERSE; 1492 r->rtm_scope = RT_SCOPE_UNIVERSE;
@@ -1609,9 +1611,7 @@ int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
1609 goto out_free; 1611 goto out_free;
1610 } 1612 }
1611 1613
1612 err = netlink_unicast(rtnl, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT); 1614 return rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
1613
1614 return err;
1615 1615
1616out_free: 1616out_free:
1617 kfree_skb(skb); 1617 kfree_skb(skb);
@@ -1781,14 +1781,9 @@ void __init dn_route_init(void)
1781{ 1781{
1782 int i, goal, order; 1782 int i, goal, order;
1783 1783
1784 dn_dst_ops.kmem_cachep = kmem_cache_create("dn_dst_cache", 1784 dn_dst_ops.kmem_cachep =
1785 sizeof(struct dn_route), 1785 kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
1786 0, SLAB_HWCACHE_ALIGN, 1786 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
1787 NULL, NULL);
1788
1789 if (!dn_dst_ops.kmem_cachep)
1790 panic("DECnet: Failed to allocate dn_dst_cache\n");
1791
1792 init_timer(&dn_route_timer); 1787 init_timer(&dn_route_timer);
1793 dn_route_timer.function = dn_dst_check_expire; 1788 dn_route_timer.function = dn_dst_check_expire;
1794 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ; 1789 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
diff --git a/net/decnet/dn_rules.c b/net/decnet/dn_rules.c
index 6986be754ef2..3e0c882c90bf 100644
--- a/net/decnet/dn_rules.c
+++ b/net/decnet/dn_rules.c
@@ -11,259 +11,213 @@
11 * 11 *
12 * 12 *
13 * Changes: 13 * Changes:
14 * Steve Whitehouse <steve@chygwyn.com>
15 * Updated for Thomas Graf's generic rules
14 * 16 *
15 */ 17 */
16#include <linux/string.h>
17#include <linux/net.h> 18#include <linux/net.h>
18#include <linux/socket.h>
19#include <linux/sockios.h>
20#include <linux/init.h> 19#include <linux/init.h>
21#include <linux/skbuff.h>
22#include <linux/netlink.h> 20#include <linux/netlink.h>
23#include <linux/rtnetlink.h> 21#include <linux/rtnetlink.h>
24#include <linux/proc_fs.h>
25#include <linux/netdevice.h> 22#include <linux/netdevice.h>
26#include <linux/timer.h>
27#include <linux/spinlock.h> 23#include <linux/spinlock.h>
28#include <linux/in_route.h>
29#include <linux/list.h> 24#include <linux/list.h>
30#include <linux/rcupdate.h> 25#include <linux/rcupdate.h>
31#include <asm/atomic.h>
32#include <asm/uaccess.h>
33#include <net/neighbour.h> 26#include <net/neighbour.h>
34#include <net/dst.h> 27#include <net/dst.h>
35#include <net/flow.h> 28#include <net/flow.h>
29#include <net/fib_rules.h>
36#include <net/dn.h> 30#include <net/dn.h>
37#include <net/dn_fib.h> 31#include <net/dn_fib.h>
38#include <net/dn_neigh.h> 32#include <net/dn_neigh.h>
39#include <net/dn_dev.h> 33#include <net/dn_dev.h>
40 34
35static struct fib_rules_ops dn_fib_rules_ops;
36
41struct dn_fib_rule 37struct dn_fib_rule
42{ 38{
43 struct hlist_node r_hlist; 39 struct fib_rule common;
44 atomic_t r_clntref; 40 unsigned char dst_len;
45 u32 r_preference; 41 unsigned char src_len;
46 unsigned char r_table; 42 __le16 src;
47 unsigned char r_action; 43 __le16 srcmask;
48 unsigned char r_dst_len; 44 __le16 dst;
49 unsigned char r_src_len; 45 __le16 dstmask;
50 __le16 r_src; 46 __le16 srcmap;
51 __le16 r_srcmask; 47 u8 flags;
52 __le16 r_dst;
53 __le16 r_dstmask;
54 __le16 r_srcmap;
55 u8 r_flags;
56#ifdef CONFIG_DECNET_ROUTE_FWMARK 48#ifdef CONFIG_DECNET_ROUTE_FWMARK
57 u32 r_fwmark; 49 u32 fwmark;
50 u32 fwmask;
58#endif 51#endif
59 int r_ifindex;
60 char r_ifname[IFNAMSIZ];
61 int r_dead;
62 struct rcu_head rcu;
63}; 52};
64 53
65static struct dn_fib_rule default_rule = { 54static struct dn_fib_rule default_rule = {
66 .r_clntref = ATOMIC_INIT(2), 55 .common = {
67 .r_preference = 0x7fff, 56 .refcnt = ATOMIC_INIT(2),
68 .r_table = RT_TABLE_MAIN, 57 .pref = 0x7fff,
69 .r_action = RTN_UNICAST 58 .table = RT_TABLE_MAIN,
59 .action = FR_ACT_TO_TBL,
60 },
70}; 61};
71 62
72static struct hlist_head dn_fib_rules; 63static LIST_HEAD(dn_fib_rules);
64
73 65
74int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 66int dn_fib_lookup(struct flowi *flp, struct dn_fib_res *res)
75{ 67{
76 struct rtattr **rta = arg; 68 struct fib_lookup_arg arg = {
77 struct rtmsg *rtm = NLMSG_DATA(nlh); 69 .result = res,
78 struct dn_fib_rule *r; 70 };
79 struct hlist_node *node; 71 int err;
80 int err = -ESRCH; 72
81 73 err = fib_rules_lookup(&dn_fib_rules_ops, flp, 0, &arg);
82 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 74 res->r = arg.rule;
83 if ((!rta[RTA_SRC-1] || memcmp(RTA_DATA(rta[RTA_SRC-1]), &r->r_src, 2) == 0) &&
84 rtm->rtm_src_len == r->r_src_len &&
85 rtm->rtm_dst_len == r->r_dst_len &&
86 (!rta[RTA_DST-1] || memcmp(RTA_DATA(rta[RTA_DST-1]), &r->r_dst, 2) == 0) &&
87#ifdef CONFIG_DECNET_ROUTE_FWMARK
88 (!rta[RTA_PROTOINFO-1] || memcmp(RTA_DATA(rta[RTA_PROTOINFO-1]), &r->r_fwmark, 4) == 0) &&
89#endif
90 (!rtm->rtm_type || rtm->rtm_type == r->r_action) &&
91 (!rta[RTA_PRIORITY-1] || memcmp(RTA_DATA(rta[RTA_PRIORITY-1]), &r->r_preference, 4) == 0) &&
92 (!rta[RTA_IIF-1] || rtattr_strcmp(rta[RTA_IIF-1], r->r_ifname) == 0) &&
93 (!rtm->rtm_table || (r && rtm->rtm_table == r->r_table))) {
94
95 err = -EPERM;
96 if (r == &default_rule)
97 break;
98
99 hlist_del_rcu(&r->r_hlist);
100 r->r_dead = 1;
101 dn_fib_rule_put(r);
102 err = 0;
103 break;
104 }
105 }
106 75
107 return err; 76 return err;
108} 77}
109 78
110static inline void dn_fib_rule_put_rcu(struct rcu_head *head) 79static int dn_fib_rule_action(struct fib_rule *rule, struct flowi *flp,
80 int flags, struct fib_lookup_arg *arg)
111{ 81{
112 struct dn_fib_rule *r = container_of(head, struct dn_fib_rule, rcu); 82 int err = -EAGAIN;
113 kfree(r); 83 struct dn_fib_table *tbl;
114}
115 84
116void dn_fib_rule_put(struct dn_fib_rule *r) 85 switch(rule->action) {
117{ 86 case FR_ACT_TO_TBL:
118 if (atomic_dec_and_test(&r->r_clntref)) { 87 break;
119 if (r->r_dead) 88
120 call_rcu(&r->rcu, dn_fib_rule_put_rcu); 89 case FR_ACT_UNREACHABLE:
121 else 90 err = -ENETUNREACH;
122 printk(KERN_DEBUG "Attempt to free alive dn_fib_rule\n"); 91 goto errout;
92
93 case FR_ACT_PROHIBIT:
94 err = -EACCES;
95 goto errout;
96
97 case FR_ACT_BLACKHOLE:
98 default:
99 err = -EINVAL;
100 goto errout;
123 } 101 }
102
103 tbl = dn_fib_get_table(rule->table, 0);
104 if (tbl == NULL)
105 goto errout;
106
107 err = tbl->lookup(tbl, flp, (struct dn_fib_res *)arg->result);
108 if (err > 0)
109 err = -EAGAIN;
110errout:
111 return err;
124} 112}
125 113
114static struct nla_policy dn_fib_rule_policy[FRA_MAX+1] __read_mostly = {
115 [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
116 [FRA_PRIORITY] = { .type = NLA_U32 },
117 [FRA_SRC] = { .type = NLA_U16 },
118 [FRA_DST] = { .type = NLA_U16 },
119 [FRA_FWMARK] = { .type = NLA_U32 },
120 [FRA_FWMASK] = { .type = NLA_U32 },
121 [FRA_TABLE] = { .type = NLA_U32 },
122};
126 123
127int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 124static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
128{ 125{
129 struct rtattr **rta = arg; 126 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
130 struct rtmsg *rtm = NLMSG_DATA(nlh); 127 u16 daddr = fl->fld_dst;
131 struct dn_fib_rule *r, *new_r, *last = NULL; 128 u16 saddr = fl->fld_src;
132 struct hlist_node *node = NULL; 129
133 unsigned char table_id; 130 if (((saddr ^ r->src) & r->srcmask) ||
134 131 ((daddr ^ r->dst) & r->dstmask))
135 if (rtm->rtm_src_len > 16 || rtm->rtm_dst_len > 16) 132 return 0;
136 return -EINVAL;
137
138 if (rta[RTA_IIF-1] && RTA_PAYLOAD(rta[RTA_IIF-1]) > IFNAMSIZ)
139 return -EINVAL;
140
141 if (rtm->rtm_type == RTN_NAT)
142 return -EINVAL;
143
144 table_id = rtm->rtm_table;
145 if (table_id == RT_TABLE_UNSPEC) {
146 struct dn_fib_table *tb;
147 if (rtm->rtm_type == RTN_UNICAST) {
148 if ((tb = dn_fib_empty_table()) == NULL)
149 return -ENOBUFS;
150 table_id = tb->n;
151 }
152 }
153 133
154 new_r = kzalloc(sizeof(*new_r), GFP_KERNEL);
155 if (!new_r)
156 return -ENOMEM;
157
158 if (rta[RTA_SRC-1])
159 memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2);
160 if (rta[RTA_DST-1])
161 memcpy(&new_r->r_dst, RTA_DATA(rta[RTA_DST-1]), 2);
162 if (rta[RTA_GATEWAY-1])
163 memcpy(&new_r->r_srcmap, RTA_DATA(rta[RTA_GATEWAY-1]), 2);
164 new_r->r_src_len = rtm->rtm_src_len;
165 new_r->r_dst_len = rtm->rtm_dst_len;
166 new_r->r_srcmask = dnet_make_mask(rtm->rtm_src_len);
167 new_r->r_dstmask = dnet_make_mask(rtm->rtm_dst_len);
168#ifdef CONFIG_DECNET_ROUTE_FWMARK 134#ifdef CONFIG_DECNET_ROUTE_FWMARK
169 if (rta[RTA_PROTOINFO-1]) 135 if ((r->fwmark ^ fl->fld_fwmark) & r->fwmask)
170 memcpy(&new_r->r_fwmark, RTA_DATA(rta[RTA_PROTOINFO-1]), 4); 136 return 0;
171#endif 137#endif
172 new_r->r_action = rtm->rtm_type;
173 new_r->r_flags = rtm->rtm_flags;
174 if (rta[RTA_PRIORITY-1])
175 memcpy(&new_r->r_preference, RTA_DATA(rta[RTA_PRIORITY-1]), 4);
176 new_r->r_table = table_id;
177 if (rta[RTA_IIF-1]) {
178 struct net_device *dev;
179 rtattr_strlcpy(new_r->r_ifname, rta[RTA_IIF-1], IFNAMSIZ);
180 new_r->r_ifindex = -1;
181 dev = dev_get_by_name(new_r->r_ifname);
182 if (dev) {
183 new_r->r_ifindex = dev->ifindex;
184 dev_put(dev);
185 }
186 }
187 138
188 r = container_of(dn_fib_rules.first, struct dn_fib_rule, r_hlist); 139 return 1;
189 if (!new_r->r_preference) { 140}
190 if (r && r->r_hlist.next != NULL) { 141
191 r = container_of(r->r_hlist.next, struct dn_fib_rule, r_hlist); 142static int dn_fib_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
192 if (r->r_preference) 143 struct nlmsghdr *nlh, struct fib_rule_hdr *frh,
193 new_r->r_preference = r->r_preference - 1; 144 struct nlattr **tb)
145{
146 int err = -EINVAL;
147 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
148
149 if (frh->src_len > 16 || frh->dst_len > 16 || frh->tos)
150 goto errout;
151
152 if (rule->table == RT_TABLE_UNSPEC) {
153 if (rule->action == FR_ACT_TO_TBL) {
154 struct dn_fib_table *table;
155
156 table = dn_fib_empty_table();
157 if (table == NULL) {
158 err = -ENOBUFS;
159 goto errout;
160 }
161
162 rule->table = table->n;
194 } 163 }
195 } 164 }
196 165
197 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 166 if (tb[FRA_SRC])
198 if (r->r_preference > new_r->r_preference) 167 r->src = nla_get_u16(tb[FRA_SRC]);
199 break; 168
200 last = r; 169 if (tb[FRA_DST])
170 r->dst = nla_get_u16(tb[FRA_DST]);
171
172#ifdef CONFIG_DECNET_ROUTE_FWMARK
173 if (tb[FRA_FWMARK]) {
174 r->fwmark = nla_get_u32(tb[FRA_FWMARK]);
175 if (r->fwmark)
176 /* compatibility: if the mark value is non-zero all bits
177 * are compared unless a mask is explicitly specified.
178 */
179 r->fwmask = 0xFFFFFFFF;
201 } 180 }
202 atomic_inc(&new_r->r_clntref);
203 181
204 if (last) 182 if (tb[FRA_FWMASK])
205 hlist_add_after_rcu(&last->r_hlist, &new_r->r_hlist); 183 r->fwmask = nla_get_u32(tb[FRA_FWMASK]);
206 else 184#endif
207 hlist_add_before_rcu(&new_r->r_hlist, &r->r_hlist);
208 return 0;
209}
210 185
186 r->src_len = frh->src_len;
187 r->srcmask = dnet_make_mask(r->src_len);
188 r->dst_len = frh->dst_len;
189 r->dstmask = dnet_make_mask(r->dst_len);
190 err = 0;
191errout:
192 return err;
193}
211 194
212int dn_fib_lookup(const struct flowi *flp, struct dn_fib_res *res) 195static int dn_fib_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
196 struct nlattr **tb)
213{ 197{
214 struct dn_fib_rule *r, *policy; 198 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
215 struct dn_fib_table *tb; 199
216 __le16 saddr = flp->fld_src; 200 if (frh->src_len && (r->src_len != frh->src_len))
217 __le16 daddr = flp->fld_dst; 201 return 0;
218 struct hlist_node *node;
219 int err;
220 202
221 rcu_read_lock(); 203 if (frh->dst_len && (r->dst_len != frh->dst_len))
204 return 0;
222 205
223 hlist_for_each_entry_rcu(r, node, &dn_fib_rules, r_hlist) {
224 if (((saddr^r->r_src) & r->r_srcmask) ||
225 ((daddr^r->r_dst) & r->r_dstmask) ||
226#ifdef CONFIG_DECNET_ROUTE_FWMARK 206#ifdef CONFIG_DECNET_ROUTE_FWMARK
227 (r->r_fwmark && r->r_fwmark != flp->fld_fwmark) || 207 if (tb[FRA_FWMARK] && (r->fwmark != nla_get_u32(tb[FRA_FWMARK])))
208 return 0;
209
210 if (tb[FRA_FWMASK] && (r->fwmask != nla_get_u32(tb[FRA_FWMASK])))
211 return 0;
228#endif 212#endif
229 (r->r_ifindex && r->r_ifindex != flp->iif))
230 continue;
231
232 switch(r->r_action) {
233 case RTN_UNICAST:
234 case RTN_NAT:
235 policy = r;
236 break;
237 case RTN_UNREACHABLE:
238 rcu_read_unlock();
239 return -ENETUNREACH;
240 default:
241 case RTN_BLACKHOLE:
242 rcu_read_unlock();
243 return -EINVAL;
244 case RTN_PROHIBIT:
245 rcu_read_unlock();
246 return -EACCES;
247 }
248 213
249 if ((tb = dn_fib_get_table(r->r_table, 0)) == NULL) 214 if (tb[FRA_SRC] && (r->src != nla_get_u16(tb[FRA_SRC])))
250 continue; 215 return 0;
251 err = tb->lookup(tb, flp, res); 216
252 if (err == 0) { 217 if (tb[FRA_DST] && (r->dst != nla_get_u16(tb[FRA_DST])))
253 res->r = policy; 218 return 0;
254 if (policy)
255 atomic_inc(&policy->r_clntref);
256 rcu_read_unlock();
257 return 0;
258 }
259 if (err < 0 && err != -EAGAIN) {
260 rcu_read_unlock();
261 return err;
262 }
263 }
264 219
265 rcu_read_unlock(); 220 return 1;
266 return -ESRCH;
267} 221}
268 222
269unsigned dnet_addr_type(__le16 addr) 223unsigned dnet_addr_type(__le16 addr)
@@ -271,7 +225,7 @@ unsigned dnet_addr_type(__le16 addr)
271 struct flowi fl = { .nl_u = { .dn_u = { .daddr = addr } } }; 225 struct flowi fl = { .nl_u = { .dn_u = { .daddr = addr } } };
272 struct dn_fib_res res; 226 struct dn_fib_res res;
273 unsigned ret = RTN_UNICAST; 227 unsigned ret = RTN_UNICAST;
274 struct dn_fib_table *tb = dn_fib_tables[RT_TABLE_LOCAL]; 228 struct dn_fib_table *tb = dn_fib_get_table(RT_TABLE_LOCAL, 0);
275 229
276 res.r = NULL; 230 res.r = NULL;
277 231
@@ -284,142 +238,79 @@ unsigned dnet_addr_type(__le16 addr)
284 return ret; 238 return ret;
285} 239}
286 240
287__le16 dn_fib_rules_policy(__le16 saddr, struct dn_fib_res *res, unsigned *flags) 241static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
242 struct nlmsghdr *nlh, struct fib_rule_hdr *frh)
288{ 243{
289 struct dn_fib_rule *r = res->r; 244 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
290 245
291 if (r->r_action == RTN_NAT) { 246 frh->family = AF_DECnet;
292 int addrtype = dnet_addr_type(r->r_srcmap); 247 frh->dst_len = r->dst_len;
248 frh->src_len = r->src_len;
249 frh->tos = 0;
293 250
294 if (addrtype == RTN_NAT) { 251#ifdef CONFIG_DECNET_ROUTE_FWMARK
295 saddr = (saddr&~r->r_srcmask)|r->r_srcmap; 252 if (r->fwmark)
296 *flags |= RTCF_SNAT; 253 NLA_PUT_U32(skb, FRA_FWMARK, r->fwmark);
297 } else if (addrtype == RTN_LOCAL || r->r_srcmap == 0) { 254 if (r->fwmask || r->fwmark)
298 saddr = r->r_srcmap; 255 NLA_PUT_U32(skb, FRA_FWMASK, r->fwmask);
299 *flags |= RTCF_MASQ; 256#endif
300 } 257 if (r->dst_len)
301 } 258 NLA_PUT_U16(skb, FRA_DST, r->dst);
302 return saddr; 259 if (r->src_len)
303} 260 NLA_PUT_U16(skb, FRA_SRC, r->src);
304
305static void dn_fib_rules_detach(struct net_device *dev)
306{
307 struct hlist_node *node;
308 struct dn_fib_rule *r;
309
310 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
311 if (r->r_ifindex == dev->ifindex)
312 r->r_ifindex = -1;
313 }
314}
315 261
316static void dn_fib_rules_attach(struct net_device *dev) 262 return 0;
317{
318 struct hlist_node *node;
319 struct dn_fib_rule *r;
320 263
321 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 264nla_put_failure:
322 if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0) 265 return -ENOBUFS;
323 r->r_ifindex = dev->ifindex;
324 }
325} 266}
326 267
327static int dn_fib_rules_event(struct notifier_block *this, unsigned long event, void *ptr) 268static u32 dn_fib_rule_default_pref(void)
328{ 269{
329 struct net_device *dev = ptr; 270 struct list_head *pos;
330 271 struct fib_rule *rule;
331 switch(event) { 272
332 case NETDEV_UNREGISTER: 273 if (!list_empty(&dn_fib_rules)) {
333 dn_fib_rules_detach(dev); 274 pos = dn_fib_rules.next;
334 dn_fib_sync_down(0, dev, 1); 275 if (pos->next != &dn_fib_rules) {
335 case NETDEV_REGISTER: 276 rule = list_entry(pos->next, struct fib_rule, list);
336 dn_fib_rules_attach(dev); 277 if (rule->pref)
337 dn_fib_sync_up(dev); 278 return rule->pref - 1;
279 }
338 } 280 }
339 281
340 return NOTIFY_DONE; 282 return 0;
341}
342
343
344static struct notifier_block dn_fib_rules_notifier = {
345 .notifier_call = dn_fib_rules_event,
346};
347
348static int dn_fib_fill_rule(struct sk_buff *skb, struct dn_fib_rule *r,
349 struct netlink_callback *cb, unsigned int flags)
350{
351 struct rtmsg *rtm;
352 struct nlmsghdr *nlh;
353 unsigned char *b = skb->tail;
354
355
356 nlh = NLMSG_NEW_ANSWER(skb, cb, RTM_NEWRULE, sizeof(*rtm), flags);
357 rtm = NLMSG_DATA(nlh);
358 rtm->rtm_family = AF_DECnet;
359 rtm->rtm_dst_len = r->r_dst_len;
360 rtm->rtm_src_len = r->r_src_len;
361 rtm->rtm_tos = 0;
362#ifdef CONFIG_DECNET_ROUTE_FWMARK
363 if (r->r_fwmark)
364 RTA_PUT(skb, RTA_PROTOINFO, 4, &r->r_fwmark);
365#endif
366 rtm->rtm_table = r->r_table;
367 rtm->rtm_protocol = 0;
368 rtm->rtm_scope = 0;
369 rtm->rtm_type = r->r_action;
370 rtm->rtm_flags = r->r_flags;
371
372 if (r->r_dst_len)
373 RTA_PUT(skb, RTA_DST, 2, &r->r_dst);
374 if (r->r_src_len)
375 RTA_PUT(skb, RTA_SRC, 2, &r->r_src);
376 if (r->r_ifname[0])
377 RTA_PUT(skb, RTA_IIF, IFNAMSIZ, &r->r_ifname);
378 if (r->r_preference)
379 RTA_PUT(skb, RTA_PRIORITY, 4, &r->r_preference);
380 if (r->r_srcmap)
381 RTA_PUT(skb, RTA_GATEWAY, 2, &r->r_srcmap);
382 nlh->nlmsg_len = skb->tail - b;
383 return skb->len;
384
385nlmsg_failure:
386rtattr_failure:
387 skb_trim(skb, b - skb->data);
388 return -1;
389} 283}
390 284
391int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb) 285int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb)
392{ 286{
393 int idx = 0; 287 return fib_rules_dump(skb, cb, AF_DECnet);
394 int s_idx = cb->args[0];
395 struct dn_fib_rule *r;
396 struct hlist_node *node;
397
398 rcu_read_lock();
399 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
400 if (idx < s_idx)
401 goto next;
402 if (dn_fib_fill_rule(skb, r, cb, NLM_F_MULTI) < 0)
403 break;
404next:
405 idx++;
406 }
407 rcu_read_unlock();
408 cb->args[0] = idx;
409
410 return skb->len;
411} 288}
412 289
290static struct fib_rules_ops dn_fib_rules_ops = {
291 .family = AF_DECnet,
292 .rule_size = sizeof(struct dn_fib_rule),
293 .action = dn_fib_rule_action,
294 .match = dn_fib_rule_match,
295 .configure = dn_fib_rule_configure,
296 .compare = dn_fib_rule_compare,
297 .fill = dn_fib_rule_fill,
298 .default_pref = dn_fib_rule_default_pref,
299 .nlgroup = RTNLGRP_DECnet_RULE,
300 .policy = dn_fib_rule_policy,
301 .rules_list = &dn_fib_rules,
302 .owner = THIS_MODULE,
303};
304
413void __init dn_fib_rules_init(void) 305void __init dn_fib_rules_init(void)
414{ 306{
415 INIT_HLIST_HEAD(&dn_fib_rules); 307 list_add_tail(&default_rule.common.list, &dn_fib_rules);
416 hlist_add_head(&default_rule.r_hlist, &dn_fib_rules); 308 fib_rules_register(&dn_fib_rules_ops);
417 register_netdevice_notifier(&dn_fib_rules_notifier);
418} 309}
419 310
420void __exit dn_fib_rules_cleanup(void) 311void __exit dn_fib_rules_cleanup(void)
421{ 312{
422 unregister_netdevice_notifier(&dn_fib_rules_notifier); 313 fib_rules_unregister(&dn_fib_rules_ops);
423} 314}
424 315
425 316
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index e926c952e363..317904bb5896 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -30,6 +30,7 @@
30#include <net/neighbour.h> 30#include <net/neighbour.h>
31#include <net/dst.h> 31#include <net/dst.h>
32#include <net/flow.h> 32#include <net/flow.h>
33#include <net/fib_rules.h>
33#include <net/dn.h> 34#include <net/dn.h>
34#include <net/dn_route.h> 35#include <net/dn_route.h>
35#include <net/dn_fib.h> 36#include <net/dn_fib.h>
@@ -74,9 +75,9 @@ for( ; ((f) = *(fp)) != NULL; (fp) = &(f)->fn_next)
74for( ; ((f) = *(fp)) != NULL && dn_key_eq((f)->fn_key, (key)); (fp) = &(f)->fn_next) 75for( ; ((f) = *(fp)) != NULL && dn_key_eq((f)->fn_key, (key)); (fp) = &(f)->fn_next)
75 76
76#define RT_TABLE_MIN 1 77#define RT_TABLE_MIN 1
77 78#define DN_FIB_TABLE_HASHSZ 256
79static struct hlist_head dn_fib_table_hash[DN_FIB_TABLE_HASHSZ];
78static DEFINE_RWLOCK(dn_fib_tables_lock); 80static DEFINE_RWLOCK(dn_fib_tables_lock);
79struct dn_fib_table *dn_fib_tables[RT_TABLE_MAX + 1];
80 81
81static kmem_cache_t *dn_hash_kmem __read_mostly; 82static kmem_cache_t *dn_hash_kmem __read_mostly;
82static int dn_fib_hash_zombies; 83static int dn_fib_hash_zombies;
@@ -263,7 +264,7 @@ static int dn_fib_nh_match(struct rtmsg *r, struct nlmsghdr *nlh, struct dn_kern
263} 264}
264 265
265static int dn_fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, 266static int dn_fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
266 u8 tb_id, u8 type, u8 scope, void *dst, int dst_len, 267 u32 tb_id, u8 type, u8 scope, void *dst, int dst_len,
267 struct dn_fib_info *fi, unsigned int flags) 268 struct dn_fib_info *fi, unsigned int flags)
268{ 269{
269 struct rtmsg *rtm; 270 struct rtmsg *rtm;
@@ -277,6 +278,7 @@ static int dn_fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
277 rtm->rtm_src_len = 0; 278 rtm->rtm_src_len = 0;
278 rtm->rtm_tos = 0; 279 rtm->rtm_tos = 0;
279 rtm->rtm_table = tb_id; 280 rtm->rtm_table = tb_id;
281 RTA_PUT_U32(skb, RTA_TABLE, tb_id);
280 rtm->rtm_flags = fi->fib_flags; 282 rtm->rtm_flags = fi->fib_flags;
281 rtm->rtm_scope = scope; 283 rtm->rtm_scope = scope;
282 rtm->rtm_type = type; 284 rtm->rtm_type = type;
@@ -326,29 +328,29 @@ rtattr_failure:
326} 328}
327 329
328 330
329static void dn_rtmsg_fib(int event, struct dn_fib_node *f, int z, int tb_id, 331static void dn_rtmsg_fib(int event, struct dn_fib_node *f, int z, u32 tb_id,
330 struct nlmsghdr *nlh, struct netlink_skb_parms *req) 332 struct nlmsghdr *nlh, struct netlink_skb_parms *req)
331{ 333{
332 struct sk_buff *skb; 334 struct sk_buff *skb;
333 u32 pid = req ? req->pid : 0; 335 u32 pid = req ? req->pid : 0;
334 int size = NLMSG_SPACE(sizeof(struct rtmsg) + 256); 336 int err = -ENOBUFS;
335 337
336 skb = alloc_skb(size, GFP_KERNEL); 338 skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
337 if (!skb) 339 if (skb == NULL)
338 return; 340 goto errout;
339 341
340 if (dn_fib_dump_info(skb, pid, nlh->nlmsg_seq, event, tb_id, 342 err = dn_fib_dump_info(skb, pid, nlh->nlmsg_seq, event, tb_id,
341 f->fn_type, f->fn_scope, &f->fn_key, z, 343 f->fn_type, f->fn_scope, &f->fn_key, z,
342 DN_FIB_INFO(f), 0) < 0) { 344 DN_FIB_INFO(f), 0);
345 if (err < 0) {
343 kfree_skb(skb); 346 kfree_skb(skb);
344 return; 347 goto errout;
345 } 348 }
346 NETLINK_CB(skb).dst_group = RTNLGRP_DECnet_ROUTE; 349
347 if (nlh->nlmsg_flags & NLM_F_ECHO) 350 err = rtnl_notify(skb, pid, RTNLGRP_DECnet_ROUTE, nlh, GFP_KERNEL);
348 atomic_inc(&skb->users); 351errout:
349 netlink_broadcast(rtnl, skb, pid, RTNLGRP_DECnet_ROUTE, GFP_KERNEL); 352 if (err < 0)
350 if (nlh->nlmsg_flags & NLM_F_ECHO) 353 rtnl_set_sk_err(RTNLGRP_DECnet_ROUTE, err);
351 netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
352} 354}
353 355
354static __inline__ int dn_hash_dump_bucket(struct sk_buff *skb, 356static __inline__ int dn_hash_dump_bucket(struct sk_buff *skb,
@@ -359,7 +361,7 @@ static __inline__ int dn_hash_dump_bucket(struct sk_buff *skb,
359{ 361{
360 int i, s_i; 362 int i, s_i;
361 363
362 s_i = cb->args[3]; 364 s_i = cb->args[4];
363 for(i = 0; f; i++, f = f->fn_next) { 365 for(i = 0; f; i++, f = f->fn_next) {
364 if (i < s_i) 366 if (i < s_i)
365 continue; 367 continue;
@@ -372,11 +374,11 @@ static __inline__ int dn_hash_dump_bucket(struct sk_buff *skb,
372 (f->fn_state & DN_S_ZOMBIE) ? 0 : f->fn_type, 374 (f->fn_state & DN_S_ZOMBIE) ? 0 : f->fn_type,
373 f->fn_scope, &f->fn_key, dz->dz_order, 375 f->fn_scope, &f->fn_key, dz->dz_order,
374 f->fn_info, NLM_F_MULTI) < 0) { 376 f->fn_info, NLM_F_MULTI) < 0) {
375 cb->args[3] = i; 377 cb->args[4] = i;
376 return -1; 378 return -1;
377 } 379 }
378 } 380 }
379 cb->args[3] = i; 381 cb->args[4] = i;
380 return skb->len; 382 return skb->len;
381} 383}
382 384
@@ -387,20 +389,20 @@ static __inline__ int dn_hash_dump_zone(struct sk_buff *skb,
387{ 389{
388 int h, s_h; 390 int h, s_h;
389 391
390 s_h = cb->args[2]; 392 s_h = cb->args[3];
391 for(h = 0; h < dz->dz_divisor; h++) { 393 for(h = 0; h < dz->dz_divisor; h++) {
392 if (h < s_h) 394 if (h < s_h)
393 continue; 395 continue;
394 if (h > s_h) 396 if (h > s_h)
395 memset(&cb->args[3], 0, sizeof(cb->args) - 3*sizeof(cb->args[0])); 397 memset(&cb->args[4], 0, sizeof(cb->args) - 4*sizeof(cb->args[0]));
396 if (dz->dz_hash == NULL || dz->dz_hash[h] == NULL) 398 if (dz->dz_hash == NULL || dz->dz_hash[h] == NULL)
397 continue; 399 continue;
398 if (dn_hash_dump_bucket(skb, cb, tb, dz, dz->dz_hash[h]) < 0) { 400 if (dn_hash_dump_bucket(skb, cb, tb, dz, dz->dz_hash[h]) < 0) {
399 cb->args[2] = h; 401 cb->args[3] = h;
400 return -1; 402 return -1;
401 } 403 }
402 } 404 }
403 cb->args[2] = h; 405 cb->args[3] = h;
404 return skb->len; 406 return skb->len;
405} 407}
406 408
@@ -411,26 +413,63 @@ static int dn_fib_table_dump(struct dn_fib_table *tb, struct sk_buff *skb,
411 struct dn_zone *dz; 413 struct dn_zone *dz;
412 struct dn_hash *table = (struct dn_hash *)tb->data; 414 struct dn_hash *table = (struct dn_hash *)tb->data;
413 415
414 s_m = cb->args[1]; 416 s_m = cb->args[2];
415 read_lock(&dn_fib_tables_lock); 417 read_lock(&dn_fib_tables_lock);
416 for(dz = table->dh_zone_list, m = 0; dz; dz = dz->dz_next, m++) { 418 for(dz = table->dh_zone_list, m = 0; dz; dz = dz->dz_next, m++) {
417 if (m < s_m) 419 if (m < s_m)
418 continue; 420 continue;
419 if (m > s_m) 421 if (m > s_m)
420 memset(&cb->args[2], 0, sizeof(cb->args) - 2*sizeof(cb->args[0])); 422 memset(&cb->args[3], 0, sizeof(cb->args) - 3*sizeof(cb->args[0]));
421 423
422 if (dn_hash_dump_zone(skb, cb, tb, dz) < 0) { 424 if (dn_hash_dump_zone(skb, cb, tb, dz) < 0) {
423 cb->args[1] = m; 425 cb->args[2] = m;
424 read_unlock(&dn_fib_tables_lock); 426 read_unlock(&dn_fib_tables_lock);
425 return -1; 427 return -1;
426 } 428 }
427 } 429 }
428 read_unlock(&dn_fib_tables_lock); 430 read_unlock(&dn_fib_tables_lock);
429 cb->args[1] = m; 431 cb->args[2] = m;
430 432
431 return skb->len; 433 return skb->len;
432} 434}
433 435
436int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb)
437{
438 unsigned int h, s_h;
439 unsigned int e = 0, s_e;
440 struct dn_fib_table *tb;
441 struct hlist_node *node;
442 int dumped = 0;
443
444 if (NLMSG_PAYLOAD(cb->nlh, 0) >= sizeof(struct rtmsg) &&
445 ((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED)
446 return dn_cache_dump(skb, cb);
447
448 s_h = cb->args[0];
449 s_e = cb->args[1];
450
451 for (h = s_h; h < DN_FIB_TABLE_HASHSZ; h++, s_h = 0) {
452 e = 0;
453 hlist_for_each_entry(tb, node, &dn_fib_table_hash[h], hlist) {
454 if (e < s_e)
455 goto next;
456 if (dumped)
457 memset(&cb->args[2], 0, sizeof(cb->args) -
458 2 * sizeof(cb->args[0]));
459 if (tb->dump(tb, skb, cb) < 0)
460 goto out;
461 dumped = 1;
462next:
463 e++;
464 }
465 }
466out:
467 cb->args[1] = e;
468 cb->args[0] = h;
469
470 return skb->len;
471}
472
434static int dn_fib_table_insert(struct dn_fib_table *tb, struct rtmsg *r, struct dn_kern_rta *rta, struct nlmsghdr *n, struct netlink_skb_parms *req) 473static int dn_fib_table_insert(struct dn_fib_table *tb, struct rtmsg *r, struct dn_kern_rta *rta, struct nlmsghdr *n, struct netlink_skb_parms *req)
435{ 474{
436 struct dn_hash *table = (struct dn_hash *)tb->data; 475 struct dn_hash *table = (struct dn_hash *)tb->data;
@@ -739,9 +778,11 @@ out:
739} 778}
740 779
741 780
742struct dn_fib_table *dn_fib_get_table(int n, int create) 781struct dn_fib_table *dn_fib_get_table(u32 n, int create)
743{ 782{
744 struct dn_fib_table *t; 783 struct dn_fib_table *t;
784 struct hlist_node *node;
785 unsigned int h;
745 786
746 if (n < RT_TABLE_MIN) 787 if (n < RT_TABLE_MIN)
747 return NULL; 788 return NULL;
@@ -749,8 +790,15 @@ struct dn_fib_table *dn_fib_get_table(int n, int create)
749 if (n > RT_TABLE_MAX) 790 if (n > RT_TABLE_MAX)
750 return NULL; 791 return NULL;
751 792
752 if (dn_fib_tables[n]) 793 h = n & (DN_FIB_TABLE_HASHSZ - 1);
753 return dn_fib_tables[n]; 794 rcu_read_lock();
795 hlist_for_each_entry_rcu(t, node, &dn_fib_table_hash[h], hlist) {
796 if (t->n == n) {
797 rcu_read_unlock();
798 return t;
799 }
800 }
801 rcu_read_unlock();
754 802
755 if (!create) 803 if (!create)
756 return NULL; 804 return NULL;
@@ -771,33 +819,37 @@ struct dn_fib_table *dn_fib_get_table(int n, int create)
771 t->flush = dn_fib_table_flush; 819 t->flush = dn_fib_table_flush;
772 t->dump = dn_fib_table_dump; 820 t->dump = dn_fib_table_dump;
773 memset(t->data, 0, sizeof(struct dn_hash)); 821 memset(t->data, 0, sizeof(struct dn_hash));
774 dn_fib_tables[n] = t; 822 hlist_add_head_rcu(&t->hlist, &dn_fib_table_hash[h]);
775 823
776 return t; 824 return t;
777} 825}
778 826
779static void dn_fib_del_tree(int n)
780{
781 struct dn_fib_table *t;
782
783 write_lock(&dn_fib_tables_lock);
784 t = dn_fib_tables[n];
785 dn_fib_tables[n] = NULL;
786 write_unlock(&dn_fib_tables_lock);
787
788 kfree(t);
789}
790
791struct dn_fib_table *dn_fib_empty_table(void) 827struct dn_fib_table *dn_fib_empty_table(void)
792{ 828{
793 int id; 829 u32 id;
794 830
795 for(id = RT_TABLE_MIN; id <= RT_TABLE_MAX; id++) 831 for(id = RT_TABLE_MIN; id <= RT_TABLE_MAX; id++)
796 if (dn_fib_tables[id] == NULL) 832 if (dn_fib_get_table(id, 0) == NULL)
797 return dn_fib_get_table(id, 1); 833 return dn_fib_get_table(id, 1);
798 return NULL; 834 return NULL;
799} 835}
800 836
837void dn_fib_flush(void)
838{
839 int flushed = 0;
840 struct dn_fib_table *tb;
841 struct hlist_node *node;
842 unsigned int h;
843
844 for (h = 0; h < DN_FIB_TABLE_HASHSZ; h++) {
845 hlist_for_each_entry(tb, node, &dn_fib_table_hash[h], hlist)
846 flushed += tb->flush(tb);
847 }
848
849 if (flushed)
850 dn_rt_cache_flush(-1);
851}
852
801void __init dn_fib_table_init(void) 853void __init dn_fib_table_init(void)
802{ 854{
803 dn_hash_kmem = kmem_cache_create("dn_fib_info_cache", 855 dn_hash_kmem = kmem_cache_create("dn_fib_info_cache",
@@ -808,10 +860,17 @@ void __init dn_fib_table_init(void)
808 860
809void __exit dn_fib_table_cleanup(void) 861void __exit dn_fib_table_cleanup(void)
810{ 862{
811 int i; 863 struct dn_fib_table *t;
812 864 struct hlist_node *node, *next;
813 for (i = RT_TABLE_MIN; i <= RT_TABLE_MAX; ++i) 865 unsigned int h;
814 dn_fib_del_tree(i);
815 866
816 return; 867 write_lock(&dn_fib_tables_lock);
868 for (h = 0; h < DN_FIB_TABLE_HASHSZ; h++) {
869 hlist_for_each_entry_safe(t, node, next, &dn_fib_table_hash[h],
870 hlist) {
871 hlist_del(&t->hlist);
872 kfree(t);
873 }
874 }
875 write_unlock(&dn_fib_tables_lock);
817} 876}