af_llc.c 31 KB

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