af_llc.c 31 KB

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