ddp.c 48 KB

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