ddp.c 48 KB

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