af_llc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /*
  2. * af_llc.c - LLC User Interface SAPs
  3. * Description:
  4. * Functions in this module are implementation of socket based llc
  5. * communications for the Linux operating system. Support of llc class
  6. * one and class two is provided via SOCK_DGRAM and SOCK_STREAM
  7. * respectively.
  8. *
  9. * An llc2 connection is (mac + sap), only one llc2 sap connection
  10. * is allowed per mac. Though one sap may have multiple mac + sap
  11. * connections.
  12. *
  13. * Copyright (c) 2001 by Jay Schulist <jschlst@samba.org>
  14. * 2002-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  15. *
  16. * This program can be redistributed or modified under the terms of the
  17. * GNU General Public License as published by the Free Software Foundation.
  18. * This program is distributed without any warranty or implied warranty
  19. * of merchantability or fitness for a particular purpose.
  20. *
  21. * See the GNU General Public License for more details.
  22. */
  23. #include <linux/compiler.h>
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/rtnetlink.h>
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <net/llc.h>
  30. #include <net/llc_sap.h>
  31. #include <net/llc_pdu.h>
  32. #include <net/llc_conn.h>
  33. #include <net/tcp_states.h>
  34. /* remember: uninitialized global data is zeroed because its in .bss */
  35. static u16 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
  36. static u16 llc_ui_sap_link_no_max[256];
  37. static struct sockaddr_llc llc_ui_addrnull;
  38. static const struct proto_ops llc_ui_ops;
  39. static int llc_ui_wait_for_conn(struct sock *sk, long timeout);
  40. static int llc_ui_wait_for_disc(struct sock *sk, long timeout);
  41. static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout);
  42. #if 0
  43. #define dprintk(args...) printk(KERN_DEBUG args)
  44. #else
  45. #define dprintk(args...)
  46. #endif
  47. /* Maybe we'll add some more in the future. */
  48. #define LLC_CMSG_PKTINFO 1
  49. /**
  50. * llc_ui_next_link_no - return the next unused link number for a sap
  51. * @sap: Address of sap to get link number from.
  52. *
  53. * Return the next unused link number for a given sap.
  54. */
  55. static inline u16 llc_ui_next_link_no(int sap)
  56. {
  57. return llc_ui_sap_link_no_max[sap]++;
  58. }
  59. /**
  60. * llc_proto_type - return eth protocol for ARP header type
  61. * @arphrd: ARP header type.
  62. *
  63. * Given an ARP header type return the corresponding ethernet protocol.
  64. */
  65. static inline __be16 llc_proto_type(u16 arphrd)
  66. {
  67. return htons(ETH_P_802_2);
  68. }
  69. /**
  70. * llc_ui_addr_null - determines if a address structure is null
  71. * @addr: Address to test if null.
  72. */
  73. static inline u8 llc_ui_addr_null(struct sockaddr_llc *addr)
  74. {
  75. return !memcmp(addr, &llc_ui_addrnull, sizeof(*addr));
  76. }
  77. /**
  78. * llc_ui_header_len - return length of llc header based on operation
  79. * @sk: Socket which contains a valid llc socket type.
  80. * @addr: Complete sockaddr_llc structure received from the user.
  81. *
  82. * Provide the length of the llc header depending on what kind of
  83. * operation the user would like to perform and the type of socket.
  84. * Returns the correct llc header length.
  85. */
  86. static inline u8 llc_ui_header_len(struct sock *sk, struct sockaddr_llc *addr)
  87. {
  88. u8 rc = LLC_PDU_LEN_U;
  89. if (addr->sllc_test || addr->sllc_xid)
  90. rc = LLC_PDU_LEN_U;
  91. else if (sk->sk_type == SOCK_STREAM)
  92. rc = LLC_PDU_LEN_I;
  93. return rc;
  94. }
  95. /**
  96. * llc_ui_send_data - send data via reliable llc2 connection
  97. * @sk: Connection the socket is using.
  98. * @skb: Data the user wishes to send.
  99. * @noblock: can we block waiting for data?
  100. *
  101. * Send data via reliable llc2 connection.
  102. * Returns 0 upon success, non-zero if action did not succeed.
  103. */
  104. static int llc_ui_send_data(struct sock* sk, struct sk_buff *skb, int noblock)
  105. {
  106. struct llc_sock* llc = llc_sk(sk);
  107. int rc = 0;
  108. if (unlikely(llc_data_accept_state(llc->state) ||
  109. llc->remote_busy_flag ||
  110. llc->p_flag)) {
  111. long timeout = sock_sndtimeo(sk, noblock);
  112. rc = llc_ui_wait_for_busy_core(sk, timeout);
  113. }
  114. if (unlikely(!rc))
  115. rc = llc_build_and_send_pkt(sk, skb);
  116. return rc;
  117. }
  118. static void llc_ui_sk_init(struct socket *sock, struct sock *sk)
  119. {
  120. sock_graft(sk, sock);
  121. sk->sk_type = sock->type;
  122. sock->ops = &llc_ui_ops;
  123. }
  124. static struct proto llc_proto = {
  125. .name = "LLC",
  126. .owner = THIS_MODULE,
  127. .obj_size = sizeof(struct llc_sock),
  128. .slab_flags = SLAB_DESTROY_BY_RCU,
  129. };
  130. /**
  131. * llc_ui_create - alloc and init a new llc_ui socket
  132. * @net: network namespace (must be default network)
  133. * @sock: Socket to initialize and attach allocated sk to.
  134. * @protocol: Unused.
  135. * @kern: on behalf of kernel or userspace
  136. *
  137. * Allocate and initialize a new llc_ui socket, validate the user wants a
  138. * socket type we have available.
  139. * Returns 0 upon success, negative upon failure.
  140. */
  141. static int llc_ui_create(struct net *net, struct socket *sock, int protocol,
  142. int kern)
  143. {
  144. struct sock *sk;
  145. int rc = -ESOCKTNOSUPPORT;
  146. if (!ns_capable(net->user_ns, CAP_NET_RAW))
  147. return -EPERM;
  148. if (!net_eq(net, &init_net))
  149. return -EAFNOSUPPORT;
  150. if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) {
  151. rc = -ENOMEM;
  152. sk = llc_sk_alloc(net, PF_LLC, GFP_KERNEL, &llc_proto, kern);
  153. if (sk) {
  154. rc = 0;
  155. llc_ui_sk_init(sock, sk);
  156. }
  157. }
  158. return rc;
  159. }
  160. /**
  161. * llc_ui_release - shutdown socket
  162. * @sock: Socket to release.
  163. *
  164. * Shutdown and deallocate an existing socket.
  165. */
  166. static int llc_ui_release(struct socket *sock)
  167. {
  168. struct sock *sk = sock->sk;
  169. struct llc_sock *llc;
  170. if (unlikely(sk == NULL))
  171. goto out;
  172. sock_hold(sk);
  173. lock_sock(sk);
  174. llc = llc_sk(sk);
  175. dprintk("%s: closing local(%02X) remote(%02X)\n", __func__,
  176. llc->laddr.lsap, llc->daddr.lsap);
  177. if (!llc_send_disc(sk))
  178. llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
  179. if (!sock_flag(sk, SOCK_ZAPPED)) {
  180. struct llc_sap *sap = llc->sap;
  181. /* Hold this for release_sock(), so that llc_backlog_rcv()
  182. * could still use it.
  183. */
  184. llc_sap_hold(sap);
  185. llc_sap_remove_socket(llc->sap, sk);
  186. release_sock(sk);
  187. llc_sap_put(sap);
  188. } else {
  189. release_sock(sk);
  190. }
  191. if (llc->dev)
  192. dev_put(llc->dev);
  193. sock_put(sk);
  194. llc_sk_free(sk);
  195. out:
  196. return 0;
  197. }
  198. /**
  199. * llc_ui_autoport - provide dynamically allocate SAP number
  200. *
  201. * Provide the caller with a dynamically allocated SAP number according
  202. * to the rules that are set in this function. Returns: 0, upon failure,
  203. * SAP number otherwise.
  204. */
  205. static int llc_ui_autoport(void)
  206. {
  207. struct llc_sap *sap;
  208. int i, tries = 0;
  209. while (tries < LLC_SAP_DYN_TRIES) {
  210. for (i = llc_ui_sap_last_autoport;
  211. i < LLC_SAP_DYN_STOP; i += 2) {
  212. sap = llc_sap_find(i);
  213. if (!sap) {
  214. llc_ui_sap_last_autoport = i + 2;
  215. goto out;
  216. }
  217. llc_sap_put(sap);
  218. }
  219. llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
  220. tries++;
  221. }
  222. i = 0;
  223. out:
  224. return i;
  225. }
  226. /**
  227. * llc_ui_autobind - automatically bind a socket to a sap
  228. * @sock: socket to bind
  229. * @addr: address to connect to
  230. *
  231. * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
  232. * specifically used llc_ui_bind to bind to an specific address/sap
  233. *
  234. * Returns: 0 upon success, negative otherwise.
  235. */
  236. static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
  237. {
  238. struct sock *sk = sock->sk;
  239. struct llc_sock *llc = llc_sk(sk);
  240. struct llc_sap *sap;
  241. int rc = -EINVAL;
  242. if (!sock_flag(sk, SOCK_ZAPPED))
  243. goto out;
  244. rc = -ENODEV;
  245. if (sk->sk_bound_dev_if) {
  246. llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
  247. if (llc->dev && addr->sllc_arphrd != llc->dev->type) {
  248. dev_put(llc->dev);
  249. llc->dev = NULL;
  250. }
  251. } else
  252. llc->dev = dev_getfirstbyhwtype(&init_net, addr->sllc_arphrd);
  253. if (!llc->dev)
  254. goto out;
  255. rc = -EUSERS;
  256. llc->laddr.lsap = llc_ui_autoport();
  257. if (!llc->laddr.lsap)
  258. goto out;
  259. rc = -EBUSY; /* some other network layer is using the sap */
  260. sap = llc_sap_open(llc->laddr.lsap, NULL);
  261. if (!sap)
  262. goto out;
  263. memcpy(llc->laddr.mac, llc->dev->dev_addr, IFHWADDRLEN);
  264. memcpy(&llc->addr, addr, sizeof(llc->addr));
  265. /* assign new connection to its SAP */
  266. llc_sap_add_socket(sap, sk);
  267. sock_reset_flag(sk, SOCK_ZAPPED);
  268. rc = 0;
  269. out:
  270. return rc;
  271. }
  272. /**
  273. * llc_ui_bind - bind a socket to a specific address.
  274. * @sock: Socket to bind an address to.
  275. * @uaddr: Address the user wants the socket bound to.
  276. * @addrlen: Length of the uaddr structure.
  277. *
  278. * Bind a socket to a specific address. For llc a user is able to bind to
  279. * a specific sap only or mac + sap.
  280. * If the user desires to bind to a specific mac + sap, it is possible to
  281. * have multiple sap connections via multiple macs.
  282. * Bind and autobind for that matter must enforce the correct sap usage
  283. * otherwise all hell will break loose.
  284. * Returns: 0 upon success, negative otherwise.
  285. */
  286. static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
  287. {
  288. struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
  289. struct sock *sk = sock->sk;
  290. struct llc_sock *llc = llc_sk(sk);
  291. struct llc_sap *sap;
  292. int rc = -EINVAL;
  293. dprintk("%s: binding %02X\n", __func__, addr->sllc_sap);
  294. lock_sock(sk);
  295. if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
  296. goto out;
  297. rc = -EAFNOSUPPORT;
  298. if (unlikely(addr->sllc_family != AF_LLC))
  299. goto out;
  300. rc = -ENODEV;
  301. rcu_read_lock();
  302. if (sk->sk_bound_dev_if) {
  303. llc->dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if);
  304. if (llc->dev) {
  305. if (!addr->sllc_arphrd)
  306. addr->sllc_arphrd = llc->dev->type;
  307. if (is_zero_ether_addr(addr->sllc_mac))
  308. memcpy(addr->sllc_mac, llc->dev->dev_addr,
  309. IFHWADDRLEN);
  310. if (addr->sllc_arphrd != llc->dev->type ||
  311. !ether_addr_equal(addr->sllc_mac,
  312. llc->dev->dev_addr)) {
  313. rc = -EINVAL;
  314. llc->dev = NULL;
  315. }
  316. }
  317. } else
  318. llc->dev = dev_getbyhwaddr_rcu(&init_net, addr->sllc_arphrd,
  319. addr->sllc_mac);
  320. if (llc->dev)
  321. dev_hold(llc->dev);
  322. rcu_read_unlock();
  323. if (!llc->dev)
  324. goto out;
  325. if (!addr->sllc_sap) {
  326. rc = -EUSERS;
  327. addr->sllc_sap = llc_ui_autoport();
  328. if (!addr->sllc_sap)
  329. goto out;
  330. }
  331. sap = llc_sap_find(addr->sllc_sap);
  332. if (!sap) {
  333. sap = llc_sap_open(addr->sllc_sap, NULL);
  334. rc = -EBUSY; /* some other network layer is using the sap */
  335. if (!sap)
  336. goto out;
  337. } else {
  338. struct llc_addr laddr, daddr;
  339. struct sock *ask;
  340. memset(&laddr, 0, sizeof(laddr));
  341. memset(&daddr, 0, sizeof(daddr));
  342. /*
  343. * FIXME: check if the address is multicast,
  344. * only SOCK_DGRAM can do this.
  345. */
  346. memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN);
  347. laddr.lsap = addr->sllc_sap;
  348. rc = -EADDRINUSE; /* mac + sap clash. */
  349. ask = llc_lookup_established(sap, &daddr, &laddr);
  350. if (ask) {
  351. sock_put(ask);
  352. goto out_put;
  353. }
  354. }
  355. llc->laddr.lsap = addr->sllc_sap;
  356. memcpy(llc->laddr.mac, addr->sllc_mac, IFHWADDRLEN);
  357. memcpy(&llc->addr, addr, sizeof(llc->addr));
  358. /* assign new connection to its SAP */
  359. llc_sap_add_socket(sap, sk);
  360. sock_reset_flag(sk, SOCK_ZAPPED);
  361. rc = 0;
  362. out_put:
  363. llc_sap_put(sap);
  364. out:
  365. release_sock(sk);
  366. return rc;
  367. }
  368. /**
  369. * llc_ui_shutdown - shutdown a connect llc2 socket.
  370. * @sock: Socket to shutdown.
  371. * @how: What part of the socket to shutdown.
  372. *
  373. * Shutdown a connected llc2 socket. Currently this function only supports
  374. * shutting down both sends and receives (2), we could probably make this
  375. * function such that a user can shutdown only half the connection but not
  376. * right now.
  377. * Returns: 0 upon success, negative otherwise.
  378. */
  379. static int llc_ui_shutdown(struct socket *sock, int how)
  380. {
  381. struct sock *sk = sock->sk;
  382. int rc = -ENOTCONN;
  383. lock_sock(sk);
  384. if (unlikely(sk->sk_state != TCP_ESTABLISHED))
  385. goto out;
  386. rc = -EINVAL;
  387. if (how != 2)
  388. goto out;
  389. rc = llc_send_disc(sk);
  390. if (!rc)
  391. rc = llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
  392. /* Wake up anyone sleeping in poll */
  393. sk->sk_state_change(sk);
  394. out:
  395. release_sock(sk);
  396. return rc;
  397. }
  398. /**
  399. * llc_ui_connect - Connect to a remote llc2 mac + sap.
  400. * @sock: Socket which will be connected to the remote destination.
  401. * @uaddr: Remote and possibly the local address of the new connection.
  402. * @addrlen: Size of uaddr structure.
  403. * @flags: Operational flags specified by the user.
  404. *
  405. * Connect to a remote llc2 mac + sap. The caller must specify the
  406. * destination mac and address to connect to. If the user hasn't previously
  407. * called bind(2) with a smac the address of the first interface of the
  408. * specified arp type will be used.
  409. * This function will autobind if user did not previously call bind.
  410. * Returns: 0 upon success, negative otherwise.
  411. */
  412. static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
  413. int addrlen, int flags)
  414. {
  415. struct sock *sk = sock->sk;
  416. struct llc_sock *llc = llc_sk(sk);
  417. struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
  418. int rc = -EINVAL;
  419. lock_sock(sk);
  420. if (unlikely(addrlen != sizeof(*addr)))
  421. goto out;
  422. rc = -EAFNOSUPPORT;
  423. if (unlikely(addr->sllc_family != AF_LLC))
  424. goto out;
  425. if (unlikely(sk->sk_type != SOCK_STREAM))
  426. goto out;
  427. rc = -EALREADY;
  428. if (unlikely(sock->state == SS_CONNECTING))
  429. goto out;
  430. /* bind connection to sap if user hasn't done it. */
  431. if (sock_flag(sk, SOCK_ZAPPED)) {
  432. /* bind to sap with null dev, exclusive */
  433. rc = llc_ui_autobind(sock, addr);
  434. if (rc)
  435. goto out;
  436. }
  437. llc->daddr.lsap = addr->sllc_sap;
  438. memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
  439. sock->state = SS_CONNECTING;
  440. sk->sk_state = TCP_SYN_SENT;
  441. llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
  442. rc = llc_establish_connection(sk, llc->dev->dev_addr,
  443. addr->sllc_mac, addr->sllc_sap);
  444. if (rc) {
  445. dprintk("%s: llc_ui_send_conn failed :-(\n", __func__);
  446. sock->state = SS_UNCONNECTED;
  447. sk->sk_state = TCP_CLOSE;
  448. goto out;
  449. }
  450. if (sk->sk_state == TCP_SYN_SENT) {
  451. const long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
  452. if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
  453. goto out;
  454. rc = sock_intr_errno(timeo);
  455. if (signal_pending(current))
  456. goto out;
  457. }
  458. if (sk->sk_state == TCP_CLOSE)
  459. goto sock_error;
  460. sock->state = SS_CONNECTED;
  461. rc = 0;
  462. out:
  463. release_sock(sk);
  464. return rc;
  465. sock_error:
  466. rc = sock_error(sk) ? : -ECONNABORTED;
  467. sock->state = SS_UNCONNECTED;
  468. goto out;
  469. }
  470. /**
  471. * llc_ui_listen - allow a normal socket to accept incoming connections
  472. * @sock: Socket to allow incoming connections on.
  473. * @backlog: Number of connections to queue.
  474. *
  475. * Allow a normal socket to accept incoming connections.
  476. * Returns 0 upon success, negative otherwise.
  477. */
  478. static int llc_ui_listen(struct socket *sock, int backlog)
  479. {
  480. struct sock *sk = sock->sk;
  481. int rc = -EINVAL;
  482. lock_sock(sk);
  483. if (unlikely(sock->state != SS_UNCONNECTED))
  484. goto out;
  485. rc = -EOPNOTSUPP;
  486. if (unlikely(sk->sk_type != SOCK_STREAM))
  487. goto out;
  488. rc = -EAGAIN;
  489. if (sock_flag(sk, SOCK_ZAPPED))
  490. goto out;
  491. rc = 0;
  492. if (!(unsigned int)backlog) /* BSDism */
  493. backlog = 1;
  494. sk->sk_max_ack_backlog = backlog;
  495. if (sk->sk_state != TCP_LISTEN) {
  496. sk->sk_ack_backlog = 0;
  497. sk->sk_state = TCP_LISTEN;
  498. }
  499. sk->sk_socket->flags |= __SO_ACCEPTCON;
  500. out:
  501. release_sock(sk);
  502. return rc;
  503. }
  504. static int llc_ui_wait_for_disc(struct sock *sk, long timeout)
  505. {
  506. DEFINE_WAIT(wait);
  507. int rc = 0;
  508. while (1) {
  509. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  510. if (sk_wait_event(sk, &timeout, sk->sk_state == TCP_CLOSE))
  511. break;
  512. rc = -ERESTARTSYS;
  513. if (signal_pending(current))
  514. break;
  515. rc = -EAGAIN;
  516. if (!timeout)
  517. break;
  518. rc = 0;
  519. }
  520. finish_wait(sk_sleep(sk), &wait);
  521. return rc;
  522. }
  523. static int llc_ui_wait_for_conn(struct sock *sk, long timeout)
  524. {
  525. DEFINE_WAIT(wait);
  526. while (1) {
  527. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  528. if (sk_wait_event(sk, &timeout, sk->sk_state != TCP_SYN_SENT))
  529. break;
  530. if (signal_pending(current) || !timeout)
  531. break;
  532. }
  533. finish_wait(sk_sleep(sk), &wait);
  534. return timeout;
  535. }
  536. static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout)
  537. {
  538. DEFINE_WAIT(wait);
  539. struct llc_sock *llc = llc_sk(sk);
  540. int rc;
  541. while (1) {
  542. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  543. rc = 0;
  544. if (sk_wait_event(sk, &timeout,
  545. (sk->sk_shutdown & RCV_SHUTDOWN) ||
  546. (!llc_data_accept_state(llc->state) &&
  547. !llc->remote_busy_flag &&
  548. !llc->p_flag)))
  549. break;
  550. rc = -ERESTARTSYS;
  551. if (signal_pending(current))
  552. break;
  553. rc = -EAGAIN;
  554. if (!timeout)
  555. break;
  556. }
  557. finish_wait(sk_sleep(sk), &wait);
  558. return rc;
  559. }
  560. static int llc_wait_data(struct sock *sk, long timeo)
  561. {
  562. int rc;
  563. while (1) {
  564. /*
  565. * POSIX 1003.1g mandates this order.
  566. */
  567. rc = sock_error(sk);
  568. if (rc)
  569. break;
  570. rc = 0;
  571. if (sk->sk_shutdown & RCV_SHUTDOWN)
  572. break;
  573. rc = -EAGAIN;
  574. if (!timeo)
  575. break;
  576. rc = sock_intr_errno(timeo);
  577. if (signal_pending(current))
  578. break;
  579. rc = 0;
  580. if (sk_wait_data(sk, &timeo, NULL))
  581. break;
  582. }
  583. return rc;
  584. }
  585. static void llc_cmsg_rcv(struct msghdr *msg, struct sk_buff *skb)
  586. {
  587. struct llc_sock *llc = llc_sk(skb->sk);
  588. if (llc->cmsg_flags & LLC_CMSG_PKTINFO) {
  589. struct llc_pktinfo info;
  590. memset(&info, 0, sizeof(info));
  591. info.lpi_ifindex = llc_sk(skb->sk)->dev->ifindex;
  592. llc_pdu_decode_dsap(skb, &info.lpi_sap);
  593. llc_pdu_decode_da(skb, info.lpi_mac);
  594. put_cmsg(msg, SOL_LLC, LLC_OPT_PKTINFO, sizeof(info), &info);
  595. }
  596. }
  597. /**
  598. * llc_ui_accept - accept a new incoming connection.
  599. * @sock: Socket which connections arrive on.
  600. * @newsock: Socket to move incoming connection to.
  601. * @flags: User specified operational flags.
  602. *
  603. * Accept a new incoming connection.
  604. * Returns 0 upon success, negative otherwise.
  605. */
  606. static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
  607. {
  608. struct sock *sk = sock->sk, *newsk;
  609. struct llc_sock *llc, *newllc;
  610. struct sk_buff *skb;
  611. int rc = -EOPNOTSUPP;
  612. dprintk("%s: accepting on %02X\n", __func__,
  613. llc_sk(sk)->laddr.lsap);
  614. lock_sock(sk);
  615. if (unlikely(sk->sk_type != SOCK_STREAM))
  616. goto out;
  617. rc = -EINVAL;
  618. if (unlikely(sock->state != SS_UNCONNECTED ||
  619. sk->sk_state != TCP_LISTEN))
  620. goto out;
  621. /* wait for a connection to arrive. */
  622. if (skb_queue_empty(&sk->sk_receive_queue)) {
  623. rc = llc_wait_data(sk, sk->sk_rcvtimeo);
  624. if (rc)
  625. goto out;
  626. }
  627. dprintk("%s: got a new connection on %02X\n", __func__,
  628. llc_sk(sk)->laddr.lsap);
  629. skb = skb_dequeue(&sk->sk_receive_queue);
  630. rc = -EINVAL;
  631. if (!skb->sk)
  632. goto frees;
  633. rc = 0;
  634. newsk = skb->sk;
  635. /* attach connection to a new socket. */
  636. llc_ui_sk_init(newsock, newsk);
  637. sock_reset_flag(newsk, SOCK_ZAPPED);
  638. newsk->sk_state = TCP_ESTABLISHED;
  639. newsock->state = SS_CONNECTED;
  640. llc = llc_sk(sk);
  641. newllc = llc_sk(newsk);
  642. memcpy(&newllc->addr, &llc->addr, sizeof(newllc->addr));
  643. newllc->link = llc_ui_next_link_no(newllc->laddr.lsap);
  644. /* put original socket back into a clean listen state. */
  645. sk->sk_state = TCP_LISTEN;
  646. sk->sk_ack_backlog--;
  647. dprintk("%s: ok success on %02X, client on %02X\n", __func__,
  648. llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap);
  649. frees:
  650. kfree_skb(skb);
  651. out:
  652. release_sock(sk);
  653. return rc;
  654. }
  655. /**
  656. * llc_ui_recvmsg - copy received data to the socket user.
  657. * @sock: Socket to copy data from.
  658. * @msg: Various user space related information.
  659. * @len: Size of user buffer.
  660. * @flags: User specified flags.
  661. *
  662. * Copy received data to the socket user.
  663. * Returns non-negative upon success, negative otherwise.
  664. */
  665. static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
  666. int flags)
  667. {
  668. DECLARE_SOCKADDR(struct sockaddr_llc *, uaddr, msg->msg_name);
  669. const int nonblock = flags & MSG_DONTWAIT;
  670. struct sk_buff *skb = NULL;
  671. struct sock *sk = sock->sk;
  672. struct llc_sock *llc = llc_sk(sk);
  673. size_t copied = 0;
  674. u32 peek_seq = 0;
  675. u32 *seq, skb_len;
  676. unsigned long used;
  677. int target; /* Read at least this many bytes */
  678. long timeo;
  679. lock_sock(sk);
  680. copied = -ENOTCONN;
  681. if (unlikely(sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN))
  682. goto out;
  683. timeo = sock_rcvtimeo(sk, nonblock);
  684. seq = &llc->copied_seq;
  685. if (flags & MSG_PEEK) {
  686. peek_seq = llc->copied_seq;
  687. seq = &peek_seq;
  688. }
  689. target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
  690. copied = 0;
  691. do {
  692. u32 offset;
  693. /*
  694. * We need to check signals first, to get correct SIGURG
  695. * handling. FIXME: Need to check this doesn't impact 1003.1g
  696. * and move it down to the bottom of the loop
  697. */
  698. if (signal_pending(current)) {
  699. if (copied)
  700. break;
  701. copied = timeo ? sock_intr_errno(timeo) : -EAGAIN;
  702. break;
  703. }
  704. /* Next get a buffer. */
  705. skb = skb_peek(&sk->sk_receive_queue);
  706. if (skb) {
  707. offset = *seq;
  708. goto found_ok_skb;
  709. }
  710. /* Well, if we have backlog, try to process it now yet. */
  711. if (copied >= target && !sk->sk_backlog.tail)
  712. break;
  713. if (copied) {
  714. if (sk->sk_err ||
  715. sk->sk_state == TCP_CLOSE ||
  716. (sk->sk_shutdown & RCV_SHUTDOWN) ||
  717. !timeo ||
  718. (flags & MSG_PEEK))
  719. break;
  720. } else {
  721. if (sock_flag(sk, SOCK_DONE))
  722. break;
  723. if (sk->sk_err) {
  724. copied = sock_error(sk);
  725. break;
  726. }
  727. if (sk->sk_shutdown & RCV_SHUTDOWN)
  728. break;
  729. if (sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_CLOSE) {
  730. if (!sock_flag(sk, SOCK_DONE)) {
  731. /*
  732. * This occurs when user tries to read
  733. * from never connected socket.
  734. */
  735. copied = -ENOTCONN;
  736. break;
  737. }
  738. break;
  739. }
  740. if (!timeo) {
  741. copied = -EAGAIN;
  742. break;
  743. }
  744. }
  745. if (copied >= target) { /* Do not sleep, just process backlog. */
  746. release_sock(sk);
  747. lock_sock(sk);
  748. } else
  749. sk_wait_data(sk, &timeo, NULL);
  750. if ((flags & MSG_PEEK) && peek_seq != llc->copied_seq) {
  751. net_dbg_ratelimited("LLC(%s:%d): Application bug, race in MSG_PEEK\n",
  752. current->comm,
  753. task_pid_nr(current));
  754. peek_seq = llc->copied_seq;
  755. }
  756. continue;
  757. found_ok_skb:
  758. skb_len = skb->len;
  759. /* Ok so how much can we use? */
  760. used = skb->len - offset;
  761. if (len < used)
  762. used = len;
  763. if (!(flags & MSG_TRUNC)) {
  764. int rc = skb_copy_datagram_msg(skb, offset, msg, used);
  765. if (rc) {
  766. /* Exception. Bailout! */
  767. if (!copied)
  768. copied = -EFAULT;
  769. break;
  770. }
  771. }
  772. *seq += used;
  773. copied += used;
  774. len -= used;
  775. /* For non stream protcols we get one packet per recvmsg call */
  776. if (sk->sk_type != SOCK_STREAM)
  777. goto copy_uaddr;
  778. if (!(flags & MSG_PEEK)) {
  779. skb_unlink(skb, &sk->sk_receive_queue);
  780. kfree_skb(skb);
  781. *seq = 0;
  782. }
  783. /* Partial read */
  784. if (used + offset < skb_len)
  785. continue;
  786. } while (len > 0);
  787. out:
  788. release_sock(sk);
  789. return copied;
  790. copy_uaddr:
  791. if (uaddr != NULL && skb != NULL) {
  792. memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
  793. msg->msg_namelen = sizeof(*uaddr);
  794. }
  795. if (llc_sk(sk)->cmsg_flags)
  796. llc_cmsg_rcv(msg, skb);
  797. if (!(flags & MSG_PEEK)) {
  798. skb_unlink(skb, &sk->sk_receive_queue);
  799. kfree_skb(skb);
  800. *seq = 0;
  801. }
  802. goto out;
  803. }
  804. /**
  805. * llc_ui_sendmsg - Transmit data provided by the socket user.
  806. * @sock: Socket to transmit data from.
  807. * @msg: Various user related information.
  808. * @len: Length of data to transmit.
  809. *
  810. * Transmit data provided by the socket user.
  811. * Returns non-negative upon success, negative otherwise.
  812. */
  813. static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
  814. {
  815. struct sock *sk = sock->sk;
  816. struct llc_sock *llc = llc_sk(sk);
  817. DECLARE_SOCKADDR(struct sockaddr_llc *, addr, msg->msg_name);
  818. int flags = msg->msg_flags;
  819. int noblock = flags & MSG_DONTWAIT;
  820. struct sk_buff *skb;
  821. size_t size = 0;
  822. int rc = -EINVAL, copied = 0, hdrlen;
  823. dprintk("%s: sending from %02X to %02X\n", __func__,
  824. llc->laddr.lsap, llc->daddr.lsap);
  825. lock_sock(sk);
  826. if (addr) {
  827. if (msg->msg_namelen < sizeof(*addr))
  828. goto release;
  829. } else {
  830. if (llc_ui_addr_null(&llc->addr))
  831. goto release;
  832. addr = &llc->addr;
  833. }
  834. /* must bind connection to sap if user hasn't done it. */
  835. if (sock_flag(sk, SOCK_ZAPPED)) {
  836. /* bind to sap with null dev, exclusive. */
  837. rc = llc_ui_autobind(sock, addr);
  838. if (rc)
  839. goto release;
  840. }
  841. hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
  842. size = hdrlen + len;
  843. if (size > llc->dev->mtu)
  844. size = llc->dev->mtu;
  845. copied = size - hdrlen;
  846. rc = -EINVAL;
  847. if (copied < 0)
  848. goto release;
  849. release_sock(sk);
  850. skb = sock_alloc_send_skb(sk, size, noblock, &rc);
  851. lock_sock(sk);
  852. if (!skb)
  853. goto release;
  854. skb->dev = llc->dev;
  855. skb->protocol = llc_proto_type(addr->sllc_arphrd);
  856. skb_reserve(skb, hdrlen);
  857. rc = memcpy_from_msg(skb_put(skb, copied), msg, copied);
  858. if (rc)
  859. goto out;
  860. if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
  861. llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
  862. addr->sllc_sap);
  863. goto out;
  864. }
  865. if (addr->sllc_test) {
  866. llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
  867. addr->sllc_sap);
  868. goto out;
  869. }
  870. if (addr->sllc_xid) {
  871. llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
  872. addr->sllc_sap);
  873. goto out;
  874. }
  875. rc = -ENOPROTOOPT;
  876. if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
  877. goto out;
  878. rc = llc_ui_send_data(sk, skb, noblock);
  879. out:
  880. if (rc) {
  881. kfree_skb(skb);
  882. release:
  883. dprintk("%s: failed sending from %02X to %02X: %d\n",
  884. __func__, llc->laddr.lsap, llc->daddr.lsap, rc);
  885. }
  886. release_sock(sk);
  887. return rc ? : copied;
  888. }
  889. /**
  890. * llc_ui_getname - return the address info of a socket
  891. * @sock: Socket to get address of.
  892. * @uaddr: Address structure to return information.
  893. * @uaddrlen: Length of address structure.
  894. * @peer: Does user want local or remote address information.
  895. *
  896. * Return the address information of a socket.
  897. */
  898. static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
  899. int *uaddrlen, int peer)
  900. {
  901. struct sockaddr_llc sllc;
  902. struct sock *sk = sock->sk;
  903. struct llc_sock *llc = llc_sk(sk);
  904. int rc = -EBADF;
  905. memset(&sllc, 0, sizeof(sllc));
  906. lock_sock(sk);
  907. if (sock_flag(sk, SOCK_ZAPPED))
  908. goto out;
  909. *uaddrlen = sizeof(sllc);
  910. if (peer) {
  911. rc = -ENOTCONN;
  912. if (sk->sk_state != TCP_ESTABLISHED)
  913. goto out;
  914. if(llc->dev)
  915. sllc.sllc_arphrd = llc->dev->type;
  916. sllc.sllc_sap = llc->daddr.lsap;
  917. memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN);
  918. } else {
  919. rc = -EINVAL;
  920. if (!llc->sap)
  921. goto out;
  922. sllc.sllc_sap = llc->sap->laddr.lsap;
  923. if (llc->dev) {
  924. sllc.sllc_arphrd = llc->dev->type;
  925. memcpy(&sllc.sllc_mac, llc->dev->dev_addr,
  926. IFHWADDRLEN);
  927. }
  928. }
  929. rc = 0;
  930. sllc.sllc_family = AF_LLC;
  931. memcpy(uaddr, &sllc, sizeof(sllc));
  932. out:
  933. release_sock(sk);
  934. return rc;
  935. }
  936. /**
  937. * llc_ui_ioctl - io controls for PF_LLC
  938. * @sock: Socket to get/set info
  939. * @cmd: command
  940. * @arg: optional argument for cmd
  941. *
  942. * get/set info on llc sockets
  943. */
  944. static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
  945. unsigned long arg)
  946. {
  947. return -ENOIOCTLCMD;
  948. }
  949. /**
  950. * llc_ui_setsockopt - set various connection specific parameters.
  951. * @sock: Socket to set options on.
  952. * @level: Socket level user is requesting operations on.
  953. * @optname: Operation name.
  954. * @optval: User provided operation data.
  955. * @optlen: Length of optval.
  956. *
  957. * Set various connection specific parameters.
  958. */
  959. static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
  960. char __user *optval, unsigned int optlen)
  961. {
  962. struct sock *sk = sock->sk;
  963. struct llc_sock *llc = llc_sk(sk);
  964. unsigned int opt;
  965. int rc = -EINVAL;
  966. lock_sock(sk);
  967. if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
  968. goto out;
  969. rc = get_user(opt, (int __user *)optval);
  970. if (rc)
  971. goto out;
  972. rc = -EINVAL;
  973. switch (optname) {
  974. case LLC_OPT_RETRY:
  975. if (opt > LLC_OPT_MAX_RETRY)
  976. goto out;
  977. llc->n2 = opt;
  978. break;
  979. case LLC_OPT_SIZE:
  980. if (opt > LLC_OPT_MAX_SIZE)
  981. goto out;
  982. llc->n1 = opt;
  983. break;
  984. case LLC_OPT_ACK_TMR_EXP:
  985. if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
  986. goto out;
  987. llc->ack_timer.expire = opt * HZ;
  988. break;
  989. case LLC_OPT_P_TMR_EXP:
  990. if (opt > LLC_OPT_MAX_P_TMR_EXP)
  991. goto out;
  992. llc->pf_cycle_timer.expire = opt * HZ;
  993. break;
  994. case LLC_OPT_REJ_TMR_EXP:
  995. if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
  996. goto out;
  997. llc->rej_sent_timer.expire = opt * HZ;
  998. break;
  999. case LLC_OPT_BUSY_TMR_EXP:
  1000. if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
  1001. goto out;
  1002. llc->busy_state_timer.expire = opt * HZ;
  1003. break;
  1004. case LLC_OPT_TX_WIN:
  1005. if (opt > LLC_OPT_MAX_WIN)
  1006. goto out;
  1007. llc->k = opt;
  1008. break;
  1009. case LLC_OPT_RX_WIN:
  1010. if (opt > LLC_OPT_MAX_WIN)
  1011. goto out;
  1012. llc->rw = opt;
  1013. break;
  1014. case LLC_OPT_PKTINFO:
  1015. if (opt)
  1016. llc->cmsg_flags |= LLC_CMSG_PKTINFO;
  1017. else
  1018. llc->cmsg_flags &= ~LLC_CMSG_PKTINFO;
  1019. break;
  1020. default:
  1021. rc = -ENOPROTOOPT;
  1022. goto out;
  1023. }
  1024. rc = 0;
  1025. out:
  1026. release_sock(sk);
  1027. return rc;
  1028. }
  1029. /**
  1030. * llc_ui_getsockopt - get connection specific socket info
  1031. * @sock: Socket to get information from.
  1032. * @level: Socket level user is requesting operations on.
  1033. * @optname: Operation name.
  1034. * @optval: Variable to return operation data in.
  1035. * @optlen: Length of optval.
  1036. *
  1037. * Get connection specific socket information.
  1038. */
  1039. static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
  1040. char __user *optval, int __user *optlen)
  1041. {
  1042. struct sock *sk = sock->sk;
  1043. struct llc_sock *llc = llc_sk(sk);
  1044. int val = 0, len = 0, rc = -EINVAL;
  1045. lock_sock(sk);
  1046. if (unlikely(level != SOL_LLC))
  1047. goto out;
  1048. rc = get_user(len, optlen);
  1049. if (rc)
  1050. goto out;
  1051. rc = -EINVAL;
  1052. if (len != sizeof(int))
  1053. goto out;
  1054. switch (optname) {
  1055. case LLC_OPT_RETRY:
  1056. val = llc->n2; break;
  1057. case LLC_OPT_SIZE:
  1058. val = llc->n1; break;
  1059. case LLC_OPT_ACK_TMR_EXP:
  1060. val = llc->ack_timer.expire / HZ; break;
  1061. case LLC_OPT_P_TMR_EXP:
  1062. val = llc->pf_cycle_timer.expire / HZ; break;
  1063. case LLC_OPT_REJ_TMR_EXP:
  1064. val = llc->rej_sent_timer.expire / HZ; break;
  1065. case LLC_OPT_BUSY_TMR_EXP:
  1066. val = llc->busy_state_timer.expire / HZ; break;
  1067. case LLC_OPT_TX_WIN:
  1068. val = llc->k; break;
  1069. case LLC_OPT_RX_WIN:
  1070. val = llc->rw; break;
  1071. case LLC_OPT_PKTINFO:
  1072. val = (llc->cmsg_flags & LLC_CMSG_PKTINFO) != 0;
  1073. break;
  1074. default:
  1075. rc = -ENOPROTOOPT;
  1076. goto out;
  1077. }
  1078. rc = 0;
  1079. if (put_user(len, optlen) || copy_to_user(optval, &val, len))
  1080. rc = -EFAULT;
  1081. out:
  1082. release_sock(sk);
  1083. return rc;
  1084. }
  1085. static const struct net_proto_family llc_ui_family_ops = {
  1086. .family = PF_LLC,
  1087. .create = llc_ui_create,
  1088. .owner = THIS_MODULE,
  1089. };
  1090. static const struct proto_ops llc_ui_ops = {
  1091. .family = PF_LLC,
  1092. .owner = THIS_MODULE,
  1093. .release = llc_ui_release,
  1094. .bind = llc_ui_bind,
  1095. .connect = llc_ui_connect,
  1096. .socketpair = sock_no_socketpair,
  1097. .accept = llc_ui_accept,
  1098. .getname = llc_ui_getname,
  1099. .poll = datagram_poll,
  1100. .ioctl = llc_ui_ioctl,
  1101. .listen = llc_ui_listen,
  1102. .shutdown = llc_ui_shutdown,
  1103. .setsockopt = llc_ui_setsockopt,
  1104. .getsockopt = llc_ui_getsockopt,
  1105. .sendmsg = llc_ui_sendmsg,
  1106. .recvmsg = llc_ui_recvmsg,
  1107. .mmap = sock_no_mmap,
  1108. .sendpage = sock_no_sendpage,
  1109. };
  1110. static const char llc_proc_err_msg[] __initconst =
  1111. KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
  1112. static const char llc_sysctl_err_msg[] __initconst =
  1113. KERN_CRIT "LLC: Unable to register the sysctl entries\n";
  1114. static const char llc_sock_err_msg[] __initconst =
  1115. KERN_CRIT "LLC: Unable to register the network family\n";
  1116. static int __init llc2_init(void)
  1117. {
  1118. int rc = proto_register(&llc_proto, 0);
  1119. if (rc != 0)
  1120. goto out;
  1121. llc_build_offset_table();
  1122. llc_station_init();
  1123. llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
  1124. rc = llc_proc_init();
  1125. if (rc != 0) {
  1126. printk(llc_proc_err_msg);
  1127. goto out_station;
  1128. }
  1129. rc = llc_sysctl_init();
  1130. if (rc) {
  1131. printk(llc_sysctl_err_msg);
  1132. goto out_proc;
  1133. }
  1134. rc = sock_register(&llc_ui_family_ops);
  1135. if (rc) {
  1136. printk(llc_sock_err_msg);
  1137. goto out_sysctl;
  1138. }
  1139. llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
  1140. llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
  1141. out:
  1142. return rc;
  1143. out_sysctl:
  1144. llc_sysctl_exit();
  1145. out_proc:
  1146. llc_proc_exit();
  1147. out_station:
  1148. llc_station_exit();
  1149. proto_unregister(&llc_proto);
  1150. goto out;
  1151. }
  1152. static void __exit llc2_exit(void)
  1153. {
  1154. llc_station_exit();
  1155. llc_remove_pack(LLC_DEST_SAP);
  1156. llc_remove_pack(LLC_DEST_CONN);
  1157. sock_unregister(PF_LLC);
  1158. llc_proc_exit();
  1159. llc_sysctl_exit();
  1160. proto_unregister(&llc_proto);
  1161. }
  1162. module_init(llc2_init);
  1163. module_exit(llc2_exit);
  1164. MODULE_LICENSE("GPL");
  1165. MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
  1166. MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
  1167. MODULE_ALIAS_NETPROTO(PF_LLC);