blob: 7c753a2ffd747d3743c6c62310557804ddaa7a61 [file] [log] [blame]
Marco Varlese191a5942017-10-30 18:17:21 +01001/*
2 * Copyright (c) 2017 SUSE LLC.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include <vppinfra/sparse_vec.h>
16#include <vnet/sctp/sctp.h>
17#include <vnet/sctp/sctp_packet.h>
18#include <vnet/sctp/sctp_debug.h>
19#include <vnet/session/session.h>
20#include <math.h>
21
22static char *sctp_error_strings[] = {
23#define sctp_error(n,s) s,
24#include <vnet/sctp/sctp_error.def>
25#undef sctp_error
26};
27
28/* All SCTP nodes have the same outgoing arcs */
29#define foreach_sctp_state_next \
Marco Varlesefae40392018-02-14 15:38:35 +010030 _ (DROP4, "ip4-drop") \
31 _ (DROP6, "ip6-drop") \
Marco Varlese191a5942017-10-30 18:17:21 +010032 _ (SCTP4_OUTPUT, "sctp4-output") \
33 _ (SCTP6_OUTPUT, "sctp6-output")
34
35typedef enum _sctp_established_phase_next
36{
37#define _(s,n) SCTP_ESTABLISHED_PHASE_NEXT_##s,
38 foreach_sctp_state_next
39#undef _
40 SCTP_ESTABLISHED_PHASE_N_NEXT,
41} sctp_established_phase_next_t;
42
43typedef enum _sctp_rcv_phase_next
44{
45#define _(s,n) SCTP_RCV_PHASE_NEXT_##s,
46 foreach_sctp_state_next
47#undef _
48 SCTP_RCV_PHASE_N_NEXT,
49} sctp_rcv_phase_next_t;
50
51typedef enum _sctp_listen_phase_next
52{
53#define _(s,n) SCTP_LISTEN_PHASE_NEXT_##s,
54 foreach_sctp_state_next
55#undef _
56 SCTP_LISTEN_PHASE_N_NEXT,
57} sctp_listen_phase_next_t;
58
59typedef enum _sctp_shutdown_phase_next
60{
61#define _(s,n) SCTP_SHUTDOWN_PHASE_NEXT_##s,
62 foreach_sctp_state_next
63#undef _
64 SCTP_SHUTDOWN_PHASE_N_NEXT,
65} sctp_shutdown_phase_next_t;
66
67/* Generic, state independent indices */
68typedef enum _sctp_state_next
69{
70#define _(s,n) SCTP_NEXT_##s,
71 foreach_sctp_state_next
72#undef _
73 SCTP_STATE_N_NEXT,
74} sctp_state_next_t;
75
76typedef enum _sctp_input_next
77{
78 SCTP_INPUT_NEXT_DROP,
79 SCTP_INPUT_NEXT_LISTEN_PHASE,
80 SCTP_INPUT_NEXT_RCV_PHASE,
81 SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
82 SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
83 SCTP_INPUT_NEXT_PUNT_PHASE,
84 SCTP_INPUT_N_NEXT
85} sctp_input_next_t;
86
87char *
88phase_to_string (u8 phase)
89{
90 switch (phase)
91 {
92 case SCTP_INPUT_NEXT_DROP:
93 return "SCTP_INPUT_NEXT_DROP";
94 case SCTP_INPUT_NEXT_LISTEN_PHASE:
95 return "SCTP_INPUT_NEXT_LISTEN_PHASE";
96 case SCTP_INPUT_NEXT_RCV_PHASE:
97 return "SCTP_INPUT_NEXT_RCV_PHASE";
98 case SCTP_INPUT_NEXT_ESTABLISHED_PHASE:
99 return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
100 case SCTP_INPUT_NEXT_SHUTDOWN_PHASE:
101 return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
102 case SCTP_INPUT_NEXT_PUNT_PHASE:
103 return "SCTP_INPUT_NEXT_PUNT_PHASE";
104 }
105 return NULL;
106}
107
108#define foreach_sctp4_input_next \
109 _ (DROP, "error-drop") \
110 _ (RCV_PHASE, "sctp4-rcv") \
111 _ (LISTEN_PHASE, "sctp4-listen") \
112 _ (ESTABLISHED_PHASE, "sctp4-established") \
113 _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
114 _ (PUNT_PHASE, "ip4-punt")
115
116
117#define foreach_sctp6_input_next \
118 _ (DROP, "error-drop") \
119 _ (RCV_PHASE, "sctp6-rcv") \
120 _ (LISTEN_PHASE, "sctp6-listen") \
121 _ (ESTABLISHED_PHASE, "sctp6-established") \
122 _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
123 _ (PUNT_PHASE, "ip6-punt")
124
125static u8
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100126sctp_lookup_is_valid (transport_connection_t * trans_conn,
Marco Varlese191a5942017-10-30 18:17:21 +0100127 sctp_header_t * sctp_hdr)
128{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100129 sctp_connection_t *sctp_conn =
130 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100131
132 if (!sctp_conn)
133 return 1;
134
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100135 u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
Marco Varlese191a5942017-10-30 18:17:21 +0100136 && (sctp_conn->state == SCTP_STATE_CLOSED
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100137 || trans_conn->rmt_port == sctp_hdr->src_port));
Marco Varlese191a5942017-10-30 18:17:21 +0100138
139 return is_valid;
140}
141
142/**
143 * Lookup transport connection
144 */
145static sctp_connection_t *
146sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
147 u8 is_ip4)
148{
149 sctp_main_t *tm = vnet_get_sctp_main ();
150 sctp_header_t *sctp_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100151 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100152 sctp_connection_t *sctp_conn;
153 u8 is_filtered, i;
154 if (is_ip4)
155 {
156 ip4_header_t *ip4_hdr;
157 ip4_hdr = vlib_buffer_get_current (b);
158 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100159 trans_conn = session_lookup_connection_wt4 (fib_index,
160 &ip4_hdr->dst_address,
161 &ip4_hdr->src_address,
162 sctp_hdr->dst_port,
163 sctp_hdr->src_port,
164 TRANSPORT_PROTO_SCTP,
165 thread_index, &is_filtered);
166 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100167 {
168 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
169 {
170 if ((tm->connections[thread_index]->sub_conn[i].
171 connection.lcl_ip.ip4.as_u32 ==
172 ip4_hdr->dst_address.as_u32)
173 && (tm->connections[thread_index]->sub_conn[i].
174 connection.rmt_ip.ip4.as_u32 ==
175 ip4_hdr->src_address.as_u32))
176 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100177 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100178 &tm->connections[thread_index]->sub_conn[i].connection;
179 break;
180 }
181 }
182 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100183 ASSERT (trans_conn != 0);
184 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100185 }
186 else
187 {
188 ip6_header_t *ip6_hdr;
189 ip6_hdr = vlib_buffer_get_current (b);
190 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100191 trans_conn = session_lookup_connection_wt6 (fib_index,
192 &ip6_hdr->dst_address,
193 &ip6_hdr->src_address,
194 sctp_hdr->dst_port,
195 sctp_hdr->src_port,
196 TRANSPORT_PROTO_SCTP,
197 thread_index, &is_filtered);
198 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100199 {
200 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
201 {
202 if ((tm->connections[thread_index]->sub_conn[i].
203 connection.lcl_ip.ip6.as_u64[0] ==
204 ip6_hdr->dst_address.as_u64[0]
205 && tm->connections[thread_index]->sub_conn[i].
206 connection.lcl_ip.ip6.as_u64[1] ==
207 ip6_hdr->dst_address.as_u64[1])
208 && (tm->connections[thread_index]->sub_conn[i].
209 connection.rmt_ip.ip6.as_u64[0] ==
210 ip6_hdr->src_address.as_u64[0]
211 && tm->connections[thread_index]->
212 sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
213 ip6_hdr->src_address.as_u64[1]))
214 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100215 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100216 &tm->connections[thread_index]->sub_conn[i].connection;
217 break;
218 }
219 }
220 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100221 ASSERT (trans_conn != 0);
222 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100223 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100224 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100225 return sctp_conn;
226}
227
228typedef struct
229{
230 sctp_header_t sctp_header;
231 sctp_connection_t sctp_connection;
232} sctp_rx_trace_t;
233
234#define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
235 : SCTP_NEXT_SCTP6_OUTPUT)
236
Marco Varlesefae40392018-02-14 15:38:35 +0100237#define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
238 : SCTP_NEXT_DROP6)
Marco Varlese191a5942017-10-30 18:17:21 +0100239
240void
241sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
242 sctp_connection_t * sctp_conn,
243 sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
244 u8 is_ip4)
245{
246 if (sctp_conn)
247 {
248 clib_memcpy (&rx_trace->sctp_connection, sctp_conn,
249 sizeof (rx_trace->sctp_connection));
250 }
251 else
252 {
253 sctp_hdr = sctp_buffer_hdr (b0);
254 }
255 clib_memcpy (&rx_trace->sctp_header, sctp_hdr,
256 sizeof (rx_trace->sctp_header));
257}
258
259always_inline u16
260sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
261 int is_ip4)
262{
263 u16 sctp_implied_packet_length = 0;
264
265 if (is_ip4)
266 sctp_implied_packet_length =
267 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
268 else
269 sctp_implied_packet_length =
270 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
271
272 return sctp_implied_packet_length;
273}
274
275always_inline u8
276sctp_is_bundling (u16 sctp_implied_length,
277 sctp_chunks_common_hdr_t * sctp_common_hdr)
278{
279 if (sctp_implied_length !=
280 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
281 return 1;
282 return 0;
283}
284
285always_inline u16
Marco Varlese200fa322018-02-26 16:33:54 +0100286sctp_handle_operation_err (sctp_header_t * sctp_hdr,
287 sctp_connection_t * sctp_conn, u8 idx,
288 vlib_buffer_t * b, u16 * next0)
289{
290 sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
291
292 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
293 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
294 {
295 return SCTP_ERROR_INVALID_TAG;
296 }
297
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100298 if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
299 STALE_COOKIE_ERROR)
Marco Varlese200fa322018-02-26 16:33:54 +0100300 {
301 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
302 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
303 else
304 {
305 sctp_connection_cleanup (sctp_conn);
306
307 stream_session_disconnect_notify (&sctp_conn->
308 sub_conn[idx].connection);
309 }
310 }
311
312 return SCTP_ERROR_NONE;
313}
314
315always_inline u16
Marco Varlese191a5942017-10-30 18:17:21 +0100316sctp_handle_init (sctp_header_t * sctp_hdr,
317 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
318 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
319 u16 sctp_implied_length)
320{
321 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +0200322 ip4_address_t ip4_addr;
323 ip6_address_t ip6_addr;
324 u8 add_ip4 = 0;
325 u8 add_ip6 = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100326 char hostname[FQDN_MAX_LENGTH];
327
328 /* Check the current state of the connection
329 *
330 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
331 * in the code below and by the "sctp_prepare_initack_chunk" function.
332 * However, for debugging purposes it is nice to have a message printed out
333 * for these corner-case scenarios.
334 */
335 if (sctp_conn->state != SCTP_STATE_CLOSED)
336 { /* UNEXPECTED scenario */
337 switch (sctp_conn->state)
338 {
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100339 case SCTP_STATE_COOKIE_WAIT:
Marco Varlese191a5942017-10-30 18:17:21 +0100340 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100341 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100342 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200343 b0, &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100344 return SCTP_ERROR_NONE;
345 case SCTP_STATE_COOKIE_ECHOED:
346 case SCTP_STATE_SHUTDOWN_ACK_SENT:
Marco Varlese191a5942017-10-30 18:17:21 +0100347 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100348 if (sctp_conn->forming_association_changed == 0)
349 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100350 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200351 b0, &ip4_addr,
352 &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100353 else
354 sctp_prepare_abort_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100355 SCTP_PRIMARY_PATH_IDX, b0,
Marco Varlese216c35b2018-04-17 16:41:51 +0200356 &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100357 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100358 }
359 }
360
361 if (sctp_hdr->verification_tag != 0x0)
362 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
363
364 /*
365 * It is not possible to bundle any other CHUNK with the INIT chunk
366 */
367 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
368 return SCTP_ERROR_BUNDLING_VIOLATION;
369
370 /* Save the INITIATE_TAG of the remote peer for this connection:
371 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
372 sctp_conn->remote_tag = init_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100373 sctp_conn->remote_initial_tsn =
374 clib_net_to_host_u32 (init_chunk->initial_tsn);
375 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
376 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
377 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
378 sctp_conn->remote_initial_tsn);
379
Marco Varlese9e09ff32018-03-05 12:31:45 +0100380 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100381 /*
382 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
383 * optional parameters have been sent with the INIT chunk and we need to parse them.
384 */
385 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
386 if (length > sizeof (sctp_init_chunk_t))
387 {
388 /* There are optional parameters in the INIT chunk */
389 u16 pointer_offset = sizeof (sctp_init_chunk_t);
390 while (pointer_offset < length)
391 {
392 sctp_opt_params_hdr_t *opt_params_hdr =
393 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
394
395 switch (clib_net_to_host_u16 (opt_params_hdr->type))
396 {
397 case SCTP_IPV4_ADDRESS_TYPE:
398 {
399 sctp_ipv4_addr_param_t *ipv4 =
400 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese216c35b2018-04-17 16:41:51 +0200401 clib_memcpy (&ip4_addr, &ipv4->address,
Marco Varlese191a5942017-10-30 18:17:21 +0100402 sizeof (ip4_address_t));
403
Marco Varlese216c35b2018-04-17 16:41:51 +0200404 if (sctp_sub_connection_add_ip4 (vlib_get_main (),
405 &sctp_conn->sub_conn
406 [SCTP_PRIMARY_PATH_IDX].connection.
407 lcl_ip.ip4,
408 &ipv4->address) ==
409 SCTP_ERROR_NONE)
410 add_ip4 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100411
412 break;
413 }
414 case SCTP_IPV6_ADDRESS_TYPE:
415 {
416 sctp_ipv6_addr_param_t *ipv6 =
417 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese216c35b2018-04-17 16:41:51 +0200418 clib_memcpy (&ip6_addr, &ipv6->address,
Marco Varlese191a5942017-10-30 18:17:21 +0100419 sizeof (ip6_address_t));
420
Marco Varlese216c35b2018-04-17 16:41:51 +0200421 if (sctp_sub_connection_add_ip6 (vlib_get_main (),
422 &sctp_conn->sub_conn
423 [SCTP_PRIMARY_PATH_IDX].connection.
424 lcl_ip.ip6,
425 &ipv6->address) ==
426 SCTP_ERROR_NONE)
427 add_ip6 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100428
429 break;
430 }
431 case SCTP_COOKIE_PRESERVATIVE_TYPE:
432 {
433 sctp_cookie_preservative_param_t *cookie_pres =
434 (sctp_cookie_preservative_param_t *) opt_params_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100435 sctp_conn->peer_cookie_life_span_increment =
436 cookie_pres->life_span_inc;
Marco Varlese191a5942017-10-30 18:17:21 +0100437 break;
438 }
439 case SCTP_HOSTNAME_ADDRESS_TYPE:
440 {
441 sctp_hostname_param_t *hostname_addr =
442 (sctp_hostname_param_t *) opt_params_hdr;
443 clib_memcpy (hostname, hostname_addr->hostname,
444 FQDN_MAX_LENGTH);
445 break;
446 }
447 case SCTP_SUPPORTED_ADDRESS_TYPES:
448 {
449 /* TODO */
450 break;
451 }
452 }
453 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
454 }
455 }
456
457 /* Reuse buffer to make init-ack and send */
Marco Varlese216c35b2018-04-17 16:41:51 +0200458 sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
459 add_ip4, &ip6_addr, add_ip6);
Marco Varlese191a5942017-10-30 18:17:21 +0100460 return SCTP_ERROR_NONE;
461}
462
463always_inline u16
464sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
465 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
466 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
467 u16 sctp_implied_length)
468{
469 sctp_init_ack_chunk_t *init_ack_chunk =
470 (sctp_init_ack_chunk_t *) (sctp_hdr);
471
472 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
473 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
474 {
475 return SCTP_ERROR_INVALID_TAG;
476 }
477
478 /*
479 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
480 */
481 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
482 return SCTP_ERROR_BUNDLING_VIOLATION;
483
484 return SCTP_ERROR_NONE;
485}
486
487always_inline u16
488sctp_handle_init_ack (sctp_header_t * sctp_hdr,
489 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100490 sctp_connection_t * sctp_conn, u8 idx,
491 vlib_buffer_t * b0, u16 sctp_implied_length)
Marco Varlese191a5942017-10-30 18:17:21 +0100492{
493 sctp_init_ack_chunk_t *init_ack_chunk =
494 (sctp_init_ack_chunk_t *) (sctp_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100495 sctp_state_cookie_param_t state_cookie;
496
497 char hostname[FQDN_MAX_LENGTH];
498
499 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
500 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
501 {
502 return SCTP_ERROR_INVALID_TAG;
503 }
504
505 /*
506 * It is not possible to bundle any other CHUNK with the INIT chunk
507 */
508 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
509 return SCTP_ERROR_BUNDLING_VIOLATION;
510
Marco Varlese9e09ff32018-03-05 12:31:45 +0100511 /* Stop the T1_INIT timer */
512 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
513
Marco Varlese21c8baf2018-02-02 17:17:51 +0100514 sctp_calculate_rto (sctp_conn, idx);
515
Marco Varlese191a5942017-10-30 18:17:21 +0100516 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
517 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100518 sctp_conn->remote_initial_tsn =
519 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
520 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
521 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
522 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
523 sctp_conn->remote_initial_tsn);
Marco Varlese9e09ff32018-03-05 12:31:45 +0100524 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100525
526 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
527
528 if (length > sizeof (sctp_init_ack_chunk_t))
529 /*
530 * There are optional parameters in the INIT ACK chunk
531 */
532 {
533 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
534
535 while (pointer_offset < length)
536 {
537 sctp_opt_params_hdr_t *opt_params_hdr =
538 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
539 pointer_offset);
540
541 switch (clib_net_to_host_u16 (opt_params_hdr->type))
542 {
543 case SCTP_IPV4_ADDRESS_TYPE:
544 {
545 sctp_ipv4_addr_param_t *ipv4 =
546 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100547
Marco Varlese3c6a9762018-03-01 11:19:59 +0100548 sctp_sub_connection_add_ip4 (vlib_get_main (),
549 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100550 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100551 lcl_ip.ip4, &ipv4->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100552
553 break;
554 }
555 case SCTP_IPV6_ADDRESS_TYPE:
556 {
557 sctp_ipv6_addr_param_t *ipv6 =
558 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100559
Marco Varlese3c6a9762018-03-01 11:19:59 +0100560 sctp_sub_connection_add_ip6 (vlib_get_main (),
561 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100562 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100563 lcl_ip.ip6, &ipv6->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100564
565 break;
566 }
567 case SCTP_STATE_COOKIE_TYPE:
568 {
569 sctp_state_cookie_param_t *state_cookie_param =
570 (sctp_state_cookie_param_t *) opt_params_hdr;
571
572 clib_memcpy (&state_cookie, state_cookie_param,
573 sizeof (sctp_state_cookie_param_t));
574 break;
575 }
576 case SCTP_HOSTNAME_ADDRESS_TYPE:
577 {
578 sctp_hostname_param_t *hostname_addr =
579 (sctp_hostname_param_t *) opt_params_hdr;
580 clib_memcpy (hostname, hostname_addr->hostname,
581 FQDN_MAX_LENGTH);
582 break;
583 }
584 case SCTP_UNRECOGNIZED_TYPE:
585 {
586 break;
587 }
588 }
589 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
590 /* This indicates something really bad happened */
591 if (increment == 0)
592 {
593 return SCTP_ERROR_INVALID_TAG;
594 }
595 pointer_offset += increment;
596 }
597 }
598
Marco Varlese9e09ff32018-03-05 12:31:45 +0100599 clib_memcpy (&(sctp_conn->cookie_param), &state_cookie,
600 sizeof (sctp_state_cookie_param_t));
601
602 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100603
604 /* Start the T1_COOKIE timer */
Marco Varlese54432f82018-02-15 17:01:56 +0100605 sctp_timer_set (sctp_conn, idx,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100606 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
Marco Varlese191a5942017-10-30 18:17:21 +0100607
608 return SCTP_ERROR_NONE;
609}
610
Marco Varlese91389ac2018-01-31 11:00:01 +0100611/** Enqueue data out-of-order for delivery to application */
612always_inline int
613sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
614 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
615{
616 int written, error = SCTP_ERROR_ENQUEUED;
617
618 written =
619 session_enqueue_stream_connection (&sctp_conn->
620 sub_conn[conn_idx].connection, b, 0,
621 1 /* queue event */ ,
622 0);
623
624 /* Update next_tsn_expected */
625 if (PREDICT_TRUE (written == data_len))
626 {
627 sctp_conn->next_tsn_expected += written;
628
629 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
630 sctp_conn->sub_conn[conn_idx].connection.c_index,
631 written, data_len);
632 }
633 /* If more data written than expected, account for out-of-order bytes. */
634 else if (written > data_len)
635 {
636 sctp_conn->next_tsn_expected += written;
637
638 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
639 sctp_conn->sub_conn[conn_idx].connection.c_index,
640 written, data_len);
641 }
642 else if (written > 0)
643 {
644 /* We've written something but FIFO is probably full now */
645 sctp_conn->next_tsn_expected += written;
646
647 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
648
649 SCTP_ADV_DBG
650 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
651 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
652 }
653 else
654 {
655 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
656 sctp_conn->sub_conn[conn_idx].connection.c_index);
657
658 return SCTP_ERROR_FIFO_FULL;
659 }
660
661 /* TODO: Update out_of_order_map & SACK list */
662
663 return error;
664}
665
Marco Varlese191a5942017-10-30 18:17:21 +0100666/** Enqueue data for delivery to application */
667always_inline int
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100668sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100669 u16 data_len, u8 conn_idx)
670{
671 int written, error = SCTP_ERROR_ENQUEUED;
672
673 written =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100674 session_enqueue_stream_connection (&sctp_conn->
675 sub_conn[conn_idx].connection, b, 0,
676 1 /* queue event */ ,
677 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100678
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100679 /* Update next_tsn_expected */
Marco Varlese191a5942017-10-30 18:17:21 +0100680 if (PREDICT_TRUE (written == data_len))
681 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100682 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100683
684 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100685 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100686 written, data_len);
687 }
688 /* If more data written than expected, account for out-of-order bytes. */
689 else if (written > data_len)
690 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100691 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100692
693 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100694 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100695 written, data_len);
696 }
697 else if (written > 0)
698 {
699 /* We've written something but FIFO is probably full now */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100700 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100701
702 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
703
704 SCTP_ADV_DBG
705 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100706 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
Marco Varlese191a5942017-10-30 18:17:21 +0100707 }
708 else
709 {
710 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100711 sctp_conn->sub_conn[conn_idx].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100712
713 return SCTP_ERROR_FIFO_FULL;
714 }
715
716 return error;
717}
718
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100719always_inline u8
Marco Varlese54432f82018-02-15 17:01:56 +0100720sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100721{
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100722 if (sctp_conn->conn_config.never_delay_sack)
723 {
724 SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
725 return 0;
726 }
727
Marco Varlese9e09ff32018-03-05 12:31:45 +0100728 /* Section 4.4 of the RFC4960 */
729 if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
730 {
731 SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
732 sctp_state_to_string (sctp_conn->state));
733 return 0;
734 }
735
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100736 if (is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100737 {
738 SCTP_CONN_TRACKING_DBG
739 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
740 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100741 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100742 }
743
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100744 sctp_conn->ack_state += 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100745 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
746 {
747 SCTP_CONN_TRACKING_DBG
748 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
749 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100750 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100751 }
752
Marco Varlesea38783e2018-02-13 12:38:52 +0100753 return 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100754}
755
Marco Varlese91389ac2018-01-31 11:00:01 +0100756always_inline void
757sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
758 u8 * gapping)
759{
760 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
761 {
762 SCTP_CONN_TRACKING_DBG
763 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100764 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
Marco Varlese91389ac2018-01-31 11:00:01 +0100765 sctp_conn->next_tsn_expected, tsn,
766 sctp_conn->next_tsn_expected - tsn);
767
768 *gapping = 1;
769 }
770}
771
Marco Varlese191a5942017-10-30 18:17:21 +0100772always_inline u16
773sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100774 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100775 u16 * next0)
776{
777 u32 error = 0, n_data_bytes;
Marco Varlese91389ac2018-01-31 11:00:01 +0100778 u8 is_gapping = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100779
780 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
781 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
782 {
783 return SCTP_ERROR_INVALID_TAG;
784 }
785
786 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
787 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100788
789 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100790
791 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
792 n_data_bytes = vnet_buffer (b)->sctp.data_len;
793 ASSERT (n_data_bytes);
794
Marco Varlese91389ac2018-01-31 11:00:01 +0100795 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100796
797 sctp_conn->last_rcvd_tsn = tsn;
798
Marco Varlese191a5942017-10-30 18:17:21 +0100799 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
800
Marco Varlese91389ac2018-01-31 11:00:01 +0100801 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
802 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
803
804 if (bbit == 1 && ebit == 1) /* Unfragmented message */
805 {
806 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
807 * segments can be enqueued after fifo tail offset changes. */
Marco Varlese54432f82018-02-15 17:01:56 +0100808 if (PREDICT_FALSE (is_gapping == 1))
809 error =
810 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
811 else
812 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
Marco Varlese91389ac2018-01-31 11:00:01 +0100813 }
814 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
815 {
816 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
817 }
818 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
819 {
820 if (PREDICT_FALSE (is_gapping == 1))
821 error =
822 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
823 else
824 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
825 }
826 else /* Middle piece of a fragmented user message */
827 {
828 if (PREDICT_FALSE (is_gapping == 1))
829 error =
830 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
831 else
832 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
833 }
834 sctp_conn->last_rcvd_tsn = tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100835
Marco Varlese91389ac2018-01-31 11:00:01 +0100836 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
837
Marco Varlese54432f82018-02-15 17:01:56 +0100838 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100839 {
840 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
841 sctp_prepare_sack_chunk (sctp_conn, idx, b);
842 }
843 else
844 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese54432f82018-02-15 17:01:56 +0100845
846 sctp_conn->sub_conn[idx].enqueue_state = error;
Marco Varlese191a5942017-10-30 18:17:21 +0100847
848 return error;
849}
850
851always_inline u16
852sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
853 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100854 sctp_connection_t * sctp_conn, u8 idx,
855 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100856{
Marco Varlese21c8baf2018-02-02 17:17:51 +0100857 u32 now = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +0100858
Marco Varlese91389ac2018-01-31 11:00:01 +0100859 sctp_cookie_echo_chunk_t *cookie_echo =
860 (sctp_cookie_echo_chunk_t *) sctp_hdr;
861
Marco Varlese191a5942017-10-30 18:17:21 +0100862 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
863 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
864 {
865 return SCTP_ERROR_INVALID_TAG;
866 }
867
Marco Varlese21c8baf2018-02-02 17:17:51 +0100868 sctp_calculate_rto (sctp_conn, idx);
869
Marco Varlese91389ac2018-01-31 11:00:01 +0100870 u32 creation_time =
871 clib_net_to_host_u32 (cookie_echo->cookie.creation_time);
872 u32 cookie_lifespan =
873 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
874 if (now > creation_time + cookie_lifespan)
875 {
876 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
877 now, creation_time, cookie_lifespan);
878 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
879 }
880
Marco Varlese54432f82018-02-15 17:01:56 +0100881 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +0100882
883 /* Change state */
884 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100885 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
Marco Varlesebe2251b2018-02-07 12:22:41 +0100886 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100887
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100888 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
889 sctp_conn->sub_conn[idx].RTO);
890
Marco Varlese15cc6a82018-02-21 12:39:52 +0100891 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
892
Marco Varlese191a5942017-10-30 18:17:21 +0100893 return SCTP_ERROR_NONE;
894
895}
896
897always_inline u16
898sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
899 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100900 sctp_connection_t * sctp_conn, u8 idx,
901 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100902{
Marco Varlese191a5942017-10-30 18:17:21 +0100903 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
904 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
905 {
906 return SCTP_ERROR_INVALID_TAG;
907 }
908
Marco Varlese21c8baf2018-02-02 17:17:51 +0100909 sctp_calculate_rto (sctp_conn, idx);
910
Marco Varlese191a5942017-10-30 18:17:21 +0100911 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
912 /* Change state */
913 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100914 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
915
Marco Varlesefae40392018-02-14 15:38:35 +0100916 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100917
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100918 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
919 sctp_conn->sub_conn[idx].RTO);
920
Marco Varlese15cc6a82018-02-21 12:39:52 +0100921 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
922
Marco Varlese191a5942017-10-30 18:17:21 +0100923 return SCTP_ERROR_NONE;
924
925}
926
927always_inline uword
928sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
929 vlib_frame_t * from_frame, int is_ip4)
930{
931 sctp_main_t *tm = vnet_get_sctp_main ();
932
933 u32 n_left_from, next_index, *from, *to_next;
934 u32 my_thread_index = vm->thread_index;
935
936 from = vlib_frame_vector_args (from_frame);
937 n_left_from = from_frame->n_vectors;
938
939 next_index = node->cached_next_index;
940
941 while (n_left_from > 0)
942 {
943 u32 n_left_to_next;
944
945 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
946
947 while (n_left_from > 0 && n_left_to_next > 0)
948 {
949 u32 bi0;
950 vlib_buffer_t *b0;
951 sctp_header_t *sctp_hdr = 0;
952 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
953 ip4_header_t *ip4_hdr = 0;
954 ip6_header_t *ip6_hdr = 0;
955 sctp_connection_t *sctp_conn, *new_sctp_conn;
956 u16 sctp_implied_length = 0;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100957 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100958 u8 idx;
959
960 bi0 = from[0];
961 to_next[0] = bi0;
962 from += 1;
963 to_next += 1;
964 n_left_from -= 1;
965 n_left_to_next -= 1;
966
967 b0 = vlib_get_buffer (vm, bi0);
968
969 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
970 * will come from the half-open connections pool.
971 */
972 sctp_conn =
973 sctp_half_open_connection_get (vnet_buffer (b0)->
974 sctp.connection_index);
975
976 if (PREDICT_FALSE (sctp_conn == 0))
977 {
Marco Varlese191a5942017-10-30 18:17:21 +0100978 SCTP_ADV_DBG
979 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
980 error0 = SCTP_ERROR_INVALID_CONNECTION;
981 goto drop;
982 }
983 if (is_ip4)
984 {
985 ip4_hdr = vlib_buffer_get_current (b0);
986 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +0100987 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100988 }
989 else
990 {
991 ip6_hdr = vlib_buffer_get_current (b0);
992 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +0100993 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100994 }
Marco Varlese191a5942017-10-30 18:17:21 +0100995
Marco Varlese04e5d642018-02-23 17:43:06 +0100996 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100997 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
998
Marco Varlese191a5942017-10-30 18:17:21 +0100999 sctp_chunk_hdr =
1000 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1001
1002 sctp_implied_length =
1003 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1004
1005 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1006
1007 switch (chunk_type)
1008 {
1009 case INIT_ACK:
1010 error0 =
1011 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1012 b0, sctp_implied_length);
1013
1014 if (error0 == SCTP_ERROR_NONE)
1015 {
1016 pool_get (tm->connections[my_thread_index], new_sctp_conn);
1017 clib_memcpy (new_sctp_conn, sctp_conn,
1018 sizeof (*new_sctp_conn));
1019 new_sctp_conn->sub_conn[idx].c_c_index =
1020 new_sctp_conn - tm->connections[my_thread_index];
1021 new_sctp_conn->sub_conn[idx].c_thread_index =
1022 my_thread_index;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001023 new_sctp_conn->sub_conn[idx].PMTU =
1024 sctp_conn->sub_conn[idx].PMTU;
Marco Varlese04e5d642018-02-23 17:43:06 +01001025 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001026
1027 if (sctp_half_open_connection_cleanup (sctp_conn))
1028 {
1029 SCTP_DBG
1030 ("Cannot cleanup half-open connection; not the owning thread");
1031 }
1032
1033 sctp_connection_timers_init (new_sctp_conn);
1034
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001035 sctp_init_cwnd (new_sctp_conn);
1036
Marco Varlese191a5942017-10-30 18:17:21 +01001037 error0 =
1038 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +01001039 new_sctp_conn, idx, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001040 sctp_implied_length);
1041
Marco Varlese191a5942017-10-30 18:17:21 +01001042 if (session_stream_connect_notify
1043 (&new_sctp_conn->sub_conn[idx].connection, 0))
1044 {
1045 SCTP_DBG
1046 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1047 new_sctp_conn->sub_conn[idx].connection.c_index);
1048 sctp_connection_cleanup (new_sctp_conn);
1049 goto drop;
1050 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001051 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001052 }
Marco Varlese191a5942017-10-30 18:17:21 +01001053 break;
1054
Marco Varlese200fa322018-02-26 16:33:54 +01001055 case OPERATION_ERROR:
1056 error0 =
1057 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1058 &next0);
1059 break;
1060
Marco Varlese191a5942017-10-30 18:17:21 +01001061 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1062 * are handled by the input-dispatcher function using the table-lookup
1063 * hence we should never get to the "default" case below.
1064 */
1065 default:
1066 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001067 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001068 goto drop;
1069 }
1070
1071 if (error0 != SCTP_ERROR_NONE)
1072 {
1073 clib_warning ("error while parsing chunk");
1074 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001075 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001076 goto drop;
1077 }
1078
1079 drop:
1080 b0->error = node->errors[error0];
1081 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1082 {
1083 sctp_rx_trace_t *t0 =
1084 vlib_add_trace (vm, node, b0, sizeof (*t0));
1085 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1086 }
1087
1088 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1089 n_left_to_next, bi0, next0);
1090 }
1091
1092 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1093 }
1094 return from_frame->n_vectors;
1095}
1096
1097static uword
1098sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1099 vlib_frame_t * from_frame)
1100{
1101 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1102}
1103
1104static uword
1105sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1106 vlib_frame_t * from_frame)
1107{
1108 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1109}
1110
1111u8 *
1112format_sctp_rx_trace_short (u8 * s, va_list * args)
1113{
1114 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1115 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1116 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1117
1118 s = format (s, "%d -> %d (%U)",
1119 clib_net_to_host_u16 (t->sctp_header.src_port),
1120 clib_net_to_host_u16 (t->sctp_header.dst_port),
1121 format_sctp_state, t->sctp_connection.state);
1122
1123 return s;
1124}
1125
1126/* *INDENT-OFF* */
1127VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1128{
1129 .function = sctp4_rcv_phase,
1130 .name = "sctp4-rcv",
1131 /* Takes a vector of packets. */
1132 .vector_size = sizeof (u32),
1133 .n_errors = SCTP_N_ERROR,
1134 .error_strings = sctp_error_strings,
1135 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1136 .next_nodes =
1137 {
1138#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1139 foreach_sctp_state_next
1140#undef _
1141 },
1142 .format_trace = format_sctp_rx_trace_short,
1143};
1144/* *INDENT-ON* */
1145
1146VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1147
1148/* *INDENT-OFF* */
1149VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1150{
1151 .function = sctp6_rcv_phase,
1152 .name = "sctp6-rcv",
1153 /* Takes a vector of packets. */
1154 .vector_size = sizeof (u32),
1155 .n_errors = SCTP_N_ERROR,
1156 .error_strings = sctp_error_strings,
1157 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1158 .next_nodes =
1159 {
1160#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1161 foreach_sctp_state_next
1162#undef _
1163 },
1164 .format_trace = format_sctp_rx_trace_short,
1165};
1166/* *INDENT-ON* */
1167
1168VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1169
1170vlib_node_registration_t sctp4_shutdown_phase_node;
1171vlib_node_registration_t sctp6_shutdown_phase_node;
1172
1173always_inline u16
1174sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1175 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001176 sctp_connection_t * sctp_conn, u8 idx,
1177 vlib_buffer_t * b0, u16 sctp_implied_length,
1178 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001179{
1180 sctp_shutdown_association_chunk_t *shutdown_chunk =
1181 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1182
1183 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1184 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1185 {
1186 return SCTP_ERROR_INVALID_TAG;
1187 }
1188
1189 /*
1190 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1191 */
1192 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1193 return SCTP_ERROR_BUNDLING_VIOLATION;
1194
1195 switch (sctp_conn->state)
1196 {
1197 case SCTP_STATE_ESTABLISHED:
1198 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1199 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
Marco Varlese54432f82018-02-15 17:01:56 +01001200 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001201 break;
1202
1203 case SCTP_STATE_SHUTDOWN_SENT:
Marco Varlese54432f82018-02-15 17:01:56 +01001204 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001205 break;
1206 }
1207
Marco Varlesebe2251b2018-02-07 12:22:41 +01001208 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1209
Marco Varlese191a5942017-10-30 18:17:21 +01001210 return SCTP_ERROR_NONE;
1211}
1212
1213always_inline u16
1214sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1215 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001216 sctp_connection_t * sctp_conn, u8 idx,
1217 vlib_buffer_t * b0, u16 sctp_implied_length,
1218 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001219{
1220 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1221 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1222
1223 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1224 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1225 {
1226 return SCTP_ERROR_INVALID_TAG;
1227 }
1228
1229 /*
1230 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1231 */
1232 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1233 return SCTP_ERROR_BUNDLING_VIOLATION;
1234
1235 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1236 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1237 * - STOP T2_SHUTDOWN timer
1238 * - SEND SHUTDOWN_COMPLETE chunk
1239 */
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001240 sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
Marco Varlesea38783e2018-02-13 12:38:52 +01001241
Marco Varlese54432f82018-02-15 17:01:56 +01001242 sctp_send_shutdown_complete (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001243
Marco Varlesebe2251b2018-02-07 12:22:41 +01001244 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1245
Marco Varlese191a5942017-10-30 18:17:21 +01001246 return SCTP_ERROR_NONE;
1247}
1248
1249always_inline u16
1250sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1251 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001252 sctp_connection_t * sctp_conn, u8 idx,
1253 vlib_buffer_t * b0, u16 sctp_implied_length,
1254 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001255{
1256 sctp_shutdown_complete_chunk_t *shutdown_complete =
1257 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1258
1259 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1260 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1261 {
1262 return SCTP_ERROR_INVALID_TAG;
1263 }
1264
1265 /*
1266 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1267 */
1268 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1269 return SCTP_ERROR_BUNDLING_VIOLATION;
1270
Marco Varlesef3ab4892018-02-19 15:23:13 +01001271 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1272
1273 stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese191a5942017-10-30 18:17:21 +01001274
1275 sctp_conn->state = SCTP_STATE_CLOSED;
1276
Marco Varlesefae40392018-02-14 15:38:35 +01001277 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001278
Marco Varlese191a5942017-10-30 18:17:21 +01001279 return SCTP_ERROR_NONE;
1280}
1281
1282always_inline uword
1283sctp46_shutdown_phase_inline (vlib_main_t * vm,
1284 vlib_node_runtime_t * node,
1285 vlib_frame_t * from_frame, int is_ip4)
1286{
1287 u32 n_left_from, next_index, *from, *to_next;
1288 u32 my_thread_index = vm->thread_index;
1289
1290 from = vlib_frame_vector_args (from_frame);
1291 n_left_from = from_frame->n_vectors;
1292
1293 next_index = node->cached_next_index;
1294
1295 while (n_left_from > 0)
1296 {
1297 u32 n_left_to_next;
1298
1299 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1300
1301 while (n_left_from > 0 && n_left_to_next > 0)
1302 {
1303 u32 bi0;
1304 vlib_buffer_t *b0;
1305 sctp_rx_trace_t *sctp_trace;
1306 sctp_header_t *sctp_hdr = 0;
1307 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1308 ip4_header_t *ip4_hdr = 0;
1309 ip6_header_t *ip6_hdr = 0;
1310 sctp_connection_t *sctp_conn;
1311 u16 sctp_implied_length = 0;
1312 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
Marco Varlese54432f82018-02-15 17:01:56 +01001313 u8 idx = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001314
1315 bi0 = from[0];
1316 to_next[0] = bi0;
1317 from += 1;
1318 to_next += 1;
1319 n_left_from -= 1;
1320 n_left_to_next -= 1;
1321
1322 b0 = vlib_get_buffer (vm, bi0);
1323 sctp_conn =
1324 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1325 my_thread_index);
1326
1327 if (PREDICT_FALSE (sctp_conn == 0))
1328 {
1329 SCTP_DBG
1330 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1331 error0 = SCTP_ERROR_INVALID_CONNECTION;
1332 goto drop;
1333 }
1334
1335 if (is_ip4)
1336 {
1337 ip4_hdr = vlib_buffer_get_current (b0);
1338 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001339 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001340 }
1341 else
1342 {
1343 ip6_hdr = vlib_buffer_get_current (b0);
1344 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001345 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001346 }
1347
1348 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1349 sctp_chunk_hdr = &full_hdr->common_hdr;
1350
1351 sctp_implied_length =
1352 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1353
Marco Varlesebe2251b2018-02-07 12:22:41 +01001354 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1355 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001356 {
1357 case SHUTDOWN:
1358 error0 =
Marco Varlesebe2251b2018-02-07 12:22:41 +01001359 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1360 idx, b0, sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001361 break;
1362
1363 case SHUTDOWN_ACK:
1364 error0 =
1365 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001366 idx, b0, sctp_implied_length,
1367 &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001368 break;
1369
1370 case SHUTDOWN_COMPLETE:
1371 error0 =
1372 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001373 sctp_conn, idx, b0,
1374 sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001375
1376 sctp_connection_cleanup (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001377 break;
1378
1379 /*
1380 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1381 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1382 */
1383 case DATA:
1384 error0 =
1385 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001386 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001387 break;
1388
Marco Varlese200fa322018-02-26 16:33:54 +01001389 case OPERATION_ERROR:
1390 error0 =
1391 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1392 &next0);
1393 break;
1394
Marco Varlese8c5f67f2018-02-27 09:38:31 +01001395 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1396 sctp_prepare_operation_error (sctp_conn, idx, b0,
1397 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1398 error0 = SCTP_ERROR_NONE;
1399 next0 = sctp_next_output (is_ip4);
1400 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001401 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1402 * are handled by the input-dispatcher function using the table-lookup
1403 * hence we should never get to the "default" case below.
1404 */
1405 default:
1406 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001407 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001408 goto drop;
1409 }
1410
1411 if (error0 != SCTP_ERROR_NONE)
1412 {
1413 clib_warning ("error while parsing chunk");
1414 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001415 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001416 goto drop;
1417 }
1418
1419 drop:
1420 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1421 {
1422 sctp_trace =
1423 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
Marco Varlesef429a932018-02-06 17:31:06 +01001424
1425 if (sctp_hdr != NULL)
1426 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1427 sizeof (sctp_trace->sctp_header));
1428
1429 if (sctp_conn != NULL)
1430 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1431 sizeof (sctp_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001432 }
1433
1434 b0->error = node->errors[error0];
1435
1436 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1437 n_left_to_next, bi0, next0);
1438 }
1439
1440 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1441 }
1442
1443 return from_frame->n_vectors;
1444
1445}
1446
1447static uword
1448sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1449 vlib_frame_t * from_frame)
1450{
1451 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1452}
1453
1454static uword
1455sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1456 vlib_frame_t * from_frame)
1457{
1458 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1459}
1460
1461/* *INDENT-OFF* */
1462VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1463{
1464 .function = sctp4_shutdown_phase,
1465 .name = "sctp4-shutdown",
1466 /* Takes a vector of packets. */
1467 .vector_size = sizeof (u32),
1468 .n_errors = SCTP_N_ERROR,
1469 .error_strings = sctp_error_strings,
1470 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1471 .next_nodes =
1472 {
1473#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1474 foreach_sctp_state_next
1475#undef _
1476 },
1477 .format_trace = format_sctp_rx_trace_short,
1478};
1479/* *INDENT-ON* */
1480
1481VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1482 sctp4_shutdown_phase);
1483
1484/* *INDENT-OFF* */
1485VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1486{
1487 .function = sctp6_shutdown_phase,
1488 .name = "sctp6-shutdown",
1489 /* Takes a vector of packets. */
1490 .vector_size = sizeof (u32),
1491 .n_errors = SCTP_N_ERROR,
1492 .error_strings = sctp_error_strings,
1493 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1494 .next_nodes =
1495 {
1496#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1497 foreach_sctp_state_next
1498#undef _
1499 },
1500 .format_trace = format_sctp_rx_trace_short,
1501};
1502/* *INDENT-ON* */
1503
1504VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1505 sctp6_shutdown_phase);
1506
1507vlib_node_registration_t sctp4_listen_phase_node;
1508vlib_node_registration_t sctp6_listen_phase_node;
1509
1510vlib_node_registration_t sctp4_established_phase_node;
1511vlib_node_registration_t sctp6_established_phase_node;
1512
1513always_inline u16
1514sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001515 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001516 u16 * next0)
1517{
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001518
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001519 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1520 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1521 {
1522 return SCTP_ERROR_INVALID_TAG;
1523 }
1524
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001525 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1526
Marco Varlese54432f82018-02-15 17:01:56 +01001527 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1528
Marco Varlesef3ab4892018-02-19 15:23:13 +01001529 /* Section 7.2.2; point (2) */
1530 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1531 sctp_conn->sub_conn[idx].partially_acked_bytes =
1532 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1533
1534 /* Section 7.2.2; point (5) */
1535 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1536 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1537
1538 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1539
Marco Varlese21c8baf2018-02-02 17:17:51 +01001540 sctp_calculate_rto (sctp_conn, idx);
1541
1542 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1543 sctp_conn->sub_conn[idx].RTO);
1544
1545 sctp_conn->sub_conn[idx].RTO_pending = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001546
Marco Varlesefae40392018-02-14 15:38:35 +01001547 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001548
1549 return SCTP_ERROR_NONE;
1550}
1551
1552always_inline u16
1553sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001554 sctp_connection_t * sctp_conn, u8 idx,
1555 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001556{
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001557 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1558 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1559 {
1560 return SCTP_ERROR_INVALID_TAG;
1561 }
1562
Marco Varlese54432f82018-02-15 17:01:56 +01001563 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001564
1565 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1566
Marco Varlese191a5942017-10-30 18:17:21 +01001567 return SCTP_ERROR_NONE;
1568}
1569
1570always_inline u16
1571sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001572 sctp_connection_t * sctp_conn, u8 idx,
1573 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001574{
Marco Varlese54432f82018-02-15 17:01:56 +01001575 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1576
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001577 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1578
1579 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1580 sctp_conn->sub_conn[idx].RTO);
1581
Marco Varlesefae40392018-02-14 15:38:35 +01001582 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001583
Marco Varlese191a5942017-10-30 18:17:21 +01001584 return SCTP_ERROR_NONE;
1585}
1586
1587always_inline void
Marco Varlese3c6a9762018-03-01 11:19:59 +01001588sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
Marco Varlese191a5942017-10-30 18:17:21 +01001589 u8 is_ip4, u8 evt, u8 val)
1590{
1591 if (PREDICT_TRUE (!val))
1592 return;
1593
1594 if (is_ip4)
Marco Varlese3c6a9762018-03-01 11:19:59 +01001595 vlib_node_increment_counter (vm, sctp4_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001596 else
Marco Varlese3c6a9762018-03-01 11:19:59 +01001597 vlib_node_increment_counter (vm, sctp6_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001598}
1599
1600always_inline uword
1601sctp46_listen_process_inline (vlib_main_t * vm,
1602 vlib_node_runtime_t * node,
1603 vlib_frame_t * from_frame, int is_ip4)
1604{
1605 u32 n_left_from, next_index, *from, *to_next;
1606 u32 my_thread_index = vm->thread_index;
1607
1608 from = vlib_frame_vector_args (from_frame);
1609 n_left_from = from_frame->n_vectors;
1610
1611 next_index = node->cached_next_index;
1612
1613 while (n_left_from > 0)
1614 {
1615 u32 n_left_to_next;
1616
1617 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1618
1619 while (n_left_from > 0 && n_left_to_next > 0)
1620 {
1621 u32 bi0;
1622 vlib_buffer_t *b0;
1623 sctp_header_t *sctp_hdr = 0;
1624 ip4_header_t *ip4_hdr;
1625 ip6_header_t *ip6_hdr;
1626 sctp_connection_t *child_conn;
1627 sctp_connection_t *sctp_listener;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001628 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
Marco Varlese191a5942017-10-30 18:17:21 +01001629
1630 bi0 = from[0];
1631 to_next[0] = bi0;
1632 from += 1;
1633 to_next += 1;
1634 n_left_from -= 1;
1635 n_left_to_next -= 1;
1636
1637 b0 = vlib_get_buffer (vm, bi0);
1638 sctp_listener =
1639 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1640
1641 if (is_ip4)
1642 {
1643 ip4_hdr = vlib_buffer_get_current (b0);
1644 sctp_hdr = ip4_next_header (ip4_hdr);
1645 }
1646 else
1647 {
1648 ip6_hdr = vlib_buffer_get_current (b0);
1649 sctp_hdr = ip6_next_header (ip6_hdr);
1650 }
1651
1652 child_conn =
1653 sctp_lookup_connection (sctp_listener->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001654 [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001655 my_thread_index, is_ip4);
1656
1657 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1658 {
1659 SCTP_DBG
1660 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001661 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001662 connection.c_index,
1663 sctp_state_to_string (child_conn->state));
1664 error0 = SCTP_ERROR_CREATE_EXISTS;
1665 goto drop;
1666 }
1667
1668 /* Create child session and send SYN-ACK */
1669 child_conn = sctp_connection_new (my_thread_index);
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001670 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1671 SCTP_PRIMARY_PATH_IDX;
1672 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001673 sctp_hdr->dst_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001674 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001675 sctp_hdr->src_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001676 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1677 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1678 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1679 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1680 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
Marco Varlese191a5942017-10-30 18:17:21 +01001681 child_conn->state = SCTP_STATE_CLOSED;
Marco Varlesee17bb712018-03-28 12:06:10 +02001682 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1683 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1684 connection.fib_index;
Marco Varlese191a5942017-10-30 18:17:21 +01001685
1686 if (is_ip4)
1687 {
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001688 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001689 ip4_hdr->dst_address.as_u32;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001690 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001691 ip4_hdr->src_address.as_u32;
1692 }
1693 else
1694 {
1695 clib_memcpy (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001696 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
Marco Varlese191a5942017-10-30 18:17:21 +01001697 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1698 clib_memcpy (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001699 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
Marco Varlese191a5942017-10-30 18:17:21 +01001700 &ip6_hdr->src_address, sizeof (ip6_address_t));
1701 }
1702
1703 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1704 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1705
1706 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +02001707 if (chunk_type != INIT && chunk_type != DATA
1708 && chunk_type != OPERATION_ERROR)
Marco Varlese191a5942017-10-30 18:17:21 +01001709 {
1710 SCTP_DBG
1711 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001712 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001713 connection.c_index, sctp_chunk_to_string (chunk_type));
1714
1715 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001716 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001717 goto drop;
1718 }
1719
1720 u16 sctp_implied_length =
1721 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1722
1723 switch (chunk_type)
1724 {
1725 case INIT:
1726 sctp_connection_timers_init (child_conn);
1727
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001728 sctp_init_snd_vars (child_conn);
1729
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001730 sctp_init_cwnd (child_conn);
1731
Marco Varlese191a5942017-10-30 18:17:21 +01001732 error0 =
1733 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1734 sctp_implied_length);
1735
Marco Varlese191a5942017-10-30 18:17:21 +01001736 if (error0 == SCTP_ERROR_NONE)
1737 {
1738 if (stream_session_accept
1739 (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001740 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
Marco Varlese191a5942017-10-30 18:17:21 +01001741 sctp_listener->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001742 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
Marco Varlese191a5942017-10-30 18:17:21 +01001743 {
1744 clib_warning ("session accept fail");
1745 sctp_connection_cleanup (child_conn);
1746 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1747 goto drop;
1748 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001749 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001750 }
Marco Varlese191a5942017-10-30 18:17:21 +01001751 break;
1752
1753 /* Reception of a DATA chunk whilst in the CLOSED state is called
1754 * "Out of the Blue" packet and handling of the chunk needs special treatment
1755 * as per RFC4960 section 8.4
1756 */
1757 case DATA:
1758 break;
Marco Varlese200fa322018-02-26 16:33:54 +01001759
1760 case OPERATION_ERROR:
1761 error0 =
1762 sctp_handle_operation_err (sctp_hdr, child_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001763 SCTP_PRIMARY_PATH_IDX, b0, &next0);
Marco Varlese200fa322018-02-26 16:33:54 +01001764 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001765 }
1766
1767 drop:
1768 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1769 {
1770 sctp_rx_trace_t *t0 =
1771 vlib_add_trace (vm, node, b0, sizeof (*t0));
1772 clib_memcpy (&t0->sctp_header, sctp_hdr,
1773 sizeof (t0->sctp_header));
1774 clib_memcpy (&t0->sctp_connection, sctp_listener,
1775 sizeof (t0->sctp_connection));
1776 }
1777
1778 b0->error = node->errors[error0];
1779
1780 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1781 n_left_to_next, bi0, next0);
1782 }
1783 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1784
1785 }
1786 return from_frame->n_vectors;
1787}
1788
1789static uword
1790sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1791 vlib_frame_t * from_frame)
1792{
1793 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1794}
1795
1796static uword
1797sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1798 vlib_frame_t * from_frame)
1799{
1800 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1801}
1802
1803always_inline uword
1804sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1805 vlib_frame_t * from_frame, int is_ip4)
1806{
1807 u32 n_left_from, next_index, *from, *to_next;
1808 u32 my_thread_index = vm->thread_index, errors = 0;
1809
1810 from = vlib_frame_vector_args (from_frame);
1811 n_left_from = from_frame->n_vectors;
1812
1813 next_index = node->cached_next_index;
1814
1815 while (n_left_from > 0)
1816 {
1817 u32 n_left_to_next;
1818
1819 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1820
1821 while (n_left_from > 0 && n_left_to_next > 0)
1822 {
1823 u32 bi0;
1824 vlib_buffer_t *b0;
1825 sctp_header_t *sctp_hdr = 0;
1826 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1827 ip4_header_t *ip4_hdr = 0;
1828 ip6_header_t *ip6_hdr = 0;
1829 sctp_connection_t *sctp_conn;
Marco Varlesefae40392018-02-14 15:38:35 +01001830 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1831 SCTP_ESTABLISHED_PHASE_N_NEXT;
Marco Varlese191a5942017-10-30 18:17:21 +01001832 u8 idx;
1833
1834 bi0 = from[0];
1835 to_next[0] = bi0;
1836 from += 1;
1837 to_next += 1;
1838 n_left_from -= 1;
1839 n_left_to_next -= 1;
1840
1841 b0 = vlib_get_buffer (vm, bi0);
1842 sctp_conn =
1843 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1844 my_thread_index);
1845
1846 if (PREDICT_FALSE (sctp_conn == 0))
1847 {
1848 SCTP_DBG
1849 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1850 error0 = SCTP_ERROR_INVALID_CONNECTION;
1851 goto done;
1852 }
1853 if (is_ip4)
1854 {
1855 ip4_hdr = vlib_buffer_get_current (b0);
1856 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001857 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001858 }
1859 else
1860 {
1861 ip6_hdr = vlib_buffer_get_current (b0);
1862 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001863 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001864 }
1865
Marco Varlese04e5d642018-02-23 17:43:06 +01001866 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001867
Marco Varlese54432f82018-02-15 17:01:56 +01001868 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +01001869 sctp_chunk_hdr =
1870 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1871
1872 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1873
1874 switch (chunk_type)
1875 {
1876 case COOKIE_ECHO:
1877 error0 =
1878 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001879 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001880 break;
1881
1882 case COOKIE_ACK:
1883 error0 =
1884 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001885 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001886 break;
1887
1888 case SACK:
1889 error0 =
1890 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001891 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001892 break;
1893
1894 case HEARTBEAT:
1895 error0 =
1896 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001897 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001898 break;
1899
1900 case HEARTBEAT_ACK:
1901 error0 =
1902 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001903 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001904 break;
1905
1906 case DATA:
1907 error0 =
1908 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001909 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001910 break;
1911
Marco Varlese200fa322018-02-26 16:33:54 +01001912 case OPERATION_ERROR:
1913 error0 =
1914 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1915 &next0);
1916 break;
1917
Marco Varlese191a5942017-10-30 18:17:21 +01001918 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1919 * are handled by the input-dispatcher function using the table-lookup
1920 * hence we should never get to the "default" case below.
1921 */
1922 default:
1923 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001924 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001925 goto done;
1926 }
1927
1928 done:
1929 b0->error = node->errors[error0];
1930 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1931 {
1932 sctp_rx_trace_t *t0 =
1933 vlib_add_trace (vm, node, b0, sizeof (*t0));
1934 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1935 }
1936
1937 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1938 n_left_to_next, bi0, next0);
1939 }
1940
1941 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1942 }
1943
1944 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1945 my_thread_index);
1946
1947 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1948 sctp6_established_phase_node.index,
1949 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1950 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1951
1952 return from_frame->n_vectors;
1953}
1954
1955static uword
1956sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1957 vlib_frame_t * from_frame)
1958{
1959 return sctp46_established_phase_inline (vm, node, from_frame,
1960 1 /* is_ip4 */ );
1961}
1962
1963static uword
1964sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1965 vlib_frame_t * from_frame)
1966{
1967 return sctp46_established_phase_inline (vm, node, from_frame,
1968 0 /* is_ip4 */ );
1969}
1970
1971u8 *
1972format_sctp_rx_trace (u8 * s, va_list * args)
1973{
1974 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1975 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1976 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1977 u32 indent = format_get_indent (s);
1978
1979 s = format (s, "%U\n%U%U",
1980 format_sctp_header, &t->sctp_header, 128,
1981 format_white_space, indent,
1982 format_sctp_connection, &t->sctp_connection, 1);
1983
1984 return s;
1985}
1986
1987/* *INDENT-OFF* */
1988VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1989{
1990 .function = sctp4_listen_phase,
1991 .name = "sctp4-listen",
1992 /* Takes a vector of packets. */
1993 .vector_size = sizeof (u32),
1994 .n_errors = SCTP_N_ERROR,
1995 .error_strings = sctp_error_strings,
1996 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1997 .next_nodes =
1998 {
1999#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2000 foreach_sctp_state_next
2001#undef _
2002 },
2003 .format_trace = format_sctp_rx_trace_short,
2004};
2005/* *INDENT-ON* */
2006
2007VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
2008
2009/* *INDENT-OFF* */
2010VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
2011{
2012 .function = sctp6_listen_phase,
2013 .name = "sctp6-listen",
2014 /* Takes a vector of packets. */
2015 .vector_size = sizeof (u32),
2016 .n_errors = SCTP_N_ERROR,
2017 .error_strings = sctp_error_strings,
2018 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2019 .next_nodes =
2020 {
2021#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2022 foreach_sctp_state_next
2023#undef _
2024 },
2025 .format_trace = format_sctp_rx_trace_short,
2026};
2027/* *INDENT-ON* */
2028
2029VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
2030
2031/* *INDENT-OFF* */
2032VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2033{
2034 .function = sctp4_established_phase,
2035 .name = "sctp4-established",
2036 /* Takes a vector of packets. */
2037 .vector_size = sizeof (u32),
2038 .n_errors = SCTP_N_ERROR,
2039 .error_strings = sctp_error_strings,
2040 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2041 .next_nodes =
2042 {
2043#define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2044 foreach_sctp_state_next
2045#undef _
2046 },
2047 .format_trace = format_sctp_rx_trace_short,
2048};
2049/* *INDENT-ON* */
2050
2051VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
2052 sctp4_established_phase);
2053
2054/* *INDENT-OFF* */
2055VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2056{
2057 .function = sctp6_established_phase,
2058 .name = "sctp6-established",
2059 /* Takes a vector of packets. */
2060 .vector_size = sizeof (u32),
2061 .n_errors = SCTP_N_ERROR,
2062 .error_strings = sctp_error_strings,
2063 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2064 .next_nodes =
2065 {
2066#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2067 foreach_sctp_state_next
2068#undef _
2069 },
2070 .format_trace = format_sctp_rx_trace_short,
2071};
2072/* *INDENT-ON* */
2073
2074VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2075 sctp6_established_phase);
2076
2077/*
2078 * This is the function executed first for the SCTP graph.
2079 * It takes care of doing the initial message parsing and
2080 * dispatch to the specialized function.
2081 */
2082always_inline uword
2083sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2084 vlib_frame_t * from_frame, int is_ip4)
2085{
2086 u32 n_left_from, next_index, *from, *to_next;
2087 u32 my_thread_index = vm->thread_index;
2088 u8 is_filtered;
2089 sctp_main_t *tm = vnet_get_sctp_main ();
2090
2091 from = vlib_frame_vector_args (from_frame);
2092 n_left_from = from_frame->n_vectors;
2093 next_index = node->cached_next_index;
2094 sctp_set_time_now (my_thread_index);
2095
2096 while (n_left_from > 0)
2097 {
2098 u32 n_left_to_next;
2099
2100 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2101
2102 while (n_left_from > 0 && n_left_to_next > 0)
2103 {
2104 int n_advance_bytes0, n_data_bytes0;
2105 u32 bi0, fib_index0;
2106 vlib_buffer_t *b0;
2107 sctp_header_t *sctp_hdr = 0;
2108 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2109 sctp_connection_t *sctp_conn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002110 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01002111 ip4_header_t *ip4_hdr;
2112 ip6_header_t *ip6_hdr;
2113 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2114
2115 bi0 = from[0];
2116 to_next[0] = bi0;
2117 from += 1;
2118 to_next += 1;
2119 n_left_from -= 1;
2120 n_left_to_next -= 1;
2121
2122 b0 = vlib_get_buffer (vm, bi0);
Marco Varlese3c6a9762018-03-01 11:19:59 +01002123 vnet_buffer (b0)->sctp.flags = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01002124 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2125
2126 /* Checksum computed by ipx_local no need to compute again */
2127
2128 if (is_ip4)
2129 {
2130 ip4_hdr = vlib_buffer_get_current (b0);
2131 sctp_hdr = ip4_next_header (ip4_hdr);
2132
2133 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2134 sctp_chunk_hdr = &full_hdr->common_hdr;
2135
2136 n_advance_bytes0 =
2137 (ip4_header_bytes (ip4_hdr) +
2138 sizeof (sctp_payload_data_chunk_t));
2139 n_data_bytes0 =
2140 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2141
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002142 trans_conn = session_lookup_connection_wt4 (fib_index0,
2143 &ip4_hdr->dst_address,
2144 &ip4_hdr->src_address,
2145 sctp_hdr->dst_port,
2146 sctp_hdr->src_port,
2147 TRANSPORT_PROTO_SCTP,
2148 my_thread_index,
2149 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002150 }
2151 else
2152 {
2153 ip6_hdr = vlib_buffer_get_current (b0);
2154 sctp_hdr = ip6_next_header (ip6_hdr);
2155
2156 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2157 sctp_chunk_hdr = &full_hdr->common_hdr;
2158
2159 n_advance_bytes0 = sctp_header_bytes ();
2160 n_data_bytes0 =
2161 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2162 n_advance_bytes0;
2163 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2164
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002165 trans_conn = session_lookup_connection_wt6 (fib_index0,
2166 &ip6_hdr->dst_address,
2167 &ip6_hdr->src_address,
2168 sctp_hdr->dst_port,
2169 sctp_hdr->src_port,
2170 TRANSPORT_PROTO_SCTP,
2171 my_thread_index,
2172 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002173 }
2174
2175 /* Length check */
2176 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2177 {
2178 error0 = SCTP_ERROR_LENGTH;
2179 goto done;
2180 }
2181
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002182 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01002183 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2184
Marco Varlesefae40392018-02-14 15:38:35 +01002185 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2186 if (chunk_type >= UNKNOWN)
2187 {
2188 clib_warning
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002189 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2190
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002191 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002192 b0, UNRECOGNIZED_CHUNK_TYPE);
2193
Marco Varlesefae40392018-02-14 15:38:35 +01002194 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002195 next0 = sctp_next_output (is_ip4);
Marco Varlesefae40392018-02-14 15:38:35 +01002196 goto done;
2197 }
2198
Marco Varlese191a5942017-10-30 18:17:21 +01002199 vnet_buffer (b0)->sctp.hdr_offset =
2200 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2201
2202 /* Session exists */
2203 if (PREDICT_TRUE (0 != sctp_conn))
2204 {
2205 /* Save connection index */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002206 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
Marco Varlese191a5942017-10-30 18:17:21 +01002207 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2208 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2209
Marco Varlesefae40392018-02-14 15:38:35 +01002210 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2211 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
Marco Varlese191a5942017-10-30 18:17:21 +01002212
Marco Varlesef3ab4892018-02-19 15:23:13 +01002213 SCTP_DBG_STATE_MACHINE
Marco Varlese15cc6a82018-02-21 12:39:52 +01002214 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
Marco Varlesef3ab4892018-02-19 15:23:13 +01002215 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002216 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002217 connection.s_index,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002218 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002219 connection.c_index, trans_conn, sctp_conn,
2220 sctp_state_to_string (sctp_conn->state),
Marco Varlesef3ab4892018-02-19 15:23:13 +01002221 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
Marco Varlese191a5942017-10-30 18:17:21 +01002222
Marco Varlesefae40392018-02-14 15:38:35 +01002223 if (chunk_type == DATA)
Marco Varlese191a5942017-10-30 18:17:21 +01002224 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2225 n_advance_bytes0, n_data_bytes0);
2226
2227 }
2228 else
2229 {
2230 if (is_filtered)
2231 {
2232 next0 = SCTP_INPUT_NEXT_DROP;
2233 error0 = SCTP_ERROR_FILTERED;
2234 }
2235 else if ((is_ip4 && tm->punt_unknown4) ||
2236 (!is_ip4 && tm->punt_unknown6))
2237 {
2238 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2239 error0 = SCTP_ERROR_PUNT;
2240 }
2241 else
2242 {
2243 next0 = SCTP_INPUT_NEXT_DROP;
2244 error0 = SCTP_ERROR_NO_LISTENER;
2245 }
2246 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2247 phase_to_string (next0));
2248 sctp_conn = 0;
2249 }
2250
2251 done:
2252 b0->error = error0 ? node->errors[error0] : 0;
2253
2254 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2255 {
2256 sctp_rx_trace_t *t0 =
2257 vlib_add_trace (vm, node, b0, sizeof (*t0));
2258 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2259 }
2260 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2261 n_left_to_next, bi0, next0);
2262 }
2263
2264 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2265 }
2266 return from_frame->n_vectors;
2267}
2268
2269static uword
2270sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2271 vlib_frame_t * from_frame)
2272{
2273 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2274}
2275
2276static uword
2277sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2278 vlib_frame_t * from_frame)
2279{
2280 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2281}
2282
2283/* *INDENT-OFF* */
2284VLIB_REGISTER_NODE (sctp4_input_node) =
2285{
2286 .function = sctp4_input_dispatcher,
2287 .name = "sctp4-input",
2288 /* Takes a vector of packets. */
2289 .vector_size = sizeof (u32),
2290 .n_errors = SCTP_N_ERROR,
2291 .error_strings = sctp_error_strings,
2292 .n_next_nodes = SCTP_INPUT_N_NEXT,
2293 .next_nodes =
2294 {
2295#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2296 foreach_sctp4_input_next
2297#undef _
2298 },
2299 .format_buffer = format_sctp_header,
2300 .format_trace = format_sctp_rx_trace,
2301};
2302/* *INDENT-ON* */
2303
2304VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2305
2306/* *INDENT-OFF* */
2307VLIB_REGISTER_NODE (sctp6_input_node) =
2308{
2309 .function = sctp6_input_dispatcher,
2310 .name = "sctp6-input",
2311 /* Takes a vector of packets. */
2312 .vector_size = sizeof (u32),
2313 .n_errors = SCTP_N_ERROR,
2314 .error_strings = sctp_error_strings,
2315 .n_next_nodes = SCTP_INPUT_N_NEXT,
2316 .next_nodes =
2317 {
2318#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2319 foreach_sctp6_input_next
2320#undef _
2321 },
2322 .format_buffer = format_sctp_header,
2323 .format_trace = format_sctp_rx_trace,
2324};
2325/* *INDENT-ON* */
2326
2327VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2328
2329vlib_node_registration_t sctp4_input_node;
2330vlib_node_registration_t sctp6_input_node;
2331
2332static void
2333sctp_dispatch_table_init (sctp_main_t * tm)
2334{
2335 int i, j;
2336 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2337 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2338 {
2339 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2340 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2341 }
2342
2343#define _(t,f,n,e) \
2344do { \
2345 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2346 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2347} while (0)
2348
2349 /*
2350 * SCTP STATE-MACHINE states:
2351 *
2352 * _(CLOSED, "CLOSED") \
2353 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2354 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2355 * _(ESTABLISHED, "ESTABLISHED") \
2356 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2357 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2358 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2359 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2360 */
Marco Varlesef3ab4892018-02-19 15:23:13 +01002361 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002362 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2363 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2364 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2365 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2366 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2367 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2368 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2369 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2370 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2371 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2372 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2373 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2374 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2375 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002376 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002377
Marco Varlese200fa322018-02-26 16:33:54 +01002378 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002379 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2380 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2381 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2382 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2383 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2384 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2385 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2386 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2387 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2388 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2389 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2390 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2391 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2392 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002393 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2394 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002395
2396 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2397 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2398 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2399 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2400 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2401 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2402 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2403 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2404 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2405 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2406 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2407 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2408 SCTP_ERROR_NONE);
2409 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2410 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2411 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002412 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2413 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002414
2415 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2416 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2417 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2418 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2419 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2420 SCTP_ERROR_NONE);
2421 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2422 SCTP_ERROR_NONE);
2423 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2424 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2425 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2426 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2427 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2428 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2429 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2430 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2431 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002432 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2433 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002434
2435 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2436 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2437 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2438 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2439 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2440 SCTP_ERROR_NONE);
2441 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2442 SCTP_ERROR_NONE);
2443 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2444 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2445 SCTP_ERROR_NONE);
2446 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2447 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002448 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2449 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002450 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2451 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2452 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2453 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002454 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2455 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002456
2457 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2458 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2459 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2460 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2461 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2462 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2463 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2464 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2465 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2466 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002467 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2468 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002469 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2470 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2471 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2472 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002473 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2474 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002475
2476 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2477 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2478 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2479 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2480 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2481 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2482 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2483 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2484 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2485 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002486 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2487 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002488 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2489 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2490 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2491 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002492 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2493 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002494
2495 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
Marco Varleseeacf3cf2018-02-26 14:52:25 +01002496 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
Marco Varlese191a5942017-10-30 18:17:21 +01002497 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2498 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2499 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2500 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2501 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2502 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2503 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002504 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2505 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002506 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2507 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2508 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2509 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2510 SCTP_ERROR_NONE);
Marco Varlese200fa322018-02-26 16:33:54 +01002511 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2512 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002513
2514 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2515
2516#undef _
2517}
2518
2519clib_error_t *
2520sctp_input_init (vlib_main_t * vm)
2521{
2522 clib_error_t *error = 0;
2523 sctp_main_t *tm = vnet_get_sctp_main ();
2524
2525 if ((error = vlib_call_init_function (vm, sctp_init)))
2526 return error;
2527
2528 /* Initialize dispatch table. */
2529 sctp_dispatch_table_init (tm);
2530
2531 return error;
2532}
2533
2534VLIB_INIT_FUNCTION (sctp_input_init);
2535
2536/*
2537 * fd.io coding-style-patch-verification: ON
2538 *
2539 * Local Variables:
2540 * eval: (c-set-style "gnu")
2541 * End:
2542 */