blob: b8a5c0515be8ea0e732c8c428c6456bbc1da7e07 [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 Dumazetfc766e42010-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);
David S. Miller0dbaee32010-12-13 12:52:14 -0800113static unsigned int dn_dst_default_advmss(const struct dst_entry *dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
115static void dn_dst_link_failure(struct sk_buff *);
116static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
117static int dn_route_input(struct sk_buff *);
118static void dn_run_flush(unsigned long dummy);
119
120static struct dn_rt_hash_bucket *dn_rt_hash_table;
121static unsigned dn_rt_hash_mask;
122
123static struct timer_list dn_route_timer;
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700124static DEFINE_TIMER(dn_rt_flush_timer, dn_run_flush, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125int decnet_dst_gc_interval = 2;
126
127static struct dst_ops dn_dst_ops = {
128 .family = PF_DECnet,
Harvey Harrison09640e62009-02-01 00:45:17 -0800129 .protocol = cpu_to_be16(ETH_P_DNA_RT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .gc_thresh = 128,
131 .gc = dn_dst_gc,
132 .check = dn_dst_check,
David S. Miller0dbaee32010-12-13 12:52:14 -0800133 .default_advmss = dn_dst_default_advmss,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 .negative_advice = dn_dst_negative_advice,
135 .link_failure = dn_dst_link_failure,
136 .update_pmtu = dn_dst_update_pmtu,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137};
138
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800139static __inline__ unsigned dn_hash(__le16 src, __le16 dst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800141 __u16 tmp = (__u16 __force)(src ^ dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 tmp ^= (tmp >> 3);
143 tmp ^= (tmp >> 5);
144 tmp ^= (tmp >> 10);
145 return dn_rt_hash_mask & (unsigned)tmp;
146}
147
148static inline void dnrt_free(struct dn_route *rt)
149{
Changli Gaod8d1f302010-06-10 23:31:35 -0700150 call_rcu_bh(&rt->dst.rcu_head, dst_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
153static inline void dnrt_drop(struct dn_route *rt)
154{
Changli Gaod8d1f302010-06-10 23:31:35 -0700155 dst_release(&rt->dst);
156 call_rcu_bh(&rt->dst.rcu_head, dst_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159static void dn_dst_check_expire(unsigned long dummy)
160{
161 int i;
Eric Dumazetfc766e42010-10-29 03:09:24 +0000162 struct dn_route *rt;
163 struct dn_route __rcu **rtp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 unsigned long now = jiffies;
165 unsigned long expire = 120 * HZ;
166
Eric Dumazetfc766e42010-10-29 03:09:24 +0000167 for (i = 0; i <= dn_rt_hash_mask; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 rtp = &dn_rt_hash_table[i].chain;
169
170 spin_lock(&dn_rt_hash_table[i].lock);
Eric Dumazetfc766e42010-10-29 03:09:24 +0000171 while ((rt = rcu_dereference_protected(*rtp,
172 lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
Changli Gaod8d1f302010-06-10 23:31:35 -0700173 if (atomic_read(&rt->dst.__refcnt) ||
174 (now - rt->dst.lastuse) < expire) {
175 rtp = &rt->dst.dn_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 continue;
177 }
Changli Gaod8d1f302010-06-10 23:31:35 -0700178 *rtp = rt->dst.dn_next;
179 rt->dst.dn_next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 dnrt_free(rt);
181 }
182 spin_unlock(&dn_rt_hash_table[i].lock);
183
184 if ((jiffies - now) > 0)
185 break;
186 }
187
188 mod_timer(&dn_route_timer, now + decnet_dst_gc_interval * HZ);
189}
190
Daniel Lezcano569d3642008-01-18 03:56:57 -0800191static int dn_dst_gc(struct dst_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Eric Dumazetfc766e42010-10-29 03:09:24 +0000193 struct dn_route *rt;
194 struct dn_route __rcu **rtp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 int i;
196 unsigned long now = jiffies;
197 unsigned long expire = 10 * HZ;
198
Eric Dumazetfc766e42010-10-29 03:09:24 +0000199 for (i = 0; i <= dn_rt_hash_mask; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 spin_lock_bh(&dn_rt_hash_table[i].lock);
202 rtp = &dn_rt_hash_table[i].chain;
203
Eric Dumazetfc766e42010-10-29 03:09:24 +0000204 while ((rt = rcu_dereference_protected(*rtp,
205 lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
Changli Gaod8d1f302010-06-10 23:31:35 -0700206 if (atomic_read(&rt->dst.__refcnt) ||
207 (now - rt->dst.lastuse) < expire) {
208 rtp = &rt->dst.dn_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 continue;
210 }
Changli Gaod8d1f302010-06-10 23:31:35 -0700211 *rtp = rt->dst.dn_next;
212 rt->dst.dn_next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 dnrt_drop(rt);
214 break;
215 }
216 spin_unlock_bh(&dn_rt_hash_table[i].lock);
217 }
218
219 return 0;
220}
221
222/*
223 * The decnet standards don't impose a particular minimum mtu, what they
224 * do insist on is that the routing layer accepts a datagram of at least
225 * 230 bytes long. Here we have to subtract the routing header length from
226 * 230 to get the minimum acceptable mtu. If there is no neighbour, then we
227 * assume the worst and use a long header size.
228 *
229 * We update both the mtu and the advertised mss (i.e. the segment size we
230 * advertise to the other end).
231 */
232static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)
233{
234 u32 min_mtu = 230;
235 struct dn_dev *dn = dst->neighbour ?
Eric Dumazetfc766e42010-10-29 03:09:24 +0000236 rcu_dereference_raw(dst->neighbour->dev->dn_ptr) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 if (dn && dn->use_long == 0)
239 min_mtu -= 6;
240 else
241 min_mtu -= 21;
242
Satoru SATOH5ffc02a2008-05-04 22:14:42 -0700243 if (dst_metric(dst, RTAX_MTU) > mtu && mtu >= min_mtu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (!(dst_metric_locked(dst, RTAX_MTU))) {
David S. Millerdefb3512010-12-08 21:16:57 -0800245 dst_metric_set(dst, RTAX_MTU, mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 dst_set_expires(dst, dn_rt_mtu_expires);
247 }
248 if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
249 u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
David S. Miller0dbaee32010-12-13 12:52:14 -0800250 u32 existing_mss = dst_metric_raw(dst, RTAX_ADVMSS);
251 if (!existing_mss || existing_mss > mss)
David S. Millerdefb3512010-12-08 21:16:57 -0800252 dst_metric_set(dst, RTAX_ADVMSS, mss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254 }
255}
256
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900257/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 * When a route has been marked obsolete. (e.g. routing cache flush)
259 */
260static struct dst_entry *dn_dst_check(struct dst_entry *dst, __u32 cookie)
261{
262 return NULL;
263}
264
265static struct dst_entry *dn_dst_negative_advice(struct dst_entry *dst)
266{
267 dst_release(dst);
268 return NULL;
269}
270
271static void dn_dst_link_failure(struct sk_buff *skb)
272{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
275static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
276{
Changli Gao58116622010-11-12 18:43:55 +0000277 return ((fl1->fld_dst ^ fl2->fld_dst) |
278 (fl1->fld_src ^ fl2->fld_src) |
Thomas Graf47dcf0c2006-11-09 15:20:38 -0800279 (fl1->mark ^ fl2->mark) |
Changli Gao58116622010-11-12 18:43:55 +0000280 (fl1->fld_scope ^ fl2->fld_scope) |
David S. Miller8238b212006-10-12 00:49:15 -0700281 (fl1->oif ^ fl2->oif) |
282 (fl1->iif ^ fl2->iif)) == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
285static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp)
286{
Eric Dumazetfc766e42010-10-29 03:09:24 +0000287 struct dn_route *rth;
288 struct dn_route __rcu **rthp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 unsigned long now = jiffies;
290
291 rthp = &dn_rt_hash_table[hash].chain;
292
293 spin_lock_bh(&dn_rt_hash_table[hash].lock);
Eric Dumazetfc766e42010-10-29 03:09:24 +0000294 while ((rth = rcu_dereference_protected(*rthp,
295 lockdep_is_held(&dn_rt_hash_table[hash].lock))) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (compare_keys(&rth->fl, &rt->fl)) {
297 /* Put it first */
Changli Gaod8d1f302010-06-10 23:31:35 -0700298 *rthp = rth->dst.dn_next;
299 rcu_assign_pointer(rth->dst.dn_next,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 dn_rt_hash_table[hash].chain);
301 rcu_assign_pointer(dn_rt_hash_table[hash].chain, rth);
302
Changli Gaod8d1f302010-06-10 23:31:35 -0700303 dst_use(&rth->dst, now);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
305
306 dnrt_drop(rt);
307 *rp = rth;
308 return 0;
309 }
Changli Gaod8d1f302010-06-10 23:31:35 -0700310 rthp = &rth->dst.dn_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 }
312
Changli Gaod8d1f302010-06-10 23:31:35 -0700313 rcu_assign_pointer(rt->dst.dn_next, dn_rt_hash_table[hash].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 rcu_assign_pointer(dn_rt_hash_table[hash].chain, rt);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900315
Changli Gaod8d1f302010-06-10 23:31:35 -0700316 dst_use(&rt->dst, now);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 spin_unlock_bh(&dn_rt_hash_table[hash].lock);
318 *rp = rt;
319 return 0;
320}
321
Roel Kluin5eaa65b2008-12-10 15:18:31 -0800322static void dn_run_flush(unsigned long dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
324 int i;
325 struct dn_route *rt, *next;
326
Eric Dumazetfc766e42010-10-29 03:09:24 +0000327 for (i = 0; i < dn_rt_hash_mask; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 spin_lock_bh(&dn_rt_hash_table[i].lock);
329
Eric Dumazetfc766e42010-10-29 03:09:24 +0000330 if ((rt = xchg((struct dn_route **)&dn_rt_hash_table[i].chain, NULL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 goto nothing_to_declare;
332
Eric Dumazetfc766e42010-10-29 03:09:24 +0000333 for(; rt; rt = next) {
334 next = rcu_dereference_raw(rt->dst.dn_next);
335 RCU_INIT_POINTER(rt->dst.dn_next, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 dst_free((struct dst_entry *)rt);
337 }
338
339nothing_to_declare:
340 spin_unlock_bh(&dn_rt_hash_table[i].lock);
341 }
342}
343
344static DEFINE_SPINLOCK(dn_rt_flush_lock);
345
346void dn_rt_cache_flush(int delay)
347{
348 unsigned long now = jiffies;
349 int user_mode = !in_interrupt();
350
351 if (delay < 0)
352 delay = dn_rt_min_delay;
353
354 spin_lock_bh(&dn_rt_flush_lock);
355
356 if (del_timer(&dn_rt_flush_timer) && delay > 0 && dn_rt_deadline) {
357 long tmo = (long)(dn_rt_deadline - now);
358
359 if (user_mode && tmo < dn_rt_max_delay - dn_rt_min_delay)
360 tmo = 0;
361
362 if (delay > tmo)
363 delay = tmo;
364 }
365
366 if (delay <= 0) {
367 spin_unlock_bh(&dn_rt_flush_lock);
368 dn_run_flush(0);
369 return;
370 }
371
372 if (dn_rt_deadline == 0)
373 dn_rt_deadline = now + dn_rt_max_delay;
374
375 dn_rt_flush_timer.expires = now + delay;
376 add_timer(&dn_rt_flush_timer);
377 spin_unlock_bh(&dn_rt_flush_lock);
378}
379
380/**
381 * dn_return_short - Return a short packet to its sender
382 * @skb: The packet to return
383 *
384 */
385static int dn_return_short(struct sk_buff *skb)
386{
387 struct dn_skb_cb *cb;
388 unsigned char *ptr;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800389 __le16 *src;
390 __le16 *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Add back headers */
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700393 skb_push(skb, skb->data - skb_network_header(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
396 return NET_RX_DROP;
397
398 cb = DN_SKB_CB(skb);
399 /* Skip packet length and point to flags */
400 ptr = skb->data + 2;
401 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
402
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800403 dst = (__le16 *)ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800405 src = (__le16 *)ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 ptr += 2;
407 *ptr = 0; /* Zero hop count */
408
Ilpo Järvinena0bffff2009-03-21 13:36:17 -0700409 swap(*src, *dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 skb->pkt_type = PACKET_OUTGOING;
412 dn_rt_finish_output(skb, NULL, NULL);
413 return NET_RX_SUCCESS;
414}
415
416/**
417 * dn_return_long - Return a long packet to its sender
418 * @skb: The long format packet to return
419 *
420 */
421static int dn_return_long(struct sk_buff *skb)
422{
423 struct dn_skb_cb *cb;
424 unsigned char *ptr;
425 unsigned char *src_addr, *dst_addr;
426 unsigned char tmp[ETH_ALEN];
427
428 /* Add back all headers */
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700429 skb_push(skb, skb->data - skb_network_header(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
432 return NET_RX_DROP;
433
434 cb = DN_SKB_CB(skb);
435 /* Ignore packet length and point to flags */
436 ptr = skb->data + 2;
437
438 /* Skip padding */
439 if (*ptr & DN_RT_F_PF) {
440 char padlen = (*ptr & ~DN_RT_F_PF);
441 ptr += padlen;
442 }
443
444 *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
445 ptr += 2;
446 dst_addr = ptr;
447 ptr += 8;
448 src_addr = ptr;
449 ptr += 6;
450 *ptr = 0; /* Zero hop count */
451
452 /* Swap source and destination */
453 memcpy(tmp, src_addr, ETH_ALEN);
454 memcpy(src_addr, dst_addr, ETH_ALEN);
455 memcpy(dst_addr, tmp, ETH_ALEN);
456
457 skb->pkt_type = PACKET_OUTGOING;
458 dn_rt_finish_output(skb, dst_addr, src_addr);
459 return NET_RX_SUCCESS;
460}
461
462/**
463 * dn_route_rx_packet - Try and find a route for an incoming packet
464 * @skb: The packet to find a route for
465 *
466 * Returns: result of input function if route is found, error code otherwise
467 */
468static int dn_route_rx_packet(struct sk_buff *skb)
469{
Eric Dumazetfc766e42010-10-29 03:09:24 +0000470 struct dn_skb_cb *cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 int err;
472
473 if ((err = dn_route_input(skb)) == 0)
474 return dst_input(skb);
475
Eric Dumazetfc766e42010-10-29 03:09:24 +0000476 cb = DN_SKB_CB(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (decnet_debug_level & 4) {
478 char *devname = skb->dev ? skb->dev->name : "???";
Eric Dumazetfc766e42010-10-29 03:09:24 +0000479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 printk(KERN_DEBUG
481 "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 -0800482 (int)cb->rt_flags, devname, skb->len,
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800483 le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 err, skb->pkt_type);
485 }
486
487 if ((skb->pkt_type == PACKET_HOST) && (cb->rt_flags & DN_RT_F_RQR)) {
488 switch(cb->rt_flags & DN_RT_PKT_MSK) {
489 case DN_RT_PKT_SHORT:
490 return dn_return_short(skb);
491 case DN_RT_PKT_LONG:
492 return dn_return_long(skb);
493 }
494 }
495
496 kfree_skb(skb);
497 return NET_RX_DROP;
498}
499
500static int dn_route_rx_long(struct sk_buff *skb)
501{
502 struct dn_skb_cb *cb = DN_SKB_CB(skb);
503 unsigned char *ptr = skb->data;
504
505 if (!pskb_may_pull(skb, 21)) /* 20 for long header, 1 for shortest nsp */
506 goto drop_it;
507
508 skb_pull(skb, 20);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300509 skb_reset_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900511 /* Destination info */
512 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800513 cb->dst = dn_eth2dn(ptr);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900514 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
515 goto drop_it;
516 ptr += 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900519 /* Source info */
520 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800521 cb->src = dn_eth2dn(ptr);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900522 if (memcmp(ptr, dn_hiord_addr, 4) != 0)
523 goto drop_it;
524 ptr += 6;
525 /* Other junk */
526 ptr++;
527 cb->hops = *ptr++; /* Visit Count */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100529 return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING, skb, skb->dev, NULL,
530 dn_route_rx_packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532drop_it:
533 kfree_skb(skb);
534 return NET_RX_DROP;
535}
536
537
538
539static int dn_route_rx_short(struct sk_buff *skb)
540{
541 struct dn_skb_cb *cb = DN_SKB_CB(skb);
542 unsigned char *ptr = skb->data;
543
544 if (!pskb_may_pull(skb, 6)) /* 5 for short header + 1 for shortest nsp */
545 goto drop_it;
546
547 skb_pull(skb, 5);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300548 skb_reset_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800550 cb->dst = *(__le16 *)ptr;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900551 ptr += 2;
552 cb->src = *(__le16 *)ptr;
553 ptr += 2;
554 cb->hops = *ptr & 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100556 return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING, skb, skb->dev, NULL,
557 dn_route_rx_packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559drop_it:
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900560 kfree_skb(skb);
561 return NET_RX_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
564static int dn_route_discard(struct sk_buff *skb)
565{
566 /*
567 * I know we drop the packet here, but thats considered success in
568 * this case
569 */
570 kfree_skb(skb);
571 return NET_RX_SUCCESS;
572}
573
574static int dn_route_ptp_hello(struct sk_buff *skb)
575{
576 dn_dev_hello(skb);
577 dn_neigh_pointopoint_hello(skb);
578 return NET_RX_SUCCESS;
579}
580
David S. Millerf2ccd8f2005-08-09 19:34:12 -0700581int 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 -0700582{
583 struct dn_skb_cb *cb;
584 unsigned char flags = 0;
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800585 __u16 len = le16_to_cpu(*(__le16 *)skb->data);
Eric Dumazetfc766e42010-10-29 03:09:24 +0000586 struct dn_dev *dn = rcu_dereference(dev->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 unsigned char padlen = 0;
588
YOSHIFUJI Hideaki721499e2008-07-19 22:34:43 -0700589 if (!net_eq(dev_net(dev), &init_net))
Eric W. Biedermane730c152007-09-17 11:53:39 -0700590 goto dump_it;
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (dn == NULL)
593 goto dump_it;
594
595 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
596 goto out;
597
598 if (!pskb_may_pull(skb, 3))
599 goto dump_it;
600
601 skb_pull(skb, 2);
602
603 if (len > skb->len)
604 goto dump_it;
605
606 skb_trim(skb, len);
607
608 flags = *skb->data;
609
610 cb = DN_SKB_CB(skb);
611 cb->stamp = jiffies;
612 cb->iif = dev->ifindex;
613
614 /*
615 * If we have padding, remove it.
616 */
617 if (flags & DN_RT_F_PF) {
618 padlen = flags & ~DN_RT_F_PF;
619 if (!pskb_may_pull(skb, padlen + 1))
620 goto dump_it;
621 skb_pull(skb, padlen);
622 flags = *skb->data;
623 }
624
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700625 skb_reset_network_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 /*
628 * Weed out future version DECnet
629 */
630 if (flags & DN_RT_F_VER)
631 goto dump_it;
632
633 cb->rt_flags = flags;
634
635 if (decnet_debug_level & 1)
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900636 printk(KERN_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 "dn_route_rcv: got 0x%02x from %s [%d %d %d]\n",
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900638 (int)flags, (dev) ? dev->name : "???", len, skb->len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 padlen);
640
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900641 if (flags & DN_RT_PKT_CNTL) {
Herbert Xu364c6ba2006-06-09 16:10:40 -0700642 if (unlikely(skb_linearize(skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 goto dump_it;
644
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900645 switch(flags & DN_RT_CNTL_MSK) {
646 case DN_RT_PKT_INIT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 dn_dev_init_pkt(skb);
648 break;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900649 case DN_RT_PKT_VERI:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 dn_dev_veri_pkt(skb);
651 break;
652 }
653
654 if (dn->parms.state != DN_DEV_S_RU)
655 goto dump_it;
656
657 switch(flags & DN_RT_CNTL_MSK) {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900658 case DN_RT_PKT_HELO:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100659 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
660 skb, skb->dev, NULL,
661 dn_route_ptp_hello);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900663 case DN_RT_PKT_L1RT:
664 case DN_RT_PKT_L2RT:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100665 return NF_HOOK(NFPROTO_DECNET, NF_DN_ROUTE,
666 skb, skb->dev, NULL,
667 dn_route_discard);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900668 case DN_RT_PKT_ERTH:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100669 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
670 skb, skb->dev, NULL,
671 dn_neigh_router_hello);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900673 case DN_RT_PKT_EEDH:
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100674 return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
675 skb, skb->dev, NULL,
676 dn_neigh_endnode_hello);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900677 }
678 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (dn->parms.state != DN_DEV_S_RU)
680 goto dump_it;
681
682 skb_pull(skb, 1); /* Pull flags */
683
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900684 switch(flags & DN_RT_PKT_MSK) {
685 case DN_RT_PKT_LONG:
686 return dn_route_rx_long(skb);
687 case DN_RT_PKT_SHORT:
688 return dn_route_rx_short(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692dump_it:
693 kfree_skb(skb);
694out:
695 return NET_RX_DROP;
696}
697
698static int dn_output(struct sk_buff *skb)
699{
Eric Dumazetadf30902009-06-02 05:19:30 +0000700 struct dst_entry *dst = skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 struct dn_route *rt = (struct dn_route *)dst;
702 struct net_device *dev = dst->dev;
703 struct dn_skb_cb *cb = DN_SKB_CB(skb);
704 struct neighbour *neigh;
705
706 int err = -EINVAL;
707
708 if ((neigh = dst->neighbour) == NULL)
709 goto error;
710
711 skb->dev = dev;
712
713 cb->src = rt->rt_saddr;
714 cb->dst = rt->rt_daddr;
715
716 /*
717 * Always set the Intra-Ethernet bit on all outgoing packets
718 * originated on this node. Only valid flag from upper layers
719 * is return-to-sender-requested. Set hop count to 0 too.
720 */
721 cb->rt_flags &= ~DN_RT_F_RQR;
722 cb->rt_flags |= DN_RT_F_IE;
723 cb->hops = 0;
724
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100725 return NF_HOOK(NFPROTO_DECNET, NF_DN_LOCAL_OUT, skb, NULL, dev,
726 neigh->output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728error:
729 if (net_ratelimit())
730 printk(KERN_DEBUG "dn_output: This should not happen\n");
731
732 kfree_skb(skb);
733
734 return err;
735}
736
737static int dn_forward(struct sk_buff *skb)
738{
739 struct dn_skb_cb *cb = DN_SKB_CB(skb);
Eric Dumazetadf30902009-06-02 05:19:30 +0000740 struct dst_entry *dst = skb_dst(skb);
Eric Dumazetfc766e42010-10-29 03:09:24 +0000741 struct dn_dev *dn_db = rcu_dereference(dst->dev->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 struct dn_route *rt;
743 struct neighbour *neigh = dst->neighbour;
744 int header_len;
745#ifdef CONFIG_NETFILTER
746 struct net_device *dev = skb->dev;
747#endif
748
749 if (skb->pkt_type != PACKET_HOST)
750 goto drop;
751
752 /* Ensure that we have enough space for headers */
Eric Dumazetadf30902009-06-02 05:19:30 +0000753 rt = (struct dn_route *)skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 header_len = dn_db->use_long ? 21 : 6;
Changli Gaod8d1f302010-06-10 23:31:35 -0700755 if (skb_cow(skb, LL_RESERVED_SPACE(rt->dst.dev)+header_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 goto drop;
757
758 /*
759 * Hop count exceeded.
760 */
761 if (++cb->hops > 30)
762 goto drop;
763
Changli Gaod8d1f302010-06-10 23:31:35 -0700764 skb->dev = rt->dst.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 /*
767 * If packet goes out same interface it came in on, then set
768 * the Intra-Ethernet bit. This has no effect for short
769 * packets, so we don't need to test for them here.
770 */
771 cb->rt_flags &= ~DN_RT_F_IE;
772 if (rt->rt_flags & RTCF_DOREDIRECT)
773 cb->rt_flags |= DN_RT_F_IE;
774
Jan Engelhardt5d877d82010-03-23 04:09:14 +0100775 return NF_HOOK(NFPROTO_DECNET, NF_DN_FORWARD, skb, dev, skb->dev,
776 neigh->output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778drop:
779 kfree_skb(skb);
780 return NET_RX_DROP;
781}
782
783/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 * Used to catch bugs. This should never normally get
785 * called.
786 */
787static int dn_rt_bug(struct sk_buff *skb)
788{
789 if (net_ratelimit()) {
790 struct dn_skb_cb *cb = DN_SKB_CB(skb);
791
792 printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800793 le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795
796 kfree_skb(skb);
797
Florian Westphal0e8635a2009-06-20 00:53:25 +0000798 return NET_RX_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
David S. Miller0dbaee32010-12-13 12:52:14 -0800801static unsigned int dn_dst_default_advmss(const struct dst_entry *dst)
802{
803 return dn_mss_from_pmtu(dst->dev, dst_mtu(dst));
804}
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
807{
808 struct dn_fib_info *fi = res->fi;
Changli Gaod8d1f302010-06-10 23:31:35 -0700809 struct net_device *dev = rt->dst.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 struct neighbour *n;
David S. Miller0dbaee32010-12-13 12:52:14 -0800811 unsigned int metric;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 if (fi) {
814 if (DN_FIB_RES_GW(*res) &&
815 DN_FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
816 rt->rt_gateway = DN_FIB_RES_GW(*res);
David S. Millerdefb3512010-12-08 21:16:57 -0800817 dst_import_metrics(&rt->dst, fi->fib_metrics);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
819 rt->rt_type = res->type;
820
Changli Gaod8d1f302010-06-10 23:31:35 -0700821 if (dev != NULL && rt->dst.neighbour == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
823 if (IS_ERR(n))
824 return PTR_ERR(n);
Changli Gaod8d1f302010-06-10 23:31:35 -0700825 rt->dst.neighbour = n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827
Changli Gaod8d1f302010-06-10 23:31:35 -0700828 if (dst_metric(&rt->dst, RTAX_MTU) == 0 ||
829 dst_metric(&rt->dst, RTAX_MTU) > rt->dst.dev->mtu)
David S. Millerdefb3512010-12-08 21:16:57 -0800830 dst_metric_set(&rt->dst, RTAX_MTU, rt->dst.dev->mtu);
David S. Miller0dbaee32010-12-13 12:52:14 -0800831 metric = dst_metric_raw(&rt->dst, RTAX_ADVMSS);
832 if (metric) {
833 unsigned int mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
834 if (metric > mss)
835 dst_metric_set(&rt->dst, RTAX_ADVMSS, mss);
836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 return 0;
838}
839
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800840static inline int dn_match_addr(__le16 addr1, __le16 addr2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800842 __u16 tmp = le16_to_cpu(addr1) ^ le16_to_cpu(addr2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 int match = 16;
844 while(tmp) {
845 tmp >>= 1;
846 match--;
847 }
848 return match;
849}
850
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800851static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800853 __le16 saddr = 0;
Eric Dumazetfc766e42010-10-29 03:09:24 +0000854 struct dn_dev *dn_db;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 struct dn_ifaddr *ifa;
856 int best_match = 0;
857 int ret;
858
Eric Dumazetfc766e42010-10-29 03:09:24 +0000859 rcu_read_lock();
860 dn_db = rcu_dereference(dev->dn_ptr);
861 for (ifa = rcu_dereference(dn_db->ifa_list);
862 ifa != NULL;
863 ifa = rcu_dereference(ifa->ifa_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (ifa->ifa_scope > scope)
865 continue;
866 if (!daddr) {
867 saddr = ifa->ifa_local;
868 break;
869 }
870 ret = dn_match_addr(daddr, ifa->ifa_local);
871 if (ret > best_match)
872 saddr = ifa->ifa_local;
873 if (best_match == 0)
874 saddr = ifa->ifa_local;
875 }
Eric Dumazetfc766e42010-10-29 03:09:24 +0000876 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 return saddr;
879}
880
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800881static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
884}
885
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800886static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800888 __le16 mask = dnet_make_mask(res->prefixlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 return (daddr&~mask)|res->fi->fib_nh->nh_gw;
890}
891
892static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *oldflp, int try_hard)
893{
Changli Gao58116622010-11-12 18:43:55 +0000894 struct flowi fl = { .fld_dst = oldflp->fld_dst,
895 .fld_src = oldflp->fld_src,
896 .fld_scope = RT_SCOPE_UNIVERSE,
Thomas Graf47dcf0c2006-11-09 15:20:38 -0800897 .mark = oldflp->mark,
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700898 .iif = init_net.loopback_dev->ifindex,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 .oif = oldflp->oif };
900 struct dn_route *rt = NULL;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700901 struct net_device *dev_out = NULL, *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 struct neighbour *neigh = NULL;
903 unsigned hash;
904 unsigned flags = 0;
905 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
906 int err;
907 int free_res = 0;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800908 __le16 gateway = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 if (decnet_debug_level & 16)
911 printk(KERN_DEBUG
912 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800913 " iif=%d oif=%d\n", le16_to_cpu(oldflp->fld_dst),
914 le16_to_cpu(oldflp->fld_src),
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700915 oldflp->mark, init_net.loopback_dev->ifindex, oldflp->oif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 /* If we have an output interface, verify its a DECnet device */
918 if (oldflp->oif) {
Eric W. Biederman881d9662007-09-17 11:56:21 -0700919 dev_out = dev_get_by_index(&init_net, oldflp->oif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 err = -ENODEV;
921 if (dev_out && dev_out->dn_ptr == NULL) {
922 dev_put(dev_out);
923 dev_out = NULL;
924 }
925 if (dev_out == NULL)
926 goto out;
927 }
928
929 /* If we have a source address, verify that its a local address */
930 if (oldflp->fld_src) {
931 err = -EADDRNOTAVAIL;
932
933 if (dev_out) {
934 if (dn_dev_islocal(dev_out, oldflp->fld_src))
935 goto source_ok;
936 dev_put(dev_out);
937 goto out;
938 }
Eric Dumazetc6d14c82009-11-04 05:43:23 -0800939 rcu_read_lock();
940 for_each_netdev_rcu(&init_net, dev) {
Pavel Emelianov7562f872007-05-03 15:13:45 -0700941 if (!dev->dn_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700943 if (!dn_dev_islocal(dev, oldflp->fld_src))
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700944 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700945 if ((dev->flags & IFF_LOOPBACK) &&
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700946 oldflp->fld_dst &&
Pavel Emelianov7562f872007-05-03 15:13:45 -0700947 !dn_dev_islocal(dev, oldflp->fld_dst))
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700948 continue;
Pavel Emelianov7562f872007-05-03 15:13:45 -0700949
950 dev_out = dev;
Patrick Caulfield9bbf28a12006-08-02 14:14:44 -0700951 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 }
Eric Dumazetc6d14c82009-11-04 05:43:23 -0800953 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (dev_out == NULL)
955 goto out;
956 dev_hold(dev_out);
957source_ok:
958 ;
959 }
960
961 /* No destination? Assume its local */
962 if (!fl.fld_dst) {
963 fl.fld_dst = fl.fld_src;
964
965 err = -EADDRNOTAVAIL;
966 if (dev_out)
967 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700968 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 dev_hold(dev_out);
970 if (!fl.fld_dst) {
971 fl.fld_dst =
972 fl.fld_src = dnet_select_source(dev_out, 0,
973 RT_SCOPE_HOST);
974 if (!fl.fld_dst)
975 goto out;
976 }
Eric W. Biederman2774c7a2007-09-26 22:10:56 -0700977 fl.oif = init_net.loopback_dev->ifindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 res.type = RTN_LOCAL;
979 goto make_route;
980 }
981
982 if (decnet_debug_level & 16)
983 printk(KERN_DEBUG
984 "dn_route_output_slow: initial checks complete."
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800985 " dst=%o4x src=%04x oif=%d try_hard=%d\n",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800986 le16_to_cpu(fl.fld_dst), le16_to_cpu(fl.fld_src),
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800987 fl.oif, try_hard);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 /*
990 * N.B. If the kernel is compiled without router support then
991 * dn_fib_lookup() will evaluate to non-zero so this if () block
992 * will always be executed.
993 */
994 err = -ESRCH;
995 if (try_hard || (err = dn_fib_lookup(&fl, &res)) != 0) {
996 struct dn_dev *dn_db;
997 if (err != -ESRCH)
998 goto out;
999 /*
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001000 * Here the fallback is basically the standard algorithm for
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 * routing in endnodes which is described in the DECnet routing
1002 * docs
1003 *
1004 * If we are not trying hard, look in neighbour cache.
1005 * The result is tested to ensure that if a specific output
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001006 * device/source address was requested, then we honour that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 * here
1008 */
1009 if (!try_hard) {
Eric W. Biederman426b5302008-01-24 00:13:18 -08001010 neigh = neigh_lookup_nodev(&dn_neigh_table, &init_net, &fl.fld_dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (neigh) {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001012 if ((oldflp->oif &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 (neigh->dev->ifindex != oldflp->oif)) ||
1014 (oldflp->fld_src &&
1015 (!dn_dev_islocal(neigh->dev,
1016 oldflp->fld_src)))) {
1017 neigh_release(neigh);
1018 neigh = NULL;
1019 } else {
1020 if (dev_out)
1021 dev_put(dev_out);
1022 if (dn_dev_islocal(neigh->dev, fl.fld_dst)) {
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001023 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 res.type = RTN_LOCAL;
1025 } else {
1026 dev_out = neigh->dev;
1027 }
1028 dev_hold(dev_out);
1029 goto select_source;
1030 }
1031 }
1032 }
1033
1034 /* Not there? Perhaps its a local address */
1035 if (dev_out == NULL)
1036 dev_out = dn_dev_get_default();
1037 err = -ENODEV;
1038 if (dev_out == NULL)
1039 goto out;
Eric Dumazetfc766e42010-10-29 03:09:24 +00001040 dn_db = rcu_dereference_raw(dev_out->dn_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 /* Possible improvement - check all devices for local addr */
1042 if (dn_dev_islocal(dev_out, fl.fld_dst)) {
1043 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001044 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 dev_hold(dev_out);
1046 res.type = RTN_LOCAL;
1047 goto select_source;
1048 }
1049 /* Not local either.... try sending it to the default router */
1050 neigh = neigh_clone(dn_db->router);
1051 BUG_ON(neigh && neigh->dev != dev_out);
1052
1053 /* Ok then, we assume its directly connected and move on */
1054select_source:
1055 if (neigh)
1056 gateway = ((struct dn_neigh *)neigh)->addr;
1057 if (gateway == 0)
1058 gateway = fl.fld_dst;
1059 if (fl.fld_src == 0) {
1060 fl.fld_src = dnet_select_source(dev_out, gateway,
1061 res.type == RTN_LOCAL ?
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001062 RT_SCOPE_HOST :
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 RT_SCOPE_LINK);
1064 if (fl.fld_src == 0 && res.type != RTN_LOCAL)
1065 goto e_addr;
1066 }
1067 fl.oif = dev_out->ifindex;
1068 goto make_route;
1069 }
1070 free_res = 1;
1071
1072 if (res.type == RTN_NAT)
1073 goto e_inval;
1074
1075 if (res.type == RTN_LOCAL) {
1076 if (!fl.fld_src)
1077 fl.fld_src = fl.fld_dst;
1078 if (dev_out)
1079 dev_put(dev_out);
Eric W. Biederman2774c7a2007-09-26 22:10:56 -07001080 dev_out = init_net.loopback_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 dev_hold(dev_out);
1082 fl.oif = dev_out->ifindex;
1083 if (res.fi)
1084 dn_fib_info_put(res.fi);
1085 res.fi = NULL;
1086 goto make_route;
1087 }
1088
1089 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1090 dn_fib_select_multipath(&fl, &res);
1091
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001092 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 * We could add some logic to deal with default routes here and
1094 * get rid of some of the special casing above.
1095 */
1096
1097 if (!fl.fld_src)
1098 fl.fld_src = DN_FIB_RES_PREFSRC(res);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (dev_out)
1101 dev_put(dev_out);
1102 dev_out = DN_FIB_RES_DEV(res);
1103 dev_hold(dev_out);
1104 fl.oif = dev_out->ifindex;
1105 gateway = DN_FIB_RES_GW(res);
1106
1107make_route:
1108 if (dev_out->flags & IFF_LOOPBACK)
1109 flags |= RTCF_LOCAL;
1110
1111 rt = dst_alloc(&dn_dst_ops);
1112 if (rt == NULL)
1113 goto e_nobufs;
1114
Changli Gaod8d1f302010-06-10 23:31:35 -07001115 atomic_set(&rt->dst.__refcnt, 1);
1116 rt->dst.flags = DST_HOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 rt->fl.fld_src = oldflp->fld_src;
1119 rt->fl.fld_dst = oldflp->fld_dst;
1120 rt->fl.oif = oldflp->oif;
1121 rt->fl.iif = 0;
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001122 rt->fl.mark = oldflp->mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 rt->rt_saddr = fl.fld_src;
1125 rt->rt_daddr = fl.fld_dst;
1126 rt->rt_gateway = gateway ? gateway : fl.fld_dst;
1127 rt->rt_local_src = fl.fld_src;
1128
1129 rt->rt_dst_map = fl.fld_dst;
1130 rt->rt_src_map = fl.fld_src;
1131
Changli Gaod8d1f302010-06-10 23:31:35 -07001132 rt->dst.dev = dev_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 dev_hold(dev_out);
Changli Gaod8d1f302010-06-10 23:31:35 -07001134 rt->dst.neighbour = neigh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 neigh = NULL;
1136
Changli Gaod8d1f302010-06-10 23:31:35 -07001137 rt->dst.lastuse = jiffies;
1138 rt->dst.output = dn_output;
1139 rt->dst.input = dn_rt_bug;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 rt->rt_flags = flags;
1141 if (flags & RTCF_LOCAL)
Changli Gaod8d1f302010-06-10 23:31:35 -07001142 rt->dst.input = dn_nsp_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 err = dn_rt_set_next_hop(rt, &res);
1145 if (err)
1146 goto e_neighbour;
1147
1148 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
1149 dn_insert_route(rt, hash, (struct dn_route **)pprt);
1150
1151done:
1152 if (neigh)
1153 neigh_release(neigh);
1154 if (free_res)
1155 dn_fib_res_put(&res);
1156 if (dev_out)
1157 dev_put(dev_out);
1158out:
1159 return err;
1160
1161e_addr:
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001162 err = -EADDRNOTAVAIL;
1163 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164e_inval:
1165 err = -EINVAL;
1166 goto done;
1167e_nobufs:
1168 err = -ENOBUFS;
1169 goto done;
1170e_neighbour:
Changli Gaod8d1f302010-06-10 23:31:35 -07001171 dst_free(&rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 goto e_nobufs;
1173}
1174
1175
1176/*
1177 * N.B. The flags may be moved into the flowi at some future stage.
1178 */
1179static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *flp, int flags)
1180{
1181 unsigned hash = dn_hash(flp->fld_src, flp->fld_dst);
1182 struct dn_route *rt = NULL;
1183
1184 if (!(flags & MSG_TRYHARD)) {
1185 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001186 for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
Changli Gaod8d1f302010-06-10 23:31:35 -07001187 rt = rcu_dereference_bh(rt->dst.dn_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if ((flp->fld_dst == rt->fl.fld_dst) &&
1189 (flp->fld_src == rt->fl.fld_src) &&
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001190 (flp->mark == rt->fl.mark) &&
David S. Millerc7537962010-11-11 17:07:48 -08001191 dn_is_output_route(rt) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 (rt->fl.oif == flp->oif)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001193 dst_use(&rt->dst, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 rcu_read_unlock_bh();
Changli Gaod8d1f302010-06-10 23:31:35 -07001195 *pprt = &rt->dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 return 0;
1197 }
1198 }
1199 rcu_read_unlock_bh();
1200 }
1201
1202 return dn_route_output_slow(pprt, flp, flags);
1203}
1204
1205static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int flags)
1206{
1207 int err;
1208
1209 err = __dn_route_output_key(pprt, flp, flags);
1210 if (err == 0 && flp->proto) {
Alexey Dobriyan52479b62008-11-25 17:35:18 -08001211 err = xfrm_lookup(&init_net, pprt, flp, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213 return err;
1214}
1215
1216int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock *sk, int flags)
1217{
1218 int err;
1219
1220 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1221 if (err == 0 && fl->proto) {
Alexey Dobriyan52479b62008-11-25 17:35:18 -08001222 err = xfrm_lookup(&init_net, pprt, fl, sk,
1223 (flags & MSG_DONTWAIT) ? 0 : XFRM_LOOKUP_WAIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 }
1225 return err;
1226}
1227
1228static int dn_route_input_slow(struct sk_buff *skb)
1229{
1230 struct dn_route *rt = NULL;
1231 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1232 struct net_device *in_dev = skb->dev;
1233 struct net_device *out_dev = NULL;
1234 struct dn_dev *dn_db;
1235 struct neighbour *neigh = NULL;
1236 unsigned hash;
1237 int flags = 0;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -08001238 __le16 gateway = 0;
1239 __le16 local_src = 0;
Changli Gao58116622010-11-12 18:43:55 +00001240 struct flowi fl = { .fld_dst = cb->dst,
1241 .fld_src = cb->src,
1242 .fld_scope = RT_SCOPE_UNIVERSE,
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001243 .mark = skb->mark,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 .iif = skb->dev->ifindex };
1245 struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
1246 int err = -EINVAL;
1247 int free_res = 0;
1248
1249 dev_hold(in_dev);
1250
Eric Dumazetfc766e42010-10-29 03:09:24 +00001251 if ((dn_db = rcu_dereference(in_dev->dn_ptr)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 goto out;
1253
1254 /* Zero source addresses are not allowed */
1255 if (fl.fld_src == 0)
1256 goto out;
1257
1258 /*
1259 * In this case we've just received a packet from a source
1260 * outside ourselves pretending to come from us. We don't
1261 * allow it any further to prevent routing loops, spoofing and
1262 * other nasties. Loopback packets already have the dst attached
1263 * so this only affects packets which have originated elsewhere.
1264 */
1265 err = -ENOTUNIQ;
1266 if (dn_dev_islocal(in_dev, cb->src))
1267 goto out;
1268
1269 err = dn_fib_lookup(&fl, &res);
1270 if (err) {
1271 if (err != -ESRCH)
1272 goto out;
1273 /*
1274 * Is the destination us ?
1275 */
1276 if (!dn_dev_islocal(in_dev, cb->dst))
1277 goto e_inval;
1278
1279 res.type = RTN_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 } else {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -08001281 __le16 src_map = fl.fld_src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 free_res = 1;
1283
1284 out_dev = DN_FIB_RES_DEV(res);
1285 if (out_dev == NULL) {
1286 if (net_ratelimit())
1287 printk(KERN_CRIT "Bug in dn_route_input_slow() "
1288 "No output device\n");
1289 goto e_inval;
1290 }
1291 dev_hold(out_dev);
1292
1293 if (res.r)
Steven Whitehousea8731cb2006-08-09 15:56:46 -07001294 src_map = fl.fld_src; /* no NAT support for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 gateway = DN_FIB_RES_GW(res);
1297 if (res.type == RTN_NAT) {
1298 fl.fld_dst = dn_fib_rules_map_destination(fl.fld_dst, &res);
1299 dn_fib_res_put(&res);
1300 free_res = 0;
1301 if (dn_fib_lookup(&fl, &res))
1302 goto e_inval;
1303 free_res = 1;
1304 if (res.type != RTN_UNICAST)
1305 goto e_inval;
1306 flags |= RTCF_DNAT;
1307 gateway = fl.fld_dst;
1308 }
1309 fl.fld_src = src_map;
1310 }
1311
1312 switch(res.type) {
1313 case RTN_UNICAST:
1314 /*
1315 * Forwarding check here, we only check for forwarding
1316 * being turned off, if you want to only forward intra
1317 * area, its up to you to set the routing tables up
1318 * correctly.
1319 */
1320 if (dn_db->parms.forwarding == 0)
1321 goto e_inval;
1322
1323 if (res.fi->fib_nhs > 1 && fl.oif == 0)
1324 dn_fib_select_multipath(&fl, &res);
1325
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001326 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
1328 * flag as a hint to set the intra-ethernet bit when
1329 * forwarding. If we've got NAT in operation, we don't do
1330 * this optimisation.
1331 */
1332 if (out_dev == in_dev && !(flags & RTCF_NAT))
1333 flags |= RTCF_DOREDIRECT;
1334
1335 local_src = DN_FIB_RES_PREFSRC(res);
1336
1337 case RTN_BLACKHOLE:
1338 case RTN_UNREACHABLE:
1339 break;
1340 case RTN_LOCAL:
1341 flags |= RTCF_LOCAL;
1342 fl.fld_src = cb->dst;
1343 fl.fld_dst = cb->src;
1344
1345 /* Routing tables gave us a gateway */
1346 if (gateway)
1347 goto make_route;
1348
1349 /* Packet was intra-ethernet, so we know its on-link */
Steven Whitehouse3a31b9d2006-10-18 20:45:22 -07001350 if (cb->rt_flags & DN_RT_F_IE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 gateway = cb->src;
1352 flags |= RTCF_DIRECTSRC;
1353 goto make_route;
1354 }
1355
1356 /* Use the default router if there is one */
1357 neigh = neigh_clone(dn_db->router);
1358 if (neigh) {
1359 gateway = ((struct dn_neigh *)neigh)->addr;
1360 goto make_route;
1361 }
1362
1363 /* Close eyes and pray */
1364 gateway = cb->src;
1365 flags |= RTCF_DIRECTSRC;
1366 goto make_route;
1367 default:
1368 goto e_inval;
1369 }
1370
1371make_route:
1372 rt = dst_alloc(&dn_dst_ops);
1373 if (rt == NULL)
1374 goto e_nobufs;
1375
1376 rt->rt_saddr = fl.fld_src;
1377 rt->rt_daddr = fl.fld_dst;
1378 rt->rt_gateway = fl.fld_dst;
1379 if (gateway)
1380 rt->rt_gateway = gateway;
1381 rt->rt_local_src = local_src ? local_src : rt->rt_saddr;
1382
1383 rt->rt_dst_map = fl.fld_dst;
1384 rt->rt_src_map = fl.fld_src;
1385
1386 rt->fl.fld_src = cb->src;
1387 rt->fl.fld_dst = cb->dst;
1388 rt->fl.oif = 0;
1389 rt->fl.iif = in_dev->ifindex;
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001390 rt->fl.mark = fl.mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Changli Gaod8d1f302010-06-10 23:31:35 -07001392 rt->dst.flags = DST_HOST;
1393 rt->dst.neighbour = neigh;
1394 rt->dst.dev = out_dev;
1395 rt->dst.lastuse = jiffies;
1396 rt->dst.output = dn_rt_bug;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 switch(res.type) {
1398 case RTN_UNICAST:
Changli Gaod8d1f302010-06-10 23:31:35 -07001399 rt->dst.input = dn_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 break;
1401 case RTN_LOCAL:
Changli Gaod8d1f302010-06-10 23:31:35 -07001402 rt->dst.output = dn_output;
1403 rt->dst.input = dn_nsp_rx;
1404 rt->dst.dev = in_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 flags |= RTCF_LOCAL;
1406 break;
1407 default:
1408 case RTN_UNREACHABLE:
1409 case RTN_BLACKHOLE:
Changli Gaod8d1f302010-06-10 23:31:35 -07001410 rt->dst.input = dst_discard;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412 rt->rt_flags = flags;
Changli Gaod8d1f302010-06-10 23:31:35 -07001413 if (rt->dst.dev)
1414 dev_hold(rt->dst.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
1416 err = dn_rt_set_next_hop(rt, &res);
1417 if (err)
1418 goto e_neighbour;
1419
1420 hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
Eric Dumazetadf30902009-06-02 05:19:30 +00001421 dn_insert_route(rt, hash, &rt);
Changli Gaod8d1f302010-06-10 23:31:35 -07001422 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
1424done:
1425 if (neigh)
1426 neigh_release(neigh);
1427 if (free_res)
1428 dn_fib_res_put(&res);
1429 dev_put(in_dev);
1430 if (out_dev)
1431 dev_put(out_dev);
1432out:
1433 return err;
1434
1435e_inval:
1436 err = -EINVAL;
1437 goto done;
1438
1439e_nobufs:
1440 err = -ENOBUFS;
1441 goto done;
1442
1443e_neighbour:
Changli Gaod8d1f302010-06-10 23:31:35 -07001444 dst_free(&rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 goto done;
1446}
1447
Roel Kluin5eaa65b2008-12-10 15:18:31 -08001448static int dn_route_input(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
1450 struct dn_route *rt;
1451 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1452 unsigned hash = dn_hash(cb->src, cb->dst);
1453
Eric Dumazetadf30902009-06-02 05:19:30 +00001454 if (skb_dst(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 return 0;
1456
1457 rcu_read_lock();
1458 for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt != NULL;
Changli Gaod8d1f302010-06-10 23:31:35 -07001459 rt = rcu_dereference(rt->dst.dn_next)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 if ((rt->fl.fld_src == cb->src) &&
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001461 (rt->fl.fld_dst == cb->dst) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 (rt->fl.oif == 0) &&
Thomas Graf47dcf0c2006-11-09 15:20:38 -08001463 (rt->fl.mark == skb->mark) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 (rt->fl.iif == cb->iif)) {
Changli Gaod8d1f302010-06-10 23:31:35 -07001465 dst_use(&rt->dst, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 rcu_read_unlock();
Eric Dumazetadf30902009-06-02 05:19:30 +00001467 skb_dst_set(skb, (struct dst_entry *)rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 return 0;
1469 }
1470 }
1471 rcu_read_unlock();
1472
1473 return dn_route_input_slow(skb);
1474}
1475
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001476static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1477 int event, int nowait, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
Eric Dumazetadf30902009-06-02 05:19:30 +00001479 struct dn_route *rt = (struct dn_route *)skb_dst(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 struct rtmsg *r;
1481 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001482 unsigned char *b = skb_tail_pointer(skb);
Thomas Grafe3703b32006-11-27 09:27:07 -08001483 long expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001485 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 r = NLMSG_DATA(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 r->rtm_family = AF_DECnet;
1488 r->rtm_dst_len = 16;
1489 r->rtm_src_len = 0;
1490 r->rtm_tos = 0;
1491 r->rtm_table = RT_TABLE_MAIN;
Patrick McHardy9e762a42006-08-10 23:09:48 -07001492 RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 r->rtm_type = rt->rt_type;
1494 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
1495 r->rtm_scope = RT_SCOPE_UNIVERSE;
1496 r->rtm_protocol = RTPROT_UNSPEC;
1497 if (rt->rt_flags & RTCF_NOTIFY)
1498 r->rtm_flags |= RTM_F_NOTIFY;
1499 RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr);
1500 if (rt->fl.fld_src) {
1501 r->rtm_src_len = 16;
1502 RTA_PUT(skb, RTA_SRC, 2, &rt->fl.fld_src);
1503 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001504 if (rt->dst.dev)
1505 RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->dst.dev->ifindex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 /*
1507 * Note to self - change this if input routes reverse direction when
1508 * they deal only with inputs and not with replies like they do
1509 * currently.
1510 */
1511 RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src);
1512 if (rt->rt_daddr != rt->rt_gateway)
1513 RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway);
David S. Millerdefb3512010-12-08 21:16:57 -08001514 if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 goto rtattr_failure;
Changli Gaod8d1f302010-06-10 23:31:35 -07001516 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
1517 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, 0, 0, expires,
1518 rt->dst.error) < 0)
Thomas Grafe3703b32006-11-27 09:27:07 -08001519 goto rtattr_failure;
David S. Millerc7537962010-11-11 17:07:48 -08001520 if (dn_is_input_route(rt))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fl.iif);
1522
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001523 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 return skb->len;
1525
1526nlmsg_failure:
1527rtattr_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001528 nlmsg_trim(skb, b);
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001529 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
1532/*
1533 * This is called by both endnodes and routers now.
1534 */
Thomas Graffa34ddd2007-03-22 11:57:46 -07001535static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001537 struct net *net = sock_net(in_skb->sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 struct rtattr **rta = arg;
1539 struct rtmsg *rtm = NLMSG_DATA(nlh);
1540 struct dn_route *rt = NULL;
1541 struct dn_skb_cb *cb;
1542 int err;
1543 struct sk_buff *skb;
1544 struct flowi fl;
1545
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001546 if (!net_eq(net, &init_net))
Denis V. Lunevb8542722007-12-01 00:21:31 +11001547 return -EINVAL;
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 memset(&fl, 0, sizeof(fl));
1550 fl.proto = DNPROTO_NSP;
1551
1552 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1553 if (skb == NULL)
1554 return -ENOBUFS;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001555 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 cb = DN_SKB_CB(skb);
1557
1558 if (rta[RTA_SRC-1])
1559 memcpy(&fl.fld_src, RTA_DATA(rta[RTA_SRC-1]), 2);
1560 if (rta[RTA_DST-1])
1561 memcpy(&fl.fld_dst, RTA_DATA(rta[RTA_DST-1]), 2);
1562 if (rta[RTA_IIF-1])
1563 memcpy(&fl.iif, RTA_DATA(rta[RTA_IIF-1]), sizeof(int));
1564
1565 if (fl.iif) {
1566 struct net_device *dev;
Eric W. Biederman881d9662007-09-17 11:56:21 -07001567 if ((dev = dev_get_by_index(&init_net, fl.iif)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 kfree_skb(skb);
1569 return -ENODEV;
1570 }
1571 if (!dev->dn_ptr) {
1572 dev_put(dev);
1573 kfree_skb(skb);
1574 return -ENODEV;
1575 }
YOSHIFUJI Hideakib98999d2007-12-12 03:51:49 +09001576 skb->protocol = htons(ETH_P_DNA_RT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 skb->dev = dev;
1578 cb->src = fl.fld_src;
1579 cb->dst = fl.fld_dst;
1580 local_bh_disable();
1581 err = dn_route_input(skb);
1582 local_bh_enable();
1583 memset(cb, 0, sizeof(struct dn_skb_cb));
Eric Dumazetadf30902009-06-02 05:19:30 +00001584 rt = (struct dn_route *)skb_dst(skb);
Changli Gaod8d1f302010-06-10 23:31:35 -07001585 if (!err && -rt->dst.error)
1586 err = rt->dst.error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 } else {
1588 int oif = 0;
1589 if (rta[RTA_OIF - 1])
1590 memcpy(&oif, RTA_DATA(rta[RTA_OIF - 1]), sizeof(int));
1591 fl.oif = oif;
1592 err = dn_route_output_key((struct dst_entry **)&rt, &fl, 0);
1593 }
1594
1595 if (skb->dev)
1596 dev_put(skb->dev);
1597 skb->dev = NULL;
1598 if (err)
1599 goto out_free;
Changli Gaod8d1f302010-06-10 23:31:35 -07001600 skb_dst_set(skb, &rt->dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 if (rtm->rtm_flags & RTM_F_NOTIFY)
1602 rt->rt_flags |= RTCF_NOTIFY;
1603
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001604 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 -07001605
1606 if (err == 0)
1607 goto out_free;
1608 if (err < 0) {
1609 err = -EMSGSIZE;
1610 goto out_free;
1611 }
1612
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08001613 return rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615out_free:
1616 kfree_skb(skb);
1617 return err;
1618}
1619
1620/*
1621 * For routers, this is called from dn_fib_dump, but for endnodes its
1622 * called directly from the rtnetlink dispatch table.
1623 */
1624int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1625{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001626 struct net *net = sock_net(skb->sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 struct dn_route *rt;
1628 int h, s_h;
1629 int idx, s_idx;
1630
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001631 if (!net_eq(net, &init_net))
Denis V. Lunevb8542722007-12-01 00:21:31 +11001632 return 0;
1633
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
1635 return -EINVAL;
1636 if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
1637 return 0;
1638
1639 s_h = cb->args[0];
1640 s_idx = idx = cb->args[1];
1641 for(h = 0; h <= dn_rt_hash_mask; h++) {
1642 if (h < s_h)
1643 continue;
1644 if (h > s_h)
1645 s_idx = 0;
1646 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001647 for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 rt;
Changli Gaod8d1f302010-06-10 23:31:35 -07001649 rt = rcu_dereference_bh(rt->dst.dn_next), idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 if (idx < s_idx)
1651 continue;
Changli Gaod8d1f302010-06-10 23:31:35 -07001652 skb_dst_set(skb, dst_clone(&rt->dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001654 cb->nlh->nlmsg_seq, RTM_NEWROUTE,
Jamal Hadi Salimb6544c02005-06-18 22:54:12 -07001655 1, NLM_F_MULTI) <= 0) {
Eric Dumazetadf30902009-06-02 05:19:30 +00001656 skb_dst_drop(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 rcu_read_unlock_bh();
1658 goto done;
1659 }
Eric Dumazetadf30902009-06-02 05:19:30 +00001660 skb_dst_drop(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 }
1662 rcu_read_unlock_bh();
1663 }
1664
1665done:
1666 cb->args[0] = h;
1667 cb->args[1] = idx;
1668 return skb->len;
1669}
1670
1671#ifdef CONFIG_PROC_FS
1672struct dn_rt_cache_iter_state {
1673 int bucket;
1674};
1675
1676static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
1677{
1678 struct dn_route *rt = NULL;
1679 struct dn_rt_cache_iter_state *s = seq->private;
1680
1681 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
1682 rcu_read_lock_bh();
Paul E. McKenneya898def2010-02-22 17:04:49 -08001683 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (rt)
1685 break;
1686 rcu_read_unlock_bh();
1687 }
Paul E. McKenneya898def2010-02-22 17:04:49 -08001688 return rt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689}
1690
1691static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
1692{
Eric Dumazet0d89d792008-01-10 22:35:21 -08001693 struct dn_rt_cache_iter_state *s = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Eric Dumazetfc766e42010-10-29 03:09:24 +00001695 rt = rcu_dereference_bh(rt->dst.dn_next);
1696 while (!rt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 rcu_read_unlock_bh();
1698 if (--s->bucket < 0)
1699 break;
1700 rcu_read_lock_bh();
Eric Dumazetfc766e42010-10-29 03:09:24 +00001701 rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 }
Eric Dumazetfc766e42010-10-29 03:09:24 +00001703 return rt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704}
1705
1706static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
1707{
1708 struct dn_route *rt = dn_rt_cache_get_first(seq);
1709
1710 if (rt) {
1711 while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
1712 --*pos;
1713 }
1714 return *pos ? NULL : rt;
1715}
1716
1717static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1718{
1719 struct dn_route *rt = dn_rt_cache_get_next(seq, v);
1720 ++*pos;
1721 return rt;
1722}
1723
1724static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
1725{
1726 if (v)
1727 rcu_read_unlock_bh();
1728}
1729
1730static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
1731{
1732 struct dn_route *rt = v;
1733 char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
1734
1735 seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
Changli Gaod8d1f302010-06-10 23:31:35 -07001736 rt->dst.dev ? rt->dst.dev->name : "*",
Harvey Harrisonc4106aa2008-11-27 00:12:47 -08001737 dn_addr2asc(le16_to_cpu(rt->rt_daddr), buf1),
1738 dn_addr2asc(le16_to_cpu(rt->rt_saddr), buf2),
Changli Gaod8d1f302010-06-10 23:31:35 -07001739 atomic_read(&rt->dst.__refcnt),
1740 rt->dst.__use,
1741 (int) dst_metric(&rt->dst, RTAX_RTT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 return 0;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001743}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001745static const struct seq_operations dn_rt_cache_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 .start = dn_rt_cache_seq_start,
1747 .next = dn_rt_cache_seq_next,
1748 .stop = dn_rt_cache_seq_stop,
1749 .show = dn_rt_cache_seq_show,
1750};
1751
1752static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
1753{
Pavel Emelyanov31164082007-10-10 02:30:23 -07001754 return seq_open_private(file, &dn_rt_cache_seq_ops,
1755 sizeof(struct dn_rt_cache_iter_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756}
1757
Arjan van de Ven9a321442007-02-12 00:55:35 -08001758static const struct file_operations dn_rt_cache_seq_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 .owner = THIS_MODULE,
1760 .open = dn_rt_cache_seq_open,
1761 .read = seq_read,
1762 .llseek = seq_lseek,
1763 .release = seq_release_private,
1764};
1765
1766#endif /* CONFIG_PROC_FS */
1767
1768void __init dn_route_init(void)
1769{
1770 int i, goal, order;
1771
Alexey Dobriyane5d679f2006-08-26 19:25:52 -07001772 dn_dst_ops.kmem_cachep =
1773 kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001774 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
Eric Dumazetfc66f952010-10-08 06:37:34 +00001775 dst_entries_init(&dn_dst_ops);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001776 setup_timer(&dn_route_timer, dn_dst_check_expire, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1778 add_timer(&dn_route_timer);
1779
Jan Beulich44813742009-09-21 17:03:05 -07001780 goal = totalram_pages >> (26 - PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 for(order = 0; (1UL << order) < goal; order++)
1783 /* NOTHING */;
1784
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001785 /*
1786 * Only want 1024 entries max, since the table is very, very unlikely
1787 * to be larger than that.
1788 */
1789 while(order && ((((1UL << order) * PAGE_SIZE) /
1790 sizeof(struct dn_rt_hash_bucket)) >= 2048))
1791 order--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001793 do {
1794 dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
1795 sizeof(struct dn_rt_hash_bucket);
1796 while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
1797 dn_rt_hash_mask--;
1798 dn_rt_hash_table = (struct dn_rt_hash_bucket *)
1799 __get_free_pages(GFP_ATOMIC, order);
1800 } while (dn_rt_hash_table == NULL && --order > 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 if (!dn_rt_hash_table)
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001803 panic("Failed to allocate DECnet route cache hash table\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001805 printk(KERN_INFO
1806 "DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
1807 dn_rt_hash_mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 (long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
1809
1810 dn_rt_hash_mask--;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001811 for(i = 0; i <= dn_rt_hash_mask; i++) {
1812 spin_lock_init(&dn_rt_hash_table[i].lock);
1813 dn_rt_hash_table[i].chain = NULL;
1814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +09001816 dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001818 proc_net_fops_create(&init_net, "decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
Thomas Graffa34ddd2007-03-22 11:57:46 -07001819
1820#ifdef CONFIG_DECNET_ROUTER
1821 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute, dn_fib_dump);
1822#else
1823 rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute,
1824 dn_cache_dump);
1825#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
1827
1828void __exit dn_route_cleanup(void)
1829{
1830 del_timer(&dn_route_timer);
1831 dn_run_flush(0);
1832
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001833 proc_net_remove(&init_net, "decnet_cache");
Eric Dumazetfc66f952010-10-08 06:37:34 +00001834 dst_entries_destroy(&dn_dst_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836