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