af_llc.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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 int)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, NULL))
  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, NULL);
  740. if ((flags & MSG_PEEK) && peek_seq != llc->copied_seq) {
  741. net_dbg_ratelimited("LLC(%s:%d): Application bug, race in MSG_PEEK\n",
  742. current->comm,
  743. task_pid_nr(current));
  744. peek_seq = llc->copied_seq;
  745. }
  746. continue;
  747. found_ok_skb:
  748. skb_len = skb->len;
  749. /* Ok so how much can we use? */
  750. used = skb->len - offset;
  751. if (len < used)
  752. used = len;
  753. if (!(flags & MSG_TRUNC)) {
  754. int rc = skb_copy_datagram_iovec(skb, offset,
  755. msg->msg_iov, used);
  756. if (rc) {
  757. /* Exception. Bailout! */
  758. if (!copied)
  759. copied = -EFAULT;
  760. break;
  761. }
  762. }
  763. *seq += used;
  764. copied += used;
  765. len -= used;
  766. /* For non stream protcols we get one packet per recvmsg call */
  767. if (sk->sk_type != SOCK_STREAM)
  768. goto copy_uaddr;
  769. if (!(flags & MSG_PEEK)) {
  770. spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags);
  771. sk_eat_skb(sk, skb, false);
  772. spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);
  773. *seq = 0;
  774. }
  775. /* Partial read */
  776. if (used + offset < skb_len)
  777. continue;
  778. } while (len > 0);
  779. out:
  780. release_sock(sk);
  781. return copied;
  782. copy_uaddr:
  783. if (uaddr != NULL && skb != NULL) {
  784. memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
  785. msg->msg_namelen = sizeof(*uaddr);
  786. }
  787. if (llc_sk(sk)->cmsg_flags)
  788. llc_cmsg_rcv(msg, skb);
  789. if (!(flags & MSG_PEEK)) {
  790. spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags);
  791. sk_eat_skb(sk, skb, false);
  792. spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);
  793. *seq = 0;
  794. }
  795. goto out;
  796. }
  797. /**
  798. * llc_ui_sendmsg - Transmit data provided by the socket user.
  799. * @sock: Socket to transmit data from.
  800. * @msg: Various user related information.
  801. * @len: Length of data to transmit.
  802. *
  803. * Transmit data provided by the socket user.
  804. * Returns non-negative upon success, negative otherwise.
  805. */
  806. static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
  807. struct msghdr *msg, size_t len)
  808. {
  809. struct sock *sk = sock->sk;
  810. struct llc_sock *llc = llc_sk(sk);
  811. struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name;
  812. int flags = msg->msg_flags;
  813. int noblock = flags & MSG_DONTWAIT;
  814. struct sk_buff *skb;
  815. size_t size = 0;
  816. int rc = -EINVAL, copied = 0, hdrlen;
  817. dprintk("%s: sending from %02X to %02X\n", __func__,
  818. llc->laddr.lsap, llc->daddr.lsap);
  819. lock_sock(sk);
  820. if (addr) {
  821. if (msg->msg_namelen < sizeof(*addr))
  822. goto release;
  823. } else {
  824. if (llc_ui_addr_null(&llc->addr))
  825. goto release;
  826. addr = &llc->addr;
  827. }
  828. /* must bind connection to sap if user hasn't done it. */
  829. if (sock_flag(sk, SOCK_ZAPPED)) {
  830. /* bind to sap with null dev, exclusive. */
  831. rc = llc_ui_autobind(sock, addr);
  832. if (rc)
  833. goto release;
  834. }
  835. hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
  836. size = hdrlen + len;
  837. if (size > llc->dev->mtu)
  838. size = llc->dev->mtu;
  839. copied = size - hdrlen;
  840. release_sock(sk);
  841. skb = sock_alloc_send_skb(sk, size, noblock, &rc);
  842. lock_sock(sk);
  843. if (!skb)
  844. goto release;
  845. skb->dev = llc->dev;
  846. skb->protocol = llc_proto_type(addr->sllc_arphrd);
  847. skb_reserve(skb, hdrlen);
  848. rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied);
  849. if (rc)
  850. goto out;
  851. if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
  852. llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
  853. addr->sllc_sap);
  854. goto out;
  855. }
  856. if (addr->sllc_test) {
  857. llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
  858. addr->sllc_sap);
  859. goto out;
  860. }
  861. if (addr->sllc_xid) {
  862. llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
  863. addr->sllc_sap);
  864. goto out;
  865. }
  866. rc = -ENOPROTOOPT;
  867. if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
  868. goto out;
  869. rc = llc_ui_send_data(sk, skb, noblock);
  870. out:
  871. if (rc) {
  872. kfree_skb(skb);
  873. release:
  874. dprintk("%s: failed sending from %02X to %02X: %d\n",
  875. __func__, llc->laddr.lsap, llc->daddr.lsap, rc);
  876. }
  877. release_sock(sk);
  878. return rc ? : copied;
  879. }
  880. /**
  881. * llc_ui_getname - return the address info of a socket
  882. * @sock: Socket to get address of.
  883. * @uaddr: Address structure to return information.
  884. * @uaddrlen: Length of address structure.
  885. * @peer: Does user want local or remote address information.
  886. *
  887. * Return the address information of a socket.
  888. */
  889. static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
  890. int *uaddrlen, int peer)
  891. {
  892. struct sockaddr_llc sllc;
  893. struct sock *sk = sock->sk;
  894. struct llc_sock *llc = llc_sk(sk);
  895. int rc = -EBADF;
  896. memset(&sllc, 0, sizeof(sllc));
  897. lock_sock(sk);
  898. if (sock_flag(sk, SOCK_ZAPPED))
  899. goto out;
  900. *uaddrlen = sizeof(sllc);
  901. if (peer) {
  902. rc = -ENOTCONN;
  903. if (sk->sk_state != TCP_ESTABLISHED)
  904. goto out;
  905. if(llc->dev)
  906. sllc.sllc_arphrd = llc->dev->type;
  907. sllc.sllc_sap = llc->daddr.lsap;
  908. memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN);
  909. } else {
  910. rc = -EINVAL;
  911. if (!llc->sap)
  912. goto out;
  913. sllc.sllc_sap = llc->sap->laddr.lsap;
  914. if (llc->dev) {
  915. sllc.sllc_arphrd = llc->dev->type;
  916. memcpy(&sllc.sllc_mac, llc->dev->dev_addr,
  917. IFHWADDRLEN);
  918. }
  919. }
  920. rc = 0;
  921. sllc.sllc_family = AF_LLC;
  922. memcpy(uaddr, &sllc, sizeof(sllc));
  923. out:
  924. release_sock(sk);
  925. return rc;
  926. }
  927. /**
  928. * llc_ui_ioctl - io controls for PF_LLC
  929. * @sock: Socket to get/set info
  930. * @cmd: command
  931. * @arg: optional argument for cmd
  932. *
  933. * get/set info on llc sockets
  934. */
  935. static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
  936. unsigned long arg)
  937. {
  938. return -ENOIOCTLCMD;
  939. }
  940. /**
  941. * llc_ui_setsockopt - set various connection specific parameters.
  942. * @sock: Socket to set options on.
  943. * @level: Socket level user is requesting operations on.
  944. * @optname: Operation name.
  945. * @optval User provided operation data.
  946. * @optlen: Length of optval.
  947. *
  948. * Set various connection specific parameters.
  949. */
  950. static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
  951. char __user *optval, unsigned int optlen)
  952. {
  953. struct sock *sk = sock->sk;
  954. struct llc_sock *llc = llc_sk(sk);
  955. unsigned int opt;
  956. int rc = -EINVAL;
  957. lock_sock(sk);
  958. if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
  959. goto out;
  960. rc = get_user(opt, (int __user *)optval);
  961. if (rc)
  962. goto out;
  963. rc = -EINVAL;
  964. switch (optname) {
  965. case LLC_OPT_RETRY:
  966. if (opt > LLC_OPT_MAX_RETRY)
  967. goto out;
  968. llc->n2 = opt;
  969. break;
  970. case LLC_OPT_SIZE:
  971. if (opt > LLC_OPT_MAX_SIZE)
  972. goto out;
  973. llc->n1 = opt;
  974. break;
  975. case LLC_OPT_ACK_TMR_EXP:
  976. if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
  977. goto out;
  978. llc->ack_timer.expire = opt * HZ;
  979. break;
  980. case LLC_OPT_P_TMR_EXP:
  981. if (opt > LLC_OPT_MAX_P_TMR_EXP)
  982. goto out;
  983. llc->pf_cycle_timer.expire = opt * HZ;
  984. break;
  985. case LLC_OPT_REJ_TMR_EXP:
  986. if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
  987. goto out;
  988. llc->rej_sent_timer.expire = opt * HZ;
  989. break;
  990. case LLC_OPT_BUSY_TMR_EXP:
  991. if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
  992. goto out;
  993. llc->busy_state_timer.expire = opt * HZ;
  994. break;
  995. case LLC_OPT_TX_WIN:
  996. if (opt > LLC_OPT_MAX_WIN)
  997. goto out;
  998. llc->k = opt;
  999. break;
  1000. case LLC_OPT_RX_WIN:
  1001. if (opt > LLC_OPT_MAX_WIN)
  1002. goto out;
  1003. llc->rw = opt;
  1004. break;
  1005. case LLC_OPT_PKTINFO:
  1006. if (opt)
  1007. llc->cmsg_flags |= LLC_CMSG_PKTINFO;
  1008. else
  1009. llc->cmsg_flags &= ~LLC_CMSG_PKTINFO;
  1010. break;
  1011. default:
  1012. rc = -ENOPROTOOPT;
  1013. goto out;
  1014. }
  1015. rc = 0;
  1016. out:
  1017. release_sock(sk);
  1018. return rc;
  1019. }
  1020. /**
  1021. * llc_ui_getsockopt - get connection specific socket info
  1022. * @sock: Socket to get information from.
  1023. * @level: Socket level user is requesting operations on.
  1024. * @optname: Operation name.
  1025. * @optval: Variable to return operation data in.
  1026. * @optlen: Length of optval.
  1027. *
  1028. * Get connection specific socket information.
  1029. */
  1030. static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
  1031. char __user *optval, int __user *optlen)
  1032. {
  1033. struct sock *sk = sock->sk;
  1034. struct llc_sock *llc = llc_sk(sk);
  1035. int val = 0, len = 0, rc = -EINVAL;
  1036. lock_sock(sk);
  1037. if (unlikely(level != SOL_LLC))
  1038. goto out;
  1039. rc = get_user(len, optlen);
  1040. if (rc)
  1041. goto out;
  1042. rc = -EINVAL;
  1043. if (len != sizeof(int))
  1044. goto out;
  1045. switch (optname) {
  1046. case LLC_OPT_RETRY:
  1047. val = llc->n2; break;
  1048. case LLC_OPT_SIZE:
  1049. val = llc->n1; break;
  1050. case LLC_OPT_ACK_TMR_EXP:
  1051. val = llc->ack_timer.expire / HZ; break;
  1052. case LLC_OPT_P_TMR_EXP:
  1053. val = llc->pf_cycle_timer.expire / HZ; break;
  1054. case LLC_OPT_REJ_TMR_EXP:
  1055. val = llc->rej_sent_timer.expire / HZ; break;
  1056. case LLC_OPT_BUSY_TMR_EXP:
  1057. val = llc->busy_state_timer.expire / HZ; break;
  1058. case LLC_OPT_TX_WIN:
  1059. val = llc->k; break;
  1060. case LLC_OPT_RX_WIN:
  1061. val = llc->rw; break;
  1062. case LLC_OPT_PKTINFO:
  1063. val = (llc->cmsg_flags & LLC_CMSG_PKTINFO) != 0;
  1064. break;
  1065. default:
  1066. rc = -ENOPROTOOPT;
  1067. goto out;
  1068. }
  1069. rc = 0;
  1070. if (put_user(len, optlen) || copy_to_user(optval, &val, len))
  1071. rc = -EFAULT;
  1072. out:
  1073. release_sock(sk);
  1074. return rc;
  1075. }
  1076. static const struct net_proto_family llc_ui_family_ops = {
  1077. .family = PF_LLC,
  1078. .create = llc_ui_create,
  1079. .owner = THIS_MODULE,
  1080. };
  1081. static const struct proto_ops llc_ui_ops = {
  1082. .family = PF_LLC,
  1083. .owner = THIS_MODULE,
  1084. .release = llc_ui_release,
  1085. .bind = llc_ui_bind,
  1086. .connect = llc_ui_connect,
  1087. .socketpair = sock_no_socketpair,
  1088. .accept = llc_ui_accept,
  1089. .getname = llc_ui_getname,
  1090. .poll = datagram_poll,
  1091. .ioctl = llc_ui_ioctl,
  1092. .listen = llc_ui_listen,
  1093. .shutdown = llc_ui_shutdown,
  1094. .setsockopt = llc_ui_setsockopt,
  1095. .getsockopt = llc_ui_getsockopt,
  1096. .sendmsg = llc_ui_sendmsg,
  1097. .recvmsg = llc_ui_recvmsg,
  1098. .mmap = sock_no_mmap,
  1099. .sendpage = sock_no_sendpage,
  1100. };
  1101. static const char llc_proc_err_msg[] __initconst =
  1102. KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
  1103. static const char llc_sysctl_err_msg[] __initconst =
  1104. KERN_CRIT "LLC: Unable to register the sysctl entries\n";
  1105. static const char llc_sock_err_msg[] __initconst =
  1106. KERN_CRIT "LLC: Unable to register the network family\n";
  1107. static int __init llc2_init(void)
  1108. {
  1109. int rc = proto_register(&llc_proto, 0);
  1110. if (rc != 0)
  1111. goto out;
  1112. llc_build_offset_table();
  1113. llc_station_init();
  1114. llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
  1115. rc = llc_proc_init();
  1116. if (rc != 0) {
  1117. printk(llc_proc_err_msg);
  1118. goto out_unregister_llc_proto;
  1119. }
  1120. rc = llc_sysctl_init();
  1121. if (rc) {
  1122. printk(llc_sysctl_err_msg);
  1123. goto out_proc;
  1124. }
  1125. rc = sock_register(&llc_ui_family_ops);
  1126. if (rc) {
  1127. printk(llc_sock_err_msg);
  1128. goto out_sysctl;
  1129. }
  1130. llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
  1131. llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
  1132. out:
  1133. return rc;
  1134. out_sysctl:
  1135. llc_sysctl_exit();
  1136. out_proc:
  1137. llc_proc_exit();
  1138. out_unregister_llc_proto:
  1139. proto_unregister(&llc_proto);
  1140. goto out;
  1141. }
  1142. static void __exit llc2_exit(void)
  1143. {
  1144. llc_station_exit();
  1145. llc_remove_pack(LLC_DEST_SAP);
  1146. llc_remove_pack(LLC_DEST_CONN);
  1147. sock_unregister(PF_LLC);
  1148. llc_proc_exit();
  1149. llc_sysctl_exit();
  1150. proto_unregister(&llc_proto);
  1151. }
  1152. module_init(llc2_init);
  1153. module_exit(llc2_exit);
  1154. MODULE_LICENSE("GPL");
  1155. MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
  1156. MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
  1157. MODULE_ALIAS_NETPROTO(PF_LLC);