2 * DECnet An implementation of the DECnet protocol suite for the LINUX
3 * operating system. DECnet is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * DECnet Routing Functions (Endnode and Router)
8 * Authors: Steve Whitehouse <SteveW@ACM.org>
9 * Eduardo Marcelo Serrat <emserrat@geocities.com>
12 * Steve Whitehouse : Fixes to allow "intra-ethernet" and
13 * "return-to-sender" bits on outgoing
15 * Steve Whitehouse : Timeouts for cached routes.
16 * Steve Whitehouse : Use dst cache for input routes too.
17 * Steve Whitehouse : Fixed error values in dn_send_skb.
18 * Steve Whitehouse : Rework routing functions to better fit
19 * DECnet routing design
20 * Alexey Kuznetsov : New SMP locking
21 * Steve Whitehouse : More SMP locking changes & dn_cache_dump()
22 * Steve Whitehouse : Prerouting NF hook, now really is prerouting.
23 * Fixed possible skb leak in rtnetlink funcs.
24 * Steve Whitehouse : Dave Miller's dynamic hash table sizing and
25 * Alexey Kuznetsov's finer grained locking
27 * Steve Whitehouse : Routing is now starting to look like a
28 * sensible set of code now, mainly due to
29 * my copying the IPv4 routing code. The
30 * hooks here are modified and will continue
31 * to evolve for a while.
32 * Steve Whitehouse : Real SMP at last :-) Also new netfilter
33 * stuff. Look out raw sockets your days
35 * Steve Whitehouse : Added return-to-sender functions. Added
36 * backlog congestion level return codes.
37 * Steve Whitehouse : Fixed bug where routes were set up with
38 * no ref count on net devices.
39 * Steve Whitehouse : RCU for the route cache
40 * Steve Whitehouse : Preparations for the flow cache
41 * Steve Whitehouse : Prepare for nonlinear skbs
44 /******************************************************************************
45 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
47 This program is free software; you can redistribute it and/or modify
48 it under the terms of the GNU General Public License as published by
49 the Free Software Foundation; either version 2 of the License, or
52 This program is distributed in the hope that it will be useful,
53 but WITHOUT ANY WARRANTY; without even the implied warranty of
54 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 GNU General Public License for more details.
56 *******************************************************************************/
58 #include <linux/errno.h>
59 #include <linux/types.h>
60 #include <linux/socket.h>
62 #include <linux/kernel.h>
63 #include <linux/sockios.h>
64 #include <linux/net.h>
65 #include <linux/netdevice.h>
66 #include <linux/inet.h>
67 #include <linux/route.h>
68 #include <linux/in_route.h>
69 #include <linux/slab.h>
72 #include <linux/proc_fs.h>
73 #include <linux/seq_file.h>
74 #include <linux/init.h>
75 #include <linux/rtnetlink.h>
76 #include <linux/string.h>
77 #include <linux/netfilter_decnet.h>
78 #include <linux/rcupdate.h>
79 #include <linux/times.h>
80 #include <asm/errno.h>
81 #include <net/net_namespace.h>
82 #include <net/netlink.h>
83 #include <net/neighbour.h>
86 #include <net/fib_rules.h>
88 #include <net/dn_dev.h>
89 #include <net/dn_nsp.h>
90 #include <net/dn_route.h>
91 #include <net/dn_neigh.h>
92 #include <net/dn_fib.h>
94 struct dn_rt_hash_bucket
96 struct dn_route __rcu *chain;
100 extern struct neigh_table dn_neigh_table;
103 static unsigned char dn_hiord_addr[6] = {0xAA,0x00,0x04,0x00,0x00,0x00};
105 static const int dn_rt_min_delay = 2 * HZ;
106 static const int dn_rt_max_delay = 10 * HZ;
107 static const int dn_rt_mtu_expires = 10 * 60 * HZ;
109 static unsigned long dn_rt_deadline;
111 static int dn_dst_gc(struct dst_ops *ops);
112 static struct dst_entry *dn_dst_check(struct dst_entry *, __u32);
113 static unsigned int dn_dst_default_advmss(const struct dst_entry *dst);
114 static unsigned int dn_dst_default_mtu(const struct dst_entry *dst);
115 static void dn_dst_destroy(struct dst_entry *);
116 static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
117 static void dn_dst_link_failure(struct sk_buff *);
118 static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
119 static int dn_route_input(struct sk_buff *);
120 static void dn_run_flush(unsigned long dummy);
122 static struct dn_rt_hash_bucket *dn_rt_hash_table;
123 static unsigned dn_rt_hash_mask;
125 static struct timer_list dn_route_timer;
126 static DEFINE_TIMER(dn_rt_flush_timer, dn_run_flush, 0, 0);
127 int decnet_dst_gc_interval = 2;
129 static struct dst_ops dn_dst_ops = {
131 .protocol = cpu_to_be16(ETH_P_DNA_RT),
134 .check = dn_dst_check,
135 .default_advmss = dn_dst_default_advmss,
136 .default_mtu = dn_dst_default_mtu,
137 .cow_metrics = dst_cow_metrics_generic,
138 .destroy = dn_dst_destroy,
139 .negative_advice = dn_dst_negative_advice,
140 .link_failure = dn_dst_link_failure,
141 .update_pmtu = dn_dst_update_pmtu,
144 static void dn_dst_destroy(struct dst_entry *dst)
146 dst_destroy_metrics_generic(dst);
149 static __inline__ unsigned dn_hash(__le16 src, __le16 dst)
151 __u16 tmp = (__u16 __force)(src ^ dst);
155 return dn_rt_hash_mask & (unsigned)tmp;
158 static inline void dnrt_free(struct dn_route *rt)
160 call_rcu_bh(&rt->dst.rcu_head, dst_rcu_free);
163 static inline void dnrt_drop(struct dn_route *rt)
165 dst_release(&rt->dst);
166 call_rcu_bh(&rt->dst.rcu_head, dst_rcu_free);
169 static void dn_dst_check_expire(unsigned long dummy)
173 struct dn_route __rcu **rtp;
174 unsigned long now = jiffies;
175 unsigned long expire = 120 * HZ;
177 for (i = 0; i <= dn_rt_hash_mask; i++) {
178 rtp = &dn_rt_hash_table[i].chain;
180 spin_lock(&dn_rt_hash_table[i].lock);
181 while ((rt = rcu_dereference_protected(*rtp,
182 lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
183 if (atomic_read(&rt->dst.__refcnt) ||
184 (now - rt->dst.lastuse) < expire) {
185 rtp = &rt->dst.dn_next;
188 *rtp = rt->dst.dn_next;
189 rt->dst.dn_next = NULL;
192 spin_unlock(&dn_rt_hash_table[i].lock);
194 if ((jiffies - now) > 0)
198 mod_timer(&dn_route_timer, now + decnet_dst_gc_interval * HZ);
201 static int dn_dst_gc(struct dst_ops *ops)
204 struct dn_route __rcu **rtp;
206 unsigned long now = jiffies;
207 unsigned long expire = 10 * HZ;
209 for (i = 0; i <= dn_rt_hash_mask; i++) {
211 spin_lock_bh(&dn_rt_hash_table[i].lock);
212 rtp = &dn_rt_hash_table[i].chain;
214 while ((rt = rcu_dereference_protected(*rtp,
215 lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
216 if (atomic_read(&rt->dst.__refcnt) ||
217 (now - rt->dst.lastuse) < expire) {
218 rtp = &rt->dst.dn_next;
221 *rtp = rt->dst.dn_next;
222 rt->dst.dn_next = NULL;
226 spin_unlock_bh(&dn_rt_hash_table[i].lock);
233 * The decnet standards don't impose a particular minimum mtu, what they
234 * do insist on is that the routing layer accepts a datagram of at least
235 * 230 bytes long. Here we have to subtract the routing header length from
236 * 230 to get the minimum acceptable mtu. If there is no neighbour, then we
237 * assume the worst and use a long header size.
239 * We update both the mtu and the advertised mss (i.e. the segment size we
240 * advertise to the other end).
242 static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)
245 struct dn_dev *dn = dst->neighbour ?
246 rcu_dereference_raw(dst->neighbour->dev->dn_ptr) : NULL;
248 if (dn && dn->use_long == 0)
253 if (dst_metric(dst, RTAX_MTU) > mtu && mtu >= min_mtu) {
254 if (!(dst_metric_locked(dst, RTAX_MTU))) {
255 dst_metric_set(dst, RTAX_MTU, mtu);
256 dst_set_expires(dst, dn_rt_mtu_expires);
258 if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
259 u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
260 u32 existing_mss = dst_metric_raw(dst, RTAX_ADVMSS);
261 if (!existing_mss || existing_mss > mss)
262 dst_metric_set(dst, RTAX_ADVMSS, mss);
268 * When a route has been marked obsolete. (e.g. routing cache flush)
270 static struct dst_entry *dn_dst_check(struct dst_entry *dst, __u32 cookie)
275 static struct dst_entry *dn_dst_negative_advice(struct dst_entry *dst)
281 static void dn_dst_link_failure(struct sk_buff *skb)
285 static inline int compare_keys(struct flowidn *fl1, struct flowidn *fl2)
287 return ((fl1->daddr ^ fl2->daddr) |
288 (fl1->saddr ^ fl2->saddr) |
289 (fl1->flowidn_mark ^ fl2->flowidn_mark) |
290 (fl1->flowidn_scope ^ fl2->flowidn_scope) |
291 (fl1->flowidn_oif ^ fl2->flowidn_oif) |
292 (fl1->flowidn_iif ^ fl2->flowidn_iif)) == 0;
295 static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp)
297 struct dn_route *rth;
298 struct dn_route __rcu **rthp;
299 unsigned long now = jiffies;
301 rthp = &dn_rt_hash_table[hash].chain;
303 spin_lock_bh(&dn_rt_hash_table[hash].lock);
304 while ((rth = rcu_dereference_protected(*rthp,
305 lockdep_is_held(&dn_rt_hash_table[hash].lock))) != NULL) {
306 if (compare_keys(&rth->fld, &rt->fld)) {
308 *rthp = rth->dst.dn_next;
309 rcu_assign_pointer(rth->dst.dn_next,
310 dn_rt_hash_table[hash].chain);
311 rcu_assign_pointer(dn_rt_hash_table[hash].chain, rth);
313 dst_use(&rth->dst, now);
314 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
320 rthp = &rth->dst.dn_next;
323 rcu_assign_pointer(rt->dst.dn_next, dn_rt_hash_table[hash].chain);
324 rcu_assign_pointer(dn_rt_hash_table[hash].chain, rt);
326 dst_use(&rt->dst, now);
327 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
332 static void dn_run_flush(unsigned long dummy)
335 struct dn_route *rt, *next;
337 for (i = 0; i < dn_rt_hash_mask; i++) {
338 spin_lock_bh(&dn_rt_hash_table[i].lock);
340 if ((rt = xchg((struct dn_route **)&dn_rt_hash_table[i].chain, NULL)) == NULL)
341 goto nothing_to_declare;
343 for(; rt; rt = next) {
344 next = rcu_dereference_raw(rt->dst.dn_next);
345 RCU_INIT_POINTER(rt->dst.dn_next, NULL);
346 dst_free((struct dst_entry *)rt);
350 spin_unlock_bh(&dn_rt_hash_table[i].lock);
354 static DEFINE_SPINLOCK(dn_rt_flush_lock);
356 void dn_rt_cache_flush(int delay)
358 unsigned long now = jiffies;
359 int user_mode = !in_interrupt();
362 delay = dn_rt_min_delay;
364 spin_lock_bh(&dn_rt_flush_lock);
366 if (del_timer(&dn_rt_flush_timer) && delay > 0 && dn_rt_deadline) {
367 long tmo = (long)(dn_rt_deadline - now);
369 if (user_mode && tmo < dn_rt_max_delay - dn_rt_min_delay)
377 spin_unlock_bh(&dn_rt_flush_lock);
382 if (dn_rt_deadline == 0)
383 dn_rt_deadline = now + dn_rt_max_delay;
385 dn_rt_flush_timer.expires = now + delay;
386 add_timer(&dn_rt_flush_timer);
387 spin_unlock_bh(&dn_rt_flush_lock);
391 * dn_return_short - Return a short packet to its sender
392 * @skb: The packet to return
395 static int dn_return_short(struct sk_buff *skb)
397 struct dn_skb_cb *cb;
402 /* Add back headers */
403 skb_push(skb, skb->data - skb_network_header(skb));
405 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
409 /* Skip packet length and point to flags */
411 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
417 *ptr = 0; /* Zero hop count */
421 skb->pkt_type = PACKET_OUTGOING;
422 dn_rt_finish_output(skb, NULL, NULL);
423 return NET_RX_SUCCESS;
427 * dn_return_long - Return a long packet to its sender
428 * @skb: The long format packet to return
431 static int dn_return_long(struct sk_buff *skb)
433 struct dn_skb_cb *cb;
435 unsigned char *src_addr, *dst_addr;
436 unsigned char tmp[ETH_ALEN];
438 /* Add back all headers */
439 skb_push(skb, skb->data - skb_network_header(skb));
441 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
445 /* Ignore packet length and point to flags */
449 if (*ptr & DN_RT_F_PF) {
450 char padlen = (*ptr & ~DN_RT_F_PF);
454 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
460 *ptr = 0; /* Zero hop count */
462 /* Swap source and destination */
463 memcpy(tmp, src_addr, ETH_ALEN);
464 memcpy(src_addr, dst_addr, ETH_ALEN);
465 memcpy(dst_addr, tmp, ETH_ALEN);
467 skb->pkt_type = PACKET_OUTGOING;
468 dn_rt_finish_output(skb, dst_addr, src_addr);
469 return NET_RX_SUCCESS;
473 * dn_route_rx_packet - Try and find a route for an incoming packet
474 * @skb: The packet to find a route for
476 * Returns: result of input function if route is found, error code otherwise
478 static int dn_route_rx_packet(struct sk_buff *skb)
480 struct dn_skb_cb *cb;
483 if ((err = dn_route_input(skb)) == 0)
484 return dst_input(skb);
487 if (decnet_debug_level & 4) {
488 char *devname = skb->dev ? skb->dev->name : "???";
491 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
492 (int)cb->rt_flags, devname, skb->len,
493 le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
497 if ((skb->pkt_type == PACKET_HOST) && (cb->rt_flags & DN_RT_F_RQR)) {
498 switch(cb->rt_flags & DN_RT_PKT_MSK) {
499 case DN_RT_PKT_SHORT:
500 return dn_return_short(skb);
502 return dn_return_long(skb);
510 static int dn_route_rx_long(struct sk_buff *skb)
512 struct dn_skb_cb *cb = DN_SKB_CB(skb);
513 unsigned char *ptr = skb->data;
515 if (!pskb_may_pull(skb, 21)) /* 20 for long header, 1 for shortest nsp */
519 skb_reset_transport_header(skb);
521 /* Destination info */
523 cb->dst = dn_eth2dn(ptr);
524 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
531 cb->src = dn_eth2dn(ptr);
532 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
537 cb->hops = *ptr++; /* Visit Count */
539 return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING, skb, skb->dev, NULL,
549 static int dn_route_rx_short(struct sk_buff *skb)
551 struct dn_skb_cb *cb = DN_SKB_CB(skb);
552 unsigned char *ptr = skb->data;
554 if (!pskb_may_pull(skb, 6)) /* 5 for short header + 1 for shortest nsp */
558 skb_reset_transport_header(skb);
560 cb->dst = *(__le16 *)ptr;
562 cb->src = *(__le16 *)ptr;
564 cb->hops = *ptr & 0x3f;
566 return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING, skb, skb->dev, NULL,
574 static int dn_route_discard(struct sk_buff *skb)
577 * I know we drop the packet here, but thats considered success in
581 return NET_RX_SUCCESS;
584 static int dn_route_ptp_hello(struct sk_buff *skb)
587 dn_neigh_pointopoint_hello(skb);
588 return NET_RX_SUCCESS;
591 int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
593 struct dn_skb_cb *cb;
594 unsigned char flags = 0;
595 __u16 len = le16_to_cpu(*(__le16 *)skb->data);
596 struct dn_dev *dn = rcu_dereference(dev->dn_ptr);
597 unsigned char padlen = 0;
599 if (!net_eq(dev_net(dev), &init_net))
605 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
608 if (!pskb_may_pull(skb, 3))
622 cb->iif = dev->ifindex;
625 * If we have padding, remove it.
627 if (flags & DN_RT_F_PF) {
628 padlen = flags & ~DN_RT_F_PF;
629 if (!pskb_may_pull(skb, padlen + 1))
631 skb_pull(skb, padlen);
635 skb_reset_network_header(skb);
638 * Weed out future version DECnet
640 if (flags & DN_RT_F_VER)
643 cb->rt_flags = flags;
645 if (decnet_debug_level & 1)
647 "dn_route_rcv: got 0x%02x from %s [%d %d %d]\n",
648 (int)flags, (dev) ? dev->name : "???", len, skb->len,
651 if (flags & DN_RT_PKT_CNTL) {
652 if (unlikely(skb_linearize(skb)))
655 switch(flags & DN_RT_CNTL_MSK) {
657 dn_dev_init_pkt(skb);
660 dn_dev_veri_pkt(skb);
664 if (dn->parms.state != DN_DEV_S_RU)
667 switch(flags & DN_RT_CNTL_MSK) {
669 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
675 return NF_HOOK(NFPROTO_DECNET, NF_DN_ROUTE,
679 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
681 dn_neigh_router_hello);
684 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
686 dn_neigh_endnode_hello);
689 if (dn->parms.state != DN_DEV_S_RU)
692 skb_pull(skb, 1); /* Pull flags */
694 switch(flags & DN_RT_PKT_MSK) {
696 return dn_route_rx_long(skb);
697 case DN_RT_PKT_SHORT:
698 return dn_route_rx_short(skb);
708 static int dn_output(struct sk_buff *skb)
710 struct dst_entry *dst = skb_dst(skb);
711 struct dn_route *rt = (struct dn_route *)dst;
712 struct net_device *dev = dst->dev;
713 struct dn_skb_cb *cb = DN_SKB_CB(skb);
714 struct neighbour *neigh;
718 if ((neigh = dst->neighbour) == NULL)
723 cb->src = rt->rt_saddr;
724 cb->dst = rt->rt_daddr;
727 * Always set the Intra-Ethernet bit on all outgoing packets
728 * originated on this node. Only valid flag from upper layers
729 * is return-to-sender-requested. Set hop count to 0 too.
731 cb->rt_flags &= ~DN_RT_F_RQR;
732 cb->rt_flags |= DN_RT_F_IE;
735 return NF_HOOK(NFPROTO_DECNET, NF_DN_LOCAL_OUT, skb, NULL, dev,
740 printk(KERN_DEBUG "dn_output: This should not happen\n");
747 static int dn_forward(struct sk_buff *skb)
749 struct dn_skb_cb *cb = DN_SKB_CB(skb);
750 struct dst_entry *dst = skb_dst(skb);
751 struct dn_dev *dn_db = rcu_dereference(dst->dev->dn_ptr);
753 struct neighbour *neigh = dst->neighbour;
755 #ifdef CONFIG_NETFILTER
756 struct net_device *dev = skb->dev;
759 if (skb->pkt_type != PACKET_HOST)
762 /* Ensure that we have enough space for headers */
763 rt = (struct dn_route *)skb_dst(skb);
764 header_len = dn_db->use_long ? 21 : 6;
765 if (skb_cow(skb, LL_RESERVED_SPACE(rt->dst.dev)+header_len))
769 * Hop count exceeded.
774 skb->dev = rt->dst.dev;
777 * If packet goes out same interface it came in on, then set
778 * the Intra-Ethernet bit. This has no effect for short
779 * packets, so we don't need to test for them here.
781 cb->rt_flags &= ~DN_RT_F_IE;
782 if (rt->rt_flags & RTCF_DOREDIRECT)
783 cb->rt_flags |= DN_RT_F_IE;
785 return NF_HOOK(NFPROTO_DECNET, NF_DN_FORWARD, skb, dev, skb->dev,
794 * Used to catch bugs. This should never normally get
797 static int dn_rt_bug(struct sk_buff *skb)
799 if (net_ratelimit()) {
800 struct dn_skb_cb *cb = DN_SKB_CB(skb);
802 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
803 le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
811 static unsigned int dn_dst_default_advmss(const struct dst_entry *dst)
813 return dn_mss_from_pmtu(dst->dev, dst_mtu(dst));
816 static unsigned int dn_dst_default_mtu(const struct dst_entry *dst)
818 return dst->dev->mtu;
821 static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
823 struct dn_fib_info *fi = res->fi;
824 struct net_device *dev = rt->dst.dev;
825 unsigned int mss_metric;
829 if (DN_FIB_RES_GW(*res) &&
830 DN_FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
831 rt->rt_gateway = DN_FIB_RES_GW(*res);
832 dst_init_metrics(&rt->dst, fi->fib_metrics, true);
834 rt->rt_type = res->type;
836 if (dev != NULL && rt->dst.neighbour == NULL) {
837 n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
840 rt->dst.neighbour = n;
843 if (dst_metric(&rt->dst, RTAX_MTU) > rt->dst.dev->mtu)
844 dst_metric_set(&rt->dst, RTAX_MTU, rt->dst.dev->mtu);
845 mss_metric = dst_metric_raw(&rt->dst, RTAX_ADVMSS);
847 unsigned int mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
848 if (mss_metric > mss)
849 dst_metric_set(&rt->dst, RTAX_ADVMSS, mss);
854 static inline int dn_match_addr(__le16 addr1, __le16 addr2)
856 __u16 tmp = le16_to_cpu(addr1) ^ le16_to_cpu(addr2);
865 static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
868 struct dn_dev *dn_db;
869 struct dn_ifaddr *ifa;
874 dn_db = rcu_dereference(dev->dn_ptr);
875 for (ifa = rcu_dereference(dn_db->ifa_list);
877 ifa = rcu_dereference(ifa->ifa_next)) {
878 if (ifa->ifa_scope > scope)
881 saddr = ifa->ifa_local;
884 ret = dn_match_addr(daddr, ifa->ifa_local);
885 if (ret > best_match)
886 saddr = ifa->ifa_local;
888 saddr = ifa->ifa_local;
895 static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
897 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
900 static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
902 __le16 mask = dnet_make_mask(res->prefixlen);
903 return (daddr&~mask)|res->fi->fib_nh->nh_gw;
906 static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *oldflp, int try_hard)
908 struct flowidn fld = {
909 .daddr = oldflp->daddr,
910 .saddr = oldflp->saddr,
911 .flowidn_scope = RT_SCOPE_UNIVERSE,
912 .flowidn_mark = oldflp->flowidn_mark,
913 .flowidn_iif = init_net.loopback_dev->ifindex,
914 .flowidn_oif = oldflp->flowidn_oif,
916 struct dn_route *rt = NULL;
917 struct net_device *dev_out = NULL, *dev;
918 struct neighbour *neigh = NULL;
921 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
926 if (decnet_debug_level & 16)
928 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
929 " iif=%d oif=%d\n", le16_to_cpu(oldflp->daddr),
930 le16_to_cpu(oldflp->saddr),
931 oldflp->flowidn_mark, init_net.loopback_dev->ifindex,
932 oldflp->flowidn_oif);
934 /* If we have an output interface, verify its a DECnet device */
935 if (oldflp->flowidn_oif) {
936 dev_out = dev_get_by_index(&init_net, oldflp->flowidn_oif);
938 if (dev_out && dev_out->dn_ptr == NULL) {
946 /* If we have a source address, verify that its a local address */
948 err = -EADDRNOTAVAIL;
951 if (dn_dev_islocal(dev_out, oldflp->saddr))
957 for_each_netdev_rcu(&init_net, dev) {
960 if (!dn_dev_islocal(dev, oldflp->saddr))
962 if ((dev->flags & IFF_LOOPBACK) &&
964 !dn_dev_islocal(dev, oldflp->daddr))
978 /* No destination? Assume its local */
980 fld.daddr = fld.saddr;
982 err = -EADDRNOTAVAIL;
985 dev_out = init_net.loopback_dev;
989 fld.saddr = dnet_select_source(dev_out, 0,
994 fld.flowidn_oif = init_net.loopback_dev->ifindex;
995 res.type = RTN_LOCAL;
999 if (decnet_debug_level & 16)
1001 "dn_route_output_slow: initial checks complete."
1002 " dst=%o4x src=%04x oif=%d try_hard=%d\n",
1003 le16_to_cpu(fld.daddr), le16_to_cpu(fld.saddr),
1004 fld.flowidn_oif, try_hard);
1007 * N.B. If the kernel is compiled without router support then
1008 * dn_fib_lookup() will evaluate to non-zero so this if () block
1009 * will always be executed.
1012 if (try_hard || (err = dn_fib_lookup(&fld, &res)) != 0) {
1013 struct dn_dev *dn_db;
1017 * Here the fallback is basically the standard algorithm for
1018 * routing in endnodes which is described in the DECnet routing
1021 * If we are not trying hard, look in neighbour cache.
1022 * The result is tested to ensure that if a specific output
1023 * device/source address was requested, then we honour that
1027 neigh = neigh_lookup_nodev(&dn_neigh_table, &init_net, &fld.daddr);
1029 if ((oldflp->flowidn_oif &&
1030 (neigh->dev->ifindex != oldflp->flowidn_oif)) ||
1032 (!dn_dev_islocal(neigh->dev,
1034 neigh_release(neigh);
1039 if (dn_dev_islocal(neigh->dev, fld.daddr)) {
1040 dev_out = init_net.loopback_dev;
1041 res.type = RTN_LOCAL;
1043 dev_out = neigh->dev;
1051 /* Not there? Perhaps its a local address */
1052 if (dev_out == NULL)
1053 dev_out = dn_dev_get_default();
1055 if (dev_out == NULL)
1057 dn_db = rcu_dereference_raw(dev_out->dn_ptr);
1058 /* Possible improvement - check all devices for local addr */
1059 if (dn_dev_islocal(dev_out, fld.daddr)) {
1061 dev_out = init_net.loopback_dev;
1063 res.type = RTN_LOCAL;
1066 /* Not local either.... try sending it to the default router */
1067 neigh = neigh_clone(dn_db->router);
1068 BUG_ON(neigh && neigh->dev != dev_out);
1070 /* Ok then, we assume its directly connected and move on */
1073 gateway = ((struct dn_neigh *)neigh)->addr;
1075 gateway = fld.daddr;
1076 if (fld.saddr == 0) {
1077 fld.saddr = dnet_select_source(dev_out, gateway,
1078 res.type == RTN_LOCAL ?
1081 if (fld.saddr == 0 && res.type != RTN_LOCAL)
1084 fld.flowidn_oif = dev_out->ifindex;
1089 if (res.type == RTN_NAT)
1092 if (res.type == RTN_LOCAL) {
1094 fld.saddr = fld.daddr;
1097 dev_out = init_net.loopback_dev;
1099 fld.flowidn_oif = dev_out->ifindex;
1101 dn_fib_info_put(res.fi);
1106 if (res.fi->fib_nhs > 1 && fld.flowidn_oif == 0)
1107 dn_fib_select_multipath(&fld, &res);
1110 * We could add some logic to deal with default routes here and
1111 * get rid of some of the special casing above.
1115 fld.saddr = DN_FIB_RES_PREFSRC(res);
1119 dev_out = DN_FIB_RES_DEV(res);
1121 fld.flowidn_oif = dev_out->ifindex;
1122 gateway = DN_FIB_RES_GW(res);
1125 if (dev_out->flags & IFF_LOOPBACK)
1126 flags |= RTCF_LOCAL;
1128 rt = dst_alloc(&dn_dst_ops, 0);
1132 atomic_set(&rt->dst.__refcnt, 1);
1133 rt->dst.flags = DST_HOST;
1135 rt->fld.saddr = oldflp->saddr;
1136 rt->fld.daddr = oldflp->daddr;
1137 rt->fld.flowidn_oif = oldflp->flowidn_oif;
1138 rt->fld.flowidn_iif = 0;
1139 rt->fld.flowidn_mark = oldflp->flowidn_mark;
1141 rt->rt_saddr = fld.saddr;
1142 rt->rt_daddr = fld.daddr;
1143 rt->rt_gateway = gateway ? gateway : fld.daddr;
1144 rt->rt_local_src = fld.saddr;
1146 rt->rt_dst_map = fld.daddr;
1147 rt->rt_src_map = fld.saddr;
1149 rt->dst.dev = dev_out;
1151 rt->dst.neighbour = neigh;
1154 rt->dst.lastuse = jiffies;
1155 rt->dst.output = dn_output;
1156 rt->dst.input = dn_rt_bug;
1157 rt->rt_flags = flags;
1158 if (flags & RTCF_LOCAL)
1159 rt->dst.input = dn_nsp_rx;
1161 err = dn_rt_set_next_hop(rt, &res);
1165 hash = dn_hash(rt->fld.saddr, rt->fld.daddr);
1166 dn_insert_route(rt, hash, (struct dn_route **)pprt);
1170 neigh_release(neigh);
1172 dn_fib_res_put(&res);
1179 err = -EADDRNOTAVAIL;
1194 * N.B. The flags may be moved into the flowi at some future stage.
1196 static int __dn_route_output_key(struct dst_entry **pprt, const struct flowidn *flp, int flags)
1198 unsigned hash = dn_hash(flp->saddr, flp->daddr);
1199 struct dn_route *rt = NULL;
1201 if (!(flags & MSG_TRYHARD)) {
1203 for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
1204 rt = rcu_dereference_bh(rt->dst.dn_next)) {
1205 if ((flp->daddr == rt->fld.daddr) &&
1206 (flp->saddr == rt->fld.saddr) &&
1207 (flp->flowidn_mark == rt->fld.flowidn_mark) &&
1208 dn_is_output_route(rt) &&
1209 (rt->fld.flowidn_oif == flp->flowidn_oif)) {
1210 dst_use(&rt->dst, jiffies);
1211 rcu_read_unlock_bh();
1216 rcu_read_unlock_bh();
1219 return dn_route_output_slow(pprt, flp, flags);
1222 static int dn_route_output_key(struct dst_entry **pprt, struct flowidn *flp, int flags)
1226 err = __dn_route_output_key(pprt, flp, flags);
1227 if (err == 0 && flp->flowidn_proto) {
1228 *pprt = xfrm_lookup(&init_net, *pprt,
1229 flowidn_to_flowi(flp), NULL, 0);
1230 if (IS_ERR(*pprt)) {
1231 err = PTR_ERR(*pprt);
1238 int dn_route_output_sock(struct dst_entry **pprt, struct flowidn *fl, struct sock *sk, int flags)
1242 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1243 if (err == 0 && fl->flowidn_proto) {
1244 if (!(flags & MSG_DONTWAIT))
1245 fl->flowidn_flags |= FLOWI_FLAG_CAN_SLEEP;
1246 *pprt = xfrm_lookup(&init_net, *pprt,
1247 flowidn_to_flowi(fl), sk, 0);
1248 if (IS_ERR(*pprt)) {
1249 err = PTR_ERR(*pprt);
1256 static int dn_route_input_slow(struct sk_buff *skb)
1258 struct dn_route *rt = NULL;
1259 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1260 struct net_device *in_dev = skb->dev;
1261 struct net_device *out_dev = NULL;
1262 struct dn_dev *dn_db;
1263 struct neighbour *neigh = NULL;
1267 __le16 local_src = 0;
1268 struct flowidn fld = {
1271 .flowidn_scope = RT_SCOPE_UNIVERSE,
1272 .flowidn_mark = skb->mark,
1273 .flowidn_iif = skb->dev->ifindex,
1275 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
1281 if ((dn_db = rcu_dereference(in_dev->dn_ptr)) == NULL)
1284 /* Zero source addresses are not allowed */
1289 * In this case we've just received a packet from a source
1290 * outside ourselves pretending to come from us. We don't
1291 * allow it any further to prevent routing loops, spoofing and
1292 * other nasties. Loopback packets already have the dst attached
1293 * so this only affects packets which have originated elsewhere.
1296 if (dn_dev_islocal(in_dev, cb->src))
1299 err = dn_fib_lookup(&fld, &res);
1304 * Is the destination us ?
1306 if (!dn_dev_islocal(in_dev, cb->dst))
1309 res.type = RTN_LOCAL;
1311 __le16 src_map = fld.saddr;
1314 out_dev = DN_FIB_RES_DEV(res);
1315 if (out_dev == NULL) {
1316 if (net_ratelimit())
1317 printk(KERN_CRIT "Bug in dn_route_input_slow() "
1318 "No output device\n");
1324 src_map = fld.saddr; /* no NAT support for now */
1326 gateway = DN_FIB_RES_GW(res);
1327 if (res.type == RTN_NAT) {
1328 fld.daddr = dn_fib_rules_map_destination(fld.daddr, &res);
1329 dn_fib_res_put(&res);
1331 if (dn_fib_lookup(&fld, &res))
1334 if (res.type != RTN_UNICAST)
1337 gateway = fld.daddr;
1339 fld.saddr = src_map;
1345 * Forwarding check here, we only check for forwarding
1346 * being turned off, if you want to only forward intra
1347 * area, its up to you to set the routing tables up
1350 if (dn_db->parms.forwarding == 0)
1353 if (res.fi->fib_nhs > 1 && fld.flowidn_oif == 0)
1354 dn_fib_select_multipath(&fld, &res);
1357 * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
1358 * flag as a hint to set the intra-ethernet bit when
1359 * forwarding. If we've got NAT in operation, we don't do
1360 * this optimisation.
1362 if (out_dev == in_dev && !(flags & RTCF_NAT))
1363 flags |= RTCF_DOREDIRECT;
1365 local_src = DN_FIB_RES_PREFSRC(res);
1368 case RTN_UNREACHABLE:
1371 flags |= RTCF_LOCAL;
1372 fld.saddr = cb->dst;
1373 fld.daddr = cb->src;
1375 /* Routing tables gave us a gateway */
1379 /* Packet was intra-ethernet, so we know its on-link */
1380 if (cb->rt_flags & DN_RT_F_IE) {
1382 flags |= RTCF_DIRECTSRC;
1386 /* Use the default router if there is one */
1387 neigh = neigh_clone(dn_db->router);
1389 gateway = ((struct dn_neigh *)neigh)->addr;
1393 /* Close eyes and pray */
1395 flags |= RTCF_DIRECTSRC;
1402 rt = dst_alloc(&dn_dst_ops, 0);
1406 rt->rt_saddr = fld.saddr;
1407 rt->rt_daddr = fld.daddr;
1408 rt->rt_gateway = fld.daddr;
1410 rt->rt_gateway = gateway;
1411 rt->rt_local_src = local_src ? local_src : rt->rt_saddr;
1413 rt->rt_dst_map = fld.daddr;
1414 rt->rt_src_map = fld.saddr;
1416 rt->fld.saddr = cb->src;
1417 rt->fld.daddr = cb->dst;
1418 rt->fld.flowidn_oif = 0;
1419 rt->fld.flowidn_iif = in_dev->ifindex;
1420 rt->fld.flowidn_mark = fld.flowidn_mark;
1422 rt->dst.flags = DST_HOST;
1423 rt->dst.neighbour = neigh;
1424 rt->dst.dev = out_dev;
1425 rt->dst.lastuse = jiffies;
1426 rt->dst.output = dn_rt_bug;
1429 rt->dst.input = dn_forward;
1432 rt->dst.output = dn_output;
1433 rt->dst.input = dn_nsp_rx;
1434 rt->dst.dev = in_dev;
1435 flags |= RTCF_LOCAL;
1438 case RTN_UNREACHABLE:
1440 rt->dst.input = dst_discard;
1442 rt->rt_flags = flags;
1444 dev_hold(rt->dst.dev);
1446 err = dn_rt_set_next_hop(rt, &res);
1450 hash = dn_hash(rt->fld.saddr, rt->fld.daddr);
1451 dn_insert_route(rt, hash, &rt);
1452 skb_dst_set(skb, &rt->dst);
1456 neigh_release(neigh);
1458 dn_fib_res_put(&res);
1478 static int dn_route_input(struct sk_buff *skb)
1480 struct dn_route *rt;
1481 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1482 unsigned hash = dn_hash(cb->src, cb->dst);
1488 for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt != NULL;
1489 rt = rcu_dereference(rt->dst.dn_next)) {
1490 if ((rt->fld.saddr == cb->src) &&
1491 (rt->fld.daddr == cb->dst) &&
1492 (rt->fld.flowidn_oif == 0) &&
1493 (rt->fld.flowidn_mark == skb->mark) &&
1494 (rt->fld.flowidn_iif == cb->iif)) {
1495 dst_use(&rt->dst, jiffies);
1497 skb_dst_set(skb, (struct dst_entry *)rt);
1503 return dn_route_input_slow(skb);
1506 static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1507 int event, int nowait, unsigned int flags)
1509 struct dn_route *rt = (struct dn_route *)skb_dst(skb);
1511 struct nlmsghdr *nlh;
1512 unsigned char *b = skb_tail_pointer(skb);
1515 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
1516 r = NLMSG_DATA(nlh);
1517 r->rtm_family = AF_DECnet;
1518 r->rtm_dst_len = 16;
1521 r->rtm_table = RT_TABLE_MAIN;
1522 RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
1523 r->rtm_type = rt->rt_type;
1524 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1525 r->rtm_scope = RT_SCOPE_UNIVERSE;
1526 r->rtm_protocol = RTPROT_UNSPEC;
1527 if (rt->rt_flags & RTCF_NOTIFY)
1528 r->rtm_flags |= RTM_F_NOTIFY;
1529 RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr);
1530 if (rt->fld.saddr) {
1531 r->rtm_src_len = 16;
1532 RTA_PUT(skb, RTA_SRC, 2, &rt->fld.saddr);
1535 RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->dst.dev->ifindex);
1537 * Note to self - change this if input routes reverse direction when
1538 * they deal only with inputs and not with replies like they do
1541 RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src);
1542 if (rt->rt_daddr != rt->rt_gateway)
1543 RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway);
1544 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
1545 goto rtattr_failure;
1546 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
1547 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires,
1549 goto rtattr_failure;
1550 if (dn_is_input_route(rt))
1551 RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fld.flowidn_iif);
1553 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1563 * This is called by both endnodes and routers now.
1565 static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
1567 struct net *net = sock_net(in_skb->sk);
1568 struct rtattr **rta = arg;
1569 struct rtmsg *rtm = NLMSG_DATA(nlh);
1570 struct dn_route *rt = NULL;
1571 struct dn_skb_cb *cb;
1573 struct sk_buff *skb;
1576 if (!net_eq(net, &init_net))
1579 memset(&fld, 0, sizeof(fld));
1580 fld.flowidn_proto = DNPROTO_NSP;
1582 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1585 skb_reset_mac_header(skb);
1586 cb = DN_SKB_CB(skb);
1589 memcpy(&fld.saddr, RTA_DATA(rta[RTA_SRC-1]), 2);
1591 memcpy(&fld.daddr, RTA_DATA(rta[RTA_DST-1]), 2);
1593 memcpy(&fld.flowidn_iif, RTA_DATA(rta[RTA_IIF-1]), sizeof(int));
1595 if (fld.flowidn_iif) {
1596 struct net_device *dev;
1597 if ((dev = dev_get_by_index(&init_net, fld.flowidn_iif)) == NULL) {
1606 skb->protocol = htons(ETH_P_DNA_RT);
1608 cb->src = fld.saddr;
1609 cb->dst = fld.daddr;
1611 err = dn_route_input(skb);
1613 memset(cb, 0, sizeof(struct dn_skb_cb));
1614 rt = (struct dn_route *)skb_dst(skb);
1615 if (!err && -rt->dst.error)
1616 err = rt->dst.error;
1619 if (rta[RTA_OIF - 1])
1620 memcpy(&oif, RTA_DATA(rta[RTA_OIF - 1]), sizeof(int));
1621 fld.flowidn_oif = oif;
1622 err = dn_route_output_key((struct dst_entry **)&rt, &fld, 0);
1630 skb_dst_set(skb, &rt->dst);
1631 if (rtm->rtm_flags & RTM_F_NOTIFY)
1632 rt->rt_flags |= RTCF_NOTIFY;
1634 err = dn_rt_fill_info(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq, RTM_NEWROUTE, 0, 0);
1643 return rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
1651 * For routers, this is called from dn_fib_dump, but for endnodes its
1652 * called directly from the rtnetlink dispatch table.
1654 int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1656 struct net *net = sock_net(skb->sk);
1657 struct dn_route *rt;
1661 if (!net_eq(net, &init_net))
1664 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
1666 if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
1670 s_idx = idx = cb->args[1];
1671 for(h = 0; h <= dn_rt_hash_mask; h++) {
1677 for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
1679 rt = rcu_dereference_bh(rt->dst.dn_next), idx++) {
1682 skb_dst_set(skb, dst_clone(&rt->dst));
1683 if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
1684 cb->nlh->nlmsg_seq, RTM_NEWROUTE,
1685 1, NLM_F_MULTI) <= 0) {
1687 rcu_read_unlock_bh();
1692 rcu_read_unlock_bh();
1701 #ifdef CONFIG_PROC_FS
1702 struct dn_rt_cache_iter_state {
1706 static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
1708 struct dn_route *rt = NULL;
1709 struct dn_rt_cache_iter_state *s = seq->private;
1711 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
1713 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
1716 rcu_read_unlock_bh();
1721 static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
1723 struct dn_rt_cache_iter_state *s = seq->private;
1725 rt = rcu_dereference_bh(rt->dst.dn_next);
1727 rcu_read_unlock_bh();
1728 if (--s->bucket < 0)
1731 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
1736 static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
1738 struct dn_route *rt = dn_rt_cache_get_first(seq);
1741 while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
1744 return *pos ? NULL : rt;
1747 static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1749 struct dn_route *rt = dn_rt_cache_get_next(seq, v);
1754 static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
1757 rcu_read_unlock_bh();
1760 static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
1762 struct dn_route *rt = v;
1763 char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
1765 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
1766 rt->dst.dev ? rt->dst.dev->name : "*",
1767 dn_addr2asc(le16_to_cpu(rt->rt_daddr), buf1),
1768 dn_addr2asc(le16_to_cpu(rt->rt_saddr), buf2),
1769 atomic_read(&rt->dst.__refcnt),
1771 (int) dst_metric(&rt->dst, RTAX_RTT));
1775 static const struct seq_operations dn_rt_cache_seq_ops = {
1776 .start = dn_rt_cache_seq_start,
1777 .next = dn_rt_cache_seq_next,
1778 .stop = dn_rt_cache_seq_stop,
1779 .show = dn_rt_cache_seq_show,
1782 static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
1784 return seq_open_private(file, &dn_rt_cache_seq_ops,
1785 sizeof(struct dn_rt_cache_iter_state));
1788 static const struct file_operations dn_rt_cache_seq_fops = {
1789 .owner = THIS_MODULE,
1790 .open = dn_rt_cache_seq_open,
1792 .llseek = seq_lseek,
1793 .release = seq_release_private,
1796 #endif /* CONFIG_PROC_FS */
1798 void __init dn_route_init(void)
1802 dn_dst_ops.kmem_cachep =
1803 kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
1804 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
1805 dst_entries_init(&dn_dst_ops);
1806 setup_timer(&dn_route_timer, dn_dst_check_expire, 0);
1807 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1808 add_timer(&dn_route_timer);
1810 goal = totalram_pages >> (26 - PAGE_SHIFT);
1812 for(order = 0; (1UL << order) < goal; order++)
1816 * Only want 1024 entries max, since the table is very, very unlikely
1817 * to be larger than that.
1819 while(order && ((((1UL << order) * PAGE_SIZE) /
1820 sizeof(struct dn_rt_hash_bucket)) >= 2048))
1824 dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
1825 sizeof(struct dn_rt_hash_bucket);
1826 while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
1828 dn_rt_hash_table = (struct dn_rt_hash_bucket *)
1829 __get_free_pages(GFP_ATOMIC, order);
1830 } while (dn_rt_hash_table == NULL && --order > 0);
1832 if (!dn_rt_hash_table)
1833 panic("Failed to allocate DECnet route cache hash table\n");
1836 "DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
1838 (long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
1841 for(i = 0; i <= dn_rt_hash_mask; i++) {
1842 spin_lock_init(&dn_rt_hash_table[i].lock);
1843 dn_rt_hash_table[i].chain = NULL;
1846 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
1848 proc_net_fops_create(&init_net, "decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
1850 #ifdef CONFIG_DECNET_ROUTER
1851 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute, dn_fib_dump);
1853 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute,
1858 void __exit dn_route_cleanup(void)
1860 del_timer(&dn_route_timer);
1863 proc_net_remove(&init_net, "decnet_cache");
1864 dst_entries_destroy(&dn_dst_ops);