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