af_llc.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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 arphrd == ARPHRD_IEEE802_TR ?
  68. htons(ETH_P_TR_802_2) : 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. static int llc_ui_send_data(struct sock* sk, struct sk_buff *skb, int noblock)
  106. {
  107. struct llc_sock* llc = llc_sk(sk);
  108. int rc = 0;
  109. if (unlikely(llc_data_accept_state(llc->state) ||
  110. llc->remote_busy_flag ||
  111. llc->p_flag)) {
  112. long timeout = sock_sndtimeo(sk, noblock);
  113. rc = llc_ui_wait_for_busy_core(sk, timeout);
  114. }
  115. if (unlikely(!rc))
  116. rc = llc_build_and_send_pkt(sk, skb);
  117. return rc;
  118. }
  119. static void llc_ui_sk_init(struct socket *sock, struct sock *sk)
  120. {
  121. sock_graft(sk, sock);
  122. sk->sk_type = sock->type;
  123. sock->ops = &llc_ui_ops;
  124. }
  125. static struct proto llc_proto = {
  126. .name = "LLC",
  127. .owner = THIS_MODULE,
  128. .obj_size = sizeof(struct llc_sock),
  129. .slab_flags = SLAB_DESTROY_BY_RCU,
  130. };
  131. /**
  132. * llc_ui_create - alloc and init a new llc_ui socket
  133. * @net: network namespace (must be default network)
  134. * @sock: Socket to initialize and attach allocated sk to.
  135. * @protocol: Unused.
  136. * @kern: on behalf of kernel or userspace
  137. *
  138. * Allocate and initialize a new llc_ui socket, validate the user wants a
  139. * socket type we have available.
  140. * Returns 0 upon success, negative upon failure.
  141. */
  142. static int llc_ui_create(struct net *net, struct socket *sock, int protocol,
  143. int kern)
  144. {
  145. struct sock *sk;
  146. int rc = -ESOCKTNOSUPPORT;
  147. if (!capable(CAP_NET_RAW))
  148. return -EPERM;
  149. if (!net_eq(net, &init_net))
  150. return -EAFNOSUPPORT;
  151. if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) {
  152. rc = -ENOMEM;
  153. sk = llc_sk_alloc(net, PF_LLC, GFP_KERNEL, &llc_proto);
  154. if (sk) {
  155. rc = 0;
  156. llc_ui_sk_init(sock, sk);
  157. }
  158. }
  159. return rc;
  160. }
  161. /**
  162. * llc_ui_release - shutdown socket
  163. * @sock: Socket to release.
  164. *
  165. * Shutdown and deallocate an existing socket.
  166. */
  167. static int llc_ui_release(struct socket *sock)
  168. {
  169. struct sock *sk = sock->sk;
  170. struct llc_sock *llc;
  171. if (unlikely(sk == NULL))
  172. goto out;
  173. sock_hold(sk);
  174. lock_sock(sk);
  175. llc = llc_sk(sk);
  176. dprintk("%s: closing local(%02X) remote(%02X)\n", __func__,
  177. llc->laddr.lsap, llc->daddr.lsap);
  178. if (!llc_send_disc(sk))
  179. llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
  180. if (!sock_flag(sk, SOCK_ZAPPED))
  181. llc_sap_remove_socket(llc->sap, sk);
  182. release_sock(sk);
  183. if (llc->dev)
  184. dev_put(llc->dev);
  185. sock_put(sk);
  186. llc_sk_free(sk);
  187. out:
  188. return 0;
  189. }
  190. /**
  191. * llc_ui_autoport - provide dynamically allocate SAP number
  192. *
  193. * Provide the caller with a dynamically allocated SAP number according
  194. * to the rules that are set in this function. Returns: 0, upon failure,
  195. * SAP number otherwise.
  196. */
  197. static int llc_ui_autoport(void)
  198. {
  199. struct llc_sap *sap;
  200. int i, tries = 0;
  201. while (tries < LLC_SAP_DYN_TRIES) {
  202. for (i = llc_ui_sap_last_autoport;
  203. i < LLC_SAP_DYN_STOP; i += 2) {
  204. sap = llc_sap_find(i);
  205. if (!sap) {
  206. llc_ui_sap_last_autoport = i + 2;
  207. goto out;
  208. }
  209. llc_sap_put(sap);
  210. }
  211. llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
  212. tries++;
  213. }
  214. i = 0;
  215. out:
  216. return i;
  217. }
  218. /**
  219. * llc_ui_autobind - automatically bind a socket to a sap
  220. * @sock: socket to bind
  221. * @addr: address to connect to
  222. *
  223. * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
  224. * specifically used llc_ui_bind to bind to an specific address/sap
  225. *
  226. * Returns: 0 upon success, negative otherwise.
  227. */
  228. static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
  229. {
  230. struct sock *sk = sock->sk;
  231. struct llc_sock *llc = llc_sk(sk);
  232. struct llc_sap *sap;
  233. int rc = -EINVAL;
  234. if (!sock_flag(sk, SOCK_ZAPPED))
  235. goto out;
  236. rc = -ENODEV;
  237. if (sk->sk_bound_dev_if) {
  238. llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if);
  239. if (llc->dev && addr->sllc_arphrd != llc->dev->type) {
  240. dev_put(llc->dev);
  241. llc->dev = NULL;
  242. }
  243. } else
  244. llc->dev = dev_getfirstbyhwtype(&init_net, addr->sllc_arphrd);
  245. if (!llc->dev)
  246. goto out;
  247. rc = -EUSERS;
  248. llc->laddr.lsap = llc_ui_autoport();
  249. if (!llc->laddr.lsap)
  250. goto out;
  251. rc = -EBUSY; /* some other network layer is using the sap */
  252. sap = llc_sap_open(llc->laddr.lsap, NULL);
  253. if (!sap)
  254. goto out;
  255. memcpy(llc->laddr.mac, llc->dev->dev_addr, IFHWADDRLEN);
  256. memcpy(&llc->addr, addr, sizeof(llc->addr));
  257. /* assign new connection to its SAP */
  258. llc_sap_add_socket(sap, sk);
  259. sock_reset_flag(sk, SOCK_ZAPPED);
  260. rc = 0;
  261. out:
  262. return rc;
  263. }
  264. /**
  265. * llc_ui_bind - bind a socket to a specific address.
  266. * @sock: Socket to bind an address to.
  267. * @uaddr: Address the user wants the socket bound to.
  268. * @addrlen: Length of the uaddr structure.
  269. *
  270. * Bind a socket to a specific address. For llc a user is able to bind to
  271. * a specific sap only or mac + sap.
  272. * If the user desires to bind to a specific mac + sap, it is possible to
  273. * have multiple sap connections via multiple macs.
  274. * Bind and autobind for that matter must enforce the correct sap usage
  275. * otherwise all hell will break loose.
  276. * Returns: 0 upon success, negative otherwise.
  277. */
  278. static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
  279. {
  280. struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
  281. struct sock *sk = sock->sk;
  282. struct llc_sock *llc = llc_sk(sk);
  283. struct llc_sap *sap;
  284. int rc = -EINVAL;
  285. dprintk("%s: binding %02X\n", __func__, addr->sllc_sap);
  286. if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
  287. goto out;
  288. rc = -EAFNOSUPPORT;
  289. if (unlikely(addr->sllc_family != AF_LLC))
  290. goto out;
  291. rc = -ENODEV;
  292. rcu_read_lock();
  293. if (sk->sk_bound_dev_if) {
  294. llc->dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if);
  295. if (llc->dev) {
  296. if (!addr->sllc_arphrd)
  297. addr->sllc_arphrd = llc->dev->type;
  298. if (llc_mac_null(addr->sllc_mac))
  299. memcpy(addr->sllc_mac, llc->dev->dev_addr,
  300. IFHWADDRLEN);
  301. if (addr->sllc_arphrd != llc->dev->type ||
  302. !llc_mac_match(addr->sllc_mac,
  303. llc->dev->dev_addr)) {
  304. rc = -EINVAL;
  305. llc->dev = NULL;
  306. }
  307. }
  308. } else
  309. llc->dev = dev_getbyhwaddr_rcu(&init_net, addr->sllc_arphrd,
  310. addr->sllc_mac);
  311. if (llc->dev)
  312. dev_hold(llc->dev);
  313. rcu_read_unlock();
  314. if (!llc->dev)
  315. goto out;
  316. if (!addr->sllc_sap) {
  317. rc = -EUSERS;
  318. addr->sllc_sap = llc_ui_autoport();
  319. if (!addr->sllc_sap)
  320. goto out;
  321. }
  322. sap = llc_sap_find(addr->sllc_sap);
  323. if (!sap) {
  324. sap = llc_sap_open(addr->sllc_sap, NULL);
  325. rc = -EBUSY; /* some other network layer is using the sap */
  326. if (!sap)
  327. goto out;
  328. } else {
  329. struct llc_addr laddr, daddr;
  330. struct sock *ask;
  331. memset(&laddr, 0, sizeof(laddr));
  332. memset(&daddr, 0, sizeof(daddr));
  333. /*
  334. * FIXME: check if the address is multicast,
  335. * only SOCK_DGRAM can do this.
  336. */
  337. memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN);
  338. laddr.lsap = addr->sllc_sap;
  339. rc = -EADDRINUSE; /* mac + sap clash. */
  340. ask = llc_lookup_established(sap, &daddr, &laddr);
  341. if (ask) {
  342. sock_put(ask);
  343. goto out_put;
  344. }
  345. }
  346. llc->laddr.lsap = addr->sllc_sap;
  347. memcpy(llc->laddr.mac, addr->sllc_mac, IFHWADDRLEN);
  348. memcpy(&llc->addr, addr, sizeof(llc->addr));
  349. /* assign new connection to its SAP */
  350. llc_sap_add_socket(sap, sk);
  351. sock_reset_flag(sk, SOCK_ZAPPED);
  352. rc = 0;
  353. out_put:
  354. llc_sap_put(sap);
  355. out:
  356. return rc;
  357. }
  358. /**
  359. * llc_ui_shutdown - shutdown a connect llc2 socket.
  360. * @sock: Socket to shutdown.
  361. * @how: What part of the socket to shutdown.
  362. *
  363. * Shutdown a connected llc2 socket. Currently this function only supports
  364. * shutting down both sends and receives (2), we could probably make this
  365. * function such that a user can shutdown only half the connection but not
  366. * right now.
  367. * Returns: 0 upon success, negative otherwise.
  368. */
  369. static int llc_ui_shutdown(struct socket *sock, int how)
  370. {
  371. struct sock *sk = sock->sk;
  372. int rc = -ENOTCONN;
  373. lock_sock(sk);
  374. if (unlikely(sk->sk_state != TCP_ESTABLISHED))
  375. goto out;
  376. rc = -EINVAL;
  377. if (how != 2)
  378. goto out;
  379. rc = llc_send_disc(sk);
  380. if (!rc)
  381. rc = llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
  382. /* Wake up anyone sleeping in poll */
  383. sk->sk_state_change(sk);
  384. out:
  385. release_sock(sk);
  386. return rc;
  387. }
  388. /**
  389. * llc_ui_connect - Connect to a remote llc2 mac + sap.
  390. * @sock: Socket which will be connected to the remote destination.
  391. * @uaddr: Remote and possibly the local address of the new connection.
  392. * @addrlen: Size of uaddr structure.
  393. * @flags: Operational flags specified by the user.
  394. *
  395. * Connect to a remote llc2 mac + sap. The caller must specify the
  396. * destination mac and address to connect to. If the user hasn't previously
  397. * called bind(2) with a smac the address of the first interface of the
  398. * specified arp type will be used.
  399. * This function will autobind if user did not previously call bind.
  400. * Returns: 0 upon success, negative otherwise.
  401. */
  402. static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
  403. int addrlen, int flags)
  404. {
  405. struct sock *sk = sock->sk;
  406. struct llc_sock *llc = llc_sk(sk);
  407. struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
  408. int rc = -EINVAL;
  409. lock_sock(sk);
  410. if (unlikely(addrlen != sizeof(*addr)))
  411. goto out;
  412. rc = -EAFNOSUPPORT;
  413. if (unlikely(addr->sllc_family != AF_LLC))
  414. goto out;
  415. if (unlikely(sk->sk_type != SOCK_STREAM))
  416. goto out;
  417. rc = -EALREADY;
  418. if (unlikely(sock->state == SS_CONNECTING))
  419. goto out;
  420. /* bind connection to sap if user hasn't done it. */
  421. if (sock_flag(sk, SOCK_ZAPPED)) {
  422. /* bind to sap with null dev, exclusive */
  423. rc = llc_ui_autobind(sock, addr);
  424. if (rc)
  425. goto out;
  426. }
  427. llc->daddr.lsap = addr->sllc_sap;
  428. memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
  429. sock->state = SS_CONNECTING;
  430. sk->sk_state = TCP_SYN_SENT;
  431. llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
  432. rc = llc_establish_connection(sk, llc->dev->dev_addr,
  433. addr->sllc_mac, addr->sllc_sap);
  434. if (rc) {
  435. dprintk("%s: llc_ui_send_conn failed :-(\n", __func__);
  436. sock->state = SS_UNCONNECTED;
  437. sk->sk_state = TCP_CLOSE;
  438. goto out;
  439. }
  440. if (sk->sk_state == TCP_SYN_SENT) {
  441. const long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
  442. if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
  443. goto out;
  444. rc = sock_intr_errno(timeo);
  445. if (signal_pending(current))
  446. goto out;
  447. }
  448. if (sk->sk_state == TCP_CLOSE)
  449. goto sock_error;
  450. sock->state = SS_CONNECTED;
  451. rc = 0;
  452. out:
  453. release_sock(sk);
  454. return rc;
  455. sock_error:
  456. rc = sock_error(sk) ? : -ECONNABORTED;
  457. sock->state = SS_UNCONNECTED;
  458. goto out;
  459. }
  460. /**
  461. * llc_ui_listen - allow a normal socket to accept incoming connections
  462. * @sock: Socket to allow incoming connections on.
  463. * @backlog: Number of connections to queue.
  464. *
  465. * Allow a normal socket to accept incoming connections.
  466. * Returns 0 upon success, negative otherwise.
  467. */
  468. static int llc_ui_listen(struct socket *sock, int backlog)
  469. {
  470. struct sock *sk = sock->sk;
  471. int rc = -EINVAL;
  472. lock_sock(sk);
  473. if (unlikely(sock->state != SS_UNCONNECTED))
  474. goto out;
  475. rc = -EOPNOTSUPP;
  476. if (unlikely(sk->sk_type != SOCK_STREAM))
  477. goto out;
  478. rc = -EAGAIN;
  479. if (sock_flag(sk, SOCK_ZAPPED))
  480. goto out;
  481. rc = 0;
  482. if (!(unsigned)backlog) /* BSDism */
  483. backlog = 1;
  484. sk->sk_max_ack_backlog = backlog;
  485. if (sk->sk_state != TCP_LISTEN) {
  486. sk->sk_ack_backlog = 0;
  487. sk->sk_state = TCP_LISTEN;
  488. }
  489. sk->sk_socket->flags |= __SO_ACCEPTCON;
  490. out:
  491. release_sock(sk);
  492. return rc;
  493. }
  494. static int llc_ui_wait_for_disc(struct sock *sk, long timeout)
  495. {
  496. DEFINE_WAIT(wait);
  497. int rc = 0;
  498. while (1) {
  499. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  500. if (sk_wait_event(sk, &timeout, sk->sk_state == TCP_CLOSE))
  501. break;
  502. rc = -ERESTARTSYS;
  503. if (signal_pending(current))
  504. break;
  505. rc = -EAGAIN;
  506. if (!timeout)
  507. break;
  508. rc = 0;
  509. }
  510. finish_wait(sk_sleep(sk), &wait);
  511. return rc;
  512. }
  513. static int llc_ui_wait_for_conn(struct sock *sk, long timeout)
  514. {
  515. DEFINE_WAIT(wait);
  516. while (1) {
  517. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  518. if (sk_wait_event(sk, &timeout, sk->sk_state != TCP_SYN_SENT))
  519. break;
  520. if (signal_pending(current) || !timeout)
  521. break;
  522. }
  523. finish_wait(sk_sleep(sk), &wait);
  524. return timeout;
  525. }
  526. static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout)
  527. {
  528. DEFINE_WAIT(wait);
  529. struct llc_sock *llc = llc_sk(sk);
  530. int rc;
  531. while (1) {
  532. prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
  533. rc = 0;
  534. if (sk_wait_event(sk, &timeout,
  535. (sk->sk_shutdown & RCV_SHUTDOWN) ||
  536. (!llc_data_accept_state(llc->state) &&
  537. !llc->remote_busy_flag &&
  538. !llc->p_flag)))
  539. break;
  540. rc = -ERESTARTSYS;
  541. if (signal_pending(current))
  542. break;
  543. rc = -EAGAIN;
  544. if (!timeout)
  545. break;
  546. }
  547. finish_wait(sk_sleep(sk), &wait);
  548. return rc;
  549. }
  550. static int llc_wait_data(struct sock *sk, long timeo)
  551. {
  552. int rc;
  553. while (1) {
  554. /*
  555. * POSIX 1003.1g mandates this order.
  556. */
  557. rc = sock_error(sk);
  558. if (rc)
  559. break;
  560. rc = 0;
  561. if (sk->sk_shutdown & RCV_SHUTDOWN)
  562. break;
  563. rc = -EAGAIN;
  564. if (!timeo)
  565. break;
  566. rc = sock_intr_errno(timeo);
  567. if (signal_pending(current))
  568. break;
  569. rc = 0;
  570. if (sk_wait_data(sk, &timeo))
  571. break;
  572. }
  573. return rc;
  574. }
  575. static void llc_cmsg_rcv(struct msghdr *msg, struct sk_buff *skb)
  576. {
  577. struct llc_sock *llc = llc_sk(skb->sk);
  578. if (llc->cmsg_flags & LLC_CMSG_PKTINFO) {
  579. struct llc_pktinfo 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. lock_sock(sk);
  670. copied = -ENOTCONN;
  671. if (unlikely(sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN))
  672. goto out;
  673. timeo = sock_rcvtimeo(sk, nonblock);
  674. seq = &llc->copied_seq;
  675. if (flags & MSG_PEEK) {
  676. peek_seq = llc->copied_seq;
  677. seq = &peek_seq;
  678. }
  679. target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
  680. copied = 0;
  681. do {
  682. u32 offset;
  683. /*
  684. * We need to check signals first, to get correct SIGURG
  685. * handling. FIXME: Need to check this doesn't impact 1003.1g
  686. * and move it down to the bottom of the loop
  687. */
  688. if (signal_pending(current)) {
  689. if (copied)
  690. break;
  691. copied = timeo ? sock_intr_errno(timeo) : -EAGAIN;
  692. break;
  693. }
  694. /* Next get a buffer. */
  695. skb = skb_peek(&sk->sk_receive_queue);
  696. if (skb) {
  697. offset = *seq;
  698. goto found_ok_skb;
  699. }
  700. /* Well, if we have backlog, try to process it now yet. */
  701. if (copied >= target && !sk->sk_backlog.tail)
  702. break;
  703. if (copied) {
  704. if (sk->sk_err ||
  705. sk->sk_state == TCP_CLOSE ||
  706. (sk->sk_shutdown & RCV_SHUTDOWN) ||
  707. !timeo ||
  708. (flags & MSG_PEEK))
  709. break;
  710. } else {
  711. if (sock_flag(sk, SOCK_DONE))
  712. break;
  713. if (sk->sk_err) {
  714. copied = sock_error(sk);
  715. break;
  716. }
  717. if (sk->sk_shutdown & RCV_SHUTDOWN)
  718. break;
  719. if (sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_CLOSE) {
  720. if (!sock_flag(sk, SOCK_DONE)) {
  721. /*
  722. * This occurs when user tries to read
  723. * from never connected socket.
  724. */
  725. copied = -ENOTCONN;
  726. break;
  727. }
  728. break;
  729. }
  730. if (!timeo) {
  731. copied = -EAGAIN;
  732. break;
  733. }
  734. }
  735. if (copied >= target) { /* Do not sleep, just process backlog. */
  736. release_sock(sk);
  737. lock_sock(sk);
  738. } else
  739. sk_wait_data(sk, &timeo);
  740. if ((flags & MSG_PEEK) && peek_seq != llc->copied_seq) {
  741. if (net_ratelimit())
  742. printk(KERN_DEBUG "LLC(%s:%d): Application "
  743. "bug, race in MSG_PEEK.\n",
  744. current->comm, 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, 0);
  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, 0);
  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);