3 * DECnet An implementation of the DECnet protocol suite for the LINUX
4 * operating system. DECnet is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
7 * DECnet Routing Functions (Endnode and Router)
9 * Authors: Steve Whitehouse <SteveW@ACM.org>
10 * Eduardo Marcelo Serrat <emserrat@geocities.com>
13 * Steve Whitehouse : Fixes to allow "intra-ethernet" and
14 * "return-to-sender" bits on outgoing
16 * Steve Whitehouse : Timeouts for cached routes.
17 * Steve Whitehouse : Use dst cache for input routes too.
18 * Steve Whitehouse : Fixed error values in dn_send_skb.
19 * Steve Whitehouse : Rework routing functions to better fit
20 * DECnet routing design
21 * Alexey Kuznetsov : New SMP locking
22 * Steve Whitehouse : More SMP locking changes & dn_cache_dump()
23 * Steve Whitehouse : Prerouting NF hook, now really is prerouting.
24 * Fixed possible skb leak in rtnetlink funcs.
25 * Steve Whitehouse : Dave Miller's dynamic hash table sizing and
26 * Alexey Kuznetsov's finer grained locking
28 * Steve Whitehouse : Routing is now starting to look like a
29 * sensible set of code now, mainly due to
30 * my copying the IPv4 routing code. The
31 * hooks here are modified and will continue
32 * to evolve for a while.
33 * Steve Whitehouse : Real SMP at last :-) Also new netfilter
34 * stuff. Look out raw sockets your days
36 * Steve Whitehouse : Added return-to-sender functions. Added
37 * backlog congestion level return codes.
38 * Steve Whitehouse : Fixed bug where routes were set up with
39 * no ref count on net devices.
40 * Steve Whitehouse : RCU for the route cache
41 * Steve Whitehouse : Preparations for the flow cache
42 * Steve Whitehouse : Prepare for nonlinear skbs
45 /******************************************************************************
46 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
48 This program is free software; you can redistribute it and/or modify
49 it under the terms of the GNU General Public License as published by
50 the Free Software Foundation; either version 2 of the License, or
53 This program is distributed in the hope that it will be useful,
54 but WITHOUT ANY WARRANTY; without even the implied warranty of
55 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 GNU General Public License for more details.
57 *******************************************************************************/
59 #include <linux/config.h>
60 #include <linux/errno.h>
61 #include <linux/types.h>
62 #include <linux/socket.h>
64 #include <linux/kernel.h>
65 #include <linux/sockios.h>
66 #include <linux/net.h>
67 #include <linux/netdevice.h>
68 #include <linux/inet.h>
69 #include <linux/route.h>
70 #include <linux/in_route.h>
73 #include <linux/proc_fs.h>
74 #include <linux/seq_file.h>
75 #include <linux/init.h>
76 #include <linux/rtnetlink.h>
77 #include <linux/string.h>
78 #include <linux/netfilter_decnet.h>
79 #include <linux/rcupdate.h>
80 #include <linux/times.h>
81 #include <asm/errno.h>
82 #include <net/neighbour.h>
86 #include <net/dn_dev.h>
87 #include <net/dn_nsp.h>
88 #include <net/dn_route.h>
89 #include <net/dn_neigh.h>
90 #include <net/dn_fib.h>
92 struct dn_rt_hash_bucket
94 struct dn_route *chain;
96 } __attribute__((__aligned__(8)));
98 extern struct neigh_table dn_neigh_table;
101 static unsigned char dn_hiord_addr[6] = {0xAA,0x00,0x04,0x00,0x00,0x00};
103 int dn_rt_min_delay = 2 * HZ;
104 int dn_rt_max_delay = 10 * HZ;
105 int dn_rt_mtu_expires = 10 * 60 * HZ;
107 static unsigned long dn_rt_deadline;
109 static int dn_dst_gc(void);
110 static struct dst_entry *dn_dst_check(struct dst_entry *, __u32);
111 static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
112 static void dn_dst_link_failure(struct sk_buff *);
113 static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
114 static int dn_route_input(struct sk_buff *);
115 static void dn_run_flush(unsigned long dummy);
117 static struct dn_rt_hash_bucket *dn_rt_hash_table;
118 static unsigned dn_rt_hash_mask;
120 static struct timer_list dn_route_timer;
121 static struct timer_list dn_rt_flush_timer =
122 TIMER_INITIALIZER(dn_run_flush, 0, 0);
123 int decnet_dst_gc_interval = 2;
125 static struct dst_ops dn_dst_ops = {
127 .protocol = __constant_htons(ETH_P_DNA_RT),
130 .check = dn_dst_check,
131 .negative_advice = dn_dst_negative_advice,
132 .link_failure = dn_dst_link_failure,
133 .update_pmtu = dn_dst_update_pmtu,
134 .entry_size = sizeof(struct dn_route),
135 .entries = ATOMIC_INIT(0),
138 static __inline__ unsigned dn_hash(unsigned short src, unsigned short dst)
140 unsigned short tmp = src ^ dst;
144 return dn_rt_hash_mask & (unsigned)tmp;
147 static inline void dnrt_free(struct dn_route *rt)
149 call_rcu(&rt->u.dst.rcu_head, dst_rcu_free);
152 static inline void dnrt_drop(struct dn_route *rt)
155 dst_release(&rt->u.dst);
156 call_rcu(&rt->u.dst.rcu_head, dst_rcu_free);
159 static void dn_dst_check_expire(unsigned long dummy)
162 struct dn_route *rt, **rtp;
163 unsigned long now = jiffies;
164 unsigned long expire = 120 * HZ;
166 for(i = 0; i <= dn_rt_hash_mask; i++) {
167 rtp = &dn_rt_hash_table[i].chain;
169 spin_lock(&dn_rt_hash_table[i].lock);
170 while((rt=*rtp) != NULL) {
171 if (atomic_read(&rt->u.dst.__refcnt) ||
172 (now - rt->u.dst.lastuse) < expire) {
173 rtp = &rt->u.rt_next;
176 *rtp = rt->u.rt_next;
177 rt->u.rt_next = NULL;
180 spin_unlock(&dn_rt_hash_table[i].lock);
182 if ((jiffies - now) > 0)
186 mod_timer(&dn_route_timer, now + decnet_dst_gc_interval * HZ);
189 static int dn_dst_gc(void)
191 struct dn_route *rt, **rtp;
193 unsigned long now = jiffies;
194 unsigned long expire = 10 * HZ;
196 for(i = 0; i <= dn_rt_hash_mask; i++) {
198 spin_lock_bh(&dn_rt_hash_table[i].lock);
199 rtp = &dn_rt_hash_table[i].chain;
201 while((rt=*rtp) != NULL) {
202 if (atomic_read(&rt->u.dst.__refcnt) ||
203 (now - rt->u.dst.lastuse) < expire) {
204 rtp = &rt->u.rt_next;
207 *rtp = rt->u.rt_next;
208 rt->u.rt_next = NULL;
212 spin_unlock_bh(&dn_rt_hash_table[i].lock);
219 * The decnet standards don't impose a particular minimum mtu, what they
220 * do insist on is that the routing layer accepts a datagram of at least
221 * 230 bytes long. Here we have to subtract the routing header length from
222 * 230 to get the minimum acceptable mtu. If there is no neighbour, then we
223 * assume the worst and use a long header size.
225 * We update both the mtu and the advertised mss (i.e. the segment size we
226 * advertise to the other end).
228 static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)
231 struct dn_dev *dn = dst->neighbour ?
232 (struct dn_dev *)dst->neighbour->dev->dn_ptr : NULL;
234 if (dn && dn->use_long == 0)
239 if (dst->metrics[RTAX_MTU-1] > mtu && mtu >= min_mtu) {
240 if (!(dst_metric_locked(dst, RTAX_MTU))) {
241 dst->metrics[RTAX_MTU-1] = mtu;
242 dst_set_expires(dst, dn_rt_mtu_expires);
244 if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
245 u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
246 if (dst->metrics[RTAX_ADVMSS-1] > mss)
247 dst->metrics[RTAX_ADVMSS-1] = mss;
253 * When a route has been marked obsolete. (e.g. routing cache flush)
255 static struct dst_entry *dn_dst_check(struct dst_entry *dst, __u32 cookie)
261 static struct dst_entry *dn_dst_negative_advice(struct dst_entry *dst)
267 static void dn_dst_link_failure(struct sk_buff *skb)
272 static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
274 return memcmp(&fl1->nl_u.dn_u, &fl2->nl_u.dn_u, sizeof(fl1->nl_u.dn_u)) == 0 &&
275 fl1->oif == fl2->oif &&
276 fl1->iif == fl2->iif;
279 static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp)
281 struct dn_route *rth, **rthp;
282 unsigned long now = jiffies;
284 rthp = &dn_rt_hash_table[hash].chain;
286 spin_lock_bh(&dn_rt_hash_table[hash].lock);
287 while((rth = *rthp) != NULL) {
288 if (compare_keys(&rth->fl, &rt->fl)) {
290 *rthp = rth->u.rt_next;
292 rth->u.rt_next = dn_rt_hash_table[hash].chain;
294 dn_rt_hash_table[hash].chain = rth;
297 dst_hold(&rth->u.dst);
298 rth->u.dst.lastuse = now;
299 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
305 rthp = &rth->u.rt_next;
309 rt->u.rt_next = dn_rt_hash_table[hash].chain;
311 dn_rt_hash_table[hash].chain = rt;
313 dst_hold(&rt->u.dst);
315 rt->u.dst.lastuse = now;
316 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
321 void dn_run_flush(unsigned long dummy)
324 struct dn_route *rt, *next;
326 for(i = 0; i < dn_rt_hash_mask; i++) {
327 spin_lock_bh(&dn_rt_hash_table[i].lock);
329 if ((rt = xchg(&dn_rt_hash_table[i].chain, NULL)) == NULL)
330 goto nothing_to_declare;
333 next = rt->u.rt_next;
334 rt->u.rt_next = NULL;
335 dst_free((struct dst_entry *)rt);
339 spin_unlock_bh(&dn_rt_hash_table[i].lock);
343 static spinlock_t dn_rt_flush_lock = SPIN_LOCK_UNLOCKED;
345 void dn_rt_cache_flush(int delay)
347 unsigned long now = jiffies;
348 int user_mode = !in_interrupt();
351 delay = dn_rt_min_delay;
353 spin_lock_bh(&dn_rt_flush_lock);
355 if (del_timer(&dn_rt_flush_timer) && delay > 0 && dn_rt_deadline) {
356 long tmo = (long)(dn_rt_deadline - now);
358 if (user_mode && tmo < dn_rt_max_delay - dn_rt_min_delay)
366 spin_unlock_bh(&dn_rt_flush_lock);
371 if (dn_rt_deadline == 0)
372 dn_rt_deadline = now + dn_rt_max_delay;
374 dn_rt_flush_timer.expires = now + delay;
375 add_timer(&dn_rt_flush_timer);
376 spin_unlock_bh(&dn_rt_flush_lock);
380 * dn_return_short - Return a short packet to its sender
381 * @skb: The packet to return
384 static int dn_return_short(struct sk_buff *skb)
386 struct dn_skb_cb *cb;
392 /* Add back headers */
393 skb_push(skb, skb->data - skb->nh.raw);
395 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
399 /* Skip packet length and point to flags */
401 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
403 dst = (dn_address *)ptr;
405 src = (dn_address *)ptr;
407 *ptr = 0; /* Zero hop count */
409 /* Swap source and destination */
414 skb->pkt_type = PACKET_OUTGOING;
415 dn_rt_finish_output(skb, NULL, NULL);
416 return NET_RX_SUCCESS;
420 * dn_return_long - Return a long packet to its sender
421 * @skb: The long format packet to return
424 static int dn_return_long(struct sk_buff *skb)
426 struct dn_skb_cb *cb;
428 unsigned char *src_addr, *dst_addr;
429 unsigned char tmp[ETH_ALEN];
431 /* Add back all headers */
432 skb_push(skb, skb->data - skb->nh.raw);
434 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
438 /* Ignore packet length and point to flags */
442 if (*ptr & DN_RT_F_PF) {
443 char padlen = (*ptr & ~DN_RT_F_PF);
447 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
453 *ptr = 0; /* Zero hop count */
455 /* Swap source and destination */
456 memcpy(tmp, src_addr, ETH_ALEN);
457 memcpy(src_addr, dst_addr, ETH_ALEN);
458 memcpy(dst_addr, tmp, ETH_ALEN);
460 skb->pkt_type = PACKET_OUTGOING;
461 dn_rt_finish_output(skb, dst_addr, src_addr);
462 return NET_RX_SUCCESS;
466 * dn_route_rx_packet - Try and find a route for an incoming packet
467 * @skb: The packet to find a route for
469 * Returns: result of input function if route is found, error code otherwise
471 static int dn_route_rx_packet(struct sk_buff *skb)
473 struct dn_skb_cb *cb = DN_SKB_CB(skb);
476 if ((err = dn_route_input(skb)) == 0)
477 return dst_input(skb);
479 if (decnet_debug_level & 4) {
480 char *devname = skb->dev ? skb->dev->name : "???";
481 struct dn_skb_cb *cb = DN_SKB_CB(skb);
483 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
484 (int)cb->rt_flags, devname, skb->len, cb->src, cb->dst,
488 if ((skb->pkt_type == PACKET_HOST) && (cb->rt_flags & DN_RT_F_RQR)) {
489 switch(cb->rt_flags & DN_RT_PKT_MSK) {
490 case DN_RT_PKT_SHORT:
491 return dn_return_short(skb);
493 return dn_return_long(skb);
501 static int dn_route_rx_long(struct sk_buff *skb)
503 struct dn_skb_cb *cb = DN_SKB_CB(skb);
504 unsigned char *ptr = skb->data;
506 if (!pskb_may_pull(skb, 21)) /* 20 for long header, 1 for shortest nsp */
510 skb->h.raw = skb->data;
512 /* Destination info */
514 cb->dst = dn_htons(dn_eth2dn(ptr));
515 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
522 cb->src = dn_htons(dn_eth2dn(ptr));
523 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
528 cb->hops = *ptr++; /* Visit Count */
530 return NF_HOOK(PF_DECnet, NF_DN_PRE_ROUTING, skb, skb->dev, NULL, dn_route_rx_packet);
539 static int dn_route_rx_short(struct sk_buff *skb)
541 struct dn_skb_cb *cb = DN_SKB_CB(skb);
542 unsigned char *ptr = skb->data;
544 if (!pskb_may_pull(skb, 6)) /* 5 for short header + 1 for shortest nsp */
548 skb->h.raw = skb->data;
550 cb->dst = *(dn_address *)ptr;
552 cb->src = *(dn_address *)ptr;
554 cb->hops = *ptr & 0x3f;
556 return NF_HOOK(PF_DECnet, NF_DN_PRE_ROUTING, skb, skb->dev, NULL, dn_route_rx_packet);
563 static int dn_route_discard(struct sk_buff *skb)
566 * I know we drop the packet here, but thats considered success in
570 return NET_RX_SUCCESS;
573 static int dn_route_ptp_hello(struct sk_buff *skb)
576 dn_neigh_pointopoint_hello(skb);
577 return NET_RX_SUCCESS;
580 int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
582 struct dn_skb_cb *cb;
583 unsigned char flags = 0;
584 __u16 len = dn_ntohs(*(__u16 *)skb->data);
585 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr;
586 unsigned char padlen = 0;
591 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
594 if (!pskb_may_pull(skb, 3))
608 cb->iif = dev->ifindex;
611 * If we have padding, remove it.
613 if (flags & DN_RT_F_PF) {
614 padlen = flags & ~DN_RT_F_PF;
615 if (!pskb_may_pull(skb, padlen + 1))
617 skb_pull(skb, padlen);
621 skb->nh.raw = skb->data;
624 * Weed out future version DECnet
626 if (flags & DN_RT_F_VER)
629 cb->rt_flags = flags;
631 if (decnet_debug_level & 1)
633 "dn_route_rcv: got 0x%02x from %s [%d %d %d]\n",
634 (int)flags, (dev) ? dev->name : "???", len, skb->len,
637 if (flags & DN_RT_PKT_CNTL) {
638 if (unlikely(skb_is_nonlinear(skb)) &&
639 skb_linearize(skb, GFP_ATOMIC) != 0)
642 switch(flags & DN_RT_CNTL_MSK) {
644 dn_dev_init_pkt(skb);
647 dn_dev_veri_pkt(skb);
651 if (dn->parms.state != DN_DEV_S_RU)
654 switch(flags & DN_RT_CNTL_MSK) {
656 return NF_HOOK(PF_DECnet, NF_DN_HELLO, skb, skb->dev, NULL, dn_route_ptp_hello);
660 return NF_HOOK(PF_DECnet, NF_DN_ROUTE, skb, skb->dev, NULL, dn_route_discard);
662 return NF_HOOK(PF_DECnet, NF_DN_HELLO, skb, skb->dev, NULL, dn_neigh_router_hello);
665 return NF_HOOK(PF_DECnet, NF_DN_HELLO, skb, skb->dev, NULL, dn_neigh_endnode_hello);
668 if (dn->parms.state != DN_DEV_S_RU)
671 skb_pull(skb, 1); /* Pull flags */
673 switch(flags & DN_RT_PKT_MSK) {
675 return dn_route_rx_long(skb);
676 case DN_RT_PKT_SHORT:
677 return dn_route_rx_short(skb);
687 static int dn_output(struct sk_buff **pskb)
689 struct sk_buff *skb = *pskb;
690 struct dst_entry *dst = skb->dst;
691 struct dn_route *rt = (struct dn_route *)dst;
692 struct net_device *dev = dst->dev;
693 struct dn_skb_cb *cb = DN_SKB_CB(skb);
694 struct neighbour *neigh;
698 if ((neigh = dst->neighbour) == NULL)
703 cb->src = rt->rt_saddr;
704 cb->dst = rt->rt_daddr;
707 * Always set the Intra-Ethernet bit on all outgoing packets
708 * originated on this node. Only valid flag from upper layers
709 * is return-to-sender-requested. Set hop count to 0 too.
711 cb->rt_flags &= ~DN_RT_F_RQR;
712 cb->rt_flags |= DN_RT_F_IE;
715 return NF_HOOK(PF_DECnet, NF_DN_LOCAL_OUT, skb, NULL, dev, neigh->output);
719 printk(KERN_DEBUG "dn_output: This should not happen\n");
726 static int dn_forward(struct sk_buff *skb)
728 struct dn_skb_cb *cb = DN_SKB_CB(skb);
729 struct dst_entry *dst = skb->dst;
730 struct dn_dev *dn_db = dst->dev->dn_ptr;
732 struct neighbour *neigh = dst->neighbour;
734 #ifdef CONFIG_NETFILTER
735 struct net_device *dev = skb->dev;
738 if (skb->pkt_type != PACKET_HOST)
741 /* Ensure that we have enough space for headers */
742 rt = (struct dn_route *)skb->dst;
743 header_len = dn_db->use_long ? 21 : 6;
744 if (skb_cow(skb, LL_RESERVED_SPACE(rt->u.dst.dev)+header_len))
748 * Hop count exceeded.
753 skb->dev = rt->u.dst.dev;
756 * If packet goes out same interface it came in on, then set
757 * the Intra-Ethernet bit. This has no effect for short
758 * packets, so we don't need to test for them here.
760 cb->rt_flags &= ~DN_RT_F_IE;
761 if (rt->rt_flags & RTCF_DOREDIRECT)
762 cb->rt_flags |= DN_RT_F_IE;
764 return NF_HOOK(PF_DECnet, NF_DN_FORWARD, skb, dev, skb->dev, neigh->output);
772 * Drop packet. This is used for endnodes and for
773 * when we should not be forwarding packets from
776 static int dn_blackhole(struct sk_buff *skb)
783 * Used to catch bugs. This should never normally get
786 static int dn_rt_bug(struct sk_buff *skb)
788 if (net_ratelimit()) {
789 struct dn_skb_cb *cb = DN_SKB_CB(skb);
791 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
800 static int dn_rt_bug_out(struct sk_buff **pskb)
802 return dn_rt_bug(*pskb);
805 static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
807 struct dn_fib_info *fi = res->fi;
808 struct net_device *dev = rt->u.dst.dev;
813 if (DN_FIB_RES_GW(*res) &&
814 DN_FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
815 rt->rt_gateway = DN_FIB_RES_GW(*res);
816 memcpy(rt->u.dst.metrics, fi->fib_metrics,
817 sizeof(rt->u.dst.metrics));
819 rt->rt_type = res->type;
821 if (dev != NULL && rt->u.dst.neighbour == NULL) {
822 n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
825 rt->u.dst.neighbour = n;
828 if (rt->u.dst.metrics[RTAX_MTU-1] == 0 ||
829 rt->u.dst.metrics[RTAX_MTU-1] > rt->u.dst.dev->mtu)
830 rt->u.dst.metrics[RTAX_MTU-1] = rt->u.dst.dev->mtu;
831 mss = dn_mss_from_pmtu(dev, dst_pmtu(&rt->u.dst));
832 if (rt->u.dst.metrics[RTAX_ADVMSS-1] == 0 ||
833 rt->u.dst.metrics[RTAX_ADVMSS-1] > mss)
834 rt->u.dst.metrics[RTAX_ADVMSS-1] = mss;
838 static inline int dn_match_addr(__u16 addr1, __u16 addr2)
840 __u16 tmp = dn_ntohs(addr1) ^ dn_ntohs(addr2);
849 static __u16 dnet_select_source(const struct net_device *dev, __u16 daddr, int scope)
852 struct dn_dev *dn_db = dev->dn_ptr;
853 struct dn_ifaddr *ifa;
857 read_lock(&dev_base_lock);
858 for(ifa = dn_db->ifa_list; ifa; ifa = ifa->ifa_next) {
859 if (ifa->ifa_scope > scope)
862 saddr = ifa->ifa_local;
865 ret = dn_match_addr(daddr, ifa->ifa_local);
866 if (ret > best_match)
867 saddr = ifa->ifa_local;
869 saddr = ifa->ifa_local;
871 read_unlock(&dev_base_lock);
876 static inline __u16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
878 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
881 static inline __u16 dn_fib_rules_map_destination(__u16 daddr, struct dn_fib_res *res)
883 __u16 mask = dnet_make_mask(res->prefixlen);
884 return (daddr&~mask)|res->fi->fib_nh->nh_gw;
887 static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *oldflp, int try_hard)
889 struct flowi fl = { .nl_u = { .dn_u =
890 { .daddr = oldflp->fld_dst,
891 .saddr = oldflp->fld_src,
892 .scope = RT_SCOPE_UNIVERSE,
893 #ifdef CONFIG_DECNET_ROUTE_FWMARK
894 .fwmark = oldflp->fld_fwmark
897 .iif = loopback_dev.ifindex,
898 .oif = oldflp->oif };
899 struct dn_route *rt = NULL;
900 struct net_device *dev_out = NULL;
901 struct neighbour *neigh = NULL;
904 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
909 if (decnet_debug_level & 16)
911 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
912 " iif=%d oif=%d\n", oldflp->fld_dst, oldflp->fld_src,
913 oldflp->fld_fwmark, loopback_dev.ifindex, oldflp->oif);
915 /* If we have an output interface, verify its a DECnet device */
917 dev_out = dev_get_by_index(oldflp->oif);
919 if (dev_out && dev_out->dn_ptr == NULL) {
927 /* If we have a source address, verify that its a local address */
928 if (oldflp->fld_src) {
929 err = -EADDRNOTAVAIL;
932 if (dn_dev_islocal(dev_out, oldflp->fld_src))
937 read_lock(&dev_base_lock);
938 for(dev_out = dev_base; dev_out; dev_out = dev_out->next) {
939 if (!dev_out->dn_ptr)
941 if (dn_dev_islocal(dev_out, oldflp->fld_src))
944 read_unlock(&dev_base_lock);
952 /* No destination? Assume its local */
954 fl.fld_dst = fl.fld_src;
956 err = -EADDRNOTAVAIL;
959 dev_out = &loopback_dev;
963 fl.fld_src = dnet_select_source(dev_out, 0,
968 fl.oif = loopback_dev.ifindex;
969 res.type = RTN_LOCAL;
973 if (decnet_debug_level & 16)
975 "dn_route_output_slow: initial checks complete."
976 " dst=%o4x src=%04x oif=%d try_hard=%d\n", fl.fld_dst,
977 fl.fld_src, fl.oif, try_hard);
980 * N.B. If the kernel is compiled without router support then
981 * dn_fib_lookup() will evaluate to non-zero so this if () block
982 * will always be executed.
985 if (try_hard || (err = dn_fib_lookup(&fl, &res)) != 0) {
986 struct dn_dev *dn_db;
990 * Here the fallback is basically the standard algorithm for
991 * routing in endnodes which is described in the DECnet routing
994 * If we are not trying hard, look in neighbour cache.
995 * The result is tested to ensure that if a specific output
996 * device/source address was requested, then we honour that
1000 neigh = dn_neigh_lookup(&dn_neigh_table, &fl.fld_dst);
1003 (neigh->dev->ifindex != oldflp->oif)) ||
1005 (!dn_dev_islocal(neigh->dev,
1006 oldflp->fld_src)))) {
1007 neigh_release(neigh);
1012 if (dn_dev_islocal(neigh->dev, fl.fld_dst)) {
1013 dev_out = &loopback_dev;
1014 res.type = RTN_LOCAL;
1016 dev_out = neigh->dev;
1024 /* Not there? Perhaps its a local address */
1025 if (dev_out == NULL)
1026 dev_out = dn_dev_get_default();
1028 if (dev_out == NULL)
1030 dn_db = dev_out->dn_ptr;
1031 /* Possible improvement - check all devices for local addr */
1032 if (dn_dev_islocal(dev_out, fl.fld_dst)) {
1034 dev_out = &loopback_dev;
1036 res.type = RTN_LOCAL;
1039 /* Not local either.... try sending it to the default router */
1040 neigh = neigh_clone(dn_db->router);
1041 BUG_ON(neigh && neigh->dev != dev_out);
1043 /* Ok then, we assume its directly connected and move on */
1046 gateway = ((struct dn_neigh *)neigh)->addr;
1048 gateway = fl.fld_dst;
1049 if (fl.fld_src == 0) {
1050 fl.fld_src = dnet_select_source(dev_out, gateway,
1051 res.type == RTN_LOCAL ?
1054 if (fl.fld_src == 0 && res.type != RTN_LOCAL)
1057 fl.oif = dev_out->ifindex;
1062 if (res.type == RTN_NAT)
1065 if (res.type == RTN_LOCAL) {
1067 fl.fld_src = fl.fld_dst;
1070 dev_out = &loopback_dev;
1072 fl.oif = dev_out->ifindex;
1074 dn_fib_info_put(res.fi);
1079 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1080 dn_fib_select_multipath(&fl, &res);
1083 * We could add some logic to deal with default routes here and
1084 * get rid of some of the special casing above.
1088 fl.fld_src = DN_FIB_RES_PREFSRC(res);
1092 dev_out = DN_FIB_RES_DEV(res);
1094 fl.oif = dev_out->ifindex;
1095 gateway = DN_FIB_RES_GW(res);
1098 if (dev_out->flags & IFF_LOOPBACK)
1099 flags |= RTCF_LOCAL;
1101 rt = dst_alloc(&dn_dst_ops);
1105 atomic_set(&rt->u.dst.__refcnt, 1);
1106 rt->u.dst.flags = DST_HOST;
1108 rt->fl.fld_src = oldflp->fld_src;
1109 rt->fl.fld_dst = oldflp->fld_dst;
1110 rt->fl.oif = oldflp->oif;
1112 #ifdef CONFIG_DECNET_ROUTE_FWMARK
1113 rt->fl.fld_fwmark = oldflp->fld_fwmark;
1116 rt->rt_saddr = fl.fld_src;
1117 rt->rt_daddr = fl.fld_dst;
1118 rt->rt_gateway = gateway ? gateway : fl.fld_dst;
1119 rt->rt_local_src = fl.fld_src;
1121 rt->rt_dst_map = fl.fld_dst;
1122 rt->rt_src_map = fl.fld_src;
1124 rt->u.dst.dev = dev_out;
1126 rt->u.dst.neighbour = neigh;
1129 rt->u.dst.lastuse = jiffies;
1130 rt->u.dst.output = dn_output;
1131 rt->u.dst.input = dn_rt_bug;
1132 rt->rt_flags = flags;
1133 if (flags & RTCF_LOCAL)
1134 rt->u.dst.input = dn_nsp_rx;
1136 err = dn_rt_set_next_hop(rt, &res);
1140 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
1141 dn_insert_route(rt, hash, (struct dn_route **)pprt);
1145 neigh_release(neigh);
1147 dn_fib_res_put(&res);
1154 err = -EADDRNOTAVAIL;
1163 dst_free(&rt->u.dst);
1169 * N.B. The flags may be moved into the flowi at some future stage.
1171 static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *flp, int flags)
1173 unsigned hash = dn_hash(flp->fld_src, flp->fld_dst);
1174 struct dn_route *rt = NULL;
1176 if (!(flags & MSG_TRYHARD)) {
1178 for(rt = dn_rt_hash_table[hash].chain; rt; rt = rt->u.rt_next) {
1179 read_barrier_depends();
1180 if ((flp->fld_dst == rt->fl.fld_dst) &&
1181 (flp->fld_src == rt->fl.fld_src) &&
1182 #ifdef CONFIG_DECNET_ROUTE_FWMARK
1183 (flp->fld_fwmark == rt->fl.fld_fwmark) &&
1185 (rt->fl.iif == 0) &&
1186 (rt->fl.oif == flp->oif)) {
1187 rt->u.dst.lastuse = jiffies;
1188 dst_hold(&rt->u.dst);
1198 return dn_route_output_slow(pprt, flp, flags);
1201 static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int flags)
1205 err = __dn_route_output_key(pprt, flp, flags);
1206 if (err == 0 && flp->proto) {
1207 err = xfrm_lookup(pprt, flp, NULL, 0);
1212 int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock *sk, int flags)
1216 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1217 if (err == 0 && fl->proto) {
1218 err = xfrm_lookup(pprt, fl, sk, !(flags & MSG_DONTWAIT));
1223 static int dn_route_input_slow(struct sk_buff *skb)
1225 struct dn_route *rt = NULL;
1226 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1227 struct net_device *in_dev = skb->dev;
1228 struct net_device *out_dev = NULL;
1229 struct dn_dev *dn_db;
1230 struct neighbour *neigh = NULL;
1234 __u16 local_src = 0;
1235 struct flowi fl = { .nl_u = { .dn_u =
1238 .scope = RT_SCOPE_UNIVERSE,
1239 #ifdef CONFIG_DECNET_ROUTE_FWMARK
1240 .fwmark = skb->nfmark
1243 .iif = skb->dev->ifindex };
1244 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
1250 if ((dn_db = in_dev->dn_ptr) == NULL)
1253 /* Zero source addresses are not allowed */
1254 if (fl.fld_src == 0)
1258 * In this case we've just received a packet from a source
1259 * outside ourselves pretending to come from us. We don't
1260 * allow it any further to prevent routing loops, spoofing and
1261 * other nasties. Loopback packets already have the dst attached
1262 * so this only affects packets which have originated elsewhere.
1265 if (dn_dev_islocal(in_dev, cb->src))
1268 err = dn_fib_lookup(&fl, &res);
1273 * Is the destination us ?
1275 if (!dn_dev_islocal(in_dev, cb->dst))
1278 res.type = RTN_LOCAL;
1279 flags |= RTCF_DIRECTSRC;
1281 __u16 src_map = fl.fld_src;
1284 out_dev = DN_FIB_RES_DEV(res);
1285 if (out_dev == NULL) {
1286 if (net_ratelimit())
1287 printk(KERN_CRIT "Bug in dn_route_input_slow() "
1288 "No output device\n");
1294 src_map = dn_fib_rules_policy(fl.fld_src, &res, &flags);
1296 gateway = DN_FIB_RES_GW(res);
1297 if (res.type == RTN_NAT) {
1298 fl.fld_dst = dn_fib_rules_map_destination(fl.fld_dst, &res);
1299 dn_fib_res_put(&res);
1301 if (dn_fib_lookup(&fl, &res))
1304 if (res.type != RTN_UNICAST)
1307 gateway = fl.fld_dst;
1309 fl.fld_src = src_map;
1315 * Forwarding check here, we only check for forwarding
1316 * being turned off, if you want to only forward intra
1317 * area, its up to you to set the routing tables up
1320 if (dn_db->parms.forwarding == 0)
1323 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1324 dn_fib_select_multipath(&fl, &res);
1327 * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
1328 * flag as a hint to set the intra-ethernet bit when
1329 * forwarding. If we've got NAT in operation, we don't do
1330 * this optimisation.
1332 if (out_dev == in_dev && !(flags & RTCF_NAT))
1333 flags |= RTCF_DOREDIRECT;
1335 local_src = DN_FIB_RES_PREFSRC(res);
1338 case RTN_UNREACHABLE:
1341 flags |= RTCF_LOCAL;
1342 fl.fld_src = cb->dst;
1343 fl.fld_dst = cb->src;
1345 /* Routing tables gave us a gateway */
1349 /* Packet was intra-ethernet, so we know its on-link */
1350 if (cb->rt_flags | DN_RT_F_IE) {
1352 flags |= RTCF_DIRECTSRC;
1356 /* Use the default router if there is one */
1357 neigh = neigh_clone(dn_db->router);
1359 gateway = ((struct dn_neigh *)neigh)->addr;
1363 /* Close eyes and pray */
1365 flags |= RTCF_DIRECTSRC;
1372 rt = dst_alloc(&dn_dst_ops);
1376 rt->rt_saddr = fl.fld_src;
1377 rt->rt_daddr = fl.fld_dst;
1378 rt->rt_gateway = fl.fld_dst;
1380 rt->rt_gateway = gateway;
1381 rt->rt_local_src = local_src ? local_src : rt->rt_saddr;
1383 rt->rt_dst_map = fl.fld_dst;
1384 rt->rt_src_map = fl.fld_src;
1386 rt->fl.fld_src = cb->src;
1387 rt->fl.fld_dst = cb->dst;
1389 rt->fl.iif = in_dev->ifindex;
1390 rt->fl.fld_fwmark = fl.fld_fwmark;
1392 rt->u.dst.flags = DST_HOST;
1393 rt->u.dst.neighbour = neigh;
1394 rt->u.dst.dev = out_dev;
1395 rt->u.dst.lastuse = jiffies;
1396 rt->u.dst.output = dn_rt_bug_out;
1399 rt->u.dst.input = dn_forward;
1402 rt->u.dst.output = dn_output;
1403 rt->u.dst.input = dn_nsp_rx;
1404 rt->u.dst.dev = in_dev;
1405 flags |= RTCF_LOCAL;
1408 case RTN_UNREACHABLE:
1410 rt->u.dst.input = dn_blackhole;
1412 rt->rt_flags = flags;
1414 dev_hold(rt->u.dst.dev);
1416 err = dn_rt_set_next_hop(rt, &res);
1420 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
1421 dn_insert_route(rt, hash, (struct dn_route **)&skb->dst);
1425 neigh_release(neigh);
1427 dn_fib_res_put(&res);
1443 dst_free(&rt->u.dst);
1447 int dn_route_input(struct sk_buff *skb)
1449 struct dn_route *rt;
1450 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1451 unsigned hash = dn_hash(cb->src, cb->dst);
1457 for(rt = dn_rt_hash_table[hash].chain; rt != NULL; rt = rt->u.rt_next) {
1458 read_barrier_depends();
1459 if ((rt->fl.fld_src == cb->src) &&
1460 (rt->fl.fld_dst == cb->dst) &&
1461 (rt->fl.oif == 0) &&
1462 #ifdef CONFIG_DECNET_ROUTE_FWMARK
1463 (rt->fl.fld_fwmark == skb->nfmark) &&
1465 (rt->fl.iif == cb->iif)) {
1466 rt->u.dst.lastuse = jiffies;
1467 dst_hold(&rt->u.dst);
1470 skb->dst = (struct dst_entry *)rt;
1476 return dn_route_input_slow(skb);
1479 static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event, int nowait)
1481 struct dn_route *rt = (struct dn_route *)skb->dst;
1483 struct nlmsghdr *nlh;
1484 unsigned char *b = skb->tail;
1485 struct rta_cacheinfo ci;
1487 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(*r));
1488 r = NLMSG_DATA(nlh);
1489 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
1490 r->rtm_family = AF_DECnet;
1491 r->rtm_dst_len = 16;
1494 r->rtm_table = RT_TABLE_MAIN;
1495 r->rtm_type = rt->rt_type;
1496 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1497 r->rtm_scope = RT_SCOPE_UNIVERSE;
1498 r->rtm_protocol = RTPROT_UNSPEC;
1499 if (rt->rt_flags & RTCF_NOTIFY)
1500 r->rtm_flags |= RTM_F_NOTIFY;
1501 RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr);
1502 if (rt->fl.fld_src) {
1503 r->rtm_src_len = 16;
1504 RTA_PUT(skb, RTA_SRC, 2, &rt->fl.fld_src);
1507 RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->u.dst.dev->ifindex);
1509 * Note to self - change this if input routes reverse direction when
1510 * they deal only with inputs and not with replies like they do
1513 RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src);
1514 if (rt->rt_daddr != rt->rt_gateway)
1515 RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway);
1516 if (rtnetlink_put_metrics(skb, rt->u.dst.metrics) < 0)
1517 goto rtattr_failure;
1518 ci.rta_lastuse = jiffies_to_clock_t(jiffies - rt->u.dst.lastuse);
1519 ci.rta_used = rt->u.dst.__use;
1520 ci.rta_clntref = atomic_read(&rt->u.dst.__refcnt);
1521 if (rt->u.dst.expires)
1522 ci.rta_expires = jiffies_to_clock_t(rt->u.dst.expires - jiffies);
1525 ci.rta_error = rt->u.dst.error;
1526 ci.rta_id = ci.rta_ts = ci.rta_tsage = 0;
1527 RTA_PUT(skb, RTA_CACHEINFO, sizeof(ci), &ci);
1529 RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fl.iif);
1531 nlh->nlmsg_len = skb->tail - b;
1536 skb_trim(skb, b - skb->data);
1541 * This is called by both endnodes and routers now.
1543 int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
1545 struct rtattr **rta = arg;
1546 struct rtmsg *rtm = NLMSG_DATA(nlh);
1547 struct dn_route *rt = NULL;
1548 struct dn_skb_cb *cb;
1550 struct sk_buff *skb;
1553 memset(&fl, 0, sizeof(fl));
1554 fl.proto = DNPROTO_NSP;
1556 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1559 skb->mac.raw = skb->data;
1560 cb = DN_SKB_CB(skb);
1563 memcpy(&fl.fld_src, RTA_DATA(rta[RTA_SRC-1]), 2);
1565 memcpy(&fl.fld_dst, RTA_DATA(rta[RTA_DST-1]), 2);
1567 memcpy(&fl.iif, RTA_DATA(rta[RTA_IIF-1]), sizeof(int));
1570 struct net_device *dev;
1571 if ((dev = dev_get_by_index(fl.iif)) == NULL) {
1580 skb->protocol = __constant_htons(ETH_P_DNA_RT);
1582 cb->src = fl.fld_src;
1583 cb->dst = fl.fld_dst;
1585 err = dn_route_input(skb);
1587 memset(cb, 0, sizeof(struct dn_skb_cb));
1588 rt = (struct dn_route *)skb->dst;
1589 if (!err && -rt->u.dst.error)
1590 err = rt->u.dst.error;
1593 if (rta[RTA_OIF - 1])
1594 memcpy(&oif, RTA_DATA(rta[RTA_OIF - 1]), sizeof(int));
1596 err = dn_route_output_key((struct dst_entry **)&rt, &fl, 0);
1604 skb->dst = &rt->u.dst;
1605 if (rtm->rtm_flags & RTM_F_NOTIFY)
1606 rt->rt_flags |= RTCF_NOTIFY;
1608 NETLINK_CB(skb).dst_pid = NETLINK_CB(in_skb).pid;
1610 err = dn_rt_fill_info(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq, RTM_NEWROUTE, 0);
1619 err = netlink_unicast(rtnl, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT);
1629 * For routers, this is called from dn_fib_dump, but for endnodes its
1630 * called directly from the rtnetlink dispatch table.
1632 int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1634 struct dn_route *rt;
1638 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
1640 if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
1644 s_idx = idx = cb->args[1];
1645 for(h = 0; h <= dn_rt_hash_mask; h++) {
1651 for(rt = dn_rt_hash_table[h].chain, idx = 0; rt; rt = rt->u.rt_next, idx++) {
1652 read_barrier_depends();
1655 skb->dst = dst_clone(&rt->u.dst);
1656 if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
1657 cb->nlh->nlmsg_seq, RTM_NEWROUTE, 1) <= 0) {
1658 dst_release(xchg(&skb->dst, NULL));
1662 dst_release(xchg(&skb->dst, NULL));
1673 #ifdef CONFIG_PROC_FS
1674 struct dn_rt_cache_iter_state {
1678 static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
1680 struct dn_route *rt = NULL;
1681 struct dn_rt_cache_iter_state *s = seq->private;
1683 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
1685 rt = dn_rt_hash_table[s->bucket].chain;
1693 static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
1695 struct dn_rt_cache_iter_state *s = seq->private;
1697 smp_read_barrier_depends();
1701 if (--s->bucket < 0)
1704 rt = dn_rt_hash_table[s->bucket].chain;
1709 static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
1711 struct dn_route *rt = dn_rt_cache_get_first(seq);
1714 while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
1717 return *pos ? NULL : rt;
1720 static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1722 struct dn_route *rt = dn_rt_cache_get_next(seq, v);
1727 static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
1733 static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
1735 struct dn_route *rt = v;
1736 char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
1738 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
1739 rt->u.dst.dev ? rt->u.dst.dev->name : "*",
1740 dn_addr2asc(dn_ntohs(rt->rt_daddr), buf1),
1741 dn_addr2asc(dn_ntohs(rt->rt_saddr), buf2),
1742 atomic_read(&rt->u.dst.__refcnt),
1744 (int) dst_metric(&rt->u.dst, RTAX_RTT));
1748 static struct seq_operations dn_rt_cache_seq_ops = {
1749 .start = dn_rt_cache_seq_start,
1750 .next = dn_rt_cache_seq_next,
1751 .stop = dn_rt_cache_seq_stop,
1752 .show = dn_rt_cache_seq_show,
1755 static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
1757 struct seq_file *seq;
1759 struct dn_rt_cache_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
1763 rc = seq_open(file, &dn_rt_cache_seq_ops);
1766 seq = file->private_data;
1768 memset(s, 0, sizeof(*s));
1776 static struct file_operations dn_rt_cache_seq_fops = {
1777 .owner = THIS_MODULE,
1778 .open = dn_rt_cache_seq_open,
1780 .llseek = seq_lseek,
1781 .release = seq_release_private,
1784 #endif /* CONFIG_PROC_FS */
1786 void __init dn_route_init(void)
1790 dn_dst_ops.kmem_cachep = kmem_cache_create("dn_dst_cache",
1791 sizeof(struct dn_route),
1792 0, SLAB_HWCACHE_ALIGN,
1795 if (!dn_dst_ops.kmem_cachep)
1796 panic("DECnet: Failed to allocate dn_dst_cache\n");
1798 init_timer(&dn_route_timer);
1799 dn_route_timer.function = dn_dst_check_expire;
1800 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1801 add_timer(&dn_route_timer);
1803 goal = num_physpages >> (26 - PAGE_SHIFT);
1805 for(order = 0; (1UL << order) < goal; order++)
1809 * Only want 1024 entries max, since the table is very, very unlikely
1810 * to be larger than that.
1812 while(order && ((((1UL << order) * PAGE_SIZE) /
1813 sizeof(struct dn_rt_hash_bucket)) >= 2048))
1817 dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
1818 sizeof(struct dn_rt_hash_bucket);
1819 while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
1821 dn_rt_hash_table = (struct dn_rt_hash_bucket *)
1822 __get_free_pages(GFP_ATOMIC, order);
1823 } while (dn_rt_hash_table == NULL && --order > 0);
1825 if (!dn_rt_hash_table)
1826 panic("Failed to allocate DECnet route cache hash table\n");
1829 "DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
1831 (long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
1834 for(i = 0; i <= dn_rt_hash_mask; i++) {
1835 dn_rt_hash_table[i].lock = SPIN_LOCK_UNLOCKED;
1836 dn_rt_hash_table[i].chain = NULL;
1839 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
1841 proc_net_fops_create("decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
1844 void __exit dn_route_cleanup(void)
1846 del_timer(&dn_route_timer);
1849 proc_net_remove("decnet_cache");