blob: 94a9eb1d313eb499dc2b6efa2943ee1fb6f2d26e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
5 *
6 * DECnet Routing Functions (Endnode and Router)
7 *
8 * Authors: Steve Whitehouse <SteveW@ACM.org>
9 * Eduardo Marcelo Serrat <emserrat@geocities.com>
10 *
11 * Changes:
12 * Steve Whitehouse : Fixes to allow "intra-ethernet" and
13 * "return-to-sender" bits on outgoing
14 * packets.
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
26 * from ipv4/route.c.
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
34 * are numbered!
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
42 */
43
44/******************************************************************************
45 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +090046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 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
50 any later version.
51
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*******************************************************************************/
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/errno.h>
59#include <linux/types.h>
60#include <linux/socket.h>
61#include <linux/in.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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090069#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#include <net/sock.h>
71#include <linux/mm.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>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020081#include <net/net_namespace.h>
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070082#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#include <net/neighbour.h>
84#include <net/dst.h>
85#include <net/flow.h>
Steven Whitehousea8731cb2006-08-09 15:56:46 -070086#include <net/fib_rules.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#include <net/dn.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>
93
94struct dn_rt_hash_bucket
95{
Eric Dumazetfc766e4c2010-10-29 03:09:24 +000096 struct dn_route __rcu *chain;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 spinlock_t lock;
Eric Dumazetfca09fb2008-02-07 23:29:57 -080098};
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100extern struct neigh_table dn_neigh_table;
101
102
103static unsigned char dn_hiord_addr[6] = {0xAA,0x00,0x04,0x00,0x00,0x00};
104
105static const int dn_rt_min_delay = 2 * HZ;
106static const int dn_rt_max_delay = 10 * HZ;
107static const int dn_rt_mtu_expires = 10 * 60 * HZ;
108
109static unsigned long dn_rt_deadline;
110
Daniel Lezcano569d3642008-01-18 03:56:57 -0800111static int dn_dst_gc(struct dst_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static struct dst_entry *dn_dst_check(struct dst_entry *, __u32);
113static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
114static void dn_dst_link_failure(struct sk_buff *);
115static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
116static int dn_route_input(struct sk_buff *);
117static void dn_run_flush(unsigned long dummy);
118
119static struct dn_rt_hash_bucket *dn_rt_hash_table;
120static unsigned dn_rt_hash_mask;
121
122static struct timer_list dn_route_timer;
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700123static DEFINE_TIMER(dn_rt_flush_timer, dn_run_flush, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124int decnet_dst_gc_interval = 2;
125
126static struct dst_ops dn_dst_ops = {
127 .family = PF_DECnet,
Harvey Harrison09640e62009-02-01 00:45:17 -0800128 .protocol = cpu_to_be16(ETH_P_DNA_RT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 .gc_thresh = 128,
130 .gc = dn_dst_gc,
131 .check = dn_dst_check,
132 .negative_advice = dn_dst_negative_advice,
133 .link_failure = dn_dst_link_failure,
134 .update_pmtu = dn_dst_update_pmtu,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800137static __inline__ unsigned dn_hash(__le16 src, __le16 dst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800139 __u16 tmp = (__u16 __force)(src ^ dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 tmp ^= (tmp >> 3);
141 tmp ^= (tmp >> 5);
142 tmp ^= (tmp >> 10);
143 return dn_rt_hash_mask & (unsigned)tmp;
144}
145
146static inline void dnrt_free(struct dn_route *rt)
147{
Changli Gaod8d1f302010-06-10 23:31:35 -0700148 call_rcu_bh(&rt->dst.rcu_head, dst_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
151static inline void dnrt_drop(struct dn_route *rt)
152{
Changli Gaod8d1f302010-06-10 23:31:35 -0700153 dst_release(&rt->dst);
154 call_rcu_bh(&rt->dst.rcu_head, dst_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
157static void dn_dst_check_expire(unsigned long dummy)
158{
159 int i;
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000160 struct dn_route *rt;
161 struct dn_route __rcu **rtp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 unsigned long now = jiffies;
163 unsigned long expire = 120 * HZ;
164
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000165 for (i = 0; i <= dn_rt_hash_mask; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 rtp = &dn_rt_hash_table[i].chain;
167
168 spin_lock(&dn_rt_hash_table[i].lock);
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000169 while ((rt = rcu_dereference_protected(*rtp,
170 lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
Changli Gaod8d1f302010-06-10 23:31:35 -0700171 if (atomic_read(&rt->dst.__refcnt) ||
172 (now - rt->dst.lastuse) < expire) {
173 rtp = &rt->dst.dn_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 continue;
175 }
Changli Gaod8d1f302010-06-10 23:31:35 -0700176 *rtp = rt->dst.dn_next;
177 rt->dst.dn_next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 dnrt_free(rt);
179 }
180 spin_unlock(&dn_rt_hash_table[i].lock);
181
182 if ((jiffies - now) > 0)
183 break;
184 }
185
186 mod_timer(&dn_route_timer, now + decnet_dst_gc_interval * HZ);
187}
188
Daniel Lezcano569d3642008-01-18 03:56:57 -0800189static int dn_dst_gc(struct dst_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000191 struct dn_route *rt;
192 struct dn_route __rcu **rtp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 int i;
194 unsigned long now = jiffies;
195 unsigned long expire = 10 * HZ;
196
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000197 for (i = 0; i <= dn_rt_hash_mask; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 spin_lock_bh(&dn_rt_hash_table[i].lock);
200 rtp = &dn_rt_hash_table[i].chain;
201
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000202 while ((rt = rcu_dereference_protected(*rtp,
203 lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
Changli Gaod8d1f302010-06-10 23:31:35 -0700204 if (atomic_read(&rt->dst.__refcnt) ||
205 (now - rt->dst.lastuse) < expire) {
206 rtp = &rt->dst.dn_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 continue;
208 }
Changli Gaod8d1f302010-06-10 23:31:35 -0700209 *rtp = rt->dst.dn_next;
210 rt->dst.dn_next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 dnrt_drop(rt);
212 break;
213 }
214 spin_unlock_bh(&dn_rt_hash_table[i].lock);
215 }
216
217 return 0;
218}
219
220/*
221 * The decnet standards don't impose a particular minimum mtu, what they
222 * do insist on is that the routing layer accepts a datagram of at least
223 * 230 bytes long. Here we have to subtract the routing header length from
224 * 230 to get the minimum acceptable mtu. If there is no neighbour, then we
225 * assume the worst and use a long header size.
226 *
227 * We update both the mtu and the advertised mss (i.e. the segment size we
228 * advertise to the other end).
229 */
230static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)
231{
232 u32 min_mtu = 230;
233 struct dn_dev *dn = dst->neighbour ?
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000234 rcu_dereference_raw(dst->neighbour->dev->dn_ptr) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 if (dn && dn->use_long == 0)
237 min_mtu -= 6;
238 else
239 min_mtu -= 21;
240
Satoru SATOH5ffc02a2008-05-04 22:14:42 -0700241 if (dst_metric(dst, RTAX_MTU) > mtu && mtu >= min_mtu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (!(dst_metric_locked(dst, RTAX_MTU))) {
243 dst->metrics[RTAX_MTU-1] = mtu;
244 dst_set_expires(dst, dn_rt_mtu_expires);
245 }
246 if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
247 u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
Satoru SATOH5ffc02a2008-05-04 22:14:42 -0700248 if (dst_metric(dst, RTAX_ADVMSS) > mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 dst->metrics[RTAX_ADVMSS-1] = mss;
250 }
251 }
252}
253
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900254/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 * When a route has been marked obsolete. (e.g. routing cache flush)
256 */
257static struct dst_entry *dn_dst_check(struct dst_entry *dst, __u32 cookie)
258{
259 return NULL;
260}
261
262static struct dst_entry *dn_dst_negative_advice(struct dst_entry *dst)
263{
264 dst_release(dst);
265 return NULL;
266}
267
268static void dn_dst_link_failure(struct sk_buff *skb)
269{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
272static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
273{
David S. Miller8238b212006-10-12 00:49:15 -0700274 return ((fl1->nl_u.dn_u.daddr ^ fl2->nl_u.dn_u.daddr) |
275 (fl1->nl_u.dn_u.saddr ^ fl2->nl_u.dn_u.saddr) |
Thomas Graf47dcf0c2006-11-09 15:20:38 -0800276 (fl1->mark ^ fl2->mark) |
David S. Miller8238b212006-10-12 00:49:15 -0700277 (fl1->nl_u.dn_u.scope ^ fl2->nl_u.dn_u.scope) |
278 (fl1->oif ^ fl2->oif) |
279 (fl1->iif ^ fl2->iif)) == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp)
283{
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000284 struct dn_route *rth;
285 struct dn_route __rcu **rthp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 unsigned long now = jiffies;
287
288 rthp = &dn_rt_hash_table[hash].chain;
289
290 spin_lock_bh(&dn_rt_hash_table[hash].lock);
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000291 while ((rth = rcu_dereference_protected(*rthp,
292 lockdep_is_held(&dn_rt_hash_table[hash].lock))) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (compare_keys(&rth->fl, &rt->fl)) {
294 /* Put it first */
Changli Gaod8d1f302010-06-10 23:31:35 -0700295 *rthp = rth->dst.dn_next;
296 rcu_assign_pointer(rth->dst.dn_next,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 dn_rt_hash_table[hash].chain);
298 rcu_assign_pointer(dn_rt_hash_table[hash].chain, rth);
299
Changli Gaod8d1f302010-06-10 23:31:35 -0700300 dst_use(&rth->dst, now);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
302
303 dnrt_drop(rt);
304 *rp = rth;
305 return 0;
306 }
Changli Gaod8d1f302010-06-10 23:31:35 -0700307 rthp = &rth->dst.dn_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309
Changli Gaod8d1f302010-06-10 23:31:35 -0700310 rcu_assign_pointer(rt->dst.dn_next, dn_rt_hash_table[hash].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 rcu_assign_pointer(dn_rt_hash_table[hash].chain, rt);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900312
Changli Gaod8d1f302010-06-10 23:31:35 -0700313 dst_use(&rt->dst, now);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
315 *rp = rt;
316 return 0;
317}
318
Roel Kluin5eaa65b2008-12-10 15:18:31 -0800319static void dn_run_flush(unsigned long dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 int i;
322 struct dn_route *rt, *next;
323
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000324 for (i = 0; i < dn_rt_hash_mask; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 spin_lock_bh(&dn_rt_hash_table[i].lock);
326
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000327 if ((rt = xchg((struct dn_route **)&dn_rt_hash_table[i].chain, NULL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 goto nothing_to_declare;
329
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000330 for(; rt; rt = next) {
331 next = rcu_dereference_raw(rt->dst.dn_next);
332 RCU_INIT_POINTER(rt->dst.dn_next, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 dst_free((struct dst_entry *)rt);
334 }
335
336nothing_to_declare:
337 spin_unlock_bh(&dn_rt_hash_table[i].lock);
338 }
339}
340
341static DEFINE_SPINLOCK(dn_rt_flush_lock);
342
343void dn_rt_cache_flush(int delay)
344{
345 unsigned long now = jiffies;
346 int user_mode = !in_interrupt();
347
348 if (delay < 0)
349 delay = dn_rt_min_delay;
350
351 spin_lock_bh(&dn_rt_flush_lock);
352
353 if (del_timer(&dn_rt_flush_timer) && delay > 0 && dn_rt_deadline) {
354 long tmo = (long)(dn_rt_deadline - now);
355
356 if (user_mode && tmo < dn_rt_max_delay - dn_rt_min_delay)
357 tmo = 0;
358
359 if (delay > tmo)
360 delay = tmo;
361 }
362
363 if (delay <= 0) {
364 spin_unlock_bh(&dn_rt_flush_lock);
365 dn_run_flush(0);
366 return;
367 }
368
369 if (dn_rt_deadline == 0)
370 dn_rt_deadline = now + dn_rt_max_delay;
371
372 dn_rt_flush_timer.expires = now + delay;
373 add_timer(&dn_rt_flush_timer);
374 spin_unlock_bh(&dn_rt_flush_lock);
375}
376
377/**
378 * dn_return_short - Return a short packet to its sender
379 * @skb: The packet to return
380 *
381 */
382static int dn_return_short(struct sk_buff *skb)
383{
384 struct dn_skb_cb *cb;
385 unsigned char *ptr;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800386 __le16 *src;
387 __le16 *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 /* Add back headers */
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700390 skb_push(skb, skb->data - skb_network_header(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
393 return NET_RX_DROP;
394
395 cb = DN_SKB_CB(skb);
396 /* Skip packet length and point to flags */
397 ptr = skb->data + 2;
398 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
399
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800400 dst = (__le16 *)ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800402 src = (__le16 *)ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 ptr += 2;
404 *ptr = 0; /* Zero hop count */
405
Ilpo Järvinena0bffff2009-03-21 13:36:17 -0700406 swap(*src, *dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 skb->pkt_type = PACKET_OUTGOING;
409 dn_rt_finish_output(skb, NULL, NULL);
410 return NET_RX_SUCCESS;
411}
412
413/**
414 * dn_return_long - Return a long packet to its sender
415 * @skb: The long format packet to return
416 *
417 */
418static int dn_return_long(struct sk_buff *skb)
419{
420 struct dn_skb_cb *cb;
421 unsigned char *ptr;
422 unsigned char *src_addr, *dst_addr;
423 unsigned char tmp[ETH_ALEN];
424
425 /* Add back all headers */
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700426 skb_push(skb, skb->data - skb_network_header(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
429 return NET_RX_DROP;
430
431 cb = DN_SKB_CB(skb);
432 /* Ignore packet length and point to flags */
433 ptr = skb->data + 2;
434
435 /* Skip padding */
436 if (*ptr & DN_RT_F_PF) {
437 char padlen = (*ptr & ~DN_RT_F_PF);
438 ptr += padlen;
439 }
440
441 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
442 ptr += 2;
443 dst_addr = ptr;
444 ptr += 8;
445 src_addr = ptr;
446 ptr += 6;
447 *ptr = 0; /* Zero hop count */
448
449 /* Swap source and destination */
450 memcpy(tmp, src_addr, ETH_ALEN);
451 memcpy(src_addr, dst_addr, ETH_ALEN);
452 memcpy(dst_addr, tmp, ETH_ALEN);
453
454 skb->pkt_type = PACKET_OUTGOING;
455 dn_rt_finish_output(skb, dst_addr, src_addr);
456 return NET_RX_SUCCESS;
457}
458
459/**
460 * dn_route_rx_packet - Try and find a route for an incoming packet
461 * @skb: The packet to find a route for
462 *
463 * Returns: result of input function if route is found, error code otherwise
464 */
465static int dn_route_rx_packet(struct sk_buff *skb)
466{
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000467 struct dn_skb_cb *cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 int err;
469
470 if ((err = dn_route_input(skb)) == 0)
471 return dst_input(skb);
472
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000473 cb = DN_SKB_CB(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (decnet_debug_level & 4) {
475 char *devname = skb->dev ? skb->dev->name : "???";
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 printk(KERN_DEBUG
478 "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800479 (int)cb->rt_flags, devname, skb->len,
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800480 le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 err, skb->pkt_type);
482 }
483
484 if ((skb->pkt_type == PACKET_HOST) && (cb->rt_flags & DN_RT_F_RQR)) {
485 switch(cb->rt_flags & DN_RT_PKT_MSK) {
486 case DN_RT_PKT_SHORT:
487 return dn_return_short(skb);
488 case DN_RT_PKT_LONG:
489 return dn_return_long(skb);
490 }
491 }
492
493 kfree_skb(skb);
494 return NET_RX_DROP;
495}
496
497static int dn_route_rx_long(struct sk_buff *skb)
498{
499 struct dn_skb_cb *cb = DN_SKB_CB(skb);
500 unsigned char *ptr = skb->data;
501
502 if (!pskb_may_pull(skb, 21)) /* 20 for long header, 1 for shortest nsp */
503 goto drop_it;
504
505 skb_pull(skb, 20);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300506 skb_reset_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900508 /* Destination info */
509 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800510 cb->dst = dn_eth2dn(ptr);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900511 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
512 goto drop_it;
513 ptr += 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900516 /* Source info */
517 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800518 cb->src = dn_eth2dn(ptr);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900519 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
520 goto drop_it;
521 ptr += 6;
522 /* Other junk */
523 ptr++;
524 cb->hops = *ptr++; /* Visit Count */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100526 return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING, skb, skb->dev, NULL,
527 dn_route_rx_packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529drop_it:
530 kfree_skb(skb);
531 return NET_RX_DROP;
532}
533
534
535
536static int dn_route_rx_short(struct sk_buff *skb)
537{
538 struct dn_skb_cb *cb = DN_SKB_CB(skb);
539 unsigned char *ptr = skb->data;
540
541 if (!pskb_may_pull(skb, 6)) /* 5 for short header + 1 for shortest nsp */
542 goto drop_it;
543
544 skb_pull(skb, 5);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300545 skb_reset_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800547 cb->dst = *(__le16 *)ptr;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900548 ptr += 2;
549 cb->src = *(__le16 *)ptr;
550 ptr += 2;
551 cb->hops = *ptr & 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100553 return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING, skb, skb->dev, NULL,
554 dn_route_rx_packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556drop_it:
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900557 kfree_skb(skb);
558 return NET_RX_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561static int dn_route_discard(struct sk_buff *skb)
562{
563 /*
564 * I know we drop the packet here, but thats considered success in
565 * this case
566 */
567 kfree_skb(skb);
568 return NET_RX_SUCCESS;
569}
570
571static int dn_route_ptp_hello(struct sk_buff *skb)
572{
573 dn_dev_hello(skb);
574 dn_neigh_pointopoint_hello(skb);
575 return NET_RX_SUCCESS;
576}
577
David S. Millerf2ccd8f2005-08-09 19:34:12 -0700578int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
580 struct dn_skb_cb *cb;
581 unsigned char flags = 0;
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800582 __u16 len = le16_to_cpu(*(__le16 *)skb->data);
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000583 struct dn_dev *dn = rcu_dereference(dev->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 unsigned char padlen = 0;
585
YOSHIFUJI Hideaki721499e2008-07-19 22:34:43 -0700586 if (!net_eq(dev_net(dev), &init_net))
Eric W. Biedermane730c152007-09-17 11:53:39 -0700587 goto dump_it;
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 if (dn == NULL)
590 goto dump_it;
591
592 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
593 goto out;
594
595 if (!pskb_may_pull(skb, 3))
596 goto dump_it;
597
598 skb_pull(skb, 2);
599
600 if (len > skb->len)
601 goto dump_it;
602
603 skb_trim(skb, len);
604
605 flags = *skb->data;
606
607 cb = DN_SKB_CB(skb);
608 cb->stamp = jiffies;
609 cb->iif = dev->ifindex;
610
611 /*
612 * If we have padding, remove it.
613 */
614 if (flags & DN_RT_F_PF) {
615 padlen = flags & ~DN_RT_F_PF;
616 if (!pskb_may_pull(skb, padlen + 1))
617 goto dump_it;
618 skb_pull(skb, padlen);
619 flags = *skb->data;
620 }
621
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700622 skb_reset_network_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /*
625 * Weed out future version DECnet
626 */
627 if (flags & DN_RT_F_VER)
628 goto dump_it;
629
630 cb->rt_flags = flags;
631
632 if (decnet_debug_level & 1)
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900633 printk(KERN_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 "dn_route_rcv: got 0x%02x from %s [%d %d %d]\n",
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900635 (int)flags, (dev) ? dev->name : "???", len, skb->len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 padlen);
637
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900638 if (flags & DN_RT_PKT_CNTL) {
Herbert Xu364c6ba2006-06-09 16:10:40 -0700639 if (unlikely(skb_linearize(skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 goto dump_it;
641
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900642 switch(flags & DN_RT_CNTL_MSK) {
643 case DN_RT_PKT_INIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 dn_dev_init_pkt(skb);
645 break;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900646 case DN_RT_PKT_VERI:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 dn_dev_veri_pkt(skb);
648 break;
649 }
650
651 if (dn->parms.state != DN_DEV_S_RU)
652 goto dump_it;
653
654 switch(flags & DN_RT_CNTL_MSK) {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900655 case DN_RT_PKT_HELO:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100656 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
657 skb, skb->dev, NULL,
658 dn_route_ptp_hello);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900660 case DN_RT_PKT_L1RT:
661 case DN_RT_PKT_L2RT:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100662 return NF_HOOK(NFPROTO_DECNET, NF_DN_ROUTE,
663 skb, skb->dev, NULL,
664 dn_route_discard);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900665 case DN_RT_PKT_ERTH:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100666 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
667 skb, skb->dev, NULL,
668 dn_neigh_router_hello);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900670 case DN_RT_PKT_EEDH:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100671 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
672 skb, skb->dev, NULL,
673 dn_neigh_endnode_hello);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900674 }
675 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (dn->parms.state != DN_DEV_S_RU)
677 goto dump_it;
678
679 skb_pull(skb, 1); /* Pull flags */
680
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900681 switch(flags & DN_RT_PKT_MSK) {
682 case DN_RT_PKT_LONG:
683 return dn_route_rx_long(skb);
684 case DN_RT_PKT_SHORT:
685 return dn_route_rx_short(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
689dump_it:
690 kfree_skb(skb);
691out:
692 return NET_RX_DROP;
693}
694
695static int dn_output(struct sk_buff *skb)
696{
Eric Dumazetadf30902009-06-02 05:19:30 +0000697 struct dst_entry *dst = skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 struct dn_route *rt = (struct dn_route *)dst;
699 struct net_device *dev = dst->dev;
700 struct dn_skb_cb *cb = DN_SKB_CB(skb);
701 struct neighbour *neigh;
702
703 int err = -EINVAL;
704
705 if ((neigh = dst->neighbour) == NULL)
706 goto error;
707
708 skb->dev = dev;
709
710 cb->src = rt->rt_saddr;
711 cb->dst = rt->rt_daddr;
712
713 /*
714 * Always set the Intra-Ethernet bit on all outgoing packets
715 * originated on this node. Only valid flag from upper layers
716 * is return-to-sender-requested. Set hop count to 0 too.
717 */
718 cb->rt_flags &= ~DN_RT_F_RQR;
719 cb->rt_flags |= DN_RT_F_IE;
720 cb->hops = 0;
721
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100722 return NF_HOOK(NFPROTO_DECNET, NF_DN_LOCAL_OUT, skb, NULL, dev,
723 neigh->output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725error:
726 if (net_ratelimit())
727 printk(KERN_DEBUG "dn_output: This should not happen\n");
728
729 kfree_skb(skb);
730
731 return err;
732}
733
734static int dn_forward(struct sk_buff *skb)
735{
736 struct dn_skb_cb *cb = DN_SKB_CB(skb);
Eric Dumazetadf30902009-06-02 05:19:30 +0000737 struct dst_entry *dst = skb_dst(skb);
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000738 struct dn_dev *dn_db = rcu_dereference(dst->dev->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 struct dn_route *rt;
740 struct neighbour *neigh = dst->neighbour;
741 int header_len;
742#ifdef CONFIG_NETFILTER
743 struct net_device *dev = skb->dev;
744#endif
745
746 if (skb->pkt_type != PACKET_HOST)
747 goto drop;
748
749 /* Ensure that we have enough space for headers */
Eric Dumazetadf30902009-06-02 05:19:30 +0000750 rt = (struct dn_route *)skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 header_len = dn_db->use_long ? 21 : 6;
Changli Gaod8d1f302010-06-10 23:31:35 -0700752 if (skb_cow(skb, LL_RESERVED_SPACE(rt->dst.dev)+header_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 goto drop;
754
755 /*
756 * Hop count exceeded.
757 */
758 if (++cb->hops > 30)
759 goto drop;
760
Changli Gaod8d1f302010-06-10 23:31:35 -0700761 skb->dev = rt->dst.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /*
764 * If packet goes out same interface it came in on, then set
765 * the Intra-Ethernet bit. This has no effect for short
766 * packets, so we don't need to test for them here.
767 */
768 cb->rt_flags &= ~DN_RT_F_IE;
769 if (rt->rt_flags & RTCF_DOREDIRECT)
770 cb->rt_flags |= DN_RT_F_IE;
771
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100772 return NF_HOOK(NFPROTO_DECNET, NF_DN_FORWARD, skb, dev, skb->dev,
773 neigh->output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775drop:
776 kfree_skb(skb);
777 return NET_RX_DROP;
778}
779
780/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 * Used to catch bugs. This should never normally get
782 * called.
783 */
784static int dn_rt_bug(struct sk_buff *skb)
785{
786 if (net_ratelimit()) {
787 struct dn_skb_cb *cb = DN_SKB_CB(skb);
788
789 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800790 le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792
793 kfree_skb(skb);
794
Florian Westphal0e8635a2009-06-20 00:53:25 +0000795 return NET_RX_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
798static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
799{
800 struct dn_fib_info *fi = res->fi;
Changli Gaod8d1f302010-06-10 23:31:35 -0700801 struct net_device *dev = rt->dst.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 struct neighbour *n;
803 unsigned mss;
804
805 if (fi) {
806 if (DN_FIB_RES_GW(*res) &&
807 DN_FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
808 rt->rt_gateway = DN_FIB_RES_GW(*res);
Changli Gaod8d1f302010-06-10 23:31:35 -0700809 memcpy(rt->dst.metrics, fi->fib_metrics,
810 sizeof(rt->dst.metrics));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
812 rt->rt_type = res->type;
813
Changli Gaod8d1f302010-06-10 23:31:35 -0700814 if (dev != NULL && rt->dst.neighbour == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
816 if (IS_ERR(n))
817 return PTR_ERR(n);
Changli Gaod8d1f302010-06-10 23:31:35 -0700818 rt->dst.neighbour = n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 }
820
Changli Gaod8d1f302010-06-10 23:31:35 -0700821 if (dst_metric(&rt->dst, RTAX_MTU) == 0 ||
822 dst_metric(&rt->dst, RTAX_MTU) > rt->dst.dev->mtu)
823 rt->dst.metrics[RTAX_MTU-1] = rt->dst.dev->mtu;
824 mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
825 if (dst_metric(&rt->dst, RTAX_ADVMSS) == 0 ||
826 dst_metric(&rt->dst, RTAX_ADVMSS) > mss)
827 rt->dst.metrics[RTAX_ADVMSS-1] = mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return 0;
829}
830
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800831static inline int dn_match_addr(__le16 addr1, __le16 addr2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800833 __u16 tmp = le16_to_cpu(addr1) ^ le16_to_cpu(addr2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 int match = 16;
835 while(tmp) {
836 tmp >>= 1;
837 match--;
838 }
839 return match;
840}
841
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800842static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800844 __le16 saddr = 0;
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000845 struct dn_dev *dn_db;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 struct dn_ifaddr *ifa;
847 int best_match = 0;
848 int ret;
849
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000850 rcu_read_lock();
851 dn_db = rcu_dereference(dev->dn_ptr);
852 for (ifa = rcu_dereference(dn_db->ifa_list);
853 ifa != NULL;
854 ifa = rcu_dereference(ifa->ifa_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (ifa->ifa_scope > scope)
856 continue;
857 if (!daddr) {
858 saddr = ifa->ifa_local;
859 break;
860 }
861 ret = dn_match_addr(daddr, ifa->ifa_local);
862 if (ret > best_match)
863 saddr = ifa->ifa_local;
864 if (best_match == 0)
865 saddr = ifa->ifa_local;
866 }
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000867 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 return saddr;
870}
871
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800872static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
874 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
875}
876
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800877static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800879 __le16 mask = dnet_make_mask(res->prefixlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 return (daddr&~mask)|res->fi->fib_nh->nh_gw;
881}
882
883static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *oldflp, int try_hard)
884{
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900885 struct flowi fl = { .nl_u = { .dn_u =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 { .daddr = oldflp->fld_dst,
887 .saddr = oldflp->fld_src,
888 .scope = RT_SCOPE_UNIVERSE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 } },
Thomas Graf47dcf0c2006-11-09 15:20:38 -0800890 .mark = oldflp->mark,
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700891 .iif = init_net.loopback_dev->ifindex,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 .oif = oldflp->oif };
893 struct dn_route *rt = NULL;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700894 struct net_device *dev_out = NULL, *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 struct neighbour *neigh = NULL;
896 unsigned hash;
897 unsigned flags = 0;
898 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
899 int err;
900 int free_res = 0;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800901 __le16 gateway = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 if (decnet_debug_level & 16)
904 printk(KERN_DEBUG
905 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800906 " iif=%d oif=%d\n", le16_to_cpu(oldflp->fld_dst),
907 le16_to_cpu(oldflp->fld_src),
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700908 oldflp->mark, init_net.loopback_dev->ifindex, oldflp->oif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 /* If we have an output interface, verify its a DECnet device */
911 if (oldflp->oif) {
Eric W. Biederman881d9662007-09-17 11:56:21 -0700912 dev_out = dev_get_by_index(&init_net, oldflp->oif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 err = -ENODEV;
914 if (dev_out && dev_out->dn_ptr == NULL) {
915 dev_put(dev_out);
916 dev_out = NULL;
917 }
918 if (dev_out == NULL)
919 goto out;
920 }
921
922 /* If we have a source address, verify that its a local address */
923 if (oldflp->fld_src) {
924 err = -EADDRNOTAVAIL;
925
926 if (dev_out) {
927 if (dn_dev_islocal(dev_out, oldflp->fld_src))
928 goto source_ok;
929 dev_put(dev_out);
930 goto out;
931 }
Eric Dumazetc6d14c82009-11-04 05:43:23 -0800932 rcu_read_lock();
933 for_each_netdev_rcu(&init_net, dev) {
Pavel Emelianov7562f872007-05-03 15:13:45 -0700934 if (!dev->dn_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700936 if (!dn_dev_islocal(dev, oldflp->fld_src))
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700937 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700938 if ((dev->flags & IFF_LOOPBACK) &&
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700939 oldflp->fld_dst &&
Pavel Emelianov7562f872007-05-03 15:13:45 -0700940 !dn_dev_islocal(dev, oldflp->fld_dst))
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700941 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700942
943 dev_out = dev;
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700944 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
Eric Dumazetc6d14c82009-11-04 05:43:23 -0800946 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (dev_out == NULL)
948 goto out;
949 dev_hold(dev_out);
950source_ok:
951 ;
952 }
953
954 /* No destination? Assume its local */
955 if (!fl.fld_dst) {
956 fl.fld_dst = fl.fld_src;
957
958 err = -EADDRNOTAVAIL;
959 if (dev_out)
960 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700961 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 dev_hold(dev_out);
963 if (!fl.fld_dst) {
964 fl.fld_dst =
965 fl.fld_src = dnet_select_source(dev_out, 0,
966 RT_SCOPE_HOST);
967 if (!fl.fld_dst)
968 goto out;
969 }
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700970 fl.oif = init_net.loopback_dev->ifindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 res.type = RTN_LOCAL;
972 goto make_route;
973 }
974
975 if (decnet_debug_level & 16)
976 printk(KERN_DEBUG
977 "dn_route_output_slow: initial checks complete."
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800978 " dst=%o4x src=%04x oif=%d try_hard=%d\n",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800979 le16_to_cpu(fl.fld_dst), le16_to_cpu(fl.fld_src),
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800980 fl.oif, try_hard);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 /*
983 * N.B. If the kernel is compiled without router support then
984 * dn_fib_lookup() will evaluate to non-zero so this if () block
985 * will always be executed.
986 */
987 err = -ESRCH;
988 if (try_hard || (err = dn_fib_lookup(&fl, &res)) != 0) {
989 struct dn_dev *dn_db;
990 if (err != -ESRCH)
991 goto out;
992 /*
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900993 * Here the fallback is basically the standard algorithm for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 * routing in endnodes which is described in the DECnet routing
995 * docs
996 *
997 * If we are not trying hard, look in neighbour cache.
998 * The result is tested to ensure that if a specific output
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900999 * device/source address was requested, then we honour that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 * here
1001 */
1002 if (!try_hard) {
Eric W. Biederman426b5302008-01-24 00:13:18 -08001003 neigh = neigh_lookup_nodev(&dn_neigh_table, &init_net, &fl.fld_dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (neigh) {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001005 if ((oldflp->oif &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 (neigh->dev->ifindex != oldflp->oif)) ||
1007 (oldflp->fld_src &&
1008 (!dn_dev_islocal(neigh->dev,
1009 oldflp->fld_src)))) {
1010 neigh_release(neigh);
1011 neigh = NULL;
1012 } else {
1013 if (dev_out)
1014 dev_put(dev_out);
1015 if (dn_dev_islocal(neigh->dev, fl.fld_dst)) {
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001016 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 res.type = RTN_LOCAL;
1018 } else {
1019 dev_out = neigh->dev;
1020 }
1021 dev_hold(dev_out);
1022 goto select_source;
1023 }
1024 }
1025 }
1026
1027 /* Not there? Perhaps its a local address */
1028 if (dev_out == NULL)
1029 dev_out = dn_dev_get_default();
1030 err = -ENODEV;
1031 if (dev_out == NULL)
1032 goto out;
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001033 dn_db = rcu_dereference_raw(dev_out->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 /* Possible improvement - check all devices for local addr */
1035 if (dn_dev_islocal(dev_out, fl.fld_dst)) {
1036 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001037 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 dev_hold(dev_out);
1039 res.type = RTN_LOCAL;
1040 goto select_source;
1041 }
1042 /* Not local either.... try sending it to the default router */
1043 neigh = neigh_clone(dn_db->router);
1044 BUG_ON(neigh && neigh->dev != dev_out);
1045
1046 /* Ok then, we assume its directly connected and move on */
1047select_source:
1048 if (neigh)
1049 gateway = ((struct dn_neigh *)neigh)->addr;
1050 if (gateway == 0)
1051 gateway = fl.fld_dst;
1052 if (fl.fld_src == 0) {
1053 fl.fld_src = dnet_select_source(dev_out, gateway,
1054 res.type == RTN_LOCAL ?
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001055 RT_SCOPE_HOST :
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 RT_SCOPE_LINK);
1057 if (fl.fld_src == 0 && res.type != RTN_LOCAL)
1058 goto e_addr;
1059 }
1060 fl.oif = dev_out->ifindex;
1061 goto make_route;
1062 }
1063 free_res = 1;
1064
1065 if (res.type == RTN_NAT)
1066 goto e_inval;
1067
1068 if (res.type == RTN_LOCAL) {
1069 if (!fl.fld_src)
1070 fl.fld_src = fl.fld_dst;
1071 if (dev_out)
1072 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001073 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 dev_hold(dev_out);
1075 fl.oif = dev_out->ifindex;
1076 if (res.fi)
1077 dn_fib_info_put(res.fi);
1078 res.fi = NULL;
1079 goto make_route;
1080 }
1081
1082 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1083 dn_fib_select_multipath(&fl, &res);
1084
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001085 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 * We could add some logic to deal with default routes here and
1087 * get rid of some of the special casing above.
1088 */
1089
1090 if (!fl.fld_src)
1091 fl.fld_src = DN_FIB_RES_PREFSRC(res);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 if (dev_out)
1094 dev_put(dev_out);
1095 dev_out = DN_FIB_RES_DEV(res);
1096 dev_hold(dev_out);
1097 fl.oif = dev_out->ifindex;
1098 gateway = DN_FIB_RES_GW(res);
1099
1100make_route:
1101 if (dev_out->flags & IFF_LOOPBACK)
1102 flags |= RTCF_LOCAL;
1103
1104 rt = dst_alloc(&dn_dst_ops);
1105 if (rt == NULL)
1106 goto e_nobufs;
1107
Changli Gaod8d1f302010-06-10 23:31:35 -07001108 atomic_set(&rt->dst.__refcnt, 1);
1109 rt->dst.flags = DST_HOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 rt->fl.fld_src = oldflp->fld_src;
1112 rt->fl.fld_dst = oldflp->fld_dst;
1113 rt->fl.oif = oldflp->oif;
1114 rt->fl.iif = 0;
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001115 rt->fl.mark = oldflp->mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 rt->rt_saddr = fl.fld_src;
1118 rt->rt_daddr = fl.fld_dst;
1119 rt->rt_gateway = gateway ? gateway : fl.fld_dst;
1120 rt->rt_local_src = fl.fld_src;
1121
1122 rt->rt_dst_map = fl.fld_dst;
1123 rt->rt_src_map = fl.fld_src;
1124
Changli Gaod8d1f302010-06-10 23:31:35 -07001125 rt->dst.dev = dev_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 dev_hold(dev_out);
Changli Gaod8d1f302010-06-10 23:31:35 -07001127 rt->dst.neighbour = neigh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 neigh = NULL;
1129
Changli Gaod8d1f302010-06-10 23:31:35 -07001130 rt->dst.lastuse = jiffies;
1131 rt->dst.output = dn_output;
1132 rt->dst.input = dn_rt_bug;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 rt->rt_flags = flags;
1134 if (flags & RTCF_LOCAL)
Changli Gaod8d1f302010-06-10 23:31:35 -07001135 rt->dst.input = dn_nsp_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 err = dn_rt_set_next_hop(rt, &res);
1138 if (err)
1139 goto e_neighbour;
1140
1141 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
1142 dn_insert_route(rt, hash, (struct dn_route **)pprt);
1143
1144done:
1145 if (neigh)
1146 neigh_release(neigh);
1147 if (free_res)
1148 dn_fib_res_put(&res);
1149 if (dev_out)
1150 dev_put(dev_out);
1151out:
1152 return err;
1153
1154e_addr:
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001155 err = -EADDRNOTAVAIL;
1156 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157e_inval:
1158 err = -EINVAL;
1159 goto done;
1160e_nobufs:
1161 err = -ENOBUFS;
1162 goto done;
1163e_neighbour:
Changli Gaod8d1f302010-06-10 23:31:35 -07001164 dst_free(&rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 goto e_nobufs;
1166}
1167
1168
1169/*
1170 * N.B. The flags may be moved into the flowi at some future stage.
1171 */
1172static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *flp, int flags)
1173{
1174 unsigned hash = dn_hash(flp->fld_src, flp->fld_dst);
1175 struct dn_route *rt = NULL;
1176
1177 if (!(flags & MSG_TRYHARD)) {
1178 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001179 for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
Changli Gaod8d1f302010-06-10 23:31:35 -07001180 rt = rcu_dereference_bh(rt->dst.dn_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 if ((flp->fld_dst == rt->fl.fld_dst) &&
1182 (flp->fld_src == rt->fl.fld_src) &&
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001183 (flp->mark == rt->fl.mark) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 (rt->fl.iif == 0) &&
1185 (rt->fl.oif == flp->oif)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001186 dst_use(&rt->dst, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 rcu_read_unlock_bh();
Changli Gaod8d1f302010-06-10 23:31:35 -07001188 *pprt = &rt->dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 return 0;
1190 }
1191 }
1192 rcu_read_unlock_bh();
1193 }
1194
1195 return dn_route_output_slow(pprt, flp, flags);
1196}
1197
1198static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int flags)
1199{
1200 int err;
1201
1202 err = __dn_route_output_key(pprt, flp, flags);
1203 if (err == 0 && flp->proto) {
Alexey Dobriyan52479b62008-11-25 17:35:18 -08001204 err = xfrm_lookup(&init_net, pprt, flp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206 return err;
1207}
1208
1209int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock *sk, int flags)
1210{
1211 int err;
1212
1213 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1214 if (err == 0 && fl->proto) {
Alexey Dobriyan52479b62008-11-25 17:35:18 -08001215 err = xfrm_lookup(&init_net, pprt, fl, sk,
1216 (flags & MSG_DONTWAIT) ? 0 : XFRM_LOOKUP_WAIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
1218 return err;
1219}
1220
1221static int dn_route_input_slow(struct sk_buff *skb)
1222{
1223 struct dn_route *rt = NULL;
1224 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1225 struct net_device *in_dev = skb->dev;
1226 struct net_device *out_dev = NULL;
1227 struct dn_dev *dn_db;
1228 struct neighbour *neigh = NULL;
1229 unsigned hash;
1230 int flags = 0;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -08001231 __le16 gateway = 0;
1232 __le16 local_src = 0;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001233 struct flowi fl = { .nl_u = { .dn_u =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 { .daddr = cb->dst,
1235 .saddr = cb->src,
1236 .scope = RT_SCOPE_UNIVERSE,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 } },
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001238 .mark = skb->mark,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 .iif = skb->dev->ifindex };
1240 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
1241 int err = -EINVAL;
1242 int free_res = 0;
1243
1244 dev_hold(in_dev);
1245
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001246 if ((dn_db = rcu_dereference(in_dev->dn_ptr)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 goto out;
1248
1249 /* Zero source addresses are not allowed */
1250 if (fl.fld_src == 0)
1251 goto out;
1252
1253 /*
1254 * In this case we've just received a packet from a source
1255 * outside ourselves pretending to come from us. We don't
1256 * allow it any further to prevent routing loops, spoofing and
1257 * other nasties. Loopback packets already have the dst attached
1258 * so this only affects packets which have originated elsewhere.
1259 */
1260 err = -ENOTUNIQ;
1261 if (dn_dev_islocal(in_dev, cb->src))
1262 goto out;
1263
1264 err = dn_fib_lookup(&fl, &res);
1265 if (err) {
1266 if (err != -ESRCH)
1267 goto out;
1268 /*
1269 * Is the destination us ?
1270 */
1271 if (!dn_dev_islocal(in_dev, cb->dst))
1272 goto e_inval;
1273
1274 res.type = RTN_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 } else {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -08001276 __le16 src_map = fl.fld_src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 free_res = 1;
1278
1279 out_dev = DN_FIB_RES_DEV(res);
1280 if (out_dev == NULL) {
1281 if (net_ratelimit())
1282 printk(KERN_CRIT "Bug in dn_route_input_slow() "
1283 "No output device\n");
1284 goto e_inval;
1285 }
1286 dev_hold(out_dev);
1287
1288 if (res.r)
Steven Whitehousea8731cb2006-08-09 15:56:46 -07001289 src_map = fl.fld_src; /* no NAT support for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 gateway = DN_FIB_RES_GW(res);
1292 if (res.type == RTN_NAT) {
1293 fl.fld_dst = dn_fib_rules_map_destination(fl.fld_dst, &res);
1294 dn_fib_res_put(&res);
1295 free_res = 0;
1296 if (dn_fib_lookup(&fl, &res))
1297 goto e_inval;
1298 free_res = 1;
1299 if (res.type != RTN_UNICAST)
1300 goto e_inval;
1301 flags |= RTCF_DNAT;
1302 gateway = fl.fld_dst;
1303 }
1304 fl.fld_src = src_map;
1305 }
1306
1307 switch(res.type) {
1308 case RTN_UNICAST:
1309 /*
1310 * Forwarding check here, we only check for forwarding
1311 * being turned off, if you want to only forward intra
1312 * area, its up to you to set the routing tables up
1313 * correctly.
1314 */
1315 if (dn_db->parms.forwarding == 0)
1316 goto e_inval;
1317
1318 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1319 dn_fib_select_multipath(&fl, &res);
1320
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001321 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
1323 * flag as a hint to set the intra-ethernet bit when
1324 * forwarding. If we've got NAT in operation, we don't do
1325 * this optimisation.
1326 */
1327 if (out_dev == in_dev && !(flags & RTCF_NAT))
1328 flags |= RTCF_DOREDIRECT;
1329
1330 local_src = DN_FIB_RES_PREFSRC(res);
1331
1332 case RTN_BLACKHOLE:
1333 case RTN_UNREACHABLE:
1334 break;
1335 case RTN_LOCAL:
1336 flags |= RTCF_LOCAL;
1337 fl.fld_src = cb->dst;
1338 fl.fld_dst = cb->src;
1339
1340 /* Routing tables gave us a gateway */
1341 if (gateway)
1342 goto make_route;
1343
1344 /* Packet was intra-ethernet, so we know its on-link */
Steven Whitehouse3a31b9d2006-10-18 20:45:22 -07001345 if (cb->rt_flags & DN_RT_F_IE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 gateway = cb->src;
1347 flags |= RTCF_DIRECTSRC;
1348 goto make_route;
1349 }
1350
1351 /* Use the default router if there is one */
1352 neigh = neigh_clone(dn_db->router);
1353 if (neigh) {
1354 gateway = ((struct dn_neigh *)neigh)->addr;
1355 goto make_route;
1356 }
1357
1358 /* Close eyes and pray */
1359 gateway = cb->src;
1360 flags |= RTCF_DIRECTSRC;
1361 goto make_route;
1362 default:
1363 goto e_inval;
1364 }
1365
1366make_route:
1367 rt = dst_alloc(&dn_dst_ops);
1368 if (rt == NULL)
1369 goto e_nobufs;
1370
1371 rt->rt_saddr = fl.fld_src;
1372 rt->rt_daddr = fl.fld_dst;
1373 rt->rt_gateway = fl.fld_dst;
1374 if (gateway)
1375 rt->rt_gateway = gateway;
1376 rt->rt_local_src = local_src ? local_src : rt->rt_saddr;
1377
1378 rt->rt_dst_map = fl.fld_dst;
1379 rt->rt_src_map = fl.fld_src;
1380
1381 rt->fl.fld_src = cb->src;
1382 rt->fl.fld_dst = cb->dst;
1383 rt->fl.oif = 0;
1384 rt->fl.iif = in_dev->ifindex;
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001385 rt->fl.mark = fl.mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Changli Gaod8d1f302010-06-10 23:31:35 -07001387 rt->dst.flags = DST_HOST;
1388 rt->dst.neighbour = neigh;
1389 rt->dst.dev = out_dev;
1390 rt->dst.lastuse = jiffies;
1391 rt->dst.output = dn_rt_bug;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 switch(res.type) {
1393 case RTN_UNICAST:
Changli Gaod8d1f302010-06-10 23:31:35 -07001394 rt->dst.input = dn_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 break;
1396 case RTN_LOCAL:
Changli Gaod8d1f302010-06-10 23:31:35 -07001397 rt->dst.output = dn_output;
1398 rt->dst.input = dn_nsp_rx;
1399 rt->dst.dev = in_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 flags |= RTCF_LOCAL;
1401 break;
1402 default:
1403 case RTN_UNREACHABLE:
1404 case RTN_BLACKHOLE:
Changli Gaod8d1f302010-06-10 23:31:35 -07001405 rt->dst.input = dst_discard;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 }
1407 rt->rt_flags = flags;
Changli Gaod8d1f302010-06-10 23:31:35 -07001408 if (rt->dst.dev)
1409 dev_hold(rt->dst.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 err = dn_rt_set_next_hop(rt, &res);
1412 if (err)
1413 goto e_neighbour;
1414
1415 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
Eric Dumazetadf30902009-06-02 05:19:30 +00001416 dn_insert_route(rt, hash, &rt);
Changli Gaod8d1f302010-06-10 23:31:35 -07001417 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
1419done:
1420 if (neigh)
1421 neigh_release(neigh);
1422 if (free_res)
1423 dn_fib_res_put(&res);
1424 dev_put(in_dev);
1425 if (out_dev)
1426 dev_put(out_dev);
1427out:
1428 return err;
1429
1430e_inval:
1431 err = -EINVAL;
1432 goto done;
1433
1434e_nobufs:
1435 err = -ENOBUFS;
1436 goto done;
1437
1438e_neighbour:
Changli Gaod8d1f302010-06-10 23:31:35 -07001439 dst_free(&rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 goto done;
1441}
1442
Roel Kluin5eaa65b2008-12-10 15:18:31 -08001443static int dn_route_input(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 struct dn_route *rt;
1446 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1447 unsigned hash = dn_hash(cb->src, cb->dst);
1448
Eric Dumazetadf30902009-06-02 05:19:30 +00001449 if (skb_dst(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 return 0;
1451
1452 rcu_read_lock();
1453 for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt != NULL;
Changli Gaod8d1f302010-06-10 23:31:35 -07001454 rt = rcu_dereference(rt->dst.dn_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 if ((rt->fl.fld_src == cb->src) &&
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001456 (rt->fl.fld_dst == cb->dst) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 (rt->fl.oif == 0) &&
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001458 (rt->fl.mark == skb->mark) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 (rt->fl.iif == cb->iif)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001460 dst_use(&rt->dst, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 rcu_read_unlock();
Eric Dumazetadf30902009-06-02 05:19:30 +00001462 skb_dst_set(skb, (struct dst_entry *)rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 return 0;
1464 }
1465 }
1466 rcu_read_unlock();
1467
1468 return dn_route_input_slow(skb);
1469}
1470
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001471static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1472 int event, int nowait, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
Eric Dumazetadf30902009-06-02 05:19:30 +00001474 struct dn_route *rt = (struct dn_route *)skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 struct rtmsg *r;
1476 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001477 unsigned char *b = skb_tail_pointer(skb);
Thomas Grafe3703b32006-11-27 09:27:07 -08001478 long expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001480 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 r = NLMSG_DATA(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 r->rtm_family = AF_DECnet;
1483 r->rtm_dst_len = 16;
1484 r->rtm_src_len = 0;
1485 r->rtm_tos = 0;
1486 r->rtm_table = RT_TABLE_MAIN;
Patrick McHardy9e762a42006-08-10 23:09:48 -07001487 RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 r->rtm_type = rt->rt_type;
1489 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1490 r->rtm_scope = RT_SCOPE_UNIVERSE;
1491 r->rtm_protocol = RTPROT_UNSPEC;
1492 if (rt->rt_flags & RTCF_NOTIFY)
1493 r->rtm_flags |= RTM_F_NOTIFY;
1494 RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr);
1495 if (rt->fl.fld_src) {
1496 r->rtm_src_len = 16;
1497 RTA_PUT(skb, RTA_SRC, 2, &rt->fl.fld_src);
1498 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001499 if (rt->dst.dev)
1500 RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->dst.dev->ifindex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 /*
1502 * Note to self - change this if input routes reverse direction when
1503 * they deal only with inputs and not with replies like they do
1504 * currently.
1505 */
1506 RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src);
1507 if (rt->rt_daddr != rt->rt_gateway)
1508 RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway);
Changli Gaod8d1f302010-06-10 23:31:35 -07001509 if (rtnetlink_put_metrics(skb, rt->dst.metrics) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 goto rtattr_failure;
Changli Gaod8d1f302010-06-10 23:31:35 -07001511 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
1512 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires,
1513 rt->dst.error) < 0)
Thomas Grafe3703b32006-11-27 09:27:07 -08001514 goto rtattr_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 if (rt->fl.iif)
1516 RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fl.iif);
1517
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001518 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 return skb->len;
1520
1521nlmsg_failure:
1522rtattr_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001523 nlmsg_trim(skb, b);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001524 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
1527/*
1528 * This is called by both endnodes and routers now.
1529 */
Thomas Graffa34ddd2007-03-22 11:57:46 -07001530static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001532 struct net *net = sock_net(in_skb->sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 struct rtattr **rta = arg;
1534 struct rtmsg *rtm = NLMSG_DATA(nlh);
1535 struct dn_route *rt = NULL;
1536 struct dn_skb_cb *cb;
1537 int err;
1538 struct sk_buff *skb;
1539 struct flowi fl;
1540
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001541 if (!net_eq(net, &init_net))
Denis V. Lunevb8542722007-12-01 00:21:31 +11001542 return -EINVAL;
1543
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 memset(&fl, 0, sizeof(fl));
1545 fl.proto = DNPROTO_NSP;
1546
1547 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1548 if (skb == NULL)
1549 return -ENOBUFS;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001550 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 cb = DN_SKB_CB(skb);
1552
1553 if (rta[RTA_SRC-1])
1554 memcpy(&fl.fld_src, RTA_DATA(rta[RTA_SRC-1]), 2);
1555 if (rta[RTA_DST-1])
1556 memcpy(&fl.fld_dst, RTA_DATA(rta[RTA_DST-1]), 2);
1557 if (rta[RTA_IIF-1])
1558 memcpy(&fl.iif, RTA_DATA(rta[RTA_IIF-1]), sizeof(int));
1559
1560 if (fl.iif) {
1561 struct net_device *dev;
Eric W. Biederman881d9662007-09-17 11:56:21 -07001562 if ((dev = dev_get_by_index(&init_net, fl.iif)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 kfree_skb(skb);
1564 return -ENODEV;
1565 }
1566 if (!dev->dn_ptr) {
1567 dev_put(dev);
1568 kfree_skb(skb);
1569 return -ENODEV;
1570 }
YOSHIFUJI Hideakib98999d2007-12-12 03:51:49 +09001571 skb->protocol = htons(ETH_P_DNA_RT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 skb->dev = dev;
1573 cb->src = fl.fld_src;
1574 cb->dst = fl.fld_dst;
1575 local_bh_disable();
1576 err = dn_route_input(skb);
1577 local_bh_enable();
1578 memset(cb, 0, sizeof(struct dn_skb_cb));
Eric Dumazetadf30902009-06-02 05:19:30 +00001579 rt = (struct dn_route *)skb_dst(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -07001580 if (!err && -rt->dst.error)
1581 err = rt->dst.error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 } else {
1583 int oif = 0;
1584 if (rta[RTA_OIF - 1])
1585 memcpy(&oif, RTA_DATA(rta[RTA_OIF - 1]), sizeof(int));
1586 fl.oif = oif;
1587 err = dn_route_output_key((struct dst_entry **)&rt, &fl, 0);
1588 }
1589
1590 if (skb->dev)
1591 dev_put(skb->dev);
1592 skb->dev = NULL;
1593 if (err)
1594 goto out_free;
Changli Gaod8d1f302010-06-10 23:31:35 -07001595 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 if (rtm->rtm_flags & RTM_F_NOTIFY)
1597 rt->rt_flags |= RTCF_NOTIFY;
1598
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001599 err = dn_rt_fill_info(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq, RTM_NEWROUTE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601 if (err == 0)
1602 goto out_free;
1603 if (err < 0) {
1604 err = -EMSGSIZE;
1605 goto out_free;
1606 }
1607
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08001608 return rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610out_free:
1611 kfree_skb(skb);
1612 return err;
1613}
1614
1615/*
1616 * For routers, this is called from dn_fib_dump, but for endnodes its
1617 * called directly from the rtnetlink dispatch table.
1618 */
1619int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1620{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001621 struct net *net = sock_net(skb->sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 struct dn_route *rt;
1623 int h, s_h;
1624 int idx, s_idx;
1625
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001626 if (!net_eq(net, &init_net))
Denis V. Lunevb8542722007-12-01 00:21:31 +11001627 return 0;
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
1630 return -EINVAL;
1631 if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
1632 return 0;
1633
1634 s_h = cb->args[0];
1635 s_idx = idx = cb->args[1];
1636 for(h = 0; h <= dn_rt_hash_mask; h++) {
1637 if (h < s_h)
1638 continue;
1639 if (h > s_h)
1640 s_idx = 0;
1641 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001642 for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 rt;
Changli Gaod8d1f302010-06-10 23:31:35 -07001644 rt = rcu_dereference_bh(rt->dst.dn_next), idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 if (idx < s_idx)
1646 continue;
Changli Gaod8d1f302010-06-10 23:31:35 -07001647 skb_dst_set(skb, dst_clone(&rt->dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001649 cb->nlh->nlmsg_seq, RTM_NEWROUTE,
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001650 1, NLM_F_MULTI) <= 0) {
Eric Dumazetadf30902009-06-02 05:19:30 +00001651 skb_dst_drop(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 rcu_read_unlock_bh();
1653 goto done;
1654 }
Eric Dumazetadf30902009-06-02 05:19:30 +00001655 skb_dst_drop(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 }
1657 rcu_read_unlock_bh();
1658 }
1659
1660done:
1661 cb->args[0] = h;
1662 cb->args[1] = idx;
1663 return skb->len;
1664}
1665
1666#ifdef CONFIG_PROC_FS
1667struct dn_rt_cache_iter_state {
1668 int bucket;
1669};
1670
1671static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
1672{
1673 struct dn_route *rt = NULL;
1674 struct dn_rt_cache_iter_state *s = seq->private;
1675
1676 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
1677 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001678 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 if (rt)
1680 break;
1681 rcu_read_unlock_bh();
1682 }
Paul E. McKenneya898def2010-02-22 17:04:49 -08001683 return rt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
1686static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
1687{
Eric Dumazet0d89d792008-01-10 22:35:21 -08001688 struct dn_rt_cache_iter_state *s = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001690 rt = rcu_dereference_bh(rt->dst.dn_next);
1691 while (!rt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 rcu_read_unlock_bh();
1693 if (--s->bucket < 0)
1694 break;
1695 rcu_read_lock_bh();
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001696 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 }
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001698 return rt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
1701static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
1702{
1703 struct dn_route *rt = dn_rt_cache_get_first(seq);
1704
1705 if (rt) {
1706 while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
1707 --*pos;
1708 }
1709 return *pos ? NULL : rt;
1710}
1711
1712static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1713{
1714 struct dn_route *rt = dn_rt_cache_get_next(seq, v);
1715 ++*pos;
1716 return rt;
1717}
1718
1719static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
1720{
1721 if (v)
1722 rcu_read_unlock_bh();
1723}
1724
1725static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
1726{
1727 struct dn_route *rt = v;
1728 char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
1729
1730 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
Changli Gaod8d1f302010-06-10 23:31:35 -07001731 rt->dst.dev ? rt->dst.dev->name : "*",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -08001732 dn_addr2asc(le16_to_cpu(rt->rt_daddr), buf1),
1733 dn_addr2asc(le16_to_cpu(rt->rt_saddr), buf2),
Changli Gaod8d1f302010-06-10 23:31:35 -07001734 atomic_read(&rt->dst.__refcnt),
1735 rt->dst.__use,
1736 (int) dst_metric(&rt->dst, RTAX_RTT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 return 0;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001738}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001740static const struct seq_operations dn_rt_cache_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 .start = dn_rt_cache_seq_start,
1742 .next = dn_rt_cache_seq_next,
1743 .stop = dn_rt_cache_seq_stop,
1744 .show = dn_rt_cache_seq_show,
1745};
1746
1747static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
1748{
Pavel Emelyanov31164082007-10-10 02:30:23 -07001749 return seq_open_private(file, &dn_rt_cache_seq_ops,
1750 sizeof(struct dn_rt_cache_iter_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
Arjan van de Ven9a321442007-02-12 00:55:35 -08001753static const struct file_operations dn_rt_cache_seq_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .owner = THIS_MODULE,
1755 .open = dn_rt_cache_seq_open,
1756 .read = seq_read,
1757 .llseek = seq_lseek,
1758 .release = seq_release_private,
1759};
1760
1761#endif /* CONFIG_PROC_FS */
1762
1763void __init dn_route_init(void)
1764{
1765 int i, goal, order;
1766
Alexey Dobriyane5d679f332006-08-26 19:25:52 -07001767 dn_dst_ops.kmem_cachep =
1768 kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001769 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
Eric Dumazetfc66f952010-10-08 06:37:34 +00001770 dst_entries_init(&dn_dst_ops);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001771 setup_timer(&dn_route_timer, dn_dst_check_expire, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1773 add_timer(&dn_route_timer);
1774
Jan Beulich44813742009-09-21 17:03:05 -07001775 goal = totalram_pages >> (26 - PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
1777 for(order = 0; (1UL << order) < goal; order++)
1778 /* NOTHING */;
1779
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001780 /*
1781 * Only want 1024 entries max, since the table is very, very unlikely
1782 * to be larger than that.
1783 */
1784 while(order && ((((1UL << order) * PAGE_SIZE) /
1785 sizeof(struct dn_rt_hash_bucket)) >= 2048))
1786 order--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001788 do {
1789 dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
1790 sizeof(struct dn_rt_hash_bucket);
1791 while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
1792 dn_rt_hash_mask--;
1793 dn_rt_hash_table = (struct dn_rt_hash_bucket *)
1794 __get_free_pages(GFP_ATOMIC, order);
1795 } while (dn_rt_hash_table == NULL && --order > 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
1797 if (!dn_rt_hash_table)
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001798 panic("Failed to allocate DECnet route cache hash table\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001800 printk(KERN_INFO
1801 "DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
1802 dn_rt_hash_mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 (long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
1804
1805 dn_rt_hash_mask--;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001806 for(i = 0; i <= dn_rt_hash_mask; i++) {
1807 spin_lock_init(&dn_rt_hash_table[i].lock);
1808 dn_rt_hash_table[i].chain = NULL;
1809 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001811 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001813 proc_net_fops_create(&init_net, "decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
Thomas Graffa34ddd2007-03-22 11:57:46 -07001814
1815#ifdef CONFIG_DECNET_ROUTER
1816 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute, dn_fib_dump);
1817#else
1818 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute,
1819 dn_cache_dump);
1820#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821}
1822
1823void __exit dn_route_cleanup(void)
1824{
1825 del_timer(&dn_route_timer);
1826 dn_run_flush(0);
1827
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001828 proc_net_remove(&init_net, "decnet_cache");
Eric Dumazetfc66f952010-10-08 06:37:34 +00001829 dst_entries_destroy(&dn_dst_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830}
1831