ddp.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. /*
  2. * DDP: An implementation of the AppleTalk DDP protocol for
  3. * Ethernet 'ELAP'.
  4. *
  5. * Alan Cox <Alan.Cox@linux.org>
  6. *
  7. * With more than a little assistance from
  8. *
  9. * Wesley Craig <netatalk@umich.edu>
  10. *
  11. * Fixes:
  12. * Neil Horman : Added missing device ioctls
  13. * Michael Callahan : Made routing work
  14. * Wesley Craig : Fix probing to listen to a
  15. * passed node id.
  16. * Alan Cox : Added send/recvmsg support
  17. * Alan Cox : Moved at. to protinfo in
  18. * socket.
  19. * Alan Cox : Added firewall hooks.
  20. * Alan Cox : Supports new ARPHRD_LOOPBACK
  21. * Christer Weinigel : Routing and /proc fixes.
  22. * Bradford Johnson : LocalTalk.
  23. * Tom Dyas : Module support.
  24. * Alan Cox : Hooks for PPP (based on the
  25. * LocalTalk hook).
  26. * Alan Cox : Posix bits
  27. * Alan Cox/Mike Freeman : Possible fix to NBP problems
  28. * Bradford Johnson : IP-over-DDP (experimental)
  29. * Jay Schulist : Moved IP-over-DDP to its own
  30. * driver file. (ipddp.c & ipddp.h)
  31. * Jay Schulist : Made work as module with
  32. * AppleTalk drivers, cleaned it.
  33. * Rob Newberry : Added proxy AARP and AARP
  34. * procfs, moved probing to AARP
  35. * module.
  36. * Adrian Sun/
  37. * Michael Zuelsdorff : fix for net.0 packets. don't
  38. * allow illegal ether/tokentalk
  39. * port assignment. we lose a
  40. * valid localtalk port as a
  41. * result.
  42. * Arnaldo C. de Melo : Cleanup, in preparation for
  43. * shared skb support 8)
  44. * Arnaldo C. de Melo : Move proc stuff to atalk_proc.c,
  45. * use seq_file
  46. *
  47. * This program is free software; you can redistribute it and/or
  48. * modify it under the terms of the GNU General Public License
  49. * as published by the Free Software Foundation; either version
  50. * 2 of the License, or (at your option) any later version.
  51. *
  52. */
  53. #include <linux/capability.h>
  54. #include <linux/module.h>
  55. #include <linux/if_arp.h>
  56. #include <linux/termios.h> /* For TIOCOUTQ/INQ */
  57. #include <net/datalink.h>
  58. #include <net/psnap.h>
  59. #include <net/sock.h>
  60. #include <net/tcp_states.h>
  61. #include <net/route.h>
  62. #include <linux/atalk.h>
  63. #include "../core/kmap_skb.h"
  64. struct datalink_proto *ddp_dl, *aarp_dl;
  65. static const struct proto_ops atalk_dgram_ops;
  66. /**************************************************************************\
  67. * *
  68. * Handlers for the socket list. *
  69. * *
  70. \**************************************************************************/
  71. HLIST_HEAD(atalk_sockets);
  72. DEFINE_RWLOCK(atalk_sockets_lock);
  73. static inline void __atalk_insert_socket(struct sock *sk)
  74. {
  75. sk_add_node(sk, &atalk_sockets);
  76. }
  77. static inline void atalk_remove_socket(struct sock *sk)
  78. {
  79. write_lock_bh(&atalk_sockets_lock);
  80. sk_del_node_init(sk);
  81. write_unlock_bh(&atalk_sockets_lock);
  82. }
  83. static struct sock *atalk_search_socket(struct sockaddr_at *to,
  84. struct atalk_iface *atif)
  85. {
  86. struct sock *s;
  87. struct hlist_node *node;
  88. read_lock_bh(&atalk_sockets_lock);
  89. sk_for_each(s, node, &atalk_sockets) {
  90. struct atalk_sock *at = at_sk(s);
  91. if (to->sat_port != at->src_port)
  92. continue;
  93. if (to->sat_addr.s_net == ATADDR_ANYNET &&
  94. to->sat_addr.s_node == ATADDR_BCAST)
  95. goto found;
  96. if (to->sat_addr.s_net == at->src_net &&
  97. (to->sat_addr.s_node == at->src_node ||
  98. to->sat_addr.s_node == ATADDR_BCAST ||
  99. to->sat_addr.s_node == ATADDR_ANYNODE))
  100. goto found;
  101. /* XXXX.0 -- we got a request for this router. make sure
  102. * that the node is appropriately set. */
  103. if (to->sat_addr.s_node == ATADDR_ANYNODE &&
  104. to->sat_addr.s_net != ATADDR_ANYNET &&
  105. atif->address.s_node == at->src_node) {
  106. to->sat_addr.s_node = atif->address.s_node;
  107. goto found;
  108. }
  109. }
  110. s = NULL;
  111. found:
  112. read_unlock_bh(&atalk_sockets_lock);
  113. return s;
  114. }
  115. /**
  116. * atalk_find_or_insert_socket - Try to find a socket matching ADDR
  117. * @sk - socket to insert in the list if it is not there already
  118. * @sat - address to search for
  119. *
  120. * Try to find a socket matching ADDR in the socket list, if found then return
  121. * it. If not, insert SK into the socket list.
  122. *
  123. * This entire operation must execute atomically.
  124. */
  125. static struct sock *atalk_find_or_insert_socket(struct sock *sk,
  126. struct sockaddr_at *sat)
  127. {
  128. struct sock *s;
  129. struct hlist_node *node;
  130. struct atalk_sock *at;
  131. write_lock_bh(&atalk_sockets_lock);
  132. sk_for_each(s, node, &atalk_sockets) {
  133. at = at_sk(s);
  134. if (at->src_net == sat->sat_addr.s_net &&
  135. at->src_node == sat->sat_addr.s_node &&
  136. at->src_port == sat->sat_port)
  137. goto found;
  138. }
  139. s = NULL;
  140. __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
  141. found:
  142. write_unlock_bh(&atalk_sockets_lock);
  143. return s;
  144. }
  145. static void atalk_destroy_timer(unsigned long data)
  146. {
  147. struct sock *sk = (struct sock *)data;
  148. if (atomic_read(&sk->sk_wmem_alloc) ||
  149. atomic_read(&sk->sk_rmem_alloc)) {
  150. sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
  151. add_timer(&sk->sk_timer);
  152. } else
  153. sock_put(sk);
  154. }
  155. static inline void atalk_destroy_socket(struct sock *sk)
  156. {
  157. atalk_remove_socket(sk);
  158. skb_queue_purge(&sk->sk_receive_queue);
  159. if (atomic_read(&sk->sk_wmem_alloc) ||
  160. atomic_read(&sk->sk_rmem_alloc)) {
  161. init_timer(&sk->sk_timer);
  162. sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
  163. sk->sk_timer.function = atalk_destroy_timer;
  164. sk->sk_timer.data = (unsigned long)sk;
  165. add_timer(&sk->sk_timer);
  166. } else
  167. sock_put(sk);
  168. }
  169. /**************************************************************************\
  170. * *
  171. * Routing tables for the AppleTalk socket layer. *
  172. * *
  173. \**************************************************************************/
  174. /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
  175. struct atalk_route *atalk_routes;
  176. DEFINE_RWLOCK(atalk_routes_lock);
  177. struct atalk_iface *atalk_interfaces;
  178. DEFINE_RWLOCK(atalk_interfaces_lock);
  179. /* For probing devices or in a routerless network */
  180. struct atalk_route atrtr_default;
  181. /* AppleTalk interface control */
  182. /*
  183. * Drop a device. Doesn't drop any of its routes - that is the caller's
  184. * problem. Called when we down the interface or delete the address.
  185. */
  186. static void atif_drop_device(struct net_device *dev)
  187. {
  188. struct atalk_iface **iface = &atalk_interfaces;
  189. struct atalk_iface *tmp;
  190. write_lock_bh(&atalk_interfaces_lock);
  191. while ((tmp = *iface) != NULL) {
  192. if (tmp->dev == dev) {
  193. *iface = tmp->next;
  194. dev_put(dev);
  195. kfree(tmp);
  196. dev->atalk_ptr = NULL;
  197. } else
  198. iface = &tmp->next;
  199. }
  200. write_unlock_bh(&atalk_interfaces_lock);
  201. }
  202. static struct atalk_iface *atif_add_device(struct net_device *dev,
  203. struct atalk_addr *sa)
  204. {
  205. struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);
  206. if (!iface)
  207. goto out;
  208. dev_hold(dev);
  209. iface->dev = dev;
  210. dev->atalk_ptr = iface;
  211. iface->address = *sa;
  212. iface->status = 0;
  213. write_lock_bh(&atalk_interfaces_lock);
  214. iface->next = atalk_interfaces;
  215. atalk_interfaces = iface;
  216. write_unlock_bh(&atalk_interfaces_lock);
  217. out:
  218. return iface;
  219. }
  220. /* Perform phase 2 AARP probing on our tentative address */
  221. static int atif_probe_device(struct atalk_iface *atif)
  222. {
  223. int netrange = ntohs(atif->nets.nr_lastnet) -
  224. ntohs(atif->nets.nr_firstnet) + 1;
  225. int probe_net = ntohs(atif->address.s_net);
  226. int probe_node = atif->address.s_node;
  227. int netct, nodect;
  228. /* Offset the network we start probing with */
  229. if (probe_net == ATADDR_ANYNET) {
  230. probe_net = ntohs(atif->nets.nr_firstnet);
  231. if (netrange)
  232. probe_net += jiffies % netrange;
  233. }
  234. if (probe_node == ATADDR_ANYNODE)
  235. probe_node = jiffies & 0xFF;
  236. /* Scan the networks */
  237. atif->status |= ATIF_PROBE;
  238. for (netct = 0; netct <= netrange; netct++) {
  239. /* Sweep the available nodes from a given start */
  240. atif->address.s_net = htons(probe_net);
  241. for (nodect = 0; nodect < 256; nodect++) {
  242. atif->address.s_node = (nodect + probe_node) & 0xFF;
  243. if (atif->address.s_node > 0 &&
  244. atif->address.s_node < 254) {
  245. /* Probe a proposed address */
  246. aarp_probe_network(atif);
  247. if (!(atif->status & ATIF_PROBE_FAIL)) {
  248. atif->status &= ~ATIF_PROBE;
  249. return 0;
  250. }
  251. }
  252. atif->status &= ~ATIF_PROBE_FAIL;
  253. }
  254. probe_net++;
  255. if (probe_net > ntohs(atif->nets.nr_lastnet))
  256. probe_net = ntohs(atif->nets.nr_firstnet);
  257. }
  258. atif->status &= ~ATIF_PROBE;
  259. return -EADDRINUSE; /* Network is full... */
  260. }
  261. /* Perform AARP probing for a proxy address */
  262. static int atif_proxy_probe_device(struct atalk_iface *atif,
  263. struct atalk_addr* proxy_addr)
  264. {
  265. int netrange = ntohs(atif->nets.nr_lastnet) -
  266. ntohs(atif->nets.nr_firstnet) + 1;
  267. /* we probe the interface's network */
  268. int probe_net = ntohs(atif->address.s_net);
  269. int probe_node = ATADDR_ANYNODE; /* we'll take anything */
  270. int netct, nodect;
  271. /* Offset the network we start probing with */
  272. if (probe_net == ATADDR_ANYNET) {
  273. probe_net = ntohs(atif->nets.nr_firstnet);
  274. if (netrange)
  275. probe_net += jiffies % netrange;
  276. }
  277. if (probe_node == ATADDR_ANYNODE)
  278. probe_node = jiffies & 0xFF;
  279. /* Scan the networks */
  280. for (netct = 0; netct <= netrange; netct++) {
  281. /* Sweep the available nodes from a given start */
  282. proxy_addr->s_net = htons(probe_net);
  283. for (nodect = 0; nodect < 256; nodect++) {
  284. proxy_addr->s_node = (nodect + probe_node) & 0xFF;
  285. if (proxy_addr->s_node > 0 &&
  286. proxy_addr->s_node < 254) {
  287. /* Tell AARP to probe a proposed address */
  288. int ret = aarp_proxy_probe_network(atif,
  289. proxy_addr);
  290. if (ret != -EADDRINUSE)
  291. return ret;
  292. }
  293. }
  294. probe_net++;
  295. if (probe_net > ntohs(atif->nets.nr_lastnet))
  296. probe_net = ntohs(atif->nets.nr_firstnet);
  297. }
  298. return -EADDRINUSE; /* Network is full... */
  299. }
  300. struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
  301. {
  302. struct atalk_iface *iface = dev->atalk_ptr;
  303. return iface ? &iface->address : NULL;
  304. }
  305. static struct atalk_addr *atalk_find_primary(void)
  306. {
  307. struct atalk_iface *fiface = NULL;
  308. struct atalk_addr *retval;
  309. struct atalk_iface *iface;
  310. /*
  311. * Return a point-to-point interface only if
  312. * there is no non-ptp interface available.
  313. */
  314. read_lock_bh(&atalk_interfaces_lock);
  315. for (iface = atalk_interfaces; iface; iface = iface->next) {
  316. if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
  317. fiface = iface;
  318. if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
  319. retval = &iface->address;
  320. goto out;
  321. }
  322. }
  323. if (fiface)
  324. retval = &fiface->address;
  325. else if (atalk_interfaces)
  326. retval = &atalk_interfaces->address;
  327. else
  328. retval = NULL;
  329. out:
  330. read_unlock_bh(&atalk_interfaces_lock);
  331. return retval;
  332. }
  333. /*
  334. * Find a match for 'any network' - ie any of our interfaces with that
  335. * node number will do just nicely.
  336. */
  337. static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
  338. {
  339. struct atalk_iface *iface = dev->atalk_ptr;
  340. if (!iface || iface->status & ATIF_PROBE)
  341. goto out_err;
  342. if (node != ATADDR_BCAST &&
  343. iface->address.s_node != node &&
  344. node != ATADDR_ANYNODE)
  345. goto out_err;
  346. out:
  347. return iface;
  348. out_err:
  349. iface = NULL;
  350. goto out;
  351. }
  352. /* Find a match for a specific network:node pair */
  353. static struct atalk_iface *atalk_find_interface(__be16 net, int node)
  354. {
  355. struct atalk_iface *iface;
  356. read_lock_bh(&atalk_interfaces_lock);
  357. for (iface = atalk_interfaces; iface; iface = iface->next) {
  358. if ((node == ATADDR_BCAST ||
  359. node == ATADDR_ANYNODE ||
  360. iface->address.s_node == node) &&
  361. iface->address.s_net == net &&
  362. !(iface->status & ATIF_PROBE))
  363. break;
  364. /* XXXX.0 -- net.0 returns the iface associated with net */
  365. if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
  366. ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
  367. ntohs(net) <= ntohs(iface->nets.nr_lastnet))
  368. break;
  369. }
  370. read_unlock_bh(&atalk_interfaces_lock);
  371. return iface;
  372. }
  373. /*
  374. * Find a route for an AppleTalk packet. This ought to get cached in
  375. * the socket (later on...). We know about host routes and the fact
  376. * that a route must be direct to broadcast.
  377. */
  378. static struct atalk_route *atrtr_find(struct atalk_addr *target)
  379. {
  380. /*
  381. * we must search through all routes unless we find a
  382. * host route, because some host routes might overlap
  383. * network routes
  384. */
  385. struct atalk_route *net_route = NULL;
  386. struct atalk_route *r;
  387. read_lock_bh(&atalk_routes_lock);
  388. for (r = atalk_routes; r; r = r->next) {
  389. if (!(r->flags & RTF_UP))
  390. continue;
  391. if (r->target.s_net == target->s_net) {
  392. if (r->flags & RTF_HOST) {
  393. /*
  394. * if this host route is for the target,
  395. * the we're done
  396. */
  397. if (r->target.s_node == target->s_node)
  398. goto out;
  399. } else
  400. /*
  401. * this route will work if there isn't a
  402. * direct host route, so cache it
  403. */
  404. net_route = r;
  405. }
  406. }
  407. /*
  408. * if we found a network route but not a direct host
  409. * route, then return it
  410. */
  411. if (net_route)
  412. r = net_route;
  413. else if (atrtr_default.dev)
  414. r = &atrtr_default;
  415. else /* No route can be found */
  416. r = NULL;
  417. out:
  418. read_unlock_bh(&atalk_routes_lock);
  419. return r;
  420. }
  421. /*
  422. * Given an AppleTalk network, find the device to use. This can be
  423. * a simple lookup.
  424. */
  425. struct net_device *atrtr_get_dev(struct atalk_addr *sa)
  426. {
  427. struct atalk_route *atr = atrtr_find(sa);
  428. return atr ? atr->dev : NULL;
  429. }
  430. /* Set up a default router */
  431. static void atrtr_set_default(struct net_device *dev)
  432. {
  433. atrtr_default.dev = dev;
  434. atrtr_default.flags = RTF_UP;
  435. atrtr_default.gateway.s_net = htons(0);
  436. atrtr_default.gateway.s_node = 0;
  437. }
  438. /*
  439. * Add a router. Basically make sure it looks valid and stuff the
  440. * entry in the list. While it uses netranges we always set them to one
  441. * entry to work like netatalk.
  442. */
  443. static int atrtr_create(struct rtentry *r, struct net_device *devhint)
  444. {
  445. struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
  446. struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
  447. struct atalk_route *rt;
  448. struct atalk_iface *iface, *riface;
  449. int retval = -EINVAL;
  450. /*
  451. * Fixme: Raise/Lower a routing change semaphore for these
  452. * operations.
  453. */
  454. /* Validate the request */
  455. if (ta->sat_family != AF_APPLETALK ||
  456. (!devhint && ga->sat_family != AF_APPLETALK))
  457. goto out;
  458. /* Now walk the routing table and make our decisions */
  459. write_lock_bh(&atalk_routes_lock);
  460. for (rt = atalk_routes; rt; rt = rt->next) {
  461. if (r->rt_flags != rt->flags)
  462. continue;
  463. if (ta->sat_addr.s_net == rt->target.s_net) {
  464. if (!(rt->flags & RTF_HOST))
  465. break;
  466. if (ta->sat_addr.s_node == rt->target.s_node)
  467. break;
  468. }
  469. }
  470. if (!devhint) {
  471. riface = NULL;
  472. read_lock_bh(&atalk_interfaces_lock);
  473. for (iface = atalk_interfaces; iface; iface = iface->next) {
  474. if (!riface &&
  475. ntohs(ga->sat_addr.s_net) >=
  476. ntohs(iface->nets.nr_firstnet) &&
  477. ntohs(ga->sat_addr.s_net) <=
  478. ntohs(iface->nets.nr_lastnet))
  479. riface = iface;
  480. if (ga->sat_addr.s_net == iface->address.s_net &&
  481. ga->sat_addr.s_node == iface->address.s_node)
  482. riface = iface;
  483. }
  484. read_unlock_bh(&atalk_interfaces_lock);
  485. retval = -ENETUNREACH;
  486. if (!riface)
  487. goto out_unlock;
  488. devhint = riface->dev;
  489. }
  490. if (!rt) {
  491. rt = kzalloc(sizeof(*rt), GFP_ATOMIC);
  492. retval = -ENOBUFS;
  493. if (!rt)
  494. goto out_unlock;
  495. rt->next = atalk_routes;
  496. atalk_routes = rt;
  497. }
  498. /* Fill in the routing entry */
  499. rt->target = ta->sat_addr;
  500. dev_hold(devhint);
  501. rt->dev = devhint;
  502. rt->flags = r->rt_flags;
  503. rt->gateway = ga->sat_addr;
  504. retval = 0;
  505. out_unlock:
  506. write_unlock_bh(&atalk_routes_lock);
  507. out:
  508. return retval;
  509. }
  510. /* Delete a route. Find it and discard it */
  511. static int atrtr_delete(struct atalk_addr * addr)
  512. {
  513. struct atalk_route **r = &atalk_routes;
  514. int retval = 0;
  515. struct atalk_route *tmp;
  516. write_lock_bh(&atalk_routes_lock);
  517. while ((tmp = *r) != NULL) {
  518. if (tmp->target.s_net == addr->s_net &&
  519. (!(tmp->flags&RTF_GATEWAY) ||
  520. tmp->target.s_node == addr->s_node)) {
  521. *r = tmp->next;
  522. dev_put(tmp->dev);
  523. kfree(tmp);
  524. goto out;
  525. }
  526. r = &tmp->next;
  527. }
  528. retval = -ENOENT;
  529. out:
  530. write_unlock_bh(&atalk_routes_lock);
  531. return retval;
  532. }
  533. /*
  534. * Called when a device is downed. Just throw away any routes
  535. * via it.
  536. */
  537. static void atrtr_device_down(struct net_device *dev)
  538. {
  539. struct atalk_route **r = &atalk_routes;
  540. struct atalk_route *tmp;
  541. write_lock_bh(&atalk_routes_lock);
  542. while ((tmp = *r) != NULL) {
  543. if (tmp->dev == dev) {
  544. *r = tmp->next;
  545. dev_put(dev);
  546. kfree(tmp);
  547. } else
  548. r = &tmp->next;
  549. }
  550. write_unlock_bh(&atalk_routes_lock);
  551. if (atrtr_default.dev == dev)
  552. atrtr_set_default(NULL);
  553. }
  554. /* Actually down the interface */
  555. static inline void atalk_dev_down(struct net_device *dev)
  556. {
  557. atrtr_device_down(dev); /* Remove all routes for the device */
  558. aarp_device_down(dev); /* Remove AARP entries for the device */
  559. atif_drop_device(dev); /* Remove the device */
  560. }
  561. /*
  562. * A device event has occurred. Watch for devices going down and
  563. * delete our use of them (iface and route).
  564. */
  565. static int ddp_device_event(struct notifier_block *this, unsigned long event,
  566. void *ptr)
  567. {
  568. if (event == NETDEV_DOWN)
  569. /* Discard any use of this */
  570. atalk_dev_down(ptr);
  571. return NOTIFY_DONE;
  572. }
  573. /* ioctl calls. Shouldn't even need touching */
  574. /* Device configuration ioctl calls */
  575. static int atif_ioctl(int cmd, void __user *arg)
  576. {
  577. static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
  578. struct ifreq atreq;
  579. struct atalk_netrange *nr;
  580. struct sockaddr_at *sa;
  581. struct net_device *dev;
  582. struct atalk_iface *atif;
  583. int ct;
  584. int limit;
  585. struct rtentry rtdef;
  586. int add_route;
  587. if (copy_from_user(&atreq, arg, sizeof(atreq)))
  588. return -EFAULT;
  589. dev = __dev_get_by_name(atreq.ifr_name);
  590. if (!dev)
  591. return -ENODEV;
  592. sa = (struct sockaddr_at *)&atreq.ifr_addr;
  593. atif = atalk_find_dev(dev);
  594. switch (cmd) {
  595. case SIOCSIFADDR:
  596. if (!capable(CAP_NET_ADMIN))
  597. return -EPERM;
  598. if (sa->sat_family != AF_APPLETALK)
  599. return -EINVAL;
  600. if (dev->type != ARPHRD_ETHER &&
  601. dev->type != ARPHRD_LOOPBACK &&
  602. dev->type != ARPHRD_LOCALTLK &&
  603. dev->type != ARPHRD_PPP)
  604. return -EPROTONOSUPPORT;
  605. nr = (struct atalk_netrange *)&sa->sat_zero[0];
  606. add_route = 1;
  607. /*
  608. * if this is a point-to-point iface, and we already
  609. * have an iface for this AppleTalk address, then we
  610. * should not add a route
  611. */
  612. if ((dev->flags & IFF_POINTOPOINT) &&
  613. atalk_find_interface(sa->sat_addr.s_net,
  614. sa->sat_addr.s_node)) {
  615. printk(KERN_DEBUG "AppleTalk: point-to-point "
  616. "interface added with "
  617. "existing address\n");
  618. add_route = 0;
  619. }
  620. /*
  621. * Phase 1 is fine on LocalTalk but we don't do
  622. * EtherTalk phase 1. Anyone wanting to add it go ahead.
  623. */
  624. if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
  625. return -EPROTONOSUPPORT;
  626. if (sa->sat_addr.s_node == ATADDR_BCAST ||
  627. sa->sat_addr.s_node == 254)
  628. return -EINVAL;
  629. if (atif) {
  630. /* Already setting address */
  631. if (atif->status & ATIF_PROBE)
  632. return -EBUSY;
  633. atif->address.s_net = sa->sat_addr.s_net;
  634. atif->address.s_node = sa->sat_addr.s_node;
  635. atrtr_device_down(dev); /* Flush old routes */
  636. } else {
  637. atif = atif_add_device(dev, &sa->sat_addr);
  638. if (!atif)
  639. return -ENOMEM;
  640. }
  641. atif->nets = *nr;
  642. /*
  643. * Check if the chosen address is used. If so we
  644. * error and atalkd will try another.
  645. */
  646. if (!(dev->flags & IFF_LOOPBACK) &&
  647. !(dev->flags & IFF_POINTOPOINT) &&
  648. atif_probe_device(atif) < 0) {
  649. atif_drop_device(dev);
  650. return -EADDRINUSE;
  651. }
  652. /* Hey it worked - add the direct routes */
  653. sa = (struct sockaddr_at *)&rtdef.rt_gateway;
  654. sa->sat_family = AF_APPLETALK;
  655. sa->sat_addr.s_net = atif->address.s_net;
  656. sa->sat_addr.s_node = atif->address.s_node;
  657. sa = (struct sockaddr_at *)&rtdef.rt_dst;
  658. rtdef.rt_flags = RTF_UP;
  659. sa->sat_family = AF_APPLETALK;
  660. sa->sat_addr.s_node = ATADDR_ANYNODE;
  661. if (dev->flags & IFF_LOOPBACK ||
  662. dev->flags & IFF_POINTOPOINT)
  663. rtdef.rt_flags |= RTF_HOST;
  664. /* Routerless initial state */
  665. if (nr->nr_firstnet == htons(0) &&
  666. nr->nr_lastnet == htons(0xFFFE)) {
  667. sa->sat_addr.s_net = atif->address.s_net;
  668. atrtr_create(&rtdef, dev);
  669. atrtr_set_default(dev);
  670. } else {
  671. limit = ntohs(nr->nr_lastnet);
  672. if (limit - ntohs(nr->nr_firstnet) > 4096) {
  673. printk(KERN_WARNING "Too many routes/"
  674. "iface.\n");
  675. return -EINVAL;
  676. }
  677. if (add_route)
  678. for (ct = ntohs(nr->nr_firstnet);
  679. ct <= limit; ct++) {
  680. sa->sat_addr.s_net = htons(ct);
  681. atrtr_create(&rtdef, dev);
  682. }
  683. }
  684. dev_mc_add(dev, aarp_mcast, 6, 1);
  685. return 0;
  686. case SIOCGIFADDR:
  687. if (!atif)
  688. return -EADDRNOTAVAIL;
  689. sa->sat_family = AF_APPLETALK;
  690. sa->sat_addr = atif->address;
  691. break;
  692. case SIOCGIFBRDADDR:
  693. if (!atif)
  694. return -EADDRNOTAVAIL;
  695. sa->sat_family = AF_APPLETALK;
  696. sa->sat_addr.s_net = atif->address.s_net;
  697. sa->sat_addr.s_node = ATADDR_BCAST;
  698. break;
  699. case SIOCATALKDIFADDR:
  700. case SIOCDIFADDR:
  701. if (!capable(CAP_NET_ADMIN))
  702. return -EPERM;
  703. if (sa->sat_family != AF_APPLETALK)
  704. return -EINVAL;
  705. atalk_dev_down(dev);
  706. break;
  707. case SIOCSARP:
  708. if (!capable(CAP_NET_ADMIN))
  709. return -EPERM;
  710. if (sa->sat_family != AF_APPLETALK)
  711. return -EINVAL;
  712. if (!atif)
  713. return -EADDRNOTAVAIL;
  714. /*
  715. * for now, we only support proxy AARP on ELAP;
  716. * we should be able to do it for LocalTalk, too.
  717. */
  718. if (dev->type != ARPHRD_ETHER)
  719. return -EPROTONOSUPPORT;
  720. /*
  721. * atif points to the current interface on this network;
  722. * we aren't concerned about its current status (at
  723. * least for now), but it has all the settings about
  724. * the network we're going to probe. Consequently, it
  725. * must exist.
  726. */
  727. if (!atif)
  728. return -EADDRNOTAVAIL;
  729. nr = (struct atalk_netrange *)&(atif->nets);
  730. /*
  731. * Phase 1 is fine on Localtalk but we don't do
  732. * Ethertalk phase 1. Anyone wanting to add it go ahead.
  733. */
  734. if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
  735. return -EPROTONOSUPPORT;
  736. if (sa->sat_addr.s_node == ATADDR_BCAST ||
  737. sa->sat_addr.s_node == 254)
  738. return -EINVAL;
  739. /*
  740. * Check if the chosen address is used. If so we
  741. * error and ATCP will try another.
  742. */
  743. if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
  744. return -EADDRINUSE;
  745. /*
  746. * We now have an address on the local network, and
  747. * the AARP code will defend it for us until we take it
  748. * down. We don't set up any routes right now, because
  749. * ATCP will install them manually via SIOCADDRT.
  750. */
  751. break;
  752. case SIOCDARP:
  753. if (!capable(CAP_NET_ADMIN))
  754. return -EPERM;
  755. if (sa->sat_family != AF_APPLETALK)
  756. return -EINVAL;
  757. if (!atif)
  758. return -EADDRNOTAVAIL;
  759. /* give to aarp module to remove proxy entry */
  760. aarp_proxy_remove(atif->dev, &(sa->sat_addr));
  761. return 0;
  762. }
  763. return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
  764. }
  765. /* Routing ioctl() calls */
  766. static int atrtr_ioctl(unsigned int cmd, void __user *arg)
  767. {
  768. struct rtentry rt;
  769. if (copy_from_user(&rt, arg, sizeof(rt)))
  770. return -EFAULT;
  771. switch (cmd) {
  772. case SIOCDELRT:
  773. if (rt.rt_dst.sa_family != AF_APPLETALK)
  774. return -EINVAL;
  775. return atrtr_delete(&((struct sockaddr_at *)
  776. &rt.rt_dst)->sat_addr);
  777. case SIOCADDRT: {
  778. struct net_device *dev = NULL;
  779. if (rt.rt_dev) {
  780. char name[IFNAMSIZ];
  781. if (copy_from_user(name, rt.rt_dev, IFNAMSIZ-1))
  782. return -EFAULT;
  783. name[IFNAMSIZ-1] = '\0';
  784. dev = __dev_get_by_name(name);
  785. if (!dev)
  786. return -ENODEV;
  787. }
  788. return atrtr_create(&rt, dev);
  789. }
  790. }
  791. return -EINVAL;
  792. }
  793. /**************************************************************************\
  794. * *
  795. * Handling for system calls applied via the various interfaces to an *
  796. * AppleTalk socket object. *
  797. * *
  798. \**************************************************************************/
  799. /*
  800. * Checksum: This is 'optional'. It's quite likely also a good
  801. * candidate for assembler hackery 8)
  802. */
  803. static unsigned long atalk_sum_partial(const unsigned char *data,
  804. int len, unsigned long sum)
  805. {
  806. /* This ought to be unwrapped neatly. I'll trust gcc for now */
  807. while (len--) {
  808. sum += *data;
  809. sum <<= 1;
  810. if (sum & 0x10000) {
  811. sum++;
  812. sum &= 0xffff;
  813. }
  814. data++;
  815. }
  816. return sum;
  817. }
  818. /* Checksum skb data -- similar to skb_checksum */
  819. static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
  820. int len, unsigned long sum)
  821. {
  822. int start = skb_headlen(skb);
  823. int i, copy;
  824. /* checksum stuff in header space */
  825. if ( (copy = start - offset) > 0) {
  826. if (copy > len)
  827. copy = len;
  828. sum = atalk_sum_partial(skb->data + offset, copy, sum);
  829. if ( (len -= copy) == 0)
  830. return sum;
  831. offset += copy;
  832. }
  833. /* checksum stuff in frags */
  834. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  835. int end;
  836. BUG_TRAP(start <= offset + len);
  837. end = start + skb_shinfo(skb)->frags[i].size;
  838. if ((copy = end - offset) > 0) {
  839. u8 *vaddr;
  840. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  841. if (copy > len)
  842. copy = len;
  843. vaddr = kmap_skb_frag(frag);
  844. sum = atalk_sum_partial(vaddr + frag->page_offset +
  845. offset - start, copy, sum);
  846. kunmap_skb_frag(vaddr);
  847. if (!(len -= copy))
  848. return sum;
  849. offset += copy;
  850. }
  851. start = end;
  852. }
  853. if (skb_shinfo(skb)->frag_list) {
  854. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  855. for (; list; list = list->next) {
  856. int end;
  857. BUG_TRAP(start <= offset + len);
  858. end = start + list->len;
  859. if ((copy = end - offset) > 0) {
  860. if (copy > len)
  861. copy = len;
  862. sum = atalk_sum_skb(list, offset - start,
  863. copy, sum);
  864. if ((len -= copy) == 0)
  865. return sum;
  866. offset += copy;
  867. }
  868. start = end;
  869. }
  870. }
  871. BUG_ON(len > 0);
  872. return sum;
  873. }
  874. static __be16 atalk_checksum(const struct sk_buff *skb, int len)
  875. {
  876. unsigned long sum;
  877. /* skip header 4 bytes */
  878. sum = atalk_sum_skb(skb, 4, len-4, 0);
  879. /* Use 0xFFFF for 0. 0 itself means none */
  880. return sum ? htons((unsigned short)sum) : htons(0xFFFF);
  881. }
  882. static struct proto ddp_proto = {
  883. .name = "DDP",
  884. .owner = THIS_MODULE,
  885. .obj_size = sizeof(struct atalk_sock),
  886. };
  887. /*
  888. * Create a socket. Initialise the socket, blank the addresses
  889. * set the state.
  890. */
  891. static int atalk_create(struct socket *sock, int protocol)
  892. {
  893. struct sock *sk;
  894. int rc = -ESOCKTNOSUPPORT;
  895. /*
  896. * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
  897. * and gives you the full ELAP frame. Should be handy for CAP 8)
  898. */
  899. if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
  900. goto out;
  901. rc = -ENOMEM;
  902. sk = sk_alloc(PF_APPLETALK, GFP_KERNEL, &ddp_proto, 1);
  903. if (!sk)
  904. goto out;
  905. rc = 0;
  906. sock->ops = &atalk_dgram_ops;
  907. sock_init_data(sock, sk);
  908. /* Checksums on by default */
  909. sock_set_flag(sk, SOCK_ZAPPED);
  910. out:
  911. return rc;
  912. }
  913. /* Free a socket. No work needed */
  914. static int atalk_release(struct socket *sock)
  915. {
  916. struct sock *sk = sock->sk;
  917. if (sk) {
  918. sock_orphan(sk);
  919. sock->sk = NULL;
  920. atalk_destroy_socket(sk);
  921. }
  922. return 0;
  923. }
  924. /**
  925. * atalk_pick_and_bind_port - Pick a source port when one is not given
  926. * @sk - socket to insert into the tables
  927. * @sat - address to search for
  928. *
  929. * Pick a source port when one is not given. If we can find a suitable free
  930. * one, we insert the socket into the tables using it.
  931. *
  932. * This whole operation must be atomic.
  933. */
  934. static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
  935. {
  936. int retval;
  937. write_lock_bh(&atalk_sockets_lock);
  938. for (sat->sat_port = ATPORT_RESERVED;
  939. sat->sat_port < ATPORT_LAST;
  940. sat->sat_port++) {
  941. struct sock *s;
  942. struct hlist_node *node;
  943. sk_for_each(s, node, &atalk_sockets) {
  944. struct atalk_sock *at = at_sk(s);
  945. if (at->src_net == sat->sat_addr.s_net &&
  946. at->src_node == sat->sat_addr.s_node &&
  947. at->src_port == sat->sat_port)
  948. goto try_next_port;
  949. }
  950. /* Wheee, it's free, assign and insert. */
  951. __atalk_insert_socket(sk);
  952. at_sk(sk)->src_port = sat->sat_port;
  953. retval = 0;
  954. goto out;
  955. try_next_port:;
  956. }
  957. retval = -EBUSY;
  958. out:
  959. write_unlock_bh(&atalk_sockets_lock);
  960. return retval;
  961. }
  962. static int atalk_autobind(struct sock *sk)
  963. {
  964. struct atalk_sock *at = at_sk(sk);
  965. struct sockaddr_at sat;
  966. struct atalk_addr *ap = atalk_find_primary();
  967. int n = -EADDRNOTAVAIL;
  968. if (!ap || ap->s_net == htons(ATADDR_ANYNET))
  969. goto out;
  970. at->src_net = sat.sat_addr.s_net = ap->s_net;
  971. at->src_node = sat.sat_addr.s_node = ap->s_node;
  972. n = atalk_pick_and_bind_port(sk, &sat);
  973. if (!n)
  974. sock_reset_flag(sk, SOCK_ZAPPED);
  975. out:
  976. return n;
  977. }
  978. /* Set the address 'our end' of the connection */
  979. static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
  980. {
  981. struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
  982. struct sock *sk = sock->sk;
  983. struct atalk_sock *at = at_sk(sk);
  984. if (!sock_flag(sk, SOCK_ZAPPED) ||
  985. addr_len != sizeof(struct sockaddr_at))
  986. return -EINVAL;
  987. if (addr->sat_family != AF_APPLETALK)
  988. return -EAFNOSUPPORT;
  989. if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
  990. struct atalk_addr *ap = atalk_find_primary();
  991. if (!ap)
  992. return -EADDRNOTAVAIL;
  993. at->src_net = addr->sat_addr.s_net = ap->s_net;
  994. at->src_node = addr->sat_addr.s_node= ap->s_node;
  995. } else {
  996. if (!atalk_find_interface(addr->sat_addr.s_net,
  997. addr->sat_addr.s_node))
  998. return -EADDRNOTAVAIL;
  999. at->src_net = addr->sat_addr.s_net;
  1000. at->src_node = addr->sat_addr.s_node;
  1001. }
  1002. if (addr->sat_port == ATADDR_ANYPORT) {
  1003. int n = atalk_pick_and_bind_port(sk, addr);
  1004. if (n < 0)
  1005. return n;
  1006. } else {
  1007. at->src_port = addr->sat_port;
  1008. if (atalk_find_or_insert_socket(sk, addr))
  1009. return -EADDRINUSE;
  1010. }
  1011. sock_reset_flag(sk, SOCK_ZAPPED);
  1012. return 0;
  1013. }
  1014. /* Set the address we talk to */
  1015. static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
  1016. int addr_len, int flags)
  1017. {
  1018. struct sock *sk = sock->sk;
  1019. struct atalk_sock *at = at_sk(sk);
  1020. struct sockaddr_at *addr;
  1021. sk->sk_state = TCP_CLOSE;
  1022. sock->state = SS_UNCONNECTED;
  1023. if (addr_len != sizeof(*addr))
  1024. return -EINVAL;
  1025. addr = (struct sockaddr_at *)uaddr;
  1026. if (addr->sat_family != AF_APPLETALK)
  1027. return -EAFNOSUPPORT;
  1028. if (addr->sat_addr.s_node == ATADDR_BCAST &&
  1029. !sock_flag(sk, SOCK_BROADCAST)) {
  1030. #if 1
  1031. printk(KERN_WARNING "%s is broken and did not set "
  1032. "SO_BROADCAST. It will break when 2.2 is "
  1033. "released.\n",
  1034. current->comm);
  1035. #else
  1036. return -EACCES;
  1037. #endif
  1038. }
  1039. if (sock_flag(sk, SOCK_ZAPPED))
  1040. if (atalk_autobind(sk) < 0)
  1041. return -EBUSY;
  1042. if (!atrtr_get_dev(&addr->sat_addr))
  1043. return -ENETUNREACH;
  1044. at->dest_port = addr->sat_port;
  1045. at->dest_net = addr->sat_addr.s_net;
  1046. at->dest_node = addr->sat_addr.s_node;
  1047. sock->state = SS_CONNECTED;
  1048. sk->sk_state = TCP_ESTABLISHED;
  1049. return 0;
  1050. }
  1051. /*
  1052. * Find the name of an AppleTalk socket. Just copy the right
  1053. * fields into the sockaddr.
  1054. */
  1055. static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
  1056. int *uaddr_len, int peer)
  1057. {
  1058. struct sockaddr_at sat;
  1059. struct sock *sk = sock->sk;
  1060. struct atalk_sock *at = at_sk(sk);
  1061. if (sock_flag(sk, SOCK_ZAPPED))
  1062. if (atalk_autobind(sk) < 0)
  1063. return -ENOBUFS;
  1064. *uaddr_len = sizeof(struct sockaddr_at);
  1065. if (peer) {
  1066. if (sk->sk_state != TCP_ESTABLISHED)
  1067. return -ENOTCONN;
  1068. sat.sat_addr.s_net = at->dest_net;
  1069. sat.sat_addr.s_node = at->dest_node;
  1070. sat.sat_port = at->dest_port;
  1071. } else {
  1072. sat.sat_addr.s_net = at->src_net;
  1073. sat.sat_addr.s_node = at->src_node;
  1074. sat.sat_port = at->src_port;
  1075. }
  1076. sat.sat_family = AF_APPLETALK;
  1077. memcpy(uaddr, &sat, sizeof(sat));
  1078. return 0;
  1079. }
  1080. #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
  1081. static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
  1082. {
  1083. return skb->data[12] == 22;
  1084. }
  1085. static int handle_ip_over_ddp(struct sk_buff *skb)
  1086. {
  1087. struct net_device *dev = __dev_get_by_name("ipddp0");
  1088. struct net_device_stats *stats;
  1089. /* This needs to be able to handle ipddp"N" devices */
  1090. if (!dev)
  1091. return -ENODEV;
  1092. skb->protocol = htons(ETH_P_IP);
  1093. skb_pull(skb, 13);
  1094. skb->dev = dev;
  1095. skb->h.raw = skb->data;
  1096. stats = dev->priv;
  1097. stats->rx_packets++;
  1098. stats->rx_bytes += skb->len + 13;
  1099. netif_rx(skb); /* Send the SKB up to a higher place. */
  1100. return 0;
  1101. }
  1102. #else
  1103. /* make it easy for gcc to optimize this test out, i.e. kill the code */
  1104. #define is_ip_over_ddp(skb) 0
  1105. #define handle_ip_over_ddp(skb) 0
  1106. #endif
  1107. static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
  1108. struct ddpehdr *ddp, __u16 len_hops,
  1109. int origlen)
  1110. {
  1111. struct atalk_route *rt;
  1112. struct atalk_addr ta;
  1113. /*
  1114. * Don't route multicast, etc., packets, or packets sent to "this
  1115. * network"
  1116. */
  1117. if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
  1118. /*
  1119. * FIXME:
  1120. *
  1121. * Can it ever happen that a packet is from a PPP iface and
  1122. * needs to be broadcast onto the default network?
  1123. */
  1124. if (dev->type == ARPHRD_PPP)
  1125. printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
  1126. "packet received from PPP iface\n");
  1127. goto free_it;
  1128. }
  1129. ta.s_net = ddp->deh_dnet;
  1130. ta.s_node = ddp->deh_dnode;
  1131. /* Route the packet */
  1132. rt = atrtr_find(&ta);
  1133. /* increment hops count */
  1134. len_hops += 1 << 10;
  1135. if (!rt || !(len_hops & (15 << 10)))
  1136. goto free_it;
  1137. /* FIXME: use skb->cb to be able to use shared skbs */
  1138. /*
  1139. * Route goes through another gateway, so set the target to the
  1140. * gateway instead.
  1141. */
  1142. if (rt->flags & RTF_GATEWAY) {
  1143. ta.s_net = rt->gateway.s_net;
  1144. ta.s_node = rt->gateway.s_node;
  1145. }
  1146. /* Fix up skb->len field */
  1147. skb_trim(skb, min_t(unsigned int, origlen,
  1148. (rt->dev->hard_header_len +
  1149. ddp_dl->header_length + (len_hops & 1023))));
  1150. /* FIXME: use skb->cb to be able to use shared skbs */
  1151. ddp->deh_len_hops = htons(len_hops);
  1152. /*
  1153. * Send the buffer onwards
  1154. *
  1155. * Now we must always be careful. If it's come from LocalTalk to
  1156. * EtherTalk it might not fit
  1157. *
  1158. * Order matters here: If a packet has to be copied to make a new
  1159. * headroom (rare hopefully) then it won't need unsharing.
  1160. *
  1161. * Note. ddp-> becomes invalid at the realloc.
  1162. */
  1163. if (skb_headroom(skb) < 22) {
  1164. /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
  1165. struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
  1166. kfree_skb(skb);
  1167. if (!nskb)
  1168. goto out;
  1169. skb = nskb;
  1170. } else
  1171. skb = skb_unshare(skb, GFP_ATOMIC);
  1172. /*
  1173. * If the buffer didn't vanish into the lack of space bitbucket we can
  1174. * send it.
  1175. */
  1176. if (skb && aarp_send_ddp(rt->dev, skb, &ta, NULL) == -1)
  1177. goto free_it;
  1178. out:
  1179. return;
  1180. free_it:
  1181. kfree_skb(skb);
  1182. }
  1183. /**
  1184. * atalk_rcv - Receive a packet (in skb) from device dev
  1185. * @skb - packet received
  1186. * @dev - network device where the packet comes from
  1187. * @pt - packet type
  1188. *
  1189. * Receive a packet (in skb) from device dev. This has come from the SNAP
  1190. * decoder, and on entry skb->h.raw is the DDP header, skb->len is the DDP
  1191. * header, skb->len is the DDP length. The physical headers have been
  1192. * extracted. PPP should probably pass frames marked as for this layer.
  1193. * [ie ARPHRD_ETHERTALK]
  1194. */
  1195. static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
  1196. struct packet_type *pt, struct net_device *orig_dev)
  1197. {
  1198. struct ddpehdr *ddp;
  1199. struct sock *sock;
  1200. struct atalk_iface *atif;
  1201. struct sockaddr_at tosat;
  1202. int origlen;
  1203. __u16 len_hops;
  1204. /* Don't mangle buffer if shared */
  1205. if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
  1206. goto out;
  1207. /* Size check and make sure header is contiguous */
  1208. if (!pskb_may_pull(skb, sizeof(*ddp)))
  1209. goto freeit;
  1210. ddp = ddp_hdr(skb);
  1211. len_hops = ntohs(ddp->deh_len_hops);
  1212. /* Trim buffer in case of stray trailing data */
  1213. origlen = skb->len;
  1214. skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
  1215. /*
  1216. * Size check to see if ddp->deh_len was crap
  1217. * (Otherwise we'll detonate most spectacularly
  1218. * in the middle of atalk_checksum() or recvmsg()).
  1219. */
  1220. if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) {
  1221. pr_debug("AppleTalk: dropping corrupted frame (deh_len=%u, "
  1222. "skb->len=%u)\n", len_hops & 1023, skb->len);
  1223. goto freeit;
  1224. }
  1225. /*
  1226. * Any checksums. Note we don't do htons() on this == is assumed to be
  1227. * valid for net byte orders all over the networking code...
  1228. */
  1229. if (ddp->deh_sum &&
  1230. atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
  1231. /* Not a valid AppleTalk frame - dustbin time */
  1232. goto freeit;
  1233. /* Check the packet is aimed at us */
  1234. if (!ddp->deh_dnet) /* Net 0 is 'this network' */
  1235. atif = atalk_find_anynet(ddp->deh_dnode, dev);
  1236. else
  1237. atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
  1238. if (!atif) {
  1239. /* Not ours, so we route the packet via the correct
  1240. * AppleTalk iface
  1241. */
  1242. atalk_route_packet(skb, dev, ddp, len_hops, origlen);
  1243. goto out;
  1244. }
  1245. /* if IP over DDP is not selected this code will be optimized out */
  1246. if (is_ip_over_ddp(skb))
  1247. return handle_ip_over_ddp(skb);
  1248. /*
  1249. * Which socket - atalk_search_socket() looks for a *full match*
  1250. * of the <net, node, port> tuple.
  1251. */
  1252. tosat.sat_addr.s_net = ddp->deh_dnet;
  1253. tosat.sat_addr.s_node = ddp->deh_dnode;
  1254. tosat.sat_port = ddp->deh_dport;
  1255. sock = atalk_search_socket(&tosat, atif);
  1256. if (!sock) /* But not one of our sockets */
  1257. goto freeit;
  1258. /* Queue packet (standard) */
  1259. skb->sk = sock;
  1260. if (sock_queue_rcv_skb(sock, skb) < 0)
  1261. goto freeit;
  1262. out:
  1263. return 0;
  1264. freeit:
  1265. kfree_skb(skb);
  1266. goto out;
  1267. }
  1268. /*
  1269. * Receive a LocalTalk frame. We make some demands on the caller here.
  1270. * Caller must provide enough headroom on the packet to pull the short
  1271. * header and append a long one.
  1272. */
  1273. static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
  1274. struct packet_type *pt, struct net_device *orig_dev)
  1275. {
  1276. /* Expand any short form frames */
  1277. if (skb->mac.raw[2] == 1) {
  1278. struct ddpehdr *ddp;
  1279. /* Find our address */
  1280. struct atalk_addr *ap = atalk_find_dev_addr(dev);
  1281. if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
  1282. goto freeit;
  1283. /* Don't mangle buffer if shared */
  1284. if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
  1285. return 0;
  1286. /*
  1287. * The push leaves us with a ddephdr not an shdr, and
  1288. * handily the port bytes in the right place preset.
  1289. */
  1290. ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
  1291. /* Now fill in the long header */
  1292. /*
  1293. * These two first. The mac overlays the new source/dest
  1294. * network information so we MUST copy these before
  1295. * we write the network numbers !
  1296. */
  1297. ddp->deh_dnode = skb->mac.raw[0]; /* From physical header */
  1298. ddp->deh_snode = skb->mac.raw[1]; /* From physical header */
  1299. ddp->deh_dnet = ap->s_net; /* Network number */
  1300. ddp->deh_snet = ap->s_net;
  1301. ddp->deh_sum = 0; /* No checksum */
  1302. /*
  1303. * Not sure about this bit...
  1304. */
  1305. /* Non routable, so force a drop if we slip up later */
  1306. ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
  1307. }
  1308. skb->h.raw = skb->data;
  1309. return atalk_rcv(skb, dev, pt, orig_dev);
  1310. freeit:
  1311. kfree_skb(skb);
  1312. return 0;
  1313. }
  1314. static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
  1315. size_t len)
  1316. {
  1317. struct sock *sk = sock->sk;
  1318. struct atalk_sock *at = at_sk(sk);
  1319. struct sockaddr_at *usat = (struct sockaddr_at *)msg->msg_name;
  1320. int flags = msg->msg_flags;
  1321. int loopback = 0;
  1322. struct sockaddr_at local_satalk, gsat;
  1323. struct sk_buff *skb;
  1324. struct net_device *dev;
  1325. struct ddpehdr *ddp;
  1326. int size;
  1327. struct atalk_route *rt;
  1328. int err;
  1329. if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
  1330. return -EINVAL;
  1331. if (len > DDP_MAXSZ)
  1332. return -EMSGSIZE;
  1333. if (usat) {
  1334. if (sock_flag(sk, SOCK_ZAPPED))
  1335. if (atalk_autobind(sk) < 0)
  1336. return -EBUSY;
  1337. if (msg->msg_namelen < sizeof(*usat) ||
  1338. usat->sat_family != AF_APPLETALK)
  1339. return -EINVAL;
  1340. /* netatalk doesn't implement this check */
  1341. if (usat->sat_addr.s_node == ATADDR_BCAST &&
  1342. !sock_flag(sk, SOCK_BROADCAST)) {
  1343. printk(KERN_INFO "SO_BROADCAST: Fix your netatalk as "
  1344. "it will break before 2.2\n");
  1345. #if 0
  1346. return -EPERM;
  1347. #endif
  1348. }
  1349. } else {
  1350. if (sk->sk_state != TCP_ESTABLISHED)
  1351. return -ENOTCONN;
  1352. usat = &local_satalk;
  1353. usat->sat_family = AF_APPLETALK;
  1354. usat->sat_port = at->dest_port;
  1355. usat->sat_addr.s_node = at->dest_node;
  1356. usat->sat_addr.s_net = at->dest_net;
  1357. }
  1358. /* Build a packet */
  1359. SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
  1360. /* For headers */
  1361. size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
  1362. if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
  1363. rt = atrtr_find(&usat->sat_addr);
  1364. } else {
  1365. struct atalk_addr at_hint;
  1366. at_hint.s_node = 0;
  1367. at_hint.s_net = at->src_net;
  1368. rt = atrtr_find(&at_hint);
  1369. }
  1370. if (!rt)
  1371. return -ENETUNREACH;
  1372. dev = rt->dev;
  1373. SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
  1374. sk, size, dev->name);
  1375. size += dev->hard_header_len;
  1376. skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
  1377. if (!skb)
  1378. return err;
  1379. skb->sk = sk;
  1380. skb_reserve(skb, ddp_dl->header_length);
  1381. skb_reserve(skb, dev->hard_header_len);
  1382. skb->dev = dev;
  1383. SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
  1384. ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
  1385. ddp->deh_len_hops = htons(len + sizeof(*ddp));
  1386. ddp->deh_dnet = usat->sat_addr.s_net;
  1387. ddp->deh_snet = at->src_net;
  1388. ddp->deh_dnode = usat->sat_addr.s_node;
  1389. ddp->deh_snode = at->src_node;
  1390. ddp->deh_dport = usat->sat_port;
  1391. ddp->deh_sport = at->src_port;
  1392. SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
  1393. err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
  1394. if (err) {
  1395. kfree_skb(skb);
  1396. return -EFAULT;
  1397. }
  1398. if (sk->sk_no_check == 1)
  1399. ddp->deh_sum = 0;
  1400. else
  1401. ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
  1402. /*
  1403. * Loopback broadcast packets to non gateway targets (ie routes
  1404. * to group we are in)
  1405. */
  1406. if (ddp->deh_dnode == ATADDR_BCAST &&
  1407. !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
  1408. struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
  1409. if (skb2) {
  1410. loopback = 1;
  1411. SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
  1412. if (aarp_send_ddp(dev, skb2,
  1413. &usat->sat_addr, NULL) == -1)
  1414. kfree_skb(skb2);
  1415. /* else queued/sent above in the aarp queue */
  1416. }
  1417. }
  1418. if (dev->flags & IFF_LOOPBACK || loopback) {
  1419. SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
  1420. /* loop back */
  1421. skb_orphan(skb);
  1422. if (ddp->deh_dnode == ATADDR_BCAST) {
  1423. struct atalk_addr at_lo;
  1424. at_lo.s_node = 0;
  1425. at_lo.s_net = 0;
  1426. rt = atrtr_find(&at_lo);
  1427. if (!rt) {
  1428. kfree_skb(skb);
  1429. return -ENETUNREACH;
  1430. }
  1431. dev = rt->dev;
  1432. skb->dev = dev;
  1433. }
  1434. ddp_dl->request(ddp_dl, skb, dev->dev_addr);
  1435. } else {
  1436. SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
  1437. if (rt->flags & RTF_GATEWAY) {
  1438. gsat.sat_addr = rt->gateway;
  1439. usat = &gsat;
  1440. }
  1441. if (aarp_send_ddp(dev, skb, &usat->sat_addr, NULL) == -1)
  1442. kfree_skb(skb);
  1443. /* else queued/sent above in the aarp queue */
  1444. }
  1445. SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
  1446. return len;
  1447. }
  1448. static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
  1449. size_t size, int flags)
  1450. {
  1451. struct sock *sk = sock->sk;
  1452. struct sockaddr_at *sat = (struct sockaddr_at *)msg->msg_name;
  1453. struct ddpehdr *ddp;
  1454. int copied = 0;
  1455. int offset = 0;
  1456. int err = 0;
  1457. struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
  1458. flags & MSG_DONTWAIT, &err);
  1459. if (!skb)
  1460. return err;
  1461. /* FIXME: use skb->cb to be able to use shared skbs */
  1462. ddp = ddp_hdr(skb);
  1463. copied = ntohs(ddp->deh_len_hops) & 1023;
  1464. if (sk->sk_type != SOCK_RAW) {
  1465. offset = sizeof(*ddp);
  1466. copied -= offset;
  1467. }
  1468. if (copied > size) {
  1469. copied = size;
  1470. msg->msg_flags |= MSG_TRUNC;
  1471. }
  1472. err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copied);
  1473. if (!err) {
  1474. if (sat) {
  1475. sat->sat_family = AF_APPLETALK;
  1476. sat->sat_port = ddp->deh_sport;
  1477. sat->sat_addr.s_node = ddp->deh_snode;
  1478. sat->sat_addr.s_net = ddp->deh_snet;
  1479. }
  1480. msg->msg_namelen = sizeof(*sat);
  1481. }
  1482. skb_free_datagram(sk, skb); /* Free the datagram. */
  1483. return err ? : copied;
  1484. }
  1485. /*
  1486. * AppleTalk ioctl calls.
  1487. */
  1488. static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1489. {
  1490. int rc = -ENOIOCTLCMD;
  1491. struct sock *sk = sock->sk;
  1492. void __user *argp = (void __user *)arg;
  1493. switch (cmd) {
  1494. /* Protocol layer */
  1495. case TIOCOUTQ: {
  1496. long amount = sk->sk_sndbuf -
  1497. atomic_read(&sk->sk_wmem_alloc);
  1498. if (amount < 0)
  1499. amount = 0;
  1500. rc = put_user(amount, (int __user *)argp);
  1501. break;
  1502. }
  1503. case TIOCINQ: {
  1504. /*
  1505. * These two are safe on a single CPU system as only
  1506. * user tasks fiddle here
  1507. */
  1508. struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
  1509. long amount = 0;
  1510. if (skb)
  1511. amount = skb->len - sizeof(struct ddpehdr);
  1512. rc = put_user(amount, (int __user *)argp);
  1513. break;
  1514. }
  1515. case SIOCGSTAMP:
  1516. rc = sock_get_timestamp(sk, argp);
  1517. break;
  1518. /* Routing */
  1519. case SIOCADDRT:
  1520. case SIOCDELRT:
  1521. rc = -EPERM;
  1522. if (capable(CAP_NET_ADMIN))
  1523. rc = atrtr_ioctl(cmd, argp);
  1524. break;
  1525. /* Interface */
  1526. case SIOCGIFADDR:
  1527. case SIOCSIFADDR:
  1528. case SIOCGIFBRDADDR:
  1529. case SIOCATALKDIFADDR:
  1530. case SIOCDIFADDR:
  1531. case SIOCSARP: /* proxy AARP */
  1532. case SIOCDARP: /* proxy AARP */
  1533. rtnl_lock();
  1534. rc = atif_ioctl(cmd, argp);
  1535. rtnl_unlock();
  1536. break;
  1537. }
  1538. return rc;
  1539. }
  1540. #ifdef CONFIG_COMPAT
  1541. static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1542. {
  1543. /*
  1544. * All Appletalk ioctls except SIOCATALKDIFADDR are standard. And
  1545. * SIOCATALKDIFADDR is handled by upper layer as well, so there is
  1546. * nothing to do. Eventually SIOCATALKDIFADDR should be moved
  1547. * here so there is no generic SIOCPROTOPRIVATE translation in the
  1548. * system.
  1549. */
  1550. return -ENOIOCTLCMD;
  1551. }
  1552. #endif
  1553. static struct net_proto_family atalk_family_ops = {
  1554. .family = PF_APPLETALK,
  1555. .create = atalk_create,
  1556. .owner = THIS_MODULE,
  1557. };
  1558. static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
  1559. .family = PF_APPLETALK,
  1560. .owner = THIS_MODULE,
  1561. .release = atalk_release,
  1562. .bind = atalk_bind,
  1563. .connect = atalk_connect,
  1564. .socketpair = sock_no_socketpair,
  1565. .accept = sock_no_accept,
  1566. .getname = atalk_getname,
  1567. .poll = datagram_poll,
  1568. .ioctl = atalk_ioctl,
  1569. #ifdef CONFIG_COMPAT
  1570. .compat_ioctl = atalk_compat_ioctl,
  1571. #endif
  1572. .listen = sock_no_listen,
  1573. .shutdown = sock_no_shutdown,
  1574. .setsockopt = sock_no_setsockopt,
  1575. .getsockopt = sock_no_getsockopt,
  1576. .sendmsg = atalk_sendmsg,
  1577. .recvmsg = atalk_recvmsg,
  1578. .mmap = sock_no_mmap,
  1579. .sendpage = sock_no_sendpage,
  1580. };
  1581. #include <linux/smp_lock.h>
  1582. SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
  1583. static struct notifier_block ddp_notifier = {
  1584. .notifier_call = ddp_device_event,
  1585. };
  1586. static struct packet_type ltalk_packet_type = {
  1587. .type = __constant_htons(ETH_P_LOCALTALK),
  1588. .func = ltalk_rcv,
  1589. };
  1590. static struct packet_type ppptalk_packet_type = {
  1591. .type = __constant_htons(ETH_P_PPPTALK),
  1592. .func = atalk_rcv,
  1593. };
  1594. static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
  1595. /* Export symbols for use by drivers when AppleTalk is a module */
  1596. EXPORT_SYMBOL(aarp_send_ddp);
  1597. EXPORT_SYMBOL(atrtr_get_dev);
  1598. EXPORT_SYMBOL(atalk_find_dev_addr);
  1599. static char atalk_err_snap[] __initdata =
  1600. KERN_CRIT "Unable to register DDP with SNAP.\n";
  1601. /* Called by proto.c on kernel start up */
  1602. static int __init atalk_init(void)
  1603. {
  1604. int rc = proto_register(&ddp_proto, 0);
  1605. if (rc != 0)
  1606. goto out;
  1607. (void)sock_register(&atalk_family_ops);
  1608. ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
  1609. if (!ddp_dl)
  1610. printk(atalk_err_snap);
  1611. dev_add_pack(&ltalk_packet_type);
  1612. dev_add_pack(&ppptalk_packet_type);
  1613. register_netdevice_notifier(&ddp_notifier);
  1614. aarp_proto_init();
  1615. atalk_proc_init();
  1616. atalk_register_sysctl();
  1617. out:
  1618. return rc;
  1619. }
  1620. module_init(atalk_init);
  1621. /*
  1622. * No explicit module reference count manipulation is needed in the
  1623. * protocol. Socket layer sets module reference count for us
  1624. * and interfaces reference counting is done
  1625. * by the network device layer.
  1626. *
  1627. * Ergo, before the AppleTalk module can be removed, all AppleTalk
  1628. * sockets be closed from user space.
  1629. */
  1630. static void __exit atalk_exit(void)
  1631. {
  1632. #ifdef CONFIG_SYSCTL
  1633. atalk_unregister_sysctl();
  1634. #endif /* CONFIG_SYSCTL */
  1635. atalk_proc_exit();
  1636. aarp_cleanup_module(); /* General aarp clean-up. */
  1637. unregister_netdevice_notifier(&ddp_notifier);
  1638. dev_remove_pack(&ltalk_packet_type);
  1639. dev_remove_pack(&ppptalk_packet_type);
  1640. unregister_snap_client(ddp_dl);
  1641. sock_unregister(PF_APPLETALK);
  1642. proto_unregister(&ddp_proto);
  1643. }
  1644. module_exit(atalk_exit);
  1645. MODULE_LICENSE("GPL");
  1646. MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>");
  1647. MODULE_DESCRIPTION("AppleTalk 0.20\n");
  1648. MODULE_ALIAS_NETPROTO(PF_APPLETALK);