dn_route.c 45 KB

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