Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* SCTP kernel reference Implementation |
| 2 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 3 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 4 | * Copyright (c) 2001-2002 International Business Machines, Corp. |
| 5 | * Copyright (c) 2001 Intel Corp. |
| 6 | * Copyright (c) 2001 Nokia, Inc. |
| 7 | * Copyright (c) 2001 La Monte H.P. Yarroll |
| 8 | * |
| 9 | * This file is part of the SCTP kernel reference Implementation |
| 10 | * |
| 11 | * This abstraction represents an SCTP endpoint. |
| 12 | * |
| 13 | * This file is part of the implementation of the add-IP extension, |
| 14 | * based on <draft-ietf-tsvwg-addip-sctp-02.txt> June 29, 2001, |
| 15 | * for the SCTP kernel reference Implementation. |
| 16 | * |
| 17 | * The SCTP reference implementation is free software; |
| 18 | * you can redistribute it and/or modify it under the terms of |
| 19 | * the GNU General Public License as published by |
| 20 | * the Free Software Foundation; either version 2, or (at your option) |
| 21 | * any later version. |
| 22 | * |
| 23 | * The SCTP reference implementation is distributed in the hope that it |
| 24 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 25 | * ************************ |
| 26 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 27 | * See the GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with GNU CC; see the file COPYING. If not, write to |
| 31 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
| 32 | * Boston, MA 02111-1307, USA. |
| 33 | * |
| 34 | * Please send any bug reports or fixes you make to the |
| 35 | * email address(es): |
| 36 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
| 37 | * |
| 38 | * Or submit a bug report through the following website: |
| 39 | * http://www.sf.net/projects/lksctp |
| 40 | * |
| 41 | * Written or modified by: |
| 42 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 43 | * Karl Knutson <karl@athena.chicago.il.us> |
| 44 | * Jon Grimm <jgrimm@austin.ibm.com> |
| 45 | * Daisy Chang <daisyc@us.ibm.com> |
| 46 | * Dajiang Zhang <dajiang.zhang@nokia.com> |
| 47 | * |
| 48 | * Any bugs reported given to us we will try to fix... any fixes shared will |
| 49 | * be incorporated into the next SCTP release. |
| 50 | */ |
| 51 | |
| 52 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <linux/slab.h> |
| 54 | #include <linux/in.h> |
| 55 | #include <linux/random.h> /* get_random_bytes() */ |
| 56 | #include <linux/crypto.h> |
| 57 | #include <net/sock.h> |
| 58 | #include <net/ipv6.h> |
| 59 | #include <net/sctp/sctp.h> |
| 60 | #include <net/sctp/sm.h> |
| 61 | |
| 62 | /* Forward declarations for internal helpers. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 63 | static void sctp_endpoint_bh_rcv(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Initialize the base fields of the endpoint structure. |
| 67 | */ |
| 68 | static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep, |
Alexey Dobriyan | 3182cd8 | 2005-07-11 20:57:47 -0700 | [diff] [blame] | 69 | struct sock *sk, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 70 | gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame^] | 72 | struct sctp_hmac_algo_param *auth_hmacs = NULL; |
| 73 | struct sctp_chunks_param *auth_chunks = NULL; |
| 74 | struct sctp_shared_key *null_key; |
| 75 | int err; |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | memset(ep, 0, sizeof(struct sctp_endpoint)); |
| 78 | |
Vlad Yasevich | b68dbca | 2006-11-09 16:29:57 -0800 | [diff] [blame] | 79 | ep->digest = kzalloc(SCTP_SIGNATURE_SIZE, gfp); |
| 80 | if (!ep->digest) |
| 81 | return NULL; |
| 82 | |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame^] | 83 | if (sctp_auth_enable) { |
| 84 | /* Allocate space for HMACS and CHUNKS authentication |
| 85 | * variables. There are arrays that we encode directly |
| 86 | * into parameters to make the rest of the operations easier. |
| 87 | */ |
| 88 | auth_hmacs = kzalloc(sizeof(sctp_hmac_algo_param_t) + |
| 89 | sizeof(__u16) * SCTP_AUTH_NUM_HMACS, gfp); |
| 90 | if (!auth_hmacs) |
| 91 | goto nomem; |
| 92 | |
| 93 | auth_chunks = kzalloc(sizeof(sctp_chunks_param_t) + |
| 94 | SCTP_NUM_CHUNK_TYPES, gfp); |
| 95 | if (!auth_chunks) |
| 96 | goto nomem; |
| 97 | |
| 98 | /* Initialize the HMACS parameter. |
| 99 | * SCTP-AUTH: Section 3.3 |
| 100 | * Every endpoint supporting SCTP chunk authentication MUST |
| 101 | * support the HMAC based on the SHA-1 algorithm. |
| 102 | */ |
| 103 | auth_hmacs->param_hdr.type = SCTP_PARAM_HMAC_ALGO; |
| 104 | auth_hmacs->param_hdr.length = |
| 105 | htons(sizeof(sctp_paramhdr_t) + 2); |
| 106 | auth_hmacs->hmac_ids[0] = htons(SCTP_AUTH_HMAC_ID_SHA1); |
| 107 | |
| 108 | /* Initialize the CHUNKS parameter */ |
| 109 | auth_chunks->param_hdr.type = SCTP_PARAM_CHUNKS; |
| 110 | |
| 111 | /* If the Add-IP functionality is enabled, we must |
| 112 | * authenticate, ASCONF and ASCONF-ACK chunks |
| 113 | */ |
| 114 | if (sctp_addip_enable) { |
| 115 | auth_chunks->chunks[0] = SCTP_CID_ASCONF; |
| 116 | auth_chunks->chunks[1] = SCTP_CID_ASCONF_ACK; |
| 117 | auth_chunks->param_hdr.length = |
| 118 | htons(sizeof(sctp_paramhdr_t) + 2); |
| 119 | } |
| 120 | } |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* Initialize the base structure. */ |
| 123 | /* What type of endpoint are we? */ |
| 124 | ep->base.type = SCTP_EP_TYPE_SOCKET; |
| 125 | |
| 126 | /* Initialize the basic object fields. */ |
| 127 | atomic_set(&ep->base.refcnt, 1); |
| 128 | ep->base.dead = 0; |
| 129 | ep->base.malloced = 1; |
| 130 | |
| 131 | /* Create an input queue. */ |
| 132 | sctp_inq_init(&ep->base.inqueue); |
| 133 | |
| 134 | /* Set its top-half handler */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 135 | sctp_inq_set_th_handler(&ep->base.inqueue, sctp_endpoint_bh_rcv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* Initialize the bind addr area */ |
| 138 | sctp_bind_addr_init(&ep->base.bind_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* Remember who we are attached to. */ |
| 141 | ep->base.sk = sk; |
| 142 | sock_hold(ep->base.sk); |
| 143 | |
| 144 | /* Create the lists of associations. */ |
| 145 | INIT_LIST_HEAD(&ep->asocs); |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* Use SCTP specific send buffer space queues. */ |
Neil Horman | 4eb701d | 2005-04-28 12:02:04 -0700 | [diff] [blame] | 148 | ep->sndbuf_policy = sctp_sndbuf_policy; |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | sk->sk_write_space = sctp_write_space; |
| 151 | sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); |
| 152 | |
Neil Horman | 049b3ff | 2005-11-11 16:08:24 -0800 | [diff] [blame] | 153 | /* Get the receive buffer policy for this endpoint */ |
| 154 | ep->rcvbuf_policy = sctp_rcvbuf_policy; |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Initialize the secret key used with cookie. */ |
| 157 | get_random_bytes(&ep->secret_key[0], SCTP_SECRET_SIZE); |
| 158 | ep->last_key = ep->current_key = 0; |
| 159 | ep->key_changed_at = jiffies; |
| 160 | |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame^] | 161 | /* SCTP-AUTH extensions*/ |
| 162 | INIT_LIST_HEAD(&ep->endpoint_shared_keys); |
| 163 | null_key = sctp_auth_shkey_create(0, GFP_KERNEL); |
| 164 | if (!null_key) |
| 165 | goto nomem; |
| 166 | |
| 167 | list_add(&null_key->key_list, &ep->endpoint_shared_keys); |
| 168 | |
| 169 | /* Allocate and initialize transorms arrays for suported HMACs. */ |
| 170 | err = sctp_auth_init_hmacs(ep, gfp); |
| 171 | if (err) |
| 172 | goto nomem_hmacs; |
| 173 | |
| 174 | /* Add the null key to the endpoint shared keys list and |
| 175 | * set the hmcas and chunks pointers. |
| 176 | */ |
| 177 | ep->auth_hmacs_list = auth_hmacs; |
| 178 | ep->auth_chunk_list = auth_chunks; |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return ep; |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame^] | 181 | |
| 182 | nomem_hmacs: |
| 183 | sctp_auth_destroy_keys(&ep->endpoint_shared_keys); |
| 184 | nomem: |
| 185 | /* Free all allocations */ |
| 186 | kfree(auth_hmacs); |
| 187 | kfree(auth_chunks); |
| 188 | kfree(ep->digest); |
| 189 | return NULL; |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* Create a sctp_endpoint with all that boring stuff initialized. |
| 194 | * Returns NULL if there isn't enough memory. |
| 195 | */ |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 196 | struct sctp_endpoint *sctp_endpoint_new(struct sock *sk, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | struct sctp_endpoint *ep; |
| 199 | |
| 200 | /* Build a local endpoint. */ |
| 201 | ep = t_new(struct sctp_endpoint, gfp); |
| 202 | if (!ep) |
| 203 | goto fail; |
| 204 | if (!sctp_endpoint_init(ep, sk, gfp)) |
| 205 | goto fail_init; |
| 206 | ep->base.malloced = 1; |
| 207 | SCTP_DBG_OBJCNT_INC(ep); |
| 208 | return ep; |
| 209 | |
| 210 | fail_init: |
| 211 | kfree(ep); |
| 212 | fail: |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | /* Add an association to an endpoint. */ |
| 217 | void sctp_endpoint_add_asoc(struct sctp_endpoint *ep, |
| 218 | struct sctp_association *asoc) |
| 219 | { |
| 220 | struct sock *sk = ep->base.sk; |
| 221 | |
Vlad Yasevich | de76e69 | 2006-10-30 18:55:11 -0800 | [diff] [blame] | 222 | /* If this is a temporary association, don't bother |
| 223 | * since we'll be removing it shortly and don't |
| 224 | * want anyone to find it anyway. |
| 225 | */ |
| 226 | if (asoc->temp) |
| 227 | return; |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | /* Now just add it to our list of asocs */ |
| 230 | list_add_tail(&asoc->asocs, &ep->asocs); |
| 231 | |
| 232 | /* Increment the backlog value for a TCP-style listening socket. */ |
| 233 | if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) |
| 234 | sk->sk_ack_backlog++; |
| 235 | } |
| 236 | |
| 237 | /* Free the endpoint structure. Delay cleanup until |
| 238 | * all users have released their reference count on this structure. |
| 239 | */ |
| 240 | void sctp_endpoint_free(struct sctp_endpoint *ep) |
| 241 | { |
| 242 | ep->base.dead = 1; |
Vlad Yasevich | cfdeef3 | 2006-07-21 14:48:26 -0700 | [diff] [blame] | 243 | |
| 244 | ep->base.sk->sk_state = SCTP_SS_CLOSED; |
| 245 | |
| 246 | /* Unlink this endpoint, so we can't find it again! */ |
| 247 | sctp_unhash_endpoint(ep); |
| 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | sctp_endpoint_put(ep); |
| 250 | } |
| 251 | |
| 252 | /* Final destructor for endpoint. */ |
| 253 | static void sctp_endpoint_destroy(struct sctp_endpoint *ep) |
| 254 | { |
| 255 | SCTP_ASSERT(ep->base.dead, "Endpoint is not dead", return); |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* Free up the HMAC transform. */ |
Herbert Xu | 1b489e1 | 2006-08-20 15:07:14 +1000 | [diff] [blame] | 258 | crypto_free_hash(sctp_sk(ep->base.sk)->hmac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Vlad Yasevich | b68dbca | 2006-11-09 16:29:57 -0800 | [diff] [blame] | 260 | /* Free the digest buffer */ |
| 261 | kfree(ep->digest); |
| 262 | |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame^] | 263 | /* SCTP-AUTH: Free up AUTH releated data such as shared keys |
| 264 | * chunks and hmacs arrays that were allocated |
| 265 | */ |
| 266 | sctp_auth_destroy_keys(&ep->endpoint_shared_keys); |
| 267 | kfree(ep->auth_hmacs_list); |
| 268 | kfree(ep->auth_chunk_list); |
| 269 | |
| 270 | /* AUTH - Free any allocated HMAC transform containers */ |
| 271 | sctp_auth_destroy_hmacs(ep->auth_hmacs); |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | /* Cleanup. */ |
| 274 | sctp_inq_free(&ep->base.inqueue); |
| 275 | sctp_bind_addr_free(&ep->base.bind_addr); |
| 276 | |
| 277 | /* Remove and free the port */ |
| 278 | if (sctp_sk(ep->base.sk)->bind_hash) |
| 279 | sctp_put_port(ep->base.sk); |
| 280 | |
| 281 | /* Give up our hold on the sock. */ |
| 282 | if (ep->base.sk) |
| 283 | sock_put(ep->base.sk); |
| 284 | |
| 285 | /* Finally, free up our memory. */ |
| 286 | if (ep->base.malloced) { |
| 287 | kfree(ep); |
| 288 | SCTP_DBG_OBJCNT_DEC(ep); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* Hold a reference to an endpoint. */ |
| 293 | void sctp_endpoint_hold(struct sctp_endpoint *ep) |
| 294 | { |
| 295 | atomic_inc(&ep->base.refcnt); |
| 296 | } |
| 297 | |
| 298 | /* Release a reference to an endpoint and clean up if there are |
| 299 | * no more references. |
| 300 | */ |
| 301 | void sctp_endpoint_put(struct sctp_endpoint *ep) |
| 302 | { |
| 303 | if (atomic_dec_and_test(&ep->base.refcnt)) |
| 304 | sctp_endpoint_destroy(ep); |
| 305 | } |
| 306 | |
| 307 | /* Is this the endpoint we are looking for? */ |
| 308 | struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *ep, |
| 309 | const union sctp_addr *laddr) |
| 310 | { |
Vlad Yasevich | 559cf71 | 2007-09-16 16:03:28 -0700 | [diff] [blame] | 311 | struct sctp_endpoint *retval = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Al Viro | 1c7d1fc | 2006-11-20 17:08:09 -0800 | [diff] [blame] | 313 | if (htons(ep->base.bind_addr.port) == laddr->v4.sin_port) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (sctp_bind_addr_match(&ep->base.bind_addr, laddr, |
Vlad Yasevich | 559cf71 | 2007-09-16 16:03:28 -0700 | [diff] [blame] | 315 | sctp_sk(ep->base.sk))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | retval = ep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | return retval; |
| 320 | } |
| 321 | |
| 322 | /* Find the association that goes with this chunk. |
| 323 | * We do a linear search of the associations for this endpoint. |
| 324 | * We return the matching transport address too. |
| 325 | */ |
| 326 | static struct sctp_association *__sctp_endpoint_lookup_assoc( |
| 327 | const struct sctp_endpoint *ep, |
| 328 | const union sctp_addr *paddr, |
| 329 | struct sctp_transport **transport) |
| 330 | { |
| 331 | int rport; |
| 332 | struct sctp_association *asoc; |
| 333 | struct list_head *pos; |
| 334 | |
Al Viro | cd4ff03 | 2006-11-20 17:11:33 -0800 | [diff] [blame] | 335 | rport = ntohs(paddr->v4.sin_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | list_for_each(pos, &ep->asocs) { |
| 338 | asoc = list_entry(pos, struct sctp_association, asocs); |
| 339 | if (rport == asoc->peer.port) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | *transport = sctp_assoc_lookup_paddr(asoc, paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | if (*transport) |
| 343 | return asoc; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | *transport = NULL; |
| 348 | return NULL; |
| 349 | } |
| 350 | |
| 351 | /* Lookup association on an endpoint based on a peer address. BH-safe. */ |
| 352 | struct sctp_association *sctp_endpoint_lookup_assoc( |
| 353 | const struct sctp_endpoint *ep, |
| 354 | const union sctp_addr *paddr, |
| 355 | struct sctp_transport **transport) |
| 356 | { |
| 357 | struct sctp_association *asoc; |
| 358 | |
| 359 | sctp_local_bh_disable(); |
| 360 | asoc = __sctp_endpoint_lookup_assoc(ep, paddr, transport); |
| 361 | sctp_local_bh_enable(); |
| 362 | |
| 363 | return asoc; |
| 364 | } |
| 365 | |
| 366 | /* Look for any peeled off association from the endpoint that matches the |
| 367 | * given peer address. |
| 368 | */ |
| 369 | int sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep, |
| 370 | const union sctp_addr *paddr) |
| 371 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | struct sctp_sockaddr_entry *addr; |
| 373 | struct sctp_bind_addr *bp; |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | bp = &ep->base.bind_addr; |
Vlad Yasevich | 559cf71 | 2007-09-16 16:03:28 -0700 | [diff] [blame] | 376 | /* This function is called with the socket lock held, |
| 377 | * so the address_list can not change. |
| 378 | */ |
| 379 | list_for_each_entry(addr, &bp->address_list, list) { |
| 380 | if (sctp_has_association(&addr->a, paddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | /* Do delayed input processing. This is scheduled by sctp_rcv(). |
| 388 | * This may be called on BH or task time. |
| 389 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 390 | static void sctp_endpoint_bh_rcv(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 392 | struct sctp_endpoint *ep = |
| 393 | container_of(work, struct sctp_endpoint, |
| 394 | base.inqueue.immediate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | struct sctp_association *asoc; |
| 396 | struct sock *sk; |
| 397 | struct sctp_transport *transport; |
| 398 | struct sctp_chunk *chunk; |
| 399 | struct sctp_inq *inqueue; |
| 400 | sctp_subtype_t subtype; |
| 401 | sctp_state_t state; |
| 402 | int error = 0; |
| 403 | |
| 404 | if (ep->base.dead) |
| 405 | return; |
| 406 | |
| 407 | asoc = NULL; |
| 408 | inqueue = &ep->base.inqueue; |
| 409 | sk = ep->base.sk; |
| 410 | |
| 411 | while (NULL != (chunk = sctp_inq_pop(inqueue))) { |
| 412 | subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type); |
| 413 | |
| 414 | /* We might have grown an association since last we |
| 415 | * looked, so try again. |
| 416 | * |
| 417 | * This happens when we've just processed our |
| 418 | * COOKIE-ECHO chunk. |
| 419 | */ |
| 420 | if (NULL == chunk->asoc) { |
| 421 | asoc = sctp_endpoint_lookup_assoc(ep, |
| 422 | sctp_source(chunk), |
| 423 | &transport); |
| 424 | chunk->asoc = asoc; |
| 425 | chunk->transport = transport; |
| 426 | } |
| 427 | |
| 428 | state = asoc ? asoc->state : SCTP_STATE_CLOSED; |
| 429 | |
| 430 | /* Remember where the last DATA chunk came from so we |
| 431 | * know where to send the SACK. |
| 432 | */ |
| 433 | if (asoc && sctp_chunk_is_data(chunk)) |
| 434 | asoc->peer.last_data_from = chunk->transport; |
| 435 | else |
| 436 | SCTP_INC_STATS(SCTP_MIB_INCTRLCHUNKS); |
| 437 | |
| 438 | if (chunk->transport) |
| 439 | chunk->transport->last_time_heard = jiffies; |
| 440 | |
| 441 | error = sctp_do_sm(SCTP_EVENT_T_CHUNK, subtype, state, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 442 | ep, asoc, chunk, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | if (error && chunk) |
| 445 | chunk->pdiscard = 1; |
| 446 | |
| 447 | /* Check to see if the endpoint is freed in response to |
| 448 | * the incoming chunk. If so, get out of the while loop. |
| 449 | */ |
| 450 | if (!sctp_sk(sk)->ep) |
| 451 | break; |
| 452 | } |
| 453 | } |