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