dn_route.c 44 KB

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