Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* SCTP kernel reference Implementation |
2 | * (C) Copyright IBM Corp. 2001, 2004 | |
3 | * Copyright (c) 1999-2000 Cisco, Inc. | |
4 | * Copyright (c) 1999-2001 Motorola, Inc. | |
5 | * Copyright (c) 2001-2002 Intel Corp. | |
6 | * Copyright (c) 2002 Nokia Corp. | |
7 | * | |
8 | * This file is part of the SCTP kernel reference Implementation | |
9 | * | |
10 | * This is part of the SCTP Linux Kernel Reference Implementation. | |
11 | * | |
12 | * These are the state functions for the state machine. | |
13 | * | |
14 | * The SCTP reference implementation is free software; | |
15 | * you can redistribute it and/or modify it under the terms of | |
16 | * the GNU General Public License as published by | |
17 | * the Free Software Foundation; either version 2, or (at your option) | |
18 | * any later version. | |
19 | * | |
20 | * The SCTP reference implementation is distributed in the hope that it | |
21 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied | |
22 | * ************************ | |
23 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
24 | * See the GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with GNU CC; see the file COPYING. If not, write to | |
28 | * the Free Software Foundation, 59 Temple Place - Suite 330, | |
29 | * Boston, MA 02111-1307, USA. | |
30 | * | |
31 | * Please send any bug reports or fixes you make to the | |
32 | * email address(es): | |
33 | * lksctp developers <lksctp-developers@lists.sourceforge.net> | |
34 | * | |
35 | * Or submit a bug report through the following website: | |
36 | * http://www.sf.net/projects/lksctp | |
37 | * | |
38 | * Written or modified by: | |
39 | * La Monte H.P. Yarroll <piggy@acm.org> | |
40 | * Karl Knutson <karl@athena.chicago.il.us> | |
41 | * Mathew Kotowsky <kotowsky@sctp.org> | |
42 | * Sridhar Samudrala <samudrala@us.ibm.com> | |
43 | * Jon Grimm <jgrimm@us.ibm.com> | |
44 | * Hui Huang <hui.huang@nokia.com> | |
45 | * Dajiang Zhang <dajiang.zhang@nokia.com> | |
46 | * Daisy Chang <daisyc@us.ibm.com> | |
47 | * Ardelle Fan <ardelle.fan@intel.com> | |
48 | * Ryan Layer <rmlayer@us.ibm.com> | |
49 | * Kevin Gao <kevin.gao@intel.com> | |
50 | * | |
51 | * Any bugs reported given to us we will try to fix... any fixes shared will | |
52 | * be incorporated into the next SCTP release. | |
53 | */ | |
54 | ||
55 | #include <linux/types.h> | |
56 | #include <linux/kernel.h> | |
57 | #include <linux/ip.h> | |
58 | #include <linux/ipv6.h> | |
59 | #include <linux/net.h> | |
60 | #include <linux/inet.h> | |
61 | #include <net/sock.h> | |
62 | #include <net/inet_ecn.h> | |
63 | #include <linux/skbuff.h> | |
64 | #include <net/sctp/sctp.h> | |
65 | #include <net/sctp/sm.h> | |
66 | #include <net/sctp/structs.h> | |
67 | ||
68 | static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep, | |
69 | const struct sctp_association *asoc, | |
70 | struct sctp_chunk *chunk, | |
71 | const void *payload, | |
72 | size_t paylen); | |
73 | static int sctp_eat_data(const struct sctp_association *asoc, | |
74 | struct sctp_chunk *chunk, | |
75 | sctp_cmd_seq_t *commands); | |
76 | static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc, | |
77 | const struct sctp_chunk *chunk); | |
78 | static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep, | |
79 | const struct sctp_association *asoc, | |
80 | const struct sctp_chunk *chunk, | |
81 | sctp_cmd_seq_t *commands, | |
82 | struct sctp_chunk *err_chunk); | |
83 | static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep, | |
84 | const struct sctp_association *asoc, | |
85 | const sctp_subtype_t type, | |
86 | void *arg, | |
87 | sctp_cmd_seq_t *commands); | |
88 | static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep, | |
89 | const struct sctp_association *asoc, | |
90 | const sctp_subtype_t type, | |
91 | void *arg, | |
92 | sctp_cmd_seq_t *commands); | |
93 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk); | |
94 | ||
52c1da39 | 95 | static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, |
f94c0198 | 96 | __be16 error, int sk_err, |
52c1da39 AB |
97 | const struct sctp_association *asoc, |
98 | struct sctp_transport *transport); | |
99 | ||
aecedeab WY |
100 | static sctp_disposition_t sctp_sf_abort_violation( |
101 | const struct sctp_association *asoc, | |
102 | void *arg, | |
103 | sctp_cmd_seq_t *commands, | |
104 | const __u8 *payload, | |
105 | const size_t paylen); | |
106 | ||
52c1da39 AB |
107 | static sctp_disposition_t sctp_sf_violation_chunklen( |
108 | const struct sctp_endpoint *ep, | |
109 | const struct sctp_association *asoc, | |
110 | const sctp_subtype_t type, | |
111 | void *arg, | |
112 | sctp_cmd_seq_t *commands); | |
1da177e4 | 113 | |
aecedeab WY |
114 | static sctp_disposition_t sctp_sf_violation_ctsn( |
115 | const struct sctp_endpoint *ep, | |
116 | const struct sctp_association *asoc, | |
117 | const sctp_subtype_t type, | |
118 | void *arg, | |
119 | sctp_cmd_seq_t *commands); | |
120 | ||
1da177e4 LT |
121 | /* Small helper function that checks if the chunk length |
122 | * is of the appropriate length. The 'required_length' argument | |
123 | * is set to be the size of a specific chunk we are testing. | |
124 | * Return Values: 1 = Valid length | |
125 | * 0 = Invalid length | |
126 | * | |
127 | */ | |
128 | static inline int | |
129 | sctp_chunk_length_valid(struct sctp_chunk *chunk, | |
130 | __u16 required_length) | |
131 | { | |
132 | __u16 chunk_length = ntohs(chunk->chunk_hdr->length); | |
133 | ||
134 | if (unlikely(chunk_length < required_length)) | |
135 | return 0; | |
136 | ||
137 | return 1; | |
138 | } | |
139 | ||
140 | /********************************************************** | |
141 | * These are the state functions for handling chunk events. | |
142 | **********************************************************/ | |
143 | ||
144 | /* | |
145 | * Process the final SHUTDOWN COMPLETE. | |
146 | * | |
147 | * Section: 4 (C) (diagram), 9.2 | |
148 | * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify | |
149 | * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be | |
150 | * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint | |
151 | * should stop the T2-shutdown timer and remove all knowledge of the | |
152 | * association (and thus the association enters the CLOSED state). | |
153 | * | |
047a2428 | 154 | * Verification Tag: 8.5.1(C), sctpimpguide 2.41. |
1da177e4 LT |
155 | * C) Rules for packet carrying SHUTDOWN COMPLETE: |
156 | * ... | |
047a2428 JF |
157 | * - The receiver of a SHUTDOWN COMPLETE shall accept the packet |
158 | * if the Verification Tag field of the packet matches its own tag and | |
159 | * the T bit is not set | |
160 | * OR | |
161 | * it is set to its peer's tag and the T bit is set in the Chunk | |
162 | * Flags. | |
163 | * Otherwise, the receiver MUST silently discard the packet | |
164 | * and take no further action. An endpoint MUST ignore the | |
165 | * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. | |
1da177e4 LT |
166 | * |
167 | * Inputs | |
168 | * (endpoint, asoc, chunk) | |
169 | * | |
170 | * Outputs | |
171 | * (asoc, reply_msg, msg_up, timers, counters) | |
172 | * | |
173 | * The return value is the disposition of the chunk. | |
174 | */ | |
175 | sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep, | |
176 | const struct sctp_association *asoc, | |
177 | const sctp_subtype_t type, | |
178 | void *arg, | |
179 | sctp_cmd_seq_t *commands) | |
180 | { | |
181 | struct sctp_chunk *chunk = arg; | |
182 | struct sctp_ulpevent *ev; | |
183 | ||
184 | /* RFC 2960 6.10 Bundling | |
185 | * | |
186 | * An endpoint MUST NOT bundle INIT, INIT ACK or | |
187 | * SHUTDOWN COMPLETE with any other chunks. | |
188 | */ | |
189 | if (!chunk->singleton) | |
190 | return SCTP_DISPOSITION_VIOLATION; | |
191 | ||
192 | if (!sctp_vtag_verify_either(chunk, asoc)) | |
193 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
194 | ||
195 | /* RFC 2960 10.2 SCTP-to-ULP | |
196 | * | |
197 | * H) SHUTDOWN COMPLETE notification | |
198 | * | |
199 | * When SCTP completes the shutdown procedures (section 9.2) this | |
200 | * notification is passed to the upper layer. | |
201 | */ | |
202 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, | |
a5a35e76 | 203 | 0, 0, 0, NULL, GFP_ATOMIC); |
df7deeb5 VY |
204 | if (ev) |
205 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, | |
d808ad9a | 206 | SCTP_ULPEVENT(ev)); |
1da177e4 LT |
207 | |
208 | /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint | |
209 | * will verify that it is in SHUTDOWN-ACK-SENT state, if it is | |
210 | * not the chunk should be discarded. If the endpoint is in | |
211 | * the SHUTDOWN-ACK-SENT state the endpoint should stop the | |
212 | * T2-shutdown timer and remove all knowledge of the | |
213 | * association (and thus the association enters the CLOSED | |
214 | * state). | |
215 | */ | |
216 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
217 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
218 | ||
219 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
220 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
221 | ||
222 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
223 | SCTP_STATE(SCTP_STATE_CLOSED)); | |
224 | ||
225 | SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); | |
226 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
227 | ||
228 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); | |
229 | ||
230 | return SCTP_DISPOSITION_DELETE_TCB; | |
1da177e4 LT |
231 | } |
232 | ||
233 | /* | |
234 | * Respond to a normal INIT chunk. | |
235 | * We are the side that is being asked for an association. | |
236 | * | |
237 | * Section: 5.1 Normal Establishment of an Association, B | |
238 | * B) "Z" shall respond immediately with an INIT ACK chunk. The | |
239 | * destination IP address of the INIT ACK MUST be set to the source | |
240 | * IP address of the INIT to which this INIT ACK is responding. In | |
241 | * the response, besides filling in other parameters, "Z" must set the | |
242 | * Verification Tag field to Tag_A, and also provide its own | |
243 | * Verification Tag (Tag_Z) in the Initiate Tag field. | |
244 | * | |
d808ad9a | 245 | * Verification Tag: Must be 0. |
1da177e4 LT |
246 | * |
247 | * Inputs | |
248 | * (endpoint, asoc, chunk) | |
249 | * | |
250 | * Outputs | |
251 | * (asoc, reply_msg, msg_up, timers, counters) | |
252 | * | |
253 | * The return value is the disposition of the chunk. | |
254 | */ | |
255 | sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep, | |
256 | const struct sctp_association *asoc, | |
257 | const sctp_subtype_t type, | |
258 | void *arg, | |
259 | sctp_cmd_seq_t *commands) | |
260 | { | |
261 | struct sctp_chunk *chunk = arg; | |
262 | struct sctp_chunk *repl; | |
263 | struct sctp_association *new_asoc; | |
264 | struct sctp_chunk *err_chunk; | |
265 | struct sctp_packet *packet; | |
266 | sctp_unrecognized_param_t *unk_param; | |
267 | struct sock *sk; | |
268 | int len; | |
269 | ||
270 | /* 6.10 Bundling | |
271 | * An endpoint MUST NOT bundle INIT, INIT ACK or | |
272 | * SHUTDOWN COMPLETE with any other chunks. | |
d808ad9a | 273 | * |
1da177e4 LT |
274 | * IG Section 2.11.2 |
275 | * Furthermore, we require that the receiver of an INIT chunk MUST | |
276 | * enforce these rules by silently discarding an arriving packet | |
277 | * with an INIT chunk that is bundled with other chunks. | |
278 | */ | |
279 | if (!chunk->singleton) | |
280 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
281 | ||
282 | /* If the packet is an OOTB packet which is temporarily on the | |
283 | * control endpoint, respond with an ABORT. | |
284 | */ | |
285 | if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) | |
286 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); | |
287 | ||
288 | sk = ep->base.sk; | |
289 | /* If the endpoint is not listening or if the number of associations | |
290 | * on the TCP-style socket exceed the max backlog, respond with an | |
291 | * ABORT. | |
292 | */ | |
293 | if (!sctp_sstate(sk, LISTENING) || | |
294 | (sctp_style(sk, TCP) && | |
295 | sk_acceptq_is_full(sk))) | |
296 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); | |
297 | ||
298 | /* 3.1 A packet containing an INIT chunk MUST have a zero Verification | |
d808ad9a | 299 | * Tag. |
1da177e4 LT |
300 | */ |
301 | if (chunk->sctp_hdr->vtag != 0) | |
302 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); | |
303 | ||
304 | /* Make sure that the INIT chunk has a valid length. | |
305 | * Normally, this would cause an ABORT with a Protocol Violation | |
306 | * error, but since we don't have an association, we'll | |
307 | * just discard the packet. | |
308 | */ | |
309 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t))) | |
310 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
311 | ||
312 | /* Verify the INIT chunk before processing it. */ | |
313 | err_chunk = NULL; | |
314 | if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, | |
315 | (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, | |
316 | &err_chunk)) { | |
317 | /* This chunk contains fatal error. It is to be discarded. | |
318 | * Send an ABORT, with causes if there is any. | |
319 | */ | |
320 | if (err_chunk) { | |
321 | packet = sctp_abort_pkt_new(ep, asoc, arg, | |
322 | (__u8 *)(err_chunk->chunk_hdr) + | |
323 | sizeof(sctp_chunkhdr_t), | |
324 | ntohs(err_chunk->chunk_hdr->length) - | |
325 | sizeof(sctp_chunkhdr_t)); | |
326 | ||
327 | sctp_chunk_free(err_chunk); | |
328 | ||
329 | if (packet) { | |
330 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, | |
331 | SCTP_PACKET(packet)); | |
332 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
333 | return SCTP_DISPOSITION_CONSUME; | |
334 | } else { | |
335 | return SCTP_DISPOSITION_NOMEM; | |
336 | } | |
337 | } else { | |
338 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, | |
339 | commands); | |
340 | } | |
341 | } | |
342 | ||
d808ad9a | 343 | /* Grab the INIT header. */ |
1da177e4 LT |
344 | chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data; |
345 | ||
346 | /* Tag the variable length parameters. */ | |
347 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); | |
348 | ||
349 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); | |
350 | if (!new_asoc) | |
351 | goto nomem; | |
352 | ||
353 | /* The call, sctp_process_init(), can fail on memory allocation. */ | |
354 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, | |
355 | sctp_source(chunk), | |
356 | (sctp_init_chunk_t *)chunk->chunk_hdr, | |
357 | GFP_ATOMIC)) | |
358 | goto nomem_init; | |
359 | ||
1da177e4 LT |
360 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
361 | ||
362 | /* If there are errors need to be reported for unknown parameters, | |
363 | * make sure to reserve enough room in the INIT ACK for them. | |
364 | */ | |
365 | len = 0; | |
366 | if (err_chunk) | |
367 | len = ntohs(err_chunk->chunk_hdr->length) - | |
368 | sizeof(sctp_chunkhdr_t); | |
369 | ||
370 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0) | |
df7deeb5 | 371 | goto nomem_init; |
1da177e4 LT |
372 | |
373 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); | |
374 | if (!repl) | |
df7deeb5 | 375 | goto nomem_init; |
1da177e4 LT |
376 | |
377 | /* If there are errors need to be reported for unknown parameters, | |
378 | * include them in the outgoing INIT ACK as "Unrecognized parameter" | |
379 | * parameter. | |
380 | */ | |
381 | if (err_chunk) { | |
382 | /* Get the "Unrecognized parameter" parameter(s) out of the | |
383 | * ERROR chunk generated by sctp_verify_init(). Since the | |
384 | * error cause code for "unknown parameter" and the | |
385 | * "Unrecognized parameter" type is the same, we can | |
386 | * construct the parameters in INIT ACK by copying the | |
387 | * ERROR causes over. | |
388 | */ | |
389 | unk_param = (sctp_unrecognized_param_t *) | |
390 | ((__u8 *)(err_chunk->chunk_hdr) + | |
391 | sizeof(sctp_chunkhdr_t)); | |
392 | /* Replace the cause code with the "Unrecognized parameter" | |
393 | * parameter type. | |
394 | */ | |
395 | sctp_addto_chunk(repl, len, unk_param); | |
396 | sctp_chunk_free(err_chunk); | |
397 | } | |
398 | ||
df7deeb5 VY |
399 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
400 | ||
1da177e4 LT |
401 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
402 | ||
403 | /* | |
404 | * Note: After sending out INIT ACK with the State Cookie parameter, | |
405 | * "Z" MUST NOT allocate any resources, nor keep any states for the | |
406 | * new association. Otherwise, "Z" will be vulnerable to resource | |
407 | * attacks. | |
408 | */ | |
409 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); | |
410 | ||
411 | return SCTP_DISPOSITION_DELETE_TCB; | |
412 | ||
1da177e4 LT |
413 | nomem_init: |
414 | sctp_association_free(new_asoc); | |
415 | nomem: | |
df7deeb5 VY |
416 | if (err_chunk) |
417 | sctp_chunk_free(err_chunk); | |
1da177e4 LT |
418 | return SCTP_DISPOSITION_NOMEM; |
419 | } | |
420 | ||
421 | /* | |
422 | * Respond to a normal INIT ACK chunk. | |
423 | * We are the side that is initiating the association. | |
424 | * | |
425 | * Section: 5.1 Normal Establishment of an Association, C | |
426 | * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init | |
427 | * timer and leave COOKIE-WAIT state. "A" shall then send the State | |
428 | * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start | |
429 | * the T1-cookie timer, and enter the COOKIE-ECHOED state. | |
430 | * | |
431 | * Note: The COOKIE ECHO chunk can be bundled with any pending outbound | |
432 | * DATA chunks, but it MUST be the first chunk in the packet and | |
433 | * until the COOKIE ACK is returned the sender MUST NOT send any | |
434 | * other packets to the peer. | |
435 | * | |
436 | * Verification Tag: 3.3.3 | |
437 | * If the value of the Initiate Tag in a received INIT ACK chunk is | |
438 | * found to be 0, the receiver MUST treat it as an error and close the | |
439 | * association by transmitting an ABORT. | |
440 | * | |
441 | * Inputs | |
442 | * (endpoint, asoc, chunk) | |
443 | * | |
444 | * Outputs | |
445 | * (asoc, reply_msg, msg_up, timers, counters) | |
446 | * | |
447 | * The return value is the disposition of the chunk. | |
448 | */ | |
449 | sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep, | |
450 | const struct sctp_association *asoc, | |
451 | const sctp_subtype_t type, | |
452 | void *arg, | |
453 | sctp_cmd_seq_t *commands) | |
454 | { | |
455 | struct sctp_chunk *chunk = arg; | |
456 | sctp_init_chunk_t *initchunk; | |
1da177e4 LT |
457 | struct sctp_chunk *err_chunk; |
458 | struct sctp_packet *packet; | |
f94c0198 | 459 | sctp_error_t error; |
1da177e4 LT |
460 | |
461 | if (!sctp_vtag_verify(chunk, asoc)) | |
462 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
463 | ||
464 | /* Make sure that the INIT-ACK chunk has a valid length */ | |
465 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t))) | |
466 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
467 | commands); | |
468 | /* 6.10 Bundling | |
469 | * An endpoint MUST NOT bundle INIT, INIT ACK or | |
470 | * SHUTDOWN COMPLETE with any other chunks. | |
471 | */ | |
472 | if (!chunk->singleton) | |
473 | return SCTP_DISPOSITION_VIOLATION; | |
474 | ||
475 | /* Grab the INIT header. */ | |
476 | chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data; | |
477 | ||
1da177e4 LT |
478 | /* Verify the INIT chunk before processing it. */ |
479 | err_chunk = NULL; | |
480 | if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, | |
481 | (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, | |
482 | &err_chunk)) { | |
483 | ||
484 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); | |
485 | ||
486 | /* This chunk contains fatal error. It is to be discarded. | |
487 | * Send an ABORT, with causes if there is any. | |
488 | */ | |
489 | if (err_chunk) { | |
490 | packet = sctp_abort_pkt_new(ep, asoc, arg, | |
491 | (__u8 *)(err_chunk->chunk_hdr) + | |
492 | sizeof(sctp_chunkhdr_t), | |
493 | ntohs(err_chunk->chunk_hdr->length) - | |
494 | sizeof(sctp_chunkhdr_t)); | |
495 | ||
496 | sctp_chunk_free(err_chunk); | |
497 | ||
498 | if (packet) { | |
499 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, | |
500 | SCTP_PACKET(packet)); | |
501 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
8de8c873 | 502 | error = SCTP_ERROR_INV_PARAM; |
1da177e4 | 503 | } else { |
8de8c873 | 504 | error = SCTP_ERROR_NO_RESOURCE; |
1da177e4 LT |
505 | } |
506 | } else { | |
8de8c873 SS |
507 | sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
508 | error = SCTP_ERROR_INV_PARAM; | |
1da177e4 | 509 | } |
8de8c873 SS |
510 | return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, |
511 | asoc, chunk->transport); | |
1da177e4 LT |
512 | } |
513 | ||
514 | /* Tag the variable length parameters. Note that we never | |
515 | * convert the parameters in an INIT chunk. | |
516 | */ | |
517 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); | |
518 | ||
519 | initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr; | |
520 | ||
521 | sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT, | |
522 | SCTP_PEER_INIT(initchunk)); | |
523 | ||
3f7a87d2 FF |
524 | /* Reset init error count upon receipt of INIT-ACK. */ |
525 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); | |
526 | ||
1da177e4 LT |
527 | /* 5.1 C) "A" shall stop the T1-init timer and leave |
528 | * COOKIE-WAIT state. "A" shall then ... start the T1-cookie | |
529 | * timer, and enter the COOKIE-ECHOED state. | |
530 | */ | |
531 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
532 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
533 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
534 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); | |
535 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
536 | SCTP_STATE(SCTP_STATE_COOKIE_ECHOED)); | |
537 | ||
538 | /* 5.1 C) "A" shall then send the State Cookie received in the | |
539 | * INIT ACK chunk in a COOKIE ECHO chunk, ... | |
540 | */ | |
541 | /* If there is any errors to report, send the ERROR chunk generated | |
542 | * for unknown parameters as well. | |
543 | */ | |
544 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO, | |
545 | SCTP_CHUNK(err_chunk)); | |
546 | ||
547 | return SCTP_DISPOSITION_CONSUME; | |
1da177e4 LT |
548 | } |
549 | ||
550 | /* | |
551 | * Respond to a normal COOKIE ECHO chunk. | |
552 | * We are the side that is being asked for an association. | |
553 | * | |
554 | * Section: 5.1 Normal Establishment of an Association, D | |
555 | * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply | |
556 | * with a COOKIE ACK chunk after building a TCB and moving to | |
557 | * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with | |
558 | * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK | |
559 | * chunk MUST be the first chunk in the packet. | |
560 | * | |
561 | * IMPLEMENTATION NOTE: An implementation may choose to send the | |
562 | * Communication Up notification to the SCTP user upon reception | |
563 | * of a valid COOKIE ECHO chunk. | |
564 | * | |
565 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules | |
566 | * D) Rules for packet carrying a COOKIE ECHO | |
567 | * | |
568 | * - When sending a COOKIE ECHO, the endpoint MUST use the value of the | |
569 | * Initial Tag received in the INIT ACK. | |
570 | * | |
571 | * - The receiver of a COOKIE ECHO follows the procedures in Section 5. | |
572 | * | |
573 | * Inputs | |
574 | * (endpoint, asoc, chunk) | |
575 | * | |
576 | * Outputs | |
577 | * (asoc, reply_msg, msg_up, timers, counters) | |
578 | * | |
579 | * The return value is the disposition of the chunk. | |
580 | */ | |
581 | sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep, | |
582 | const struct sctp_association *asoc, | |
583 | const sctp_subtype_t type, void *arg, | |
584 | sctp_cmd_seq_t *commands) | |
585 | { | |
586 | struct sctp_chunk *chunk = arg; | |
587 | struct sctp_association *new_asoc; | |
588 | sctp_init_chunk_t *peer_init; | |
589 | struct sctp_chunk *repl; | |
df7deeb5 | 590 | struct sctp_ulpevent *ev, *ai_ev = NULL; |
1da177e4 LT |
591 | int error = 0; |
592 | struct sctp_chunk *err_chk_p; | |
593 | ||
594 | /* If the packet is an OOTB packet which is temporarily on the | |
595 | * control endpoint, respond with an ABORT. | |
596 | */ | |
597 | if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) | |
598 | return sctp_sf_ootb(ep, asoc, type, arg, commands); | |
599 | ||
600 | /* Make sure that the COOKIE_ECHO chunk has a valid length. | |
601 | * In this case, we check that we have enough for at least a | |
602 | * chunk header. More detailed verification is done | |
603 | * in sctp_unpack_cookie(). | |
604 | */ | |
605 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) | |
606 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
607 | ||
608 | /* "Decode" the chunk. We have no optional parameters so we | |
609 | * are in good shape. | |
610 | */ | |
d808ad9a | 611 | chunk->subh.cookie_hdr = |
1da177e4 | 612 | (struct sctp_signed_cookie *)chunk->skb->data; |
62b08083 SS |
613 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
614 | sizeof(sctp_chunkhdr_t))) | |
615 | goto nomem; | |
1da177e4 LT |
616 | |
617 | /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint | |
618 | * "Z" will reply with a COOKIE ACK chunk after building a TCB | |
619 | * and moving to the ESTABLISHED state. | |
620 | */ | |
621 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, | |
622 | &err_chk_p); | |
623 | ||
624 | /* FIXME: | |
625 | * If the re-build failed, what is the proper error path | |
626 | * from here? | |
627 | * | |
628 | * [We should abort the association. --piggy] | |
629 | */ | |
630 | if (!new_asoc) { | |
631 | /* FIXME: Several errors are possible. A bad cookie should | |
632 | * be silently discarded, but think about logging it too. | |
633 | */ | |
634 | switch (error) { | |
635 | case -SCTP_IERROR_NOMEM: | |
636 | goto nomem; | |
637 | ||
638 | case -SCTP_IERROR_STALE_COOKIE: | |
639 | sctp_send_stale_cookie_err(ep, asoc, chunk, commands, | |
640 | err_chk_p); | |
641 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
642 | ||
643 | case -SCTP_IERROR_BAD_SIG: | |
644 | default: | |
645 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3ff50b79 | 646 | } |
1da177e4 LT |
647 | } |
648 | ||
1da177e4 | 649 | |
df7deeb5 VY |
650 | /* Delay state machine commands until later. |
651 | * | |
652 | * Re-build the bind address for the association is done in | |
1da177e4 LT |
653 | * the sctp_unpack_cookie() already. |
654 | */ | |
655 | /* This is a brand-new association, so these are not yet side | |
656 | * effects--it is safe to run them here. | |
657 | */ | |
658 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; | |
659 | ||
660 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, | |
6a1e5f33 | 661 | &chunk->subh.cookie_hdr->c.peer_addr, |
1da177e4 LT |
662 | peer_init, GFP_ATOMIC)) |
663 | goto nomem_init; | |
664 | ||
665 | repl = sctp_make_cookie_ack(new_asoc, chunk); | |
666 | if (!repl) | |
df7deeb5 | 667 | goto nomem_init; |
1da177e4 LT |
668 | |
669 | /* RFC 2960 5.1 Normal Establishment of an Association | |
670 | * | |
671 | * D) IMPLEMENTATION NOTE: An implementation may choose to | |
672 | * send the Communication Up notification to the SCTP user | |
673 | * upon reception of a valid COOKIE ECHO chunk. | |
674 | */ | |
675 | ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0, | |
676 | new_asoc->c.sinit_num_ostreams, | |
677 | new_asoc->c.sinit_max_instreams, | |
a5a35e76 | 678 | NULL, GFP_ATOMIC); |
1da177e4 LT |
679 | if (!ev) |
680 | goto nomem_ev; | |
681 | ||
d808ad9a | 682 | /* Sockets API Draft Section 5.3.1.6 |
0f3fffd8 | 683 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
1da177e4 | 684 | * delivers this notification to inform the application that of the |
0f3fffd8 | 685 | * peers requested adaptation layer. |
1da177e4 | 686 | */ |
0f3fffd8 ISJ |
687 | if (new_asoc->peer.adaptation_ind) { |
688 | ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc, | |
1da177e4 | 689 | GFP_ATOMIC); |
df7deeb5 VY |
690 | if (!ai_ev) |
691 | goto nomem_aiev; | |
692 | } | |
693 | ||
694 | /* Add all the state machine commands now since we've created | |
695 | * everything. This way we don't introduce memory corruptions | |
696 | * during side-effect processing and correclty count established | |
697 | * associations. | |
698 | */ | |
699 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); | |
700 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
701 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); | |
702 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); | |
703 | SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS); | |
704 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); | |
705 | ||
706 | if (new_asoc->autoclose) | |
707 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
708 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); | |
709 | ||
710 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); | |
1da177e4 | 711 | |
df7deeb5 VY |
712 | /* This will send the COOKIE ACK */ |
713 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); | |
714 | ||
715 | /* Queue the ASSOC_CHANGE event */ | |
716 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); | |
717 | ||
718 | /* Send up the Adaptation Layer Indication event */ | |
719 | if (ai_ev) | |
1da177e4 | 720 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
df7deeb5 | 721 | SCTP_ULPEVENT(ai_ev)); |
1da177e4 LT |
722 | |
723 | return SCTP_DISPOSITION_CONSUME; | |
724 | ||
df7deeb5 VY |
725 | nomem_aiev: |
726 | sctp_ulpevent_free(ev); | |
1da177e4 LT |
727 | nomem_ev: |
728 | sctp_chunk_free(repl); | |
1da177e4 LT |
729 | nomem_init: |
730 | sctp_association_free(new_asoc); | |
731 | nomem: | |
732 | return SCTP_DISPOSITION_NOMEM; | |
733 | } | |
734 | ||
735 | /* | |
736 | * Respond to a normal COOKIE ACK chunk. | |
737 | * We are the side that is being asked for an association. | |
738 | * | |
739 | * RFC 2960 5.1 Normal Establishment of an Association | |
740 | * | |
741 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the | |
742 | * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie | |
743 | * timer. It may also notify its ULP about the successful | |
744 | * establishment of the association with a Communication Up | |
745 | * notification (see Section 10). | |
746 | * | |
747 | * Verification Tag: | |
748 | * Inputs | |
749 | * (endpoint, asoc, chunk) | |
750 | * | |
751 | * Outputs | |
752 | * (asoc, reply_msg, msg_up, timers, counters) | |
753 | * | |
754 | * The return value is the disposition of the chunk. | |
755 | */ | |
756 | sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep, | |
757 | const struct sctp_association *asoc, | |
758 | const sctp_subtype_t type, void *arg, | |
759 | sctp_cmd_seq_t *commands) | |
760 | { | |
761 | struct sctp_chunk *chunk = arg; | |
762 | struct sctp_ulpevent *ev; | |
763 | ||
764 | if (!sctp_vtag_verify(chunk, asoc)) | |
765 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
766 | ||
767 | /* Verify that the chunk length for the COOKIE-ACK is OK. | |
768 | * If we don't do this, any bundled chunks may be junked. | |
769 | */ | |
770 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) | |
771 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
772 | commands); | |
773 | ||
774 | /* Reset init error count upon receipt of COOKIE-ACK, | |
775 | * to avoid problems with the managemement of this | |
776 | * counter in stale cookie situations when a transition back | |
777 | * from the COOKIE-ECHOED state to the COOKIE-WAIT | |
778 | * state is performed. | |
779 | */ | |
3f7a87d2 | 780 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
1da177e4 LT |
781 | |
782 | /* RFC 2960 5.1 Normal Establishment of an Association | |
783 | * | |
784 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move | |
785 | * from the COOKIE-ECHOED state to the ESTABLISHED state, | |
786 | * stopping the T1-cookie timer. | |
787 | */ | |
788 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
789 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); | |
790 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
791 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); | |
792 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); | |
793 | SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS); | |
794 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); | |
795 | if (asoc->autoclose) | |
796 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
797 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); | |
798 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); | |
799 | ||
800 | /* It may also notify its ULP about the successful | |
801 | * establishment of the association with a Communication Up | |
802 | * notification (see Section 10). | |
803 | */ | |
804 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, | |
805 | 0, asoc->c.sinit_num_ostreams, | |
806 | asoc->c.sinit_max_instreams, | |
a5a35e76 | 807 | NULL, GFP_ATOMIC); |
1da177e4 LT |
808 | |
809 | if (!ev) | |
810 | goto nomem; | |
811 | ||
812 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); | |
813 | ||
814 | /* Sockets API Draft Section 5.3.1.6 | |
0f3fffd8 | 815 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
1da177e4 | 816 | * delivers this notification to inform the application that of the |
0f3fffd8 | 817 | * peers requested adaptation layer. |
1da177e4 | 818 | */ |
0f3fffd8 ISJ |
819 | if (asoc->peer.adaptation_ind) { |
820 | ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC); | |
1da177e4 LT |
821 | if (!ev) |
822 | goto nomem; | |
823 | ||
824 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, | |
825 | SCTP_ULPEVENT(ev)); | |
826 | } | |
827 | ||
828 | return SCTP_DISPOSITION_CONSUME; | |
829 | nomem: | |
830 | return SCTP_DISPOSITION_NOMEM; | |
831 | } | |
832 | ||
833 | /* Generate and sendout a heartbeat packet. */ | |
834 | static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep, | |
835 | const struct sctp_association *asoc, | |
836 | const sctp_subtype_t type, | |
837 | void *arg, | |
838 | sctp_cmd_seq_t *commands) | |
839 | { | |
840 | struct sctp_transport *transport = (struct sctp_transport *) arg; | |
841 | struct sctp_chunk *reply; | |
842 | sctp_sender_hb_info_t hbinfo; | |
843 | size_t paylen = 0; | |
844 | ||
845 | hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO; | |
846 | hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t)); | |
63de08f4 | 847 | hbinfo.daddr = transport->ipaddr; |
1da177e4 | 848 | hbinfo.sent_at = jiffies; |
ad8fec17 | 849 | hbinfo.hb_nonce = transport->hb_nonce; |
1da177e4 LT |
850 | |
851 | /* Send a heartbeat to our peer. */ | |
852 | paylen = sizeof(sctp_sender_hb_info_t); | |
853 | reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen); | |
854 | if (!reply) | |
855 | return SCTP_DISPOSITION_NOMEM; | |
856 | ||
857 | /* Set rto_pending indicating that an RTT measurement | |
858 | * is started with this heartbeat chunk. | |
859 | */ | |
860 | sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING, | |
861 | SCTP_TRANSPORT(transport)); | |
862 | ||
863 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
864 | return SCTP_DISPOSITION_CONSUME; | |
865 | } | |
866 | ||
867 | /* Generate a HEARTBEAT packet on the given transport. */ | |
868 | sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep, | |
869 | const struct sctp_association *asoc, | |
870 | const sctp_subtype_t type, | |
871 | void *arg, | |
872 | sctp_cmd_seq_t *commands) | |
873 | { | |
874 | struct sctp_transport *transport = (struct sctp_transport *) arg; | |
875 | ||
e2c2fc2c | 876 | if (asoc->overall_error_count >= asoc->max_retrans) { |
8de8c873 SS |
877 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
878 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 LT |
879 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
880 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, | |
5be291fe | 881 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
1da177e4 LT |
882 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
883 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
884 | return SCTP_DISPOSITION_DELETE_TCB; | |
885 | } | |
886 | ||
887 | /* Section 3.3.5. | |
888 | * The Sender-specific Heartbeat Info field should normally include | |
889 | * information about the sender's current time when this HEARTBEAT | |
890 | * chunk is sent and the destination transport address to which this | |
891 | * HEARTBEAT is sent (see Section 8.3). | |
892 | */ | |
893 | ||
52ccb8e9 | 894 | if (transport->param_flags & SPP_HB_ENABLE) { |
1da177e4 LT |
895 | if (SCTP_DISPOSITION_NOMEM == |
896 | sctp_sf_heartbeat(ep, asoc, type, arg, | |
897 | commands)) | |
898 | return SCTP_DISPOSITION_NOMEM; | |
899 | /* Set transport error counter and association error counter | |
900 | * when sending heartbeat. | |
901 | */ | |
902 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET, | |
903 | SCTP_TRANSPORT(transport)); | |
904 | } | |
905 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE, | |
906 | SCTP_TRANSPORT(transport)); | |
907 | ||
d808ad9a | 908 | return SCTP_DISPOSITION_CONSUME; |
1da177e4 LT |
909 | } |
910 | ||
911 | /* | |
912 | * Process an heartbeat request. | |
913 | * | |
914 | * Section: 8.3 Path Heartbeat | |
915 | * The receiver of the HEARTBEAT should immediately respond with a | |
916 | * HEARTBEAT ACK that contains the Heartbeat Information field copied | |
917 | * from the received HEARTBEAT chunk. | |
918 | * | |
919 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
920 | * When receiving an SCTP packet, the endpoint MUST ensure that the | |
921 | * value in the Verification Tag field of the received SCTP packet | |
922 | * matches its own Tag. If the received Verification Tag value does not | |
923 | * match the receiver's own tag value, the receiver shall silently | |
924 | * discard the packet and shall not process it any further except for | |
925 | * those cases listed in Section 8.5.1 below. | |
926 | * | |
927 | * Inputs | |
928 | * (endpoint, asoc, chunk) | |
929 | * | |
930 | * Outputs | |
931 | * (asoc, reply_msg, msg_up, timers, counters) | |
932 | * | |
933 | * The return value is the disposition of the chunk. | |
934 | */ | |
935 | sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep, | |
936 | const struct sctp_association *asoc, | |
937 | const sctp_subtype_t type, | |
938 | void *arg, | |
939 | sctp_cmd_seq_t *commands) | |
940 | { | |
941 | struct sctp_chunk *chunk = arg; | |
942 | struct sctp_chunk *reply; | |
943 | size_t paylen = 0; | |
944 | ||
945 | if (!sctp_vtag_verify(chunk, asoc)) | |
946 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
947 | ||
948 | /* Make sure that the HEARTBEAT chunk has a valid length. */ | |
949 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t))) | |
950 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
951 | commands); | |
952 | ||
953 | /* 8.3 The receiver of the HEARTBEAT should immediately | |
954 | * respond with a HEARTBEAT ACK that contains the Heartbeat | |
955 | * Information field copied from the received HEARTBEAT chunk. | |
956 | */ | |
957 | chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data; | |
958 | paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t); | |
62b08083 SS |
959 | if (!pskb_pull(chunk->skb, paylen)) |
960 | goto nomem; | |
1da177e4 LT |
961 | |
962 | reply = sctp_make_heartbeat_ack(asoc, chunk, | |
963 | chunk->subh.hb_hdr, paylen); | |
964 | if (!reply) | |
965 | goto nomem; | |
966 | ||
967 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
968 | return SCTP_DISPOSITION_CONSUME; | |
969 | ||
970 | nomem: | |
971 | return SCTP_DISPOSITION_NOMEM; | |
972 | } | |
973 | ||
974 | /* | |
975 | * Process the returning HEARTBEAT ACK. | |
976 | * | |
977 | * Section: 8.3 Path Heartbeat | |
978 | * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT | |
979 | * should clear the error counter of the destination transport | |
980 | * address to which the HEARTBEAT was sent, and mark the destination | |
981 | * transport address as active if it is not so marked. The endpoint may | |
982 | * optionally report to the upper layer when an inactive destination | |
983 | * address is marked as active due to the reception of the latest | |
984 | * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also | |
985 | * clear the association overall error count as well (as defined | |
986 | * in section 8.1). | |
987 | * | |
988 | * The receiver of the HEARTBEAT ACK should also perform an RTT | |
989 | * measurement for that destination transport address using the time | |
990 | * value carried in the HEARTBEAT ACK chunk. | |
991 | * | |
992 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
993 | * | |
994 | * Inputs | |
995 | * (endpoint, asoc, chunk) | |
996 | * | |
997 | * Outputs | |
998 | * (asoc, reply_msg, msg_up, timers, counters) | |
999 | * | |
1000 | * The return value is the disposition of the chunk. | |
1001 | */ | |
1002 | sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep, | |
1003 | const struct sctp_association *asoc, | |
1004 | const sctp_subtype_t type, | |
1005 | void *arg, | |
1006 | sctp_cmd_seq_t *commands) | |
1007 | { | |
1008 | struct sctp_chunk *chunk = arg; | |
1009 | union sctp_addr from_addr; | |
1010 | struct sctp_transport *link; | |
1011 | sctp_sender_hb_info_t *hbinfo; | |
1012 | unsigned long max_interval; | |
1013 | ||
1014 | if (!sctp_vtag_verify(chunk, asoc)) | |
1015 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
1016 | ||
1017 | /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */ | |
1018 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t))) | |
1019 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
1020 | commands); | |
1021 | ||
1022 | hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data; | |
a601266e VY |
1023 | /* Make sure that the length of the parameter is what we expect */ |
1024 | if (ntohs(hbinfo->param_hdr.length) != | |
1025 | sizeof(sctp_sender_hb_info_t)) { | |
1026 | return SCTP_DISPOSITION_DISCARD; | |
1027 | } | |
1028 | ||
1da177e4 | 1029 | from_addr = hbinfo->daddr; |
63de08f4 | 1030 | link = sctp_assoc_lookup_paddr(asoc, &from_addr); |
1da177e4 LT |
1031 | |
1032 | /* This should never happen, but lets log it if so. */ | |
3f7a87d2 FF |
1033 | if (unlikely(!link)) { |
1034 | if (from_addr.sa.sa_family == AF_INET6) { | |
d99fa429 WY |
1035 | if (net_ratelimit()) |
1036 | printk(KERN_WARNING | |
1037 | "%s association %p could not find address " | |
1038 | NIP6_FMT "\n", | |
1039 | __FUNCTION__, | |
1040 | asoc, | |
1041 | NIP6(from_addr.v6.sin6_addr)); | |
3f7a87d2 | 1042 | } else { |
d99fa429 WY |
1043 | if (net_ratelimit()) |
1044 | printk(KERN_WARNING | |
1045 | "%s association %p could not find address " | |
1046 | NIPQUAD_FMT "\n", | |
1047 | __FUNCTION__, | |
1048 | asoc, | |
1049 | NIPQUAD(from_addr.v4.sin_addr.s_addr)); | |
3f7a87d2 | 1050 | } |
1da177e4 LT |
1051 | return SCTP_DISPOSITION_DISCARD; |
1052 | } | |
1053 | ||
ad8fec17 SS |
1054 | /* Validate the 64-bit random nonce. */ |
1055 | if (hbinfo->hb_nonce != link->hb_nonce) | |
1056 | return SCTP_DISPOSITION_DISCARD; | |
1057 | ||
52ccb8e9 | 1058 | max_interval = link->hbinterval + link->rto; |
1da177e4 LT |
1059 | |
1060 | /* Check if the timestamp looks valid. */ | |
1061 | if (time_after(hbinfo->sent_at, jiffies) || | |
1062 | time_after(jiffies, hbinfo->sent_at + max_interval)) { | |
1063 | SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp" | |
1064 | "received for transport: %p\n", | |
1065 | __FUNCTION__, link); | |
1066 | return SCTP_DISPOSITION_DISCARD; | |
1067 | } | |
1068 | ||
1069 | /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of | |
1070 | * the HEARTBEAT should clear the error counter of the | |
1071 | * destination transport address to which the HEARTBEAT was | |
1072 | * sent and mark the destination transport address as active if | |
1073 | * it is not so marked. | |
1074 | */ | |
1075 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link)); | |
1076 | ||
1077 | return SCTP_DISPOSITION_CONSUME; | |
1078 | } | |
1079 | ||
1080 | /* Helper function to send out an abort for the restart | |
1081 | * condition. | |
1082 | */ | |
1083 | static int sctp_sf_send_restart_abort(union sctp_addr *ssa, | |
1084 | struct sctp_chunk *init, | |
1085 | sctp_cmd_seq_t *commands) | |
1086 | { | |
1087 | int len; | |
1088 | struct sctp_packet *pkt; | |
1089 | union sctp_addr_param *addrparm; | |
1090 | struct sctp_errhdr *errhdr; | |
1091 | struct sctp_endpoint *ep; | |
1092 | char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)]; | |
1093 | struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family); | |
1094 | ||
1095 | /* Build the error on the stack. We are way to malloc crazy | |
1096 | * throughout the code today. | |
1097 | */ | |
1098 | errhdr = (struct sctp_errhdr *)buffer; | |
1099 | addrparm = (union sctp_addr_param *)errhdr->variable; | |
1100 | ||
1101 | /* Copy into a parm format. */ | |
1102 | len = af->to_addr_param(ssa, addrparm); | |
1103 | len += sizeof(sctp_errhdr_t); | |
1104 | ||
1105 | errhdr->cause = SCTP_ERROR_RESTART; | |
1106 | errhdr->length = htons(len); | |
1107 | ||
1108 | /* Assign to the control socket. */ | |
1109 | ep = sctp_sk((sctp_get_ctl_sock()))->ep; | |
1110 | ||
1111 | /* Association is NULL since this may be a restart attack and we | |
1112 | * want to send back the attacker's vtag. | |
1113 | */ | |
1114 | pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len); | |
1115 | ||
1116 | if (!pkt) | |
1117 | goto out; | |
1118 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt)); | |
1119 | ||
1120 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
1121 | ||
1122 | /* Discard the rest of the inbound packet. */ | |
1123 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); | |
1124 | ||
1125 | out: | |
1126 | /* Even if there is no memory, treat as a failure so | |
1127 | * the packet will get dropped. | |
1128 | */ | |
1129 | return 0; | |
1130 | } | |
1131 | ||
1132 | /* A restart is occurring, check to make sure no new addresses | |
1133 | * are being added as we may be under a takeover attack. | |
1134 | */ | |
1135 | static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, | |
1136 | const struct sctp_association *asoc, | |
1137 | struct sctp_chunk *init, | |
1138 | sctp_cmd_seq_t *commands) | |
1139 | { | |
1140 | struct sctp_transport *new_addr, *addr; | |
1141 | struct list_head *pos, *pos2; | |
1142 | int found; | |
1143 | ||
1144 | /* Implementor's Guide - Sectin 5.2.2 | |
1145 | * ... | |
1146 | * Before responding the endpoint MUST check to see if the | |
1147 | * unexpected INIT adds new addresses to the association. If new | |
1148 | * addresses are added to the association, the endpoint MUST respond | |
1149 | * with an ABORT.. | |
1150 | */ | |
1151 | ||
1152 | /* Search through all current addresses and make sure | |
1153 | * we aren't adding any new ones. | |
1154 | */ | |
1155 | new_addr = NULL; | |
1156 | found = 0; | |
1157 | ||
1158 | list_for_each(pos, &new_asoc->peer.transport_addr_list) { | |
1159 | new_addr = list_entry(pos, struct sctp_transport, transports); | |
1160 | found = 0; | |
1161 | list_for_each(pos2, &asoc->peer.transport_addr_list) { | |
1162 | addr = list_entry(pos2, struct sctp_transport, | |
1163 | transports); | |
5f242a13 AV |
1164 | if (sctp_cmp_addr_exact(&new_addr->ipaddr, |
1165 | &addr->ipaddr)) { | |
1da177e4 LT |
1166 | found = 1; |
1167 | break; | |
1168 | } | |
1169 | } | |
1170 | if (!found) | |
1171 | break; | |
1172 | } | |
1173 | ||
1174 | /* If a new address was added, ABORT the sender. */ | |
1175 | if (!found && new_addr) { | |
7dd8a582 | 1176 | sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands); |
1da177e4 LT |
1177 | } |
1178 | ||
1179 | /* Return success if all addresses were found. */ | |
1180 | return found; | |
1181 | } | |
1182 | ||
1183 | /* Populate the verification/tie tags based on overlapping INIT | |
1184 | * scenario. | |
1185 | * | |
1186 | * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state. | |
1187 | */ | |
1188 | static void sctp_tietags_populate(struct sctp_association *new_asoc, | |
1189 | const struct sctp_association *asoc) | |
1190 | { | |
1191 | switch (asoc->state) { | |
1192 | ||
1193 | /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */ | |
1194 | ||
1195 | case SCTP_STATE_COOKIE_WAIT: | |
1196 | new_asoc->c.my_vtag = asoc->c.my_vtag; | |
1197 | new_asoc->c.my_ttag = asoc->c.my_vtag; | |
1198 | new_asoc->c.peer_ttag = 0; | |
1199 | break; | |
1200 | ||
1201 | case SCTP_STATE_COOKIE_ECHOED: | |
1202 | new_asoc->c.my_vtag = asoc->c.my_vtag; | |
1203 | new_asoc->c.my_ttag = asoc->c.my_vtag; | |
1204 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; | |
1205 | break; | |
1206 | ||
1207 | /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED, | |
1208 | * COOKIE-WAIT and SHUTDOWN-ACK-SENT | |
1209 | */ | |
1210 | default: | |
1211 | new_asoc->c.my_ttag = asoc->c.my_vtag; | |
1212 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; | |
1213 | break; | |
3ff50b79 | 1214 | } |
1da177e4 LT |
1215 | |
1216 | /* Other parameters for the endpoint SHOULD be copied from the | |
1217 | * existing parameters of the association (e.g. number of | |
1218 | * outbound streams) into the INIT ACK and cookie. | |
1219 | */ | |
1220 | new_asoc->rwnd = asoc->rwnd; | |
1221 | new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams; | |
1222 | new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams; | |
1223 | new_asoc->c.initial_tsn = asoc->c.initial_tsn; | |
1224 | } | |
1225 | ||
1226 | /* | |
1227 | * Compare vtag/tietag values to determine unexpected COOKIE-ECHO | |
1228 | * handling action. | |
1229 | * | |
1230 | * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists. | |
1231 | * | |
1232 | * Returns value representing action to be taken. These action values | |
1233 | * correspond to Action/Description values in RFC 2960, Table 2. | |
1234 | */ | |
1235 | static char sctp_tietags_compare(struct sctp_association *new_asoc, | |
1236 | const struct sctp_association *asoc) | |
1237 | { | |
1238 | /* In this case, the peer may have restarted. */ | |
1239 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && | |
1240 | (asoc->c.peer_vtag != new_asoc->c.peer_vtag) && | |
1241 | (asoc->c.my_vtag == new_asoc->c.my_ttag) && | |
1242 | (asoc->c.peer_vtag == new_asoc->c.peer_ttag)) | |
1243 | return 'A'; | |
1244 | ||
1245 | /* Collision case B. */ | |
1246 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && | |
1247 | ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) || | |
1248 | (0 == asoc->c.peer_vtag))) { | |
1249 | return 'B'; | |
1250 | } | |
1251 | ||
1252 | /* Collision case D. */ | |
1253 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && | |
1254 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag)) | |
1255 | return 'D'; | |
1256 | ||
1257 | /* Collision case C. */ | |
1258 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && | |
1259 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag) && | |
1260 | (0 == new_asoc->c.my_ttag) && | |
1261 | (0 == new_asoc->c.peer_ttag)) | |
1262 | return 'C'; | |
1263 | ||
1264 | /* No match to any of the special cases; discard this packet. */ | |
1265 | return 'E'; | |
1266 | } | |
1267 | ||
1268 | /* Common helper routine for both duplicate and simulataneous INIT | |
1269 | * chunk handling. | |
1270 | */ | |
1271 | static sctp_disposition_t sctp_sf_do_unexpected_init( | |
1272 | const struct sctp_endpoint *ep, | |
1273 | const struct sctp_association *asoc, | |
1274 | const sctp_subtype_t type, | |
1275 | void *arg, sctp_cmd_seq_t *commands) | |
1276 | { | |
1277 | sctp_disposition_t retval; | |
1278 | struct sctp_chunk *chunk = arg; | |
1279 | struct sctp_chunk *repl; | |
1280 | struct sctp_association *new_asoc; | |
1281 | struct sctp_chunk *err_chunk; | |
1282 | struct sctp_packet *packet; | |
1283 | sctp_unrecognized_param_t *unk_param; | |
1284 | int len; | |
1285 | ||
1286 | /* 6.10 Bundling | |
1287 | * An endpoint MUST NOT bundle INIT, INIT ACK or | |
1288 | * SHUTDOWN COMPLETE with any other chunks. | |
1289 | * | |
1290 | * IG Section 2.11.2 | |
1291 | * Furthermore, we require that the receiver of an INIT chunk MUST | |
1292 | * enforce these rules by silently discarding an arriving packet | |
1293 | * with an INIT chunk that is bundled with other chunks. | |
1294 | */ | |
1295 | if (!chunk->singleton) | |
1296 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
1297 | ||
1298 | /* 3.1 A packet containing an INIT chunk MUST have a zero Verification | |
d808ad9a | 1299 | * Tag. |
1da177e4 LT |
1300 | */ |
1301 | if (chunk->sctp_hdr->vtag != 0) | |
1302 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); | |
1303 | ||
1304 | /* Make sure that the INIT chunk has a valid length. | |
1305 | * In this case, we generate a protocol violation since we have | |
1306 | * an association established. | |
1307 | */ | |
1308 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t))) | |
1309 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
1310 | commands); | |
1311 | /* Grab the INIT header. */ | |
1312 | chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data; | |
1313 | ||
1314 | /* Tag the variable length parameters. */ | |
1315 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); | |
1316 | ||
1317 | /* Verify the INIT chunk before processing it. */ | |
1318 | err_chunk = NULL; | |
1319 | if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, | |
1320 | (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, | |
1321 | &err_chunk)) { | |
1322 | /* This chunk contains fatal error. It is to be discarded. | |
1323 | * Send an ABORT, with causes if there is any. | |
1324 | */ | |
1325 | if (err_chunk) { | |
1326 | packet = sctp_abort_pkt_new(ep, asoc, arg, | |
1327 | (__u8 *)(err_chunk->chunk_hdr) + | |
1328 | sizeof(sctp_chunkhdr_t), | |
1329 | ntohs(err_chunk->chunk_hdr->length) - | |
1330 | sizeof(sctp_chunkhdr_t)); | |
1331 | ||
1332 | if (packet) { | |
1333 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, | |
1334 | SCTP_PACKET(packet)); | |
1335 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
1336 | retval = SCTP_DISPOSITION_CONSUME; | |
1337 | } else { | |
1338 | retval = SCTP_DISPOSITION_NOMEM; | |
1339 | } | |
1340 | goto cleanup; | |
1341 | } else { | |
1342 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, | |
1343 | commands); | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | /* | |
1348 | * Other parameters for the endpoint SHOULD be copied from the | |
1349 | * existing parameters of the association (e.g. number of | |
1350 | * outbound streams) into the INIT ACK and cookie. | |
1351 | * FIXME: We are copying parameters from the endpoint not the | |
1352 | * association. | |
1353 | */ | |
1354 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); | |
1355 | if (!new_asoc) | |
1356 | goto nomem; | |
1357 | ||
1358 | /* In the outbound INIT ACK the endpoint MUST copy its current | |
1359 | * Verification Tag and Peers Verification tag into a reserved | |
1360 | * place (local tie-tag and per tie-tag) within the state cookie. | |
1361 | */ | |
1362 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, | |
1363 | sctp_source(chunk), | |
1364 | (sctp_init_chunk_t *)chunk->chunk_hdr, | |
df7deeb5 VY |
1365 | GFP_ATOMIC)) |
1366 | goto nomem; | |
1da177e4 LT |
1367 | |
1368 | /* Make sure no new addresses are being added during the | |
1369 | * restart. Do not do this check for COOKIE-WAIT state, | |
1370 | * since there are no peer addresses to check against. | |
1371 | * Upon return an ABORT will have been sent if needed. | |
1372 | */ | |
1373 | if (!sctp_state(asoc, COOKIE_WAIT)) { | |
1374 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, | |
1375 | commands)) { | |
1376 | retval = SCTP_DISPOSITION_CONSUME; | |
df7deeb5 | 1377 | goto nomem_retval; |
1da177e4 LT |
1378 | } |
1379 | } | |
1380 | ||
1381 | sctp_tietags_populate(new_asoc, asoc); | |
1382 | ||
1383 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ | |
1384 | ||
1385 | /* If there are errors need to be reported for unknown parameters, | |
1386 | * make sure to reserve enough room in the INIT ACK for them. | |
1387 | */ | |
1388 | len = 0; | |
1389 | if (err_chunk) { | |
1390 | len = ntohs(err_chunk->chunk_hdr->length) - | |
1391 | sizeof(sctp_chunkhdr_t); | |
1392 | } | |
1393 | ||
1394 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0) | |
1395 | goto nomem; | |
1396 | ||
1397 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); | |
1398 | if (!repl) | |
1399 | goto nomem; | |
1400 | ||
1401 | /* If there are errors need to be reported for unknown parameters, | |
1402 | * include them in the outgoing INIT ACK as "Unrecognized parameter" | |
1403 | * parameter. | |
1404 | */ | |
1405 | if (err_chunk) { | |
1406 | /* Get the "Unrecognized parameter" parameter(s) out of the | |
1407 | * ERROR chunk generated by sctp_verify_init(). Since the | |
1408 | * error cause code for "unknown parameter" and the | |
1409 | * "Unrecognized parameter" type is the same, we can | |
1410 | * construct the parameters in INIT ACK by copying the | |
1411 | * ERROR causes over. | |
1412 | */ | |
1413 | unk_param = (sctp_unrecognized_param_t *) | |
1414 | ((__u8 *)(err_chunk->chunk_hdr) + | |
1415 | sizeof(sctp_chunkhdr_t)); | |
1416 | /* Replace the cause code with the "Unrecognized parameter" | |
1417 | * parameter type. | |
1418 | */ | |
1419 | sctp_addto_chunk(repl, len, unk_param); | |
1420 | } | |
1421 | ||
1422 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); | |
1423 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); | |
1424 | ||
1425 | /* | |
1426 | * Note: After sending out INIT ACK with the State Cookie parameter, | |
1427 | * "Z" MUST NOT allocate any resources for this new association. | |
1428 | * Otherwise, "Z" will be vulnerable to resource attacks. | |
1429 | */ | |
1430 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); | |
1431 | retval = SCTP_DISPOSITION_CONSUME; | |
1432 | ||
df7deeb5 VY |
1433 | return retval; |
1434 | ||
1435 | nomem: | |
1436 | retval = SCTP_DISPOSITION_NOMEM; | |
1437 | nomem_retval: | |
1438 | if (new_asoc) | |
1439 | sctp_association_free(new_asoc); | |
1da177e4 LT |
1440 | cleanup: |
1441 | if (err_chunk) | |
1442 | sctp_chunk_free(err_chunk); | |
1443 | return retval; | |
1da177e4 LT |
1444 | } |
1445 | ||
1446 | /* | |
1447 | * Handle simultanous INIT. | |
1448 | * This means we started an INIT and then we got an INIT request from | |
1449 | * our peer. | |
1450 | * | |
1451 | * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B) | |
1452 | * This usually indicates an initialization collision, i.e., each | |
1453 | * endpoint is attempting, at about the same time, to establish an | |
1454 | * association with the other endpoint. | |
1455 | * | |
1456 | * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an | |
1457 | * endpoint MUST respond with an INIT ACK using the same parameters it | |
1458 | * sent in its original INIT chunk (including its Verification Tag, | |
1459 | * unchanged). These original parameters are combined with those from the | |
1460 | * newly received INIT chunk. The endpoint shall also generate a State | |
1461 | * Cookie with the INIT ACK. The endpoint uses the parameters sent in its | |
1462 | * INIT to calculate the State Cookie. | |
1463 | * | |
1464 | * After that, the endpoint MUST NOT change its state, the T1-init | |
1465 | * timer shall be left running and the corresponding TCB MUST NOT be | |
1466 | * destroyed. The normal procedures for handling State Cookies when | |
1467 | * a TCB exists will resolve the duplicate INITs to a single association. | |
1468 | * | |
1469 | * For an endpoint that is in the COOKIE-ECHOED state it MUST populate | |
1470 | * its Tie-Tags with the Tag information of itself and its peer (see | |
1471 | * section 5.2.2 for a description of the Tie-Tags). | |
1472 | * | |
1473 | * Verification Tag: Not explicit, but an INIT can not have a valid | |
1474 | * verification tag, so we skip the check. | |
1475 | * | |
1476 | * Inputs | |
1477 | * (endpoint, asoc, chunk) | |
1478 | * | |
1479 | * Outputs | |
1480 | * (asoc, reply_msg, msg_up, timers, counters) | |
1481 | * | |
1482 | * The return value is the disposition of the chunk. | |
1483 | */ | |
1484 | sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep, | |
1485 | const struct sctp_association *asoc, | |
1486 | const sctp_subtype_t type, | |
1487 | void *arg, | |
1488 | sctp_cmd_seq_t *commands) | |
1489 | { | |
1490 | /* Call helper to do the real work for both simulataneous and | |
1491 | * duplicate INIT chunk handling. | |
1492 | */ | |
1493 | return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands); | |
1494 | } | |
1495 | ||
1496 | /* | |
1497 | * Handle duplicated INIT messages. These are usually delayed | |
1498 | * restransmissions. | |
1499 | * | |
1500 | * Section: 5.2.2 Unexpected INIT in States Other than CLOSED, | |
1501 | * COOKIE-ECHOED and COOKIE-WAIT | |
1502 | * | |
1503 | * Unless otherwise stated, upon reception of an unexpected INIT for | |
1504 | * this association, the endpoint shall generate an INIT ACK with a | |
1505 | * State Cookie. In the outbound INIT ACK the endpoint MUST copy its | |
1506 | * current Verification Tag and peer's Verification Tag into a reserved | |
1507 | * place within the state cookie. We shall refer to these locations as | |
1508 | * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet | |
1509 | * containing this INIT ACK MUST carry a Verification Tag value equal to | |
1510 | * the Initiation Tag found in the unexpected INIT. And the INIT ACK | |
1511 | * MUST contain a new Initiation Tag (randomly generated see Section | |
1512 | * 5.3.1). Other parameters for the endpoint SHOULD be copied from the | |
1513 | * existing parameters of the association (e.g. number of outbound | |
1514 | * streams) into the INIT ACK and cookie. | |
1515 | * | |
1516 | * After sending out the INIT ACK, the endpoint shall take no further | |
1517 | * actions, i.e., the existing association, including its current state, | |
1518 | * and the corresponding TCB MUST NOT be changed. | |
1519 | * | |
1520 | * Note: Only when a TCB exists and the association is not in a COOKIE- | |
1521 | * WAIT state are the Tie-Tags populated. For a normal association INIT | |
1522 | * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be | |
1523 | * set to 0 (indicating that no previous TCB existed). The INIT ACK and | |
1524 | * State Cookie are populated as specified in section 5.2.1. | |
1525 | * | |
1526 | * Verification Tag: Not specified, but an INIT has no way of knowing | |
1527 | * what the verification tag could be, so we ignore it. | |
1528 | * | |
1529 | * Inputs | |
1530 | * (endpoint, asoc, chunk) | |
1531 | * | |
1532 | * Outputs | |
1533 | * (asoc, reply_msg, msg_up, timers, counters) | |
1534 | * | |
1535 | * The return value is the disposition of the chunk. | |
1536 | */ | |
1537 | sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep, | |
1538 | const struct sctp_association *asoc, | |
1539 | const sctp_subtype_t type, | |
1540 | void *arg, | |
1541 | sctp_cmd_seq_t *commands) | |
1542 | { | |
1543 | /* Call helper to do the real work for both simulataneous and | |
1544 | * duplicate INIT chunk handling. | |
1545 | */ | |
1546 | return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands); | |
1547 | } | |
1548 | ||
1549 | ||
610ab73a VY |
1550 | /* |
1551 | * Unexpected INIT-ACK handler. | |
1552 | * | |
1553 | * Section 5.2.3 | |
1554 | * If an INIT ACK received by an endpoint in any state other than the | |
1555 | * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk. | |
1556 | * An unexpected INIT ACK usually indicates the processing of an old or | |
1557 | * duplicated INIT chunk. | |
1558 | */ | |
1559 | sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep, | |
1560 | const struct sctp_association *asoc, | |
1561 | const sctp_subtype_t type, | |
1562 | void *arg, sctp_cmd_seq_t *commands) | |
1563 | { | |
1564 | /* Per the above section, we'll discard the chunk if we have an | |
1565 | * endpoint. If this is an OOTB INIT-ACK, treat it as such. | |
1566 | */ | |
d808ad9a | 1567 | if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) |
610ab73a VY |
1568 | return sctp_sf_ootb(ep, asoc, type, arg, commands); |
1569 | else | |
1570 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); | |
1571 | } | |
1da177e4 LT |
1572 | |
1573 | /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A') | |
1574 | * | |
1575 | * Section 5.2.4 | |
1576 | * A) In this case, the peer may have restarted. | |
1577 | */ | |
1578 | static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep, | |
1579 | const struct sctp_association *asoc, | |
1580 | struct sctp_chunk *chunk, | |
1581 | sctp_cmd_seq_t *commands, | |
1582 | struct sctp_association *new_asoc) | |
1583 | { | |
1584 | sctp_init_chunk_t *peer_init; | |
1585 | struct sctp_ulpevent *ev; | |
1586 | struct sctp_chunk *repl; | |
1587 | struct sctp_chunk *err; | |
1588 | sctp_disposition_t disposition; | |
1589 | ||
1590 | /* new_asoc is a brand-new association, so these are not yet | |
1591 | * side effects--it is safe to run them here. | |
1592 | */ | |
1593 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; | |
1594 | ||
1595 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, | |
1596 | sctp_source(chunk), peer_init, | |
1597 | GFP_ATOMIC)) | |
1598 | goto nomem; | |
1599 | ||
1600 | /* Make sure no new addresses are being added during the | |
1601 | * restart. Though this is a pretty complicated attack | |
1602 | * since you'd have to get inside the cookie. | |
1603 | */ | |
1604 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) { | |
1605 | return SCTP_DISPOSITION_CONSUME; | |
1606 | } | |
1607 | ||
1608 | /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes | |
1609 | * the peer has restarted (Action A), it MUST NOT setup a new | |
1610 | * association but instead resend the SHUTDOWN ACK and send an ERROR | |
1611 | * chunk with a "Cookie Received while Shutting Down" error cause to | |
1612 | * its peer. | |
1613 | */ | |
1614 | if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) { | |
1615 | disposition = sctp_sf_do_9_2_reshutack(ep, asoc, | |
1616 | SCTP_ST_CHUNK(chunk->chunk_hdr->type), | |
1617 | chunk, commands); | |
1618 | if (SCTP_DISPOSITION_NOMEM == disposition) | |
1619 | goto nomem; | |
1620 | ||
1621 | err = sctp_make_op_error(asoc, chunk, | |
1622 | SCTP_ERROR_COOKIE_IN_SHUTDOWN, | |
1623 | NULL, 0); | |
1624 | if (err) | |
1625 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, | |
1626 | SCTP_CHUNK(err)); | |
1627 | ||
1628 | return SCTP_DISPOSITION_CONSUME; | |
1629 | } | |
1630 | ||
1631 | /* For now, fail any unsent/unacked data. Consider the optional | |
1632 | * choice of resending of this data. | |
1633 | */ | |
1634 | sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL()); | |
1635 | ||
1da177e4 LT |
1636 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
1637 | if (!repl) | |
1638 | goto nomem; | |
1639 | ||
1da177e4 LT |
1640 | /* Report association restart to upper layer. */ |
1641 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0, | |
1642 | new_asoc->c.sinit_num_ostreams, | |
1643 | new_asoc->c.sinit_max_instreams, | |
a5a35e76 | 1644 | NULL, GFP_ATOMIC); |
1da177e4 LT |
1645 | if (!ev) |
1646 | goto nomem_ev; | |
1647 | ||
df7deeb5 VY |
1648 | /* Update the content of current association. */ |
1649 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); | |
1650 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); | |
1da177e4 LT |
1651 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
1652 | return SCTP_DISPOSITION_CONSUME; | |
1653 | ||
1654 | nomem_ev: | |
1655 | sctp_chunk_free(repl); | |
1656 | nomem: | |
1657 | return SCTP_DISPOSITION_NOMEM; | |
1658 | } | |
1659 | ||
1660 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B') | |
1661 | * | |
1662 | * Section 5.2.4 | |
1663 | * B) In this case, both sides may be attempting to start an association | |
1664 | * at about the same time but the peer endpoint started its INIT | |
1665 | * after responding to the local endpoint's INIT | |
1666 | */ | |
1667 | /* This case represents an initialization collision. */ | |
1668 | static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep, | |
1669 | const struct sctp_association *asoc, | |
1670 | struct sctp_chunk *chunk, | |
1671 | sctp_cmd_seq_t *commands, | |
1672 | struct sctp_association *new_asoc) | |
1673 | { | |
1674 | sctp_init_chunk_t *peer_init; | |
1da177e4 LT |
1675 | struct sctp_chunk *repl; |
1676 | ||
1677 | /* new_asoc is a brand-new association, so these are not yet | |
1678 | * side effects--it is safe to run them here. | |
1679 | */ | |
1680 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; | |
1681 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, | |
1682 | sctp_source(chunk), peer_init, | |
1683 | GFP_ATOMIC)) | |
1684 | goto nomem; | |
1685 | ||
1686 | /* Update the content of current association. */ | |
1687 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); | |
1688 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
1689 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); | |
1690 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); | |
1691 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); | |
1692 | ||
1693 | repl = sctp_make_cookie_ack(new_asoc, chunk); | |
1694 | if (!repl) | |
1695 | goto nomem; | |
1696 | ||
1697 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); | |
1698 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); | |
1699 | ||
1700 | /* RFC 2960 5.1 Normal Establishment of an Association | |
1701 | * | |
1702 | * D) IMPLEMENTATION NOTE: An implementation may choose to | |
1703 | * send the Communication Up notification to the SCTP user | |
1704 | * upon reception of a valid COOKIE ECHO chunk. | |
07d93967 VY |
1705 | * |
1706 | * Sadly, this needs to be implemented as a side-effect, because | |
1707 | * we are not guaranteed to have set the association id of the real | |
1708 | * association and so these notifications need to be delayed until | |
1709 | * the association id is allocated. | |
1da177e4 | 1710 | */ |
1da177e4 | 1711 | |
07d93967 | 1712 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP)); |
1da177e4 LT |
1713 | |
1714 | /* Sockets API Draft Section 5.3.1.6 | |
0f3fffd8 | 1715 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
1da177e4 | 1716 | * delivers this notification to inform the application that of the |
0f3fffd8 | 1717 | * peers requested adaptation layer. |
07d93967 VY |
1718 | * |
1719 | * This also needs to be done as a side effect for the same reason as | |
1720 | * above. | |
1da177e4 | 1721 | */ |
07d93967 VY |
1722 | if (asoc->peer.adaptation_ind) |
1723 | sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL()); | |
1da177e4 LT |
1724 | |
1725 | return SCTP_DISPOSITION_CONSUME; | |
1726 | ||
1da177e4 LT |
1727 | nomem: |
1728 | return SCTP_DISPOSITION_NOMEM; | |
1729 | } | |
1730 | ||
1731 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C') | |
1732 | * | |
1733 | * Section 5.2.4 | |
1734 | * C) In this case, the local endpoint's cookie has arrived late. | |
1735 | * Before it arrived, the local endpoint sent an INIT and received an | |
1736 | * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag | |
1737 | * but a new tag of its own. | |
1738 | */ | |
1739 | /* This case represents an initialization collision. */ | |
1740 | static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep, | |
1741 | const struct sctp_association *asoc, | |
1742 | struct sctp_chunk *chunk, | |
1743 | sctp_cmd_seq_t *commands, | |
1744 | struct sctp_association *new_asoc) | |
1745 | { | |
1746 | /* The cookie should be silently discarded. | |
1747 | * The endpoint SHOULD NOT change states and should leave | |
1748 | * any timers running. | |
1749 | */ | |
1750 | return SCTP_DISPOSITION_DISCARD; | |
1751 | } | |
1752 | ||
1753 | /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D') | |
1754 | * | |
1755 | * Section 5.2.4 | |
1756 | * | |
1757 | * D) When both local and remote tags match the endpoint should always | |
1758 | * enter the ESTABLISHED state, if it has not already done so. | |
1759 | */ | |
1760 | /* This case represents an initialization collision. */ | |
1761 | static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep, | |
1762 | const struct sctp_association *asoc, | |
1763 | struct sctp_chunk *chunk, | |
1764 | sctp_cmd_seq_t *commands, | |
1765 | struct sctp_association *new_asoc) | |
1766 | { | |
df7deeb5 | 1767 | struct sctp_ulpevent *ev = NULL, *ai_ev = NULL; |
1da177e4 LT |
1768 | struct sctp_chunk *repl; |
1769 | ||
1770 | /* Clarification from Implementor's Guide: | |
1771 | * D) When both local and remote tags match the endpoint should | |
d808ad9a YH |
1772 | * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state. |
1773 | * It should stop any cookie timer that may be running and send | |
1774 | * a COOKIE ACK. | |
1da177e4 LT |
1775 | */ |
1776 | ||
1777 | /* Don't accidentally move back into established state. */ | |
1778 | if (asoc->state < SCTP_STATE_ESTABLISHED) { | |
1779 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
1780 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); | |
1781 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
1782 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); | |
1783 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); | |
1784 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, | |
1785 | SCTP_NULL()); | |
1786 | ||
1787 | /* RFC 2960 5.1 Normal Establishment of an Association | |
1788 | * | |
1789 | * D) IMPLEMENTATION NOTE: An implementation may choose | |
1790 | * to send the Communication Up notification to the | |
1791 | * SCTP user upon reception of a valid COOKIE | |
1792 | * ECHO chunk. | |
1793 | */ | |
df7deeb5 | 1794 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, |
1da177e4 | 1795 | SCTP_COMM_UP, 0, |
df7deeb5 VY |
1796 | asoc->c.sinit_num_ostreams, |
1797 | asoc->c.sinit_max_instreams, | |
9cbcbf4e | 1798 | NULL, GFP_ATOMIC); |
1da177e4 LT |
1799 | if (!ev) |
1800 | goto nomem; | |
1da177e4 LT |
1801 | |
1802 | /* Sockets API Draft Section 5.3.1.6 | |
0f3fffd8 | 1803 | * When a peer sends a Adaptation Layer Indication parameter, |
1da177e4 | 1804 | * SCTP delivers this notification to inform the application |
0f3fffd8 | 1805 | * that of the peers requested adaptation layer. |
1da177e4 | 1806 | */ |
0f3fffd8 ISJ |
1807 | if (asoc->peer.adaptation_ind) { |
1808 | ai_ev = sctp_ulpevent_make_adaptation_indication(asoc, | |
1da177e4 | 1809 | GFP_ATOMIC); |
df7deeb5 | 1810 | if (!ai_ev) |
1da177e4 LT |
1811 | goto nomem; |
1812 | ||
1da177e4 LT |
1813 | } |
1814 | } | |
1815 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); | |
1816 | ||
1817 | repl = sctp_make_cookie_ack(new_asoc, chunk); | |
1818 | if (!repl) | |
1819 | goto nomem; | |
1820 | ||
df7deeb5 VY |
1821 | if (ev) |
1822 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, | |
1823 | SCTP_ULPEVENT(ev)); | |
1824 | if (ai_ev) | |
1825 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, | |
1826 | SCTP_ULPEVENT(ai_ev)); | |
1827 | ||
1da177e4 LT |
1828 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
1829 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL()); | |
1830 | ||
1831 | return SCTP_DISPOSITION_CONSUME; | |
1832 | ||
1833 | nomem: | |
df7deeb5 VY |
1834 | if (ai_ev) |
1835 | sctp_ulpevent_free(ai_ev); | |
1da177e4 LT |
1836 | if (ev) |
1837 | sctp_ulpevent_free(ev); | |
1838 | return SCTP_DISPOSITION_NOMEM; | |
1839 | } | |
1840 | ||
1841 | /* | |
1842 | * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying | |
1843 | * chunk was retransmitted and then delayed in the network. | |
1844 | * | |
1845 | * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists | |
1846 | * | |
1847 | * Verification Tag: None. Do cookie validation. | |
1848 | * | |
1849 | * Inputs | |
1850 | * (endpoint, asoc, chunk) | |
1851 | * | |
1852 | * Outputs | |
1853 | * (asoc, reply_msg, msg_up, timers, counters) | |
1854 | * | |
1855 | * The return value is the disposition of the chunk. | |
1856 | */ | |
1857 | sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep, | |
1858 | const struct sctp_association *asoc, | |
1859 | const sctp_subtype_t type, | |
1860 | void *arg, | |
1861 | sctp_cmd_seq_t *commands) | |
1862 | { | |
1863 | sctp_disposition_t retval; | |
1864 | struct sctp_chunk *chunk = arg; | |
1865 | struct sctp_association *new_asoc; | |
1866 | int error = 0; | |
1867 | char action; | |
1868 | struct sctp_chunk *err_chk_p; | |
1869 | ||
1870 | /* Make sure that the chunk has a valid length from the protocol | |
1871 | * perspective. In this case check to make sure we have at least | |
1872 | * enough for the chunk header. Cookie length verification is | |
1873 | * done later. | |
1874 | */ | |
1875 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) | |
1876 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
1877 | commands); | |
1878 | ||
1879 | /* "Decode" the chunk. We have no optional parameters so we | |
1880 | * are in good shape. | |
1881 | */ | |
d808ad9a | 1882 | chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; |
62b08083 SS |
1883 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
1884 | sizeof(sctp_chunkhdr_t))) | |
1885 | goto nomem; | |
1da177e4 LT |
1886 | |
1887 | /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie | |
1888 | * of a duplicate COOKIE ECHO match the Verification Tags of the | |
1889 | * current association, consider the State Cookie valid even if | |
1890 | * the lifespan is exceeded. | |
1891 | */ | |
1892 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, | |
1893 | &err_chk_p); | |
1894 | ||
1895 | /* FIXME: | |
1896 | * If the re-build failed, what is the proper error path | |
1897 | * from here? | |
1898 | * | |
1899 | * [We should abort the association. --piggy] | |
1900 | */ | |
1901 | if (!new_asoc) { | |
1902 | /* FIXME: Several errors are possible. A bad cookie should | |
1903 | * be silently discarded, but think about logging it too. | |
1904 | */ | |
1905 | switch (error) { | |
1906 | case -SCTP_IERROR_NOMEM: | |
1907 | goto nomem; | |
1908 | ||
1909 | case -SCTP_IERROR_STALE_COOKIE: | |
1910 | sctp_send_stale_cookie_err(ep, asoc, chunk, commands, | |
1911 | err_chk_p); | |
1912 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
1913 | case -SCTP_IERROR_BAD_SIG: | |
1914 | default: | |
1915 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3ff50b79 | 1916 | } |
1da177e4 LT |
1917 | } |
1918 | ||
1919 | /* Compare the tie_tag in cookie with the verification tag of | |
1920 | * current association. | |
1921 | */ | |
1922 | action = sctp_tietags_compare(new_asoc, asoc); | |
1923 | ||
1924 | switch (action) { | |
1925 | case 'A': /* Association restart. */ | |
1926 | retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands, | |
1927 | new_asoc); | |
1928 | break; | |
1929 | ||
1930 | case 'B': /* Collision case B. */ | |
1931 | retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands, | |
1932 | new_asoc); | |
1933 | break; | |
1934 | ||
1935 | case 'C': /* Collision case C. */ | |
1936 | retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands, | |
1937 | new_asoc); | |
1938 | break; | |
1939 | ||
1940 | case 'D': /* Collision case D. */ | |
1941 | retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands, | |
1942 | new_asoc); | |
1943 | break; | |
1944 | ||
1945 | default: /* Discard packet for all others. */ | |
1946 | retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
1947 | break; | |
3ff50b79 | 1948 | } |
1da177e4 LT |
1949 | |
1950 | /* Delete the tempory new association. */ | |
1951 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); | |
1952 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); | |
1953 | ||
1954 | return retval; | |
1955 | ||
1956 | nomem: | |
1957 | return SCTP_DISPOSITION_NOMEM; | |
1958 | } | |
1959 | ||
1960 | /* | |
1961 | * Process an ABORT. (SHUTDOWN-PENDING state) | |
1962 | * | |
1963 | * See sctp_sf_do_9_1_abort(). | |
1964 | */ | |
1965 | sctp_disposition_t sctp_sf_shutdown_pending_abort( | |
1966 | const struct sctp_endpoint *ep, | |
1967 | const struct sctp_association *asoc, | |
1968 | const sctp_subtype_t type, | |
1969 | void *arg, | |
1970 | sctp_cmd_seq_t *commands) | |
1971 | { | |
1972 | struct sctp_chunk *chunk = arg; | |
1973 | ||
1974 | if (!sctp_vtag_verify_either(chunk, asoc)) | |
1975 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
1976 | ||
1977 | /* Make sure that the ABORT chunk has a valid length. | |
1978 | * Since this is an ABORT chunk, we have to discard it | |
1979 | * because of the following text: | |
1980 | * RFC 2960, Section 3.3.7 | |
1981 | * If an endpoint receives an ABORT with a format error or for an | |
1982 | * association that doesn't exist, it MUST silently discard it. | |
1983 | * Becasue the length is "invalid", we can't really discard just | |
1984 | * as we do not know its true length. So, to be safe, discard the | |
1985 | * packet. | |
1986 | */ | |
1987 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) | |
1988 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
1989 | ||
1990 | /* Stop the T5-shutdown guard timer. */ | |
1991 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
1992 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
1993 | ||
1994 | return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); | |
1995 | } | |
1996 | ||
1997 | /* | |
1998 | * Process an ABORT. (SHUTDOWN-SENT state) | |
1999 | * | |
2000 | * See sctp_sf_do_9_1_abort(). | |
2001 | */ | |
2002 | sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep, | |
2003 | const struct sctp_association *asoc, | |
2004 | const sctp_subtype_t type, | |
2005 | void *arg, | |
2006 | sctp_cmd_seq_t *commands) | |
2007 | { | |
2008 | struct sctp_chunk *chunk = arg; | |
2009 | ||
2010 | if (!sctp_vtag_verify_either(chunk, asoc)) | |
2011 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2012 | ||
2013 | /* Make sure that the ABORT chunk has a valid length. | |
2014 | * Since this is an ABORT chunk, we have to discard it | |
2015 | * because of the following text: | |
2016 | * RFC 2960, Section 3.3.7 | |
2017 | * If an endpoint receives an ABORT with a format error or for an | |
2018 | * association that doesn't exist, it MUST silently discard it. | |
2019 | * Becasue the length is "invalid", we can't really discard just | |
2020 | * as we do not know its true length. So, to be safe, discard the | |
2021 | * packet. | |
2022 | */ | |
2023 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) | |
2024 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2025 | ||
2026 | /* Stop the T2-shutdown timer. */ | |
2027 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
2028 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
2029 | ||
2030 | /* Stop the T5-shutdown guard timer. */ | |
2031 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
2032 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
2033 | ||
2034 | return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); | |
2035 | } | |
2036 | ||
2037 | /* | |
2038 | * Process an ABORT. (SHUTDOWN-ACK-SENT state) | |
2039 | * | |
2040 | * See sctp_sf_do_9_1_abort(). | |
2041 | */ | |
2042 | sctp_disposition_t sctp_sf_shutdown_ack_sent_abort( | |
2043 | const struct sctp_endpoint *ep, | |
2044 | const struct sctp_association *asoc, | |
2045 | const sctp_subtype_t type, | |
2046 | void *arg, | |
2047 | sctp_cmd_seq_t *commands) | |
2048 | { | |
2049 | /* The same T2 timer, so we should be able to use | |
2050 | * common function with the SHUTDOWN-SENT state. | |
2051 | */ | |
2052 | return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands); | |
2053 | } | |
2054 | ||
2055 | /* | |
2056 | * Handle an Error received in COOKIE_ECHOED state. | |
2057 | * | |
2058 | * Only handle the error type of stale COOKIE Error, the other errors will | |
2059 | * be ignored. | |
2060 | * | |
2061 | * Inputs | |
2062 | * (endpoint, asoc, chunk) | |
2063 | * | |
2064 | * Outputs | |
2065 | * (asoc, reply_msg, msg_up, timers, counters) | |
2066 | * | |
2067 | * The return value is the disposition of the chunk. | |
2068 | */ | |
2069 | sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep, | |
2070 | const struct sctp_association *asoc, | |
2071 | const sctp_subtype_t type, | |
2072 | void *arg, | |
2073 | sctp_cmd_seq_t *commands) | |
2074 | { | |
2075 | struct sctp_chunk *chunk = arg; | |
2076 | sctp_errhdr_t *err; | |
2077 | ||
2078 | if (!sctp_vtag_verify(chunk, asoc)) | |
2079 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2080 | ||
2081 | /* Make sure that the ERROR chunk has a valid length. | |
2082 | * The parameter walking depends on this as well. | |
2083 | */ | |
2084 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t))) | |
2085 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2086 | commands); | |
2087 | ||
2088 | /* Process the error here */ | |
2089 | /* FUTURE FIXME: When PR-SCTP related and other optional | |
2090 | * parms are emitted, this will have to change to handle multiple | |
2091 | * errors. | |
2092 | */ | |
2093 | sctp_walk_errors(err, chunk->chunk_hdr) { | |
2094 | if (SCTP_ERROR_STALE_COOKIE == err->cause) | |
d808ad9a | 2095 | return sctp_sf_do_5_2_6_stale(ep, asoc, type, |
1da177e4 LT |
2096 | arg, commands); |
2097 | } | |
2098 | ||
2099 | /* It is possible to have malformed error causes, and that | |
2100 | * will cause us to end the walk early. However, since | |
2101 | * we are discarding the packet, there should be no adverse | |
2102 | * affects. | |
2103 | */ | |
2104 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2105 | } | |
2106 | ||
2107 | /* | |
2108 | * Handle a Stale COOKIE Error | |
2109 | * | |
2110 | * Section: 5.2.6 Handle Stale COOKIE Error | |
2111 | * If the association is in the COOKIE-ECHOED state, the endpoint may elect | |
2112 | * one of the following three alternatives. | |
2113 | * ... | |
2114 | * 3) Send a new INIT chunk to the endpoint, adding a Cookie | |
2115 | * Preservative parameter requesting an extension to the lifetime of | |
2116 | * the State Cookie. When calculating the time extension, an | |
2117 | * implementation SHOULD use the RTT information measured based on the | |
2118 | * previous COOKIE ECHO / ERROR exchange, and should add no more | |
2119 | * than 1 second beyond the measured RTT, due to long State Cookie | |
2120 | * lifetimes making the endpoint more subject to a replay attack. | |
2121 | * | |
2122 | * Verification Tag: Not explicit, but safe to ignore. | |
2123 | * | |
2124 | * Inputs | |
2125 | * (endpoint, asoc, chunk) | |
2126 | * | |
2127 | * Outputs | |
2128 | * (asoc, reply_msg, msg_up, timers, counters) | |
2129 | * | |
2130 | * The return value is the disposition of the chunk. | |
2131 | */ | |
2132 | static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep, | |
2133 | const struct sctp_association *asoc, | |
2134 | const sctp_subtype_t type, | |
2135 | void *arg, | |
2136 | sctp_cmd_seq_t *commands) | |
2137 | { | |
2138 | struct sctp_chunk *chunk = arg; | |
2139 | time_t stale; | |
2140 | sctp_cookie_preserve_param_t bht; | |
2141 | sctp_errhdr_t *err; | |
2142 | struct sctp_chunk *reply; | |
2143 | struct sctp_bind_addr *bp; | |
3f7a87d2 | 2144 | int attempts = asoc->init_err_counter + 1; |
1da177e4 | 2145 | |
81845c21 | 2146 | if (attempts > asoc->max_init_attempts) { |
8de8c873 SS |
2147 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
2148 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 | 2149 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
dc251b2b | 2150 | SCTP_PERR(SCTP_ERROR_STALE_COOKIE)); |
1da177e4 LT |
2151 | return SCTP_DISPOSITION_DELETE_TCB; |
2152 | } | |
2153 | ||
2154 | err = (sctp_errhdr_t *)(chunk->skb->data); | |
2155 | ||
2156 | /* When calculating the time extension, an implementation | |
2157 | * SHOULD use the RTT information measured based on the | |
2158 | * previous COOKIE ECHO / ERROR exchange, and should add no | |
2159 | * more than 1 second beyond the measured RTT, due to long | |
2160 | * State Cookie lifetimes making the endpoint more subject to | |
2161 | * a replay attack. | |
2162 | * Measure of Staleness's unit is usec. (1/1000000 sec) | |
2163 | * Suggested Cookie Life-span Increment's unit is msec. | |
2164 | * (1/1000 sec) | |
2165 | * In general, if you use the suggested cookie life, the value | |
2166 | * found in the field of measure of staleness should be doubled | |
2167 | * to give ample time to retransmit the new cookie and thus | |
2168 | * yield a higher probability of success on the reattempt. | |
2169 | */ | |
34bcca28 | 2170 | stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t))); |
1da177e4 LT |
2171 | stale = (stale * 2) / 1000; |
2172 | ||
2173 | bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE; | |
2174 | bht.param_hdr.length = htons(sizeof(bht)); | |
2175 | bht.lifespan_increment = htonl(stale); | |
2176 | ||
2177 | /* Build that new INIT chunk. */ | |
2178 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; | |
2179 | reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht)); | |
2180 | if (!reply) | |
2181 | goto nomem; | |
2182 | ||
2183 | sctp_addto_chunk(reply, sizeof(bht), &bht); | |
2184 | ||
2185 | /* Clear peer's init_tag cached in assoc as we are sending a new INIT */ | |
2186 | sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL()); | |
2187 | ||
2188 | /* Stop pending T3-rtx and heartbeat timers */ | |
2189 | sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); | |
2190 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); | |
2191 | ||
2192 | /* Delete non-primary peer ip addresses since we are transitioning | |
2193 | * back to the COOKIE-WAIT state | |
2194 | */ | |
2195 | sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL()); | |
2196 | ||
d808ad9a YH |
2197 | /* If we've sent any data bundled with COOKIE-ECHO we will need to |
2198 | * resend | |
1da177e4 | 2199 | */ |
d808ad9a | 2200 | sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, |
1da177e4 LT |
2201 | SCTP_TRANSPORT(asoc->peer.primary_path)); |
2202 | ||
2203 | /* Cast away the const modifier, as we want to just | |
2204 | * rerun it through as a sideffect. | |
2205 | */ | |
3f7a87d2 | 2206 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL()); |
1da177e4 LT |
2207 | |
2208 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
2209 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); | |
2210 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
2211 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); | |
2212 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
2213 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
2214 | ||
2215 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
2216 | ||
2217 | return SCTP_DISPOSITION_CONSUME; | |
2218 | ||
2219 | nomem: | |
2220 | return SCTP_DISPOSITION_NOMEM; | |
2221 | } | |
2222 | ||
2223 | /* | |
2224 | * Process an ABORT. | |
2225 | * | |
2226 | * Section: 9.1 | |
2227 | * After checking the Verification Tag, the receiving endpoint shall | |
2228 | * remove the association from its record, and shall report the | |
2229 | * termination to its upper layer. | |
2230 | * | |
2231 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules | |
2232 | * B) Rules for packet carrying ABORT: | |
2233 | * | |
2234 | * - The endpoint shall always fill in the Verification Tag field of the | |
2235 | * outbound packet with the destination endpoint's tag value if it | |
2236 | * is known. | |
2237 | * | |
2238 | * - If the ABORT is sent in response to an OOTB packet, the endpoint | |
2239 | * MUST follow the procedure described in Section 8.4. | |
2240 | * | |
2241 | * - The receiver MUST accept the packet if the Verification Tag | |
2242 | * matches either its own tag, OR the tag of its peer. Otherwise, the | |
2243 | * receiver MUST silently discard the packet and take no further | |
2244 | * action. | |
2245 | * | |
2246 | * Inputs | |
2247 | * (endpoint, asoc, chunk) | |
2248 | * | |
2249 | * Outputs | |
2250 | * (asoc, reply_msg, msg_up, timers, counters) | |
2251 | * | |
2252 | * The return value is the disposition of the chunk. | |
2253 | */ | |
2254 | sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep, | |
2255 | const struct sctp_association *asoc, | |
2256 | const sctp_subtype_t type, | |
2257 | void *arg, | |
2258 | sctp_cmd_seq_t *commands) | |
2259 | { | |
2260 | struct sctp_chunk *chunk = arg; | |
2261 | unsigned len; | |
5be291fe | 2262 | __be16 error = SCTP_ERROR_NO_ERROR; |
1da177e4 LT |
2263 | |
2264 | if (!sctp_vtag_verify_either(chunk, asoc)) | |
2265 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2266 | ||
2267 | /* Make sure that the ABORT chunk has a valid length. | |
2268 | * Since this is an ABORT chunk, we have to discard it | |
2269 | * because of the following text: | |
2270 | * RFC 2960, Section 3.3.7 | |
2271 | * If an endpoint receives an ABORT with a format error or for an | |
2272 | * association that doesn't exist, it MUST silently discard it. | |
2273 | * Becasue the length is "invalid", we can't really discard just | |
2274 | * as we do not know its true length. So, to be safe, discard the | |
2275 | * packet. | |
2276 | */ | |
2277 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) | |
2278 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2279 | ||
2280 | /* See if we have an error cause code in the chunk. */ | |
2281 | len = ntohs(chunk->chunk_hdr->length); | |
2282 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) | |
2283 | error = ((sctp_errhdr_t *)chunk->skb->data)->cause; | |
2284 | ||
8de8c873 | 2285 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET)); |
d808ad9a | 2286 | /* ASSOC_FAILED will DELETE_TCB. */ |
5be291fe | 2287 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error)); |
1da177e4 LT |
2288 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
2289 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
2290 | ||
2291 | return SCTP_DISPOSITION_ABORT; | |
2292 | } | |
2293 | ||
2294 | /* | |
2295 | * Process an ABORT. (COOKIE-WAIT state) | |
2296 | * | |
2297 | * See sctp_sf_do_9_1_abort() above. | |
2298 | */ | |
2299 | sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep, | |
2300 | const struct sctp_association *asoc, | |
2301 | const sctp_subtype_t type, | |
2302 | void *arg, | |
2303 | sctp_cmd_seq_t *commands) | |
2304 | { | |
2305 | struct sctp_chunk *chunk = arg; | |
2306 | unsigned len; | |
f94c0198 | 2307 | __be16 error = SCTP_ERROR_NO_ERROR; |
1da177e4 LT |
2308 | |
2309 | if (!sctp_vtag_verify_either(chunk, asoc)) | |
2310 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2311 | ||
2312 | /* Make sure that the ABORT chunk has a valid length. | |
2313 | * Since this is an ABORT chunk, we have to discard it | |
2314 | * because of the following text: | |
2315 | * RFC 2960, Section 3.3.7 | |
2316 | * If an endpoint receives an ABORT with a format error or for an | |
2317 | * association that doesn't exist, it MUST silently discard it. | |
2318 | * Becasue the length is "invalid", we can't really discard just | |
2319 | * as we do not know its true length. So, to be safe, discard the | |
2320 | * packet. | |
2321 | */ | |
2322 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) | |
2323 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2324 | ||
2325 | /* See if we have an error cause code in the chunk. */ | |
2326 | len = ntohs(chunk->chunk_hdr->length); | |
2327 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) | |
2328 | error = ((sctp_errhdr_t *)chunk->skb->data)->cause; | |
2329 | ||
8de8c873 SS |
2330 | return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc, |
2331 | chunk->transport); | |
1da177e4 LT |
2332 | } |
2333 | ||
2334 | /* | |
2335 | * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state) | |
2336 | */ | |
2337 | sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep, | |
2338 | const struct sctp_association *asoc, | |
2339 | const sctp_subtype_t type, | |
2340 | void *arg, | |
2341 | sctp_cmd_seq_t *commands) | |
2342 | { | |
8de8c873 SS |
2343 | return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR, |
2344 | ENOPROTOOPT, asoc, | |
3f7a87d2 | 2345 | (struct sctp_transport *)arg); |
1da177e4 LT |
2346 | } |
2347 | ||
2348 | /* | |
2349 | * Process an ABORT. (COOKIE-ECHOED state) | |
2350 | */ | |
2351 | sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep, | |
2352 | const struct sctp_association *asoc, | |
2353 | const sctp_subtype_t type, | |
2354 | void *arg, | |
2355 | sctp_cmd_seq_t *commands) | |
2356 | { | |
2357 | /* There is a single T1 timer, so we should be able to use | |
2358 | * common function with the COOKIE-WAIT state. | |
2359 | */ | |
2360 | return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands); | |
2361 | } | |
2362 | ||
2363 | /* | |
2364 | * Stop T1 timer and abort association with "INIT failed". | |
2365 | * | |
2366 | * This is common code called by several sctp_sf_*_abort() functions above. | |
2367 | */ | |
52c1da39 | 2368 | static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, |
f94c0198 | 2369 | __be16 error, int sk_err, |
3f7a87d2 FF |
2370 | const struct sctp_association *asoc, |
2371 | struct sctp_transport *transport) | |
1da177e4 | 2372 | { |
3f7a87d2 | 2373 | SCTP_DEBUG_PRINTK("ABORT received (INIT).\n"); |
1da177e4 LT |
2374 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
2375 | SCTP_STATE(SCTP_STATE_CLOSED)); | |
2376 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); | |
2377 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
2378 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
8de8c873 | 2379 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err)); |
1da177e4 LT |
2380 | /* CMD_INIT_FAILED will DELETE_TCB. */ |
2381 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, | |
dc251b2b | 2382 | SCTP_PERR(error)); |
3f7a87d2 | 2383 | return SCTP_DISPOSITION_ABORT; |
1da177e4 LT |
2384 | } |
2385 | ||
2386 | /* | |
2387 | * sctp_sf_do_9_2_shut | |
2388 | * | |
2389 | * Section: 9.2 | |
2390 | * Upon the reception of the SHUTDOWN, the peer endpoint shall | |
2391 | * - enter the SHUTDOWN-RECEIVED state, | |
2392 | * | |
2393 | * - stop accepting new data from its SCTP user | |
2394 | * | |
2395 | * - verify, by checking the Cumulative TSN Ack field of the chunk, | |
2396 | * that all its outstanding DATA chunks have been received by the | |
2397 | * SHUTDOWN sender. | |
2398 | * | |
2399 | * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT | |
2400 | * send a SHUTDOWN in response to a ULP request. And should discard | |
2401 | * subsequent SHUTDOWN chunks. | |
2402 | * | |
2403 | * If there are still outstanding DATA chunks left, the SHUTDOWN | |
2404 | * receiver shall continue to follow normal data transmission | |
2405 | * procedures defined in Section 6 until all outstanding DATA chunks | |
2406 | * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept | |
2407 | * new data from its SCTP user. | |
2408 | * | |
2409 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
2410 | * | |
2411 | * Inputs | |
2412 | * (endpoint, asoc, chunk) | |
2413 | * | |
2414 | * Outputs | |
2415 | * (asoc, reply_msg, msg_up, timers, counters) | |
2416 | * | |
2417 | * The return value is the disposition of the chunk. | |
2418 | */ | |
2419 | sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep, | |
2420 | const struct sctp_association *asoc, | |
2421 | const sctp_subtype_t type, | |
2422 | void *arg, | |
2423 | sctp_cmd_seq_t *commands) | |
2424 | { | |
2425 | struct sctp_chunk *chunk = arg; | |
2426 | sctp_shutdownhdr_t *sdh; | |
2427 | sctp_disposition_t disposition; | |
2428 | struct sctp_ulpevent *ev; | |
2429 | ||
2430 | if (!sctp_vtag_verify(chunk, asoc)) | |
2431 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2432 | ||
2433 | /* Make sure that the SHUTDOWN chunk has a valid length. */ | |
2434 | if (!sctp_chunk_length_valid(chunk, | |
2435 | sizeof(struct sctp_shutdown_chunk_t))) | |
2436 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2437 | commands); | |
2438 | ||
2439 | /* Convert the elaborate header. */ | |
2440 | sdh = (sctp_shutdownhdr_t *)chunk->skb->data; | |
2441 | skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t)); | |
2442 | chunk->subh.shutdown_hdr = sdh; | |
2443 | ||
eb0e0076 SS |
2444 | /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT |
2445 | * When a peer sends a SHUTDOWN, SCTP delivers this notification to | |
2446 | * inform the application that it should cease sending data. | |
2447 | */ | |
2448 | ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC); | |
2449 | if (!ev) { | |
2450 | disposition = SCTP_DISPOSITION_NOMEM; | |
d808ad9a | 2451 | goto out; |
eb0e0076 SS |
2452 | } |
2453 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); | |
2454 | ||
1da177e4 LT |
2455 | /* Upon the reception of the SHUTDOWN, the peer endpoint shall |
2456 | * - enter the SHUTDOWN-RECEIVED state, | |
2457 | * - stop accepting new data from its SCTP user | |
2458 | * | |
2459 | * [This is implicit in the new state.] | |
2460 | */ | |
2461 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
2462 | SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED)); | |
2463 | disposition = SCTP_DISPOSITION_CONSUME; | |
2464 | ||
2465 | if (sctp_outq_is_empty(&asoc->outqueue)) { | |
2466 | disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type, | |
2467 | arg, commands); | |
2468 | } | |
2469 | ||
2470 | if (SCTP_DISPOSITION_NOMEM == disposition) | |
2471 | goto out; | |
2472 | ||
2473 | /* - verify, by checking the Cumulative TSN Ack field of the | |
2474 | * chunk, that all its outstanding DATA chunks have been | |
2475 | * received by the SHUTDOWN sender. | |
2476 | */ | |
2477 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, | |
2178eda8 | 2478 | SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack)); |
1da177e4 | 2479 | |
1da177e4 LT |
2480 | out: |
2481 | return disposition; | |
2482 | } | |
2483 | ||
2484 | /* RFC 2960 9.2 | |
2485 | * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk | |
2486 | * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination | |
2487 | * transport addresses (either in the IP addresses or in the INIT chunk) | |
2488 | * that belong to this association, it should discard the INIT chunk and | |
2489 | * retransmit the SHUTDOWN ACK chunk. | |
2490 | */ | |
2491 | sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep, | |
2492 | const struct sctp_association *asoc, | |
2493 | const sctp_subtype_t type, | |
2494 | void *arg, | |
2495 | sctp_cmd_seq_t *commands) | |
2496 | { | |
2497 | struct sctp_chunk *chunk = (struct sctp_chunk *) arg; | |
2498 | struct sctp_chunk *reply; | |
2499 | ||
2500 | /* Since we are not going to really process this INIT, there | |
2501 | * is no point in verifying chunk boundries. Just generate | |
2502 | * the SHUTDOWN ACK. | |
2503 | */ | |
2504 | reply = sctp_make_shutdown_ack(asoc, chunk); | |
2505 | if (NULL == reply) | |
2506 | goto nomem; | |
2507 | ||
2508 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for | |
2509 | * the T2-SHUTDOWN timer. | |
2510 | */ | |
2511 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); | |
2512 | ||
2513 | /* and restart the T2-shutdown timer. */ | |
2514 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
2515 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
2516 | ||
2517 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
2518 | ||
2519 | return SCTP_DISPOSITION_CONSUME; | |
2520 | nomem: | |
2521 | return SCTP_DISPOSITION_NOMEM; | |
2522 | } | |
2523 | ||
2524 | /* | |
2525 | * sctp_sf_do_ecn_cwr | |
2526 | * | |
2527 | * Section: Appendix A: Explicit Congestion Notification | |
2528 | * | |
2529 | * CWR: | |
2530 | * | |
2531 | * RFC 2481 details a specific bit for a sender to send in the header of | |
2532 | * its next outbound TCP segment to indicate to its peer that it has | |
2533 | * reduced its congestion window. This is termed the CWR bit. For | |
2534 | * SCTP the same indication is made by including the CWR chunk. | |
2535 | * This chunk contains one data element, i.e. the TSN number that | |
2536 | * was sent in the ECNE chunk. This element represents the lowest | |
2537 | * TSN number in the datagram that was originally marked with the | |
2538 | * CE bit. | |
2539 | * | |
2540 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
2541 | * Inputs | |
2542 | * (endpoint, asoc, chunk) | |
2543 | * | |
2544 | * Outputs | |
2545 | * (asoc, reply_msg, msg_up, timers, counters) | |
2546 | * | |
2547 | * The return value is the disposition of the chunk. | |
2548 | */ | |
2549 | sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep, | |
2550 | const struct sctp_association *asoc, | |
2551 | const sctp_subtype_t type, | |
2552 | void *arg, | |
2553 | sctp_cmd_seq_t *commands) | |
2554 | { | |
2555 | sctp_cwrhdr_t *cwr; | |
2556 | struct sctp_chunk *chunk = arg; | |
34bcca28 | 2557 | u32 lowest_tsn; |
1da177e4 LT |
2558 | |
2559 | if (!sctp_vtag_verify(chunk, asoc)) | |
2560 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2561 | ||
2562 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t))) | |
2563 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2564 | commands); | |
d808ad9a | 2565 | |
1da177e4 LT |
2566 | cwr = (sctp_cwrhdr_t *) chunk->skb->data; |
2567 | skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t)); | |
2568 | ||
34bcca28 | 2569 | lowest_tsn = ntohl(cwr->lowest_tsn); |
1da177e4 LT |
2570 | |
2571 | /* Does this CWR ack the last sent congestion notification? */ | |
34bcca28 | 2572 | if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) { |
1da177e4 LT |
2573 | /* Stop sending ECNE. */ |
2574 | sctp_add_cmd_sf(commands, | |
2575 | SCTP_CMD_ECN_CWR, | |
34bcca28 | 2576 | SCTP_U32(lowest_tsn)); |
1da177e4 LT |
2577 | } |
2578 | return SCTP_DISPOSITION_CONSUME; | |
2579 | } | |
2580 | ||
2581 | /* | |
2582 | * sctp_sf_do_ecne | |
2583 | * | |
2584 | * Section: Appendix A: Explicit Congestion Notification | |
2585 | * | |
2586 | * ECN-Echo | |
2587 | * | |
2588 | * RFC 2481 details a specific bit for a receiver to send back in its | |
2589 | * TCP acknowledgements to notify the sender of the Congestion | |
2590 | * Experienced (CE) bit having arrived from the network. For SCTP this | |
2591 | * same indication is made by including the ECNE chunk. This chunk | |
2592 | * contains one data element, i.e. the lowest TSN associated with the IP | |
2593 | * datagram marked with the CE bit..... | |
2594 | * | |
2595 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
2596 | * Inputs | |
2597 | * (endpoint, asoc, chunk) | |
2598 | * | |
2599 | * Outputs | |
2600 | * (asoc, reply_msg, msg_up, timers, counters) | |
2601 | * | |
2602 | * The return value is the disposition of the chunk. | |
2603 | */ | |
2604 | sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep, | |
2605 | const struct sctp_association *asoc, | |
2606 | const sctp_subtype_t type, | |
2607 | void *arg, | |
2608 | sctp_cmd_seq_t *commands) | |
2609 | { | |
2610 | sctp_ecnehdr_t *ecne; | |
2611 | struct sctp_chunk *chunk = arg; | |
2612 | ||
2613 | if (!sctp_vtag_verify(chunk, asoc)) | |
2614 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2615 | ||
2616 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t))) | |
2617 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2618 | commands); | |
2619 | ||
2620 | ecne = (sctp_ecnehdr_t *) chunk->skb->data; | |
2621 | skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t)); | |
2622 | ||
2623 | /* If this is a newer ECNE than the last CWR packet we sent out */ | |
2624 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE, | |
2625 | SCTP_U32(ntohl(ecne->lowest_tsn))); | |
2626 | ||
2627 | return SCTP_DISPOSITION_CONSUME; | |
2628 | } | |
2629 | ||
2630 | /* | |
2631 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks | |
2632 | * | |
2633 | * The SCTP endpoint MUST always acknowledge the reception of each valid | |
2634 | * DATA chunk. | |
2635 | * | |
2636 | * The guidelines on delayed acknowledgement algorithm specified in | |
2637 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an | |
2638 | * acknowledgement SHOULD be generated for at least every second packet | |
2639 | * (not every second DATA chunk) received, and SHOULD be generated within | |
2640 | * 200 ms of the arrival of any unacknowledged DATA chunk. In some | |
2641 | * situations it may be beneficial for an SCTP transmitter to be more | |
2642 | * conservative than the algorithms detailed in this document allow. | |
2643 | * However, an SCTP transmitter MUST NOT be more aggressive than the | |
2644 | * following algorithms allow. | |
2645 | * | |
2646 | * A SCTP receiver MUST NOT generate more than one SACK for every | |
2647 | * incoming packet, other than to update the offered window as the | |
2648 | * receiving application consumes new data. | |
2649 | * | |
2650 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
2651 | * | |
2652 | * Inputs | |
2653 | * (endpoint, asoc, chunk) | |
2654 | * | |
2655 | * Outputs | |
2656 | * (asoc, reply_msg, msg_up, timers, counters) | |
2657 | * | |
2658 | * The return value is the disposition of the chunk. | |
2659 | */ | |
2660 | sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep, | |
2661 | const struct sctp_association *asoc, | |
2662 | const sctp_subtype_t type, | |
2663 | void *arg, | |
2664 | sctp_cmd_seq_t *commands) | |
2665 | { | |
2666 | struct sctp_chunk *chunk = arg; | |
2667 | int error; | |
2668 | ||
2669 | if (!sctp_vtag_verify(chunk, asoc)) { | |
2670 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, | |
2671 | SCTP_NULL()); | |
2672 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
d808ad9a | 2673 | } |
1da177e4 LT |
2674 | |
2675 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t))) | |
2676 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2677 | commands); | |
2678 | ||
2679 | error = sctp_eat_data(asoc, chunk, commands ); | |
2680 | switch (error) { | |
2681 | case SCTP_IERROR_NO_ERROR: | |
2682 | break; | |
2683 | case SCTP_IERROR_HIGH_TSN: | |
2684 | case SCTP_IERROR_BAD_STREAM: | |
ac0b0462 | 2685 | SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
1da177e4 LT |
2686 | goto discard_noforce; |
2687 | case SCTP_IERROR_DUP_TSN: | |
2688 | case SCTP_IERROR_IGNORE_TSN: | |
ac0b0462 | 2689 | SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
1da177e4 LT |
2690 | goto discard_force; |
2691 | case SCTP_IERROR_NO_DATA: | |
2692 | goto consume; | |
2693 | default: | |
2694 | BUG(); | |
2695 | } | |
2696 | ||
2697 | if (asoc->autoclose) { | |
2698 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
2699 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); | |
2700 | } | |
2701 | ||
2702 | /* If this is the last chunk in a packet, we need to count it | |
2703 | * toward sack generation. Note that we need to SACK every | |
2704 | * OTHER packet containing data chunks, EVEN IF WE DISCARD | |
2705 | * THEM. We elect to NOT generate SACK's if the chunk fails | |
2706 | * the verification tag test. | |
2707 | * | |
2708 | * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks | |
2709 | * | |
2710 | * The SCTP endpoint MUST always acknowledge the reception of | |
2711 | * each valid DATA chunk. | |
2712 | * | |
2713 | * The guidelines on delayed acknowledgement algorithm | |
2714 | * specified in Section 4.2 of [RFC2581] SHOULD be followed. | |
2715 | * Specifically, an acknowledgement SHOULD be generated for at | |
2716 | * least every second packet (not every second DATA chunk) | |
2717 | * received, and SHOULD be generated within 200 ms of the | |
2718 | * arrival of any unacknowledged DATA chunk. In some | |
2719 | * situations it may be beneficial for an SCTP transmitter to | |
2720 | * be more conservative than the algorithms detailed in this | |
2721 | * document allow. However, an SCTP transmitter MUST NOT be | |
2722 | * more aggressive than the following algorithms allow. | |
2723 | */ | |
52ccb8e9 | 2724 | if (chunk->end_of_packet) |
1da177e4 LT |
2725 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
2726 | ||
1da177e4 LT |
2727 | return SCTP_DISPOSITION_CONSUME; |
2728 | ||
2729 | discard_force: | |
2730 | /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks | |
2731 | * | |
2732 | * When a packet arrives with duplicate DATA chunk(s) and with | |
2733 | * no new DATA chunk(s), the endpoint MUST immediately send a | |
2734 | * SACK with no delay. If a packet arrives with duplicate | |
2735 | * DATA chunk(s) bundled with new DATA chunks, the endpoint | |
2736 | * MAY immediately send a SACK. Normally receipt of duplicate | |
2737 | * DATA chunks will occur when the original SACK chunk was lost | |
2738 | * and the peer's RTO has expired. The duplicate TSN number(s) | |
2739 | * SHOULD be reported in the SACK as duplicate. | |
2740 | */ | |
2741 | /* In our case, we split the MAY SACK advice up whether or not | |
2742 | * the last chunk is a duplicate.' | |
2743 | */ | |
2744 | if (chunk->end_of_packet) | |
2745 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); | |
2746 | return SCTP_DISPOSITION_DISCARD; | |
2747 | ||
2748 | discard_noforce: | |
52ccb8e9 | 2749 | if (chunk->end_of_packet) |
1da177e4 LT |
2750 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
2751 | ||
1da177e4 LT |
2752 | return SCTP_DISPOSITION_DISCARD; |
2753 | consume: | |
2754 | return SCTP_DISPOSITION_CONSUME; | |
d808ad9a | 2755 | |
1da177e4 LT |
2756 | } |
2757 | ||
2758 | /* | |
2759 | * sctp_sf_eat_data_fast_4_4 | |
2760 | * | |
2761 | * Section: 4 (4) | |
2762 | * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received | |
2763 | * DATA chunks without delay. | |
2764 | * | |
2765 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
2766 | * Inputs | |
2767 | * (endpoint, asoc, chunk) | |
2768 | * | |
2769 | * Outputs | |
2770 | * (asoc, reply_msg, msg_up, timers, counters) | |
2771 | * | |
2772 | * The return value is the disposition of the chunk. | |
2773 | */ | |
2774 | sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep, | |
2775 | const struct sctp_association *asoc, | |
2776 | const sctp_subtype_t type, | |
2777 | void *arg, | |
2778 | sctp_cmd_seq_t *commands) | |
2779 | { | |
2780 | struct sctp_chunk *chunk = arg; | |
2781 | int error; | |
2782 | ||
2783 | if (!sctp_vtag_verify(chunk, asoc)) { | |
2784 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, | |
2785 | SCTP_NULL()); | |
2786 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2787 | } | |
2788 | ||
2789 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t))) | |
2790 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2791 | commands); | |
2792 | ||
2793 | error = sctp_eat_data(asoc, chunk, commands ); | |
2794 | switch (error) { | |
2795 | case SCTP_IERROR_NO_ERROR: | |
2796 | case SCTP_IERROR_HIGH_TSN: | |
2797 | case SCTP_IERROR_DUP_TSN: | |
2798 | case SCTP_IERROR_IGNORE_TSN: | |
2799 | case SCTP_IERROR_BAD_STREAM: | |
2800 | break; | |
2801 | case SCTP_IERROR_NO_DATA: | |
2802 | goto consume; | |
2803 | default: | |
2804 | BUG(); | |
2805 | } | |
2806 | ||
2807 | /* Go a head and force a SACK, since we are shutting down. */ | |
2808 | ||
2809 | /* Implementor's Guide. | |
2810 | * | |
2811 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately | |
2812 | * respond to each received packet containing one or more DATA chunk(s) | |
2813 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer | |
2814 | */ | |
2815 | if (chunk->end_of_packet) { | |
2816 | /* We must delay the chunk creation since the cumulative | |
2817 | * TSN has not been updated yet. | |
2818 | */ | |
2819 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); | |
2820 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); | |
2821 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
2822 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
2823 | } | |
2824 | ||
2825 | consume: | |
2826 | return SCTP_DISPOSITION_CONSUME; | |
2827 | } | |
2828 | ||
2829 | /* | |
2830 | * Section: 6.2 Processing a Received SACK | |
2831 | * D) Any time a SACK arrives, the endpoint performs the following: | |
2832 | * | |
2833 | * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point, | |
2834 | * then drop the SACK. Since Cumulative TSN Ack is monotonically | |
2835 | * increasing, a SACK whose Cumulative TSN Ack is less than the | |
2836 | * Cumulative TSN Ack Point indicates an out-of-order SACK. | |
2837 | * | |
2838 | * ii) Set rwnd equal to the newly received a_rwnd minus the number | |
2839 | * of bytes still outstanding after processing the Cumulative TSN Ack | |
2840 | * and the Gap Ack Blocks. | |
2841 | * | |
2842 | * iii) If the SACK is missing a TSN that was previously | |
2843 | * acknowledged via a Gap Ack Block (e.g., the data receiver | |
2844 | * reneged on the data), then mark the corresponding DATA chunk | |
2845 | * as available for retransmit: Mark it as missing for fast | |
2846 | * retransmit as described in Section 7.2.4 and if no retransmit | |
2847 | * timer is running for the destination address to which the DATA | |
2848 | * chunk was originally transmitted, then T3-rtx is started for | |
2849 | * that destination address. | |
2850 | * | |
2851 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
2852 | * | |
2853 | * Inputs | |
2854 | * (endpoint, asoc, chunk) | |
2855 | * | |
2856 | * Outputs | |
2857 | * (asoc, reply_msg, msg_up, timers, counters) | |
2858 | * | |
2859 | * The return value is the disposition of the chunk. | |
2860 | */ | |
2861 | sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep, | |
2862 | const struct sctp_association *asoc, | |
2863 | const sctp_subtype_t type, | |
2864 | void *arg, | |
2865 | sctp_cmd_seq_t *commands) | |
2866 | { | |
2867 | struct sctp_chunk *chunk = arg; | |
2868 | sctp_sackhdr_t *sackh; | |
2869 | __u32 ctsn; | |
2870 | ||
2871 | if (!sctp_vtag_verify(chunk, asoc)) | |
2872 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2873 | ||
2874 | /* Make sure that the SACK chunk has a valid length. */ | |
2875 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t))) | |
2876 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2877 | commands); | |
2878 | ||
2879 | /* Pull the SACK chunk from the data buffer */ | |
2880 | sackh = sctp_sm_pull_sack(chunk); | |
2881 | /* Was this a bogus SACK? */ | |
2882 | if (!sackh) | |
2883 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2884 | chunk->subh.sack_hdr = sackh; | |
2885 | ctsn = ntohl(sackh->cum_tsn_ack); | |
2886 | ||
2887 | /* i) If Cumulative TSN Ack is less than the Cumulative TSN | |
2888 | * Ack Point, then drop the SACK. Since Cumulative TSN | |
2889 | * Ack is monotonically increasing, a SACK whose | |
2890 | * Cumulative TSN Ack is less than the Cumulative TSN Ack | |
2891 | * Point indicates an out-of-order SACK. | |
2892 | */ | |
2893 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { | |
2894 | SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn); | |
2895 | SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point); | |
2896 | return SCTP_DISPOSITION_DISCARD; | |
2897 | } | |
2898 | ||
aecedeab WY |
2899 | /* If Cumulative TSN Ack beyond the max tsn currently |
2900 | * send, terminating the association and respond to the | |
2901 | * sender with an ABORT. | |
2902 | */ | |
2903 | if (!TSN_lt(ctsn, asoc->next_tsn)) | |
2904 | return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands); | |
2905 | ||
1da177e4 LT |
2906 | /* Return this SACK for further processing. */ |
2907 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh)); | |
2908 | ||
2909 | /* Note: We do the rest of the work on the PROCESS_SACK | |
2910 | * sideeffect. | |
2911 | */ | |
2912 | return SCTP_DISPOSITION_CONSUME; | |
2913 | } | |
2914 | ||
2915 | /* | |
2916 | * Generate an ABORT in response to a packet. | |
2917 | * | |
047a2428 | 2918 | * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41 |
1da177e4 | 2919 | * |
047a2428 JF |
2920 | * 8) The receiver should respond to the sender of the OOTB packet with |
2921 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet | |
2922 | * MUST fill in the Verification Tag field of the outbound packet | |
2923 | * with the value found in the Verification Tag field of the OOTB | |
2924 | * packet and set the T-bit in the Chunk Flags to indicate that the | |
2925 | * Verification Tag is reflected. After sending this ABORT, the | |
2926 | * receiver of the OOTB packet shall discard the OOTB packet and take | |
2927 | * no further action. | |
1da177e4 LT |
2928 | * |
2929 | * Verification Tag: | |
2930 | * | |
2931 | * The return value is the disposition of the chunk. | |
2932 | */ | |
2933 | sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep, | |
2934 | const struct sctp_association *asoc, | |
2935 | const sctp_subtype_t type, | |
2936 | void *arg, | |
2937 | sctp_cmd_seq_t *commands) | |
2938 | { | |
2939 | struct sctp_packet *packet = NULL; | |
2940 | struct sctp_chunk *chunk = arg; | |
2941 | struct sctp_chunk *abort; | |
2942 | ||
2943 | packet = sctp_ootb_pkt_new(asoc, chunk); | |
2944 | ||
2945 | if (packet) { | |
2946 | /* Make an ABORT. The T bit will be set if the asoc | |
2947 | * is NULL. | |
2948 | */ | |
d808ad9a | 2949 | abort = sctp_make_abort(asoc, chunk, 0); |
1da177e4 LT |
2950 | if (!abort) { |
2951 | sctp_ootb_pkt_free(packet); | |
2952 | return SCTP_DISPOSITION_NOMEM; | |
2953 | } | |
2954 | ||
047a2428 JF |
2955 | /* Reflect vtag if T-Bit is set */ |
2956 | if (sctp_test_T_bit(abort)) | |
2957 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); | |
2958 | ||
1da177e4 LT |
2959 | /* Set the skb to the belonging sock for accounting. */ |
2960 | abort->skb->sk = ep->base.sk; | |
2961 | ||
2962 | sctp_packet_append_chunk(packet, abort); | |
2963 | ||
2964 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, | |
2965 | SCTP_PACKET(packet)); | |
2966 | ||
2967 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
2968 | ||
2969 | return SCTP_DISPOSITION_CONSUME; | |
2970 | } | |
2971 | ||
2972 | return SCTP_DISPOSITION_NOMEM; | |
2973 | } | |
2974 | ||
2975 | /* | |
2976 | * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR | |
2977 | * event as ULP notification for each cause included in the chunk. | |
2978 | * | |
2979 | * API 5.3.1.3 - SCTP_REMOTE_ERROR | |
2980 | * | |
2981 | * The return value is the disposition of the chunk. | |
2982 | */ | |
2983 | sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep, | |
2984 | const struct sctp_association *asoc, | |
2985 | const sctp_subtype_t type, | |
2986 | void *arg, | |
2987 | sctp_cmd_seq_t *commands) | |
2988 | { | |
2989 | struct sctp_chunk *chunk = arg; | |
2990 | struct sctp_ulpevent *ev; | |
2991 | ||
2992 | if (!sctp_vtag_verify(chunk, asoc)) | |
2993 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
2994 | ||
2995 | /* Make sure that the ERROR chunk has a valid length. */ | |
2996 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t))) | |
2997 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
2998 | commands); | |
2999 | ||
3000 | while (chunk->chunk_end > chunk->skb->data) { | |
3001 | ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0, | |
3002 | GFP_ATOMIC); | |
3003 | if (!ev) | |
3004 | goto nomem; | |
3005 | ||
3006 | if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP, | |
3007 | SCTP_ULPEVENT(ev))) { | |
3008 | sctp_ulpevent_free(ev); | |
3009 | goto nomem; | |
3010 | } | |
3011 | ||
3012 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR, | |
d808ad9a | 3013 | SCTP_CHUNK(chunk)); |
1da177e4 LT |
3014 | } |
3015 | return SCTP_DISPOSITION_CONSUME; | |
3016 | ||
3017 | nomem: | |
3018 | return SCTP_DISPOSITION_NOMEM; | |
3019 | } | |
3020 | ||
3021 | /* | |
3022 | * Process an inbound SHUTDOWN ACK. | |
3023 | * | |
3024 | * From Section 9.2: | |
3025 | * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall | |
3026 | * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its | |
3027 | * peer, and remove all record of the association. | |
3028 | * | |
3029 | * The return value is the disposition. | |
3030 | */ | |
3031 | sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep, | |
3032 | const struct sctp_association *asoc, | |
3033 | const sctp_subtype_t type, | |
3034 | void *arg, | |
3035 | sctp_cmd_seq_t *commands) | |
3036 | { | |
3037 | struct sctp_chunk *chunk = arg; | |
3038 | struct sctp_chunk *reply; | |
3039 | struct sctp_ulpevent *ev; | |
3040 | ||
3041 | if (!sctp_vtag_verify(chunk, asoc)) | |
3042 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3043 | ||
3044 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ | |
3045 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) | |
3046 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
3047 | commands); | |
1da177e4 LT |
3048 | /* 10.2 H) SHUTDOWN COMPLETE notification |
3049 | * | |
3050 | * When SCTP completes the shutdown procedures (section 9.2) this | |
3051 | * notification is passed to the upper layer. | |
3052 | */ | |
3053 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, | |
a5a35e76 | 3054 | 0, 0, 0, NULL, GFP_ATOMIC); |
1da177e4 LT |
3055 | if (!ev) |
3056 | goto nomem; | |
3057 | ||
df7deeb5 VY |
3058 | /* ...send a SHUTDOWN COMPLETE chunk to its peer, */ |
3059 | reply = sctp_make_shutdown_complete(asoc, chunk); | |
3060 | if (!reply) | |
3061 | goto nomem_chunk; | |
3062 | ||
3063 | /* Do all the commands now (after allocation), so that we | |
3064 | * have consistent state if memory allocation failes | |
3065 | */ | |
1da177e4 LT |
3066 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
3067 | ||
3068 | /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall | |
3069 | * stop the T2-shutdown timer, | |
3070 | */ | |
3071 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
3072 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
3073 | ||
3074 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
3075 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
3076 | ||
1da177e4 LT |
3077 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
3078 | SCTP_STATE(SCTP_STATE_CLOSED)); | |
3079 | SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); | |
3080 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
3081 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
3082 | ||
3083 | /* ...and remove all record of the association. */ | |
3084 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); | |
3085 | return SCTP_DISPOSITION_DELETE_TCB; | |
3086 | ||
df7deeb5 VY |
3087 | nomem_chunk: |
3088 | sctp_ulpevent_free(ev); | |
1da177e4 LT |
3089 | nomem: |
3090 | return SCTP_DISPOSITION_NOMEM; | |
3091 | } | |
3092 | ||
3093 | /* | |
047a2428 JF |
3094 | * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41. |
3095 | * | |
1da177e4 LT |
3096 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
3097 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. | |
3098 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB | |
3099 | * packet must fill in the Verification Tag field of the outbound | |
3100 | * packet with the Verification Tag received in the SHUTDOWN ACK and | |
047a2428 JF |
3101 | * set the T-bit in the Chunk Flags to indicate that the Verification |
3102 | * Tag is reflected. | |
1da177e4 LT |
3103 | * |
3104 | * 8) The receiver should respond to the sender of the OOTB packet with | |
3105 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet | |
3106 | * MUST fill in the Verification Tag field of the outbound packet | |
3107 | * with the value found in the Verification Tag field of the OOTB | |
047a2428 JF |
3108 | * packet and set the T-bit in the Chunk Flags to indicate that the |
3109 | * Verification Tag is reflected. After sending this ABORT, the | |
3110 | * receiver of the OOTB packet shall discard the OOTB packet and take | |
3111 | * no further action. | |
1da177e4 LT |
3112 | */ |
3113 | sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep, | |
3114 | const struct sctp_association *asoc, | |
3115 | const sctp_subtype_t type, | |
3116 | void *arg, | |
3117 | sctp_cmd_seq_t *commands) | |
3118 | { | |
3119 | struct sctp_chunk *chunk = arg; | |
3120 | struct sk_buff *skb = chunk->skb; | |
3121 | sctp_chunkhdr_t *ch; | |
3122 | __u8 *ch_end; | |
3123 | int ootb_shut_ack = 0; | |
3124 | ||
3125 | SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES); | |
3126 | ||
3127 | ch = (sctp_chunkhdr_t *) chunk->chunk_hdr; | |
3128 | do { | |
3129 | /* Break out if chunk length is less then minimal. */ | |
3130 | if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t)) | |
3131 | break; | |
3132 | ||
3133 | ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); | |
27a884dc | 3134 | if (ch_end > skb_tail_pointer(skb)) |
a7d1f1b6 | 3135 | break; |
1da177e4 LT |
3136 | |
3137 | if (SCTP_CID_SHUTDOWN_ACK == ch->type) | |
3138 | ootb_shut_ack = 1; | |
3139 | ||
3140 | /* RFC 2960, Section 3.3.7 | |
3141 | * Moreover, under any circumstances, an endpoint that | |
3142 | * receives an ABORT MUST NOT respond to that ABORT by | |
3143 | * sending an ABORT of its own. | |
3144 | */ | |
3145 | if (SCTP_CID_ABORT == ch->type) | |
3146 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
d808ad9a | 3147 | |
1da177e4 | 3148 | ch = (sctp_chunkhdr_t *) ch_end; |
27a884dc | 3149 | } while (ch_end < skb_tail_pointer(skb)); |
1da177e4 LT |
3150 | |
3151 | if (ootb_shut_ack) | |
3152 | sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands); | |
3153 | else | |
3154 | sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); | |
3155 | ||
3156 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3157 | } | |
3158 | ||
3159 | /* | |
3160 | * Handle an "Out of the blue" SHUTDOWN ACK. | |
3161 | * | |
047a2428 JF |
3162 | * Section: 8.4 5, sctpimpguide 2.41. |
3163 | * | |
1da177e4 | 3164 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
047a2428 JF |
3165 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
3166 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB | |
3167 | * packet must fill in the Verification Tag field of the outbound | |
3168 | * packet with the Verification Tag received in the SHUTDOWN ACK and | |
3169 | * set the T-bit in the Chunk Flags to indicate that the Verification | |
3170 | * Tag is reflected. | |
1da177e4 LT |
3171 | * |
3172 | * Inputs | |
3173 | * (endpoint, asoc, type, arg, commands) | |
3174 | * | |
3175 | * Outputs | |
3176 | * (sctp_disposition_t) | |
3177 | * | |
3178 | * The return value is the disposition of the chunk. | |
3179 | */ | |
3180 | static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep, | |
3181 | const struct sctp_association *asoc, | |
3182 | const sctp_subtype_t type, | |
3183 | void *arg, | |
3184 | sctp_cmd_seq_t *commands) | |
3185 | { | |
3186 | struct sctp_packet *packet = NULL; | |
3187 | struct sctp_chunk *chunk = arg; | |
3188 | struct sctp_chunk *shut; | |
3189 | ||
3190 | packet = sctp_ootb_pkt_new(asoc, chunk); | |
3191 | ||
3192 | if (packet) { | |
3193 | /* Make an SHUTDOWN_COMPLETE. | |
d808ad9a YH |
3194 | * The T bit will be set if the asoc is NULL. |
3195 | */ | |
1da177e4 LT |
3196 | shut = sctp_make_shutdown_complete(asoc, chunk); |
3197 | if (!shut) { | |
3198 | sctp_ootb_pkt_free(packet); | |
3199 | return SCTP_DISPOSITION_NOMEM; | |
3200 | } | |
3201 | ||
047a2428 JF |
3202 | /* Reflect vtag if T-Bit is set */ |
3203 | if (sctp_test_T_bit(shut)) | |
3204 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); | |
3205 | ||
1da177e4 LT |
3206 | /* Set the skb to the belonging sock for accounting. */ |
3207 | shut->skb->sk = ep->base.sk; | |
3208 | ||
3209 | sctp_packet_append_chunk(packet, shut); | |
3210 | ||
3211 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, | |
3212 | SCTP_PACKET(packet)); | |
3213 | ||
3214 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
3215 | ||
3216 | /* If the chunk length is invalid, we don't want to process | |
3217 | * the reset of the packet. | |
3218 | */ | |
3219 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) | |
3220 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3221 | ||
3222 | return SCTP_DISPOSITION_CONSUME; | |
3223 | } | |
3224 | ||
3225 | return SCTP_DISPOSITION_NOMEM; | |
3226 | } | |
3227 | ||
3228 | /* | |
3229 | * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state. | |
3230 | * | |
3231 | * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK | |
3232 | * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the | |
3233 | * procedures in section 8.4 SHOULD be followed, in other words it | |
3234 | * should be treated as an Out Of The Blue packet. | |
3235 | * [This means that we do NOT check the Verification Tag on these | |
3236 | * chunks. --piggy ] | |
3237 | * | |
3238 | */ | |
3239 | sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep, | |
3240 | const struct sctp_association *asoc, | |
3241 | const sctp_subtype_t type, | |
3242 | void *arg, | |
3243 | sctp_cmd_seq_t *commands) | |
3244 | { | |
3245 | /* Although we do have an association in this case, it corresponds | |
3246 | * to a restarted association. So the packet is treated as an OOTB | |
3247 | * packet and the state function that handles OOTB SHUTDOWN_ACK is | |
3248 | * called with a NULL association. | |
3249 | */ | |
3250 | return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands); | |
3251 | } | |
3252 | ||
3253 | /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */ | |
3254 | sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep, | |
3255 | const struct sctp_association *asoc, | |
3256 | const sctp_subtype_t type, void *arg, | |
3257 | sctp_cmd_seq_t *commands) | |
3258 | { | |
3259 | struct sctp_chunk *chunk = arg; | |
3260 | struct sctp_chunk *asconf_ack = NULL; | |
3261 | sctp_addiphdr_t *hdr; | |
3262 | __u32 serial; | |
3263 | ||
3264 | if (!sctp_vtag_verify(chunk, asoc)) { | |
3265 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, | |
3266 | SCTP_NULL()); | |
3267 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3268 | } | |
3269 | ||
3270 | /* Make sure that the ASCONF ADDIP chunk has a valid length. */ | |
3271 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t))) | |
3272 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
3273 | commands); | |
3274 | ||
3275 | hdr = (sctp_addiphdr_t *)chunk->skb->data; | |
3276 | serial = ntohl(hdr->serial); | |
3277 | ||
3278 | /* ADDIP 4.2 C1) Compare the value of the serial number to the value | |
3279 | * the endpoint stored in a new association variable | |
d808ad9a | 3280 | * 'Peer-Serial-Number'. |
1da177e4 LT |
3281 | */ |
3282 | if (serial == asoc->peer.addip_serial + 1) { | |
d808ad9a | 3283 | /* ADDIP 4.2 C2) If the value found in the serial number is |
1da177e4 LT |
3284 | * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST |
3285 | * do V1-V5. | |
3286 | */ | |
3287 | asconf_ack = sctp_process_asconf((struct sctp_association *) | |
3288 | asoc, chunk); | |
3289 | if (!asconf_ack) | |
3290 | return SCTP_DISPOSITION_NOMEM; | |
3291 | } else if (serial == asoc->peer.addip_serial) { | |
3292 | /* ADDIP 4.2 C3) If the value found in the serial number is | |
3293 | * equal to the value stored in the 'Peer-Serial-Number' | |
3294 | * IMPLEMENTATION NOTE: As an optimization a receiver may wish | |
3295 | * to save the last ASCONF-ACK for some predetermined period of | |
3296 | * time and instead of re-processing the ASCONF (with the same | |
3297 | * serial number) it may just re-transmit the ASCONF-ACK. | |
3298 | */ | |
3299 | if (asoc->addip_last_asconf_ack) | |
3300 | asconf_ack = asoc->addip_last_asconf_ack; | |
3301 | else | |
3302 | return SCTP_DISPOSITION_DISCARD; | |
3303 | } else { | |
d808ad9a | 3304 | /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since |
1da177e4 | 3305 | * it must be either a stale packet or from an attacker. |
d808ad9a | 3306 | */ |
1da177e4 LT |
3307 | return SCTP_DISPOSITION_DISCARD; |
3308 | } | |
3309 | ||
3310 | /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent | |
3311 | * back to the source address contained in the IP header of the ASCONF | |
3312 | * being responded to. | |
3313 | */ | |
3314 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); | |
d808ad9a | 3315 | |
1da177e4 LT |
3316 | return SCTP_DISPOSITION_CONSUME; |
3317 | } | |
3318 | ||
3319 | /* | |
3320 | * ADDIP Section 4.3 General rules for address manipulation | |
3321 | * When building TLV parameters for the ASCONF Chunk that will add or | |
3322 | * delete IP addresses the D0 to D13 rules should be applied: | |
3323 | */ | |
3324 | sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep, | |
3325 | const struct sctp_association *asoc, | |
d808ad9a | 3326 | const sctp_subtype_t type, void *arg, |
1da177e4 LT |
3327 | sctp_cmd_seq_t *commands) |
3328 | { | |
3329 | struct sctp_chunk *asconf_ack = arg; | |
3330 | struct sctp_chunk *last_asconf = asoc->addip_last_asconf; | |
3331 | struct sctp_chunk *abort; | |
3332 | sctp_addiphdr_t *addip_hdr; | |
3333 | __u32 sent_serial, rcvd_serial; | |
3334 | ||
3335 | if (!sctp_vtag_verify(asconf_ack, asoc)) { | |
3336 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, | |
3337 | SCTP_NULL()); | |
3338 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3339 | } | |
3340 | ||
3341 | /* Make sure that the ADDIP chunk has a valid length. */ | |
3342 | if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t))) | |
3343 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
3344 | commands); | |
3345 | ||
3346 | addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data; | |
3347 | rcvd_serial = ntohl(addip_hdr->serial); | |
3348 | ||
3349 | if (last_asconf) { | |
3350 | addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr; | |
3351 | sent_serial = ntohl(addip_hdr->serial); | |
3352 | } else { | |
3353 | sent_serial = asoc->addip_serial - 1; | |
3354 | } | |
3355 | ||
3356 | /* D0) If an endpoint receives an ASCONF-ACK that is greater than or | |
3357 | * equal to the next serial number to be used but no ASCONF chunk is | |
3358 | * outstanding the endpoint MUST ABORT the association. Note that a | |
3359 | * sequence number is greater than if it is no more than 2^^31-1 | |
3360 | * larger than the current sequence number (using serial arithmetic). | |
3361 | */ | |
3362 | if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) && | |
3363 | !(asoc->addip_last_asconf)) { | |
3364 | abort = sctp_make_abort(asoc, asconf_ack, | |
3365 | sizeof(sctp_errhdr_t)); | |
3366 | if (abort) { | |
00f1c2df | 3367 | sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0); |
1da177e4 LT |
3368 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
3369 | SCTP_CHUNK(abort)); | |
3370 | } | |
3371 | /* We are going to ABORT, so we might as well stop | |
3372 | * processing the rest of the chunks in the packet. | |
3373 | */ | |
3374 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
3375 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); | |
3376 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); | |
8de8c873 | 3377 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
d808ad9a | 3378 | SCTP_ERROR(ECONNABORTED)); |
1da177e4 | 3379 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
5be291fe | 3380 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
1da177e4 LT |
3381 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
3382 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
3383 | return SCTP_DISPOSITION_ABORT; | |
3384 | } | |
3385 | ||
3386 | if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) { | |
3387 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
3388 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); | |
3389 | ||
3390 | if (!sctp_process_asconf_ack((struct sctp_association *)asoc, | |
3391 | asconf_ack)) | |
3392 | return SCTP_DISPOSITION_CONSUME; | |
3393 | ||
3394 | abort = sctp_make_abort(asoc, asconf_ack, | |
3395 | sizeof(sctp_errhdr_t)); | |
3396 | if (abort) { | |
00f1c2df | 3397 | sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0); |
1da177e4 LT |
3398 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
3399 | SCTP_CHUNK(abort)); | |
3400 | } | |
3401 | /* We are going to ABORT, so we might as well stop | |
3402 | * processing the rest of the chunks in the packet. | |
3403 | */ | |
3404 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); | |
8de8c873 | 3405 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
d808ad9a | 3406 | SCTP_ERROR(ECONNABORTED)); |
1da177e4 | 3407 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
5be291fe | 3408 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
1da177e4 LT |
3409 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
3410 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
3411 | return SCTP_DISPOSITION_ABORT; | |
3412 | } | |
3413 | ||
3414 | return SCTP_DISPOSITION_DISCARD; | |
3415 | } | |
3416 | ||
3417 | /* | |
3418 | * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP | |
3419 | * | |
3420 | * When a FORWARD TSN chunk arrives, the data receiver MUST first update | |
3421 | * its cumulative TSN point to the value carried in the FORWARD TSN | |
3422 | * chunk, and then MUST further advance its cumulative TSN point locally | |
3423 | * if possible. | |
3424 | * After the above processing, the data receiver MUST stop reporting any | |
3425 | * missing TSNs earlier than or equal to the new cumulative TSN point. | |
3426 | * | |
3427 | * Verification Tag: 8.5 Verification Tag [Normal verification] | |
3428 | * | |
3429 | * The return value is the disposition of the chunk. | |
3430 | */ | |
3431 | sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep, | |
3432 | const struct sctp_association *asoc, | |
3433 | const sctp_subtype_t type, | |
3434 | void *arg, | |
3435 | sctp_cmd_seq_t *commands) | |
3436 | { | |
3437 | struct sctp_chunk *chunk = arg; | |
3438 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; | |
3439 | __u16 len; | |
3440 | __u32 tsn; | |
3441 | ||
3442 | if (!sctp_vtag_verify(chunk, asoc)) { | |
3443 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, | |
3444 | SCTP_NULL()); | |
3445 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3446 | } | |
3447 | ||
3448 | /* Make sure that the FORWARD_TSN chunk has valid length. */ | |
3449 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) | |
3450 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
3451 | commands); | |
3452 | ||
3453 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; | |
3454 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; | |
3455 | len = ntohs(chunk->chunk_hdr->length); | |
3456 | len -= sizeof(struct sctp_chunkhdr); | |
3457 | skb_pull(chunk->skb, len); | |
3458 | ||
3459 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); | |
3460 | SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn); | |
3461 | ||
3462 | /* The TSN is too high--silently discard the chunk and count on it | |
3463 | * getting retransmitted later. | |
3464 | */ | |
3465 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) | |
3466 | goto discard_noforce; | |
3467 | ||
3468 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); | |
3469 | if (len > sizeof(struct sctp_fwdtsn_hdr)) | |
d808ad9a | 3470 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
1da177e4 | 3471 | SCTP_CHUNK(chunk)); |
d808ad9a | 3472 | |
1da177e4 LT |
3473 | /* Count this as receiving DATA. */ |
3474 | if (asoc->autoclose) { | |
3475 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
3476 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); | |
3477 | } | |
d808ad9a | 3478 | |
1da177e4 | 3479 | /* FIXME: For now send a SACK, but DATA processing may |
d808ad9a | 3480 | * send another. |
1da177e4 LT |
3481 | */ |
3482 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); | |
1da177e4 LT |
3483 | |
3484 | return SCTP_DISPOSITION_CONSUME; | |
3485 | ||
3486 | discard_noforce: | |
3487 | return SCTP_DISPOSITION_DISCARD; | |
3488 | } | |
3489 | ||
3490 | sctp_disposition_t sctp_sf_eat_fwd_tsn_fast( | |
3491 | const struct sctp_endpoint *ep, | |
3492 | const struct sctp_association *asoc, | |
3493 | const sctp_subtype_t type, | |
3494 | void *arg, | |
3495 | sctp_cmd_seq_t *commands) | |
3496 | { | |
3497 | struct sctp_chunk *chunk = arg; | |
3498 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; | |
3499 | __u16 len; | |
3500 | __u32 tsn; | |
3501 | ||
3502 | if (!sctp_vtag_verify(chunk, asoc)) { | |
3503 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, | |
3504 | SCTP_NULL()); | |
3505 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3506 | } | |
3507 | ||
3508 | /* Make sure that the FORWARD_TSN chunk has a valid length. */ | |
3509 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) | |
3510 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
3511 | commands); | |
3512 | ||
3513 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; | |
3514 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; | |
3515 | len = ntohs(chunk->chunk_hdr->length); | |
3516 | len -= sizeof(struct sctp_chunkhdr); | |
3517 | skb_pull(chunk->skb, len); | |
3518 | ||
3519 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); | |
3520 | SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn); | |
3521 | ||
3522 | /* The TSN is too high--silently discard the chunk and count on it | |
3523 | * getting retransmitted later. | |
3524 | */ | |
3525 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) | |
3526 | goto gen_shutdown; | |
3527 | ||
3528 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); | |
3529 | if (len > sizeof(struct sctp_fwdtsn_hdr)) | |
d808ad9a | 3530 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
1da177e4 | 3531 | SCTP_CHUNK(chunk)); |
d808ad9a | 3532 | |
1da177e4 LT |
3533 | /* Go a head and force a SACK, since we are shutting down. */ |
3534 | gen_shutdown: | |
3535 | /* Implementor's Guide. | |
3536 | * | |
3537 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately | |
3538 | * respond to each received packet containing one or more DATA chunk(s) | |
3539 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer | |
3540 | */ | |
3541 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); | |
3542 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); | |
3543 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
3544 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
3545 | ||
d808ad9a | 3546 | return SCTP_DISPOSITION_CONSUME; |
1da177e4 LT |
3547 | } |
3548 | ||
3549 | /* | |
3550 | * Process an unknown chunk. | |
3551 | * | |
3552 | * Section: 3.2. Also, 2.1 in the implementor's guide. | |
3553 | * | |
3554 | * Chunk Types are encoded such that the highest-order two bits specify | |
3555 | * the action that must be taken if the processing endpoint does not | |
3556 | * recognize the Chunk Type. | |
3557 | * | |
3558 | * 00 - Stop processing this SCTP packet and discard it, do not process | |
3559 | * any further chunks within it. | |
3560 | * | |
3561 | * 01 - Stop processing this SCTP packet and discard it, do not process | |
3562 | * any further chunks within it, and report the unrecognized | |
3563 | * chunk in an 'Unrecognized Chunk Type'. | |
3564 | * | |
3565 | * 10 - Skip this chunk and continue processing. | |
3566 | * | |
3567 | * 11 - Skip this chunk and continue processing, but report in an ERROR | |
3568 | * Chunk using the 'Unrecognized Chunk Type' cause of error. | |
3569 | * | |
3570 | * The return value is the disposition of the chunk. | |
3571 | */ | |
3572 | sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep, | |
3573 | const struct sctp_association *asoc, | |
3574 | const sctp_subtype_t type, | |
3575 | void *arg, | |
3576 | sctp_cmd_seq_t *commands) | |
3577 | { | |
3578 | struct sctp_chunk *unk_chunk = arg; | |
3579 | struct sctp_chunk *err_chunk; | |
3580 | sctp_chunkhdr_t *hdr; | |
3581 | ||
3582 | SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk); | |
3583 | ||
3584 | if (!sctp_vtag_verify(unk_chunk, asoc)) | |
3585 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3586 | ||
3587 | /* Make sure that the chunk has a valid length. | |
3588 | * Since we don't know the chunk type, we use a general | |
3589 | * chunkhdr structure to make a comparison. | |
3590 | */ | |
3591 | if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t))) | |
3592 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
3593 | commands); | |
3594 | ||
3595 | switch (type.chunk & SCTP_CID_ACTION_MASK) { | |
3596 | case SCTP_CID_ACTION_DISCARD: | |
3597 | /* Discard the packet. */ | |
3598 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3599 | break; | |
3600 | case SCTP_CID_ACTION_DISCARD_ERR: | |
3601 | /* Discard the packet. */ | |
3602 | sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
3603 | ||
3604 | /* Generate an ERROR chunk as response. */ | |
3605 | hdr = unk_chunk->chunk_hdr; | |
3606 | err_chunk = sctp_make_op_error(asoc, unk_chunk, | |
3607 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, | |
3608 | WORD_ROUND(ntohs(hdr->length))); | |
3609 | if (err_chunk) { | |
3610 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, | |
3611 | SCTP_CHUNK(err_chunk)); | |
3612 | } | |
3613 | return SCTP_DISPOSITION_CONSUME; | |
3614 | break; | |
3615 | case SCTP_CID_ACTION_SKIP: | |
3616 | /* Skip the chunk. */ | |
3617 | return SCTP_DISPOSITION_DISCARD; | |
3618 | break; | |
3619 | case SCTP_CID_ACTION_SKIP_ERR: | |
3620 | /* Generate an ERROR chunk as response. */ | |
3621 | hdr = unk_chunk->chunk_hdr; | |
3622 | err_chunk = sctp_make_op_error(asoc, unk_chunk, | |
3623 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, | |
3624 | WORD_ROUND(ntohs(hdr->length))); | |
3625 | if (err_chunk) { | |
3626 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, | |
3627 | SCTP_CHUNK(err_chunk)); | |
3628 | } | |
3629 | /* Skip the chunk. */ | |
3630 | return SCTP_DISPOSITION_CONSUME; | |
3631 | break; | |
3632 | default: | |
3633 | break; | |
3634 | } | |
3635 | ||
3636 | return SCTP_DISPOSITION_DISCARD; | |
3637 | } | |
3638 | ||
3639 | /* | |
3640 | * Discard the chunk. | |
3641 | * | |
3642 | * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2 | |
3643 | * [Too numerous to mention...] | |
3644 | * Verification Tag: No verification needed. | |
3645 | * Inputs | |
3646 | * (endpoint, asoc, chunk) | |
3647 | * | |
3648 | * Outputs | |
3649 | * (asoc, reply_msg, msg_up, timers, counters) | |
3650 | * | |
3651 | * The return value is the disposition of the chunk. | |
3652 | */ | |
3653 | sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep, | |
3654 | const struct sctp_association *asoc, | |
3655 | const sctp_subtype_t type, | |
3656 | void *arg, | |
3657 | sctp_cmd_seq_t *commands) | |
3658 | { | |
3659 | SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk); | |
3660 | return SCTP_DISPOSITION_DISCARD; | |
3661 | } | |
3662 | ||
3663 | /* | |
3664 | * Discard the whole packet. | |
3665 | * | |
3666 | * Section: 8.4 2) | |
3667 | * | |
3668 | * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST | |
3669 | * silently discard the OOTB packet and take no further action. | |
1da177e4 LT |
3670 | * |
3671 | * Verification Tag: No verification necessary | |
3672 | * | |
3673 | * Inputs | |
3674 | * (endpoint, asoc, chunk) | |
3675 | * | |
3676 | * Outputs | |
3677 | * (asoc, reply_msg, msg_up, timers, counters) | |
3678 | * | |
3679 | * The return value is the disposition of the chunk. | |
3680 | */ | |
3681 | sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep, | |
3682 | const struct sctp_association *asoc, | |
3683 | const sctp_subtype_t type, | |
3684 | void *arg, | |
3685 | sctp_cmd_seq_t *commands) | |
3686 | { | |
ac0b0462 | 3687 | SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS); |
1da177e4 LT |
3688 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
3689 | ||
3690 | return SCTP_DISPOSITION_CONSUME; | |
3691 | } | |
3692 | ||
3693 | ||
3694 | /* | |
3695 | * The other end is violating protocol. | |
3696 | * | |
3697 | * Section: Not specified | |
3698 | * Verification Tag: Not specified | |
3699 | * Inputs | |
3700 | * (endpoint, asoc, chunk) | |
3701 | * | |
3702 | * Outputs | |
3703 | * (asoc, reply_msg, msg_up, timers, counters) | |
3704 | * | |
3705 | * We simply tag the chunk as a violation. The state machine will log | |
3706 | * the violation and continue. | |
3707 | */ | |
3708 | sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep, | |
3709 | const struct sctp_association *asoc, | |
3710 | const sctp_subtype_t type, | |
3711 | void *arg, | |
3712 | sctp_cmd_seq_t *commands) | |
3713 | { | |
3714 | return SCTP_DISPOSITION_VIOLATION; | |
3715 | } | |
3716 | ||
1da177e4 | 3717 | /* |
aecedeab | 3718 | * Common function to handle a protocol violation. |
1da177e4 | 3719 | */ |
aecedeab | 3720 | static sctp_disposition_t sctp_sf_abort_violation( |
1da177e4 | 3721 | const struct sctp_association *asoc, |
1da177e4 | 3722 | void *arg, |
aecedeab WY |
3723 | sctp_cmd_seq_t *commands, |
3724 | const __u8 *payload, | |
3725 | const size_t paylen) | |
1da177e4 LT |
3726 | { |
3727 | struct sctp_chunk *chunk = arg; | |
3728 | struct sctp_chunk *abort = NULL; | |
1da177e4 LT |
3729 | |
3730 | /* Make the abort chunk. */ | |
aecedeab | 3731 | abort = sctp_make_abort_violation(asoc, chunk, payload, paylen); |
1da177e4 LT |
3732 | if (!abort) |
3733 | goto nomem; | |
3734 | ||
3735 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); | |
3736 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
3737 | ||
3738 | if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) { | |
3739 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
3740 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
8de8c873 SS |
3741 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
3742 | SCTP_ERROR(ECONNREFUSED)); | |
1da177e4 | 3743 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
dc251b2b | 3744 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
1da177e4 | 3745 | } else { |
8de8c873 | 3746 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
d808ad9a | 3747 | SCTP_ERROR(ECONNABORTED)); |
1da177e4 | 3748 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
5be291fe | 3749 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
1da177e4 LT |
3750 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
3751 | } | |
3752 | ||
3753 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); | |
3754 | ||
3755 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); | |
d808ad9a | 3756 | |
1da177e4 LT |
3757 | return SCTP_DISPOSITION_ABORT; |
3758 | ||
3759 | nomem: | |
3760 | return SCTP_DISPOSITION_NOMEM; | |
3761 | } | |
3762 | ||
aecedeab WY |
3763 | /* |
3764 | * Handle a protocol violation when the chunk length is invalid. | |
3765 | * "Invalid" length is identified as smaller then the minimal length a | |
3766 | * given chunk can be. For example, a SACK chunk has invalid length | |
3767 | * if it's length is set to be smaller then the size of sctp_sack_chunk_t. | |
3768 | * | |
3769 | * We inform the other end by sending an ABORT with a Protocol Violation | |
3770 | * error code. | |
3771 | * | |
3772 | * Section: Not specified | |
3773 | * Verification Tag: Nothing to do | |
3774 | * Inputs | |
3775 | * (endpoint, asoc, chunk) | |
3776 | * | |
3777 | * Outputs | |
3778 | * (reply_msg, msg_up, counters) | |
3779 | * | |
3780 | * Generate an ABORT chunk and terminate the association. | |
3781 | */ | |
3782 | static sctp_disposition_t sctp_sf_violation_chunklen( | |
3783 | const struct sctp_endpoint *ep, | |
3784 | const struct sctp_association *asoc, | |
3785 | const sctp_subtype_t type, | |
3786 | void *arg, | |
3787 | sctp_cmd_seq_t *commands) | |
3788 | { | |
3789 | char err_str[]="The following chunk had invalid length:"; | |
3790 | ||
3791 | return sctp_sf_abort_violation(asoc, arg, commands, err_str, | |
3792 | sizeof(err_str)); | |
3793 | } | |
3794 | ||
3795 | /* Handle a protocol violation when the peer trying to advance the | |
3796 | * cumulative tsn ack to a point beyond the max tsn currently sent. | |
3797 | * | |
3798 | * We inform the other end by sending an ABORT with a Protocol Violation | |
3799 | * error code. | |
3800 | */ | |
3801 | static sctp_disposition_t sctp_sf_violation_ctsn( | |
3802 | const struct sctp_endpoint *ep, | |
3803 | const struct sctp_association *asoc, | |
3804 | const sctp_subtype_t type, | |
3805 | void *arg, | |
3806 | sctp_cmd_seq_t *commands) | |
3807 | { | |
3808 | char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:"; | |
3809 | ||
3810 | return sctp_sf_abort_violation(asoc, arg, commands, err_str, | |
3811 | sizeof(err_str)); | |
3812 | } | |
3813 | ||
1da177e4 LT |
3814 | /*************************************************************************** |
3815 | * These are the state functions for handling primitive (Section 10) events. | |
3816 | ***************************************************************************/ | |
3817 | /* | |
3818 | * sctp_sf_do_prm_asoc | |
3819 | * | |
3820 | * Section: 10.1 ULP-to-SCTP | |
3821 | * B) Associate | |
3822 | * | |
3823 | * Format: ASSOCIATE(local SCTP instance name, destination transport addr, | |
3824 | * outbound stream count) | |
3825 | * -> association id [,destination transport addr list] [,outbound stream | |
3826 | * count] | |
3827 | * | |
3828 | * This primitive allows the upper layer to initiate an association to a | |
3829 | * specific peer endpoint. | |
3830 | * | |
3831 | * The peer endpoint shall be specified by one of the transport addresses | |
3832 | * which defines the endpoint (see Section 1.4). If the local SCTP | |
3833 | * instance has not been initialized, the ASSOCIATE is considered an | |
3834 | * error. | |
3835 | * [This is not relevant for the kernel implementation since we do all | |
3836 | * initialization at boot time. It we hadn't initialized we wouldn't | |
3837 | * get anywhere near this code.] | |
3838 | * | |
3839 | * An association id, which is a local handle to the SCTP association, | |
3840 | * will be returned on successful establishment of the association. If | |
3841 | * SCTP is not able to open an SCTP association with the peer endpoint, | |
3842 | * an error is returned. | |
3843 | * [In the kernel implementation, the struct sctp_association needs to | |
3844 | * be created BEFORE causing this primitive to run.] | |
3845 | * | |
3846 | * Other association parameters may be returned, including the | |
3847 | * complete destination transport addresses of the peer as well as the | |
3848 | * outbound stream count of the local endpoint. One of the transport | |
3849 | * address from the returned destination addresses will be selected by | |
3850 | * the local endpoint as default primary path for sending SCTP packets | |
3851 | * to this peer. The returned "destination transport addr list" can | |
3852 | * be used by the ULP to change the default primary path or to force | |
3853 | * sending a packet to a specific transport address. [All of this | |
3854 | * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING | |
3855 | * function.] | |
3856 | * | |
3857 | * Mandatory attributes: | |
3858 | * | |
3859 | * o local SCTP instance name - obtained from the INITIALIZE operation. | |
3860 | * [This is the argument asoc.] | |
3861 | * o destination transport addr - specified as one of the transport | |
3862 | * addresses of the peer endpoint with which the association is to be | |
3863 | * established. | |
3864 | * [This is asoc->peer.active_path.] | |
3865 | * o outbound stream count - the number of outbound streams the ULP | |
3866 | * would like to open towards this peer endpoint. | |
3867 | * [BUG: This is not currently implemented.] | |
3868 | * Optional attributes: | |
3869 | * | |
3870 | * None. | |
3871 | * | |
3872 | * The return value is a disposition. | |
3873 | */ | |
3874 | sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep, | |
3875 | const struct sctp_association *asoc, | |
3876 | const sctp_subtype_t type, | |
3877 | void *arg, | |
3878 | sctp_cmd_seq_t *commands) | |
3879 | { | |
3880 | struct sctp_chunk *repl; | |
3881 | ||
3882 | /* The comment below says that we enter COOKIE-WAIT AFTER | |
3883 | * sending the INIT, but that doesn't actually work in our | |
3884 | * implementation... | |
3885 | */ | |
3886 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
3887 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); | |
3888 | ||
3889 | /* RFC 2960 5.1 Normal Establishment of an Association | |
3890 | * | |
3891 | * A) "A" first sends an INIT chunk to "Z". In the INIT, "A" | |
3892 | * must provide its Verification Tag (Tag_A) in the Initiate | |
3893 | * Tag field. Tag_A SHOULD be a random number in the range of | |
3894 | * 1 to 4294967295 (see 5.3.1 for Tag value selection). ... | |
3895 | */ | |
3896 | ||
3897 | repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0); | |
3898 | if (!repl) | |
3899 | goto nomem; | |
3900 | ||
3901 | /* Cast away the const modifier, as we want to just | |
3902 | * rerun it through as a sideffect. | |
3903 | */ | |
3904 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, | |
3905 | SCTP_ASOC((struct sctp_association *) asoc)); | |
3906 | ||
3f7a87d2 FF |
3907 | /* Choose transport for INIT. */ |
3908 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, | |
3909 | SCTP_CHUNK(repl)); | |
3910 | ||
1da177e4 LT |
3911 | /* After sending the INIT, "A" starts the T1-init timer and |
3912 | * enters the COOKIE-WAIT state. | |
3913 | */ | |
3914 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
3915 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
3916 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); | |
3917 | return SCTP_DISPOSITION_CONSUME; | |
3918 | ||
3919 | nomem: | |
3920 | return SCTP_DISPOSITION_NOMEM; | |
3921 | } | |
3922 | ||
3923 | /* | |
3924 | * Process the SEND primitive. | |
3925 | * | |
3926 | * Section: 10.1 ULP-to-SCTP | |
3927 | * E) Send | |
3928 | * | |
3929 | * Format: SEND(association id, buffer address, byte count [,context] | |
3930 | * [,stream id] [,life time] [,destination transport address] | |
3931 | * [,unorder flag] [,no-bundle flag] [,payload protocol-id] ) | |
3932 | * -> result | |
3933 | * | |
3934 | * This is the main method to send user data via SCTP. | |
3935 | * | |
3936 | * Mandatory attributes: | |
3937 | * | |
3938 | * o association id - local handle to the SCTP association | |
3939 | * | |
3940 | * o buffer address - the location where the user message to be | |
3941 | * transmitted is stored; | |
3942 | * | |
3943 | * o byte count - The size of the user data in number of bytes; | |
3944 | * | |
3945 | * Optional attributes: | |
3946 | * | |
3947 | * o context - an optional 32 bit integer that will be carried in the | |
3948 | * sending failure notification to the ULP if the transportation of | |
3949 | * this User Message fails. | |
3950 | * | |
3951 | * o stream id - to indicate which stream to send the data on. If not | |
3952 | * specified, stream 0 will be used. | |
3953 | * | |
3954 | * o life time - specifies the life time of the user data. The user data | |
3955 | * will not be sent by SCTP after the life time expires. This | |
3956 | * parameter can be used to avoid efforts to transmit stale | |
3957 | * user messages. SCTP notifies the ULP if the data cannot be | |
3958 | * initiated to transport (i.e. sent to the destination via SCTP's | |
3959 | * send primitive) within the life time variable. However, the | |
3960 | * user data will be transmitted if SCTP has attempted to transmit a | |
3961 | * chunk before the life time expired. | |
3962 | * | |
3963 | * o destination transport address - specified as one of the destination | |
3964 | * transport addresses of the peer endpoint to which this packet | |
3965 | * should be sent. Whenever possible, SCTP should use this destination | |
3966 | * transport address for sending the packets, instead of the current | |
3967 | * primary path. | |
3968 | * | |
3969 | * o unorder flag - this flag, if present, indicates that the user | |
3970 | * would like the data delivered in an unordered fashion to the peer | |
3971 | * (i.e., the U flag is set to 1 on all DATA chunks carrying this | |
3972 | * message). | |
3973 | * | |
3974 | * o no-bundle flag - instructs SCTP not to bundle this user data with | |
3975 | * other outbound DATA chunks. SCTP MAY still bundle even when | |
3976 | * this flag is present, when faced with network congestion. | |
3977 | * | |
3978 | * o payload protocol-id - A 32 bit unsigned integer that is to be | |
3979 | * passed to the peer indicating the type of payload protocol data | |
3980 | * being transmitted. This value is passed as opaque data by SCTP. | |
3981 | * | |
3982 | * The return value is the disposition. | |
3983 | */ | |
3984 | sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep, | |
3985 | const struct sctp_association *asoc, | |
3986 | const sctp_subtype_t type, | |
3987 | void *arg, | |
3988 | sctp_cmd_seq_t *commands) | |
3989 | { | |
3990 | struct sctp_chunk *chunk = arg; | |
3991 | ||
3992 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); | |
3993 | return SCTP_DISPOSITION_CONSUME; | |
3994 | } | |
3995 | ||
3996 | /* | |
3997 | * Process the SHUTDOWN primitive. | |
3998 | * | |
3999 | * Section: 10.1: | |
4000 | * C) Shutdown | |
4001 | * | |
4002 | * Format: SHUTDOWN(association id) | |
4003 | * -> result | |
4004 | * | |
4005 | * Gracefully closes an association. Any locally queued user data | |
4006 | * will be delivered to the peer. The association will be terminated only | |
4007 | * after the peer acknowledges all the SCTP packets sent. A success code | |
4008 | * will be returned on successful termination of the association. If | |
4009 | * attempting to terminate the association results in a failure, an error | |
4010 | * code shall be returned. | |
4011 | * | |
4012 | * Mandatory attributes: | |
4013 | * | |
4014 | * o association id - local handle to the SCTP association | |
4015 | * | |
4016 | * Optional attributes: | |
4017 | * | |
4018 | * None. | |
4019 | * | |
4020 | * The return value is the disposition. | |
4021 | */ | |
4022 | sctp_disposition_t sctp_sf_do_9_2_prm_shutdown( | |
4023 | const struct sctp_endpoint *ep, | |
4024 | const struct sctp_association *asoc, | |
4025 | const sctp_subtype_t type, | |
4026 | void *arg, | |
4027 | sctp_cmd_seq_t *commands) | |
4028 | { | |
4029 | int disposition; | |
4030 | ||
4031 | /* From 9.2 Shutdown of an Association | |
4032 | * Upon receipt of the SHUTDOWN primitive from its upper | |
4033 | * layer, the endpoint enters SHUTDOWN-PENDING state and | |
4034 | * remains there until all outstanding data has been | |
4035 | * acknowledged by its peer. The endpoint accepts no new data | |
4036 | * from its upper layer, but retransmits data to the far end | |
4037 | * if necessary to fill gaps. | |
4038 | */ | |
4039 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
4040 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); | |
4041 | ||
4042 | /* sctpimpguide-05 Section 2.12.2 | |
4043 | * The sender of the SHUTDOWN MAY also start an overall guard timer | |
4044 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. | |
4045 | */ | |
4046 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
4047 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
4048 | ||
4049 | disposition = SCTP_DISPOSITION_CONSUME; | |
4050 | if (sctp_outq_is_empty(&asoc->outqueue)) { | |
4051 | disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type, | |
4052 | arg, commands); | |
4053 | } | |
4054 | return disposition; | |
4055 | } | |
4056 | ||
4057 | /* | |
4058 | * Process the ABORT primitive. | |
4059 | * | |
4060 | * Section: 10.1: | |
4061 | * C) Abort | |
4062 | * | |
4063 | * Format: Abort(association id [, cause code]) | |
4064 | * -> result | |
4065 | * | |
4066 | * Ungracefully closes an association. Any locally queued user data | |
4067 | * will be discarded and an ABORT chunk is sent to the peer. A success code | |
4068 | * will be returned on successful abortion of the association. If | |
4069 | * attempting to abort the association results in a failure, an error | |
4070 | * code shall be returned. | |
4071 | * | |
4072 | * Mandatory attributes: | |
4073 | * | |
4074 | * o association id - local handle to the SCTP association | |
4075 | * | |
4076 | * Optional attributes: | |
4077 | * | |
4078 | * o cause code - reason of the abort to be passed to the peer | |
4079 | * | |
4080 | * None. | |
4081 | * | |
4082 | * The return value is the disposition. | |
4083 | */ | |
4084 | sctp_disposition_t sctp_sf_do_9_1_prm_abort( | |
4085 | const struct sctp_endpoint *ep, | |
4086 | const struct sctp_association *asoc, | |
4087 | const sctp_subtype_t type, | |
4088 | void *arg, | |
4089 | sctp_cmd_seq_t *commands) | |
4090 | { | |
4091 | /* From 9.1 Abort of an Association | |
4092 | * Upon receipt of the ABORT primitive from its upper | |
4093 | * layer, the endpoint enters CLOSED state and | |
4094 | * discard all outstanding data has been | |
4095 | * acknowledged by its peer. The endpoint accepts no new data | |
4096 | * from its upper layer, but retransmits data to the far end | |
4097 | * if necessary to fill gaps. | |
4098 | */ | |
c164a9ba | 4099 | struct sctp_chunk *abort = arg; |
1da177e4 LT |
4100 | sctp_disposition_t retval; |
4101 | ||
4102 | retval = SCTP_DISPOSITION_CONSUME; | |
4103 | ||
c164a9ba | 4104 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
1da177e4 LT |
4105 | |
4106 | /* Even if we can't send the ABORT due to low memory delete the | |
4107 | * TCB. This is a departure from our typical NOMEM handling. | |
4108 | */ | |
4109 | ||
8de8c873 SS |
4110 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4111 | SCTP_ERROR(ECONNABORTED)); | |
1da177e4 LT |
4112 | /* Delete the established association. */ |
4113 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, | |
5be291fe | 4114 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
1da177e4 LT |
4115 | |
4116 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); | |
4117 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
4118 | ||
4119 | return retval; | |
4120 | } | |
4121 | ||
4122 | /* We tried an illegal operation on an association which is closed. */ | |
4123 | sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep, | |
4124 | const struct sctp_association *asoc, | |
4125 | const sctp_subtype_t type, | |
4126 | void *arg, | |
4127 | sctp_cmd_seq_t *commands) | |
4128 | { | |
4129 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL)); | |
4130 | return SCTP_DISPOSITION_CONSUME; | |
4131 | } | |
4132 | ||
4133 | /* We tried an illegal operation on an association which is shutting | |
4134 | * down. | |
4135 | */ | |
4136 | sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep, | |
4137 | const struct sctp_association *asoc, | |
4138 | const sctp_subtype_t type, | |
4139 | void *arg, | |
4140 | sctp_cmd_seq_t *commands) | |
4141 | { | |
4142 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, | |
4143 | SCTP_ERROR(-ESHUTDOWN)); | |
4144 | return SCTP_DISPOSITION_CONSUME; | |
4145 | } | |
4146 | ||
4147 | /* | |
4148 | * sctp_cookie_wait_prm_shutdown | |
4149 | * | |
4150 | * Section: 4 Note: 2 | |
4151 | * Verification Tag: | |
4152 | * Inputs | |
4153 | * (endpoint, asoc) | |
4154 | * | |
4155 | * The RFC does not explicitly address this issue, but is the route through the | |
4156 | * state table when someone issues a shutdown while in COOKIE_WAIT state. | |
4157 | * | |
4158 | * Outputs | |
4159 | * (timers) | |
4160 | */ | |
4161 | sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown( | |
4162 | const struct sctp_endpoint *ep, | |
4163 | const struct sctp_association *asoc, | |
4164 | const sctp_subtype_t type, | |
4165 | void *arg, | |
4166 | sctp_cmd_seq_t *commands) | |
4167 | { | |
4168 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4169 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
4170 | ||
4171 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
4172 | SCTP_STATE(SCTP_STATE_CLOSED)); | |
4173 | ||
4174 | SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); | |
4175 | ||
4176 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); | |
4177 | ||
4178 | return SCTP_DISPOSITION_DELETE_TCB; | |
4179 | } | |
4180 | ||
4181 | /* | |
4182 | * sctp_cookie_echoed_prm_shutdown | |
4183 | * | |
4184 | * Section: 4 Note: 2 | |
4185 | * Verification Tag: | |
4186 | * Inputs | |
4187 | * (endpoint, asoc) | |
4188 | * | |
4189 | * The RFC does not explcitly address this issue, but is the route through the | |
4190 | * state table when someone issues a shutdown while in COOKIE_ECHOED state. | |
4191 | * | |
4192 | * Outputs | |
4193 | * (timers) | |
4194 | */ | |
4195 | sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown( | |
4196 | const struct sctp_endpoint *ep, | |
4197 | const struct sctp_association *asoc, | |
4198 | const sctp_subtype_t type, | |
4199 | void *arg, sctp_cmd_seq_t *commands) | |
4200 | { | |
4201 | /* There is a single T1 timer, so we should be able to use | |
4202 | * common function with the COOKIE-WAIT state. | |
4203 | */ | |
4204 | return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands); | |
4205 | } | |
4206 | ||
4207 | /* | |
4208 | * sctp_sf_cookie_wait_prm_abort | |
4209 | * | |
4210 | * Section: 4 Note: 2 | |
4211 | * Verification Tag: | |
4212 | * Inputs | |
4213 | * (endpoint, asoc) | |
4214 | * | |
4215 | * The RFC does not explicitly address this issue, but is the route through the | |
4216 | * state table when someone issues an abort while in COOKIE_WAIT state. | |
4217 | * | |
4218 | * Outputs | |
4219 | * (timers) | |
4220 | */ | |
4221 | sctp_disposition_t sctp_sf_cookie_wait_prm_abort( | |
4222 | const struct sctp_endpoint *ep, | |
4223 | const struct sctp_association *asoc, | |
4224 | const sctp_subtype_t type, | |
4225 | void *arg, | |
4226 | sctp_cmd_seq_t *commands) | |
4227 | { | |
c164a9ba | 4228 | struct sctp_chunk *abort = arg; |
1da177e4 LT |
4229 | sctp_disposition_t retval; |
4230 | ||
4231 | /* Stop T1-init timer */ | |
4232 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4233 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
4234 | retval = SCTP_DISPOSITION_CONSUME; | |
4235 | ||
c164a9ba | 4236 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
1da177e4 LT |
4237 | |
4238 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
4239 | SCTP_STATE(SCTP_STATE_CLOSED)); | |
4240 | ||
4241 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); | |
4242 | ||
4243 | /* Even if we can't send the ABORT due to low memory delete the | |
4244 | * TCB. This is a departure from our typical NOMEM handling. | |
4245 | */ | |
4246 | ||
8de8c873 SS |
4247 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4248 | SCTP_ERROR(ECONNREFUSED)); | |
1da177e4 LT |
4249 | /* Delete the established association. */ |
4250 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, | |
dc251b2b | 4251 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
1da177e4 LT |
4252 | |
4253 | return retval; | |
4254 | } | |
4255 | ||
4256 | /* | |
4257 | * sctp_sf_cookie_echoed_prm_abort | |
4258 | * | |
4259 | * Section: 4 Note: 3 | |
4260 | * Verification Tag: | |
4261 | * Inputs | |
4262 | * (endpoint, asoc) | |
4263 | * | |
4264 | * The RFC does not explcitly address this issue, but is the route through the | |
4265 | * state table when someone issues an abort while in COOKIE_ECHOED state. | |
4266 | * | |
4267 | * Outputs | |
4268 | * (timers) | |
4269 | */ | |
4270 | sctp_disposition_t sctp_sf_cookie_echoed_prm_abort( | |
4271 | const struct sctp_endpoint *ep, | |
4272 | const struct sctp_association *asoc, | |
4273 | const sctp_subtype_t type, | |
4274 | void *arg, | |
4275 | sctp_cmd_seq_t *commands) | |
4276 | { | |
4277 | /* There is a single T1 timer, so we should be able to use | |
4278 | * common function with the COOKIE-WAIT state. | |
4279 | */ | |
4280 | return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands); | |
4281 | } | |
4282 | ||
4283 | /* | |
4284 | * sctp_sf_shutdown_pending_prm_abort | |
4285 | * | |
4286 | * Inputs | |
4287 | * (endpoint, asoc) | |
4288 | * | |
4289 | * The RFC does not explicitly address this issue, but is the route through the | |
4290 | * state table when someone issues an abort while in SHUTDOWN-PENDING state. | |
4291 | * | |
4292 | * Outputs | |
4293 | * (timers) | |
4294 | */ | |
4295 | sctp_disposition_t sctp_sf_shutdown_pending_prm_abort( | |
4296 | const struct sctp_endpoint *ep, | |
4297 | const struct sctp_association *asoc, | |
4298 | const sctp_subtype_t type, | |
4299 | void *arg, | |
4300 | sctp_cmd_seq_t *commands) | |
4301 | { | |
4302 | /* Stop the T5-shutdown guard timer. */ | |
4303 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4304 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
4305 | ||
4306 | return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands); | |
4307 | } | |
4308 | ||
4309 | /* | |
4310 | * sctp_sf_shutdown_sent_prm_abort | |
4311 | * | |
4312 | * Inputs | |
4313 | * (endpoint, asoc) | |
4314 | * | |
4315 | * The RFC does not explicitly address this issue, but is the route through the | |
4316 | * state table when someone issues an abort while in SHUTDOWN-SENT state. | |
4317 | * | |
4318 | * Outputs | |
4319 | * (timers) | |
4320 | */ | |
4321 | sctp_disposition_t sctp_sf_shutdown_sent_prm_abort( | |
4322 | const struct sctp_endpoint *ep, | |
4323 | const struct sctp_association *asoc, | |
4324 | const sctp_subtype_t type, | |
4325 | void *arg, | |
4326 | sctp_cmd_seq_t *commands) | |
4327 | { | |
4328 | /* Stop the T2-shutdown timer. */ | |
4329 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4330 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
4331 | ||
4332 | /* Stop the T5-shutdown guard timer. */ | |
4333 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4334 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
4335 | ||
4336 | return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands); | |
4337 | } | |
4338 | ||
4339 | /* | |
4340 | * sctp_sf_cookie_echoed_prm_abort | |
4341 | * | |
4342 | * Inputs | |
4343 | * (endpoint, asoc) | |
4344 | * | |
4345 | * The RFC does not explcitly address this issue, but is the route through the | |
4346 | * state table when someone issues an abort while in COOKIE_ECHOED state. | |
4347 | * | |
4348 | * Outputs | |
4349 | * (timers) | |
4350 | */ | |
4351 | sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort( | |
4352 | const struct sctp_endpoint *ep, | |
4353 | const struct sctp_association *asoc, | |
4354 | const sctp_subtype_t type, | |
4355 | void *arg, | |
4356 | sctp_cmd_seq_t *commands) | |
4357 | { | |
4358 | /* The same T2 timer, so we should be able to use | |
4359 | * common function with the SHUTDOWN-SENT state. | |
4360 | */ | |
4361 | return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands); | |
4362 | } | |
4363 | ||
4364 | /* | |
4365 | * Process the REQUESTHEARTBEAT primitive | |
4366 | * | |
4367 | * 10.1 ULP-to-SCTP | |
4368 | * J) Request Heartbeat | |
4369 | * | |
4370 | * Format: REQUESTHEARTBEAT(association id, destination transport address) | |
4371 | * | |
4372 | * -> result | |
4373 | * | |
4374 | * Instructs the local endpoint to perform a HeartBeat on the specified | |
4375 | * destination transport address of the given association. The returned | |
4376 | * result should indicate whether the transmission of the HEARTBEAT | |
4377 | * chunk to the destination address is successful. | |
4378 | * | |
4379 | * Mandatory attributes: | |
4380 | * | |
4381 | * o association id - local handle to the SCTP association | |
4382 | * | |
4383 | * o destination transport address - the transport address of the | |
4384 | * association on which a heartbeat should be issued. | |
4385 | */ | |
4386 | sctp_disposition_t sctp_sf_do_prm_requestheartbeat( | |
4387 | const struct sctp_endpoint *ep, | |
4388 | const struct sctp_association *asoc, | |
4389 | const sctp_subtype_t type, | |
4390 | void *arg, | |
4391 | sctp_cmd_seq_t *commands) | |
4392 | { | |
fb78525a VY |
4393 | if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type, |
4394 | (struct sctp_transport *)arg, commands)) | |
4395 | return SCTP_DISPOSITION_NOMEM; | |
4396 | ||
4397 | /* | |
4398 | * RFC 2960 (bis), section 8.3 | |
4399 | * | |
4400 | * D) Request an on-demand HEARTBEAT on a specific destination | |
4401 | * transport address of a given association. | |
4402 | * | |
4403 | * The endpoint should increment the respective error counter of | |
4404 | * the destination transport address each time a HEARTBEAT is sent | |
4405 | * to that address and not acknowledged within one RTO. | |
4406 | * | |
4407 | */ | |
4408 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET, | |
4409 | SCTP_TRANSPORT(arg)); | |
4410 | return SCTP_DISPOSITION_CONSUME; | |
1da177e4 LT |
4411 | } |
4412 | ||
4413 | /* | |
4414 | * ADDIP Section 4.1 ASCONF Chunk Procedures | |
4415 | * When an endpoint has an ASCONF signaled change to be sent to the | |
4416 | * remote endpoint it should do A1 to A9 | |
4417 | */ | |
4418 | sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep, | |
4419 | const struct sctp_association *asoc, | |
4420 | const sctp_subtype_t type, | |
4421 | void *arg, | |
4422 | sctp_cmd_seq_t *commands) | |
4423 | { | |
4424 | struct sctp_chunk *chunk = arg; | |
4425 | ||
4426 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); | |
4427 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
4428 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); | |
4429 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); | |
4430 | return SCTP_DISPOSITION_CONSUME; | |
4431 | } | |
4432 | ||
4433 | /* | |
4434 | * Ignore the primitive event | |
4435 | * | |
4436 | * The return value is the disposition of the primitive. | |
4437 | */ | |
4438 | sctp_disposition_t sctp_sf_ignore_primitive( | |
4439 | const struct sctp_endpoint *ep, | |
4440 | const struct sctp_association *asoc, | |
4441 | const sctp_subtype_t type, | |
4442 | void *arg, | |
4443 | sctp_cmd_seq_t *commands) | |
4444 | { | |
4445 | SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive); | |
4446 | return SCTP_DISPOSITION_DISCARD; | |
4447 | } | |
4448 | ||
4449 | /*************************************************************************** | |
4450 | * These are the state functions for the OTHER events. | |
4451 | ***************************************************************************/ | |
4452 | ||
4453 | /* | |
4454 | * Start the shutdown negotiation. | |
4455 | * | |
4456 | * From Section 9.2: | |
4457 | * Once all its outstanding data has been acknowledged, the endpoint | |
4458 | * shall send a SHUTDOWN chunk to its peer including in the Cumulative | |
4459 | * TSN Ack field the last sequential TSN it has received from the peer. | |
4460 | * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT | |
4461 | * state. If the timer expires, the endpoint must re-send the SHUTDOWN | |
4462 | * with the updated last sequential TSN received from its peer. | |
4463 | * | |
4464 | * The return value is the disposition. | |
4465 | */ | |
4466 | sctp_disposition_t sctp_sf_do_9_2_start_shutdown( | |
4467 | const struct sctp_endpoint *ep, | |
4468 | const struct sctp_association *asoc, | |
4469 | const sctp_subtype_t type, | |
4470 | void *arg, | |
4471 | sctp_cmd_seq_t *commands) | |
4472 | { | |
4473 | struct sctp_chunk *reply; | |
4474 | ||
4475 | /* Once all its outstanding data has been acknowledged, the | |
4476 | * endpoint shall send a SHUTDOWN chunk to its peer including | |
4477 | * in the Cumulative TSN Ack field the last sequential TSN it | |
4478 | * has received from the peer. | |
4479 | */ | |
4480 | reply = sctp_make_shutdown(asoc, NULL); | |
4481 | if (!reply) | |
4482 | goto nomem; | |
4483 | ||
4484 | /* Set the transport for the SHUTDOWN chunk and the timeout for the | |
4485 | * T2-shutdown timer. | |
4486 | */ | |
4487 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); | |
4488 | ||
4489 | /* It shall then start the T2-shutdown timer */ | |
4490 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, | |
4491 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
4492 | ||
4493 | if (asoc->autoclose) | |
4494 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4495 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); | |
4496 | ||
4497 | /* and enter the SHUTDOWN-SENT state. */ | |
4498 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
4499 | SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT)); | |
4500 | ||
4501 | /* sctp-implguide 2.10 Issues with Heartbeating and failover | |
4502 | * | |
4503 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN | |
d808ad9a | 4504 | * or SHUTDOWN-ACK. |
1da177e4 LT |
4505 | */ |
4506 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); | |
4507 | ||
4508 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
4509 | ||
4510 | return SCTP_DISPOSITION_CONSUME; | |
4511 | ||
4512 | nomem: | |
4513 | return SCTP_DISPOSITION_NOMEM; | |
4514 | } | |
4515 | ||
4516 | /* | |
4517 | * Generate a SHUTDOWN ACK now that everything is SACK'd. | |
4518 | * | |
4519 | * From Section 9.2: | |
4520 | * | |
4521 | * If it has no more outstanding DATA chunks, the SHUTDOWN receiver | |
4522 | * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own, | |
4523 | * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the | |
4524 | * endpoint must re-send the SHUTDOWN ACK. | |
4525 | * | |
4526 | * The return value is the disposition. | |
4527 | */ | |
4528 | sctp_disposition_t sctp_sf_do_9_2_shutdown_ack( | |
4529 | const struct sctp_endpoint *ep, | |
4530 | const struct sctp_association *asoc, | |
4531 | const sctp_subtype_t type, | |
4532 | void *arg, | |
4533 | sctp_cmd_seq_t *commands) | |
4534 | { | |
4535 | struct sctp_chunk *chunk = (struct sctp_chunk *) arg; | |
4536 | struct sctp_chunk *reply; | |
4537 | ||
4538 | /* There are 2 ways of getting here: | |
4539 | * 1) called in response to a SHUTDOWN chunk | |
4540 | * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued. | |
4541 | * | |
4542 | * For the case (2), the arg parameter is set to NULL. We need | |
4543 | * to check that we have a chunk before accessing it's fields. | |
4544 | */ | |
4545 | if (chunk) { | |
4546 | if (!sctp_vtag_verify(chunk, asoc)) | |
4547 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); | |
4548 | ||
4549 | /* Make sure that the SHUTDOWN chunk has a valid length. */ | |
4550 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t))) | |
4551 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, | |
4552 | commands); | |
4553 | } | |
4554 | ||
4555 | /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver | |
4556 | * shall send a SHUTDOWN ACK ... | |
4557 | */ | |
4558 | reply = sctp_make_shutdown_ack(asoc, chunk); | |
4559 | if (!reply) | |
4560 | goto nomem; | |
4561 | ||
4562 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for | |
4563 | * the T2-shutdown timer. | |
4564 | */ | |
4565 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); | |
4566 | ||
4567 | /* and start/restart a T2-shutdown timer of its own, */ | |
4568 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
4569 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
4570 | ||
4571 | if (asoc->autoclose) | |
4572 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4573 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); | |
4574 | ||
4575 | /* Enter the SHUTDOWN-ACK-SENT state. */ | |
4576 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
4577 | SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT)); | |
4578 | ||
4579 | /* sctp-implguide 2.10 Issues with Heartbeating and failover | |
4580 | * | |
4581 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN | |
d808ad9a | 4582 | * or SHUTDOWN-ACK. |
1da177e4 LT |
4583 | */ |
4584 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); | |
4585 | ||
4586 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
4587 | ||
4588 | return SCTP_DISPOSITION_CONSUME; | |
4589 | ||
4590 | nomem: | |
4591 | return SCTP_DISPOSITION_NOMEM; | |
4592 | } | |
4593 | ||
4594 | /* | |
4595 | * Ignore the event defined as other | |
4596 | * | |
4597 | * The return value is the disposition of the event. | |
4598 | */ | |
4599 | sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep, | |
4600 | const struct sctp_association *asoc, | |
4601 | const sctp_subtype_t type, | |
4602 | void *arg, | |
4603 | sctp_cmd_seq_t *commands) | |
4604 | { | |
4605 | SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other); | |
4606 | return SCTP_DISPOSITION_DISCARD; | |
4607 | } | |
4608 | ||
4609 | /************************************************************ | |
4610 | * These are the state functions for handling timeout events. | |
4611 | ************************************************************/ | |
4612 | ||
4613 | /* | |
4614 | * RTX Timeout | |
4615 | * | |
4616 | * Section: 6.3.3 Handle T3-rtx Expiration | |
4617 | * | |
4618 | * Whenever the retransmission timer T3-rtx expires for a destination | |
4619 | * address, do the following: | |
4620 | * [See below] | |
4621 | * | |
4622 | * The return value is the disposition of the chunk. | |
4623 | */ | |
4624 | sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep, | |
4625 | const struct sctp_association *asoc, | |
4626 | const sctp_subtype_t type, | |
4627 | void *arg, | |
4628 | sctp_cmd_seq_t *commands) | |
4629 | { | |
4630 | struct sctp_transport *transport = arg; | |
4631 | ||
ac0b0462 SS |
4632 | SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS); |
4633 | ||
1da177e4 | 4634 | if (asoc->overall_error_count >= asoc->max_retrans) { |
8de8c873 SS |
4635 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4636 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 LT |
4637 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
4638 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, | |
5be291fe | 4639 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
1da177e4 LT |
4640 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
4641 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
4642 | return SCTP_DISPOSITION_DELETE_TCB; | |
4643 | } | |
4644 | ||
4645 | /* E1) For the destination address for which the timer | |
4646 | * expires, adjust its ssthresh with rules defined in Section | |
4647 | * 7.2.3 and set the cwnd <- MTU. | |
4648 | */ | |
4649 | ||
4650 | /* E2) For the destination address for which the timer | |
4651 | * expires, set RTO <- RTO * 2 ("back off the timer"). The | |
4652 | * maximum value discussed in rule C7 above (RTO.max) may be | |
4653 | * used to provide an upper bound to this doubling operation. | |
4654 | */ | |
4655 | ||
4656 | /* E3) Determine how many of the earliest (i.e., lowest TSN) | |
4657 | * outstanding DATA chunks for the address for which the | |
4658 | * T3-rtx has expired will fit into a single packet, subject | |
4659 | * to the MTU constraint for the path corresponding to the | |
4660 | * destination transport address to which the retransmission | |
4661 | * is being sent (this may be different from the address for | |
4662 | * which the timer expires [see Section 6.4]). Call this | |
4663 | * value K. Bundle and retransmit those K DATA chunks in a | |
4664 | * single packet to the destination endpoint. | |
4665 | * | |
4666 | * Note: Any DATA chunks that were sent to the address for | |
4667 | * which the T3-rtx timer expired but did not fit in one MTU | |
4668 | * (rule E3 above), should be marked for retransmission and | |
4669 | * sent as soon as cwnd allows (normally when a SACK arrives). | |
4670 | */ | |
4671 | ||
1da177e4 LT |
4672 | /* Do some failure management (Section 8.2). */ |
4673 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); | |
4674 | ||
1845a579 VY |
4675 | /* NB: Rules E4 and F1 are implicit in R1. */ |
4676 | sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport)); | |
4677 | ||
1da177e4 LT |
4678 | return SCTP_DISPOSITION_CONSUME; |
4679 | } | |
4680 | ||
4681 | /* | |
4682 | * Generate delayed SACK on timeout | |
4683 | * | |
4684 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks | |
4685 | * | |
4686 | * The guidelines on delayed acknowledgement algorithm specified in | |
4687 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an | |
4688 | * acknowledgement SHOULD be generated for at least every second packet | |
4689 | * (not every second DATA chunk) received, and SHOULD be generated | |
4690 | * within 200 ms of the arrival of any unacknowledged DATA chunk. In | |
4691 | * some situations it may be beneficial for an SCTP transmitter to be | |
4692 | * more conservative than the algorithms detailed in this document | |
4693 | * allow. However, an SCTP transmitter MUST NOT be more aggressive than | |
4694 | * the following algorithms allow. | |
4695 | */ | |
4696 | sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep, | |
4697 | const struct sctp_association *asoc, | |
4698 | const sctp_subtype_t type, | |
4699 | void *arg, | |
4700 | sctp_cmd_seq_t *commands) | |
4701 | { | |
ac0b0462 | 4702 | SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS); |
1da177e4 LT |
4703 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
4704 | return SCTP_DISPOSITION_CONSUME; | |
4705 | } | |
4706 | ||
4707 | /* | |
3f7a87d2 | 4708 | * sctp_sf_t1_init_timer_expire |
1da177e4 LT |
4709 | * |
4710 | * Section: 4 Note: 2 | |
4711 | * Verification Tag: | |
4712 | * Inputs | |
4713 | * (endpoint, asoc) | |
4714 | * | |
4715 | * RFC 2960 Section 4 Notes | |
4716 | * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT | |
4717 | * and re-start the T1-init timer without changing state. This MUST | |
4718 | * be repeated up to 'Max.Init.Retransmits' times. After that, the | |
4719 | * endpoint MUST abort the initialization process and report the | |
4720 | * error to SCTP user. | |
4721 | * | |
3f7a87d2 FF |
4722 | * Outputs |
4723 | * (timers, events) | |
4724 | * | |
4725 | */ | |
4726 | sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep, | |
4727 | const struct sctp_association *asoc, | |
4728 | const sctp_subtype_t type, | |
4729 | void *arg, | |
4730 | sctp_cmd_seq_t *commands) | |
4731 | { | |
4732 | struct sctp_chunk *repl = NULL; | |
4733 | struct sctp_bind_addr *bp; | |
4734 | int attempts = asoc->init_err_counter + 1; | |
4735 | ||
4736 | SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n"); | |
ac0b0462 | 4737 | SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS); |
3f7a87d2 | 4738 | |
81845c21 | 4739 | if (attempts <= asoc->max_init_attempts) { |
3f7a87d2 FF |
4740 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
4741 | repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); | |
4742 | if (!repl) | |
4743 | return SCTP_DISPOSITION_NOMEM; | |
4744 | ||
4745 | /* Choose transport for INIT. */ | |
4746 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, | |
4747 | SCTP_CHUNK(repl)); | |
4748 | ||
4749 | /* Issue a sideeffect to do the needed accounting. */ | |
4750 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, | |
4751 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); | |
4752 | ||
4753 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); | |
4754 | } else { | |
4755 | SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d" | |
4756 | " max_init_attempts: %d\n", | |
4757 | attempts, asoc->max_init_attempts); | |
8de8c873 SS |
4758 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4759 | SCTP_ERROR(ETIMEDOUT)); | |
3f7a87d2 | 4760 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
dc251b2b | 4761 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
3f7a87d2 FF |
4762 | return SCTP_DISPOSITION_DELETE_TCB; |
4763 | } | |
4764 | ||
4765 | return SCTP_DISPOSITION_CONSUME; | |
4766 | } | |
4767 | ||
4768 | /* | |
4769 | * sctp_sf_t1_cookie_timer_expire | |
4770 | * | |
4771 | * Section: 4 Note: 2 | |
4772 | * Verification Tag: | |
4773 | * Inputs | |
4774 | * (endpoint, asoc) | |
4775 | * | |
4776 | * RFC 2960 Section 4 Notes | |
4777 | * 3) If the T1-cookie timer expires, the endpoint MUST retransmit | |
1da177e4 LT |
4778 | * COOKIE ECHO and re-start the T1-cookie timer without changing |
4779 | * state. This MUST be repeated up to 'Max.Init.Retransmits' times. | |
4780 | * After that, the endpoint MUST abort the initialization process and | |
4781 | * report the error to SCTP user. | |
4782 | * | |
4783 | * Outputs | |
4784 | * (timers, events) | |
4785 | * | |
4786 | */ | |
3f7a87d2 | 4787 | sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep, |
1da177e4 LT |
4788 | const struct sctp_association *asoc, |
4789 | const sctp_subtype_t type, | |
4790 | void *arg, | |
4791 | sctp_cmd_seq_t *commands) | |
4792 | { | |
3f7a87d2 FF |
4793 | struct sctp_chunk *repl = NULL; |
4794 | int attempts = asoc->init_err_counter + 1; | |
1da177e4 | 4795 | |
3f7a87d2 | 4796 | SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n"); |
ac0b0462 | 4797 | SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS); |
1da177e4 | 4798 | |
81845c21 | 4799 | if (attempts <= asoc->max_init_attempts) { |
3f7a87d2 | 4800 | repl = sctp_make_cookie_echo(asoc, NULL); |
1da177e4 | 4801 | if (!repl) |
3f7a87d2 | 4802 | return SCTP_DISPOSITION_NOMEM; |
1da177e4 LT |
4803 | |
4804 | /* Issue a sideeffect to do the needed accounting. */ | |
3f7a87d2 FF |
4805 | sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART, |
4806 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); | |
4807 | ||
1da177e4 LT |
4808 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
4809 | } else { | |
8de8c873 SS |
4810 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4811 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 | 4812 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
dc251b2b | 4813 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
1da177e4 LT |
4814 | return SCTP_DISPOSITION_DELETE_TCB; |
4815 | } | |
4816 | ||
4817 | return SCTP_DISPOSITION_CONSUME; | |
1da177e4 LT |
4818 | } |
4819 | ||
4820 | /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN | |
4821 | * with the updated last sequential TSN received from its peer. | |
4822 | * | |
4823 | * An endpoint should limit the number of retransmissions of the | |
4824 | * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'. | |
4825 | * If this threshold is exceeded the endpoint should destroy the TCB and | |
4826 | * MUST report the peer endpoint unreachable to the upper layer (and | |
4827 | * thus the association enters the CLOSED state). The reception of any | |
4828 | * packet from its peer (i.e. as the peer sends all of its queued DATA | |
4829 | * chunks) should clear the endpoint's retransmission count and restart | |
4830 | * the T2-Shutdown timer, giving its peer ample opportunity to transmit | |
4831 | * all of its queued DATA chunks that have not yet been sent. | |
4832 | */ | |
4833 | sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep, | |
4834 | const struct sctp_association *asoc, | |
4835 | const sctp_subtype_t type, | |
4836 | void *arg, | |
4837 | sctp_cmd_seq_t *commands) | |
4838 | { | |
4839 | struct sctp_chunk *reply = NULL; | |
4840 | ||
4841 | SCTP_DEBUG_PRINTK("Timer T2 expired.\n"); | |
ac0b0462 SS |
4842 | SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS); |
4843 | ||
1da177e4 | 4844 | if (asoc->overall_error_count >= asoc->max_retrans) { |
8de8c873 SS |
4845 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4846 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 LT |
4847 | /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
4848 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, | |
5be291fe | 4849 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
1da177e4 LT |
4850 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
4851 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
4852 | return SCTP_DISPOSITION_DELETE_TCB; | |
4853 | } | |
4854 | ||
4855 | switch (asoc->state) { | |
4856 | case SCTP_STATE_SHUTDOWN_SENT: | |
4857 | reply = sctp_make_shutdown(asoc, NULL); | |
4858 | break; | |
4859 | ||
4860 | case SCTP_STATE_SHUTDOWN_ACK_SENT: | |
4861 | reply = sctp_make_shutdown_ack(asoc, NULL); | |
4862 | break; | |
4863 | ||
4864 | default: | |
4865 | BUG(); | |
4866 | break; | |
3ff50b79 | 4867 | } |
1da177e4 LT |
4868 | |
4869 | if (!reply) | |
4870 | goto nomem; | |
4871 | ||
4872 | /* Do some failure management (Section 8.2). */ | |
4873 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, | |
4874 | SCTP_TRANSPORT(asoc->shutdown_last_sent_to)); | |
4875 | ||
4876 | /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for | |
4877 | * the T2-shutdown timer. | |
4878 | */ | |
4879 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); | |
4880 | ||
4881 | /* Restart the T2-shutdown timer. */ | |
4882 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
4883 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); | |
4884 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
4885 | return SCTP_DISPOSITION_CONSUME; | |
4886 | ||
4887 | nomem: | |
4888 | return SCTP_DISPOSITION_NOMEM; | |
4889 | } | |
4890 | ||
4891 | /* | |
4892 | * ADDIP Section 4.1 ASCONF CHunk Procedures | |
4893 | * If the T4 RTO timer expires the endpoint should do B1 to B5 | |
4894 | */ | |
4895 | sctp_disposition_t sctp_sf_t4_timer_expire( | |
4896 | const struct sctp_endpoint *ep, | |
4897 | const struct sctp_association *asoc, | |
4898 | const sctp_subtype_t type, | |
4899 | void *arg, | |
4900 | sctp_cmd_seq_t *commands) | |
4901 | { | |
4902 | struct sctp_chunk *chunk = asoc->addip_last_asconf; | |
4903 | struct sctp_transport *transport = chunk->transport; | |
4904 | ||
ac0b0462 SS |
4905 | SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS); |
4906 | ||
1da177e4 LT |
4907 | /* ADDIP 4.1 B1) Increment the error counters and perform path failure |
4908 | * detection on the appropriate destination address as defined in | |
4909 | * RFC2960 [5] section 8.1 and 8.2. | |
4910 | */ | |
4911 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); | |
4912 | ||
4913 | /* Reconfig T4 timer and transport. */ | |
4914 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); | |
4915 | ||
4916 | /* ADDIP 4.1 B2) Increment the association error counters and perform | |
4917 | * endpoint failure detection on the association as defined in | |
4918 | * RFC2960 [5] section 8.1 and 8.2. | |
4919 | * association error counter is incremented in SCTP_CMD_STRIKE. | |
4920 | */ | |
4921 | if (asoc->overall_error_count >= asoc->max_retrans) { | |
4922 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, | |
4923 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); | |
8de8c873 SS |
4924 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4925 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 | 4926 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
5be291fe | 4927 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
1da177e4 LT |
4928 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
4929 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); | |
4930 | return SCTP_DISPOSITION_ABORT; | |
4931 | } | |
4932 | ||
4933 | /* ADDIP 4.1 B3) Back-off the destination address RTO value to which | |
4934 | * the ASCONF chunk was sent by doubling the RTO timer value. | |
4935 | * This is done in SCTP_CMD_STRIKE. | |
4936 | */ | |
4937 | ||
4938 | /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible | |
4939 | * choose an alternate destination address (please refer to RFC2960 | |
4940 | * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this | |
d808ad9a | 4941 | * chunk, it MUST be the same (including its serial number) as the last |
1da177e4 LT |
4942 | * ASCONF sent. |
4943 | */ | |
4944 | sctp_chunk_hold(asoc->addip_last_asconf); | |
4945 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, | |
4946 | SCTP_CHUNK(asoc->addip_last_asconf)); | |
4947 | ||
4948 | /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different | |
4949 | * destination is selected, then the RTO used will be that of the new | |
4950 | * destination address. | |
4951 | */ | |
4952 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, | |
4953 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); | |
4954 | ||
4955 | return SCTP_DISPOSITION_CONSUME; | |
4956 | } | |
4957 | ||
4958 | /* sctpimpguide-05 Section 2.12.2 | |
4959 | * The sender of the SHUTDOWN MAY also start an overall guard timer | |
4960 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. | |
4961 | * At the expiration of this timer the sender SHOULD abort the association | |
4962 | * by sending an ABORT chunk. | |
4963 | */ | |
4964 | sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep, | |
4965 | const struct sctp_association *asoc, | |
4966 | const sctp_subtype_t type, | |
4967 | void *arg, | |
4968 | sctp_cmd_seq_t *commands) | |
4969 | { | |
4970 | struct sctp_chunk *reply = NULL; | |
4971 | ||
4972 | SCTP_DEBUG_PRINTK("Timer T5 expired.\n"); | |
ac0b0462 | 4973 | SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS); |
1da177e4 LT |
4974 | |
4975 | reply = sctp_make_abort(asoc, NULL, 0); | |
4976 | if (!reply) | |
4977 | goto nomem; | |
4978 | ||
4979 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); | |
8de8c873 SS |
4980 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
4981 | SCTP_ERROR(ETIMEDOUT)); | |
1da177e4 | 4982 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
5be291fe | 4983 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
1da177e4 LT |
4984 | |
4985 | return SCTP_DISPOSITION_DELETE_TCB; | |
4986 | nomem: | |
4987 | return SCTP_DISPOSITION_NOMEM; | |
4988 | } | |
4989 | ||
4990 | /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires, | |
4991 | * the association is automatically closed by starting the shutdown process. | |
4992 | * The work that needs to be done is same as when SHUTDOWN is initiated by | |
4993 | * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown(). | |
4994 | */ | |
4995 | sctp_disposition_t sctp_sf_autoclose_timer_expire( | |
4996 | const struct sctp_endpoint *ep, | |
4997 | const struct sctp_association *asoc, | |
4998 | const sctp_subtype_t type, | |
4999 | void *arg, | |
5000 | sctp_cmd_seq_t *commands) | |
5001 | { | |
5002 | int disposition; | |
5003 | ||
ac0b0462 SS |
5004 | SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS); |
5005 | ||
1da177e4 LT |
5006 | /* From 9.2 Shutdown of an Association |
5007 | * Upon receipt of the SHUTDOWN primitive from its upper | |
5008 | * layer, the endpoint enters SHUTDOWN-PENDING state and | |
5009 | * remains there until all outstanding data has been | |
5010 | * acknowledged by its peer. The endpoint accepts no new data | |
5011 | * from its upper layer, but retransmits data to the far end | |
5012 | * if necessary to fill gaps. | |
5013 | */ | |
5014 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, | |
5015 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); | |
5016 | ||
5017 | /* sctpimpguide-05 Section 2.12.2 | |
5018 | * The sender of the SHUTDOWN MAY also start an overall guard timer | |
5019 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. | |
d808ad9a | 5020 | */ |
1da177e4 LT |
5021 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
5022 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); | |
5023 | disposition = SCTP_DISPOSITION_CONSUME; | |
5024 | if (sctp_outq_is_empty(&asoc->outqueue)) { | |
5025 | disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type, | |
5026 | arg, commands); | |
5027 | } | |
5028 | return disposition; | |
5029 | } | |
5030 | ||
5031 | /***************************************************************************** | |
5032 | * These are sa state functions which could apply to all types of events. | |
5033 | ****************************************************************************/ | |
5034 | ||
5035 | /* | |
5036 | * This table entry is not implemented. | |
5037 | * | |
5038 | * Inputs | |
5039 | * (endpoint, asoc, chunk) | |
5040 | * | |
5041 | * The return value is the disposition of the chunk. | |
5042 | */ | |
5043 | sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep, | |
5044 | const struct sctp_association *asoc, | |
5045 | const sctp_subtype_t type, | |
5046 | void *arg, | |
5047 | sctp_cmd_seq_t *commands) | |
5048 | { | |
5049 | return SCTP_DISPOSITION_NOT_IMPL; | |
5050 | } | |
5051 | ||
5052 | /* | |
5053 | * This table entry represents a bug. | |
5054 | * | |
5055 | * Inputs | |
5056 | * (endpoint, asoc, chunk) | |
5057 | * | |
5058 | * The return value is the disposition of the chunk. | |
5059 | */ | |
5060 | sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep, | |
5061 | const struct sctp_association *asoc, | |
5062 | const sctp_subtype_t type, | |
5063 | void *arg, | |
5064 | sctp_cmd_seq_t *commands) | |
5065 | { | |
5066 | return SCTP_DISPOSITION_BUG; | |
5067 | } | |
5068 | ||
5069 | /* | |
5070 | * This table entry represents the firing of a timer in the wrong state. | |
5071 | * Since timer deletion cannot be guaranteed a timer 'may' end up firing | |
5072 | * when the association is in the wrong state. This event should | |
5073 | * be ignored, so as to prevent any rearming of the timer. | |
5074 | * | |
5075 | * Inputs | |
5076 | * (endpoint, asoc, chunk) | |
5077 | * | |
5078 | * The return value is the disposition of the chunk. | |
5079 | */ | |
5080 | sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep, | |
5081 | const struct sctp_association *asoc, | |
5082 | const sctp_subtype_t type, | |
5083 | void *arg, | |
5084 | sctp_cmd_seq_t *commands) | |
5085 | { | |
5086 | SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk); | |
5087 | return SCTP_DISPOSITION_CONSUME; | |
5088 | } | |
5089 | ||
5090 | /******************************************************************** | |
5091 | * 2nd Level Abstractions | |
5092 | ********************************************************************/ | |
5093 | ||
5094 | /* Pull the SACK chunk based on the SACK header. */ | |
5095 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk) | |
5096 | { | |
5097 | struct sctp_sackhdr *sack; | |
5098 | unsigned int len; | |
5099 | __u16 num_blocks; | |
5100 | __u16 num_dup_tsns; | |
5101 | ||
5102 | /* Protect ourselves from reading too far into | |
5103 | * the skb from a bogus sender. | |
5104 | */ | |
5105 | sack = (struct sctp_sackhdr *) chunk->skb->data; | |
5106 | ||
5107 | num_blocks = ntohs(sack->num_gap_ack_blocks); | |
5108 | num_dup_tsns = ntohs(sack->num_dup_tsns); | |
5109 | len = sizeof(struct sctp_sackhdr); | |
5110 | len += (num_blocks + num_dup_tsns) * sizeof(__u32); | |
5111 | if (len > chunk->skb->len) | |
5112 | return NULL; | |
5113 | ||
5114 | skb_pull(chunk->skb, len); | |
5115 | ||
5116 | return sack; | |
5117 | } | |
5118 | ||
5119 | /* Create an ABORT packet to be sent as a response, with the specified | |
5120 | * error causes. | |
5121 | */ | |
5122 | static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep, | |
5123 | const struct sctp_association *asoc, | |
5124 | struct sctp_chunk *chunk, | |
5125 | const void *payload, | |
5126 | size_t paylen) | |
5127 | { | |
5128 | struct sctp_packet *packet; | |
5129 | struct sctp_chunk *abort; | |
5130 | ||
5131 | packet = sctp_ootb_pkt_new(asoc, chunk); | |
5132 | ||
5133 | if (packet) { | |
5134 | /* Make an ABORT. | |
5135 | * The T bit will be set if the asoc is NULL. | |
5136 | */ | |
5137 | abort = sctp_make_abort(asoc, chunk, paylen); | |
5138 | if (!abort) { | |
5139 | sctp_ootb_pkt_free(packet); | |
5140 | return NULL; | |
5141 | } | |
047a2428 JF |
5142 | |
5143 | /* Reflect vtag if T-Bit is set */ | |
5144 | if (sctp_test_T_bit(abort)) | |
5145 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); | |
5146 | ||
1da177e4 LT |
5147 | /* Add specified error causes, i.e., payload, to the |
5148 | * end of the chunk. | |
5149 | */ | |
5150 | sctp_addto_chunk(abort, paylen, payload); | |
5151 | ||
5152 | /* Set the skb to the belonging sock for accounting. */ | |
5153 | abort->skb->sk = ep->base.sk; | |
5154 | ||
5155 | sctp_packet_append_chunk(packet, abort); | |
5156 | ||
5157 | } | |
5158 | ||
5159 | return packet; | |
5160 | } | |
5161 | ||
5162 | /* Allocate a packet for responding in the OOTB conditions. */ | |
5163 | static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc, | |
5164 | const struct sctp_chunk *chunk) | |
5165 | { | |
5166 | struct sctp_packet *packet; | |
5167 | struct sctp_transport *transport; | |
5168 | __u16 sport; | |
5169 | __u16 dport; | |
5170 | __u32 vtag; | |
5171 | ||
5172 | /* Get the source and destination port from the inbound packet. */ | |
5173 | sport = ntohs(chunk->sctp_hdr->dest); | |
5174 | dport = ntohs(chunk->sctp_hdr->source); | |
5175 | ||
5176 | /* The V-tag is going to be the same as the inbound packet if no | |
5177 | * association exists, otherwise, use the peer's vtag. | |
5178 | */ | |
5179 | if (asoc) { | |
5180 | vtag = asoc->peer.i.init_tag; | |
5181 | } else { | |
5182 | /* Special case the INIT and stale COOKIE_ECHO as there is no | |
5183 | * vtag yet. | |
5184 | */ | |
5185 | switch(chunk->chunk_hdr->type) { | |
5186 | case SCTP_CID_INIT: | |
5187 | { | |
5188 | sctp_init_chunk_t *init; | |
5189 | ||
5190 | init = (sctp_init_chunk_t *)chunk->chunk_hdr; | |
5191 | vtag = ntohl(init->init_hdr.init_tag); | |
5192 | break; | |
5193 | } | |
d808ad9a | 5194 | default: |
1da177e4 LT |
5195 | vtag = ntohl(chunk->sctp_hdr->vtag); |
5196 | break; | |
5197 | } | |
5198 | } | |
5199 | ||
5200 | /* Make a transport for the bucket, Eliza... */ | |
6a1e5f33 | 5201 | transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC); |
1da177e4 LT |
5202 | if (!transport) |
5203 | goto nomem; | |
5204 | ||
5205 | /* Cache a route for the transport with the chunk's destination as | |
5206 | * the source address. | |
5207 | */ | |
16b0a030 | 5208 | sctp_transport_route(transport, (union sctp_addr *)&chunk->dest, |
1da177e4 LT |
5209 | sctp_sk(sctp_get_ctl_sock())); |
5210 | ||
5211 | packet = sctp_packet_init(&transport->packet, transport, sport, dport); | |
5212 | packet = sctp_packet_config(packet, vtag, 0); | |
5213 | ||
5214 | return packet; | |
5215 | ||
5216 | nomem: | |
5217 | return NULL; | |
5218 | } | |
5219 | ||
5220 | /* Free the packet allocated earlier for responding in the OOTB condition. */ | |
5221 | void sctp_ootb_pkt_free(struct sctp_packet *packet) | |
5222 | { | |
5223 | sctp_transport_free(packet->transport); | |
5224 | } | |
5225 | ||
5226 | /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */ | |
5227 | static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep, | |
5228 | const struct sctp_association *asoc, | |
5229 | const struct sctp_chunk *chunk, | |
5230 | sctp_cmd_seq_t *commands, | |
5231 | struct sctp_chunk *err_chunk) | |
5232 | { | |
5233 | struct sctp_packet *packet; | |
5234 | ||
5235 | if (err_chunk) { | |
5236 | packet = sctp_ootb_pkt_new(asoc, chunk); | |
5237 | if (packet) { | |
5238 | struct sctp_signed_cookie *cookie; | |
5239 | ||
5240 | /* Override the OOTB vtag from the cookie. */ | |
5241 | cookie = chunk->subh.cookie_hdr; | |
5242 | packet->vtag = cookie->c.peer_vtag; | |
d808ad9a | 5243 | |
1da177e4 LT |
5244 | /* Set the skb to the belonging sock for accounting. */ |
5245 | err_chunk->skb->sk = ep->base.sk; | |
5246 | sctp_packet_append_chunk(packet, err_chunk); | |
5247 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, | |
5248 | SCTP_PACKET(packet)); | |
5249 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); | |
5250 | } else | |
5251 | sctp_chunk_free (err_chunk); | |
5252 | } | |
5253 | } | |
5254 | ||
5255 | ||
5256 | /* Process a data chunk */ | |
5257 | static int sctp_eat_data(const struct sctp_association *asoc, | |
5258 | struct sctp_chunk *chunk, | |
5259 | sctp_cmd_seq_t *commands) | |
5260 | { | |
5261 | sctp_datahdr_t *data_hdr; | |
5262 | struct sctp_chunk *err; | |
5263 | size_t datalen; | |
5264 | sctp_verb_t deliver; | |
5265 | int tmp; | |
5266 | __u32 tsn; | |
049b3ff5 | 5267 | int account_value; |
7c3ceb4f | 5268 | struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map; |
049b3ff5 | 5269 | struct sock *sk = asoc->base.sk; |
7c3ceb4f | 5270 | int rcvbuf_over = 0; |
1da177e4 LT |
5271 | |
5272 | data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data; | |
5273 | skb_pull(chunk->skb, sizeof(sctp_datahdr_t)); | |
5274 | ||
5275 | tsn = ntohl(data_hdr->tsn); | |
5276 | SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn); | |
5277 | ||
5278 | /* ASSERT: Now skb->data is really the user data. */ | |
5279 | ||
049b3ff5 | 5280 | /* |
7c3ceb4f NH |
5281 | * If we are established, and we have used up our receive buffer |
5282 | * memory, think about droping the frame. | |
5283 | * Note that we have an opportunity to improve performance here. | |
5284 | * If we accept one chunk from an skbuff, we have to keep all the | |
5285 | * memory of that skbuff around until the chunk is read into user | |
5286 | * space. Therefore, once we accept 1 chunk we may as well accept all | |
5287 | * remaining chunks in the skbuff. The data_accepted flag helps us do | |
5288 | * that. | |
5289 | */ | |
5290 | if ((asoc->state == SCTP_STATE_ESTABLISHED) && (!chunk->data_accepted)) { | |
049b3ff5 NH |
5291 | /* |
5292 | * If the receive buffer policy is 1, then each | |
5293 | * association can allocate up to sk_rcvbuf bytes | |
5294 | * otherwise, all the associations in aggregate | |
5295 | * may allocate up to sk_rcvbuf bytes | |
5296 | */ | |
5297 | if (asoc->ep->rcvbuf_policy) | |
5298 | account_value = atomic_read(&asoc->rmem_alloc); | |
5299 | else | |
5300 | account_value = atomic_read(&sk->sk_rmem_alloc); | |
7c3ceb4f NH |
5301 | if (account_value > sk->sk_rcvbuf) { |
5302 | /* | |
5303 | * We need to make forward progress, even when we are | |
5304 | * under memory pressure, so we always allow the | |
5305 | * next tsn after the ctsn ack point to be accepted. | |
5306 | * This lets us avoid deadlocks in which we have to | |
5307 | * drop frames that would otherwise let us drain the | |
5308 | * receive queue. | |
5309 | */ | |
5310 | if ((sctp_tsnmap_get_ctsn(map) + 1) != tsn) | |
5311 | return SCTP_IERROR_IGNORE_TSN; | |
5312 | ||
5313 | /* | |
5314 | * We're going to accept the frame but we should renege | |
5315 | * to make space for it. This will send us down that | |
5316 | * path later in this function. | |
5317 | */ | |
5318 | rcvbuf_over = 1; | |
5319 | } | |
049b3ff5 NH |
5320 | } |
5321 | ||
1da177e4 LT |
5322 | /* Process ECN based congestion. |
5323 | * | |
5324 | * Since the chunk structure is reused for all chunks within | |
5325 | * a packet, we use ecn_ce_done to track if we've already | |
5326 | * done CE processing for this packet. | |
5327 | * | |
5328 | * We need to do ECN processing even if we plan to discard the | |
5329 | * chunk later. | |
5330 | */ | |
5331 | ||
5332 | if (!chunk->ecn_ce_done) { | |
5333 | struct sctp_af *af; | |
5334 | chunk->ecn_ce_done = 1; | |
5335 | ||
5336 | af = sctp_get_af_specific( | |
eddc9ec5 | 5337 | ipver2af(ip_hdr(chunk->skb)->version)); |
1da177e4 LT |
5338 | |
5339 | if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) { | |
5340 | /* Do real work as sideffect. */ | |
5341 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE, | |
5342 | SCTP_U32(tsn)); | |
5343 | } | |
5344 | } | |
5345 | ||
5346 | tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn); | |
5347 | if (tmp < 0) { | |
5348 | /* The TSN is too high--silently discard the chunk and | |
5349 | * count on it getting retransmitted later. | |
5350 | */ | |
5351 | return SCTP_IERROR_HIGH_TSN; | |
5352 | } else if (tmp > 0) { | |
5353 | /* This is a duplicate. Record it. */ | |
5354 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn)); | |
5355 | return SCTP_IERROR_DUP_TSN; | |
5356 | } | |
5357 | ||
5358 | /* This is a new TSN. */ | |
5359 | ||
5360 | /* Discard if there is no room in the receive window. | |
5361 | * Actually, allow a little bit of overflow (up to a MTU). | |
5362 | */ | |
5363 | datalen = ntohs(chunk->chunk_hdr->length); | |
5364 | datalen -= sizeof(sctp_data_chunk_t); | |
5365 | ||
5366 | deliver = SCTP_CMD_CHUNK_ULP; | |
5367 | ||
5368 | /* Think about partial delivery. */ | |
5369 | if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { | |
5370 | ||
5371 | /* Even if we don't accept this chunk there is | |
5372 | * memory pressure. | |
5373 | */ | |
5374 | sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL()); | |
5375 | } | |
5376 | ||
d808ad9a | 5377 | /* Spill over rwnd a little bit. Note: While allowed, this spill over |
1da177e4 LT |
5378 | * seems a bit troublesome in that frag_point varies based on |
5379 | * PMTU. In cases, such as loopback, this might be a rather | |
5380 | * large spill over. | |
d5b9f4c0 NH |
5381 | * NOTE: If we have a full receive buffer here, we only renege if |
5382 | * our receiver can still make progress without the tsn being | |
5383 | * received. We do this because in the event that the associations | |
5384 | * receive queue is empty we are filling a leading gap, and since | |
5385 | * reneging moves the gap to the end of the tsn stream, we are likely | |
5386 | * to stall again very shortly. Avoiding the renege when we fill a | |
5387 | * leading gap is a good heuristic for avoiding such steady state | |
5388 | * stalls. | |
1da177e4 LT |
5389 | */ |
5390 | if (!asoc->rwnd || asoc->rwnd_over || | |
7c3ceb4f | 5391 | (datalen > asoc->rwnd + asoc->frag_point) || |
d5b9f4c0 | 5392 | (rcvbuf_over && (!skb_queue_len(&sk->sk_receive_queue)))) { |
1da177e4 LT |
5393 | |
5394 | /* If this is the next TSN, consider reneging to make | |
5395 | * room. Note: Playing nice with a confused sender. A | |
5396 | * malicious sender can still eat up all our buffer | |
5397 | * space and in the future we may want to detect and | |
5398 | * do more drastic reneging. | |
5399 | */ | |
7c3ceb4f NH |
5400 | if (sctp_tsnmap_has_gap(map) && |
5401 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { | |
1da177e4 LT |
5402 | SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn); |
5403 | deliver = SCTP_CMD_RENEGE; | |
5404 | } else { | |
5405 | SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, " | |
5406 | "rwnd: %d\n", tsn, datalen, | |
5407 | asoc->rwnd); | |
5408 | return SCTP_IERROR_IGNORE_TSN; | |
5409 | } | |
5410 | } | |
5411 | ||
5412 | /* | |
5413 | * Section 3.3.10.9 No User Data (9) | |
5414 | * | |
5415 | * Cause of error | |
5416 | * --------------- | |
5417 | * No User Data: This error cause is returned to the originator of a | |
5418 | * DATA chunk if a received DATA chunk has no user data. | |
5419 | */ | |
5420 | if (unlikely(0 == datalen)) { | |
5421 | err = sctp_make_abort_no_data(asoc, chunk, tsn); | |
5422 | if (err) { | |
5423 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, | |
5424 | SCTP_CHUNK(err)); | |
5425 | } | |
5426 | /* We are going to ABORT, so we might as well stop | |
5427 | * processing the rest of the chunks in the packet. | |
5428 | */ | |
5429 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); | |
8de8c873 SS |
5430 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
5431 | SCTP_ERROR(ECONNABORTED)); | |
1da177e4 | 5432 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
5be291fe | 5433 | SCTP_PERR(SCTP_ERROR_NO_DATA)); |
1da177e4 LT |
5434 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
5435 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); | |
5436 | return SCTP_IERROR_NO_DATA; | |
5437 | } | |
5438 | ||
5439 | /* If definately accepting the DATA chunk, record its TSN, otherwise | |
5440 | * wait for renege processing. | |
5441 | */ | |
5442 | if (SCTP_CMD_CHUNK_ULP == deliver) | |
5443 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn)); | |
5444 | ||
9faa730f SS |
5445 | chunk->data_accepted = 1; |
5446 | ||
1da177e4 LT |
5447 | /* Note: Some chunks may get overcounted (if we drop) or overcounted |
5448 | * if we renege and the chunk arrives again. | |
5449 | */ | |
5450 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) | |
5451 | SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS); | |
5452 | else | |
5453 | SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS); | |
5454 | ||
5455 | /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number | |
5456 | * | |
5457 | * If an endpoint receive a DATA chunk with an invalid stream | |
5458 | * identifier, it shall acknowledge the reception of the DATA chunk | |
5459 | * following the normal procedure, immediately send an ERROR chunk | |
5460 | * with cause set to "Invalid Stream Identifier" (See Section 3.3.10) | |
5461 | * and discard the DATA chunk. | |
5462 | */ | |
5463 | if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) { | |
5464 | err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM, | |
5465 | &data_hdr->stream, | |
5466 | sizeof(data_hdr->stream)); | |
5467 | if (err) | |
5468 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, | |
5469 | SCTP_CHUNK(err)); | |
5470 | return SCTP_IERROR_BAD_STREAM; | |
5471 | } | |
5472 | ||
5473 | /* Send the data up to the user. Note: Schedule the | |
5474 | * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK | |
5475 | * chunk needs the updated rwnd. | |
5476 | */ | |
5477 | sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk)); | |
5478 | ||
5479 | return SCTP_IERROR_NO_ERROR; | |
5480 | } |