ddp.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. /*
  2. * DDP: An implementation of the AppleTalk DDP protocol for
  3. * Ethernet 'ELAP'.
  4. *
  5. * Alan Cox <Alan.Cox@linux.org>
  6. *
  7. * With more than a little assistance from
  8. *
  9. * Wesley Craig <netatalk@umich.edu>
  10. *
  11. * Fixes:
  12. * Neil Horman : Added missing device ioctls
  13. * Michael Callahan : Made routing work
  14. * Wesley Craig : Fix probing to listen to a
  15. * passed node id.
  16. * Alan Cox : Added send/recvmsg support
  17. * Alan Cox : Moved at. to protinfo in
  18. * socket.
  19. * Alan Cox : Added firewall hooks.
  20. * Alan Cox : Supports new ARPHRD_LOOPBACK
  21. * Christer Weinigel : Routing and /proc fixes.
  22. * Bradford Johnson : LocalTalk.
  23. * Tom Dyas : Module support.
  24. * Alan Cox : Hooks for PPP (based on the
  25. * LocalTalk hook).
  26. * Alan Cox : Posix bits
  27. * Alan Cox/Mike Freeman : Possible fix to NBP problems
  28. * Bradford Johnson : IP-over-DDP (experimental)
  29. * Jay Schulist : Moved IP-over-DDP to its own
  30. * driver file. (ipddp.c & ipddp.h)
  31. * Jay Schulist : Made work as module with
  32. * AppleTalk drivers, cleaned it.
  33. * Rob Newberry : Added proxy AARP and AARP
  34. * procfs, moved probing to AARP
  35. * module.
  36. * Adrian Sun/
  37. * Michael Zuelsdorff : fix for net.0 packets. don't
  38. * allow illegal ether/tokentalk
  39. * port assignment. we lose a
  40. * valid localtalk port as a
  41. * result.
  42. * Arnaldo C. de Melo : Cleanup, in preparation for
  43. * shared skb support 8)
  44. * Arnaldo C. de Melo : Move proc stuff to atalk_proc.c,
  45. * use seq_file
  46. *
  47. * This program is free software; you can redistribute it and/or
  48. * modify it under the terms of the GNU General Public License
  49. * as published by the Free Software Foundation; either version
  50. * 2 of the License, or (at your option) any later version.
  51. *
  52. */
  53. #include <linux/capability.h>
  54. #include <linux/module.h>
  55. #include <linux/if_arp.h>
  56. #include <linux/termios.h> /* For TIOCOUTQ/INQ */
  57. #include <net/datalink.h>
  58. #include <net/psnap.h>
  59. #include <net/sock.h>
  60. #include <net/tcp_states.h>
  61. #include <net/route.h>
  62. #include <linux/atalk.h>
  63. struct datalink_proto *ddp_dl, *aarp_dl;
  64. static const struct proto_ops atalk_dgram_ops;
  65. /**************************************************************************\
  66. * *
  67. * Handlers for the socket list. *
  68. * *
  69. \**************************************************************************/
  70. HLIST_HEAD(atalk_sockets);
  71. DEFINE_RWLOCK(atalk_sockets_lock);
  72. static inline void __atalk_insert_socket(struct sock *sk)
  73. {
  74. sk_add_node(sk, &atalk_sockets);
  75. }
  76. static inline void atalk_remove_socket(struct sock *sk)
  77. {
  78. write_lock_bh(&atalk_sockets_lock);
  79. sk_del_node_init(sk);
  80. write_unlock_bh(&atalk_sockets_lock);
  81. }
  82. static struct sock *atalk_search_socket(struct sockaddr_at *to,
  83. struct atalk_iface *atif)
  84. {
  85. struct sock *s;
  86. struct hlist_node *node;
  87. read_lock_bh(&atalk_sockets_lock);
  88. sk_for_each(s, node, &atalk_sockets) {
  89. struct atalk_sock *at = at_sk(s);
  90. if (to->sat_port != at->src_port)
  91. continue;
  92. if (to->sat_addr.s_net == ATADDR_ANYNET &&
  93. to->sat_addr.s_node == ATADDR_BCAST)
  94. goto found;
  95. if (to->sat_addr.s_net == at->src_net &&
  96. (to->sat_addr.s_node == at->src_node ||
  97. to->sat_addr.s_node == ATADDR_BCAST ||
  98. to->sat_addr.s_node == ATADDR_ANYNODE))
  99. goto found;
  100. /* XXXX.0 -- we got a request for this router. make sure
  101. * that the node is appropriately set. */
  102. if (to->sat_addr.s_node == ATADDR_ANYNODE &&
  103. to->sat_addr.s_net != ATADDR_ANYNET &&
  104. atif->address.s_node == at->src_node) {
  105. to->sat_addr.s_node = atif->address.s_node;
  106. goto found;
  107. }
  108. }
  109. s = NULL;
  110. found:
  111. read_unlock_bh(&atalk_sockets_lock);
  112. return s;
  113. }
  114. /**
  115. * atalk_find_or_insert_socket - Try to find a socket matching ADDR
  116. * @sk - socket to insert in the list if it is not there already
  117. * @sat - address to search for
  118. *
  119. * Try to find a socket matching ADDR in the socket list, if found then return
  120. * it. If not, insert SK into the socket list.
  121. *
  122. * This entire operation must execute atomically.
  123. */
  124. static struct sock *atalk_find_or_insert_socket(struct sock *sk,
  125. struct sockaddr_at *sat)
  126. {
  127. struct sock *s;
  128. struct hlist_node *node;
  129. struct atalk_sock *at;
  130. write_lock_bh(&atalk_sockets_lock);
  131. sk_for_each(s, node, &atalk_sockets) {
  132. at = at_sk(s);
  133. if (at->src_net == sat->sat_addr.s_net &&
  134. at->src_node == sat->sat_addr.s_node &&
  135. at->src_port == sat->sat_port)
  136. goto found;
  137. }
  138. s = NULL;
  139. __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
  140. found:
  141. write_unlock_bh(&atalk_sockets_lock);
  142. return s;
  143. }
  144. static void atalk_destroy_timer(unsigned long data)
  145. {
  146. struct sock *sk = (struct sock *)data;
  147. if (atomic_read(&sk->sk_wmem_alloc) ||
  148. atomic_read(&sk->sk_rmem_alloc)) {
  149. sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
  150. add_timer(&sk->sk_timer);
  151. } else
  152. sock_put(sk);
  153. }
  154. static inline void atalk_destroy_socket(struct sock *sk)
  155. {
  156. atalk_remove_socket(sk);
  157. skb_queue_purge(&sk->sk_receive_queue);
  158. if (atomic_read(&sk->sk_wmem_alloc) ||
  159. atomic_read(&sk->sk_rmem_alloc)) {
  160. init_timer(&sk->sk_timer);
  161. sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
  162. sk->sk_timer.function = atalk_destroy_timer;
  163. sk->sk_timer.data = (unsigned long)sk;
  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. if (event == NETDEV_DOWN)
  568. /* Discard any use of this */
  569. atalk_dev_down(ptr);
  570. return NOTIFY_DONE;
  571. }
  572. /* ioctl calls. Shouldn't even need touching */
  573. /* Device configuration ioctl calls */
  574. static int atif_ioctl(int cmd, void __user *arg)
  575. {
  576. static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
  577. struct ifreq atreq;
  578. struct atalk_netrange *nr;
  579. struct sockaddr_at *sa;
  580. struct net_device *dev;
  581. struct atalk_iface *atif;
  582. int ct;
  583. int limit;
  584. struct rtentry rtdef;
  585. int add_route;
  586. if (copy_from_user(&atreq, arg, sizeof(atreq)))
  587. return -EFAULT;
  588. dev = __dev_get_by_name(atreq.ifr_name);
  589. if (!dev)
  590. return -ENODEV;
  591. sa = (struct sockaddr_at *)&atreq.ifr_addr;
  592. atif = atalk_find_dev(dev);
  593. switch (cmd) {
  594. case SIOCSIFADDR:
  595. if (!capable(CAP_NET_ADMIN))
  596. return -EPERM;
  597. if (sa->sat_family != AF_APPLETALK)
  598. return -EINVAL;
  599. if (dev->type != ARPHRD_ETHER &&
  600. dev->type != ARPHRD_LOOPBACK &&
  601. dev->type != ARPHRD_LOCALTLK &&
  602. dev->type != ARPHRD_PPP)
  603. return -EPROTONOSUPPORT;
  604. nr = (struct atalk_netrange *)&sa->sat_zero[0];
  605. add_route = 1;
  606. /*
  607. * if this is a point-to-point iface, and we already
  608. * have an iface for this AppleTalk address, then we
  609. * should not add a route
  610. */
  611. if ((dev->flags & IFF_POINTOPOINT) &&
  612. atalk_find_interface(sa->sat_addr.s_net,
  613. sa->sat_addr.s_node)) {
  614. printk(KERN_DEBUG "AppleTalk: point-to-point "
  615. "interface added with "
  616. "existing address\n");
  617. add_route = 0;
  618. }
  619. /*
  620. * Phase 1 is fine on LocalTalk but we don't do
  621. * EtherTalk phase 1. Anyone wanting to add it go ahead.
  622. */
  623. if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
  624. return -EPROTONOSUPPORT;
  625. if (sa->sat_addr.s_node == ATADDR_BCAST ||
  626. sa->sat_addr.s_node == 254)
  627. return -EINVAL;
  628. if (atif) {
  629. /* Already setting address */
  630. if (atif->status & ATIF_PROBE)
  631. return -EBUSY;
  632. atif->address.s_net = sa->sat_addr.s_net;
  633. atif->address.s_node = sa->sat_addr.s_node;
  634. atrtr_device_down(dev); /* Flush old routes */
  635. } else {
  636. atif = atif_add_device(dev, &sa->sat_addr);
  637. if (!atif)
  638. return -ENOMEM;
  639. }
  640. atif->nets = *nr;
  641. /*
  642. * Check if the chosen address is used. If so we
  643. * error and atalkd will try another.
  644. */
  645. if (!(dev->flags & IFF_LOOPBACK) &&
  646. !(dev->flags & IFF_POINTOPOINT) &&
  647. atif_probe_device(atif) < 0) {
  648. atif_drop_device(dev);
  649. return -EADDRINUSE;
  650. }
  651. /* Hey it worked - add the direct routes */
  652. sa = (struct sockaddr_at *)&rtdef.rt_gateway;
  653. sa->sat_family = AF_APPLETALK;
  654. sa->sat_addr.s_net = atif->address.s_net;
  655. sa->sat_addr.s_node = atif->address.s_node;
  656. sa = (struct sockaddr_at *)&rtdef.rt_dst;
  657. rtdef.rt_flags = RTF_UP;
  658. sa->sat_family = AF_APPLETALK;
  659. sa->sat_addr.s_node = ATADDR_ANYNODE;
  660. if (dev->flags & IFF_LOOPBACK ||
  661. dev->flags & IFF_POINTOPOINT)
  662. rtdef.rt_flags |= RTF_HOST;
  663. /* Routerless initial state */
  664. if (nr->nr_firstnet == htons(0) &&
  665. nr->nr_lastnet == htons(0xFFFE)) {
  666. sa->sat_addr.s_net = atif->address.s_net;
  667. atrtr_create(&rtdef, dev);
  668. atrtr_set_default(dev);
  669. } else {
  670. limit = ntohs(nr->nr_lastnet);
  671. if (limit - ntohs(nr->nr_firstnet) > 4096) {
  672. printk(KERN_WARNING "Too many routes/"
  673. "iface.\n");
  674. return -EINVAL;
  675. }
  676. if (add_route)
  677. for (ct = ntohs(nr->nr_firstnet);
  678. ct <= limit; ct++) {
  679. sa->sat_addr.s_net = htons(ct);
  680. atrtr_create(&rtdef, dev);
  681. }
  682. }
  683. dev_mc_add(dev, aarp_mcast, 6, 1);
  684. return 0;
  685. case SIOCGIFADDR:
  686. if (!atif)
  687. return -EADDRNOTAVAIL;
  688. sa->sat_family = AF_APPLETALK;
  689. sa->sat_addr = atif->address;
  690. break;
  691. case SIOCGIFBRDADDR:
  692. if (!atif)
  693. return -EADDRNOTAVAIL;
  694. sa->sat_family = AF_APPLETALK;
  695. sa->sat_addr.s_net = atif->address.s_net;
  696. sa->sat_addr.s_node = ATADDR_BCAST;
  697. break;
  698. case SIOCATALKDIFADDR:
  699. case SIOCDIFADDR:
  700. if (!capable(CAP_NET_ADMIN))
  701. return -EPERM;
  702. if (sa->sat_family != AF_APPLETALK)
  703. return -EINVAL;
  704. atalk_dev_down(dev);
  705. break;
  706. case SIOCSARP:
  707. if (!capable(CAP_NET_ADMIN))
  708. return -EPERM;
  709. if (sa->sat_family != AF_APPLETALK)
  710. return -EINVAL;
  711. if (!atif)
  712. return -EADDRNOTAVAIL;
  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(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. int i, copy;
  823. /* checksum stuff in header space */
  824. if ( (copy = start - offset) > 0) {
  825. if (copy > len)
  826. copy = len;
  827. sum = atalk_sum_partial(skb->data + offset, copy, sum);
  828. if ( (len -= copy) == 0)
  829. return sum;
  830. offset += copy;
  831. }
  832. /* checksum stuff in frags */
  833. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  834. int end;
  835. BUG_TRAP(start <= offset + len);
  836. end = start + skb_shinfo(skb)->frags[i].size;
  837. if ((copy = end - offset) > 0) {
  838. u8 *vaddr;
  839. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  840. if (copy > len)
  841. copy = len;
  842. vaddr = kmap_skb_frag(frag);
  843. sum = atalk_sum_partial(vaddr + frag->page_offset +
  844. offset - start, copy, sum);
  845. kunmap_skb_frag(vaddr);
  846. if (!(len -= copy))
  847. return sum;
  848. offset += copy;
  849. }
  850. start = end;
  851. }
  852. if (skb_shinfo(skb)->frag_list) {
  853. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  854. for (; list; list = list->next) {
  855. int end;
  856. BUG_TRAP(start <= offset + len);
  857. end = start + list->len;
  858. if ((copy = end - offset) > 0) {
  859. if (copy > len)
  860. copy = len;
  861. sum = atalk_sum_skb(list, offset - start,
  862. copy, sum);
  863. if ((len -= copy) == 0)
  864. return sum;
  865. offset += copy;
  866. }
  867. start = end;
  868. }
  869. }
  870. BUG_ON(len > 0);
  871. return sum;
  872. }
  873. static __be16 atalk_checksum(const struct sk_buff *skb, int len)
  874. {
  875. unsigned long sum;
  876. /* skip header 4 bytes */
  877. sum = atalk_sum_skb(skb, 4, len-4, 0);
  878. /* Use 0xFFFF for 0. 0 itself means none */
  879. return sum ? htons((unsigned short)sum) : htons(0xFFFF);
  880. }
  881. static struct proto ddp_proto = {
  882. .name = "DDP",
  883. .owner = THIS_MODULE,
  884. .obj_size = sizeof(struct atalk_sock),
  885. };
  886. /*
  887. * Create a socket. Initialise the socket, blank the addresses
  888. * set the state.
  889. */
  890. static int atalk_create(struct socket *sock, int protocol)
  891. {
  892. struct sock *sk;
  893. int rc = -ESOCKTNOSUPPORT;
  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(PF_APPLETALK, GFP_KERNEL, &ddp_proto, 1);
  902. if (!sk)
  903. goto out;
  904. rc = 0;
  905. sock->ops = &atalk_dgram_ops;
  906. sock_init_data(sock, sk);
  907. /* Checksums on by default */
  908. sock_set_flag(sk, SOCK_ZAPPED);
  909. out:
  910. return rc;
  911. }
  912. /* Free a socket. No work needed */
  913. static int atalk_release(struct socket *sock)
  914. {
  915. struct sock *sk = sock->sk;
  916. if (sk) {
  917. sock_orphan(sk);
  918. sock->sk = NULL;
  919. atalk_destroy_socket(sk);
  920. }
  921. return 0;
  922. }
  923. /**
  924. * atalk_pick_and_bind_port - Pick a source port when one is not given
  925. * @sk - socket to insert into the tables
  926. * @sat - address to search for
  927. *
  928. * Pick a source port when one is not given. If we can find a suitable free
  929. * one, we insert the socket into the tables using it.
  930. *
  931. * This whole operation must be atomic.
  932. */
  933. static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
  934. {
  935. int retval;
  936. write_lock_bh(&atalk_sockets_lock);
  937. for (sat->sat_port = ATPORT_RESERVED;
  938. sat->sat_port < ATPORT_LAST;
  939. sat->sat_port++) {
  940. struct sock *s;
  941. struct hlist_node *node;
  942. sk_for_each(s, node, &atalk_sockets) {
  943. struct atalk_sock *at = at_sk(s);
  944. if (at->src_net == sat->sat_addr.s_net &&
  945. at->src_node == sat->sat_addr.s_node &&
  946. at->src_port == sat->sat_port)
  947. goto try_next_port;
  948. }
  949. /* Wheee, it's free, assign and insert. */
  950. __atalk_insert_socket(sk);
  951. at_sk(sk)->src_port = sat->sat_port;
  952. retval = 0;
  953. goto out;
  954. try_next_port:;
  955. }
  956. retval = -EBUSY;
  957. out:
  958. write_unlock_bh(&atalk_sockets_lock);
  959. return retval;
  960. }
  961. static int atalk_autobind(struct sock *sk)
  962. {
  963. struct atalk_sock *at = at_sk(sk);
  964. struct sockaddr_at sat;
  965. struct atalk_addr *ap = atalk_find_primary();
  966. int n = -EADDRNOTAVAIL;
  967. if (!ap || ap->s_net == htons(ATADDR_ANYNET))
  968. goto out;
  969. at->src_net = sat.sat_addr.s_net = ap->s_net;
  970. at->src_node = sat.sat_addr.s_node = ap->s_node;
  971. n = atalk_pick_and_bind_port(sk, &sat);
  972. if (!n)
  973. sock_reset_flag(sk, SOCK_ZAPPED);
  974. out:
  975. return n;
  976. }
  977. /* Set the address 'our end' of the connection */
  978. static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
  979. {
  980. struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
  981. struct sock *sk = sock->sk;
  982. struct atalk_sock *at = at_sk(sk);
  983. if (!sock_flag(sk, SOCK_ZAPPED) ||
  984. addr_len != sizeof(struct sockaddr_at))
  985. return -EINVAL;
  986. if (addr->sat_family != AF_APPLETALK)
  987. return -EAFNOSUPPORT;
  988. if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
  989. struct atalk_addr *ap = atalk_find_primary();
  990. if (!ap)
  991. return -EADDRNOTAVAIL;
  992. at->src_net = addr->sat_addr.s_net = ap->s_net;
  993. at->src_node = addr->sat_addr.s_node= ap->s_node;
  994. } else {
  995. if (!atalk_find_interface(addr->sat_addr.s_net,
  996. addr->sat_addr.s_node))
  997. return -EADDRNOTAVAIL;
  998. at->src_net = addr->sat_addr.s_net;
  999. at->src_node = addr->sat_addr.s_node;
  1000. }
  1001. if (addr->sat_port == ATADDR_ANYPORT) {
  1002. int n = atalk_pick_and_bind_port(sk, addr);
  1003. if (n < 0)
  1004. return n;
  1005. } else {
  1006. at->src_port = addr->sat_port;
  1007. if (atalk_find_or_insert_socket(sk, addr))
  1008. return -EADDRINUSE;
  1009. }
  1010. sock_reset_flag(sk, SOCK_ZAPPED);
  1011. return 0;
  1012. }
  1013. /* Set the address we talk to */
  1014. static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
  1015. int addr_len, int flags)
  1016. {
  1017. struct sock *sk = sock->sk;
  1018. struct atalk_sock *at = at_sk(sk);
  1019. struct sockaddr_at *addr;
  1020. sk->sk_state = TCP_CLOSE;
  1021. sock->state = SS_UNCONNECTED;
  1022. if (addr_len != sizeof(*addr))
  1023. return -EINVAL;
  1024. addr = (struct sockaddr_at *)uaddr;
  1025. if (addr->sat_family != AF_APPLETALK)
  1026. return -EAFNOSUPPORT;
  1027. if (addr->sat_addr.s_node == ATADDR_BCAST &&
  1028. !sock_flag(sk, SOCK_BROADCAST)) {
  1029. #if 1
  1030. printk(KERN_WARNING "%s is broken and did not set "
  1031. "SO_BROADCAST. It will break when 2.2 is "
  1032. "released.\n",
  1033. current->comm);
  1034. #else
  1035. return -EACCES;
  1036. #endif
  1037. }
  1038. if (sock_flag(sk, SOCK_ZAPPED))
  1039. if (atalk_autobind(sk) < 0)
  1040. return -EBUSY;
  1041. if (!atrtr_get_dev(&addr->sat_addr))
  1042. return -ENETUNREACH;
  1043. at->dest_port = addr->sat_port;
  1044. at->dest_net = addr->sat_addr.s_net;
  1045. at->dest_node = addr->sat_addr.s_node;
  1046. sock->state = SS_CONNECTED;
  1047. sk->sk_state = TCP_ESTABLISHED;
  1048. return 0;
  1049. }
  1050. /*
  1051. * Find the name of an AppleTalk socket. Just copy the right
  1052. * fields into the sockaddr.
  1053. */
  1054. static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
  1055. int *uaddr_len, int peer)
  1056. {
  1057. struct sockaddr_at sat;
  1058. struct sock *sk = sock->sk;
  1059. struct atalk_sock *at = at_sk(sk);
  1060. if (sock_flag(sk, SOCK_ZAPPED))
  1061. if (atalk_autobind(sk) < 0)
  1062. return -ENOBUFS;
  1063. *uaddr_len = sizeof(struct sockaddr_at);
  1064. if (peer) {
  1065. if (sk->sk_state != TCP_ESTABLISHED)
  1066. return -ENOTCONN;
  1067. sat.sat_addr.s_net = at->dest_net;
  1068. sat.sat_addr.s_node = at->dest_node;
  1069. sat.sat_port = at->dest_port;
  1070. } else {
  1071. sat.sat_addr.s_net = at->src_net;
  1072. sat.sat_addr.s_node = at->src_node;
  1073. sat.sat_port = at->src_port;
  1074. }
  1075. sat.sat_family = AF_APPLETALK;
  1076. memcpy(uaddr, &sat, sizeof(sat));
  1077. return 0;
  1078. }
  1079. #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
  1080. static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
  1081. {
  1082. return skb->data[12] == 22;
  1083. }
  1084. static int handle_ip_over_ddp(struct sk_buff *skb)
  1085. {
  1086. struct net_device *dev = __dev_get_by_name("ipddp0");
  1087. struct net_device_stats *stats;
  1088. /* This needs to be able to handle ipddp"N" devices */
  1089. if (!dev)
  1090. return -ENODEV;
  1091. skb->protocol = htons(ETH_P_IP);
  1092. skb_pull(skb, 13);
  1093. skb->dev = dev;
  1094. skb->h.raw = skb->data;
  1095. stats = dev->priv;
  1096. stats->rx_packets++;
  1097. stats->rx_bytes += skb->len + 13;
  1098. netif_rx(skb); /* Send the SKB up to a higher place. */
  1099. return 0;
  1100. }
  1101. #else
  1102. /* make it easy for gcc to optimize this test out, i.e. kill the code */
  1103. #define is_ip_over_ddp(skb) 0
  1104. #define handle_ip_over_ddp(skb) 0
  1105. #endif
  1106. static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
  1107. struct ddpehdr *ddp, __u16 len_hops,
  1108. int origlen)
  1109. {
  1110. struct atalk_route *rt;
  1111. struct atalk_addr ta;
  1112. /*
  1113. * Don't route multicast, etc., packets, or packets sent to "this
  1114. * network"
  1115. */
  1116. if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
  1117. /*
  1118. * FIXME:
  1119. *
  1120. * Can it ever happen that a packet is from a PPP iface and
  1121. * needs to be broadcast onto the default network?
  1122. */
  1123. if (dev->type == ARPHRD_PPP)
  1124. printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
  1125. "packet received from PPP iface\n");
  1126. goto free_it;
  1127. }
  1128. ta.s_net = ddp->deh_dnet;
  1129. ta.s_node = ddp->deh_dnode;
  1130. /* Route the packet */
  1131. rt = atrtr_find(&ta);
  1132. /* increment hops count */
  1133. len_hops += 1 << 10;
  1134. if (!rt || !(len_hops & (15 << 10)))
  1135. goto free_it;
  1136. /* FIXME: use skb->cb to be able to use shared skbs */
  1137. /*
  1138. * Route goes through another gateway, so set the target to the
  1139. * gateway instead.
  1140. */
  1141. if (rt->flags & RTF_GATEWAY) {
  1142. ta.s_net = rt->gateway.s_net;
  1143. ta.s_node = rt->gateway.s_node;
  1144. }
  1145. /* Fix up skb->len field */
  1146. skb_trim(skb, min_t(unsigned int, origlen,
  1147. (rt->dev->hard_header_len +
  1148. ddp_dl->header_length + (len_hops & 1023))));
  1149. /* FIXME: use skb->cb to be able to use shared skbs */
  1150. ddp->deh_len_hops = htons(len_hops);
  1151. /*
  1152. * Send the buffer onwards
  1153. *
  1154. * Now we must always be careful. If it's come from LocalTalk to
  1155. * EtherTalk it might not fit
  1156. *
  1157. * Order matters here: If a packet has to be copied to make a new
  1158. * headroom (rare hopefully) then it won't need unsharing.
  1159. *
  1160. * Note. ddp-> becomes invalid at the realloc.
  1161. */
  1162. if (skb_headroom(skb) < 22) {
  1163. /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
  1164. struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
  1165. kfree_skb(skb);
  1166. if (!nskb)
  1167. goto out;
  1168. skb = nskb;
  1169. } else
  1170. skb = skb_unshare(skb, GFP_ATOMIC);
  1171. /*
  1172. * If the buffer didn't vanish into the lack of space bitbucket we can
  1173. * send it.
  1174. */
  1175. if (skb && aarp_send_ddp(rt->dev, skb, &ta, NULL) == -1)
  1176. goto free_it;
  1177. out:
  1178. return;
  1179. free_it:
  1180. kfree_skb(skb);
  1181. }
  1182. /**
  1183. * atalk_rcv - Receive a packet (in skb) from device dev
  1184. * @skb - packet received
  1185. * @dev - network device where the packet comes from
  1186. * @pt - packet type
  1187. *
  1188. * Receive a packet (in skb) from device dev. This has come from the SNAP
  1189. * decoder, and on entry skb->h.raw is the DDP header, skb->len is the DDP
  1190. * header, skb->len is the DDP length. The physical headers have been
  1191. * extracted. PPP should probably pass frames marked as for this layer.
  1192. * [ie ARPHRD_ETHERTALK]
  1193. */
  1194. static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
  1195. struct packet_type *pt, struct net_device *orig_dev)
  1196. {
  1197. struct ddpehdr *ddp;
  1198. struct sock *sock;
  1199. struct atalk_iface *atif;
  1200. struct sockaddr_at tosat;
  1201. int origlen;
  1202. __u16 len_hops;
  1203. /* Don't mangle buffer if shared */
  1204. if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
  1205. goto out;
  1206. /* Size check and make sure header is contiguous */
  1207. if (!pskb_may_pull(skb, sizeof(*ddp)))
  1208. goto freeit;
  1209. ddp = ddp_hdr(skb);
  1210. len_hops = ntohs(ddp->deh_len_hops);
  1211. /* Trim buffer in case of stray trailing data */
  1212. origlen = skb->len;
  1213. skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
  1214. /*
  1215. * Size check to see if ddp->deh_len was crap
  1216. * (Otherwise we'll detonate most spectacularly
  1217. * in the middle of recvmsg()).
  1218. */
  1219. if (skb->len < sizeof(*ddp))
  1220. goto freeit;
  1221. /*
  1222. * Any checksums. Note we don't do htons() on this == is assumed to be
  1223. * valid for net byte orders all over the networking code...
  1224. */
  1225. if (ddp->deh_sum &&
  1226. atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
  1227. /* Not a valid AppleTalk frame - dustbin time */
  1228. goto freeit;
  1229. /* Check the packet is aimed at us */
  1230. if (!ddp->deh_dnet) /* Net 0 is 'this network' */
  1231. atif = atalk_find_anynet(ddp->deh_dnode, dev);
  1232. else
  1233. atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
  1234. if (!atif) {
  1235. /* Not ours, so we route the packet via the correct
  1236. * AppleTalk iface
  1237. */
  1238. atalk_route_packet(skb, dev, ddp, len_hops, origlen);
  1239. goto out;
  1240. }
  1241. /* if IP over DDP is not selected this code will be optimized out */
  1242. if (is_ip_over_ddp(skb))
  1243. return handle_ip_over_ddp(skb);
  1244. /*
  1245. * Which socket - atalk_search_socket() looks for a *full match*
  1246. * of the <net, node, port> tuple.
  1247. */
  1248. tosat.sat_addr.s_net = ddp->deh_dnet;
  1249. tosat.sat_addr.s_node = ddp->deh_dnode;
  1250. tosat.sat_port = ddp->deh_dport;
  1251. sock = atalk_search_socket(&tosat, atif);
  1252. if (!sock) /* But not one of our sockets */
  1253. goto freeit;
  1254. /* Queue packet (standard) */
  1255. skb->sk = sock;
  1256. if (sock_queue_rcv_skb(sock, skb) < 0)
  1257. goto freeit;
  1258. out:
  1259. return 0;
  1260. freeit:
  1261. kfree_skb(skb);
  1262. goto out;
  1263. }
  1264. /*
  1265. * Receive a LocalTalk frame. We make some demands on the caller here.
  1266. * Caller must provide enough headroom on the packet to pull the short
  1267. * header and append a long one.
  1268. */
  1269. static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
  1270. struct packet_type *pt, struct net_device *orig_dev)
  1271. {
  1272. /* Expand any short form frames */
  1273. if (skb->mac.raw[2] == 1) {
  1274. struct ddpehdr *ddp;
  1275. /* Find our address */
  1276. struct atalk_addr *ap = atalk_find_dev_addr(dev);
  1277. if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
  1278. goto freeit;
  1279. /* Don't mangle buffer if shared */
  1280. if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
  1281. return 0;
  1282. /*
  1283. * The push leaves us with a ddephdr not an shdr, and
  1284. * handily the port bytes in the right place preset.
  1285. */
  1286. ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
  1287. /* Now fill in the long header */
  1288. /*
  1289. * These two first. The mac overlays the new source/dest
  1290. * network information so we MUST copy these before
  1291. * we write the network numbers !
  1292. */
  1293. ddp->deh_dnode = skb->mac.raw[0]; /* From physical header */
  1294. ddp->deh_snode = skb->mac.raw[1]; /* From physical header */
  1295. ddp->deh_dnet = ap->s_net; /* Network number */
  1296. ddp->deh_snet = ap->s_net;
  1297. ddp->deh_sum = 0; /* No checksum */
  1298. /*
  1299. * Not sure about this bit...
  1300. */
  1301. /* Non routable, so force a drop if we slip up later */
  1302. ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
  1303. }
  1304. skb->h.raw = skb->data;
  1305. return atalk_rcv(skb, dev, pt, orig_dev);
  1306. freeit:
  1307. kfree_skb(skb);
  1308. return 0;
  1309. }
  1310. static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
  1311. size_t len)
  1312. {
  1313. struct sock *sk = sock->sk;
  1314. struct atalk_sock *at = at_sk(sk);
  1315. struct sockaddr_at *usat = (struct sockaddr_at *)msg->msg_name;
  1316. int flags = msg->msg_flags;
  1317. int loopback = 0;
  1318. struct sockaddr_at local_satalk, gsat;
  1319. struct sk_buff *skb;
  1320. struct net_device *dev;
  1321. struct ddpehdr *ddp;
  1322. int size;
  1323. struct atalk_route *rt;
  1324. int err;
  1325. if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
  1326. return -EINVAL;
  1327. if (len > DDP_MAXSZ)
  1328. return -EMSGSIZE;
  1329. if (usat) {
  1330. if (sock_flag(sk, SOCK_ZAPPED))
  1331. if (atalk_autobind(sk) < 0)
  1332. return -EBUSY;
  1333. if (msg->msg_namelen < sizeof(*usat) ||
  1334. usat->sat_family != AF_APPLETALK)
  1335. return -EINVAL;
  1336. /* netatalk doesn't implement this check */
  1337. if (usat->sat_addr.s_node == ATADDR_BCAST &&
  1338. !sock_flag(sk, SOCK_BROADCAST)) {
  1339. printk(KERN_INFO "SO_BROADCAST: Fix your netatalk as "
  1340. "it will break before 2.2\n");
  1341. #if 0
  1342. return -EPERM;
  1343. #endif
  1344. }
  1345. } else {
  1346. if (sk->sk_state != TCP_ESTABLISHED)
  1347. return -ENOTCONN;
  1348. usat = &local_satalk;
  1349. usat->sat_family = AF_APPLETALK;
  1350. usat->sat_port = at->dest_port;
  1351. usat->sat_addr.s_node = at->dest_node;
  1352. usat->sat_addr.s_net = at->dest_net;
  1353. }
  1354. /* Build a packet */
  1355. SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
  1356. /* For headers */
  1357. size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
  1358. if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
  1359. rt = atrtr_find(&usat->sat_addr);
  1360. dev = rt->dev;
  1361. } else {
  1362. struct atalk_addr at_hint;
  1363. at_hint.s_node = 0;
  1364. at_hint.s_net = at->src_net;
  1365. rt = atrtr_find(&at_hint);
  1366. dev = rt->dev;
  1367. }
  1368. if (!rt)
  1369. return -ENETUNREACH;
  1370. dev = rt->dev;
  1371. SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
  1372. sk, size, dev->name);
  1373. size += dev->hard_header_len;
  1374. skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
  1375. if (!skb)
  1376. return err;
  1377. skb->sk = sk;
  1378. skb_reserve(skb, ddp_dl->header_length);
  1379. skb_reserve(skb, dev->hard_header_len);
  1380. skb->dev = dev;
  1381. SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
  1382. ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
  1383. ddp->deh_len_hops = htons(len + sizeof(*ddp));
  1384. ddp->deh_dnet = usat->sat_addr.s_net;
  1385. ddp->deh_snet = at->src_net;
  1386. ddp->deh_dnode = usat->sat_addr.s_node;
  1387. ddp->deh_snode = at->src_node;
  1388. ddp->deh_dport = usat->sat_port;
  1389. ddp->deh_sport = at->src_port;
  1390. SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
  1391. err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
  1392. if (err) {
  1393. kfree_skb(skb);
  1394. return -EFAULT;
  1395. }
  1396. if (sk->sk_no_check == 1)
  1397. ddp->deh_sum = 0;
  1398. else
  1399. ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
  1400. /*
  1401. * Loopback broadcast packets to non gateway targets (ie routes
  1402. * to group we are in)
  1403. */
  1404. if (ddp->deh_dnode == ATADDR_BCAST &&
  1405. !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
  1406. struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
  1407. if (skb2) {
  1408. loopback = 1;
  1409. SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
  1410. if (aarp_send_ddp(dev, skb2,
  1411. &usat->sat_addr, NULL) == -1)
  1412. kfree_skb(skb2);
  1413. /* else queued/sent above in the aarp queue */
  1414. }
  1415. }
  1416. if (dev->flags & IFF_LOOPBACK || loopback) {
  1417. SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
  1418. /* loop back */
  1419. skb_orphan(skb);
  1420. if (ddp->deh_dnode == ATADDR_BCAST) {
  1421. struct atalk_addr at_lo;
  1422. at_lo.s_node = 0;
  1423. at_lo.s_net = 0;
  1424. rt = atrtr_find(&at_lo);
  1425. if (!rt) {
  1426. kfree_skb(skb);
  1427. return -ENETUNREACH;
  1428. }
  1429. dev = rt->dev;
  1430. skb->dev = dev;
  1431. }
  1432. ddp_dl->request(ddp_dl, skb, dev->dev_addr);
  1433. } else {
  1434. SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
  1435. if (rt->flags & RTF_GATEWAY) {
  1436. gsat.sat_addr = rt->gateway;
  1437. usat = &gsat;
  1438. }
  1439. if (aarp_send_ddp(dev, skb, &usat->sat_addr, NULL) == -1)
  1440. kfree_skb(skb);
  1441. /* else queued/sent above in the aarp queue */
  1442. }
  1443. SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
  1444. return len;
  1445. }
  1446. static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
  1447. size_t size, int flags)
  1448. {
  1449. struct sock *sk = sock->sk;
  1450. struct sockaddr_at *sat = (struct sockaddr_at *)msg->msg_name;
  1451. struct ddpehdr *ddp;
  1452. int copied = 0;
  1453. int offset = 0;
  1454. int err = 0;
  1455. struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
  1456. flags & MSG_DONTWAIT, &err);
  1457. if (!skb)
  1458. return err;
  1459. /* FIXME: use skb->cb to be able to use shared skbs */
  1460. ddp = ddp_hdr(skb);
  1461. copied = ntohs(ddp->deh_len_hops) & 1023;
  1462. if (sk->sk_type != SOCK_RAW) {
  1463. offset = sizeof(*ddp);
  1464. copied -= offset;
  1465. }
  1466. if (copied > size) {
  1467. copied = size;
  1468. msg->msg_flags |= MSG_TRUNC;
  1469. }
  1470. err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copied);
  1471. if (!err) {
  1472. if (sat) {
  1473. sat->sat_family = AF_APPLETALK;
  1474. sat->sat_port = ddp->deh_sport;
  1475. sat->sat_addr.s_node = ddp->deh_snode;
  1476. sat->sat_addr.s_net = ddp->deh_snet;
  1477. }
  1478. msg->msg_namelen = sizeof(*sat);
  1479. }
  1480. skb_free_datagram(sk, skb); /* Free the datagram. */
  1481. return err ? : copied;
  1482. }
  1483. /*
  1484. * AppleTalk ioctl calls.
  1485. */
  1486. static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1487. {
  1488. int rc = -ENOIOCTLCMD;
  1489. struct sock *sk = sock->sk;
  1490. void __user *argp = (void __user *)arg;
  1491. switch (cmd) {
  1492. /* Protocol layer */
  1493. case TIOCOUTQ: {
  1494. long amount = sk->sk_sndbuf -
  1495. atomic_read(&sk->sk_wmem_alloc);
  1496. if (amount < 0)
  1497. amount = 0;
  1498. rc = put_user(amount, (int __user *)argp);
  1499. break;
  1500. }
  1501. case TIOCINQ: {
  1502. /*
  1503. * These two are safe on a single CPU system as only
  1504. * user tasks fiddle here
  1505. */
  1506. struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
  1507. long amount = 0;
  1508. if (skb)
  1509. amount = skb->len - sizeof(struct ddpehdr);
  1510. rc = put_user(amount, (int __user *)argp);
  1511. break;
  1512. }
  1513. case SIOCGSTAMP:
  1514. rc = sock_get_timestamp(sk, argp);
  1515. break;
  1516. /* Routing */
  1517. case SIOCADDRT:
  1518. case SIOCDELRT:
  1519. rc = -EPERM;
  1520. if (capable(CAP_NET_ADMIN))
  1521. rc = atrtr_ioctl(cmd, argp);
  1522. break;
  1523. /* Interface */
  1524. case SIOCGIFADDR:
  1525. case SIOCSIFADDR:
  1526. case SIOCGIFBRDADDR:
  1527. case SIOCATALKDIFADDR:
  1528. case SIOCDIFADDR:
  1529. case SIOCSARP: /* proxy AARP */
  1530. case SIOCDARP: /* proxy AARP */
  1531. rtnl_lock();
  1532. rc = atif_ioctl(cmd, argp);
  1533. rtnl_unlock();
  1534. break;
  1535. }
  1536. return rc;
  1537. }
  1538. #ifdef CONFIG_COMPAT
  1539. static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1540. {
  1541. /*
  1542. * All Appletalk ioctls except SIOCATALKDIFADDR are standard. And
  1543. * SIOCATALKDIFADDR is handled by upper layer as well, so there is
  1544. * nothing to do. Eventually SIOCATALKDIFADDR should be moved
  1545. * here so there is no generic SIOCPROTOPRIVATE translation in the
  1546. * system.
  1547. */
  1548. return -ENOIOCTLCMD;
  1549. }
  1550. #endif
  1551. static struct net_proto_family atalk_family_ops = {
  1552. .family = PF_APPLETALK,
  1553. .create = atalk_create,
  1554. .owner = THIS_MODULE,
  1555. };
  1556. static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
  1557. .family = PF_APPLETALK,
  1558. .owner = THIS_MODULE,
  1559. .release = atalk_release,
  1560. .bind = atalk_bind,
  1561. .connect = atalk_connect,
  1562. .socketpair = sock_no_socketpair,
  1563. .accept = sock_no_accept,
  1564. .getname = atalk_getname,
  1565. .poll = datagram_poll,
  1566. .ioctl = atalk_ioctl,
  1567. #ifdef CONFIG_COMPAT
  1568. .compat_ioctl = atalk_compat_ioctl,
  1569. #endif
  1570. .listen = sock_no_listen,
  1571. .shutdown = sock_no_shutdown,
  1572. .setsockopt = sock_no_setsockopt,
  1573. .getsockopt = sock_no_getsockopt,
  1574. .sendmsg = atalk_sendmsg,
  1575. .recvmsg = atalk_recvmsg,
  1576. .mmap = sock_no_mmap,
  1577. .sendpage = sock_no_sendpage,
  1578. };
  1579. #include <linux/smp_lock.h>
  1580. SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
  1581. static struct notifier_block ddp_notifier = {
  1582. .notifier_call = ddp_device_event,
  1583. };
  1584. static struct packet_type ltalk_packet_type = {
  1585. .type = __constant_htons(ETH_P_LOCALTALK),
  1586. .func = ltalk_rcv,
  1587. };
  1588. static struct packet_type ppptalk_packet_type = {
  1589. .type = __constant_htons(ETH_P_PPPTALK),
  1590. .func = atalk_rcv,
  1591. };
  1592. static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
  1593. /* Export symbols for use by drivers when AppleTalk is a module */
  1594. EXPORT_SYMBOL(aarp_send_ddp);
  1595. EXPORT_SYMBOL(atrtr_get_dev);
  1596. EXPORT_SYMBOL(atalk_find_dev_addr);
  1597. static char atalk_err_snap[] __initdata =
  1598. KERN_CRIT "Unable to register DDP with SNAP.\n";
  1599. /* Called by proto.c on kernel start up */
  1600. static int __init atalk_init(void)
  1601. {
  1602. int rc = proto_register(&ddp_proto, 0);
  1603. if (rc != 0)
  1604. goto out;
  1605. (void)sock_register(&atalk_family_ops);
  1606. ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
  1607. if (!ddp_dl)
  1608. printk(atalk_err_snap);
  1609. dev_add_pack(&ltalk_packet_type);
  1610. dev_add_pack(&ppptalk_packet_type);
  1611. register_netdevice_notifier(&ddp_notifier);
  1612. aarp_proto_init();
  1613. atalk_proc_init();
  1614. atalk_register_sysctl();
  1615. out:
  1616. return rc;
  1617. }
  1618. module_init(atalk_init);
  1619. /*
  1620. * No explicit module reference count manipulation is needed in the
  1621. * protocol. Socket layer sets module reference count for us
  1622. * and interfaces reference counting is done
  1623. * by the network device layer.
  1624. *
  1625. * Ergo, before the AppleTalk module can be removed, all AppleTalk
  1626. * sockets be closed from user space.
  1627. */
  1628. static void __exit atalk_exit(void)
  1629. {
  1630. #ifdef CONFIG_SYSCTL
  1631. atalk_unregister_sysctl();
  1632. #endif /* CONFIG_SYSCTL */
  1633. atalk_proc_exit();
  1634. aarp_cleanup_module(); /* General aarp clean-up. */
  1635. unregister_netdevice_notifier(&ddp_notifier);
  1636. dev_remove_pack(&ltalk_packet_type);
  1637. dev_remove_pack(&ppptalk_packet_type);
  1638. unregister_snap_client(ddp_dl);
  1639. sock_unregister(PF_APPLETALK);
  1640. proto_unregister(&ddp_proto);
  1641. }
  1642. module_exit(atalk_exit);
  1643. MODULE_LICENSE("GPL");
  1644. MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>");
  1645. MODULE_DESCRIPTION("AppleTalk 0.20\n");
  1646. MODULE_ALIAS_NETPROTO(PF_APPLETALK);