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