af_llc.c 31 KB

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