ddp.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  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. memset(&sat.sat_zero, 0, sizeof(sat.sat_zero));
  1065. if (peer) {
  1066. if (sk->sk_state != TCP_ESTABLISHED)
  1067. return -ENOTCONN;
  1068. sat.sat_addr.s_net = at->dest_net;
  1069. sat.sat_addr.s_node = at->dest_node;
  1070. sat.sat_port = at->dest_port;
  1071. } else {
  1072. sat.sat_addr.s_net = at->src_net;
  1073. sat.sat_addr.s_node = at->src_node;
  1074. sat.sat_port = at->src_port;
  1075. }
  1076. sat.sat_family = AF_APPLETALK;
  1077. memcpy(uaddr, &sat, sizeof(sat));
  1078. return 0;
  1079. }
  1080. #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
  1081. static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
  1082. {
  1083. return skb->data[12] == 22;
  1084. }
  1085. static int handle_ip_over_ddp(struct sk_buff *skb)
  1086. {
  1087. struct net_device *dev = __dev_get_by_name(&init_net, "ipddp0");
  1088. struct net_device_stats *stats;
  1089. /* This needs to be able to handle ipddp"N" devices */
  1090. if (!dev) {
  1091. kfree_skb(skb);
  1092. return NET_RX_DROP;
  1093. }
  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. return netif_rx(skb); /* Send the SKB up to a higher place. */
  1102. }
  1103. #else
  1104. /* make it easy for gcc to optimize this test out, i.e. kill the code */
  1105. #define is_ip_over_ddp(skb) 0
  1106. #define handle_ip_over_ddp(skb) 0
  1107. #endif
  1108. static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
  1109. struct ddpehdr *ddp, __u16 len_hops, int origlen)
  1110. {
  1111. struct atalk_route *rt;
  1112. struct atalk_addr ta;
  1113. /*
  1114. * Don't route multicast, etc., packets, or packets sent to "this
  1115. * network"
  1116. */
  1117. if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
  1118. /*
  1119. * FIXME:
  1120. *
  1121. * Can it ever happen that a packet is from a PPP iface and
  1122. * needs to be broadcast onto the default network?
  1123. */
  1124. if (dev->type == ARPHRD_PPP)
  1125. printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
  1126. "packet received from PPP iface\n");
  1127. goto free_it;
  1128. }
  1129. ta.s_net = ddp->deh_dnet;
  1130. ta.s_node = ddp->deh_dnode;
  1131. /* Route the packet */
  1132. rt = atrtr_find(&ta);
  1133. /* increment hops count */
  1134. len_hops += 1 << 10;
  1135. if (!rt || !(len_hops & (15 << 10)))
  1136. goto free_it;
  1137. /* FIXME: use skb->cb to be able to use shared skbs */
  1138. /*
  1139. * Route goes through another gateway, so set the target to the
  1140. * gateway instead.
  1141. */
  1142. if (rt->flags & RTF_GATEWAY) {
  1143. ta.s_net = rt->gateway.s_net;
  1144. ta.s_node = rt->gateway.s_node;
  1145. }
  1146. /* Fix up skb->len field */
  1147. skb_trim(skb, min_t(unsigned int, origlen,
  1148. (rt->dev->hard_header_len +
  1149. ddp_dl->header_length + (len_hops & 1023))));
  1150. /* FIXME: use skb->cb to be able to use shared skbs */
  1151. ddp->deh_len_hops = htons(len_hops);
  1152. /*
  1153. * Send the buffer onwards
  1154. *
  1155. * Now we must always be careful. If it's come from LocalTalk to
  1156. * EtherTalk it might not fit
  1157. *
  1158. * Order matters here: If a packet has to be copied to make a new
  1159. * headroom (rare hopefully) then it won't need unsharing.
  1160. *
  1161. * Note. ddp-> becomes invalid at the realloc.
  1162. */
  1163. if (skb_headroom(skb) < 22) {
  1164. /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
  1165. struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
  1166. kfree_skb(skb);
  1167. skb = nskb;
  1168. } else
  1169. skb = skb_unshare(skb, GFP_ATOMIC);
  1170. /*
  1171. * If the buffer didn't vanish into the lack of space bitbucket we can
  1172. * send it.
  1173. */
  1174. if (skb == NULL)
  1175. goto drop;
  1176. if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
  1177. return NET_RX_DROP;
  1178. return NET_RX_SUCCESS;
  1179. free_it:
  1180. kfree_skb(skb);
  1181. drop:
  1182. return NET_RX_DROP;
  1183. }
  1184. /**
  1185. * atalk_rcv - Receive a packet (in skb) from device dev
  1186. * @skb - packet received
  1187. * @dev - network device where the packet comes from
  1188. * @pt - packet type
  1189. *
  1190. * Receive a packet (in skb) from device dev. This has come from the SNAP
  1191. * decoder, and on entry skb->transport_header is the DDP header, skb->len
  1192. * is the DDP header, skb->len is the DDP length. The physical headers
  1193. * have been extracted. PPP should probably pass frames marked as for this
  1194. * layer. [ie ARPHRD_ETHERTALK]
  1195. */
  1196. static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
  1197. struct packet_type *pt, struct net_device *orig_dev)
  1198. {
  1199. struct ddpehdr *ddp;
  1200. struct sock *sock;
  1201. struct atalk_iface *atif;
  1202. struct sockaddr_at tosat;
  1203. int origlen;
  1204. __u16 len_hops;
  1205. if (!net_eq(dev_net(dev), &init_net))
  1206. goto drop;
  1207. /* Don't mangle buffer if shared */
  1208. if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
  1209. goto out;
  1210. /* Size check and make sure header is contiguous */
  1211. if (!pskb_may_pull(skb, sizeof(*ddp)))
  1212. goto drop;
  1213. ddp = ddp_hdr(skb);
  1214. len_hops = ntohs(ddp->deh_len_hops);
  1215. /* Trim buffer in case of stray trailing data */
  1216. origlen = skb->len;
  1217. skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
  1218. /*
  1219. * Size check to see if ddp->deh_len was crap
  1220. * (Otherwise we'll detonate most spectacularly
  1221. * in the middle of atalk_checksum() or recvmsg()).
  1222. */
  1223. if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) {
  1224. pr_debug("AppleTalk: dropping corrupted frame (deh_len=%u, "
  1225. "skb->len=%u)\n", len_hops & 1023, skb->len);
  1226. goto drop;
  1227. }
  1228. /*
  1229. * Any checksums. Note we don't do htons() on this == is assumed to be
  1230. * valid for net byte orders all over the networking code...
  1231. */
  1232. if (ddp->deh_sum &&
  1233. atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
  1234. /* Not a valid AppleTalk frame - dustbin time */
  1235. goto drop;
  1236. /* Check the packet is aimed at us */
  1237. if (!ddp->deh_dnet) /* Net 0 is 'this network' */
  1238. atif = atalk_find_anynet(ddp->deh_dnode, dev);
  1239. else
  1240. atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
  1241. if (!atif) {
  1242. /* Not ours, so we route the packet via the correct
  1243. * AppleTalk iface
  1244. */
  1245. return atalk_route_packet(skb, dev, ddp, len_hops, origlen);
  1246. }
  1247. /* if IP over DDP is not selected this code will be optimized out */
  1248. if (is_ip_over_ddp(skb))
  1249. return handle_ip_over_ddp(skb);
  1250. /*
  1251. * Which socket - atalk_search_socket() looks for a *full match*
  1252. * of the <net, node, port> tuple.
  1253. */
  1254. tosat.sat_addr.s_net = ddp->deh_dnet;
  1255. tosat.sat_addr.s_node = ddp->deh_dnode;
  1256. tosat.sat_port = ddp->deh_dport;
  1257. sock = atalk_search_socket(&tosat, atif);
  1258. if (!sock) /* But not one of our sockets */
  1259. goto drop;
  1260. /* Queue packet (standard) */
  1261. skb->sk = sock;
  1262. if (sock_queue_rcv_skb(sock, skb) < 0)
  1263. goto drop;
  1264. return NET_RX_SUCCESS;
  1265. drop:
  1266. kfree_skb(skb);
  1267. out:
  1268. return NET_RX_DROP;
  1269. }
  1270. /*
  1271. * Receive a LocalTalk frame. We make some demands on the caller here.
  1272. * Caller must provide enough headroom on the packet to pull the short
  1273. * header and append a long one.
  1274. */
  1275. static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
  1276. struct packet_type *pt, struct net_device *orig_dev)
  1277. {
  1278. if (!net_eq(dev_net(dev), &init_net))
  1279. goto freeit;
  1280. /* Expand any short form frames */
  1281. if (skb_mac_header(skb)[2] == 1) {
  1282. struct ddpehdr *ddp;
  1283. /* Find our address */
  1284. struct atalk_addr *ap = atalk_find_dev_addr(dev);
  1285. if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
  1286. goto freeit;
  1287. /* Don't mangle buffer if shared */
  1288. if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
  1289. return 0;
  1290. /*
  1291. * The push leaves us with a ddephdr not an shdr, and
  1292. * handily the port bytes in the right place preset.
  1293. */
  1294. ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
  1295. /* Now fill in the long header */
  1296. /*
  1297. * These two first. The mac overlays the new source/dest
  1298. * network information so we MUST copy these before
  1299. * we write the network numbers !
  1300. */
  1301. ddp->deh_dnode = skb_mac_header(skb)[0]; /* From physical header */
  1302. ddp->deh_snode = skb_mac_header(skb)[1]; /* From physical header */
  1303. ddp->deh_dnet = ap->s_net; /* Network number */
  1304. ddp->deh_snet = ap->s_net;
  1305. ddp->deh_sum = 0; /* No checksum */
  1306. /*
  1307. * Not sure about this bit...
  1308. */
  1309. /* Non routable, so force a drop if we slip up later */
  1310. ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
  1311. }
  1312. skb_reset_transport_header(skb);
  1313. return atalk_rcv(skb, dev, pt, orig_dev);
  1314. freeit:
  1315. kfree_skb(skb);
  1316. return 0;
  1317. }
  1318. static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
  1319. size_t len)
  1320. {
  1321. struct sock *sk = sock->sk;
  1322. struct atalk_sock *at = at_sk(sk);
  1323. struct sockaddr_at *usat = (struct sockaddr_at *)msg->msg_name;
  1324. int flags = msg->msg_flags;
  1325. int loopback = 0;
  1326. struct sockaddr_at local_satalk, gsat;
  1327. struct sk_buff *skb;
  1328. struct net_device *dev;
  1329. struct ddpehdr *ddp;
  1330. int size;
  1331. struct atalk_route *rt;
  1332. int err;
  1333. if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
  1334. return -EINVAL;
  1335. if (len > DDP_MAXSZ)
  1336. return -EMSGSIZE;
  1337. if (usat) {
  1338. if (sock_flag(sk, SOCK_ZAPPED))
  1339. if (atalk_autobind(sk) < 0)
  1340. return -EBUSY;
  1341. if (msg->msg_namelen < sizeof(*usat) ||
  1342. usat->sat_family != AF_APPLETALK)
  1343. return -EINVAL;
  1344. /* netatalk didn't implement this check */
  1345. if (usat->sat_addr.s_node == ATADDR_BCAST &&
  1346. !sock_flag(sk, SOCK_BROADCAST)) {
  1347. return -EPERM;
  1348. }
  1349. } else {
  1350. if (sk->sk_state != TCP_ESTABLISHED)
  1351. return -ENOTCONN;
  1352. usat = &local_satalk;
  1353. usat->sat_family = AF_APPLETALK;
  1354. usat->sat_port = at->dest_port;
  1355. usat->sat_addr.s_node = at->dest_node;
  1356. usat->sat_addr.s_net = at->dest_net;
  1357. }
  1358. /* Build a packet */
  1359. SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
  1360. /* For headers */
  1361. size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
  1362. if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
  1363. rt = atrtr_find(&usat->sat_addr);
  1364. } else {
  1365. struct atalk_addr at_hint;
  1366. at_hint.s_node = 0;
  1367. at_hint.s_net = at->src_net;
  1368. rt = atrtr_find(&at_hint);
  1369. }
  1370. if (!rt)
  1371. return -ENETUNREACH;
  1372. dev = rt->dev;
  1373. SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
  1374. sk, size, dev->name);
  1375. size += dev->hard_header_len;
  1376. skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
  1377. if (!skb)
  1378. return err;
  1379. skb->sk = sk;
  1380. skb_reserve(skb, ddp_dl->header_length);
  1381. skb_reserve(skb, dev->hard_header_len);
  1382. skb->dev = dev;
  1383. SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
  1384. ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
  1385. ddp->deh_len_hops = htons(len + sizeof(*ddp));
  1386. ddp->deh_dnet = usat->sat_addr.s_net;
  1387. ddp->deh_snet = at->src_net;
  1388. ddp->deh_dnode = usat->sat_addr.s_node;
  1389. ddp->deh_snode = at->src_node;
  1390. ddp->deh_dport = usat->sat_port;
  1391. ddp->deh_sport = at->src_port;
  1392. SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
  1393. err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
  1394. if (err) {
  1395. kfree_skb(skb);
  1396. return -EFAULT;
  1397. }
  1398. if (sk->sk_no_check == 1)
  1399. ddp->deh_sum = 0;
  1400. else
  1401. ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
  1402. /*
  1403. * Loopback broadcast packets to non gateway targets (ie routes
  1404. * to group we are in)
  1405. */
  1406. if (ddp->deh_dnode == ATADDR_BCAST &&
  1407. !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
  1408. struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
  1409. if (skb2) {
  1410. loopback = 1;
  1411. SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
  1412. /*
  1413. * If it fails it is queued/sent above in the aarp queue
  1414. */
  1415. aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL);
  1416. }
  1417. }
  1418. if (dev->flags & IFF_LOOPBACK || loopback) {
  1419. SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
  1420. /* loop back */
  1421. skb_orphan(skb);
  1422. if (ddp->deh_dnode == ATADDR_BCAST) {
  1423. struct atalk_addr at_lo;
  1424. at_lo.s_node = 0;
  1425. at_lo.s_net = 0;
  1426. rt = atrtr_find(&at_lo);
  1427. if (!rt) {
  1428. kfree_skb(skb);
  1429. return -ENETUNREACH;
  1430. }
  1431. dev = rt->dev;
  1432. skb->dev = dev;
  1433. }
  1434. ddp_dl->request(ddp_dl, skb, dev->dev_addr);
  1435. } else {
  1436. SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
  1437. if (rt->flags & RTF_GATEWAY) {
  1438. gsat.sat_addr = rt->gateway;
  1439. usat = &gsat;
  1440. }
  1441. /*
  1442. * If it fails it is queued/sent above in the aarp queue
  1443. */
  1444. aarp_send_ddp(dev, skb, &usat->sat_addr, NULL);
  1445. }
  1446. SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
  1447. return len;
  1448. }
  1449. static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
  1450. size_t size, int flags)
  1451. {
  1452. struct sock *sk = sock->sk;
  1453. struct sockaddr_at *sat = (struct sockaddr_at *)msg->msg_name;
  1454. struct ddpehdr *ddp;
  1455. int copied = 0;
  1456. int offset = 0;
  1457. int err = 0;
  1458. struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
  1459. flags & MSG_DONTWAIT, &err);
  1460. if (!skb)
  1461. return err;
  1462. /* FIXME: use skb->cb to be able to use shared skbs */
  1463. ddp = ddp_hdr(skb);
  1464. copied = ntohs(ddp->deh_len_hops) & 1023;
  1465. if (sk->sk_type != SOCK_RAW) {
  1466. offset = sizeof(*ddp);
  1467. copied -= offset;
  1468. }
  1469. if (copied > size) {
  1470. copied = size;
  1471. msg->msg_flags |= MSG_TRUNC;
  1472. }
  1473. err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copied);
  1474. if (!err) {
  1475. if (sat) {
  1476. sat->sat_family = AF_APPLETALK;
  1477. sat->sat_port = ddp->deh_sport;
  1478. sat->sat_addr.s_node = ddp->deh_snode;
  1479. sat->sat_addr.s_net = ddp->deh_snet;
  1480. }
  1481. msg->msg_namelen = sizeof(*sat);
  1482. }
  1483. skb_free_datagram(sk, skb); /* Free the datagram. */
  1484. return err ? : copied;
  1485. }
  1486. /*
  1487. * AppleTalk ioctl calls.
  1488. */
  1489. static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1490. {
  1491. int rc = -ENOIOCTLCMD;
  1492. struct sock *sk = sock->sk;
  1493. void __user *argp = (void __user *)arg;
  1494. switch (cmd) {
  1495. /* Protocol layer */
  1496. case TIOCOUTQ: {
  1497. long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
  1498. if (amount < 0)
  1499. amount = 0;
  1500. rc = put_user(amount, (int __user *)argp);
  1501. break;
  1502. }
  1503. case TIOCINQ: {
  1504. /*
  1505. * These two are safe on a single CPU system as only
  1506. * user tasks fiddle here
  1507. */
  1508. struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
  1509. long amount = 0;
  1510. if (skb)
  1511. amount = skb->len - sizeof(struct ddpehdr);
  1512. rc = put_user(amount, (int __user *)argp);
  1513. break;
  1514. }
  1515. case SIOCGSTAMP:
  1516. rc = sock_get_timestamp(sk, argp);
  1517. break;
  1518. case SIOCGSTAMPNS:
  1519. rc = sock_get_timestampns(sk, argp);
  1520. break;
  1521. /* Routing */
  1522. case SIOCADDRT:
  1523. case SIOCDELRT:
  1524. rc = -EPERM;
  1525. if (capable(CAP_NET_ADMIN))
  1526. rc = atrtr_ioctl(cmd, argp);
  1527. break;
  1528. /* Interface */
  1529. case SIOCGIFADDR:
  1530. case SIOCSIFADDR:
  1531. case SIOCGIFBRDADDR:
  1532. case SIOCATALKDIFADDR:
  1533. case SIOCDIFADDR:
  1534. case SIOCSARP: /* proxy AARP */
  1535. case SIOCDARP: /* proxy AARP */
  1536. rtnl_lock();
  1537. rc = atif_ioctl(cmd, argp);
  1538. rtnl_unlock();
  1539. break;
  1540. }
  1541. return rc;
  1542. }
  1543. #ifdef CONFIG_COMPAT
  1544. static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1545. {
  1546. /*
  1547. * All Appletalk ioctls except SIOCATALKDIFADDR are standard. And
  1548. * SIOCATALKDIFADDR is handled by upper layer as well, so there is
  1549. * nothing to do. Eventually SIOCATALKDIFADDR should be moved
  1550. * here so there is no generic SIOCPROTOPRIVATE translation in the
  1551. * system.
  1552. */
  1553. return -ENOIOCTLCMD;
  1554. }
  1555. #endif
  1556. static struct net_proto_family atalk_family_ops = {
  1557. .family = PF_APPLETALK,
  1558. .create = atalk_create,
  1559. .owner = THIS_MODULE,
  1560. };
  1561. static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
  1562. .family = PF_APPLETALK,
  1563. .owner = THIS_MODULE,
  1564. .release = atalk_release,
  1565. .bind = atalk_bind,
  1566. .connect = atalk_connect,
  1567. .socketpair = sock_no_socketpair,
  1568. .accept = sock_no_accept,
  1569. .getname = atalk_getname,
  1570. .poll = datagram_poll,
  1571. .ioctl = atalk_ioctl,
  1572. #ifdef CONFIG_COMPAT
  1573. .compat_ioctl = atalk_compat_ioctl,
  1574. #endif
  1575. .listen = sock_no_listen,
  1576. .shutdown = sock_no_shutdown,
  1577. .setsockopt = sock_no_setsockopt,
  1578. .getsockopt = sock_no_getsockopt,
  1579. .sendmsg = atalk_sendmsg,
  1580. .recvmsg = atalk_recvmsg,
  1581. .mmap = sock_no_mmap,
  1582. .sendpage = sock_no_sendpage,
  1583. };
  1584. SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
  1585. static struct notifier_block ddp_notifier = {
  1586. .notifier_call = ddp_device_event,
  1587. };
  1588. static struct packet_type ltalk_packet_type __read_mostly = {
  1589. .type = cpu_to_be16(ETH_P_LOCALTALK),
  1590. .func = ltalk_rcv,
  1591. };
  1592. static struct packet_type ppptalk_packet_type __read_mostly = {
  1593. .type = cpu_to_be16(ETH_P_PPPTALK),
  1594. .func = atalk_rcv,
  1595. };
  1596. static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
  1597. /* Export symbols for use by drivers when AppleTalk is a module */
  1598. EXPORT_SYMBOL(atrtr_get_dev);
  1599. EXPORT_SYMBOL(atalk_find_dev_addr);
  1600. static const char atalk_err_snap[] __initconst =
  1601. KERN_CRIT "Unable to register DDP with SNAP.\n";
  1602. /* Called by proto.c on kernel start up */
  1603. static int __init atalk_init(void)
  1604. {
  1605. int rc = proto_register(&ddp_proto, 0);
  1606. if (rc != 0)
  1607. goto out;
  1608. (void)sock_register(&atalk_family_ops);
  1609. ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
  1610. if (!ddp_dl)
  1611. printk(atalk_err_snap);
  1612. dev_add_pack(&ltalk_packet_type);
  1613. dev_add_pack(&ppptalk_packet_type);
  1614. register_netdevice_notifier(&ddp_notifier);
  1615. aarp_proto_init();
  1616. atalk_proc_init();
  1617. atalk_register_sysctl();
  1618. out:
  1619. return rc;
  1620. }
  1621. module_init(atalk_init);
  1622. /*
  1623. * No explicit module reference count manipulation is needed in the
  1624. * protocol. Socket layer sets module reference count for us
  1625. * and interfaces reference counting is done
  1626. * by the network device layer.
  1627. *
  1628. * Ergo, before the AppleTalk module can be removed, all AppleTalk
  1629. * sockets be closed from user space.
  1630. */
  1631. static void __exit atalk_exit(void)
  1632. {
  1633. #ifdef CONFIG_SYSCTL
  1634. atalk_unregister_sysctl();
  1635. #endif /* CONFIG_SYSCTL */
  1636. atalk_proc_exit();
  1637. aarp_cleanup_module(); /* General aarp clean-up. */
  1638. unregister_netdevice_notifier(&ddp_notifier);
  1639. dev_remove_pack(&ltalk_packet_type);
  1640. dev_remove_pack(&ppptalk_packet_type);
  1641. unregister_snap_client(ddp_dl);
  1642. sock_unregister(PF_APPLETALK);
  1643. proto_unregister(&ddp_proto);
  1644. }
  1645. module_exit(atalk_exit);
  1646. MODULE_LICENSE("GPL");
  1647. MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
  1648. MODULE_DESCRIPTION("AppleTalk 0.20\n");
  1649. MODULE_ALIAS_NETPROTO(PF_APPLETALK);