blob: 1863c89ef459c54e31555c1e782d1793f55defff [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
298 if (op_err->err_causes[0].cause_info == STALE_COOKIE_ERROR)
299 {
300 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
301 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
302 else
303 {
304 sctp_connection_cleanup (sctp_conn);
305
306 stream_session_disconnect_notify (&sctp_conn->
307 sub_conn[idx].connection);
308 }
309 }
310
311 return SCTP_ERROR_NONE;
312}
313
314always_inline u16
Marco Varlese191a5942017-10-30 18:17:21 +0100315sctp_handle_init (sctp_header_t * sctp_hdr,
316 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
317 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
318 u16 sctp_implied_length)
319{
320 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
321 ip4_address_t *ip4_addr = 0;
322 ip6_address_t *ip6_addr = 0;
323 char hostname[FQDN_MAX_LENGTH];
324
325 /* Check the current state of the connection
326 *
327 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
328 * in the code below and by the "sctp_prepare_initack_chunk" function.
329 * However, for debugging purposes it is nice to have a message printed out
330 * for these corner-case scenarios.
331 */
332 if (sctp_conn->state != SCTP_STATE_CLOSED)
333 { /* UNEXPECTED scenario */
334 switch (sctp_conn->state)
335 {
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100336 case SCTP_STATE_COOKIE_WAIT:
Marco Varlese191a5942017-10-30 18:17:21 +0100337 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100338 sctp_prepare_initack_chunk_for_collision (sctp_conn,
339 MAIN_SCTP_SUB_CONN_IDX,
340 b0, ip4_addr, ip6_addr);
341 return SCTP_ERROR_NONE;
342 case SCTP_STATE_COOKIE_ECHOED:
343 case SCTP_STATE_SHUTDOWN_ACK_SENT:
Marco Varlese191a5942017-10-30 18:17:21 +0100344 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100345 if (sctp_conn->forming_association_changed == 0)
346 sctp_prepare_initack_chunk_for_collision (sctp_conn,
347 MAIN_SCTP_SUB_CONN_IDX,
348 b0, ip4_addr, ip6_addr);
349 else
350 sctp_prepare_abort_for_collision (sctp_conn,
351 MAIN_SCTP_SUB_CONN_IDX, b0,
352 ip4_addr, ip6_addr);
353 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100354 }
355 }
356
357 if (sctp_hdr->verification_tag != 0x0)
358 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
359
360 /*
361 * It is not possible to bundle any other CHUNK with the INIT chunk
362 */
363 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
364 return SCTP_ERROR_BUNDLING_VIOLATION;
365
366 /* Save the INITIATE_TAG of the remote peer for this connection:
367 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
368 sctp_conn->remote_tag = init_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100369 sctp_conn->remote_initial_tsn =
370 clib_net_to_host_u32 (init_chunk->initial_tsn);
371 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
372 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
373 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
374 sctp_conn->remote_initial_tsn);
375
Marco Varlese191a5942017-10-30 18:17:21 +0100376 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
377
378 /*
379 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
380 * optional parameters have been sent with the INIT chunk and we need to parse them.
381 */
382 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
383 if (length > sizeof (sctp_init_chunk_t))
384 {
385 /* There are optional parameters in the INIT chunk */
386 u16 pointer_offset = sizeof (sctp_init_chunk_t);
387 while (pointer_offset < length)
388 {
389 sctp_opt_params_hdr_t *opt_params_hdr =
390 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
391
392 switch (clib_net_to_host_u16 (opt_params_hdr->type))
393 {
394 case SCTP_IPV4_ADDRESS_TYPE:
395 {
396 sctp_ipv4_addr_param_t *ipv4 =
397 (sctp_ipv4_addr_param_t *) opt_params_hdr;
398 clib_memcpy (ip4_addr, &ipv4->address,
399 sizeof (ip4_address_t));
400
401 sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
402
403 break;
404 }
405 case SCTP_IPV6_ADDRESS_TYPE:
406 {
407 sctp_ipv6_addr_param_t *ipv6 =
408 (sctp_ipv6_addr_param_t *) opt_params_hdr;
409 clib_memcpy (ip6_addr, &ipv6->address,
410 sizeof (ip6_address_t));
411
412 sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
413
414 break;
415 }
416 case SCTP_COOKIE_PRESERVATIVE_TYPE:
417 {
418 sctp_cookie_preservative_param_t *cookie_pres =
419 (sctp_cookie_preservative_param_t *) opt_params_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100420 sctp_conn->peer_cookie_life_span_increment =
421 cookie_pres->life_span_inc;
Marco Varlese191a5942017-10-30 18:17:21 +0100422 break;
423 }
424 case SCTP_HOSTNAME_ADDRESS_TYPE:
425 {
426 sctp_hostname_param_t *hostname_addr =
427 (sctp_hostname_param_t *) opt_params_hdr;
428 clib_memcpy (hostname, hostname_addr->hostname,
429 FQDN_MAX_LENGTH);
430 break;
431 }
432 case SCTP_SUPPORTED_ADDRESS_TYPES:
433 {
434 /* TODO */
435 break;
436 }
437 }
438 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
439 }
440 }
441
442 /* Reuse buffer to make init-ack and send */
Marco Varlese54432f82018-02-15 17:01:56 +0100443 sctp_prepare_initack_chunk (sctp_conn, MAIN_SCTP_SUB_CONN_IDX, b0, ip4_addr,
444 ip6_addr);
Marco Varlese191a5942017-10-30 18:17:21 +0100445 return SCTP_ERROR_NONE;
446}
447
448always_inline u16
449sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
450 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
451 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
452 u16 sctp_implied_length)
453{
454 sctp_init_ack_chunk_t *init_ack_chunk =
455 (sctp_init_ack_chunk_t *) (sctp_hdr);
456
457 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
458 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
459 {
460 return SCTP_ERROR_INVALID_TAG;
461 }
462
463 /*
464 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
465 */
466 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
467 return SCTP_ERROR_BUNDLING_VIOLATION;
468
469 return SCTP_ERROR_NONE;
470}
471
472always_inline u16
473sctp_handle_init_ack (sctp_header_t * sctp_hdr,
474 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100475 sctp_connection_t * sctp_conn, u8 idx,
476 vlib_buffer_t * b0, u16 sctp_implied_length)
Marco Varlese191a5942017-10-30 18:17:21 +0100477{
478 sctp_init_ack_chunk_t *init_ack_chunk =
479 (sctp_init_ack_chunk_t *) (sctp_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100480 sctp_state_cookie_param_t state_cookie;
481
482 char hostname[FQDN_MAX_LENGTH];
483
484 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
485 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
486 {
487 return SCTP_ERROR_INVALID_TAG;
488 }
489
490 /*
491 * It is not possible to bundle any other CHUNK with the INIT chunk
492 */
493 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
494 return SCTP_ERROR_BUNDLING_VIOLATION;
495
Marco Varlese21c8baf2018-02-02 17:17:51 +0100496 sctp_calculate_rto (sctp_conn, idx);
497
Marco Varlese191a5942017-10-30 18:17:21 +0100498 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
499 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100500 sctp_conn->remote_initial_tsn =
501 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
502 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
503 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
504 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
505 sctp_conn->remote_initial_tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100506 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
507
508 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
509
510 if (length > sizeof (sctp_init_ack_chunk_t))
511 /*
512 * There are optional parameters in the INIT ACK chunk
513 */
514 {
515 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
516
517 while (pointer_offset < length)
518 {
519 sctp_opt_params_hdr_t *opt_params_hdr =
520 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
521 pointer_offset);
522
523 switch (clib_net_to_host_u16 (opt_params_hdr->type))
524 {
525 case SCTP_IPV4_ADDRESS_TYPE:
526 {
527 sctp_ipv4_addr_param_t *ipv4 =
528 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100529
530 sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
531
532 break;
533 }
534 case SCTP_IPV6_ADDRESS_TYPE:
535 {
536 sctp_ipv6_addr_param_t *ipv6 =
537 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100538
539 sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
540
541 break;
542 }
543 case SCTP_STATE_COOKIE_TYPE:
544 {
545 sctp_state_cookie_param_t *state_cookie_param =
546 (sctp_state_cookie_param_t *) opt_params_hdr;
547
548 clib_memcpy (&state_cookie, state_cookie_param,
549 sizeof (sctp_state_cookie_param_t));
550 break;
551 }
552 case SCTP_HOSTNAME_ADDRESS_TYPE:
553 {
554 sctp_hostname_param_t *hostname_addr =
555 (sctp_hostname_param_t *) opt_params_hdr;
556 clib_memcpy (hostname, hostname_addr->hostname,
557 FQDN_MAX_LENGTH);
558 break;
559 }
560 case SCTP_UNRECOGNIZED_TYPE:
561 {
562 break;
563 }
564 }
565 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
566 /* This indicates something really bad happened */
567 if (increment == 0)
568 {
569 return SCTP_ERROR_INVALID_TAG;
570 }
571 pointer_offset += increment;
572 }
573 }
574
Marco Varlese54432f82018-02-15 17:01:56 +0100575 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, &state_cookie);
Marco Varlese191a5942017-10-30 18:17:21 +0100576
577 /* Start the T1_COOKIE timer */
Marco Varlese54432f82018-02-15 17:01:56 +0100578 sctp_timer_set (sctp_conn, idx,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100579 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
Marco Varlese191a5942017-10-30 18:17:21 +0100580
581 return SCTP_ERROR_NONE;
582}
583
Marco Varlese91389ac2018-01-31 11:00:01 +0100584/** Enqueue data out-of-order for delivery to application */
585always_inline int
586sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
587 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
588{
589 int written, error = SCTP_ERROR_ENQUEUED;
590
591 written =
592 session_enqueue_stream_connection (&sctp_conn->
593 sub_conn[conn_idx].connection, b, 0,
594 1 /* queue event */ ,
595 0);
596
597 /* Update next_tsn_expected */
598 if (PREDICT_TRUE (written == data_len))
599 {
600 sctp_conn->next_tsn_expected += written;
601
602 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
603 sctp_conn->sub_conn[conn_idx].connection.c_index,
604 written, data_len);
605 }
606 /* If more data written than expected, account for out-of-order bytes. */
607 else if (written > data_len)
608 {
609 sctp_conn->next_tsn_expected += written;
610
611 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
612 sctp_conn->sub_conn[conn_idx].connection.c_index,
613 written, data_len);
614 }
615 else if (written > 0)
616 {
617 /* We've written something but FIFO is probably full now */
618 sctp_conn->next_tsn_expected += written;
619
620 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
621
622 SCTP_ADV_DBG
623 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
624 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
625 }
626 else
627 {
628 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
629 sctp_conn->sub_conn[conn_idx].connection.c_index);
630
631 return SCTP_ERROR_FIFO_FULL;
632 }
633
634 /* TODO: Update out_of_order_map & SACK list */
635
636 return error;
637}
638
Marco Varlese191a5942017-10-30 18:17:21 +0100639/** Enqueue data for delivery to application */
640always_inline int
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100641sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100642 u16 data_len, u8 conn_idx)
643{
644 int written, error = SCTP_ERROR_ENQUEUED;
645
646 written =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100647 session_enqueue_stream_connection (&sctp_conn->
648 sub_conn[conn_idx].connection, b, 0,
649 1 /* queue event */ ,
650 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100651
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100652 /* Update next_tsn_expected */
Marco Varlese191a5942017-10-30 18:17:21 +0100653 if (PREDICT_TRUE (written == data_len))
654 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100655 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100656
657 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100658 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100659 written, data_len);
660 }
661 /* If more data written than expected, account for out-of-order bytes. */
662 else if (written > data_len)
663 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100664 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100665
666 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100667 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100668 written, data_len);
669 }
670 else if (written > 0)
671 {
672 /* We've written something but FIFO is probably full now */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100673 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100674
675 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
676
677 SCTP_ADV_DBG
678 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100679 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
Marco Varlese191a5942017-10-30 18:17:21 +0100680 }
681 else
682 {
683 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100684 sctp_conn->sub_conn[conn_idx].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100685
686 return SCTP_ERROR_FIFO_FULL;
687 }
688
689 return error;
690}
691
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100692always_inline u8
Marco Varlese54432f82018-02-15 17:01:56 +0100693sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100694{
Marco Varlesea38783e2018-02-13 12:38:52 +0100695 if (is_gapping != 0)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100696 {
697 SCTP_CONN_TRACKING_DBG
698 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
699 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100700 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100701 }
702
703 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
704 {
705 SCTP_CONN_TRACKING_DBG
706 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
707 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100708 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100709 }
710
711 sctp_conn->ack_state += 1;
712
Marco Varlesea38783e2018-02-13 12:38:52 +0100713 return 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100714}
715
Marco Varlese91389ac2018-01-31 11:00:01 +0100716always_inline void
717sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
718 u8 * gapping)
719{
720 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
721 {
722 SCTP_CONN_TRACKING_DBG
723 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
Marco Varlese54432f82018-02-15 17:01:56 +0100724 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.c_index,
Marco Varlese91389ac2018-01-31 11:00:01 +0100725 sctp_conn->next_tsn_expected, tsn,
726 sctp_conn->next_tsn_expected - tsn);
727
728 *gapping = 1;
729 }
730}
731
Marco Varlese191a5942017-10-30 18:17:21 +0100732always_inline u16
733sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100734 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100735 u16 * next0)
736{
737 u32 error = 0, n_data_bytes;
Marco Varlese91389ac2018-01-31 11:00:01 +0100738 u8 is_gapping = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100739
740 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
741 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
742 {
743 return SCTP_ERROR_INVALID_TAG;
744 }
745
746 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
747 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100748
749 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100750
751 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
752 n_data_bytes = vnet_buffer (b)->sctp.data_len;
753 ASSERT (n_data_bytes);
754
Marco Varlese91389ac2018-01-31 11:00:01 +0100755 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100756
757 sctp_conn->last_rcvd_tsn = tsn;
758
Marco Varlese191a5942017-10-30 18:17:21 +0100759 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
760
Marco Varlese91389ac2018-01-31 11:00:01 +0100761 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
762 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
763
764 if (bbit == 1 && ebit == 1) /* Unfragmented message */
765 {
766 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
767 * segments can be enqueued after fifo tail offset changes. */
Marco Varlese54432f82018-02-15 17:01:56 +0100768 if (PREDICT_FALSE (is_gapping == 1))
769 error =
770 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
771 else
772 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
Marco Varlese91389ac2018-01-31 11:00:01 +0100773 }
774 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
775 {
776 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
777 }
778 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
779 {
780 if (PREDICT_FALSE (is_gapping == 1))
781 error =
782 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
783 else
784 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
785 }
786 else /* Middle piece of a fragmented user message */
787 {
788 if (PREDICT_FALSE (is_gapping == 1))
789 error =
790 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
791 else
792 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
793 }
794 sctp_conn->last_rcvd_tsn = tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100795
Marco Varlesefae40392018-02-14 15:38:35 +0100796 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100797
Marco Varlese91389ac2018-01-31 11:00:01 +0100798 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
799
Marco Varlese54432f82018-02-15 17:01:56 +0100800 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
801 sctp_prepare_sack_chunk (sctp_conn, idx, b);
802
803 sctp_conn->sub_conn[idx].enqueue_state = error;
Marco Varlese191a5942017-10-30 18:17:21 +0100804
805 return error;
806}
807
808always_inline u16
809sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
810 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100811 sctp_connection_t * sctp_conn, u8 idx,
812 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100813{
Marco Varlese21c8baf2018-02-02 17:17:51 +0100814 u32 now = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +0100815
Marco Varlese91389ac2018-01-31 11:00:01 +0100816 sctp_cookie_echo_chunk_t *cookie_echo =
817 (sctp_cookie_echo_chunk_t *) sctp_hdr;
818
Marco Varlese191a5942017-10-30 18:17:21 +0100819 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
820 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
821 {
822 return SCTP_ERROR_INVALID_TAG;
823 }
824
Marco Varlese21c8baf2018-02-02 17:17:51 +0100825 sctp_calculate_rto (sctp_conn, idx);
826
Marco Varlese91389ac2018-01-31 11:00:01 +0100827 u32 creation_time =
828 clib_net_to_host_u32 (cookie_echo->cookie.creation_time);
829 u32 cookie_lifespan =
830 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
831 if (now > creation_time + cookie_lifespan)
832 {
833 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
834 now, creation_time, cookie_lifespan);
835 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
836 }
837
Marco Varlese54432f82018-02-15 17:01:56 +0100838 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +0100839
840 /* Change state */
841 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100842 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
Marco Varlesebe2251b2018-02-07 12:22:41 +0100843 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100844
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100845 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
846 sctp_conn->sub_conn[idx].RTO);
847
Marco Varlese15cc6a82018-02-21 12:39:52 +0100848 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
849
Marco Varlese191a5942017-10-30 18:17:21 +0100850 return SCTP_ERROR_NONE;
851
852}
853
854always_inline u16
855sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
856 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100857 sctp_connection_t * sctp_conn, u8 idx,
858 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100859{
Marco Varlese191a5942017-10-30 18:17:21 +0100860 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
861 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
862 {
863 return SCTP_ERROR_INVALID_TAG;
864 }
865
Marco Varlese21c8baf2018-02-02 17:17:51 +0100866 sctp_calculate_rto (sctp_conn, idx);
867
Marco Varlese191a5942017-10-30 18:17:21 +0100868 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
869 /* Change state */
870 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100871 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
872
Marco Varlesefae40392018-02-14 15:38:35 +0100873 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100874
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100875 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
876 sctp_conn->sub_conn[idx].RTO);
877
Marco Varlese15cc6a82018-02-21 12:39:52 +0100878 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
879
Marco Varlese191a5942017-10-30 18:17:21 +0100880 return SCTP_ERROR_NONE;
881
882}
883
884always_inline uword
885sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
886 vlib_frame_t * from_frame, int is_ip4)
887{
888 sctp_main_t *tm = vnet_get_sctp_main ();
889
890 u32 n_left_from, next_index, *from, *to_next;
891 u32 my_thread_index = vm->thread_index;
892
893 from = vlib_frame_vector_args (from_frame);
894 n_left_from = from_frame->n_vectors;
895
896 next_index = node->cached_next_index;
897
898 while (n_left_from > 0)
899 {
900 u32 n_left_to_next;
901
902 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
903
904 while (n_left_from > 0 && n_left_to_next > 0)
905 {
906 u32 bi0;
907 vlib_buffer_t *b0;
908 sctp_header_t *sctp_hdr = 0;
909 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
910 ip4_header_t *ip4_hdr = 0;
911 ip6_header_t *ip6_hdr = 0;
912 sctp_connection_t *sctp_conn, *new_sctp_conn;
913 u16 sctp_implied_length = 0;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100914 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100915 u8 idx;
916
917 bi0 = from[0];
918 to_next[0] = bi0;
919 from += 1;
920 to_next += 1;
921 n_left_from -= 1;
922 n_left_to_next -= 1;
923
924 b0 = vlib_get_buffer (vm, bi0);
925
926 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
927 * will come from the half-open connections pool.
928 */
929 sctp_conn =
930 sctp_half_open_connection_get (vnet_buffer (b0)->
931 sctp.connection_index);
932
933 if (PREDICT_FALSE (sctp_conn == 0))
934 {
Marco Varlese191a5942017-10-30 18:17:21 +0100935 SCTP_ADV_DBG
936 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
937 error0 = SCTP_ERROR_INVALID_CONNECTION;
938 goto drop;
939 }
940 if (is_ip4)
941 {
942 ip4_hdr = vlib_buffer_get_current (b0);
943 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +0100944 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100945 }
946 else
947 {
948 ip6_hdr = vlib_buffer_get_current (b0);
949 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +0100950 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100951 }
Marco Varlese191a5942017-10-30 18:17:21 +0100952
Marco Varlese04e5d642018-02-23 17:43:06 +0100953 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100954 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
955
Marco Varlese191a5942017-10-30 18:17:21 +0100956 sctp_chunk_hdr =
957 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
958
959 sctp_implied_length =
960 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
961
962 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
963
964 switch (chunk_type)
965 {
966 case INIT_ACK:
967 error0 =
968 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
969 b0, sctp_implied_length);
970
971 if (error0 == SCTP_ERROR_NONE)
972 {
973 pool_get (tm->connections[my_thread_index], new_sctp_conn);
974 clib_memcpy (new_sctp_conn, sctp_conn,
975 sizeof (*new_sctp_conn));
976 new_sctp_conn->sub_conn[idx].c_c_index =
977 new_sctp_conn - tm->connections[my_thread_index];
978 new_sctp_conn->sub_conn[idx].c_thread_index =
979 my_thread_index;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100980 new_sctp_conn->sub_conn[idx].PMTU =
981 sctp_conn->sub_conn[idx].PMTU;
Marco Varlese04e5d642018-02-23 17:43:06 +0100982 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100983
984 if (sctp_half_open_connection_cleanup (sctp_conn))
985 {
986 SCTP_DBG
987 ("Cannot cleanup half-open connection; not the owning thread");
988 }
989
990 sctp_connection_timers_init (new_sctp_conn);
991
992 error0 =
993 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100994 new_sctp_conn, idx, b0,
Marco Varlese191a5942017-10-30 18:17:21 +0100995 sctp_implied_length);
996
Marco Varlesef3ab4892018-02-19 15:23:13 +0100997 sctp_init_cwnd (new_sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100998
999 if (session_stream_connect_notify
1000 (&new_sctp_conn->sub_conn[idx].connection, 0))
1001 {
1002 SCTP_DBG
1003 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1004 new_sctp_conn->sub_conn[idx].connection.c_index);
1005 sctp_connection_cleanup (new_sctp_conn);
1006 goto drop;
1007 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001008 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001009 }
Marco Varlese191a5942017-10-30 18:17:21 +01001010 break;
1011
Marco Varlese200fa322018-02-26 16:33:54 +01001012 case OPERATION_ERROR:
1013 error0 =
1014 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1015 &next0);
1016 break;
1017
Marco Varlese191a5942017-10-30 18:17:21 +01001018 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1019 * are handled by the input-dispatcher function using the table-lookup
1020 * hence we should never get to the "default" case below.
1021 */
1022 default:
1023 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001024 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001025 goto drop;
1026 }
1027
1028 if (error0 != SCTP_ERROR_NONE)
1029 {
1030 clib_warning ("error while parsing chunk");
1031 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001032 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001033 goto drop;
1034 }
1035
1036 drop:
1037 b0->error = node->errors[error0];
1038 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1039 {
1040 sctp_rx_trace_t *t0 =
1041 vlib_add_trace (vm, node, b0, sizeof (*t0));
1042 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1043 }
1044
1045 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1046 n_left_to_next, bi0, next0);
1047 }
1048
1049 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1050 }
1051 return from_frame->n_vectors;
1052}
1053
1054static uword
1055sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1056 vlib_frame_t * from_frame)
1057{
1058 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1059}
1060
1061static uword
1062sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1063 vlib_frame_t * from_frame)
1064{
1065 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1066}
1067
1068u8 *
1069format_sctp_rx_trace_short (u8 * s, va_list * args)
1070{
1071 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1072 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1073 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1074
1075 s = format (s, "%d -> %d (%U)",
1076 clib_net_to_host_u16 (t->sctp_header.src_port),
1077 clib_net_to_host_u16 (t->sctp_header.dst_port),
1078 format_sctp_state, t->sctp_connection.state);
1079
1080 return s;
1081}
1082
1083/* *INDENT-OFF* */
1084VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1085{
1086 .function = sctp4_rcv_phase,
1087 .name = "sctp4-rcv",
1088 /* Takes a vector of packets. */
1089 .vector_size = sizeof (u32),
1090 .n_errors = SCTP_N_ERROR,
1091 .error_strings = sctp_error_strings,
1092 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1093 .next_nodes =
1094 {
1095#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1096 foreach_sctp_state_next
1097#undef _
1098 },
1099 .format_trace = format_sctp_rx_trace_short,
1100};
1101/* *INDENT-ON* */
1102
1103VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1104
1105/* *INDENT-OFF* */
1106VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1107{
1108 .function = sctp6_rcv_phase,
1109 .name = "sctp6-rcv",
1110 /* Takes a vector of packets. */
1111 .vector_size = sizeof (u32),
1112 .n_errors = SCTP_N_ERROR,
1113 .error_strings = sctp_error_strings,
1114 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1115 .next_nodes =
1116 {
1117#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1118 foreach_sctp_state_next
1119#undef _
1120 },
1121 .format_trace = format_sctp_rx_trace_short,
1122};
1123/* *INDENT-ON* */
1124
1125VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1126
1127vlib_node_registration_t sctp4_shutdown_phase_node;
1128vlib_node_registration_t sctp6_shutdown_phase_node;
1129
1130always_inline u16
1131sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1132 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001133 sctp_connection_t * sctp_conn, u8 idx,
1134 vlib_buffer_t * b0, u16 sctp_implied_length,
1135 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001136{
1137 sctp_shutdown_association_chunk_t *shutdown_chunk =
1138 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1139
1140 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1141 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1142 {
1143 return SCTP_ERROR_INVALID_TAG;
1144 }
1145
1146 /*
1147 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1148 */
1149 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1150 return SCTP_ERROR_BUNDLING_VIOLATION;
1151
1152 switch (sctp_conn->state)
1153 {
1154 case SCTP_STATE_ESTABLISHED:
1155 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1156 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
Marco Varlese54432f82018-02-15 17:01:56 +01001157 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001158 break;
1159
1160 case SCTP_STATE_SHUTDOWN_SENT:
Marco Varlese54432f82018-02-15 17:01:56 +01001161 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001162 break;
1163 }
1164
Marco Varlesebe2251b2018-02-07 12:22:41 +01001165 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1166
Marco Varlese191a5942017-10-30 18:17:21 +01001167 return SCTP_ERROR_NONE;
1168}
1169
1170always_inline u16
1171sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1172 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001173 sctp_connection_t * sctp_conn, u8 idx,
1174 vlib_buffer_t * b0, u16 sctp_implied_length,
1175 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001176{
1177 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1178 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1179
1180 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1181 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1182 {
1183 return SCTP_ERROR_INVALID_TAG;
1184 }
1185
1186 /*
1187 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1188 */
1189 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1190 return SCTP_ERROR_BUNDLING_VIOLATION;
1191
1192 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1193 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1194 * - STOP T2_SHUTDOWN timer
1195 * - SEND SHUTDOWN_COMPLETE chunk
1196 */
1197 sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
1198 SCTP_TIMER_T2_SHUTDOWN);
Marco Varlesea38783e2018-02-13 12:38:52 +01001199
Marco Varlese54432f82018-02-15 17:01:56 +01001200 sctp_send_shutdown_complete (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001201
Marco Varlesebe2251b2018-02-07 12:22:41 +01001202 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1203
Marco Varlese191a5942017-10-30 18:17:21 +01001204 return SCTP_ERROR_NONE;
1205}
1206
1207always_inline u16
1208sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1209 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001210 sctp_connection_t * sctp_conn, u8 idx,
1211 vlib_buffer_t * b0, u16 sctp_implied_length,
1212 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001213{
1214 sctp_shutdown_complete_chunk_t *shutdown_complete =
1215 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1216
1217 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1218 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1219 {
1220 return SCTP_ERROR_INVALID_TAG;
1221 }
1222
1223 /*
1224 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1225 */
1226 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1227 return SCTP_ERROR_BUNDLING_VIOLATION;
1228
Marco Varlesef3ab4892018-02-19 15:23:13 +01001229 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1230
1231 stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese191a5942017-10-30 18:17:21 +01001232
1233 sctp_conn->state = SCTP_STATE_CLOSED;
1234
Marco Varlesefae40392018-02-14 15:38:35 +01001235 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001236
Marco Varlese191a5942017-10-30 18:17:21 +01001237 return SCTP_ERROR_NONE;
1238}
1239
1240always_inline uword
1241sctp46_shutdown_phase_inline (vlib_main_t * vm,
1242 vlib_node_runtime_t * node,
1243 vlib_frame_t * from_frame, int is_ip4)
1244{
1245 u32 n_left_from, next_index, *from, *to_next;
1246 u32 my_thread_index = vm->thread_index;
1247
1248 from = vlib_frame_vector_args (from_frame);
1249 n_left_from = from_frame->n_vectors;
1250
1251 next_index = node->cached_next_index;
1252
1253 while (n_left_from > 0)
1254 {
1255 u32 n_left_to_next;
1256
1257 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1258
1259 while (n_left_from > 0 && n_left_to_next > 0)
1260 {
1261 u32 bi0;
1262 vlib_buffer_t *b0;
1263 sctp_rx_trace_t *sctp_trace;
1264 sctp_header_t *sctp_hdr = 0;
1265 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1266 ip4_header_t *ip4_hdr = 0;
1267 ip6_header_t *ip6_hdr = 0;
1268 sctp_connection_t *sctp_conn;
1269 u16 sctp_implied_length = 0;
1270 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
Marco Varlese54432f82018-02-15 17:01:56 +01001271 u8 idx = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001272
1273 bi0 = from[0];
1274 to_next[0] = bi0;
1275 from += 1;
1276 to_next += 1;
1277 n_left_from -= 1;
1278 n_left_to_next -= 1;
1279
1280 b0 = vlib_get_buffer (vm, bi0);
1281 sctp_conn =
1282 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1283 my_thread_index);
1284
1285 if (PREDICT_FALSE (sctp_conn == 0))
1286 {
1287 SCTP_DBG
1288 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1289 error0 = SCTP_ERROR_INVALID_CONNECTION;
1290 goto drop;
1291 }
1292
1293 if (is_ip4)
1294 {
1295 ip4_hdr = vlib_buffer_get_current (b0);
1296 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001297 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001298 }
1299 else
1300 {
1301 ip6_hdr = vlib_buffer_get_current (b0);
1302 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001303 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001304 }
1305
1306 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1307 sctp_chunk_hdr = &full_hdr->common_hdr;
1308
1309 sctp_implied_length =
1310 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1311
Marco Varlesebe2251b2018-02-07 12:22:41 +01001312 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1313 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001314 {
1315 case SHUTDOWN:
1316 error0 =
Marco Varlesebe2251b2018-02-07 12:22:41 +01001317 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1318 idx, b0, sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001319 break;
1320
1321 case SHUTDOWN_ACK:
1322 error0 =
1323 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001324 idx, b0, sctp_implied_length,
1325 &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001326 break;
1327
1328 case SHUTDOWN_COMPLETE:
1329 error0 =
1330 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001331 sctp_conn, idx, b0,
1332 sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001333
1334 sctp_connection_cleanup (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001335 break;
1336
1337 /*
1338 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1339 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1340 */
1341 case DATA:
1342 error0 =
1343 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001344 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001345 break;
1346
Marco Varlese200fa322018-02-26 16:33:54 +01001347 case OPERATION_ERROR:
1348 error0 =
1349 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1350 &next0);
1351 break;
1352
Marco Varlese191a5942017-10-30 18:17:21 +01001353 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1354 * are handled by the input-dispatcher function using the table-lookup
1355 * hence we should never get to the "default" case below.
1356 */
1357 default:
1358 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001359 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001360 goto drop;
1361 }
1362
1363 if (error0 != SCTP_ERROR_NONE)
1364 {
1365 clib_warning ("error while parsing chunk");
1366 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001367 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001368 goto drop;
1369 }
1370
1371 drop:
1372 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1373 {
1374 sctp_trace =
1375 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
Marco Varlesef429a932018-02-06 17:31:06 +01001376
1377 if (sctp_hdr != NULL)
1378 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1379 sizeof (sctp_trace->sctp_header));
1380
1381 if (sctp_conn != NULL)
1382 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1383 sizeof (sctp_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001384 }
1385
1386 b0->error = node->errors[error0];
1387
1388 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1389 n_left_to_next, bi0, next0);
1390 }
1391
1392 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1393 }
1394
1395 return from_frame->n_vectors;
1396
1397}
1398
1399static uword
1400sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1401 vlib_frame_t * from_frame)
1402{
1403 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1404}
1405
1406static uword
1407sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1408 vlib_frame_t * from_frame)
1409{
1410 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1411}
1412
1413/* *INDENT-OFF* */
1414VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1415{
1416 .function = sctp4_shutdown_phase,
1417 .name = "sctp4-shutdown",
1418 /* Takes a vector of packets. */
1419 .vector_size = sizeof (u32),
1420 .n_errors = SCTP_N_ERROR,
1421 .error_strings = sctp_error_strings,
1422 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1423 .next_nodes =
1424 {
1425#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1426 foreach_sctp_state_next
1427#undef _
1428 },
1429 .format_trace = format_sctp_rx_trace_short,
1430};
1431/* *INDENT-ON* */
1432
1433VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1434 sctp4_shutdown_phase);
1435
1436/* *INDENT-OFF* */
1437VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1438{
1439 .function = sctp6_shutdown_phase,
1440 .name = "sctp6-shutdown",
1441 /* Takes a vector of packets. */
1442 .vector_size = sizeof (u32),
1443 .n_errors = SCTP_N_ERROR,
1444 .error_strings = sctp_error_strings,
1445 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1446 .next_nodes =
1447 {
1448#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1449 foreach_sctp_state_next
1450#undef _
1451 },
1452 .format_trace = format_sctp_rx_trace_short,
1453};
1454/* *INDENT-ON* */
1455
1456VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1457 sctp6_shutdown_phase);
1458
1459vlib_node_registration_t sctp4_listen_phase_node;
1460vlib_node_registration_t sctp6_listen_phase_node;
1461
1462vlib_node_registration_t sctp4_established_phase_node;
1463vlib_node_registration_t sctp6_established_phase_node;
1464
1465always_inline u16
1466sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001467 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001468 u16 * next0)
1469{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001470 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1471 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1472 {
1473 return SCTP_ERROR_INVALID_TAG;
1474 }
1475
Marco Varlese54432f82018-02-15 17:01:56 +01001476 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1477
Marco Varlesef3ab4892018-02-19 15:23:13 +01001478 /* Section 7.2.2; point (2) */
1479 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1480 sctp_conn->sub_conn[idx].partially_acked_bytes =
1481 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1482
1483 /* Section 7.2.2; point (5) */
1484 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1485 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1486
1487 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1488
Marco Varlese21c8baf2018-02-02 17:17:51 +01001489 sctp_calculate_rto (sctp_conn, idx);
1490
1491 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1492 sctp_conn->sub_conn[idx].RTO);
1493
1494 sctp_conn->sub_conn[idx].RTO_pending = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001495
Marco Varlesefae40392018-02-14 15:38:35 +01001496 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001497
1498 return SCTP_ERROR_NONE;
1499}
1500
1501always_inline u16
1502sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001503 sctp_connection_t * sctp_conn, u8 idx,
1504 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001505{
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001506 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1507 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1508 {
1509 return SCTP_ERROR_INVALID_TAG;
1510 }
1511
Marco Varlese54432f82018-02-15 17:01:56 +01001512 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001513
1514 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1515
Marco Varlese191a5942017-10-30 18:17:21 +01001516 return SCTP_ERROR_NONE;
1517}
1518
1519always_inline u16
1520sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001521 sctp_connection_t * sctp_conn, u8 idx,
1522 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001523{
Marco Varlese54432f82018-02-15 17:01:56 +01001524 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1525
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001526 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1527
1528 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1529 sctp_conn->sub_conn[idx].RTO);
1530
Marco Varlesefae40392018-02-14 15:38:35 +01001531 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001532
Marco Varlese191a5942017-10-30 18:17:21 +01001533 return SCTP_ERROR_NONE;
1534}
1535
1536always_inline void
1537sctp_node_inc_counter (vlib_main_t * vm, u32 tcp4_node, u32 tcp6_node,
1538 u8 is_ip4, u8 evt, u8 val)
1539{
1540 if (PREDICT_TRUE (!val))
1541 return;
1542
1543 if (is_ip4)
1544 vlib_node_increment_counter (vm, tcp4_node, evt, val);
1545 else
1546 vlib_node_increment_counter (vm, tcp6_node, evt, val);
1547}
1548
1549always_inline uword
1550sctp46_listen_process_inline (vlib_main_t * vm,
1551 vlib_node_runtime_t * node,
1552 vlib_frame_t * from_frame, int is_ip4)
1553{
1554 u32 n_left_from, next_index, *from, *to_next;
1555 u32 my_thread_index = vm->thread_index;
1556
1557 from = vlib_frame_vector_args (from_frame);
1558 n_left_from = from_frame->n_vectors;
1559
1560 next_index = node->cached_next_index;
1561
1562 while (n_left_from > 0)
1563 {
1564 u32 n_left_to_next;
1565
1566 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1567
1568 while (n_left_from > 0 && n_left_to_next > 0)
1569 {
1570 u32 bi0;
1571 vlib_buffer_t *b0;
1572 sctp_header_t *sctp_hdr = 0;
1573 ip4_header_t *ip4_hdr;
1574 ip6_header_t *ip6_hdr;
1575 sctp_connection_t *child_conn;
1576 sctp_connection_t *sctp_listener;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001577 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
Marco Varlese191a5942017-10-30 18:17:21 +01001578
1579 bi0 = from[0];
1580 to_next[0] = bi0;
1581 from += 1;
1582 to_next += 1;
1583 n_left_from -= 1;
1584 n_left_to_next -= 1;
1585
1586 b0 = vlib_get_buffer (vm, bi0);
1587 sctp_listener =
1588 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1589
1590 if (is_ip4)
1591 {
1592 ip4_hdr = vlib_buffer_get_current (b0);
1593 sctp_hdr = ip4_next_header (ip4_hdr);
1594 }
1595 else
1596 {
1597 ip6_hdr = vlib_buffer_get_current (b0);
1598 sctp_hdr = ip6_next_header (ip6_hdr);
1599 }
1600
1601 child_conn =
1602 sctp_lookup_connection (sctp_listener->sub_conn
1603 [MAIN_SCTP_SUB_CONN_IDX].c_fib_index, b0,
1604 my_thread_index, is_ip4);
1605
1606 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1607 {
1608 SCTP_DBG
1609 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1610 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1611 connection.c_index,
1612 sctp_state_to_string (child_conn->state));
1613 error0 = SCTP_ERROR_CREATE_EXISTS;
1614 goto drop;
1615 }
1616
1617 /* Create child session and send SYN-ACK */
1618 child_conn = sctp_connection_new (my_thread_index);
Marco Varlese04e5d642018-02-23 17:43:06 +01001619 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].subconn_idx =
1620 MAIN_SCTP_SUB_CONN_IDX;
Marco Varlese191a5942017-10-30 18:17:21 +01001621 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_port =
1622 sctp_hdr->dst_port;
1623 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_port =
1624 sctp_hdr->src_port;
1625 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_is_ip4 = is_ip4;
1626 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto =
1627 sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001628 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU =
1629 sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU;
Marco Varlese191a5942017-10-30 18:17:21 +01001630 child_conn->state = SCTP_STATE_CLOSED;
1631
1632 if (is_ip4)
1633 {
1634 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip4.as_u32 =
1635 ip4_hdr->dst_address.as_u32;
1636 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip4.as_u32 =
1637 ip4_hdr->src_address.as_u32;
1638 }
1639 else
1640 {
1641 clib_memcpy (&child_conn->
1642 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip6,
1643 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1644 clib_memcpy (&child_conn->
1645 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip6,
1646 &ip6_hdr->src_address, sizeof (ip6_address_t));
1647 }
1648
1649 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1650 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1651
1652 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1653 if (chunk_type != INIT)
1654 {
1655 SCTP_DBG
1656 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1657 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1658 connection.c_index, sctp_chunk_to_string (chunk_type));
1659
1660 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001661 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001662 goto drop;
1663 }
1664
1665 u16 sctp_implied_length =
1666 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1667
1668 switch (chunk_type)
1669 {
1670 case INIT:
1671 sctp_connection_timers_init (child_conn);
1672
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001673 sctp_init_snd_vars (child_conn);
1674
Marco Varlese191a5942017-10-30 18:17:21 +01001675 error0 =
1676 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1677 sctp_implied_length);
1678
Marco Varlesef3ab4892018-02-19 15:23:13 +01001679 sctp_init_cwnd (child_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001680
1681 if (error0 == SCTP_ERROR_NONE)
1682 {
1683 if (stream_session_accept
1684 (&child_conn->
1685 sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection,
1686 sctp_listener->
1687 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index, 0))
1688 {
1689 clib_warning ("session accept fail");
1690 sctp_connection_cleanup (child_conn);
1691 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1692 goto drop;
1693 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001694 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001695 }
Marco Varlese191a5942017-10-30 18:17:21 +01001696 break;
1697
1698 /* Reception of a DATA chunk whilst in the CLOSED state is called
1699 * "Out of the Blue" packet and handling of the chunk needs special treatment
1700 * as per RFC4960 section 8.4
1701 */
1702 case DATA:
1703 break;
Marco Varlese200fa322018-02-26 16:33:54 +01001704
1705 case OPERATION_ERROR:
1706 error0 =
1707 sctp_handle_operation_err (sctp_hdr, child_conn,
1708 MAIN_SCTP_SUB_CONN_IDX, b0,
1709 &next0);
1710 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001711 }
1712
1713 drop:
1714 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1715 {
1716 sctp_rx_trace_t *t0 =
1717 vlib_add_trace (vm, node, b0, sizeof (*t0));
1718 clib_memcpy (&t0->sctp_header, sctp_hdr,
1719 sizeof (t0->sctp_header));
1720 clib_memcpy (&t0->sctp_connection, sctp_listener,
1721 sizeof (t0->sctp_connection));
1722 }
1723
1724 b0->error = node->errors[error0];
1725
1726 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1727 n_left_to_next, bi0, next0);
1728 }
1729 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1730
1731 }
1732 return from_frame->n_vectors;
1733}
1734
1735static uword
1736sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1737 vlib_frame_t * from_frame)
1738{
1739 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1740}
1741
1742static uword
1743sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1744 vlib_frame_t * from_frame)
1745{
1746 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1747}
1748
1749always_inline uword
1750sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1751 vlib_frame_t * from_frame, int is_ip4)
1752{
1753 u32 n_left_from, next_index, *from, *to_next;
1754 u32 my_thread_index = vm->thread_index, errors = 0;
1755
1756 from = vlib_frame_vector_args (from_frame);
1757 n_left_from = from_frame->n_vectors;
1758
1759 next_index = node->cached_next_index;
1760
1761 while (n_left_from > 0)
1762 {
1763 u32 n_left_to_next;
1764
1765 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1766
1767 while (n_left_from > 0 && n_left_to_next > 0)
1768 {
1769 u32 bi0;
1770 vlib_buffer_t *b0;
1771 sctp_header_t *sctp_hdr = 0;
1772 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1773 ip4_header_t *ip4_hdr = 0;
1774 ip6_header_t *ip6_hdr = 0;
1775 sctp_connection_t *sctp_conn;
Marco Varlesefae40392018-02-14 15:38:35 +01001776 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1777 SCTP_ESTABLISHED_PHASE_N_NEXT;
Marco Varlese191a5942017-10-30 18:17:21 +01001778 u8 idx;
1779
1780 bi0 = from[0];
1781 to_next[0] = bi0;
1782 from += 1;
1783 to_next += 1;
1784 n_left_from -= 1;
1785 n_left_to_next -= 1;
1786
1787 b0 = vlib_get_buffer (vm, bi0);
1788 sctp_conn =
1789 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1790 my_thread_index);
1791
1792 if (PREDICT_FALSE (sctp_conn == 0))
1793 {
1794 SCTP_DBG
1795 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1796 error0 = SCTP_ERROR_INVALID_CONNECTION;
1797 goto done;
1798 }
1799 if (is_ip4)
1800 {
1801 ip4_hdr = vlib_buffer_get_current (b0);
1802 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001803 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001804 }
1805 else
1806 {
1807 ip6_hdr = vlib_buffer_get_current (b0);
1808 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001809 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001810 }
1811
Marco Varlese04e5d642018-02-23 17:43:06 +01001812 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001813
Marco Varlese54432f82018-02-15 17:01:56 +01001814 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +01001815 sctp_chunk_hdr =
1816 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1817
1818 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1819
1820 switch (chunk_type)
1821 {
1822 case COOKIE_ECHO:
1823 error0 =
1824 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001825 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001826 break;
1827
1828 case COOKIE_ACK:
1829 error0 =
1830 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001831 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001832 break;
1833
1834 case SACK:
1835 error0 =
1836 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001837 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001838 break;
1839
1840 case HEARTBEAT:
1841 error0 =
1842 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001843 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001844 break;
1845
1846 case HEARTBEAT_ACK:
1847 error0 =
1848 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001849 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001850 break;
1851
1852 case DATA:
1853 error0 =
1854 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001855 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001856 break;
1857
Marco Varlese200fa322018-02-26 16:33:54 +01001858 case OPERATION_ERROR:
1859 error0 =
1860 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1861 &next0);
1862 break;
1863
Marco Varlese191a5942017-10-30 18:17:21 +01001864 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1865 * are handled by the input-dispatcher function using the table-lookup
1866 * hence we should never get to the "default" case below.
1867 */
1868 default:
1869 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001870 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001871 goto done;
1872 }
1873
1874 done:
1875 b0->error = node->errors[error0];
1876 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1877 {
1878 sctp_rx_trace_t *t0 =
1879 vlib_add_trace (vm, node, b0, sizeof (*t0));
1880 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1881 }
1882
1883 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1884 n_left_to_next, bi0, next0);
1885 }
1886
1887 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1888 }
1889
1890 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1891 my_thread_index);
1892
1893 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1894 sctp6_established_phase_node.index,
1895 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1896 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1897
1898 return from_frame->n_vectors;
1899}
1900
1901static uword
1902sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1903 vlib_frame_t * from_frame)
1904{
1905 return sctp46_established_phase_inline (vm, node, from_frame,
1906 1 /* is_ip4 */ );
1907}
1908
1909static uword
1910sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1911 vlib_frame_t * from_frame)
1912{
1913 return sctp46_established_phase_inline (vm, node, from_frame,
1914 0 /* is_ip4 */ );
1915}
1916
1917u8 *
1918format_sctp_rx_trace (u8 * s, va_list * args)
1919{
1920 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1921 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1922 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1923 u32 indent = format_get_indent (s);
1924
1925 s = format (s, "%U\n%U%U",
1926 format_sctp_header, &t->sctp_header, 128,
1927 format_white_space, indent,
1928 format_sctp_connection, &t->sctp_connection, 1);
1929
1930 return s;
1931}
1932
1933/* *INDENT-OFF* */
1934VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1935{
1936 .function = sctp4_listen_phase,
1937 .name = "sctp4-listen",
1938 /* Takes a vector of packets. */
1939 .vector_size = sizeof (u32),
1940 .n_errors = SCTP_N_ERROR,
1941 .error_strings = sctp_error_strings,
1942 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1943 .next_nodes =
1944 {
1945#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1946 foreach_sctp_state_next
1947#undef _
1948 },
1949 .format_trace = format_sctp_rx_trace_short,
1950};
1951/* *INDENT-ON* */
1952
1953VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
1954
1955/* *INDENT-OFF* */
1956VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
1957{
1958 .function = sctp6_listen_phase,
1959 .name = "sctp6-listen",
1960 /* Takes a vector of packets. */
1961 .vector_size = sizeof (u32),
1962 .n_errors = SCTP_N_ERROR,
1963 .error_strings = sctp_error_strings,
1964 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1965 .next_nodes =
1966 {
1967#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1968 foreach_sctp_state_next
1969#undef _
1970 },
1971 .format_trace = format_sctp_rx_trace_short,
1972};
1973/* *INDENT-ON* */
1974
1975VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
1976
1977/* *INDENT-OFF* */
1978VLIB_REGISTER_NODE (sctp4_established_phase_node) =
1979{
1980 .function = sctp4_established_phase,
1981 .name = "sctp4-established",
1982 /* Takes a vector of packets. */
1983 .vector_size = sizeof (u32),
1984 .n_errors = SCTP_N_ERROR,
1985 .error_strings = sctp_error_strings,
1986 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
1987 .next_nodes =
1988 {
1989#define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
1990 foreach_sctp_state_next
1991#undef _
1992 },
1993 .format_trace = format_sctp_rx_trace_short,
1994};
1995/* *INDENT-ON* */
1996
1997VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
1998 sctp4_established_phase);
1999
2000/* *INDENT-OFF* */
2001VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2002{
2003 .function = sctp6_established_phase,
2004 .name = "sctp6-established",
2005 /* Takes a vector of packets. */
2006 .vector_size = sizeof (u32),
2007 .n_errors = SCTP_N_ERROR,
2008 .error_strings = sctp_error_strings,
2009 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2010 .next_nodes =
2011 {
2012#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2013 foreach_sctp_state_next
2014#undef _
2015 },
2016 .format_trace = format_sctp_rx_trace_short,
2017};
2018/* *INDENT-ON* */
2019
2020VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2021 sctp6_established_phase);
2022
2023/*
2024 * This is the function executed first for the SCTP graph.
2025 * It takes care of doing the initial message parsing and
2026 * dispatch to the specialized function.
2027 */
2028always_inline uword
2029sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2030 vlib_frame_t * from_frame, int is_ip4)
2031{
2032 u32 n_left_from, next_index, *from, *to_next;
2033 u32 my_thread_index = vm->thread_index;
2034 u8 is_filtered;
2035 sctp_main_t *tm = vnet_get_sctp_main ();
2036
2037 from = vlib_frame_vector_args (from_frame);
2038 n_left_from = from_frame->n_vectors;
2039 next_index = node->cached_next_index;
2040 sctp_set_time_now (my_thread_index);
2041
2042 while (n_left_from > 0)
2043 {
2044 u32 n_left_to_next;
2045
2046 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2047
2048 while (n_left_from > 0 && n_left_to_next > 0)
2049 {
2050 int n_advance_bytes0, n_data_bytes0;
2051 u32 bi0, fib_index0;
2052 vlib_buffer_t *b0;
2053 sctp_header_t *sctp_hdr = 0;
2054 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2055 sctp_connection_t *sctp_conn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002056 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01002057 ip4_header_t *ip4_hdr;
2058 ip6_header_t *ip6_hdr;
2059 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2060
2061 bi0 = from[0];
2062 to_next[0] = bi0;
2063 from += 1;
2064 to_next += 1;
2065 n_left_from -= 1;
2066 n_left_to_next -= 1;
2067
2068 b0 = vlib_get_buffer (vm, bi0);
2069 vnet_buffer (b0)->tcp.flags = 0;
2070 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2071
2072 /* Checksum computed by ipx_local no need to compute again */
2073
2074 if (is_ip4)
2075 {
2076 ip4_hdr = vlib_buffer_get_current (b0);
2077 sctp_hdr = ip4_next_header (ip4_hdr);
2078
2079 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2080 sctp_chunk_hdr = &full_hdr->common_hdr;
2081
2082 n_advance_bytes0 =
2083 (ip4_header_bytes (ip4_hdr) +
2084 sizeof (sctp_payload_data_chunk_t));
2085 n_data_bytes0 =
2086 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2087
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002088 trans_conn = session_lookup_connection_wt4 (fib_index0,
2089 &ip4_hdr->dst_address,
2090 &ip4_hdr->src_address,
2091 sctp_hdr->dst_port,
2092 sctp_hdr->src_port,
2093 TRANSPORT_PROTO_SCTP,
2094 my_thread_index,
2095 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002096 }
2097 else
2098 {
2099 ip6_hdr = vlib_buffer_get_current (b0);
2100 sctp_hdr = ip6_next_header (ip6_hdr);
2101
2102 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2103 sctp_chunk_hdr = &full_hdr->common_hdr;
2104
2105 n_advance_bytes0 = sctp_header_bytes ();
2106 n_data_bytes0 =
2107 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2108 n_advance_bytes0;
2109 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2110
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002111 trans_conn = session_lookup_connection_wt6 (fib_index0,
2112 &ip6_hdr->dst_address,
2113 &ip6_hdr->src_address,
2114 sctp_hdr->dst_port,
2115 sctp_hdr->src_port,
2116 TRANSPORT_PROTO_SCTP,
2117 my_thread_index,
2118 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002119 }
2120
2121 /* Length check */
2122 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2123 {
2124 error0 = SCTP_ERROR_LENGTH;
2125 goto done;
2126 }
2127
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002128 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01002129 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2130
Marco Varlesefae40392018-02-14 15:38:35 +01002131 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2132 if (chunk_type >= UNKNOWN)
2133 {
2134 clib_warning
2135 ("Received an unrecognized chunk... something is really bad.");
2136 error0 = SCTP_ERROR_UNKOWN_CHUNK;
2137 next0 = SCTP_INPUT_NEXT_DROP;
2138 goto done;
2139 }
2140
Marco Varlese191a5942017-10-30 18:17:21 +01002141 vnet_buffer (b0)->sctp.hdr_offset =
2142 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2143
2144 /* Session exists */
2145 if (PREDICT_TRUE (0 != sctp_conn))
2146 {
2147 /* Save connection index */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002148 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
Marco Varlese191a5942017-10-30 18:17:21 +01002149 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2150 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2151
Marco Varlesefae40392018-02-14 15:38:35 +01002152 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2153 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
Marco Varlese191a5942017-10-30 18:17:21 +01002154
Marco Varlesef3ab4892018-02-19 15:23:13 +01002155 SCTP_DBG_STATE_MACHINE
Marco Varlese15cc6a82018-02-21 12:39:52 +01002156 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
Marco Varlesef3ab4892018-02-19 15:23:13 +01002157 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2158 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002159 connection.s_index,
2160 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
2161 connection.c_index, trans_conn, sctp_conn,
2162 sctp_state_to_string (sctp_conn->state),
Marco Varlesef3ab4892018-02-19 15:23:13 +01002163 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
Marco Varlese191a5942017-10-30 18:17:21 +01002164
Marco Varlesefae40392018-02-14 15:38:35 +01002165 if (chunk_type == DATA)
Marco Varlese191a5942017-10-30 18:17:21 +01002166 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2167 n_advance_bytes0, n_data_bytes0);
2168
2169 }
2170 else
2171 {
2172 if (is_filtered)
2173 {
2174 next0 = SCTP_INPUT_NEXT_DROP;
2175 error0 = SCTP_ERROR_FILTERED;
2176 }
2177 else if ((is_ip4 && tm->punt_unknown4) ||
2178 (!is_ip4 && tm->punt_unknown6))
2179 {
2180 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2181 error0 = SCTP_ERROR_PUNT;
2182 }
2183 else
2184 {
2185 next0 = SCTP_INPUT_NEXT_DROP;
2186 error0 = SCTP_ERROR_NO_LISTENER;
2187 }
2188 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2189 phase_to_string (next0));
2190 sctp_conn = 0;
2191 }
2192
2193 done:
2194 b0->error = error0 ? node->errors[error0] : 0;
2195
2196 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2197 {
2198 sctp_rx_trace_t *t0 =
2199 vlib_add_trace (vm, node, b0, sizeof (*t0));
2200 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2201 }
2202 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2203 n_left_to_next, bi0, next0);
2204 }
2205
2206 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2207 }
2208 return from_frame->n_vectors;
2209}
2210
2211static uword
2212sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2213 vlib_frame_t * from_frame)
2214{
2215 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2216}
2217
2218static uword
2219sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2220 vlib_frame_t * from_frame)
2221{
2222 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2223}
2224
2225/* *INDENT-OFF* */
2226VLIB_REGISTER_NODE (sctp4_input_node) =
2227{
2228 .function = sctp4_input_dispatcher,
2229 .name = "sctp4-input",
2230 /* Takes a vector of packets. */
2231 .vector_size = sizeof (u32),
2232 .n_errors = SCTP_N_ERROR,
2233 .error_strings = sctp_error_strings,
2234 .n_next_nodes = SCTP_INPUT_N_NEXT,
2235 .next_nodes =
2236 {
2237#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2238 foreach_sctp4_input_next
2239#undef _
2240 },
2241 .format_buffer = format_sctp_header,
2242 .format_trace = format_sctp_rx_trace,
2243};
2244/* *INDENT-ON* */
2245
2246VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2247
2248/* *INDENT-OFF* */
2249VLIB_REGISTER_NODE (sctp6_input_node) =
2250{
2251 .function = sctp6_input_dispatcher,
2252 .name = "sctp6-input",
2253 /* Takes a vector of packets. */
2254 .vector_size = sizeof (u32),
2255 .n_errors = SCTP_N_ERROR,
2256 .error_strings = sctp_error_strings,
2257 .n_next_nodes = SCTP_INPUT_N_NEXT,
2258 .next_nodes =
2259 {
2260#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2261 foreach_sctp6_input_next
2262#undef _
2263 },
2264 .format_buffer = format_sctp_header,
2265 .format_trace = format_sctp_rx_trace,
2266};
2267/* *INDENT-ON* */
2268
2269VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2270
2271vlib_node_registration_t sctp4_input_node;
2272vlib_node_registration_t sctp6_input_node;
2273
2274static void
2275sctp_dispatch_table_init (sctp_main_t * tm)
2276{
2277 int i, j;
2278 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2279 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2280 {
2281 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2282 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2283 }
2284
2285#define _(t,f,n,e) \
2286do { \
2287 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2288 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2289} while (0)
2290
2291 /*
2292 * SCTP STATE-MACHINE states:
2293 *
2294 * _(CLOSED, "CLOSED") \
2295 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2296 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2297 * _(ESTABLISHED, "ESTABLISHED") \
2298 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2299 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2300 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2301 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2302 */
Marco Varlesef3ab4892018-02-19 15:23:13 +01002303 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002304 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2305 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2306 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2307 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2308 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2309 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2310 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2311 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2312 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2313 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2314 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2315 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2316 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2317 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002318 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002319
Marco Varlese200fa322018-02-26 16:33:54 +01002320 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002321 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2322 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2323 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2324 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2325 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2326 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2327 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2328 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2329 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2330 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2331 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2332 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2333 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2334 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002335 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2336 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002337
2338 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2339 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2340 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2341 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2342 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2343 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2344 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2345 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2346 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2347 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2348 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2349 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2350 SCTP_ERROR_NONE);
2351 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2352 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2353 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002354 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2355 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002356
2357 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2358 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2359 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2360 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2361 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2362 SCTP_ERROR_NONE);
2363 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2364 SCTP_ERROR_NONE);
2365 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2366 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2367 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2368 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2369 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2370 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2371 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2372 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2373 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002374 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2375 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002376
2377 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2378 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2379 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2380 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2381 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2382 SCTP_ERROR_NONE);
2383 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2384 SCTP_ERROR_NONE);
2385 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2386 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2387 SCTP_ERROR_NONE);
2388 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2389 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2390 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2391 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2392 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2393 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2394 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002395 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2396 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002397
2398 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2399 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2400 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2401 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2402 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2403 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2404 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2405 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2406 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2407 SCTP_ERROR_NONE);
2408 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2409 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2410 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2411 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2412 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002413 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2414 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002415
2416 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2417 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2418 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2419 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2420 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2421 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2422 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2423 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2424 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2425 SCTP_ERROR_NONE);
2426 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2427 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2428 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2429 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2430 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002431 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2432 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002433
2434 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
Marco Varleseeacf3cf2018-02-26 14:52:25 +01002435 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
Marco Varlese191a5942017-10-30 18:17:21 +01002436 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2437 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2438 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2439 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2440 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2441 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2442 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2443 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2444 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2445 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2446 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2447 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2448 SCTP_ERROR_NONE);
Marco Varlese200fa322018-02-26 16:33:54 +01002449 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2450 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002451
2452 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2453
2454#undef _
2455}
2456
2457clib_error_t *
2458sctp_input_init (vlib_main_t * vm)
2459{
2460 clib_error_t *error = 0;
2461 sctp_main_t *tm = vnet_get_sctp_main ();
2462
2463 if ((error = vlib_call_init_function (vm, sctp_init)))
2464 return error;
2465
2466 /* Initialize dispatch table. */
2467 sctp_dispatch_table_init (tm);
2468
2469 return error;
2470}
2471
2472VLIB_INIT_FUNCTION (sctp_input_init);
2473
2474/*
2475 * fd.io coding-style-patch-verification: ON
2476 *
2477 * Local Variables:
2478 * eval: (c-set-style "gnu")
2479 * End:
2480 */