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 (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
301 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
302 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
305 sctp_connection_cleanup (sctp_conn);
307 stream_session_disconnect_notify (&sctp_conn->
308 sub_conn[idx].connection);
312 return SCTP_ERROR_NONE;
316 sctp_handle_init (sctp_header_t * sctp_hdr,
317 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
318 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
319 u16 sctp_implied_length)
321 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
322 ip4_address_t *ip4_addr = 0;
323 ip6_address_t *ip6_addr = 0;
324 char hostname[FQDN_MAX_LENGTH];
326 /* Check the current state of the connection
328 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
329 * in the code below and by the "sctp_prepare_initack_chunk" function.
330 * However, for debugging purposes it is nice to have a message printed out
331 * for these corner-case scenarios.
333 if (sctp_conn->state != SCTP_STATE_CLOSED)
334 { /* UNEXPECTED scenario */
335 switch (sctp_conn->state)
337 case SCTP_STATE_COOKIE_WAIT:
338 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
339 sctp_prepare_initack_chunk_for_collision (sctp_conn,
340 SCTP_PRIMARY_PATH_IDX,
341 b0, ip4_addr, ip6_addr);
342 return SCTP_ERROR_NONE;
343 case SCTP_STATE_COOKIE_ECHOED:
344 case SCTP_STATE_SHUTDOWN_ACK_SENT:
345 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
346 if (sctp_conn->forming_association_changed == 0)
347 sctp_prepare_initack_chunk_for_collision (sctp_conn,
348 SCTP_PRIMARY_PATH_IDX,
349 b0, ip4_addr, ip6_addr);
351 sctp_prepare_abort_for_collision (sctp_conn,
352 SCTP_PRIMARY_PATH_IDX, b0,
354 return SCTP_ERROR_NONE;
358 if (sctp_hdr->verification_tag != 0x0)
359 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
362 * It is not possible to bundle any other CHUNK with the INIT chunk
364 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
365 return SCTP_ERROR_BUNDLING_VIOLATION;
367 /* Save the INITIATE_TAG of the remote peer for this connection:
368 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
369 sctp_conn->remote_tag = init_chunk->initiate_tag;
370 sctp_conn->remote_initial_tsn =
371 clib_net_to_host_u32 (init_chunk->initial_tsn);
372 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
373 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
374 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
375 sctp_conn->remote_initial_tsn);
377 sctp_conn->peer_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_main (),
403 [SCTP_PRIMARY_PATH_IDX].connection.
404 lcl_ip.ip4, &ipv4->address);
408 case SCTP_IPV6_ADDRESS_TYPE:
410 sctp_ipv6_addr_param_t *ipv6 =
411 (sctp_ipv6_addr_param_t *) opt_params_hdr;
412 clib_memcpy (ip6_addr, &ipv6->address,
413 sizeof (ip6_address_t));
415 sctp_sub_connection_add_ip6 (vlib_get_main (),
417 [SCTP_PRIMARY_PATH_IDX].connection.
418 lcl_ip.ip6, &ipv6->address);
422 case SCTP_COOKIE_PRESERVATIVE_TYPE:
424 sctp_cookie_preservative_param_t *cookie_pres =
425 (sctp_cookie_preservative_param_t *) opt_params_hdr;
426 sctp_conn->peer_cookie_life_span_increment =
427 cookie_pres->life_span_inc;
430 case SCTP_HOSTNAME_ADDRESS_TYPE:
432 sctp_hostname_param_t *hostname_addr =
433 (sctp_hostname_param_t *) opt_params_hdr;
434 clib_memcpy (hostname, hostname_addr->hostname,
438 case SCTP_SUPPORTED_ADDRESS_TYPES:
444 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
448 /* Reuse buffer to make init-ack and send */
449 sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, ip4_addr,
451 return SCTP_ERROR_NONE;
455 sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
456 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
457 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
458 u16 sctp_implied_length)
460 sctp_init_ack_chunk_t *init_ack_chunk =
461 (sctp_init_ack_chunk_t *) (sctp_hdr);
463 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
464 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
466 return SCTP_ERROR_INVALID_TAG;
470 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
472 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
473 return SCTP_ERROR_BUNDLING_VIOLATION;
475 return SCTP_ERROR_NONE;
479 sctp_handle_init_ack (sctp_header_t * sctp_hdr,
480 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
481 sctp_connection_t * sctp_conn, u8 idx,
482 vlib_buffer_t * b0, u16 sctp_implied_length)
484 sctp_init_ack_chunk_t *init_ack_chunk =
485 (sctp_init_ack_chunk_t *) (sctp_hdr);
486 sctp_state_cookie_param_t state_cookie;
488 char hostname[FQDN_MAX_LENGTH];
490 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
491 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
493 return SCTP_ERROR_INVALID_TAG;
497 * It is not possible to bundle any other CHUNK with the INIT chunk
499 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
500 return SCTP_ERROR_BUNDLING_VIOLATION;
502 /* Stop the T1_INIT timer */
503 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
505 sctp_calculate_rto (sctp_conn, idx);
507 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
508 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
509 sctp_conn->remote_initial_tsn =
510 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
511 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
512 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
513 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
514 sctp_conn->remote_initial_tsn);
515 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
517 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
519 if (length > sizeof (sctp_init_ack_chunk_t))
521 * There are optional parameters in the INIT ACK chunk
524 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
526 while (pointer_offset < length)
528 sctp_opt_params_hdr_t *opt_params_hdr =
529 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
532 switch (clib_net_to_host_u16 (opt_params_hdr->type))
534 case SCTP_IPV4_ADDRESS_TYPE:
536 sctp_ipv4_addr_param_t *ipv4 =
537 (sctp_ipv4_addr_param_t *) opt_params_hdr;
539 sctp_sub_connection_add_ip4 (vlib_get_main (),
541 [SCTP_PRIMARY_PATH_IDX].connection.
542 lcl_ip.ip4, &ipv4->address);
546 case SCTP_IPV6_ADDRESS_TYPE:
548 sctp_ipv6_addr_param_t *ipv6 =
549 (sctp_ipv6_addr_param_t *) opt_params_hdr;
551 sctp_sub_connection_add_ip6 (vlib_get_main (),
553 [SCTP_PRIMARY_PATH_IDX].connection.
554 lcl_ip.ip6, &ipv6->address);
558 case SCTP_STATE_COOKIE_TYPE:
560 sctp_state_cookie_param_t *state_cookie_param =
561 (sctp_state_cookie_param_t *) opt_params_hdr;
563 clib_memcpy (&state_cookie, state_cookie_param,
564 sizeof (sctp_state_cookie_param_t));
567 case SCTP_HOSTNAME_ADDRESS_TYPE:
569 sctp_hostname_param_t *hostname_addr =
570 (sctp_hostname_param_t *) opt_params_hdr;
571 clib_memcpy (hostname, hostname_addr->hostname,
575 case SCTP_UNRECOGNIZED_TYPE:
580 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
581 /* This indicates something really bad happened */
584 return SCTP_ERROR_INVALID_TAG;
586 pointer_offset += increment;
590 clib_memcpy (&(sctp_conn->cookie_param), &state_cookie,
591 sizeof (sctp_state_cookie_param_t));
593 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
595 /* Start the T1_COOKIE timer */
596 sctp_timer_set (sctp_conn, idx,
597 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
599 return SCTP_ERROR_NONE;
602 /** Enqueue data out-of-order for delivery to application */
604 sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
605 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
607 int written, error = SCTP_ERROR_ENQUEUED;
610 session_enqueue_stream_connection (&sctp_conn->
611 sub_conn[conn_idx].connection, b, 0,
612 1 /* queue event */ ,
615 /* Update next_tsn_expected */
616 if (PREDICT_TRUE (written == data_len))
618 sctp_conn->next_tsn_expected += written;
620 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
621 sctp_conn->sub_conn[conn_idx].connection.c_index,
624 /* If more data written than expected, account for out-of-order bytes. */
625 else if (written > data_len)
627 sctp_conn->next_tsn_expected += written;
629 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
630 sctp_conn->sub_conn[conn_idx].connection.c_index,
633 else if (written > 0)
635 /* We've written something but FIFO is probably full now */
636 sctp_conn->next_tsn_expected += written;
638 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
641 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
642 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
646 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
647 sctp_conn->sub_conn[conn_idx].connection.c_index);
649 return SCTP_ERROR_FIFO_FULL;
652 /* TODO: Update out_of_order_map & SACK list */
657 /** Enqueue data for delivery to application */
659 sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
660 u16 data_len, u8 conn_idx)
662 int written, error = SCTP_ERROR_ENQUEUED;
665 session_enqueue_stream_connection (&sctp_conn->
666 sub_conn[conn_idx].connection, b, 0,
667 1 /* queue event */ ,
670 /* Update next_tsn_expected */
671 if (PREDICT_TRUE (written == data_len))
673 sctp_conn->next_tsn_expected += written;
675 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
676 sctp_conn->sub_conn[conn_idx].connection.c_index,
679 /* If more data written than expected, account for out-of-order bytes. */
680 else if (written > data_len)
682 sctp_conn->next_tsn_expected += written;
684 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
685 sctp_conn->sub_conn[conn_idx].connection.c_index,
688 else if (written > 0)
690 /* We've written something but FIFO is probably full now */
691 sctp_conn->next_tsn_expected += written;
693 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
696 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
697 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
701 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
702 sctp_conn->sub_conn[conn_idx].connection.c_index);
704 return SCTP_ERROR_FIFO_FULL;
711 sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
713 if (sctp_conn->conn_config.never_delay_sack)
715 SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
719 /* Section 4.4 of the RFC4960 */
720 if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
722 SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
723 sctp_state_to_string (sctp_conn->state));
729 SCTP_CONN_TRACKING_DBG
730 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
731 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
735 sctp_conn->ack_state += 1;
736 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
738 SCTP_CONN_TRACKING_DBG
739 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
740 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
748 sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
751 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
753 SCTP_CONN_TRACKING_DBG
754 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
755 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
756 sctp_conn->next_tsn_expected, tsn,
757 sctp_conn->next_tsn_expected - tsn);
764 sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
765 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
768 u32 error = 0, n_data_bytes;
771 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
772 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
774 return SCTP_ERROR_INVALID_TAG;
777 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
778 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
780 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
782 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
783 n_data_bytes = vnet_buffer (b)->sctp.data_len;
784 ASSERT (n_data_bytes);
786 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
788 sctp_conn->last_rcvd_tsn = tsn;
790 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
792 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
793 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
795 if (bbit == 1 && ebit == 1) /* Unfragmented message */
797 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
798 * segments can be enqueued after fifo tail offset changes. */
799 if (PREDICT_FALSE (is_gapping == 1))
801 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
803 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
805 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
807 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
809 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
811 if (PREDICT_FALSE (is_gapping == 1))
813 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
815 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
817 else /* Middle piece of a fragmented user message */
819 if (PREDICT_FALSE (is_gapping == 1))
821 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
823 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
825 sctp_conn->last_rcvd_tsn = tsn;
827 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
829 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
831 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
832 sctp_prepare_sack_chunk (sctp_conn, idx, b);
835 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
837 sctp_conn->sub_conn[idx].enqueue_state = error;
843 sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
844 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
845 sctp_connection_t * sctp_conn, u8 idx,
846 vlib_buffer_t * b0, u16 * next0)
848 u32 now = sctp_time_now ();
850 sctp_cookie_echo_chunk_t *cookie_echo =
851 (sctp_cookie_echo_chunk_t *) sctp_hdr;
853 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
854 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
856 return SCTP_ERROR_INVALID_TAG;
859 sctp_calculate_rto (sctp_conn, idx);
862 clib_net_to_host_u32 (cookie_echo->cookie.creation_time);
863 u32 cookie_lifespan =
864 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
865 if (now > creation_time + cookie_lifespan)
867 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
868 now, creation_time, cookie_lifespan);
869 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
872 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
875 sctp_conn->state = SCTP_STATE_ESTABLISHED;
876 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
877 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
879 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
880 sctp_conn->sub_conn[idx].RTO);
882 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
884 return SCTP_ERROR_NONE;
889 sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
890 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
891 sctp_connection_t * sctp_conn, u8 idx,
892 vlib_buffer_t * b0, u16 * next0)
894 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
895 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
897 return SCTP_ERROR_INVALID_TAG;
900 sctp_calculate_rto (sctp_conn, idx);
902 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
904 sctp_conn->state = SCTP_STATE_ESTABLISHED;
905 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
907 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
909 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
910 sctp_conn->sub_conn[idx].RTO);
912 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
914 return SCTP_ERROR_NONE;
919 sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
920 vlib_frame_t * from_frame, int is_ip4)
922 sctp_main_t *tm = vnet_get_sctp_main ();
924 u32 n_left_from, next_index, *from, *to_next;
925 u32 my_thread_index = vm->thread_index;
927 from = vlib_frame_vector_args (from_frame);
928 n_left_from = from_frame->n_vectors;
930 next_index = node->cached_next_index;
932 while (n_left_from > 0)
936 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
938 while (n_left_from > 0 && n_left_to_next > 0)
942 sctp_header_t *sctp_hdr = 0;
943 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
944 ip4_header_t *ip4_hdr = 0;
945 ip6_header_t *ip6_hdr = 0;
946 sctp_connection_t *sctp_conn, *new_sctp_conn;
947 u16 sctp_implied_length = 0;
948 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
958 b0 = vlib_get_buffer (vm, bi0);
960 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
961 * will come from the half-open connections pool.
964 sctp_half_open_connection_get (vnet_buffer (b0)->
965 sctp.connection_index);
967 if (PREDICT_FALSE (sctp_conn == 0))
970 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
971 error0 = SCTP_ERROR_INVALID_CONNECTION;
976 ip4_hdr = vlib_buffer_get_current (b0);
977 sctp_hdr = ip4_next_header (ip4_hdr);
978 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
982 ip6_hdr = vlib_buffer_get_current (b0);
983 sctp_hdr = ip6_next_header (ip6_hdr);
984 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
987 sctp_conn->sub_conn[idx].subconn_idx = idx;
988 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
991 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
993 sctp_implied_length =
994 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
996 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1002 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1003 b0, sctp_implied_length);
1005 if (error0 == SCTP_ERROR_NONE)
1007 pool_get (tm->connections[my_thread_index], new_sctp_conn);
1008 clib_memcpy (new_sctp_conn, sctp_conn,
1009 sizeof (*new_sctp_conn));
1010 new_sctp_conn->sub_conn[idx].c_c_index =
1011 new_sctp_conn - tm->connections[my_thread_index];
1012 new_sctp_conn->sub_conn[idx].c_thread_index =
1014 new_sctp_conn->sub_conn[idx].PMTU =
1015 sctp_conn->sub_conn[idx].PMTU;
1016 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
1018 if (sctp_half_open_connection_cleanup (sctp_conn))
1021 ("Cannot cleanup half-open connection; not the owning thread");
1024 sctp_connection_timers_init (new_sctp_conn);
1026 sctp_init_cwnd (new_sctp_conn);
1029 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
1030 new_sctp_conn, idx, b0,
1031 sctp_implied_length);
1033 if (session_stream_connect_notify
1034 (&new_sctp_conn->sub_conn[idx].connection, 0))
1037 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1038 new_sctp_conn->sub_conn[idx].connection.c_index);
1039 sctp_connection_cleanup (new_sctp_conn);
1042 next0 = sctp_next_output (is_ip4);
1046 case OPERATION_ERROR:
1048 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1052 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1053 * are handled by the input-dispatcher function using the table-lookup
1054 * hence we should never get to the "default" case below.
1057 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1058 next0 = sctp_next_drop (is_ip4);
1062 if (error0 != SCTP_ERROR_NONE)
1064 clib_warning ("error while parsing chunk");
1065 sctp_connection_cleanup (sctp_conn);
1066 next0 = sctp_next_drop (is_ip4);
1071 b0->error = node->errors[error0];
1072 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1074 sctp_rx_trace_t *t0 =
1075 vlib_add_trace (vm, node, b0, sizeof (*t0));
1076 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1079 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1080 n_left_to_next, bi0, next0);
1083 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1085 return from_frame->n_vectors;
1089 sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1090 vlib_frame_t * from_frame)
1092 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1096 sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1097 vlib_frame_t * from_frame)
1099 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1103 format_sctp_rx_trace_short (u8 * s, va_list * args)
1105 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1106 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1107 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1109 s = format (s, "%d -> %d (%U)",
1110 clib_net_to_host_u16 (t->sctp_header.src_port),
1111 clib_net_to_host_u16 (t->sctp_header.dst_port),
1112 format_sctp_state, t->sctp_connection.state);
1118 VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1120 .function = sctp4_rcv_phase,
1121 .name = "sctp4-rcv",
1122 /* Takes a vector of packets. */
1123 .vector_size = sizeof (u32),
1124 .n_errors = SCTP_N_ERROR,
1125 .error_strings = sctp_error_strings,
1126 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1129 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1130 foreach_sctp_state_next
1133 .format_trace = format_sctp_rx_trace_short,
1137 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1140 VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1142 .function = sctp6_rcv_phase,
1143 .name = "sctp6-rcv",
1144 /* Takes a vector of packets. */
1145 .vector_size = sizeof (u32),
1146 .n_errors = SCTP_N_ERROR,
1147 .error_strings = sctp_error_strings,
1148 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1151 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1152 foreach_sctp_state_next
1155 .format_trace = format_sctp_rx_trace_short,
1159 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1161 vlib_node_registration_t sctp4_shutdown_phase_node;
1162 vlib_node_registration_t sctp6_shutdown_phase_node;
1165 sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1166 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1167 sctp_connection_t * sctp_conn, u8 idx,
1168 vlib_buffer_t * b0, u16 sctp_implied_length,
1171 sctp_shutdown_association_chunk_t *shutdown_chunk =
1172 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1174 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1175 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1177 return SCTP_ERROR_INVALID_TAG;
1181 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1183 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1184 return SCTP_ERROR_BUNDLING_VIOLATION;
1186 switch (sctp_conn->state)
1188 case SCTP_STATE_ESTABLISHED:
1189 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1190 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
1191 sctp_send_shutdown_ack (sctp_conn, idx, b0);
1194 case SCTP_STATE_SHUTDOWN_SENT:
1195 sctp_send_shutdown_ack (sctp_conn, idx, b0);
1199 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1201 return SCTP_ERROR_NONE;
1205 sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1206 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1207 sctp_connection_t * sctp_conn, u8 idx,
1208 vlib_buffer_t * b0, u16 sctp_implied_length,
1211 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1212 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1214 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1215 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1217 return SCTP_ERROR_INVALID_TAG;
1221 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1223 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1224 return SCTP_ERROR_BUNDLING_VIOLATION;
1226 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1227 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1228 * - STOP T2_SHUTDOWN timer
1229 * - SEND SHUTDOWN_COMPLETE chunk
1231 sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
1233 sctp_send_shutdown_complete (sctp_conn, idx, b0);
1235 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1237 return SCTP_ERROR_NONE;
1241 sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1242 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1243 sctp_connection_t * sctp_conn, u8 idx,
1244 vlib_buffer_t * b0, u16 sctp_implied_length,
1247 sctp_shutdown_complete_chunk_t *shutdown_complete =
1248 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1250 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1251 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1253 return SCTP_ERROR_INVALID_TAG;
1257 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1259 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1260 return SCTP_ERROR_BUNDLING_VIOLATION;
1262 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1264 stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
1266 sctp_conn->state = SCTP_STATE_CLOSED;
1268 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1270 return SCTP_ERROR_NONE;
1274 sctp46_shutdown_phase_inline (vlib_main_t * vm,
1275 vlib_node_runtime_t * node,
1276 vlib_frame_t * from_frame, int is_ip4)
1278 u32 n_left_from, next_index, *from, *to_next;
1279 u32 my_thread_index = vm->thread_index;
1281 from = vlib_frame_vector_args (from_frame);
1282 n_left_from = from_frame->n_vectors;
1284 next_index = node->cached_next_index;
1286 while (n_left_from > 0)
1290 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1292 while (n_left_from > 0 && n_left_to_next > 0)
1296 sctp_rx_trace_t *sctp_trace;
1297 sctp_header_t *sctp_hdr = 0;
1298 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1299 ip4_header_t *ip4_hdr = 0;
1300 ip6_header_t *ip6_hdr = 0;
1301 sctp_connection_t *sctp_conn;
1302 u16 sctp_implied_length = 0;
1303 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
1311 n_left_to_next -= 1;
1313 b0 = vlib_get_buffer (vm, bi0);
1315 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1318 if (PREDICT_FALSE (sctp_conn == 0))
1321 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1322 error0 = SCTP_ERROR_INVALID_CONNECTION;
1328 ip4_hdr = vlib_buffer_get_current (b0);
1329 sctp_hdr = ip4_next_header (ip4_hdr);
1330 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1334 ip6_hdr = vlib_buffer_get_current (b0);
1335 sctp_hdr = ip6_next_header (ip6_hdr);
1336 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1339 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1340 sctp_chunk_hdr = &full_hdr->common_hdr;
1342 sctp_implied_length =
1343 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1345 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1350 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1351 idx, b0, sctp_implied_length, &next0);
1356 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1357 idx, b0, sctp_implied_length,
1361 case SHUTDOWN_COMPLETE:
1363 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
1365 sctp_implied_length, &next0);
1367 sctp_connection_cleanup (sctp_conn);
1371 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1372 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1376 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1377 sctp_conn, idx, b0, &next0);
1380 case OPERATION_ERROR:
1382 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1386 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1387 sctp_prepare_operation_error (sctp_conn, idx, b0,
1388 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1389 error0 = SCTP_ERROR_NONE;
1390 next0 = sctp_next_output (is_ip4);
1392 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1393 * are handled by the input-dispatcher function using the table-lookup
1394 * hence we should never get to the "default" case below.
1397 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1398 next0 = sctp_next_drop (is_ip4);
1402 if (error0 != SCTP_ERROR_NONE)
1404 clib_warning ("error while parsing chunk");
1405 sctp_connection_cleanup (sctp_conn);
1406 next0 = sctp_next_drop (is_ip4);
1411 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1414 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
1416 if (sctp_hdr != NULL)
1417 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1418 sizeof (sctp_trace->sctp_header));
1420 if (sctp_conn != NULL)
1421 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1422 sizeof (sctp_trace->sctp_connection));
1425 b0->error = node->errors[error0];
1427 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1428 n_left_to_next, bi0, next0);
1431 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1434 return from_frame->n_vectors;
1439 sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1440 vlib_frame_t * from_frame)
1442 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1446 sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1447 vlib_frame_t * from_frame)
1449 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1453 VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1455 .function = sctp4_shutdown_phase,
1456 .name = "sctp4-shutdown",
1457 /* Takes a vector of packets. */
1458 .vector_size = sizeof (u32),
1459 .n_errors = SCTP_N_ERROR,
1460 .error_strings = sctp_error_strings,
1461 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1464 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1465 foreach_sctp_state_next
1468 .format_trace = format_sctp_rx_trace_short,
1472 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1473 sctp4_shutdown_phase);
1476 VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1478 .function = sctp6_shutdown_phase,
1479 .name = "sctp6-shutdown",
1480 /* Takes a vector of packets. */
1481 .vector_size = sizeof (u32),
1482 .n_errors = SCTP_N_ERROR,
1483 .error_strings = sctp_error_strings,
1484 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1487 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1488 foreach_sctp_state_next
1491 .format_trace = format_sctp_rx_trace_short,
1495 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1496 sctp6_shutdown_phase);
1498 vlib_node_registration_t sctp4_listen_phase_node;
1499 vlib_node_registration_t sctp6_listen_phase_node;
1501 vlib_node_registration_t sctp4_established_phase_node;
1502 vlib_node_registration_t sctp6_established_phase_node;
1505 sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
1506 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
1510 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1511 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1513 return SCTP_ERROR_INVALID_TAG;
1516 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1518 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1520 /* Section 7.2.2; point (2) */
1521 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1522 sctp_conn->sub_conn[idx].partially_acked_bytes =
1523 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1525 /* Section 7.2.2; point (5) */
1526 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1527 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1529 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1531 sctp_calculate_rto (sctp_conn, idx);
1533 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1534 sctp_conn->sub_conn[idx].RTO);
1536 sctp_conn->sub_conn[idx].RTO_pending = 0;
1538 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1540 return SCTP_ERROR_NONE;
1544 sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
1545 sctp_connection_t * sctp_conn, u8 idx,
1546 vlib_buffer_t * b0, u16 * next0)
1548 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1549 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1551 return SCTP_ERROR_INVALID_TAG;
1554 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
1556 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1558 return SCTP_ERROR_NONE;
1562 sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
1563 sctp_connection_t * sctp_conn, u8 idx,
1564 vlib_buffer_t * b0, u16 * next0)
1566 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1568 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1570 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1571 sctp_conn->sub_conn[idx].RTO);
1573 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1575 return SCTP_ERROR_NONE;
1579 sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
1580 u8 is_ip4, u8 evt, u8 val)
1582 if (PREDICT_TRUE (!val))
1586 vlib_node_increment_counter (vm, sctp4_node, evt, val);
1588 vlib_node_increment_counter (vm, sctp6_node, evt, val);
1592 sctp46_listen_process_inline (vlib_main_t * vm,
1593 vlib_node_runtime_t * node,
1594 vlib_frame_t * from_frame, int is_ip4)
1596 u32 n_left_from, next_index, *from, *to_next;
1597 u32 my_thread_index = vm->thread_index;
1599 from = vlib_frame_vector_args (from_frame);
1600 n_left_from = from_frame->n_vectors;
1602 next_index = node->cached_next_index;
1604 while (n_left_from > 0)
1608 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1610 while (n_left_from > 0 && n_left_to_next > 0)
1614 sctp_header_t *sctp_hdr = 0;
1615 ip4_header_t *ip4_hdr;
1616 ip6_header_t *ip6_hdr;
1617 sctp_connection_t *child_conn;
1618 sctp_connection_t *sctp_listener;
1619 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
1626 n_left_to_next -= 1;
1628 b0 = vlib_get_buffer (vm, bi0);
1630 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1634 ip4_hdr = vlib_buffer_get_current (b0);
1635 sctp_hdr = ip4_next_header (ip4_hdr);
1639 ip6_hdr = vlib_buffer_get_current (b0);
1640 sctp_hdr = ip6_next_header (ip6_hdr);
1644 sctp_lookup_connection (sctp_listener->sub_conn
1645 [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
1646 my_thread_index, is_ip4);
1648 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1651 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1652 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1654 sctp_state_to_string (child_conn->state));
1655 error0 = SCTP_ERROR_CREATE_EXISTS;
1659 /* Create child session and send SYN-ACK */
1660 child_conn = sctp_connection_new (my_thread_index);
1661 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1662 SCTP_PRIMARY_PATH_IDX;
1663 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
1665 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
1667 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1668 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1669 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1670 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1671 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
1672 child_conn->state = SCTP_STATE_CLOSED;
1673 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1674 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1675 connection.fib_index;
1679 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
1680 ip4_hdr->dst_address.as_u32;
1681 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
1682 ip4_hdr->src_address.as_u32;
1686 clib_memcpy (&child_conn->
1687 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
1688 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1689 clib_memcpy (&child_conn->
1690 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
1691 &ip6_hdr->src_address, sizeof (ip6_address_t));
1694 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1695 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1697 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1698 if (chunk_type != INIT)
1701 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1702 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1703 connection.c_index, sctp_chunk_to_string (chunk_type));
1705 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1706 next0 = sctp_next_drop (is_ip4);
1710 u16 sctp_implied_length =
1711 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1716 sctp_connection_timers_init (child_conn);
1718 sctp_init_snd_vars (child_conn);
1720 sctp_init_cwnd (child_conn);
1723 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1724 sctp_implied_length);
1726 if (error0 == SCTP_ERROR_NONE)
1728 if (stream_session_accept
1730 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
1732 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
1734 clib_warning ("session accept fail");
1735 sctp_connection_cleanup (child_conn);
1736 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1739 next0 = sctp_next_output (is_ip4);
1743 /* Reception of a DATA chunk whilst in the CLOSED state is called
1744 * "Out of the Blue" packet and handling of the chunk needs special treatment
1745 * as per RFC4960 section 8.4
1750 case OPERATION_ERROR:
1752 sctp_handle_operation_err (sctp_hdr, child_conn,
1753 SCTP_PRIMARY_PATH_IDX, b0, &next0);
1758 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1760 sctp_rx_trace_t *t0 =
1761 vlib_add_trace (vm, node, b0, sizeof (*t0));
1762 clib_memcpy (&t0->sctp_header, sctp_hdr,
1763 sizeof (t0->sctp_header));
1764 clib_memcpy (&t0->sctp_connection, sctp_listener,
1765 sizeof (t0->sctp_connection));
1768 b0->error = node->errors[error0];
1770 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1771 n_left_to_next, bi0, next0);
1773 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1776 return from_frame->n_vectors;
1780 sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1781 vlib_frame_t * from_frame)
1783 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1787 sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1788 vlib_frame_t * from_frame)
1790 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1794 sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1795 vlib_frame_t * from_frame, int is_ip4)
1797 u32 n_left_from, next_index, *from, *to_next;
1798 u32 my_thread_index = vm->thread_index, errors = 0;
1800 from = vlib_frame_vector_args (from_frame);
1801 n_left_from = from_frame->n_vectors;
1803 next_index = node->cached_next_index;
1805 while (n_left_from > 0)
1809 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1811 while (n_left_from > 0 && n_left_to_next > 0)
1815 sctp_header_t *sctp_hdr = 0;
1816 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1817 ip4_header_t *ip4_hdr = 0;
1818 ip6_header_t *ip6_hdr = 0;
1819 sctp_connection_t *sctp_conn;
1820 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1821 SCTP_ESTABLISHED_PHASE_N_NEXT;
1829 n_left_to_next -= 1;
1831 b0 = vlib_get_buffer (vm, bi0);
1833 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1836 if (PREDICT_FALSE (sctp_conn == 0))
1839 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1840 error0 = SCTP_ERROR_INVALID_CONNECTION;
1845 ip4_hdr = vlib_buffer_get_current (b0);
1846 sctp_hdr = ip4_next_header (ip4_hdr);
1847 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1851 ip6_hdr = vlib_buffer_get_current (b0);
1852 sctp_hdr = ip6_next_header (ip6_hdr);
1853 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1856 sctp_conn->sub_conn[idx].subconn_idx = idx;
1858 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1860 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1862 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1868 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1874 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1880 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
1881 sctp_conn, idx, b0, &next0);
1886 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
1887 sctp_conn, idx, b0, &next0);
1892 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
1893 sctp_conn, idx, b0, &next0);
1898 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1899 sctp_conn, idx, b0, &next0);
1902 case OPERATION_ERROR:
1904 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1908 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1909 * are handled by the input-dispatcher function using the table-lookup
1910 * hence we should never get to the "default" case below.
1913 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1914 next0 = sctp_next_drop (is_ip4);
1919 b0->error = node->errors[error0];
1920 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1922 sctp_rx_trace_t *t0 =
1923 vlib_add_trace (vm, node, b0, sizeof (*t0));
1924 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1927 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1928 n_left_to_next, bi0, next0);
1931 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1934 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1937 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1938 sctp6_established_phase_node.index,
1939 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1940 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1942 return from_frame->n_vectors;
1946 sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1947 vlib_frame_t * from_frame)
1949 return sctp46_established_phase_inline (vm, node, from_frame,
1954 sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1955 vlib_frame_t * from_frame)
1957 return sctp46_established_phase_inline (vm, node, from_frame,
1962 format_sctp_rx_trace (u8 * s, va_list * args)
1964 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1965 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1966 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1967 u32 indent = format_get_indent (s);
1969 s = format (s, "%U\n%U%U",
1970 format_sctp_header, &t->sctp_header, 128,
1971 format_white_space, indent,
1972 format_sctp_connection, &t->sctp_connection, 1);
1978 VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1980 .function = sctp4_listen_phase,
1981 .name = "sctp4-listen",
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_LISTEN_PHASE_N_NEXT,
1989 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1990 foreach_sctp_state_next
1993 .format_trace = format_sctp_rx_trace_short,
1997 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
2000 VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
2002 .function = sctp6_listen_phase,
2003 .name = "sctp6-listen",
2004 /* Takes a vector of packets. */
2005 .vector_size = sizeof (u32),
2006 .n_errors = SCTP_N_ERROR,
2007 .error_strings = sctp_error_strings,
2008 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2011 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2012 foreach_sctp_state_next
2015 .format_trace = format_sctp_rx_trace_short,
2019 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
2022 VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2024 .function = sctp4_established_phase,
2025 .name = "sctp4-established",
2026 /* Takes a vector of packets. */
2027 .vector_size = sizeof (u32),
2028 .n_errors = SCTP_N_ERROR,
2029 .error_strings = sctp_error_strings,
2030 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2033 #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2034 foreach_sctp_state_next
2037 .format_trace = format_sctp_rx_trace_short,
2041 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
2042 sctp4_established_phase);
2045 VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2047 .function = sctp6_established_phase,
2048 .name = "sctp6-established",
2049 /* Takes a vector of packets. */
2050 .vector_size = sizeof (u32),
2051 .n_errors = SCTP_N_ERROR,
2052 .error_strings = sctp_error_strings,
2053 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2056 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2057 foreach_sctp_state_next
2060 .format_trace = format_sctp_rx_trace_short,
2064 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2065 sctp6_established_phase);
2068 * This is the function executed first for the SCTP graph.
2069 * It takes care of doing the initial message parsing and
2070 * dispatch to the specialized function.
2073 sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2074 vlib_frame_t * from_frame, int is_ip4)
2076 u32 n_left_from, next_index, *from, *to_next;
2077 u32 my_thread_index = vm->thread_index;
2079 sctp_main_t *tm = vnet_get_sctp_main ();
2081 from = vlib_frame_vector_args (from_frame);
2082 n_left_from = from_frame->n_vectors;
2083 next_index = node->cached_next_index;
2084 sctp_set_time_now (my_thread_index);
2086 while (n_left_from > 0)
2090 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2092 while (n_left_from > 0 && n_left_to_next > 0)
2094 int n_advance_bytes0, n_data_bytes0;
2095 u32 bi0, fib_index0;
2097 sctp_header_t *sctp_hdr = 0;
2098 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2099 sctp_connection_t *sctp_conn;
2100 transport_connection_t *trans_conn;
2101 ip4_header_t *ip4_hdr;
2102 ip6_header_t *ip6_hdr;
2103 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2110 n_left_to_next -= 1;
2112 b0 = vlib_get_buffer (vm, bi0);
2113 vnet_buffer (b0)->sctp.flags = 0;
2114 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2116 /* Checksum computed by ipx_local no need to compute again */
2120 ip4_hdr = vlib_buffer_get_current (b0);
2121 sctp_hdr = ip4_next_header (ip4_hdr);
2123 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2124 sctp_chunk_hdr = &full_hdr->common_hdr;
2127 (ip4_header_bytes (ip4_hdr) +
2128 sizeof (sctp_payload_data_chunk_t));
2130 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2132 trans_conn = session_lookup_connection_wt4 (fib_index0,
2133 &ip4_hdr->dst_address,
2134 &ip4_hdr->src_address,
2137 TRANSPORT_PROTO_SCTP,
2143 ip6_hdr = vlib_buffer_get_current (b0);
2144 sctp_hdr = ip6_next_header (ip6_hdr);
2146 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2147 sctp_chunk_hdr = &full_hdr->common_hdr;
2149 n_advance_bytes0 = sctp_header_bytes ();
2151 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2153 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2155 trans_conn = session_lookup_connection_wt6 (fib_index0,
2156 &ip6_hdr->dst_address,
2157 &ip6_hdr->src_address,
2160 TRANSPORT_PROTO_SCTP,
2166 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2168 error0 = SCTP_ERROR_LENGTH;
2172 sctp_conn = sctp_get_connection_from_transport (trans_conn);
2173 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2175 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2176 if (chunk_type >= UNKNOWN)
2179 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2181 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
2182 b0, UNRECOGNIZED_CHUNK_TYPE);
2184 error0 = SCTP_ERROR_UNKOWN_CHUNK;
2185 next0 = sctp_next_output (is_ip4);
2189 vnet_buffer (b0)->sctp.hdr_offset =
2190 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2192 /* Session exists */
2193 if (PREDICT_TRUE (0 != sctp_conn))
2195 /* Save connection index */
2196 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
2197 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2198 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2200 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2201 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
2203 SCTP_DBG_STATE_MACHINE
2204 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
2205 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2206 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2208 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2209 connection.c_index, trans_conn, sctp_conn,
2210 sctp_state_to_string (sctp_conn->state),
2211 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
2213 if (chunk_type == DATA)
2214 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2215 n_advance_bytes0, n_data_bytes0);
2222 next0 = SCTP_INPUT_NEXT_DROP;
2223 error0 = SCTP_ERROR_FILTERED;
2225 else if ((is_ip4 && tm->punt_unknown4) ||
2226 (!is_ip4 && tm->punt_unknown6))
2228 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2229 error0 = SCTP_ERROR_PUNT;
2233 next0 = SCTP_INPUT_NEXT_DROP;
2234 error0 = SCTP_ERROR_NO_LISTENER;
2236 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2237 phase_to_string (next0));
2242 b0->error = error0 ? node->errors[error0] : 0;
2244 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2246 sctp_rx_trace_t *t0 =
2247 vlib_add_trace (vm, node, b0, sizeof (*t0));
2248 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2250 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2251 n_left_to_next, bi0, next0);
2254 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2256 return from_frame->n_vectors;
2260 sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2261 vlib_frame_t * from_frame)
2263 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2267 sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2268 vlib_frame_t * from_frame)
2270 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2274 VLIB_REGISTER_NODE (sctp4_input_node) =
2276 .function = sctp4_input_dispatcher,
2277 .name = "sctp4-input",
2278 /* Takes a vector of packets. */
2279 .vector_size = sizeof (u32),
2280 .n_errors = SCTP_N_ERROR,
2281 .error_strings = sctp_error_strings,
2282 .n_next_nodes = SCTP_INPUT_N_NEXT,
2285 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2286 foreach_sctp4_input_next
2289 .format_buffer = format_sctp_header,
2290 .format_trace = format_sctp_rx_trace,
2294 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2297 VLIB_REGISTER_NODE (sctp6_input_node) =
2299 .function = sctp6_input_dispatcher,
2300 .name = "sctp6-input",
2301 /* Takes a vector of packets. */
2302 .vector_size = sizeof (u32),
2303 .n_errors = SCTP_N_ERROR,
2304 .error_strings = sctp_error_strings,
2305 .n_next_nodes = SCTP_INPUT_N_NEXT,
2308 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2309 foreach_sctp6_input_next
2312 .format_buffer = format_sctp_header,
2313 .format_trace = format_sctp_rx_trace,
2317 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2319 vlib_node_registration_t sctp4_input_node;
2320 vlib_node_registration_t sctp6_input_node;
2323 sctp_dispatch_table_init (sctp_main_t * tm)
2326 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2327 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2329 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2330 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2333 #define _(t,f,n,e) \
2335 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2336 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2340 * SCTP STATE-MACHINE states:
2342 * _(CLOSED, "CLOSED") \
2343 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2344 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2345 * _(ESTABLISHED, "ESTABLISHED") \
2346 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2347 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2348 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2349 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2351 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2352 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2353 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2354 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2355 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2356 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2357 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2358 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2359 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2360 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2361 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2362 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2363 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2364 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2365 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2366 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2368 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2369 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2370 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2371 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2372 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2373 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2374 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2375 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2376 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2377 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2378 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2379 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2380 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2381 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2382 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2383 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2386 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2387 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2388 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2389 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2390 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2391 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2392 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2393 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2394 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2395 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2396 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2397 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2399 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2400 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2401 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2402 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2405 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2406 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2407 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2408 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2409 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2411 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2413 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2414 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2415 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2416 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2417 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2418 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2419 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2420 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2421 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2422 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2425 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2426 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2427 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2428 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2429 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2431 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2433 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2434 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2436 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2437 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2438 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2440 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2441 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2442 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2443 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2444 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2447 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2448 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2449 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2450 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2451 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2452 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2453 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2454 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2455 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2457 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2459 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2460 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2461 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2462 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2463 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2466 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2467 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2468 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2469 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2470 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2471 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2472 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2473 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2474 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2476 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2478 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2479 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2480 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2481 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2482 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2485 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2486 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
2487 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2488 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2489 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2490 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2491 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2492 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2493 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2494 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2496 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2497 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2498 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2499 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2501 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2504 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2510 sctp_input_init (vlib_main_t * vm)
2512 clib_error_t *error = 0;
2513 sctp_main_t *tm = vnet_get_sctp_main ();
2515 if ((error = vlib_call_init_function (vm, sctp_init)))
2518 /* Initialize dispatch table. */
2519 sctp_dispatch_table_init (tm);
2524 VLIB_INIT_FUNCTION (sctp_input_init);
2527 * fd.io coding-style-patch-verification: ON
2530 * eval: (c-set-style "gnu")