ddp.c 48 KB

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