dn_route.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  1. /*
  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. (c) 1995-1998 E.M. Serrat emserrat@geocities.com
  45. This program is free software; you can redistribute it and/or modify
  46. it under the terms of the GNU General Public License as published by
  47. the Free Software Foundation; either version 2 of the License, or
  48. any later version.
  49. This program is distributed in the hope that it will be useful,
  50. but WITHOUT ANY WARRANTY; without even the implied warranty of
  51. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52. GNU General Public License for more details.
  53. *******************************************************************************/
  54. #include <linux/errno.h>
  55. #include <linux/types.h>
  56. #include <linux/socket.h>
  57. #include <linux/in.h>
  58. #include <linux/kernel.h>
  59. #include <linux/sockios.h>
  60. #include <linux/net.h>
  61. #include <linux/netdevice.h>
  62. #include <linux/inet.h>
  63. #include <linux/route.h>
  64. #include <linux/in_route.h>
  65. #include <net/sock.h>
  66. #include <linux/mm.h>
  67. #include <linux/proc_fs.h>
  68. #include <linux/seq_file.h>
  69. #include <linux/init.h>
  70. #include <linux/rtnetlink.h>
  71. #include <linux/string.h>
  72. #include <linux/netfilter_decnet.h>
  73. #include <linux/rcupdate.h>
  74. #include <linux/times.h>
  75. #include <asm/errno.h>
  76. #include <net/neighbour.h>
  77. #include <net/dst.h>
  78. #include <net/flow.h>
  79. #include <net/fib_rules.h>
  80. #include <net/dn.h>
  81. #include <net/dn_dev.h>
  82. #include <net/dn_nsp.h>
  83. #include <net/dn_route.h>
  84. #include <net/dn_neigh.h>
  85. #include <net/dn_fib.h>
  86. struct dn_rt_hash_bucket
  87. {
  88. struct dn_route *chain;
  89. spinlock_t lock;
  90. } __attribute__((__aligned__(8)));
  91. extern struct neigh_table dn_neigh_table;
  92. static unsigned char dn_hiord_addr[6] = {0xAA,0x00,0x04,0x00,0x00,0x00};
  93. static const int dn_rt_min_delay = 2 * HZ;
  94. static const int dn_rt_max_delay = 10 * HZ;
  95. static const int dn_rt_mtu_expires = 10 * 60 * HZ;
  96. static unsigned long dn_rt_deadline;
  97. static int dn_dst_gc(void);
  98. static struct dst_entry *dn_dst_check(struct dst_entry *, __u32);
  99. static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
  100. static void dn_dst_link_failure(struct sk_buff *);
  101. static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
  102. static int dn_route_input(struct sk_buff *);
  103. static void dn_run_flush(unsigned long dummy);
  104. static struct dn_rt_hash_bucket *dn_rt_hash_table;
  105. static unsigned dn_rt_hash_mask;
  106. static struct timer_list dn_route_timer;
  107. static DEFINE_TIMER(dn_rt_flush_timer, dn_run_flush, 0, 0);
  108. int decnet_dst_gc_interval = 2;
  109. static struct dst_ops dn_dst_ops = {
  110. .family = PF_DECnet,
  111. .protocol = __constant_htons(ETH_P_DNA_RT),
  112. .gc_thresh = 128,
  113. .gc = dn_dst_gc,
  114. .check = dn_dst_check,
  115. .negative_advice = dn_dst_negative_advice,
  116. .link_failure = dn_dst_link_failure,
  117. .update_pmtu = dn_dst_update_pmtu,
  118. .entry_size = sizeof(struct dn_route),
  119. .entries = ATOMIC_INIT(0),
  120. };
  121. static __inline__ unsigned dn_hash(__le16 src, __le16 dst)
  122. {
  123. __u16 tmp = (__u16 __force)(src ^ dst);
  124. tmp ^= (tmp >> 3);
  125. tmp ^= (tmp >> 5);
  126. tmp ^= (tmp >> 10);
  127. return dn_rt_hash_mask & (unsigned)tmp;
  128. }
  129. static inline void dnrt_free(struct dn_route *rt)
  130. {
  131. call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
  132. }
  133. static inline void dnrt_drop(struct dn_route *rt)
  134. {
  135. dst_release(&rt->u.dst);
  136. call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
  137. }
  138. static void dn_dst_check_expire(unsigned long dummy)
  139. {
  140. int i;
  141. struct dn_route *rt, **rtp;
  142. unsigned long now = jiffies;
  143. unsigned long expire = 120 * HZ;
  144. for(i = 0; i <= dn_rt_hash_mask; i++) {
  145. rtp = &dn_rt_hash_table[i].chain;
  146. spin_lock(&dn_rt_hash_table[i].lock);
  147. while((rt=*rtp) != NULL) {
  148. if (atomic_read(&rt->u.dst.__refcnt) ||
  149. (now - rt->u.dst.lastuse) < expire) {
  150. rtp = &rt->u.dst.dn_next;
  151. continue;
  152. }
  153. *rtp = rt->u.dst.dn_next;
  154. rt->u.dst.dn_next = NULL;
  155. dnrt_free(rt);
  156. }
  157. spin_unlock(&dn_rt_hash_table[i].lock);
  158. if ((jiffies - now) > 0)
  159. break;
  160. }
  161. mod_timer(&dn_route_timer, now + decnet_dst_gc_interval * HZ);
  162. }
  163. static int dn_dst_gc(void)
  164. {
  165. struct dn_route *rt, **rtp;
  166. int i;
  167. unsigned long now = jiffies;
  168. unsigned long expire = 10 * HZ;
  169. for(i = 0; i <= dn_rt_hash_mask; i++) {
  170. spin_lock_bh(&dn_rt_hash_table[i].lock);
  171. rtp = &dn_rt_hash_table[i].chain;
  172. while((rt=*rtp) != NULL) {
  173. if (atomic_read(&rt->u.dst.__refcnt) ||
  174. (now - rt->u.dst.lastuse) < expire) {
  175. rtp = &rt->u.dst.dn_next;
  176. continue;
  177. }
  178. *rtp = rt->u.dst.dn_next;
  179. rt->u.dst.dn_next = NULL;
  180. dnrt_drop(rt);
  181. break;
  182. }
  183. spin_unlock_bh(&dn_rt_hash_table[i].lock);
  184. }
  185. return 0;
  186. }
  187. /*
  188. * The decnet standards don't impose a particular minimum mtu, what they
  189. * do insist on is that the routing layer accepts a datagram of at least
  190. * 230 bytes long. Here we have to subtract the routing header length from
  191. * 230 to get the minimum acceptable mtu. If there is no neighbour, then we
  192. * assume the worst and use a long header size.
  193. *
  194. * We update both the mtu and the advertised mss (i.e. the segment size we
  195. * advertise to the other end).
  196. */
  197. static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu)
  198. {
  199. u32 min_mtu = 230;
  200. struct dn_dev *dn = dst->neighbour ?
  201. (struct dn_dev *)dst->neighbour->dev->dn_ptr : NULL;
  202. if (dn && dn->use_long == 0)
  203. min_mtu -= 6;
  204. else
  205. min_mtu -= 21;
  206. if (dst->metrics[RTAX_MTU-1] > mtu && mtu >= min_mtu) {
  207. if (!(dst_metric_locked(dst, RTAX_MTU))) {
  208. dst->metrics[RTAX_MTU-1] = mtu;
  209. dst_set_expires(dst, dn_rt_mtu_expires);
  210. }
  211. if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
  212. u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
  213. if (dst->metrics[RTAX_ADVMSS-1] > mss)
  214. dst->metrics[RTAX_ADVMSS-1] = mss;
  215. }
  216. }
  217. }
  218. /*
  219. * When a route has been marked obsolete. (e.g. routing cache flush)
  220. */
  221. static struct dst_entry *dn_dst_check(struct dst_entry *dst, __u32 cookie)
  222. {
  223. return NULL;
  224. }
  225. static struct dst_entry *dn_dst_negative_advice(struct dst_entry *dst)
  226. {
  227. dst_release(dst);
  228. return NULL;
  229. }
  230. static void dn_dst_link_failure(struct sk_buff *skb)
  231. {
  232. return;
  233. }
  234. static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
  235. {
  236. return ((fl1->nl_u.dn_u.daddr ^ fl2->nl_u.dn_u.daddr) |
  237. (fl1->nl_u.dn_u.saddr ^ fl2->nl_u.dn_u.saddr) |
  238. (fl1->mark ^ fl2->mark) |
  239. (fl1->nl_u.dn_u.scope ^ fl2->nl_u.dn_u.scope) |
  240. (fl1->oif ^ fl2->oif) |
  241. (fl1->iif ^ fl2->iif)) == 0;
  242. }
  243. static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp)
  244. {
  245. struct dn_route *rth, **rthp;
  246. unsigned long now = jiffies;
  247. rthp = &dn_rt_hash_table[hash].chain;
  248. spin_lock_bh(&dn_rt_hash_table[hash].lock);
  249. while((rth = *rthp) != NULL) {
  250. if (compare_keys(&rth->fl, &rt->fl)) {
  251. /* Put it first */
  252. *rthp = rth->u.dst.dn_next;
  253. rcu_assign_pointer(rth->u.dst.dn_next,
  254. dn_rt_hash_table[hash].chain);
  255. rcu_assign_pointer(dn_rt_hash_table[hash].chain, rth);
  256. rth->u.dst.__use++;
  257. dst_hold(&rth->u.dst);
  258. rth->u.dst.lastuse = now;
  259. spin_unlock_bh(&dn_rt_hash_table[hash].lock);
  260. dnrt_drop(rt);
  261. *rp = rth;
  262. return 0;
  263. }
  264. rthp = &rth->u.dst.dn_next;
  265. }
  266. rcu_assign_pointer(rt->u.dst.dn_next, dn_rt_hash_table[hash].chain);
  267. rcu_assign_pointer(dn_rt_hash_table[hash].chain, rt);
  268. dst_hold(&rt->u.dst);
  269. rt->u.dst.__use++;
  270. rt->u.dst.lastuse = now;
  271. spin_unlock_bh(&dn_rt_hash_table[hash].lock);
  272. *rp = rt;
  273. return 0;
  274. }
  275. void dn_run_flush(unsigned long dummy)
  276. {
  277. int i;
  278. struct dn_route *rt, *next;
  279. for(i = 0; i < dn_rt_hash_mask; i++) {
  280. spin_lock_bh(&dn_rt_hash_table[i].lock);
  281. if ((rt = xchg(&dn_rt_hash_table[i].chain, NULL)) == NULL)
  282. goto nothing_to_declare;
  283. for(; rt; rt=next) {
  284. next = rt->u.dst.dn_next;
  285. rt->u.dst.dn_next = NULL;
  286. dst_free((struct dst_entry *)rt);
  287. }
  288. nothing_to_declare:
  289. spin_unlock_bh(&dn_rt_hash_table[i].lock);
  290. }
  291. }
  292. static DEFINE_SPINLOCK(dn_rt_flush_lock);
  293. void dn_rt_cache_flush(int delay)
  294. {
  295. unsigned long now = jiffies;
  296. int user_mode = !in_interrupt();
  297. if (delay < 0)
  298. delay = dn_rt_min_delay;
  299. spin_lock_bh(&dn_rt_flush_lock);
  300. if (del_timer(&dn_rt_flush_timer) && delay > 0 && dn_rt_deadline) {
  301. long tmo = (long)(dn_rt_deadline - now);
  302. if (user_mode && tmo < dn_rt_max_delay - dn_rt_min_delay)
  303. tmo = 0;
  304. if (delay > tmo)
  305. delay = tmo;
  306. }
  307. if (delay <= 0) {
  308. spin_unlock_bh(&dn_rt_flush_lock);
  309. dn_run_flush(0);
  310. return;
  311. }
  312. if (dn_rt_deadline == 0)
  313. dn_rt_deadline = now + dn_rt_max_delay;
  314. dn_rt_flush_timer.expires = now + delay;
  315. add_timer(&dn_rt_flush_timer);
  316. spin_unlock_bh(&dn_rt_flush_lock);
  317. }
  318. /**
  319. * dn_return_short - Return a short packet to its sender
  320. * @skb: The packet to return
  321. *
  322. */
  323. static int dn_return_short(struct sk_buff *skb)
  324. {
  325. struct dn_skb_cb *cb;
  326. unsigned char *ptr;
  327. __le16 *src;
  328. __le16 *dst;
  329. __le16 tmp;
  330. /* Add back headers */
  331. skb_push(skb, skb->data - skb->nh.raw);
  332. if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
  333. return NET_RX_DROP;
  334. cb = DN_SKB_CB(skb);
  335. /* Skip packet length and point to flags */
  336. ptr = skb->data + 2;
  337. *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
  338. dst = (__le16 *)ptr;
  339. ptr += 2;
  340. src = (__le16 *)ptr;
  341. ptr += 2;
  342. *ptr = 0; /* Zero hop count */
  343. /* Swap source and destination */
  344. tmp = *src;
  345. *src = *dst;
  346. *dst = tmp;
  347. skb->pkt_type = PACKET_OUTGOING;
  348. dn_rt_finish_output(skb, NULL, NULL);
  349. return NET_RX_SUCCESS;
  350. }
  351. /**
  352. * dn_return_long - Return a long packet to its sender
  353. * @skb: The long format packet to return
  354. *
  355. */
  356. static int dn_return_long(struct sk_buff *skb)
  357. {
  358. struct dn_skb_cb *cb;
  359. unsigned char *ptr;
  360. unsigned char *src_addr, *dst_addr;
  361. unsigned char tmp[ETH_ALEN];
  362. /* Add back all headers */
  363. skb_push(skb, skb->data - skb->nh.raw);
  364. if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
  365. return NET_RX_DROP;
  366. cb = DN_SKB_CB(skb);
  367. /* Ignore packet length and point to flags */
  368. ptr = skb->data + 2;
  369. /* Skip padding */
  370. if (*ptr & DN_RT_F_PF) {
  371. char padlen = (*ptr & ~DN_RT_F_PF);
  372. ptr += padlen;
  373. }
  374. *ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
  375. ptr += 2;
  376. dst_addr = ptr;
  377. ptr += 8;
  378. src_addr = ptr;
  379. ptr += 6;
  380. *ptr = 0; /* Zero hop count */
  381. /* Swap source and destination */
  382. memcpy(tmp, src_addr, ETH_ALEN);
  383. memcpy(src_addr, dst_addr, ETH_ALEN);
  384. memcpy(dst_addr, tmp, ETH_ALEN);
  385. skb->pkt_type = PACKET_OUTGOING;
  386. dn_rt_finish_output(skb, dst_addr, src_addr);
  387. return NET_RX_SUCCESS;
  388. }
  389. /**
  390. * dn_route_rx_packet - Try and find a route for an incoming packet
  391. * @skb: The packet to find a route for
  392. *
  393. * Returns: result of input function if route is found, error code otherwise
  394. */
  395. static int dn_route_rx_packet(struct sk_buff *skb)
  396. {
  397. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  398. int err;
  399. if ((err = dn_route_input(skb)) == 0)
  400. return dst_input(skb);
  401. if (decnet_debug_level & 4) {
  402. char *devname = skb->dev ? skb->dev->name : "???";
  403. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  404. printk(KERN_DEBUG
  405. "DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
  406. (int)cb->rt_flags, devname, skb->len,
  407. dn_ntohs(cb->src), dn_ntohs(cb->dst),
  408. err, skb->pkt_type);
  409. }
  410. if ((skb->pkt_type == PACKET_HOST) && (cb->rt_flags & DN_RT_F_RQR)) {
  411. switch(cb->rt_flags & DN_RT_PKT_MSK) {
  412. case DN_RT_PKT_SHORT:
  413. return dn_return_short(skb);
  414. case DN_RT_PKT_LONG:
  415. return dn_return_long(skb);
  416. }
  417. }
  418. kfree_skb(skb);
  419. return NET_RX_DROP;
  420. }
  421. static int dn_route_rx_long(struct sk_buff *skb)
  422. {
  423. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  424. unsigned char *ptr = skb->data;
  425. if (!pskb_may_pull(skb, 21)) /* 20 for long header, 1 for shortest nsp */
  426. goto drop_it;
  427. skb_pull(skb, 20);
  428. skb->h.raw = skb->data;
  429. /* Destination info */
  430. ptr += 2;
  431. cb->dst = dn_eth2dn(ptr);
  432. if (memcmp(ptr, dn_hiord_addr, 4) != 0)
  433. goto drop_it;
  434. ptr += 6;
  435. /* Source info */
  436. ptr += 2;
  437. cb->src = dn_eth2dn(ptr);
  438. if (memcmp(ptr, dn_hiord_addr, 4) != 0)
  439. goto drop_it;
  440. ptr += 6;
  441. /* Other junk */
  442. ptr++;
  443. cb->hops = *ptr++; /* Visit Count */
  444. return NF_HOOK(PF_DECnet, NF_DN_PRE_ROUTING, skb, skb->dev, NULL, dn_route_rx_packet);
  445. drop_it:
  446. kfree_skb(skb);
  447. return NET_RX_DROP;
  448. }
  449. static int dn_route_rx_short(struct sk_buff *skb)
  450. {
  451. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  452. unsigned char *ptr = skb->data;
  453. if (!pskb_may_pull(skb, 6)) /* 5 for short header + 1 for shortest nsp */
  454. goto drop_it;
  455. skb_pull(skb, 5);
  456. skb->h.raw = skb->data;
  457. cb->dst = *(__le16 *)ptr;
  458. ptr += 2;
  459. cb->src = *(__le16 *)ptr;
  460. ptr += 2;
  461. cb->hops = *ptr & 0x3f;
  462. return NF_HOOK(PF_DECnet, NF_DN_PRE_ROUTING, skb, skb->dev, NULL, dn_route_rx_packet);
  463. drop_it:
  464. kfree_skb(skb);
  465. return NET_RX_DROP;
  466. }
  467. static int dn_route_discard(struct sk_buff *skb)
  468. {
  469. /*
  470. * I know we drop the packet here, but thats considered success in
  471. * this case
  472. */
  473. kfree_skb(skb);
  474. return NET_RX_SUCCESS;
  475. }
  476. static int dn_route_ptp_hello(struct sk_buff *skb)
  477. {
  478. dn_dev_hello(skb);
  479. dn_neigh_pointopoint_hello(skb);
  480. return NET_RX_SUCCESS;
  481. }
  482. int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
  483. {
  484. struct dn_skb_cb *cb;
  485. unsigned char flags = 0;
  486. __u16 len = dn_ntohs(*(__le16 *)skb->data);
  487. struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr;
  488. unsigned char padlen = 0;
  489. if (dn == NULL)
  490. goto dump_it;
  491. if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
  492. goto out;
  493. if (!pskb_may_pull(skb, 3))
  494. goto dump_it;
  495. skb_pull(skb, 2);
  496. if (len > skb->len)
  497. goto dump_it;
  498. skb_trim(skb, len);
  499. flags = *skb->data;
  500. cb = DN_SKB_CB(skb);
  501. cb->stamp = jiffies;
  502. cb->iif = dev->ifindex;
  503. /*
  504. * If we have padding, remove it.
  505. */
  506. if (flags & DN_RT_F_PF) {
  507. padlen = flags & ~DN_RT_F_PF;
  508. if (!pskb_may_pull(skb, padlen + 1))
  509. goto dump_it;
  510. skb_pull(skb, padlen);
  511. flags = *skb->data;
  512. }
  513. skb->nh.raw = skb->data;
  514. /*
  515. * Weed out future version DECnet
  516. */
  517. if (flags & DN_RT_F_VER)
  518. goto dump_it;
  519. cb->rt_flags = flags;
  520. if (decnet_debug_level & 1)
  521. printk(KERN_DEBUG
  522. "dn_route_rcv: got 0x%02x from %s [%d %d %d]\n",
  523. (int)flags, (dev) ? dev->name : "???", len, skb->len,
  524. padlen);
  525. if (flags & DN_RT_PKT_CNTL) {
  526. if (unlikely(skb_linearize(skb)))
  527. goto dump_it;
  528. switch(flags & DN_RT_CNTL_MSK) {
  529. case DN_RT_PKT_INIT:
  530. dn_dev_init_pkt(skb);
  531. break;
  532. case DN_RT_PKT_VERI:
  533. dn_dev_veri_pkt(skb);
  534. break;
  535. }
  536. if (dn->parms.state != DN_DEV_S_RU)
  537. goto dump_it;
  538. switch(flags & DN_RT_CNTL_MSK) {
  539. case DN_RT_PKT_HELO:
  540. return NF_HOOK(PF_DECnet, NF_DN_HELLO, skb, skb->dev, NULL, dn_route_ptp_hello);
  541. case DN_RT_PKT_L1RT:
  542. case DN_RT_PKT_L2RT:
  543. return NF_HOOK(PF_DECnet, NF_DN_ROUTE, skb, skb->dev, NULL, dn_route_discard);
  544. case DN_RT_PKT_ERTH:
  545. return NF_HOOK(PF_DECnet, NF_DN_HELLO, skb, skb->dev, NULL, dn_neigh_router_hello);
  546. case DN_RT_PKT_EEDH:
  547. return NF_HOOK(PF_DECnet, NF_DN_HELLO, skb, skb->dev, NULL, dn_neigh_endnode_hello);
  548. }
  549. } else {
  550. if (dn->parms.state != DN_DEV_S_RU)
  551. goto dump_it;
  552. skb_pull(skb, 1); /* Pull flags */
  553. switch(flags & DN_RT_PKT_MSK) {
  554. case DN_RT_PKT_LONG:
  555. return dn_route_rx_long(skb);
  556. case DN_RT_PKT_SHORT:
  557. return dn_route_rx_short(skb);
  558. }
  559. }
  560. dump_it:
  561. kfree_skb(skb);
  562. out:
  563. return NET_RX_DROP;
  564. }
  565. static int dn_output(struct sk_buff *skb)
  566. {
  567. struct dst_entry *dst = skb->dst;
  568. struct dn_route *rt = (struct dn_route *)dst;
  569. struct net_device *dev = dst->dev;
  570. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  571. struct neighbour *neigh;
  572. int err = -EINVAL;
  573. if ((neigh = dst->neighbour) == NULL)
  574. goto error;
  575. skb->dev = dev;
  576. cb->src = rt->rt_saddr;
  577. cb->dst = rt->rt_daddr;
  578. /*
  579. * Always set the Intra-Ethernet bit on all outgoing packets
  580. * originated on this node. Only valid flag from upper layers
  581. * is return-to-sender-requested. Set hop count to 0 too.
  582. */
  583. cb->rt_flags &= ~DN_RT_F_RQR;
  584. cb->rt_flags |= DN_RT_F_IE;
  585. cb->hops = 0;
  586. return NF_HOOK(PF_DECnet, NF_DN_LOCAL_OUT, skb, NULL, dev, neigh->output);
  587. error:
  588. if (net_ratelimit())
  589. printk(KERN_DEBUG "dn_output: This should not happen\n");
  590. kfree_skb(skb);
  591. return err;
  592. }
  593. static int dn_forward(struct sk_buff *skb)
  594. {
  595. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  596. struct dst_entry *dst = skb->dst;
  597. struct dn_dev *dn_db = dst->dev->dn_ptr;
  598. struct dn_route *rt;
  599. struct neighbour *neigh = dst->neighbour;
  600. int header_len;
  601. #ifdef CONFIG_NETFILTER
  602. struct net_device *dev = skb->dev;
  603. #endif
  604. if (skb->pkt_type != PACKET_HOST)
  605. goto drop;
  606. /* Ensure that we have enough space for headers */
  607. rt = (struct dn_route *)skb->dst;
  608. header_len = dn_db->use_long ? 21 : 6;
  609. if (skb_cow(skb, LL_RESERVED_SPACE(rt->u.dst.dev)+header_len))
  610. goto drop;
  611. /*
  612. * Hop count exceeded.
  613. */
  614. if (++cb->hops > 30)
  615. goto drop;
  616. skb->dev = rt->u.dst.dev;
  617. /*
  618. * If packet goes out same interface it came in on, then set
  619. * the Intra-Ethernet bit. This has no effect for short
  620. * packets, so we don't need to test for them here.
  621. */
  622. cb->rt_flags &= ~DN_RT_F_IE;
  623. if (rt->rt_flags & RTCF_DOREDIRECT)
  624. cb->rt_flags |= DN_RT_F_IE;
  625. return NF_HOOK(PF_DECnet, NF_DN_FORWARD, skb, dev, skb->dev, neigh->output);
  626. drop:
  627. kfree_skb(skb);
  628. return NET_RX_DROP;
  629. }
  630. /*
  631. * Drop packet. This is used for endnodes and for
  632. * when we should not be forwarding packets from
  633. * this dest.
  634. */
  635. static int dn_blackhole(struct sk_buff *skb)
  636. {
  637. kfree_skb(skb);
  638. return NET_RX_DROP;
  639. }
  640. /*
  641. * Used to catch bugs. This should never normally get
  642. * called.
  643. */
  644. static int dn_rt_bug(struct sk_buff *skb)
  645. {
  646. if (net_ratelimit()) {
  647. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  648. printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
  649. dn_ntohs(cb->src), dn_ntohs(cb->dst));
  650. }
  651. kfree_skb(skb);
  652. return NET_RX_BAD;
  653. }
  654. static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
  655. {
  656. struct dn_fib_info *fi = res->fi;
  657. struct net_device *dev = rt->u.dst.dev;
  658. struct neighbour *n;
  659. unsigned mss;
  660. if (fi) {
  661. if (DN_FIB_RES_GW(*res) &&
  662. DN_FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
  663. rt->rt_gateway = DN_FIB_RES_GW(*res);
  664. memcpy(rt->u.dst.metrics, fi->fib_metrics,
  665. sizeof(rt->u.dst.metrics));
  666. }
  667. rt->rt_type = res->type;
  668. if (dev != NULL && rt->u.dst.neighbour == NULL) {
  669. n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
  670. if (IS_ERR(n))
  671. return PTR_ERR(n);
  672. rt->u.dst.neighbour = n;
  673. }
  674. if (rt->u.dst.metrics[RTAX_MTU-1] == 0 ||
  675. rt->u.dst.metrics[RTAX_MTU-1] > rt->u.dst.dev->mtu)
  676. rt->u.dst.metrics[RTAX_MTU-1] = rt->u.dst.dev->mtu;
  677. mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->u.dst));
  678. if (rt->u.dst.metrics[RTAX_ADVMSS-1] == 0 ||
  679. rt->u.dst.metrics[RTAX_ADVMSS-1] > mss)
  680. rt->u.dst.metrics[RTAX_ADVMSS-1] = mss;
  681. return 0;
  682. }
  683. static inline int dn_match_addr(__le16 addr1, __le16 addr2)
  684. {
  685. __u16 tmp = dn_ntohs(addr1) ^ dn_ntohs(addr2);
  686. int match = 16;
  687. while(tmp) {
  688. tmp >>= 1;
  689. match--;
  690. }
  691. return match;
  692. }
  693. static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
  694. {
  695. __le16 saddr = 0;
  696. struct dn_dev *dn_db = dev->dn_ptr;
  697. struct dn_ifaddr *ifa;
  698. int best_match = 0;
  699. int ret;
  700. read_lock(&dev_base_lock);
  701. for(ifa = dn_db->ifa_list; ifa; ifa = ifa->ifa_next) {
  702. if (ifa->ifa_scope > scope)
  703. continue;
  704. if (!daddr) {
  705. saddr = ifa->ifa_local;
  706. break;
  707. }
  708. ret = dn_match_addr(daddr, ifa->ifa_local);
  709. if (ret > best_match)
  710. saddr = ifa->ifa_local;
  711. if (best_match == 0)
  712. saddr = ifa->ifa_local;
  713. }
  714. read_unlock(&dev_base_lock);
  715. return saddr;
  716. }
  717. static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
  718. {
  719. return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
  720. }
  721. static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
  722. {
  723. __le16 mask = dnet_make_mask(res->prefixlen);
  724. return (daddr&~mask)|res->fi->fib_nh->nh_gw;
  725. }
  726. static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *oldflp, int try_hard)
  727. {
  728. struct flowi fl = { .nl_u = { .dn_u =
  729. { .daddr = oldflp->fld_dst,
  730. .saddr = oldflp->fld_src,
  731. .scope = RT_SCOPE_UNIVERSE,
  732. } },
  733. .mark = oldflp->mark,
  734. .iif = loopback_dev.ifindex,
  735. .oif = oldflp->oif };
  736. struct dn_route *rt = NULL;
  737. struct net_device *dev_out = NULL;
  738. struct neighbour *neigh = NULL;
  739. unsigned hash;
  740. unsigned flags = 0;
  741. struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
  742. int err;
  743. int free_res = 0;
  744. __le16 gateway = 0;
  745. if (decnet_debug_level & 16)
  746. printk(KERN_DEBUG
  747. "dn_route_output_slow: dst=%04x src=%04x mark=%d"
  748. " iif=%d oif=%d\n", dn_ntohs(oldflp->fld_dst),
  749. dn_ntohs(oldflp->fld_src),
  750. oldflp->mark, loopback_dev.ifindex, oldflp->oif);
  751. /* If we have an output interface, verify its a DECnet device */
  752. if (oldflp->oif) {
  753. dev_out = dev_get_by_index(oldflp->oif);
  754. err = -ENODEV;
  755. if (dev_out && dev_out->dn_ptr == NULL) {
  756. dev_put(dev_out);
  757. dev_out = NULL;
  758. }
  759. if (dev_out == NULL)
  760. goto out;
  761. }
  762. /* If we have a source address, verify that its a local address */
  763. if (oldflp->fld_src) {
  764. err = -EADDRNOTAVAIL;
  765. if (dev_out) {
  766. if (dn_dev_islocal(dev_out, oldflp->fld_src))
  767. goto source_ok;
  768. dev_put(dev_out);
  769. goto out;
  770. }
  771. read_lock(&dev_base_lock);
  772. for(dev_out = dev_base; dev_out; dev_out = dev_out->next) {
  773. if (!dev_out->dn_ptr)
  774. continue;
  775. if (!dn_dev_islocal(dev_out, oldflp->fld_src))
  776. continue;
  777. if ((dev_out->flags & IFF_LOOPBACK) &&
  778. oldflp->fld_dst &&
  779. !dn_dev_islocal(dev_out, oldflp->fld_dst))
  780. continue;
  781. break;
  782. }
  783. read_unlock(&dev_base_lock);
  784. if (dev_out == NULL)
  785. goto out;
  786. dev_hold(dev_out);
  787. source_ok:
  788. ;
  789. }
  790. /* No destination? Assume its local */
  791. if (!fl.fld_dst) {
  792. fl.fld_dst = fl.fld_src;
  793. err = -EADDRNOTAVAIL;
  794. if (dev_out)
  795. dev_put(dev_out);
  796. dev_out = &loopback_dev;
  797. dev_hold(dev_out);
  798. if (!fl.fld_dst) {
  799. fl.fld_dst =
  800. fl.fld_src = dnet_select_source(dev_out, 0,
  801. RT_SCOPE_HOST);
  802. if (!fl.fld_dst)
  803. goto out;
  804. }
  805. fl.oif = loopback_dev.ifindex;
  806. res.type = RTN_LOCAL;
  807. goto make_route;
  808. }
  809. if (decnet_debug_level & 16)
  810. printk(KERN_DEBUG
  811. "dn_route_output_slow: initial checks complete."
  812. " dst=%o4x src=%04x oif=%d try_hard=%d\n",
  813. dn_ntohs(fl.fld_dst), dn_ntohs(fl.fld_src),
  814. fl.oif, try_hard);
  815. /*
  816. * N.B. If the kernel is compiled without router support then
  817. * dn_fib_lookup() will evaluate to non-zero so this if () block
  818. * will always be executed.
  819. */
  820. err = -ESRCH;
  821. if (try_hard || (err = dn_fib_lookup(&fl, &res)) != 0) {
  822. struct dn_dev *dn_db;
  823. if (err != -ESRCH)
  824. goto out;
  825. /*
  826. * Here the fallback is basically the standard algorithm for
  827. * routing in endnodes which is described in the DECnet routing
  828. * docs
  829. *
  830. * If we are not trying hard, look in neighbour cache.
  831. * The result is tested to ensure that if a specific output
  832. * device/source address was requested, then we honour that
  833. * here
  834. */
  835. if (!try_hard) {
  836. neigh = neigh_lookup_nodev(&dn_neigh_table, &fl.fld_dst);
  837. if (neigh) {
  838. if ((oldflp->oif &&
  839. (neigh->dev->ifindex != oldflp->oif)) ||
  840. (oldflp->fld_src &&
  841. (!dn_dev_islocal(neigh->dev,
  842. oldflp->fld_src)))) {
  843. neigh_release(neigh);
  844. neigh = NULL;
  845. } else {
  846. if (dev_out)
  847. dev_put(dev_out);
  848. if (dn_dev_islocal(neigh->dev, fl.fld_dst)) {
  849. dev_out = &loopback_dev;
  850. res.type = RTN_LOCAL;
  851. } else {
  852. dev_out = neigh->dev;
  853. }
  854. dev_hold(dev_out);
  855. goto select_source;
  856. }
  857. }
  858. }
  859. /* Not there? Perhaps its a local address */
  860. if (dev_out == NULL)
  861. dev_out = dn_dev_get_default();
  862. err = -ENODEV;
  863. if (dev_out == NULL)
  864. goto out;
  865. dn_db = dev_out->dn_ptr;
  866. /* Possible improvement - check all devices for local addr */
  867. if (dn_dev_islocal(dev_out, fl.fld_dst)) {
  868. dev_put(dev_out);
  869. dev_out = &loopback_dev;
  870. dev_hold(dev_out);
  871. res.type = RTN_LOCAL;
  872. goto select_source;
  873. }
  874. /* Not local either.... try sending it to the default router */
  875. neigh = neigh_clone(dn_db->router);
  876. BUG_ON(neigh && neigh->dev != dev_out);
  877. /* Ok then, we assume its directly connected and move on */
  878. select_source:
  879. if (neigh)
  880. gateway = ((struct dn_neigh *)neigh)->addr;
  881. if (gateway == 0)
  882. gateway = fl.fld_dst;
  883. if (fl.fld_src == 0) {
  884. fl.fld_src = dnet_select_source(dev_out, gateway,
  885. res.type == RTN_LOCAL ?
  886. RT_SCOPE_HOST :
  887. RT_SCOPE_LINK);
  888. if (fl.fld_src == 0 && res.type != RTN_LOCAL)
  889. goto e_addr;
  890. }
  891. fl.oif = dev_out->ifindex;
  892. goto make_route;
  893. }
  894. free_res = 1;
  895. if (res.type == RTN_NAT)
  896. goto e_inval;
  897. if (res.type == RTN_LOCAL) {
  898. if (!fl.fld_src)
  899. fl.fld_src = fl.fld_dst;
  900. if (dev_out)
  901. dev_put(dev_out);
  902. dev_out = &loopback_dev;
  903. dev_hold(dev_out);
  904. fl.oif = dev_out->ifindex;
  905. if (res.fi)
  906. dn_fib_info_put(res.fi);
  907. res.fi = NULL;
  908. goto make_route;
  909. }
  910. if (res.fi->fib_nhs > 1 && fl.oif == 0)
  911. dn_fib_select_multipath(&fl, &res);
  912. /*
  913. * We could add some logic to deal with default routes here and
  914. * get rid of some of the special casing above.
  915. */
  916. if (!fl.fld_src)
  917. fl.fld_src = DN_FIB_RES_PREFSRC(res);
  918. if (dev_out)
  919. dev_put(dev_out);
  920. dev_out = DN_FIB_RES_DEV(res);
  921. dev_hold(dev_out);
  922. fl.oif = dev_out->ifindex;
  923. gateway = DN_FIB_RES_GW(res);
  924. make_route:
  925. if (dev_out->flags & IFF_LOOPBACK)
  926. flags |= RTCF_LOCAL;
  927. rt = dst_alloc(&dn_dst_ops);
  928. if (rt == NULL)
  929. goto e_nobufs;
  930. atomic_set(&rt->u.dst.__refcnt, 1);
  931. rt->u.dst.flags = DST_HOST;
  932. rt->fl.fld_src = oldflp->fld_src;
  933. rt->fl.fld_dst = oldflp->fld_dst;
  934. rt->fl.oif = oldflp->oif;
  935. rt->fl.iif = 0;
  936. rt->fl.mark = oldflp->mark;
  937. rt->rt_saddr = fl.fld_src;
  938. rt->rt_daddr = fl.fld_dst;
  939. rt->rt_gateway = gateway ? gateway : fl.fld_dst;
  940. rt->rt_local_src = fl.fld_src;
  941. rt->rt_dst_map = fl.fld_dst;
  942. rt->rt_src_map = fl.fld_src;
  943. rt->u.dst.dev = dev_out;
  944. dev_hold(dev_out);
  945. rt->u.dst.neighbour = neigh;
  946. neigh = NULL;
  947. rt->u.dst.lastuse = jiffies;
  948. rt->u.dst.output = dn_output;
  949. rt->u.dst.input = dn_rt_bug;
  950. rt->rt_flags = flags;
  951. if (flags & RTCF_LOCAL)
  952. rt->u.dst.input = dn_nsp_rx;
  953. err = dn_rt_set_next_hop(rt, &res);
  954. if (err)
  955. goto e_neighbour;
  956. hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
  957. dn_insert_route(rt, hash, (struct dn_route **)pprt);
  958. done:
  959. if (neigh)
  960. neigh_release(neigh);
  961. if (free_res)
  962. dn_fib_res_put(&res);
  963. if (dev_out)
  964. dev_put(dev_out);
  965. out:
  966. return err;
  967. e_addr:
  968. err = -EADDRNOTAVAIL;
  969. goto done;
  970. e_inval:
  971. err = -EINVAL;
  972. goto done;
  973. e_nobufs:
  974. err = -ENOBUFS;
  975. goto done;
  976. e_neighbour:
  977. dst_free(&rt->u.dst);
  978. goto e_nobufs;
  979. }
  980. /*
  981. * N.B. The flags may be moved into the flowi at some future stage.
  982. */
  983. static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *flp, int flags)
  984. {
  985. unsigned hash = dn_hash(flp->fld_src, flp->fld_dst);
  986. struct dn_route *rt = NULL;
  987. if (!(flags & MSG_TRYHARD)) {
  988. rcu_read_lock_bh();
  989. for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt;
  990. rt = rcu_dereference(rt->u.dst.dn_next)) {
  991. if ((flp->fld_dst == rt->fl.fld_dst) &&
  992. (flp->fld_src == rt->fl.fld_src) &&
  993. (flp->mark == rt->fl.mark) &&
  994. (rt->fl.iif == 0) &&
  995. (rt->fl.oif == flp->oif)) {
  996. rt->u.dst.lastuse = jiffies;
  997. dst_hold(&rt->u.dst);
  998. rt->u.dst.__use++;
  999. rcu_read_unlock_bh();
  1000. *pprt = &rt->u.dst;
  1001. return 0;
  1002. }
  1003. }
  1004. rcu_read_unlock_bh();
  1005. }
  1006. return dn_route_output_slow(pprt, flp, flags);
  1007. }
  1008. static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int flags)
  1009. {
  1010. int err;
  1011. err = __dn_route_output_key(pprt, flp, flags);
  1012. if (err == 0 && flp->proto) {
  1013. err = xfrm_lookup(pprt, flp, NULL, 0);
  1014. }
  1015. return err;
  1016. }
  1017. int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock *sk, int flags)
  1018. {
  1019. int err;
  1020. err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
  1021. if (err == 0 && fl->proto) {
  1022. err = xfrm_lookup(pprt, fl, sk, !(flags & MSG_DONTWAIT));
  1023. }
  1024. return err;
  1025. }
  1026. static int dn_route_input_slow(struct sk_buff *skb)
  1027. {
  1028. struct dn_route *rt = NULL;
  1029. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  1030. struct net_device *in_dev = skb->dev;
  1031. struct net_device *out_dev = NULL;
  1032. struct dn_dev *dn_db;
  1033. struct neighbour *neigh = NULL;
  1034. unsigned hash;
  1035. int flags = 0;
  1036. __le16 gateway = 0;
  1037. __le16 local_src = 0;
  1038. struct flowi fl = { .nl_u = { .dn_u =
  1039. { .daddr = cb->dst,
  1040. .saddr = cb->src,
  1041. .scope = RT_SCOPE_UNIVERSE,
  1042. } },
  1043. .mark = skb->mark,
  1044. .iif = skb->dev->ifindex };
  1045. struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
  1046. int err = -EINVAL;
  1047. int free_res = 0;
  1048. dev_hold(in_dev);
  1049. if ((dn_db = in_dev->dn_ptr) == NULL)
  1050. goto out;
  1051. /* Zero source addresses are not allowed */
  1052. if (fl.fld_src == 0)
  1053. goto out;
  1054. /*
  1055. * In this case we've just received a packet from a source
  1056. * outside ourselves pretending to come from us. We don't
  1057. * allow it any further to prevent routing loops, spoofing and
  1058. * other nasties. Loopback packets already have the dst attached
  1059. * so this only affects packets which have originated elsewhere.
  1060. */
  1061. err = -ENOTUNIQ;
  1062. if (dn_dev_islocal(in_dev, cb->src))
  1063. goto out;
  1064. err = dn_fib_lookup(&fl, &res);
  1065. if (err) {
  1066. if (err != -ESRCH)
  1067. goto out;
  1068. /*
  1069. * Is the destination us ?
  1070. */
  1071. if (!dn_dev_islocal(in_dev, cb->dst))
  1072. goto e_inval;
  1073. res.type = RTN_LOCAL;
  1074. } else {
  1075. __le16 src_map = fl.fld_src;
  1076. free_res = 1;
  1077. out_dev = DN_FIB_RES_DEV(res);
  1078. if (out_dev == NULL) {
  1079. if (net_ratelimit())
  1080. printk(KERN_CRIT "Bug in dn_route_input_slow() "
  1081. "No output device\n");
  1082. goto e_inval;
  1083. }
  1084. dev_hold(out_dev);
  1085. if (res.r)
  1086. src_map = fl.fld_src; /* no NAT support for now */
  1087. gateway = DN_FIB_RES_GW(res);
  1088. if (res.type == RTN_NAT) {
  1089. fl.fld_dst = dn_fib_rules_map_destination(fl.fld_dst, &res);
  1090. dn_fib_res_put(&res);
  1091. free_res = 0;
  1092. if (dn_fib_lookup(&fl, &res))
  1093. goto e_inval;
  1094. free_res = 1;
  1095. if (res.type != RTN_UNICAST)
  1096. goto e_inval;
  1097. flags |= RTCF_DNAT;
  1098. gateway = fl.fld_dst;
  1099. }
  1100. fl.fld_src = src_map;
  1101. }
  1102. switch(res.type) {
  1103. case RTN_UNICAST:
  1104. /*
  1105. * Forwarding check here, we only check for forwarding
  1106. * being turned off, if you want to only forward intra
  1107. * area, its up to you to set the routing tables up
  1108. * correctly.
  1109. */
  1110. if (dn_db->parms.forwarding == 0)
  1111. goto e_inval;
  1112. if (res.fi->fib_nhs > 1 && fl.oif == 0)
  1113. dn_fib_select_multipath(&fl, &res);
  1114. /*
  1115. * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
  1116. * flag as a hint to set the intra-ethernet bit when
  1117. * forwarding. If we've got NAT in operation, we don't do
  1118. * this optimisation.
  1119. */
  1120. if (out_dev == in_dev && !(flags & RTCF_NAT))
  1121. flags |= RTCF_DOREDIRECT;
  1122. local_src = DN_FIB_RES_PREFSRC(res);
  1123. case RTN_BLACKHOLE:
  1124. case RTN_UNREACHABLE:
  1125. break;
  1126. case RTN_LOCAL:
  1127. flags |= RTCF_LOCAL;
  1128. fl.fld_src = cb->dst;
  1129. fl.fld_dst = cb->src;
  1130. /* Routing tables gave us a gateway */
  1131. if (gateway)
  1132. goto make_route;
  1133. /* Packet was intra-ethernet, so we know its on-link */
  1134. if (cb->rt_flags & DN_RT_F_IE) {
  1135. gateway = cb->src;
  1136. flags |= RTCF_DIRECTSRC;
  1137. goto make_route;
  1138. }
  1139. /* Use the default router if there is one */
  1140. neigh = neigh_clone(dn_db->router);
  1141. if (neigh) {
  1142. gateway = ((struct dn_neigh *)neigh)->addr;
  1143. goto make_route;
  1144. }
  1145. /* Close eyes and pray */
  1146. gateway = cb->src;
  1147. flags |= RTCF_DIRECTSRC;
  1148. goto make_route;
  1149. default:
  1150. goto e_inval;
  1151. }
  1152. make_route:
  1153. rt = dst_alloc(&dn_dst_ops);
  1154. if (rt == NULL)
  1155. goto e_nobufs;
  1156. rt->rt_saddr = fl.fld_src;
  1157. rt->rt_daddr = fl.fld_dst;
  1158. rt->rt_gateway = fl.fld_dst;
  1159. if (gateway)
  1160. rt->rt_gateway = gateway;
  1161. rt->rt_local_src = local_src ? local_src : rt->rt_saddr;
  1162. rt->rt_dst_map = fl.fld_dst;
  1163. rt->rt_src_map = fl.fld_src;
  1164. rt->fl.fld_src = cb->src;
  1165. rt->fl.fld_dst = cb->dst;
  1166. rt->fl.oif = 0;
  1167. rt->fl.iif = in_dev->ifindex;
  1168. rt->fl.mark = fl.mark;
  1169. rt->u.dst.flags = DST_HOST;
  1170. rt->u.dst.neighbour = neigh;
  1171. rt->u.dst.dev = out_dev;
  1172. rt->u.dst.lastuse = jiffies;
  1173. rt->u.dst.output = dn_rt_bug;
  1174. switch(res.type) {
  1175. case RTN_UNICAST:
  1176. rt->u.dst.input = dn_forward;
  1177. break;
  1178. case RTN_LOCAL:
  1179. rt->u.dst.output = dn_output;
  1180. rt->u.dst.input = dn_nsp_rx;
  1181. rt->u.dst.dev = in_dev;
  1182. flags |= RTCF_LOCAL;
  1183. break;
  1184. default:
  1185. case RTN_UNREACHABLE:
  1186. case RTN_BLACKHOLE:
  1187. rt->u.dst.input = dn_blackhole;
  1188. }
  1189. rt->rt_flags = flags;
  1190. if (rt->u.dst.dev)
  1191. dev_hold(rt->u.dst.dev);
  1192. err = dn_rt_set_next_hop(rt, &res);
  1193. if (err)
  1194. goto e_neighbour;
  1195. hash = dn_hash(rt->fl.fld_src, rt->fl.fld_dst);
  1196. dn_insert_route(rt, hash, (struct dn_route **)&skb->dst);
  1197. done:
  1198. if (neigh)
  1199. neigh_release(neigh);
  1200. if (free_res)
  1201. dn_fib_res_put(&res);
  1202. dev_put(in_dev);
  1203. if (out_dev)
  1204. dev_put(out_dev);
  1205. out:
  1206. return err;
  1207. e_inval:
  1208. err = -EINVAL;
  1209. goto done;
  1210. e_nobufs:
  1211. err = -ENOBUFS;
  1212. goto done;
  1213. e_neighbour:
  1214. dst_free(&rt->u.dst);
  1215. goto done;
  1216. }
  1217. int dn_route_input(struct sk_buff *skb)
  1218. {
  1219. struct dn_route *rt;
  1220. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  1221. unsigned hash = dn_hash(cb->src, cb->dst);
  1222. if (skb->dst)
  1223. return 0;
  1224. rcu_read_lock();
  1225. for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt != NULL;
  1226. rt = rcu_dereference(rt->u.dst.dn_next)) {
  1227. if ((rt->fl.fld_src == cb->src) &&
  1228. (rt->fl.fld_dst == cb->dst) &&
  1229. (rt->fl.oif == 0) &&
  1230. (rt->fl.mark == skb->mark) &&
  1231. (rt->fl.iif == cb->iif)) {
  1232. rt->u.dst.lastuse = jiffies;
  1233. dst_hold(&rt->u.dst);
  1234. rt->u.dst.__use++;
  1235. rcu_read_unlock();
  1236. skb->dst = (struct dst_entry *)rt;
  1237. return 0;
  1238. }
  1239. }
  1240. rcu_read_unlock();
  1241. return dn_route_input_slow(skb);
  1242. }
  1243. static int dn_rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
  1244. int event, int nowait, unsigned int flags)
  1245. {
  1246. struct dn_route *rt = (struct dn_route *)skb->dst;
  1247. struct rtmsg *r;
  1248. struct nlmsghdr *nlh;
  1249. unsigned char *b = skb->tail;
  1250. long expires;
  1251. nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
  1252. r = NLMSG_DATA(nlh);
  1253. r->rtm_family = AF_DECnet;
  1254. r->rtm_dst_len = 16;
  1255. r->rtm_src_len = 0;
  1256. r->rtm_tos = 0;
  1257. r->rtm_table = RT_TABLE_MAIN;
  1258. RTA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
  1259. r->rtm_type = rt->rt_type;
  1260. r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
  1261. r->rtm_scope = RT_SCOPE_UNIVERSE;
  1262. r->rtm_protocol = RTPROT_UNSPEC;
  1263. if (rt->rt_flags & RTCF_NOTIFY)
  1264. r->rtm_flags |= RTM_F_NOTIFY;
  1265. RTA_PUT(skb, RTA_DST, 2, &rt->rt_daddr);
  1266. if (rt->fl.fld_src) {
  1267. r->rtm_src_len = 16;
  1268. RTA_PUT(skb, RTA_SRC, 2, &rt->fl.fld_src);
  1269. }
  1270. if (rt->u.dst.dev)
  1271. RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->u.dst.dev->ifindex);
  1272. /*
  1273. * Note to self - change this if input routes reverse direction when
  1274. * they deal only with inputs and not with replies like they do
  1275. * currently.
  1276. */
  1277. RTA_PUT(skb, RTA_PREFSRC, 2, &rt->rt_local_src);
  1278. if (rt->rt_daddr != rt->rt_gateway)
  1279. RTA_PUT(skb, RTA_GATEWAY, 2, &rt->rt_gateway);
  1280. if (rtnetlink_put_metrics(skb, rt->u.dst.metrics) < 0)
  1281. goto rtattr_failure;
  1282. expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies : 0;
  1283. if (rtnl_put_cacheinfo(skb, &rt->u.dst, 0, 0, 0, expires,
  1284. rt->u.dst.error) < 0)
  1285. goto rtattr_failure;
  1286. if (rt->fl.iif)
  1287. RTA_PUT(skb, RTA_IIF, sizeof(int), &rt->fl.iif);
  1288. nlh->nlmsg_len = skb->tail - b;
  1289. return skb->len;
  1290. nlmsg_failure:
  1291. rtattr_failure:
  1292. skb_trim(skb, b - skb->data);
  1293. return -1;
  1294. }
  1295. /*
  1296. * This is called by both endnodes and routers now.
  1297. */
  1298. int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
  1299. {
  1300. struct rtattr **rta = arg;
  1301. struct rtmsg *rtm = NLMSG_DATA(nlh);
  1302. struct dn_route *rt = NULL;
  1303. struct dn_skb_cb *cb;
  1304. int err;
  1305. struct sk_buff *skb;
  1306. struct flowi fl;
  1307. memset(&fl, 0, sizeof(fl));
  1308. fl.proto = DNPROTO_NSP;
  1309. skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
  1310. if (skb == NULL)
  1311. return -ENOBUFS;
  1312. skb->mac.raw = skb->data;
  1313. cb = DN_SKB_CB(skb);
  1314. if (rta[RTA_SRC-1])
  1315. memcpy(&fl.fld_src, RTA_DATA(rta[RTA_SRC-1]), 2);
  1316. if (rta[RTA_DST-1])
  1317. memcpy(&fl.fld_dst, RTA_DATA(rta[RTA_DST-1]), 2);
  1318. if (rta[RTA_IIF-1])
  1319. memcpy(&fl.iif, RTA_DATA(rta[RTA_IIF-1]), sizeof(int));
  1320. if (fl.iif) {
  1321. struct net_device *dev;
  1322. if ((dev = dev_get_by_index(fl.iif)) == NULL) {
  1323. kfree_skb(skb);
  1324. return -ENODEV;
  1325. }
  1326. if (!dev->dn_ptr) {
  1327. dev_put(dev);
  1328. kfree_skb(skb);
  1329. return -ENODEV;
  1330. }
  1331. skb->protocol = __constant_htons(ETH_P_DNA_RT);
  1332. skb->dev = dev;
  1333. cb->src = fl.fld_src;
  1334. cb->dst = fl.fld_dst;
  1335. local_bh_disable();
  1336. err = dn_route_input(skb);
  1337. local_bh_enable();
  1338. memset(cb, 0, sizeof(struct dn_skb_cb));
  1339. rt = (struct dn_route *)skb->dst;
  1340. if (!err && -rt->u.dst.error)
  1341. err = rt->u.dst.error;
  1342. } else {
  1343. int oif = 0;
  1344. if (rta[RTA_OIF - 1])
  1345. memcpy(&oif, RTA_DATA(rta[RTA_OIF - 1]), sizeof(int));
  1346. fl.oif = oif;
  1347. err = dn_route_output_key((struct dst_entry **)&rt, &fl, 0);
  1348. }
  1349. if (skb->dev)
  1350. dev_put(skb->dev);
  1351. skb->dev = NULL;
  1352. if (err)
  1353. goto out_free;
  1354. skb->dst = &rt->u.dst;
  1355. if (rtm->rtm_flags & RTM_F_NOTIFY)
  1356. rt->rt_flags |= RTCF_NOTIFY;
  1357. err = dn_rt_fill_info(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq, RTM_NEWROUTE, 0, 0);
  1358. if (err == 0)
  1359. goto out_free;
  1360. if (err < 0) {
  1361. err = -EMSGSIZE;
  1362. goto out_free;
  1363. }
  1364. return rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
  1365. out_free:
  1366. kfree_skb(skb);
  1367. return err;
  1368. }
  1369. /*
  1370. * For routers, this is called from dn_fib_dump, but for endnodes its
  1371. * called directly from the rtnetlink dispatch table.
  1372. */
  1373. int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
  1374. {
  1375. struct dn_route *rt;
  1376. int h, s_h;
  1377. int idx, s_idx;
  1378. if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
  1379. return -EINVAL;
  1380. if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
  1381. return 0;
  1382. s_h = cb->args[0];
  1383. s_idx = idx = cb->args[1];
  1384. for(h = 0; h <= dn_rt_hash_mask; h++) {
  1385. if (h < s_h)
  1386. continue;
  1387. if (h > s_h)
  1388. s_idx = 0;
  1389. rcu_read_lock_bh();
  1390. for(rt = rcu_dereference(dn_rt_hash_table[h].chain), idx = 0;
  1391. rt;
  1392. rt = rcu_dereference(rt->u.dst.dn_next), idx++) {
  1393. if (idx < s_idx)
  1394. continue;
  1395. skb->dst = dst_clone(&rt->u.dst);
  1396. if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
  1397. cb->nlh->nlmsg_seq, RTM_NEWROUTE,
  1398. 1, NLM_F_MULTI) <= 0) {
  1399. dst_release(xchg(&skb->dst, NULL));
  1400. rcu_read_unlock_bh();
  1401. goto done;
  1402. }
  1403. dst_release(xchg(&skb->dst, NULL));
  1404. }
  1405. rcu_read_unlock_bh();
  1406. }
  1407. done:
  1408. cb->args[0] = h;
  1409. cb->args[1] = idx;
  1410. return skb->len;
  1411. }
  1412. #ifdef CONFIG_PROC_FS
  1413. struct dn_rt_cache_iter_state {
  1414. int bucket;
  1415. };
  1416. static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
  1417. {
  1418. struct dn_route *rt = NULL;
  1419. struct dn_rt_cache_iter_state *s = seq->private;
  1420. for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
  1421. rcu_read_lock_bh();
  1422. rt = dn_rt_hash_table[s->bucket].chain;
  1423. if (rt)
  1424. break;
  1425. rcu_read_unlock_bh();
  1426. }
  1427. return rt;
  1428. }
  1429. static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
  1430. {
  1431. struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);
  1432. rt = rt->u.dst.dn_next;
  1433. while(!rt) {
  1434. rcu_read_unlock_bh();
  1435. if (--s->bucket < 0)
  1436. break;
  1437. rcu_read_lock_bh();
  1438. rt = dn_rt_hash_table[s->bucket].chain;
  1439. }
  1440. return rt;
  1441. }
  1442. static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
  1443. {
  1444. struct dn_route *rt = dn_rt_cache_get_first(seq);
  1445. if (rt) {
  1446. while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
  1447. --*pos;
  1448. }
  1449. return *pos ? NULL : rt;
  1450. }
  1451. static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1452. {
  1453. struct dn_route *rt = dn_rt_cache_get_next(seq, v);
  1454. ++*pos;
  1455. return rt;
  1456. }
  1457. static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
  1458. {
  1459. if (v)
  1460. rcu_read_unlock_bh();
  1461. }
  1462. static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
  1463. {
  1464. struct dn_route *rt = v;
  1465. char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
  1466. seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
  1467. rt->u.dst.dev ? rt->u.dst.dev->name : "*",
  1468. dn_addr2asc(dn_ntohs(rt->rt_daddr), buf1),
  1469. dn_addr2asc(dn_ntohs(rt->rt_saddr), buf2),
  1470. atomic_read(&rt->u.dst.__refcnt),
  1471. rt->u.dst.__use,
  1472. (int) dst_metric(&rt->u.dst, RTAX_RTT));
  1473. return 0;
  1474. }
  1475. static struct seq_operations dn_rt_cache_seq_ops = {
  1476. .start = dn_rt_cache_seq_start,
  1477. .next = dn_rt_cache_seq_next,
  1478. .stop = dn_rt_cache_seq_stop,
  1479. .show = dn_rt_cache_seq_show,
  1480. };
  1481. static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
  1482. {
  1483. struct seq_file *seq;
  1484. int rc = -ENOMEM;
  1485. struct dn_rt_cache_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
  1486. if (!s)
  1487. goto out;
  1488. rc = seq_open(file, &dn_rt_cache_seq_ops);
  1489. if (rc)
  1490. goto out_kfree;
  1491. seq = file->private_data;
  1492. seq->private = s;
  1493. memset(s, 0, sizeof(*s));
  1494. out:
  1495. return rc;
  1496. out_kfree:
  1497. kfree(s);
  1498. goto out;
  1499. }
  1500. static const struct file_operations dn_rt_cache_seq_fops = {
  1501. .owner = THIS_MODULE,
  1502. .open = dn_rt_cache_seq_open,
  1503. .read = seq_read,
  1504. .llseek = seq_lseek,
  1505. .release = seq_release_private,
  1506. };
  1507. #endif /* CONFIG_PROC_FS */
  1508. void __init dn_route_init(void)
  1509. {
  1510. int i, goal, order;
  1511. dn_dst_ops.kmem_cachep =
  1512. kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
  1513. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1514. init_timer(&dn_route_timer);
  1515. dn_route_timer.function = dn_dst_check_expire;
  1516. dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
  1517. add_timer(&dn_route_timer);
  1518. goal = num_physpages >> (26 - PAGE_SHIFT);
  1519. for(order = 0; (1UL << order) < goal; order++)
  1520. /* NOTHING */;
  1521. /*
  1522. * Only want 1024 entries max, since the table is very, very unlikely
  1523. * to be larger than that.
  1524. */
  1525. while(order && ((((1UL << order) * PAGE_SIZE) /
  1526. sizeof(struct dn_rt_hash_bucket)) >= 2048))
  1527. order--;
  1528. do {
  1529. dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
  1530. sizeof(struct dn_rt_hash_bucket);
  1531. while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
  1532. dn_rt_hash_mask--;
  1533. dn_rt_hash_table = (struct dn_rt_hash_bucket *)
  1534. __get_free_pages(GFP_ATOMIC, order);
  1535. } while (dn_rt_hash_table == NULL && --order > 0);
  1536. if (!dn_rt_hash_table)
  1537. panic("Failed to allocate DECnet route cache hash table\n");
  1538. printk(KERN_INFO
  1539. "DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
  1540. dn_rt_hash_mask,
  1541. (long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
  1542. dn_rt_hash_mask--;
  1543. for(i = 0; i <= dn_rt_hash_mask; i++) {
  1544. spin_lock_init(&dn_rt_hash_table[i].lock);
  1545. dn_rt_hash_table[i].chain = NULL;
  1546. }
  1547. dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
  1548. proc_net_fops_create("decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
  1549. }
  1550. void __exit dn_route_cleanup(void)
  1551. {
  1552. del_timer(&dn_route_timer);
  1553. dn_run_flush(0);
  1554. proc_net_remove("decnet_cache");
  1555. }