af_llc.c 31 KB

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