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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
22 static char *sctp_error_strings[] = {
23 #define sctp_error(n,s) s,
24 #include <vnet/sctp/sctp_error.def>
28 /* All SCTP nodes have the same outgoing arcs */
29 #define foreach_sctp_state_next \
30 _ (DROP4, "ip4-drop") \
31 _ (DROP6, "ip6-drop") \
32 _ (SCTP4_OUTPUT, "sctp4-output") \
33 _ (SCTP6_OUTPUT, "sctp6-output")
35 typedef enum _sctp_established_phase_next
37 #define _(s,n) SCTP_ESTABLISHED_PHASE_NEXT_##s,
38 foreach_sctp_state_next
40 SCTP_ESTABLISHED_PHASE_N_NEXT,
41 } sctp_established_phase_next_t;
43 typedef enum _sctp_rcv_phase_next
45 #define _(s,n) SCTP_RCV_PHASE_NEXT_##s,
46 foreach_sctp_state_next
48 SCTP_RCV_PHASE_N_NEXT,
49 } sctp_rcv_phase_next_t;
51 typedef enum _sctp_listen_phase_next
53 #define _(s,n) SCTP_LISTEN_PHASE_NEXT_##s,
54 foreach_sctp_state_next
56 SCTP_LISTEN_PHASE_N_NEXT,
57 } sctp_listen_phase_next_t;
59 typedef enum _sctp_shutdown_phase_next
61 #define _(s,n) SCTP_SHUTDOWN_PHASE_NEXT_##s,
62 foreach_sctp_state_next
64 SCTP_SHUTDOWN_PHASE_N_NEXT,
65 } sctp_shutdown_phase_next_t;
67 /* Generic, state independent indices */
68 typedef enum _sctp_state_next
70 #define _(s,n) SCTP_NEXT_##s,
71 foreach_sctp_state_next
76 typedef enum _sctp_input_next
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,
88 phase_to_string (u8 phase)
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";
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")
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")
126 sctp_lookup_is_valid (transport_connection_t * trans_conn,
127 sctp_header_t * sctp_hdr)
129 sctp_connection_t *sctp_conn =
130 sctp_get_connection_from_transport (trans_conn);
135 u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
136 && (sctp_conn->state == SCTP_STATE_CLOSED
137 || trans_conn->rmt_port == sctp_hdr->src_port));
143 * Lookup transport connection
145 static sctp_connection_t *
146 sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
149 sctp_main_t *tm = vnet_get_sctp_main ();
150 sctp_header_t *sctp_hdr;
151 transport_connection_t *trans_conn;
152 sctp_connection_t *sctp_conn;
156 ip4_header_t *ip4_hdr;
157 ip4_hdr = vlib_buffer_get_current (b);
158 sctp_hdr = ip4_next_header (ip4_hdr);
159 trans_conn = session_lookup_connection_wt4 (fib_index,
160 &ip4_hdr->dst_address,
161 &ip4_hdr->src_address,
164 TRANSPORT_PROTO_SCTP,
165 thread_index, &is_filtered);
166 if (trans_conn == 0) /* Not primary connection */
168 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
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))
178 &tm->connections[thread_index]->sub_conn[i].connection;
183 ASSERT (trans_conn != 0);
184 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
188 ip6_header_t *ip6_hdr;
189 ip6_hdr = vlib_buffer_get_current (b);
190 sctp_hdr = ip6_next_header (ip6_hdr);
191 trans_conn = session_lookup_connection_wt6 (fib_index,
192 &ip6_hdr->dst_address,
193 &ip6_hdr->src_address,
196 TRANSPORT_PROTO_SCTP,
197 thread_index, &is_filtered);
198 if (trans_conn == 0) /* Not primary connection */
200 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
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]))
216 &tm->connections[thread_index]->sub_conn[i].connection;
221 ASSERT (trans_conn != 0);
222 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
224 sctp_conn = sctp_get_connection_from_transport (trans_conn);
230 sctp_header_t sctp_header;
231 sctp_connection_t sctp_connection;
234 #define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
235 : SCTP_NEXT_SCTP6_OUTPUT)
237 #define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
241 sctp_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,
248 clib_memcpy (&rx_trace->sctp_connection, sctp_conn,
249 sizeof (rx_trace->sctp_connection));
253 sctp_hdr = sctp_buffer_hdr (b0);
255 clib_memcpy (&rx_trace->sctp_header, sctp_hdr,
256 sizeof (rx_trace->sctp_header));
260 sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
263 u16 sctp_implied_packet_length = 0;
266 sctp_implied_packet_length =
267 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
269 sctp_implied_packet_length =
270 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
272 return sctp_implied_packet_length;
276 sctp_is_bundling (u16 sctp_implied_length,
277 sctp_chunks_common_hdr_t * sctp_common_hdr)
279 if (sctp_implied_length !=
280 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
286 sctp_handle_operation_err (sctp_header_t * sctp_hdr,
287 sctp_connection_t * sctp_conn, u8 idx,
288 vlib_buffer_t * b, u16 * next0)
290 sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
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)
295 return SCTP_ERROR_INVALID_TAG;
298 if (op_err->err_causes[0].cause_info == STALE_COOKIE_ERROR)
300 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
301 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
304 sctp_connection_cleanup (sctp_conn);
306 stream_session_disconnect_notify (&sctp_conn->
307 sub_conn[idx].connection);
311 return SCTP_ERROR_NONE;
315 sctp_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)
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];
325 /* Check the current state of the connection
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.
332 if (sctp_conn->state != SCTP_STATE_CLOSED)
333 { /* UNEXPECTED scenario */
334 switch (sctp_conn->state)
336 case SCTP_STATE_COOKIE_WAIT:
337 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
338 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:
344 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
345 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);
350 sctp_prepare_abort_for_collision (sctp_conn,
351 MAIN_SCTP_SUB_CONN_IDX, b0,
353 return SCTP_ERROR_NONE;
357 if (sctp_hdr->verification_tag != 0x0)
358 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
361 * It is not possible to bundle any other CHUNK with the INIT chunk
363 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
364 return SCTP_ERROR_BUNDLING_VIOLATION;
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;
369 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);
376 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
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.
382 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
383 if (length > sizeof (sctp_init_chunk_t))
385 /* There are optional parameters in the INIT chunk */
386 u16 pointer_offset = sizeof (sctp_init_chunk_t);
387 while (pointer_offset < length)
389 sctp_opt_params_hdr_t *opt_params_hdr =
390 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
392 switch (clib_net_to_host_u16 (opt_params_hdr->type))
394 case SCTP_IPV4_ADDRESS_TYPE:
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));
401 sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
405 case SCTP_IPV6_ADDRESS_TYPE:
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));
412 sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
416 case SCTP_COOKIE_PRESERVATIVE_TYPE:
418 sctp_cookie_preservative_param_t *cookie_pres =
419 (sctp_cookie_preservative_param_t *) opt_params_hdr;
420 sctp_conn->peer_cookie_life_span_increment =
421 cookie_pres->life_span_inc;
424 case SCTP_HOSTNAME_ADDRESS_TYPE:
426 sctp_hostname_param_t *hostname_addr =
427 (sctp_hostname_param_t *) opt_params_hdr;
428 clib_memcpy (hostname, hostname_addr->hostname,
432 case SCTP_SUPPORTED_ADDRESS_TYPES:
438 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
442 /* Reuse buffer to make init-ack and send */
443 sctp_prepare_initack_chunk (sctp_conn, MAIN_SCTP_SUB_CONN_IDX, b0, ip4_addr,
445 return SCTP_ERROR_NONE;
449 sctp_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)
454 sctp_init_ack_chunk_t *init_ack_chunk =
455 (sctp_init_ack_chunk_t *) (sctp_hdr);
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)
460 return SCTP_ERROR_INVALID_TAG;
464 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
466 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
467 return SCTP_ERROR_BUNDLING_VIOLATION;
469 return SCTP_ERROR_NONE;
473 sctp_handle_init_ack (sctp_header_t * sctp_hdr,
474 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
475 sctp_connection_t * sctp_conn, u8 idx,
476 vlib_buffer_t * b0, u16 sctp_implied_length)
478 sctp_init_ack_chunk_t *init_ack_chunk =
479 (sctp_init_ack_chunk_t *) (sctp_hdr);
480 sctp_state_cookie_param_t state_cookie;
482 char hostname[FQDN_MAX_LENGTH];
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)
487 return SCTP_ERROR_INVALID_TAG;
491 * It is not possible to bundle any other CHUNK with the INIT chunk
493 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
494 return SCTP_ERROR_BUNDLING_VIOLATION;
496 sctp_calculate_rto (sctp_conn, idx);
498 /* 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;
500 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);
506 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
508 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
510 if (length > sizeof (sctp_init_ack_chunk_t))
512 * There are optional parameters in the INIT ACK chunk
515 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
517 while (pointer_offset < length)
519 sctp_opt_params_hdr_t *opt_params_hdr =
520 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
523 switch (clib_net_to_host_u16 (opt_params_hdr->type))
525 case SCTP_IPV4_ADDRESS_TYPE:
527 sctp_ipv4_addr_param_t *ipv4 =
528 (sctp_ipv4_addr_param_t *) opt_params_hdr;
530 sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
534 case SCTP_IPV6_ADDRESS_TYPE:
536 sctp_ipv6_addr_param_t *ipv6 =
537 (sctp_ipv6_addr_param_t *) opt_params_hdr;
539 sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
543 case SCTP_STATE_COOKIE_TYPE:
545 sctp_state_cookie_param_t *state_cookie_param =
546 (sctp_state_cookie_param_t *) opt_params_hdr;
548 clib_memcpy (&state_cookie, state_cookie_param,
549 sizeof (sctp_state_cookie_param_t));
552 case SCTP_HOSTNAME_ADDRESS_TYPE:
554 sctp_hostname_param_t *hostname_addr =
555 (sctp_hostname_param_t *) opt_params_hdr;
556 clib_memcpy (hostname, hostname_addr->hostname,
560 case SCTP_UNRECOGNIZED_TYPE:
565 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
566 /* This indicates something really bad happened */
569 return SCTP_ERROR_INVALID_TAG;
571 pointer_offset += increment;
575 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, &state_cookie);
577 /* Start the T1_COOKIE timer */
578 sctp_timer_set (sctp_conn, idx,
579 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
581 return SCTP_ERROR_NONE;
584 /** Enqueue data out-of-order for delivery to application */
586 sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
587 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
589 int written, error = SCTP_ERROR_ENQUEUED;
592 session_enqueue_stream_connection (&sctp_conn->
593 sub_conn[conn_idx].connection, b, 0,
594 1 /* queue event */ ,
597 /* Update next_tsn_expected */
598 if (PREDICT_TRUE (written == data_len))
600 sctp_conn->next_tsn_expected += written;
602 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
603 sctp_conn->sub_conn[conn_idx].connection.c_index,
606 /* If more data written than expected, account for out-of-order bytes. */
607 else if (written > data_len)
609 sctp_conn->next_tsn_expected += written;
611 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
612 sctp_conn->sub_conn[conn_idx].connection.c_index,
615 else if (written > 0)
617 /* We've written something but FIFO is probably full now */
618 sctp_conn->next_tsn_expected += written;
620 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
623 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
624 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
628 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
629 sctp_conn->sub_conn[conn_idx].connection.c_index);
631 return SCTP_ERROR_FIFO_FULL;
634 /* TODO: Update out_of_order_map & SACK list */
639 /** Enqueue data for delivery to application */
641 sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
642 u16 data_len, u8 conn_idx)
644 int written, error = SCTP_ERROR_ENQUEUED;
647 session_enqueue_stream_connection (&sctp_conn->
648 sub_conn[conn_idx].connection, b, 0,
649 1 /* queue event */ ,
652 /* Update next_tsn_expected */
653 if (PREDICT_TRUE (written == data_len))
655 sctp_conn->next_tsn_expected += written;
657 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
658 sctp_conn->sub_conn[conn_idx].connection.c_index,
661 /* If more data written than expected, account for out-of-order bytes. */
662 else if (written > data_len)
664 sctp_conn->next_tsn_expected += written;
666 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
667 sctp_conn->sub_conn[conn_idx].connection.c_index,
670 else if (written > 0)
672 /* We've written something but FIFO is probably full now */
673 sctp_conn->next_tsn_expected += written;
675 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
678 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
679 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
683 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
684 sctp_conn->sub_conn[conn_idx].connection.c_index);
686 return SCTP_ERROR_FIFO_FULL;
693 sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
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);
703 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
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);
711 sctp_conn->ack_state += 1;
717 sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
720 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
722 SCTP_CONN_TRACKING_DBG
723 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
724 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.c_index,
725 sctp_conn->next_tsn_expected, tsn,
726 sctp_conn->next_tsn_expected - tsn);
733 sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
734 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
737 u32 error = 0, n_data_bytes;
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)
743 return SCTP_ERROR_INVALID_TAG;
746 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
747 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
749 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
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);
755 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
757 sctp_conn->last_rcvd_tsn = tsn;
759 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
761 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
762 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
764 if (bbit == 1 && ebit == 1) /* Unfragmented message */
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. */
768 if (PREDICT_FALSE (is_gapping == 1))
770 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
772 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
774 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
776 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
778 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
780 if (PREDICT_FALSE (is_gapping == 1))
782 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
784 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
786 else /* Middle piece of a fragmented user message */
788 if (PREDICT_FALSE (is_gapping == 1))
790 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
792 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
794 sctp_conn->last_rcvd_tsn = tsn;
796 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
798 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
800 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
801 sctp_prepare_sack_chunk (sctp_conn, idx, b);
803 sctp_conn->sub_conn[idx].enqueue_state = error;
809 sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
810 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
811 sctp_connection_t * sctp_conn, u8 idx,
812 vlib_buffer_t * b0, u16 * next0)
814 u32 now = sctp_time_now ();
816 sctp_cookie_echo_chunk_t *cookie_echo =
817 (sctp_cookie_echo_chunk_t *) sctp_hdr;
819 /* 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)
822 return SCTP_ERROR_INVALID_TAG;
825 sctp_calculate_rto (sctp_conn, idx);
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)
833 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
834 now, creation_time, cookie_lifespan);
835 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
838 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
841 sctp_conn->state = SCTP_STATE_ESTABLISHED;
842 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
843 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
845 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
846 sctp_conn->sub_conn[idx].RTO);
848 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
850 return SCTP_ERROR_NONE;
855 sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
856 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
857 sctp_connection_t * sctp_conn, u8 idx,
858 vlib_buffer_t * b0, u16 * next0)
860 /* 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)
863 return SCTP_ERROR_INVALID_TAG;
866 sctp_calculate_rto (sctp_conn, idx);
868 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
870 sctp_conn->state = SCTP_STATE_ESTABLISHED;
871 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
873 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
875 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
876 sctp_conn->sub_conn[idx].RTO);
878 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
880 return SCTP_ERROR_NONE;
885 sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
886 vlib_frame_t * from_frame, int is_ip4)
888 sctp_main_t *tm = vnet_get_sctp_main ();
890 u32 n_left_from, next_index, *from, *to_next;
891 u32 my_thread_index = vm->thread_index;
893 from = vlib_frame_vector_args (from_frame);
894 n_left_from = from_frame->n_vectors;
896 next_index = node->cached_next_index;
898 while (n_left_from > 0)
902 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
904 while (n_left_from > 0 && n_left_to_next > 0)
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;
914 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
924 b0 = vlib_get_buffer (vm, bi0);
926 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
927 * will come from the half-open connections pool.
930 sctp_half_open_connection_get (vnet_buffer (b0)->
931 sctp.connection_index);
933 if (PREDICT_FALSE (sctp_conn == 0))
936 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
937 error0 = SCTP_ERROR_INVALID_CONNECTION;
942 ip4_hdr = vlib_buffer_get_current (b0);
943 sctp_hdr = ip4_next_header (ip4_hdr);
944 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
948 ip6_hdr = vlib_buffer_get_current (b0);
949 sctp_hdr = ip6_next_header (ip6_hdr);
950 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
953 sctp_conn->sub_conn[idx].subconn_idx = idx;
954 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
957 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
959 sctp_implied_length =
960 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
962 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
968 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
969 b0, sctp_implied_length);
971 if (error0 == SCTP_ERROR_NONE)
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 =
980 new_sctp_conn->sub_conn[idx].PMTU =
981 sctp_conn->sub_conn[idx].PMTU;
982 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
984 if (sctp_half_open_connection_cleanup (sctp_conn))
987 ("Cannot cleanup half-open connection; not the owning thread");
990 sctp_connection_timers_init (new_sctp_conn);
993 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
994 new_sctp_conn, idx, b0,
995 sctp_implied_length);
997 sctp_init_cwnd (new_sctp_conn);
999 if (session_stream_connect_notify
1000 (&new_sctp_conn->sub_conn[idx].connection, 0))
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);
1008 next0 = sctp_next_output (is_ip4);
1012 case OPERATION_ERROR:
1014 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1018 /* 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.
1023 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1024 next0 = sctp_next_drop (is_ip4);
1028 if (error0 != SCTP_ERROR_NONE)
1030 clib_warning ("error while parsing chunk");
1031 sctp_connection_cleanup (sctp_conn);
1032 next0 = sctp_next_drop (is_ip4);
1037 b0->error = node->errors[error0];
1038 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
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);
1045 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1046 n_left_to_next, bi0, next0);
1049 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1051 return from_frame->n_vectors;
1055 sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1056 vlib_frame_t * from_frame)
1058 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1062 sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1063 vlib_frame_t * from_frame)
1065 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1069 format_sctp_rx_trace_short (u8 * s, va_list * args)
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 *);
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);
1084 VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
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,
1095 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1096 foreach_sctp_state_next
1099 .format_trace = format_sctp_rx_trace_short,
1103 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1106 VLIB_REGISTER_NODE (sctp6_init_phase_node) =
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,
1117 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1118 foreach_sctp_state_next
1121 .format_trace = format_sctp_rx_trace_short,
1125 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1127 vlib_node_registration_t sctp4_shutdown_phase_node;
1128 vlib_node_registration_t sctp6_shutdown_phase_node;
1131 sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1132 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1133 sctp_connection_t * sctp_conn, u8 idx,
1134 vlib_buffer_t * b0, u16 sctp_implied_length,
1137 sctp_shutdown_association_chunk_t *shutdown_chunk =
1138 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
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)
1143 return SCTP_ERROR_INVALID_TAG;
1147 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1149 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1150 return SCTP_ERROR_BUNDLING_VIOLATION;
1152 switch (sctp_conn->state)
1154 case SCTP_STATE_ESTABLISHED:
1155 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1156 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
1157 sctp_send_shutdown_ack (sctp_conn, idx, b0);
1160 case SCTP_STATE_SHUTDOWN_SENT:
1161 sctp_send_shutdown_ack (sctp_conn, idx, b0);
1165 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1167 return SCTP_ERROR_NONE;
1171 sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1172 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1173 sctp_connection_t * sctp_conn, u8 idx,
1174 vlib_buffer_t * b0, u16 sctp_implied_length,
1177 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1178 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
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)
1183 return SCTP_ERROR_INVALID_TAG;
1187 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1189 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1190 return SCTP_ERROR_BUNDLING_VIOLATION;
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
1197 sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
1198 SCTP_TIMER_T2_SHUTDOWN);
1200 sctp_send_shutdown_complete (sctp_conn, idx, b0);
1202 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1204 return SCTP_ERROR_NONE;
1208 sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1209 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1210 sctp_connection_t * sctp_conn, u8 idx,
1211 vlib_buffer_t * b0, u16 sctp_implied_length,
1214 sctp_shutdown_complete_chunk_t *shutdown_complete =
1215 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
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)
1220 return SCTP_ERROR_INVALID_TAG;
1224 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1226 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1227 return SCTP_ERROR_BUNDLING_VIOLATION;
1229 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1231 stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
1233 sctp_conn->state = SCTP_STATE_CLOSED;
1235 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1237 return SCTP_ERROR_NONE;
1241 sctp46_shutdown_phase_inline (vlib_main_t * vm,
1242 vlib_node_runtime_t * node,
1243 vlib_frame_t * from_frame, int is_ip4)
1245 u32 n_left_from, next_index, *from, *to_next;
1246 u32 my_thread_index = vm->thread_index;
1248 from = vlib_frame_vector_args (from_frame);
1249 n_left_from = from_frame->n_vectors;
1251 next_index = node->cached_next_index;
1253 while (n_left_from > 0)
1257 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1259 while (n_left_from > 0 && n_left_to_next > 0)
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;
1278 n_left_to_next -= 1;
1280 b0 = vlib_get_buffer (vm, bi0);
1282 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1285 if (PREDICT_FALSE (sctp_conn == 0))
1288 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1289 error0 = SCTP_ERROR_INVALID_CONNECTION;
1295 ip4_hdr = vlib_buffer_get_current (b0);
1296 sctp_hdr = ip4_next_header (ip4_hdr);
1297 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1301 ip6_hdr = vlib_buffer_get_current (b0);
1302 sctp_hdr = ip6_next_header (ip6_hdr);
1303 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1306 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1307 sctp_chunk_hdr = &full_hdr->common_hdr;
1309 sctp_implied_length =
1310 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1312 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1317 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1318 idx, b0, sctp_implied_length, &next0);
1323 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1324 idx, b0, sctp_implied_length,
1328 case SHUTDOWN_COMPLETE:
1330 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
1332 sctp_implied_length, &next0);
1334 sctp_connection_cleanup (sctp_conn);
1338 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1339 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1343 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1344 sctp_conn, idx, b0, &next0);
1347 case OPERATION_ERROR:
1349 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1353 /* 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.
1358 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1359 next0 = sctp_next_drop (is_ip4);
1363 if (error0 != SCTP_ERROR_NONE)
1365 clib_warning ("error while parsing chunk");
1366 sctp_connection_cleanup (sctp_conn);
1367 next0 = sctp_next_drop (is_ip4);
1372 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1375 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
1377 if (sctp_hdr != NULL)
1378 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1379 sizeof (sctp_trace->sctp_header));
1381 if (sctp_conn != NULL)
1382 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1383 sizeof (sctp_trace->sctp_connection));
1386 b0->error = node->errors[error0];
1388 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1389 n_left_to_next, bi0, next0);
1392 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1395 return from_frame->n_vectors;
1400 sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1401 vlib_frame_t * from_frame)
1403 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1407 sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1408 vlib_frame_t * from_frame)
1410 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1414 VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
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,
1425 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1426 foreach_sctp_state_next
1429 .format_trace = format_sctp_rx_trace_short,
1433 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1434 sctp4_shutdown_phase);
1437 VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
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,
1448 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1449 foreach_sctp_state_next
1452 .format_trace = format_sctp_rx_trace_short,
1456 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1457 sctp6_shutdown_phase);
1459 vlib_node_registration_t sctp4_listen_phase_node;
1460 vlib_node_registration_t sctp6_listen_phase_node;
1462 vlib_node_registration_t sctp4_established_phase_node;
1463 vlib_node_registration_t sctp6_established_phase_node;
1466 sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
1467 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
1470 /* 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)
1473 return SCTP_ERROR_INVALID_TAG;
1476 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1478 /* 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;
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;
1487 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1489 sctp_calculate_rto (sctp_conn, idx);
1491 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1492 sctp_conn->sub_conn[idx].RTO);
1494 sctp_conn->sub_conn[idx].RTO_pending = 0;
1496 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1498 return SCTP_ERROR_NONE;
1502 sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
1503 sctp_connection_t * sctp_conn, u8 idx,
1504 vlib_buffer_t * b0, u16 * next0)
1506 /* 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)
1509 return SCTP_ERROR_INVALID_TAG;
1512 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
1514 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1516 return SCTP_ERROR_NONE;
1520 sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
1521 sctp_connection_t * sctp_conn, u8 idx,
1522 vlib_buffer_t * b0, u16 * next0)
1524 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1526 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1528 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1529 sctp_conn->sub_conn[idx].RTO);
1531 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1533 return SCTP_ERROR_NONE;
1537 sctp_node_inc_counter (vlib_main_t * vm, u32 tcp4_node, u32 tcp6_node,
1538 u8 is_ip4, u8 evt, u8 val)
1540 if (PREDICT_TRUE (!val))
1544 vlib_node_increment_counter (vm, tcp4_node, evt, val);
1546 vlib_node_increment_counter (vm, tcp6_node, evt, val);
1550 sctp46_listen_process_inline (vlib_main_t * vm,
1551 vlib_node_runtime_t * node,
1552 vlib_frame_t * from_frame, int is_ip4)
1554 u32 n_left_from, next_index, *from, *to_next;
1555 u32 my_thread_index = vm->thread_index;
1557 from = vlib_frame_vector_args (from_frame);
1558 n_left_from = from_frame->n_vectors;
1560 next_index = node->cached_next_index;
1562 while (n_left_from > 0)
1566 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1568 while (n_left_from > 0 && n_left_to_next > 0)
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;
1577 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
1584 n_left_to_next -= 1;
1586 b0 = vlib_get_buffer (vm, bi0);
1588 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1592 ip4_hdr = vlib_buffer_get_current (b0);
1593 sctp_hdr = ip4_next_header (ip4_hdr);
1597 ip6_hdr = vlib_buffer_get_current (b0);
1598 sctp_hdr = ip6_next_header (ip6_hdr);
1602 sctp_lookup_connection (sctp_listener->sub_conn
1603 [MAIN_SCTP_SUB_CONN_IDX].c_fib_index, b0,
1604 my_thread_index, is_ip4);
1606 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1609 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1610 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1612 sctp_state_to_string (child_conn->state));
1613 error0 = SCTP_ERROR_CREATE_EXISTS;
1617 /* Create child session and send SYN-ACK */
1618 child_conn = sctp_connection_new (my_thread_index);
1619 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].subconn_idx =
1620 MAIN_SCTP_SUB_CONN_IDX;
1621 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_port =
1623 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_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;
1628 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU =
1629 sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU;
1630 child_conn->state = SCTP_STATE_CLOSED;
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;
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));
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;
1652 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1653 if (chunk_type != INIT)
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));
1660 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1661 next0 = sctp_next_drop (is_ip4);
1665 u16 sctp_implied_length =
1666 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1671 sctp_connection_timers_init (child_conn);
1673 sctp_init_snd_vars (child_conn);
1676 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1677 sctp_implied_length);
1679 sctp_init_cwnd (child_conn);
1681 if (error0 == SCTP_ERROR_NONE)
1683 if (stream_session_accept
1685 sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection,
1687 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index, 0))
1689 clib_warning ("session accept fail");
1690 sctp_connection_cleanup (child_conn);
1691 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1694 next0 = sctp_next_output (is_ip4);
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
1705 case OPERATION_ERROR:
1707 sctp_handle_operation_err (sctp_hdr, child_conn,
1708 MAIN_SCTP_SUB_CONN_IDX, b0,
1714 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
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));
1724 b0->error = node->errors[error0];
1726 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1727 n_left_to_next, bi0, next0);
1729 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1732 return from_frame->n_vectors;
1736 sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1737 vlib_frame_t * from_frame)
1739 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1743 sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1744 vlib_frame_t * from_frame)
1746 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1750 sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1751 vlib_frame_t * from_frame, int is_ip4)
1753 u32 n_left_from, next_index, *from, *to_next;
1754 u32 my_thread_index = vm->thread_index, errors = 0;
1756 from = vlib_frame_vector_args (from_frame);
1757 n_left_from = from_frame->n_vectors;
1759 next_index = node->cached_next_index;
1761 while (n_left_from > 0)
1765 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1767 while (n_left_from > 0 && n_left_to_next > 0)
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;
1776 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1777 SCTP_ESTABLISHED_PHASE_N_NEXT;
1785 n_left_to_next -= 1;
1787 b0 = vlib_get_buffer (vm, bi0);
1789 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1792 if (PREDICT_FALSE (sctp_conn == 0))
1795 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1796 error0 = SCTP_ERROR_INVALID_CONNECTION;
1801 ip4_hdr = vlib_buffer_get_current (b0);
1802 sctp_hdr = ip4_next_header (ip4_hdr);
1803 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1807 ip6_hdr = vlib_buffer_get_current (b0);
1808 sctp_hdr = ip6_next_header (ip6_hdr);
1809 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1812 sctp_conn->sub_conn[idx].subconn_idx = idx;
1814 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1816 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1818 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1824 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1830 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1836 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
1837 sctp_conn, idx, b0, &next0);
1842 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
1843 sctp_conn, idx, b0, &next0);
1848 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
1849 sctp_conn, idx, b0, &next0);
1854 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1855 sctp_conn, idx, b0, &next0);
1858 case OPERATION_ERROR:
1860 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1864 /* 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.
1869 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1870 next0 = sctp_next_drop (is_ip4);
1875 b0->error = node->errors[error0];
1876 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
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);
1883 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1884 n_left_to_next, bi0, next0);
1887 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1890 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
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);
1898 return from_frame->n_vectors;
1902 sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1903 vlib_frame_t * from_frame)
1905 return sctp46_established_phase_inline (vm, node, from_frame,
1910 sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1911 vlib_frame_t * from_frame)
1913 return sctp46_established_phase_inline (vm, node, from_frame,
1918 format_sctp_rx_trace (u8 * s, va_list * args)
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);
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);
1934 VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
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,
1945 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1946 foreach_sctp_state_next
1949 .format_trace = format_sctp_rx_trace_short,
1953 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
1956 VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
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,
1967 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1968 foreach_sctp_state_next
1971 .format_trace = format_sctp_rx_trace_short,
1975 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
1978 VLIB_REGISTER_NODE (sctp4_established_phase_node) =
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,
1989 #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
1990 foreach_sctp_state_next
1993 .format_trace = format_sctp_rx_trace_short,
1997 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
1998 sctp4_established_phase);
2001 VLIB_REGISTER_NODE (sctp6_established_phase_node) =
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,
2012 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2013 foreach_sctp_state_next
2016 .format_trace = format_sctp_rx_trace_short,
2020 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2021 sctp6_established_phase);
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.
2029 sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2030 vlib_frame_t * from_frame, int is_ip4)
2032 u32 n_left_from, next_index, *from, *to_next;
2033 u32 my_thread_index = vm->thread_index;
2035 sctp_main_t *tm = vnet_get_sctp_main ();
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);
2042 while (n_left_from > 0)
2046 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2048 while (n_left_from > 0 && n_left_to_next > 0)
2050 int n_advance_bytes0, n_data_bytes0;
2051 u32 bi0, fib_index0;
2053 sctp_header_t *sctp_hdr = 0;
2054 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2055 sctp_connection_t *sctp_conn;
2056 transport_connection_t *trans_conn;
2057 ip4_header_t *ip4_hdr;
2058 ip6_header_t *ip6_hdr;
2059 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2066 n_left_to_next -= 1;
2068 b0 = vlib_get_buffer (vm, bi0);
2069 vnet_buffer (b0)->tcp.flags = 0;
2070 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2072 /* Checksum computed by ipx_local no need to compute again */
2076 ip4_hdr = vlib_buffer_get_current (b0);
2077 sctp_hdr = ip4_next_header (ip4_hdr);
2079 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2080 sctp_chunk_hdr = &full_hdr->common_hdr;
2083 (ip4_header_bytes (ip4_hdr) +
2084 sizeof (sctp_payload_data_chunk_t));
2086 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2088 trans_conn = session_lookup_connection_wt4 (fib_index0,
2089 &ip4_hdr->dst_address,
2090 &ip4_hdr->src_address,
2093 TRANSPORT_PROTO_SCTP,
2099 ip6_hdr = vlib_buffer_get_current (b0);
2100 sctp_hdr = ip6_next_header (ip6_hdr);
2102 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2103 sctp_chunk_hdr = &full_hdr->common_hdr;
2105 n_advance_bytes0 = sctp_header_bytes ();
2107 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2109 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2111 trans_conn = session_lookup_connection_wt6 (fib_index0,
2112 &ip6_hdr->dst_address,
2113 &ip6_hdr->src_address,
2116 TRANSPORT_PROTO_SCTP,
2122 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2124 error0 = SCTP_ERROR_LENGTH;
2128 sctp_conn = sctp_get_connection_from_transport (trans_conn);
2129 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2131 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2132 if (chunk_type >= UNKNOWN)
2135 ("Received an unrecognized chunk... something is really bad.");
2136 error0 = SCTP_ERROR_UNKOWN_CHUNK;
2137 next0 = SCTP_INPUT_NEXT_DROP;
2141 vnet_buffer (b0)->sctp.hdr_offset =
2142 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2144 /* Session exists */
2145 if (PREDICT_TRUE (0 != sctp_conn))
2147 /* Save connection index */
2148 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
2149 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2150 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2152 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2153 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
2155 SCTP_DBG_STATE_MACHINE
2156 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
2157 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2158 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
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),
2163 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
2165 if (chunk_type == DATA)
2166 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2167 n_advance_bytes0, n_data_bytes0);
2174 next0 = SCTP_INPUT_NEXT_DROP;
2175 error0 = SCTP_ERROR_FILTERED;
2177 else if ((is_ip4 && tm->punt_unknown4) ||
2178 (!is_ip4 && tm->punt_unknown6))
2180 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2181 error0 = SCTP_ERROR_PUNT;
2185 next0 = SCTP_INPUT_NEXT_DROP;
2186 error0 = SCTP_ERROR_NO_LISTENER;
2188 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2189 phase_to_string (next0));
2194 b0->error = error0 ? node->errors[error0] : 0;
2196 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
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);
2202 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2203 n_left_to_next, bi0, next0);
2206 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2208 return from_frame->n_vectors;
2212 sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2213 vlib_frame_t * from_frame)
2215 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2219 sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2220 vlib_frame_t * from_frame)
2222 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2226 VLIB_REGISTER_NODE (sctp4_input_node) =
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,
2237 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2238 foreach_sctp4_input_next
2241 .format_buffer = format_sctp_header,
2242 .format_trace = format_sctp_rx_trace,
2246 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2249 VLIB_REGISTER_NODE (sctp6_input_node) =
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,
2260 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2261 foreach_sctp6_input_next
2264 .format_buffer = format_sctp_header,
2265 .format_trace = format_sctp_rx_trace,
2269 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2271 vlib_node_registration_t sctp4_input_node;
2272 vlib_node_registration_t sctp6_input_node;
2275 sctp_dispatch_table_init (sctp_main_t * tm)
2278 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2279 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2281 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2282 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2285 #define _(t,f,n,e) \
2287 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2288 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2292 * SCTP STATE-MACHINE states:
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")
2303 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2304 _(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 */
2318 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2320 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2321 _(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 */
2335 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
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,
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 */
2354 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
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,
2363 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
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 */
2374 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
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,
2383 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
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,
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 */
2395 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
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,
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 */
2413 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
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,
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 */
2431 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2434 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2435 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
2436 _(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,
2449 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2452 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2458 sctp_input_init (vlib_main_t * vm)
2460 clib_error_t *error = 0;
2461 sctp_main_t *tm = vnet_get_sctp_main ();
2463 if ((error = vlib_call_init_function (vm, sctp_init)))
2466 /* Initialize dispatch table. */
2467 sctp_dispatch_table_init (tm);
2472 VLIB_INIT_FUNCTION (sctp_input_init);
2475 * fd.io coding-style-patch-verification: ON
2478 * eval: (c-set-style "gnu")