blob: e2e926841fe6255e75f128f45919ba78fad2aa8f [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))) {
David S. Millerdefb3512010-12-08 21:16:57 -0800243 dst_metric_set(dst, RTAX_MTU, mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 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)
David S. Millerdefb3512010-12-08 21:16:57 -0800249 dst_metric_set(dst, RTAX_ADVMSS, mss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
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{
Changli Gao58116622010-11-12 18:43:55 +0000274 return ((fl1->fld_dst ^ fl2->fld_dst) |
275 (fl1->fld_src ^ fl2->fld_src) |
Thomas Graf47dcf0c2006-11-09 15:20:38 -0800276 (fl1->mark ^ fl2->mark) |
Changli Gao58116622010-11-12 18:43:55 +0000277 (fl1->fld_scope ^ fl2->fld_scope) |
David S. Miller8238b212006-10-12 00:49:15 -0700278 (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);
David S. Millerdefb3512010-12-08 21:16:57 -0800809 dst_import_metrics(&rt->dst, fi->fib_metrics);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811 rt->rt_type = res->type;
812
Changli Gaod8d1f302010-06-10 23:31:35 -0700813 if (dev != NULL && rt->dst.neighbour == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
815 if (IS_ERR(n))
816 return PTR_ERR(n);
Changli Gaod8d1f302010-06-10 23:31:35 -0700817 rt->dst.neighbour = n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
819
Changli Gaod8d1f302010-06-10 23:31:35 -0700820 if (dst_metric(&rt->dst, RTAX_MTU) == 0 ||
821 dst_metric(&rt->dst, RTAX_MTU) > rt->dst.dev->mtu)
David S. Millerdefb3512010-12-08 21:16:57 -0800822 dst_metric_set(&rt->dst, RTAX_MTU, rt->dst.dev->mtu);
Changli Gaod8d1f302010-06-10 23:31:35 -0700823 mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
824 if (dst_metric(&rt->dst, RTAX_ADVMSS) == 0 ||
825 dst_metric(&rt->dst, RTAX_ADVMSS) > mss)
David S. Millerdefb3512010-12-08 21:16:57 -0800826 dst_metric_set(&rt->dst, RTAX_ADVMSS, mss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return 0;
828}
829
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800830static inline int dn_match_addr(__le16 addr1, __le16 addr2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800832 __u16 tmp = le16_to_cpu(addr1) ^ le16_to_cpu(addr2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 int match = 16;
834 while(tmp) {
835 tmp >>= 1;
836 match--;
837 }
838 return match;
839}
840
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800841static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800843 __le16 saddr = 0;
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000844 struct dn_dev *dn_db;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 struct dn_ifaddr *ifa;
846 int best_match = 0;
847 int ret;
848
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000849 rcu_read_lock();
850 dn_db = rcu_dereference(dev->dn_ptr);
851 for (ifa = rcu_dereference(dn_db->ifa_list);
852 ifa != NULL;
853 ifa = rcu_dereference(ifa->ifa_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (ifa->ifa_scope > scope)
855 continue;
856 if (!daddr) {
857 saddr = ifa->ifa_local;
858 break;
859 }
860 ret = dn_match_addr(daddr, ifa->ifa_local);
861 if (ret > best_match)
862 saddr = ifa->ifa_local;
863 if (best_match == 0)
864 saddr = ifa->ifa_local;
865 }
Eric Dumazetfc766e4c2010-10-29 03:09:24 +0000866 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 return saddr;
869}
870
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800871static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
873 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
874}
875
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800876static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800878 __le16 mask = dnet_make_mask(res->prefixlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 return (daddr&~mask)|res->fi->fib_nh->nh_gw;
880}
881
882static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *oldflp, int try_hard)
883{
Changli Gao58116622010-11-12 18:43:55 +0000884 struct flowi fl = { .fld_dst = oldflp->fld_dst,
885 .fld_src = oldflp->fld_src,
886 .fld_scope = RT_SCOPE_UNIVERSE,
Thomas Graf47dcf0c2006-11-09 15:20:38 -0800887 .mark = oldflp->mark,
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700888 .iif = init_net.loopback_dev->ifindex,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 .oif = oldflp->oif };
890 struct dn_route *rt = NULL;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700891 struct net_device *dev_out = NULL, *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 struct neighbour *neigh = NULL;
893 unsigned hash;
894 unsigned flags = 0;
895 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
896 int err;
897 int free_res = 0;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800898 __le16 gateway = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 if (decnet_debug_level & 16)
901 printk(KERN_DEBUG
902 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800903 " iif=%d oif=%d\n", le16_to_cpu(oldflp->fld_dst),
904 le16_to_cpu(oldflp->fld_src),
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700905 oldflp->mark, init_net.loopback_dev->ifindex, oldflp->oif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907 /* If we have an output interface, verify its a DECnet device */
908 if (oldflp->oif) {
Eric W. Biederman881d9662007-09-17 11:56:21 -0700909 dev_out = dev_get_by_index(&init_net, oldflp->oif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 err = -ENODEV;
911 if (dev_out && dev_out->dn_ptr == NULL) {
912 dev_put(dev_out);
913 dev_out = NULL;
914 }
915 if (dev_out == NULL)
916 goto out;
917 }
918
919 /* If we have a source address, verify that its a local address */
920 if (oldflp->fld_src) {
921 err = -EADDRNOTAVAIL;
922
923 if (dev_out) {
924 if (dn_dev_islocal(dev_out, oldflp->fld_src))
925 goto source_ok;
926 dev_put(dev_out);
927 goto out;
928 }
Eric Dumazetc6d14c82009-11-04 05:43:23 -0800929 rcu_read_lock();
930 for_each_netdev_rcu(&init_net, dev) {
Pavel Emelianov7562f872007-05-03 15:13:45 -0700931 if (!dev->dn_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700933 if (!dn_dev_islocal(dev, oldflp->fld_src))
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700934 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700935 if ((dev->flags & IFF_LOOPBACK) &&
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700936 oldflp->fld_dst &&
Pavel Emelianov7562f872007-05-03 15:13:45 -0700937 !dn_dev_islocal(dev, oldflp->fld_dst))
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700938 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700939
940 dev_out = dev;
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700941 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 }
Eric Dumazetc6d14c82009-11-04 05:43:23 -0800943 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if (dev_out == NULL)
945 goto out;
946 dev_hold(dev_out);
947source_ok:
948 ;
949 }
950
951 /* No destination? Assume its local */
952 if (!fl.fld_dst) {
953 fl.fld_dst = fl.fld_src;
954
955 err = -EADDRNOTAVAIL;
956 if (dev_out)
957 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700958 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 dev_hold(dev_out);
960 if (!fl.fld_dst) {
961 fl.fld_dst =
962 fl.fld_src = dnet_select_source(dev_out, 0,
963 RT_SCOPE_HOST);
964 if (!fl.fld_dst)
965 goto out;
966 }
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700967 fl.oif = init_net.loopback_dev->ifindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 res.type = RTN_LOCAL;
969 goto make_route;
970 }
971
972 if (decnet_debug_level & 16)
973 printk(KERN_DEBUG
974 "dn_route_output_slow: initial checks complete."
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800975 " dst=%o4x src=%04x oif=%d try_hard=%d\n",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800976 le16_to_cpu(fl.fld_dst), le16_to_cpu(fl.fld_src),
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800977 fl.oif, try_hard);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 /*
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.
983 */
984 err = -ESRCH;
985 if (try_hard || (err = dn_fib_lookup(&fl, &res)) != 0) {
986 struct dn_dev *dn_db;
987 if (err != -ESRCH)
988 goto out;
989 /*
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900990 * Here the fallback is basically the standard algorithm for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 * routing in endnodes which is described in the DECnet routing
992 * docs
993 *
994 * If we are not trying hard, look in neighbour cache.
995 * The result is tested to ensure that if a specific output
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900996 * device/source address was requested, then we honour that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 * here
998 */
999 if (!try_hard) {
Eric W. Biederman426b5302008-01-24 00:13:18 -08001000 neigh = neigh_lookup_nodev(&dn_neigh_table, &init_net, &fl.fld_dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 if (neigh) {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001002 if ((oldflp->oif &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 (neigh->dev->ifindex != oldflp->oif)) ||
1004 (oldflp->fld_src &&
1005 (!dn_dev_islocal(neigh->dev,
1006 oldflp->fld_src)))) {
1007 neigh_release(neigh);
1008 neigh = NULL;
1009 } else {
1010 if (dev_out)
1011 dev_put(dev_out);
1012 if (dn_dev_islocal(neigh->dev, fl.fld_dst)) {
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001013 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 res.type = RTN_LOCAL;
1015 } else {
1016 dev_out = neigh->dev;
1017 }
1018 dev_hold(dev_out);
1019 goto select_source;
1020 }
1021 }
1022 }
1023
1024 /* Not there? Perhaps its a local address */
1025 if (dev_out == NULL)
1026 dev_out = dn_dev_get_default();
1027 err = -ENODEV;
1028 if (dev_out == NULL)
1029 goto out;
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001030 dn_db = rcu_dereference_raw(dev_out->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* Possible improvement - check all devices for local addr */
1032 if (dn_dev_islocal(dev_out, fl.fld_dst)) {
1033 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001034 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 dev_hold(dev_out);
1036 res.type = RTN_LOCAL;
1037 goto select_source;
1038 }
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);
1042
1043 /* Ok then, we assume its directly connected and move on */
1044select_source:
1045 if (neigh)
1046 gateway = ((struct dn_neigh *)neigh)->addr;
1047 if (gateway == 0)
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 ?
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001052 RT_SCOPE_HOST :
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 RT_SCOPE_LINK);
1054 if (fl.fld_src == 0 && res.type != RTN_LOCAL)
1055 goto e_addr;
1056 }
1057 fl.oif = dev_out->ifindex;
1058 goto make_route;
1059 }
1060 free_res = 1;
1061
1062 if (res.type == RTN_NAT)
1063 goto e_inval;
1064
1065 if (res.type == RTN_LOCAL) {
1066 if (!fl.fld_src)
1067 fl.fld_src = fl.fld_dst;
1068 if (dev_out)
1069 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001070 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 dev_hold(dev_out);
1072 fl.oif = dev_out->ifindex;
1073 if (res.fi)
1074 dn_fib_info_put(res.fi);
1075 res.fi = NULL;
1076 goto make_route;
1077 }
1078
1079 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1080 dn_fib_select_multipath(&fl, &res);
1081
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001082 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 * We could add some logic to deal with default routes here and
1084 * get rid of some of the special casing above.
1085 */
1086
1087 if (!fl.fld_src)
1088 fl.fld_src = DN_FIB_RES_PREFSRC(res);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (dev_out)
1091 dev_put(dev_out);
1092 dev_out = DN_FIB_RES_DEV(res);
1093 dev_hold(dev_out);
1094 fl.oif = dev_out->ifindex;
1095 gateway = DN_FIB_RES_GW(res);
1096
1097make_route:
1098 if (dev_out->flags & IFF_LOOPBACK)
1099 flags |= RTCF_LOCAL;
1100
1101 rt = dst_alloc(&dn_dst_ops);
1102 if (rt == NULL)
1103 goto e_nobufs;
1104
Changli Gaod8d1f302010-06-10 23:31:35 -07001105 atomic_set(&rt->dst.__refcnt, 1);
1106 rt->dst.flags = DST_HOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 rt->fl.fld_src = oldflp->fld_src;
1109 rt->fl.fld_dst = oldflp->fld_dst;
1110 rt->fl.oif = oldflp->oif;
1111 rt->fl.iif = 0;
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001112 rt->fl.mark = oldflp->mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 rt->rt_saddr = fl.fld_src;
1115 rt->rt_daddr = fl.fld_dst;
1116 rt->rt_gateway = gateway ? gateway : fl.fld_dst;
1117 rt->rt_local_src = fl.fld_src;
1118
1119 rt->rt_dst_map = fl.fld_dst;
1120 rt->rt_src_map = fl.fld_src;
1121
Changli Gaod8d1f302010-06-10 23:31:35 -07001122 rt->dst.dev = dev_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 dev_hold(dev_out);
Changli Gaod8d1f302010-06-10 23:31:35 -07001124 rt->dst.neighbour = neigh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 neigh = NULL;
1126
Changli Gaod8d1f302010-06-10 23:31:35 -07001127 rt->dst.lastuse = jiffies;
1128 rt->dst.output = dn_output;
1129 rt->dst.input = dn_rt_bug;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 rt->rt_flags = flags;
1131 if (flags & RTCF_LOCAL)
Changli Gaod8d1f302010-06-10 23:31:35 -07001132 rt->dst.input = dn_nsp_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 err = dn_rt_set_next_hop(rt, &res);
1135 if (err)
1136 goto e_neighbour;
1137
1138 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
1139 dn_insert_route(rt, hash, (struct dn_route **)pprt);
1140
1141done:
1142 if (neigh)
1143 neigh_release(neigh);
1144 if (free_res)
1145 dn_fib_res_put(&res);
1146 if (dev_out)
1147 dev_put(dev_out);
1148out:
1149 return err;
1150
1151e_addr:
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001152 err = -EADDRNOTAVAIL;
1153 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154e_inval:
1155 err = -EINVAL;
1156 goto done;
1157e_nobufs:
1158 err = -ENOBUFS;
1159 goto done;
1160e_neighbour:
Changli Gaod8d1f302010-06-10 23:31:35 -07001161 dst_free(&rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 goto e_nobufs;
1163}
1164
1165
1166/*
1167 * N.B. The flags may be moved into the flowi at some future stage.
1168 */
1169static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *flp, int flags)
1170{
1171 unsigned hash = dn_hash(flp->fld_src, flp->fld_dst);
1172 struct dn_route *rt = NULL;
1173
1174 if (!(flags & MSG_TRYHARD)) {
1175 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001176 for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
Changli Gaod8d1f302010-06-10 23:31:35 -07001177 rt = rcu_dereference_bh(rt->dst.dn_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 if ((flp->fld_dst == rt->fl.fld_dst) &&
1179 (flp->fld_src == rt->fl.fld_src) &&
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001180 (flp->mark == rt->fl.mark) &&
David S. Millerc7537962010-11-11 17:07:48 -08001181 dn_is_output_route(rt) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 (rt->fl.oif == flp->oif)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001183 dst_use(&rt->dst, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 rcu_read_unlock_bh();
Changli Gaod8d1f302010-06-10 23:31:35 -07001185 *pprt = &rt->dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 return 0;
1187 }
1188 }
1189 rcu_read_unlock_bh();
1190 }
1191
1192 return dn_route_output_slow(pprt, flp, flags);
1193}
1194
1195static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int flags)
1196{
1197 int err;
1198
1199 err = __dn_route_output_key(pprt, flp, flags);
1200 if (err == 0 && flp->proto) {
Alexey Dobriyan52479b62008-11-25 17:35:18 -08001201 err = xfrm_lookup(&init_net, pprt, flp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
1203 return err;
1204}
1205
1206int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock *sk, int flags)
1207{
1208 int err;
1209
1210 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1211 if (err == 0 && fl->proto) {
Alexey Dobriyan52479b62008-11-25 17:35:18 -08001212 err = xfrm_lookup(&init_net, pprt, fl, sk,
1213 (flags & MSG_DONTWAIT) ? 0 : XFRM_LOOKUP_WAIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
1215 return err;
1216}
1217
1218static int dn_route_input_slow(struct sk_buff *skb)
1219{
1220 struct dn_route *rt = NULL;
1221 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1222 struct net_device *in_dev = skb->dev;
1223 struct net_device *out_dev = NULL;
1224 struct dn_dev *dn_db;
1225 struct neighbour *neigh = NULL;
1226 unsigned hash;
1227 int flags = 0;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -08001228 __le16 gateway = 0;
1229 __le16 local_src = 0;
Changli Gao58116622010-11-12 18:43:55 +00001230 struct flowi fl = { .fld_dst = cb->dst,
1231 .fld_src = cb->src,
1232 .fld_scope = RT_SCOPE_UNIVERSE,
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001233 .mark = skb->mark,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 .iif = skb->dev->ifindex };
1235 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
1236 int err = -EINVAL;
1237 int free_res = 0;
1238
1239 dev_hold(in_dev);
1240
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001241 if ((dn_db = rcu_dereference(in_dev->dn_ptr)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 goto out;
1243
1244 /* Zero source addresses are not allowed */
1245 if (fl.fld_src == 0)
1246 goto out;
1247
1248 /*
1249 * In this case we've just received a packet from a source
1250 * outside ourselves pretending to come from us. We don't
1251 * allow it any further to prevent routing loops, spoofing and
1252 * other nasties. Loopback packets already have the dst attached
1253 * so this only affects packets which have originated elsewhere.
1254 */
1255 err = -ENOTUNIQ;
1256 if (dn_dev_islocal(in_dev, cb->src))
1257 goto out;
1258
1259 err = dn_fib_lookup(&fl, &res);
1260 if (err) {
1261 if (err != -ESRCH)
1262 goto out;
1263 /*
1264 * Is the destination us ?
1265 */
1266 if (!dn_dev_islocal(in_dev, cb->dst))
1267 goto e_inval;
1268
1269 res.type = RTN_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 } else {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -08001271 __le16 src_map = fl.fld_src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 free_res = 1;
1273
1274 out_dev = DN_FIB_RES_DEV(res);
1275 if (out_dev == NULL) {
1276 if (net_ratelimit())
1277 printk(KERN_CRIT "Bug in dn_route_input_slow() "
1278 "No output device\n");
1279 goto e_inval;
1280 }
1281 dev_hold(out_dev);
1282
1283 if (res.r)
Steven Whitehousea8731cb2006-08-09 15:56:46 -07001284 src_map = fl.fld_src; /* no NAT support for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 gateway = DN_FIB_RES_GW(res);
1287 if (res.type == RTN_NAT) {
1288 fl.fld_dst = dn_fib_rules_map_destination(fl.fld_dst, &res);
1289 dn_fib_res_put(&res);
1290 free_res = 0;
1291 if (dn_fib_lookup(&fl, &res))
1292 goto e_inval;
1293 free_res = 1;
1294 if (res.type != RTN_UNICAST)
1295 goto e_inval;
1296 flags |= RTCF_DNAT;
1297 gateway = fl.fld_dst;
1298 }
1299 fl.fld_src = src_map;
1300 }
1301
1302 switch(res.type) {
1303 case RTN_UNICAST:
1304 /*
1305 * Forwarding check here, we only check for forwarding
1306 * being turned off, if you want to only forward intra
1307 * area, its up to you to set the routing tables up
1308 * correctly.
1309 */
1310 if (dn_db->parms.forwarding == 0)
1311 goto e_inval;
1312
1313 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1314 dn_fib_select_multipath(&fl, &res);
1315
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001316 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
1318 * flag as a hint to set the intra-ethernet bit when
1319 * forwarding. If we've got NAT in operation, we don't do
1320 * this optimisation.
1321 */
1322 if (out_dev == in_dev && !(flags & RTCF_NAT))
1323 flags |= RTCF_DOREDIRECT;
1324
1325 local_src = DN_FIB_RES_PREFSRC(res);
1326
1327 case RTN_BLACKHOLE:
1328 case RTN_UNREACHABLE:
1329 break;
1330 case RTN_LOCAL:
1331 flags |= RTCF_LOCAL;
1332 fl.fld_src = cb->dst;
1333 fl.fld_dst = cb->src;
1334
1335 /* Routing tables gave us a gateway */
1336 if (gateway)
1337 goto make_route;
1338
1339 /* Packet was intra-ethernet, so we know its on-link */
Steven Whitehouse3a31b9d2006-10-18 20:45:22 -07001340 if (cb->rt_flags & DN_RT_F_IE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 gateway = cb->src;
1342 flags |= RTCF_DIRECTSRC;
1343 goto make_route;
1344 }
1345
1346 /* Use the default router if there is one */
1347 neigh = neigh_clone(dn_db->router);
1348 if (neigh) {
1349 gateway = ((struct dn_neigh *)neigh)->addr;
1350 goto make_route;
1351 }
1352
1353 /* Close eyes and pray */
1354 gateway = cb->src;
1355 flags |= RTCF_DIRECTSRC;
1356 goto make_route;
1357 default:
1358 goto e_inval;
1359 }
1360
1361make_route:
1362 rt = dst_alloc(&dn_dst_ops);
1363 if (rt == NULL)
1364 goto e_nobufs;
1365
1366 rt->rt_saddr = fl.fld_src;
1367 rt->rt_daddr = fl.fld_dst;
1368 rt->rt_gateway = fl.fld_dst;
1369 if (gateway)
1370 rt->rt_gateway = gateway;
1371 rt->rt_local_src = local_src ? local_src : rt->rt_saddr;
1372
1373 rt->rt_dst_map = fl.fld_dst;
1374 rt->rt_src_map = fl.fld_src;
1375
1376 rt->fl.fld_src = cb->src;
1377 rt->fl.fld_dst = cb->dst;
1378 rt->fl.oif = 0;
1379 rt->fl.iif = in_dev->ifindex;
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001380 rt->fl.mark = fl.mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Changli Gaod8d1f302010-06-10 23:31:35 -07001382 rt->dst.flags = DST_HOST;
1383 rt->dst.neighbour = neigh;
1384 rt->dst.dev = out_dev;
1385 rt->dst.lastuse = jiffies;
1386 rt->dst.output = dn_rt_bug;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 switch(res.type) {
1388 case RTN_UNICAST:
Changli Gaod8d1f302010-06-10 23:31:35 -07001389 rt->dst.input = dn_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 break;
1391 case RTN_LOCAL:
Changli Gaod8d1f302010-06-10 23:31:35 -07001392 rt->dst.output = dn_output;
1393 rt->dst.input = dn_nsp_rx;
1394 rt->dst.dev = in_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 flags |= RTCF_LOCAL;
1396 break;
1397 default:
1398 case RTN_UNREACHABLE:
1399 case RTN_BLACKHOLE:
Changli Gaod8d1f302010-06-10 23:31:35 -07001400 rt->dst.input = dst_discard;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 }
1402 rt->rt_flags = flags;
Changli Gaod8d1f302010-06-10 23:31:35 -07001403 if (rt->dst.dev)
1404 dev_hold(rt->dst.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
1406 err = dn_rt_set_next_hop(rt, &res);
1407 if (err)
1408 goto e_neighbour;
1409
1410 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
Eric Dumazetadf30902009-06-02 05:19:30 +00001411 dn_insert_route(rt, hash, &rt);
Changli Gaod8d1f302010-06-10 23:31:35 -07001412 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
1414done:
1415 if (neigh)
1416 neigh_release(neigh);
1417 if (free_res)
1418 dn_fib_res_put(&res);
1419 dev_put(in_dev);
1420 if (out_dev)
1421 dev_put(out_dev);
1422out:
1423 return err;
1424
1425e_inval:
1426 err = -EINVAL;
1427 goto done;
1428
1429e_nobufs:
1430 err = -ENOBUFS;
1431 goto done;
1432
1433e_neighbour:
Changli Gaod8d1f302010-06-10 23:31:35 -07001434 dst_free(&rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 goto done;
1436}
1437
Roel Kluin5eaa65b2008-12-10 15:18:31 -08001438static int dn_route_input(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
1440 struct dn_route *rt;
1441 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1442 unsigned hash = dn_hash(cb->src, cb->dst);
1443
Eric Dumazetadf30902009-06-02 05:19:30 +00001444 if (skb_dst(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return 0;
1446
1447 rcu_read_lock();
1448 for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt != NULL;
Changli Gaod8d1f302010-06-10 23:31:35 -07001449 rt = rcu_dereference(rt->dst.dn_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 if ((rt->fl.fld_src == cb->src) &&
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001451 (rt->fl.fld_dst == cb->dst) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 (rt->fl.oif == 0) &&
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001453 (rt->fl.mark == skb->mark) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 (rt->fl.iif == cb->iif)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001455 dst_use(&rt->dst, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 rcu_read_unlock();
Eric Dumazetadf30902009-06-02 05:19:30 +00001457 skb_dst_set(skb, (struct dst_entry *)rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 return 0;
1459 }
1460 }
1461 rcu_read_unlock();
1462
1463 return dn_route_input_slow(skb);
1464}
1465
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001466static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1467 int event, int nowait, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Eric Dumazetadf30902009-06-02 05:19:30 +00001469 struct dn_route *rt = (struct dn_route *)skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 struct rtmsg *r;
1471 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001472 unsigned char *b = skb_tail_pointer(skb);
Thomas Grafe3703b32006-11-27 09:27:07 -08001473 long expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001475 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 r = NLMSG_DATA(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 r->rtm_family = AF_DECnet;
1478 r->rtm_dst_len = 16;
1479 r->rtm_src_len = 0;
1480 r->rtm_tos = 0;
1481 r->rtm_table = RT_TABLE_MAIN;
Patrick McHardy9e762a42006-08-10 23:09:48 -07001482 RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 r->rtm_type = rt->rt_type;
1484 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1485 r->rtm_scope = RT_SCOPE_UNIVERSE;
1486 r->rtm_protocol = RTPROT_UNSPEC;
1487 if (rt->rt_flags & RTCF_NOTIFY)
1488 r->rtm_flags |= RTM_F_NOTIFY;
1489 RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr);
1490 if (rt->fl.fld_src) {
1491 r->rtm_src_len = 16;
1492 RTA_PUT(skb, RTA_SRC, 2, &rt->fl.fld_src);
1493 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001494 if (rt->dst.dev)
1495 RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->dst.dev->ifindex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 /*
1497 * Note to self - change this if input routes reverse direction when
1498 * they deal only with inputs and not with replies like they do
1499 * currently.
1500 */
1501 RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src);
1502 if (rt->rt_daddr != rt->rt_gateway)
1503 RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway);
David S. Millerdefb3512010-12-08 21:16:57 -08001504 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 goto rtattr_failure;
Changli Gaod8d1f302010-06-10 23:31:35 -07001506 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
1507 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires,
1508 rt->dst.error) < 0)
Thomas Grafe3703b32006-11-27 09:27:07 -08001509 goto rtattr_failure;
David S. Millerc7537962010-11-11 17:07:48 -08001510 if (dn_is_input_route(rt))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fl.iif);
1512
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001513 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 return skb->len;
1515
1516nlmsg_failure:
1517rtattr_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001518 nlmsg_trim(skb, b);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001519 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
1522/*
1523 * This is called by both endnodes and routers now.
1524 */
Thomas Graffa34ddd2007-03-22 11:57:46 -07001525static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001527 struct net *net = sock_net(in_skb->sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 struct rtattr **rta = arg;
1529 struct rtmsg *rtm = NLMSG_DATA(nlh);
1530 struct dn_route *rt = NULL;
1531 struct dn_skb_cb *cb;
1532 int err;
1533 struct sk_buff *skb;
1534 struct flowi fl;
1535
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001536 if (!net_eq(net, &init_net))
Denis V. Lunevb8542722007-12-01 00:21:31 +11001537 return -EINVAL;
1538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 memset(&fl, 0, sizeof(fl));
1540 fl.proto = DNPROTO_NSP;
1541
1542 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1543 if (skb == NULL)
1544 return -ENOBUFS;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001545 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 cb = DN_SKB_CB(skb);
1547
1548 if (rta[RTA_SRC-1])
1549 memcpy(&fl.fld_src, RTA_DATA(rta[RTA_SRC-1]), 2);
1550 if (rta[RTA_DST-1])
1551 memcpy(&fl.fld_dst, RTA_DATA(rta[RTA_DST-1]), 2);
1552 if (rta[RTA_IIF-1])
1553 memcpy(&fl.iif, RTA_DATA(rta[RTA_IIF-1]), sizeof(int));
1554
1555 if (fl.iif) {
1556 struct net_device *dev;
Eric W. Biederman881d9662007-09-17 11:56:21 -07001557 if ((dev = dev_get_by_index(&init_net, fl.iif)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 kfree_skb(skb);
1559 return -ENODEV;
1560 }
1561 if (!dev->dn_ptr) {
1562 dev_put(dev);
1563 kfree_skb(skb);
1564 return -ENODEV;
1565 }
YOSHIFUJI Hideakib98999d2007-12-12 03:51:49 +09001566 skb->protocol = htons(ETH_P_DNA_RT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 skb->dev = dev;
1568 cb->src = fl.fld_src;
1569 cb->dst = fl.fld_dst;
1570 local_bh_disable();
1571 err = dn_route_input(skb);
1572 local_bh_enable();
1573 memset(cb, 0, sizeof(struct dn_skb_cb));
Eric Dumazetadf30902009-06-02 05:19:30 +00001574 rt = (struct dn_route *)skb_dst(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -07001575 if (!err && -rt->dst.error)
1576 err = rt->dst.error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 } else {
1578 int oif = 0;
1579 if (rta[RTA_OIF - 1])
1580 memcpy(&oif, RTA_DATA(rta[RTA_OIF - 1]), sizeof(int));
1581 fl.oif = oif;
1582 err = dn_route_output_key((struct dst_entry **)&rt, &fl, 0);
1583 }
1584
1585 if (skb->dev)
1586 dev_put(skb->dev);
1587 skb->dev = NULL;
1588 if (err)
1589 goto out_free;
Changli Gaod8d1f302010-06-10 23:31:35 -07001590 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 if (rtm->rtm_flags & RTM_F_NOTIFY)
1592 rt->rt_flags |= RTCF_NOTIFY;
1593
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001594 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 -07001595
1596 if (err == 0)
1597 goto out_free;
1598 if (err < 0) {
1599 err = -EMSGSIZE;
1600 goto out_free;
1601 }
1602
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08001603 return rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605out_free:
1606 kfree_skb(skb);
1607 return err;
1608}
1609
1610/*
1611 * For routers, this is called from dn_fib_dump, but for endnodes its
1612 * called directly from the rtnetlink dispatch table.
1613 */
1614int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1615{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001616 struct net *net = sock_net(skb->sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 struct dn_route *rt;
1618 int h, s_h;
1619 int idx, s_idx;
1620
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001621 if (!net_eq(net, &init_net))
Denis V. Lunevb8542722007-12-01 00:21:31 +11001622 return 0;
1623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
1625 return -EINVAL;
1626 if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
1627 return 0;
1628
1629 s_h = cb->args[0];
1630 s_idx = idx = cb->args[1];
1631 for(h = 0; h <= dn_rt_hash_mask; h++) {
1632 if (h < s_h)
1633 continue;
1634 if (h > s_h)
1635 s_idx = 0;
1636 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001637 for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 rt;
Changli Gaod8d1f302010-06-10 23:31:35 -07001639 rt = rcu_dereference_bh(rt->dst.dn_next), idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 if (idx < s_idx)
1641 continue;
Changli Gaod8d1f302010-06-10 23:31:35 -07001642 skb_dst_set(skb, dst_clone(&rt->dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001644 cb->nlh->nlmsg_seq, RTM_NEWROUTE,
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001645 1, NLM_F_MULTI) <= 0) {
Eric Dumazetadf30902009-06-02 05:19:30 +00001646 skb_dst_drop(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 rcu_read_unlock_bh();
1648 goto done;
1649 }
Eric Dumazetadf30902009-06-02 05:19:30 +00001650 skb_dst_drop(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 }
1652 rcu_read_unlock_bh();
1653 }
1654
1655done:
1656 cb->args[0] = h;
1657 cb->args[1] = idx;
1658 return skb->len;
1659}
1660
1661#ifdef CONFIG_PROC_FS
1662struct dn_rt_cache_iter_state {
1663 int bucket;
1664};
1665
1666static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
1667{
1668 struct dn_route *rt = NULL;
1669 struct dn_rt_cache_iter_state *s = seq->private;
1670
1671 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
1672 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001673 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 if (rt)
1675 break;
1676 rcu_read_unlock_bh();
1677 }
Paul E. McKenneya898def2010-02-22 17:04:49 -08001678 return rt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
1681static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
1682{
Eric Dumazet0d89d792008-01-10 22:35:21 -08001683 struct dn_rt_cache_iter_state *s = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001685 rt = rcu_dereference_bh(rt->dst.dn_next);
1686 while (!rt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 rcu_read_unlock_bh();
1688 if (--s->bucket < 0)
1689 break;
1690 rcu_read_lock_bh();
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001691 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 }
Eric Dumazetfc766e4c2010-10-29 03:09:24 +00001693 return rt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
1696static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
1697{
1698 struct dn_route *rt = dn_rt_cache_get_first(seq);
1699
1700 if (rt) {
1701 while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
1702 --*pos;
1703 }
1704 return *pos ? NULL : rt;
1705}
1706
1707static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1708{
1709 struct dn_route *rt = dn_rt_cache_get_next(seq, v);
1710 ++*pos;
1711 return rt;
1712}
1713
1714static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
1715{
1716 if (v)
1717 rcu_read_unlock_bh();
1718}
1719
1720static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
1721{
1722 struct dn_route *rt = v;
1723 char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
1724
1725 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
Changli Gaod8d1f302010-06-10 23:31:35 -07001726 rt->dst.dev ? rt->dst.dev->name : "*",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -08001727 dn_addr2asc(le16_to_cpu(rt->rt_daddr), buf1),
1728 dn_addr2asc(le16_to_cpu(rt->rt_saddr), buf2),
Changli Gaod8d1f302010-06-10 23:31:35 -07001729 atomic_read(&rt->dst.__refcnt),
1730 rt->dst.__use,
1731 (int) dst_metric(&rt->dst, RTAX_RTT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 return 0;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001733}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001735static const struct seq_operations dn_rt_cache_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 .start = dn_rt_cache_seq_start,
1737 .next = dn_rt_cache_seq_next,
1738 .stop = dn_rt_cache_seq_stop,
1739 .show = dn_rt_cache_seq_show,
1740};
1741
1742static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
1743{
Pavel Emelyanov31164082007-10-10 02:30:23 -07001744 return seq_open_private(file, &dn_rt_cache_seq_ops,
1745 sizeof(struct dn_rt_cache_iter_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746}
1747
Arjan van de Ven9a321442007-02-12 00:55:35 -08001748static const struct file_operations dn_rt_cache_seq_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 .owner = THIS_MODULE,
1750 .open = dn_rt_cache_seq_open,
1751 .read = seq_read,
1752 .llseek = seq_lseek,
1753 .release = seq_release_private,
1754};
1755
1756#endif /* CONFIG_PROC_FS */
1757
1758void __init dn_route_init(void)
1759{
1760 int i, goal, order;
1761
Alexey Dobriyane5d679f332006-08-26 19:25:52 -07001762 dn_dst_ops.kmem_cachep =
1763 kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001764 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
Eric Dumazetfc66f952010-10-08 06:37:34 +00001765 dst_entries_init(&dn_dst_ops);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001766 setup_timer(&dn_route_timer, dn_dst_check_expire, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1768 add_timer(&dn_route_timer);
1769
Jan Beulich44813742009-09-21 17:03:05 -07001770 goal = totalram_pages >> (26 - PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 for(order = 0; (1UL << order) < goal; order++)
1773 /* NOTHING */;
1774
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001775 /*
1776 * Only want 1024 entries max, since the table is very, very unlikely
1777 * to be larger than that.
1778 */
1779 while(order && ((((1UL << order) * PAGE_SIZE) /
1780 sizeof(struct dn_rt_hash_bucket)) >= 2048))
1781 order--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001783 do {
1784 dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
1785 sizeof(struct dn_rt_hash_bucket);
1786 while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
1787 dn_rt_hash_mask--;
1788 dn_rt_hash_table = (struct dn_rt_hash_bucket *)
1789 __get_free_pages(GFP_ATOMIC, order);
1790 } while (dn_rt_hash_table == NULL && --order > 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 if (!dn_rt_hash_table)
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001793 panic("Failed to allocate DECnet route cache hash table\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001795 printk(KERN_INFO
1796 "DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
1797 dn_rt_hash_mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 (long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
1799
1800 dn_rt_hash_mask--;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001801 for(i = 0; i <= dn_rt_hash_mask; i++) {
1802 spin_lock_init(&dn_rt_hash_table[i].lock);
1803 dn_rt_hash_table[i].chain = NULL;
1804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001806 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001808 proc_net_fops_create(&init_net, "decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
Thomas Graffa34ddd2007-03-22 11:57:46 -07001809
1810#ifdef CONFIG_DECNET_ROUTER
1811 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute, dn_fib_dump);
1812#else
1813 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute,
1814 dn_cache_dump);
1815#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816}
1817
1818void __exit dn_route_cleanup(void)
1819{
1820 del_timer(&dn_route_timer);
1821 dn_run_flush(0);
1822
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001823 proc_net_remove(&init_net, "decnet_cache");
Eric Dumazetfc66f952010-10-08 06:37:34 +00001824 dst_entries_destroy(&dn_dst_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825}
1826