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