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