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;
1676 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
1677 ip4_hdr->dst_address.as_u32;
1678 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
1679 ip4_hdr->src_address.as_u32;
1683 clib_memcpy (&child_conn->
1684 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
1685 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1686 clib_memcpy (&child_conn->
1687 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
1688 &ip6_hdr->src_address, sizeof (ip6_address_t));
1691 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1692 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1694 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1695 if (chunk_type != INIT)
1698 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1699 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1700 connection.c_index, sctp_chunk_to_string (chunk_type));
1702 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1703 next0 = sctp_next_drop (is_ip4);
1707 u16 sctp_implied_length =
1708 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1713 sctp_connection_timers_init (child_conn);
1715 sctp_init_snd_vars (child_conn);
1717 sctp_init_cwnd (child_conn);
1720 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1721 sctp_implied_length);
1723 if (error0 == SCTP_ERROR_NONE)
1725 if (stream_session_accept
1727 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
1729 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
1731 clib_warning ("session accept fail");
1732 sctp_connection_cleanup (child_conn);
1733 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1736 next0 = sctp_next_output (is_ip4);
1740 /* Reception of a DATA chunk whilst in the CLOSED state is called
1741 * "Out of the Blue" packet and handling of the chunk needs special treatment
1742 * as per RFC4960 section 8.4
1747 case OPERATION_ERROR:
1749 sctp_handle_operation_err (sctp_hdr, child_conn,
1750 SCTP_PRIMARY_PATH_IDX, b0, &next0);
1755 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1757 sctp_rx_trace_t *t0 =
1758 vlib_add_trace (vm, node, b0, sizeof (*t0));
1759 clib_memcpy (&t0->sctp_header, sctp_hdr,
1760 sizeof (t0->sctp_header));
1761 clib_memcpy (&t0->sctp_connection, sctp_listener,
1762 sizeof (t0->sctp_connection));
1765 b0->error = node->errors[error0];
1767 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1768 n_left_to_next, bi0, next0);
1770 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1773 return from_frame->n_vectors;
1777 sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1778 vlib_frame_t * from_frame)
1780 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1784 sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1785 vlib_frame_t * from_frame)
1787 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1791 sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1792 vlib_frame_t * from_frame, int is_ip4)
1794 u32 n_left_from, next_index, *from, *to_next;
1795 u32 my_thread_index = vm->thread_index, errors = 0;
1797 from = vlib_frame_vector_args (from_frame);
1798 n_left_from = from_frame->n_vectors;
1800 next_index = node->cached_next_index;
1802 while (n_left_from > 0)
1806 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1808 while (n_left_from > 0 && n_left_to_next > 0)
1812 sctp_header_t *sctp_hdr = 0;
1813 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1814 ip4_header_t *ip4_hdr = 0;
1815 ip6_header_t *ip6_hdr = 0;
1816 sctp_connection_t *sctp_conn;
1817 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1818 SCTP_ESTABLISHED_PHASE_N_NEXT;
1826 n_left_to_next -= 1;
1828 b0 = vlib_get_buffer (vm, bi0);
1830 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1833 if (PREDICT_FALSE (sctp_conn == 0))
1836 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1837 error0 = SCTP_ERROR_INVALID_CONNECTION;
1842 ip4_hdr = vlib_buffer_get_current (b0);
1843 sctp_hdr = ip4_next_header (ip4_hdr);
1844 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1848 ip6_hdr = vlib_buffer_get_current (b0);
1849 sctp_hdr = ip6_next_header (ip6_hdr);
1850 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1853 sctp_conn->sub_conn[idx].subconn_idx = idx;
1855 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1857 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1859 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1865 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1871 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1877 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
1878 sctp_conn, idx, b0, &next0);
1883 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
1884 sctp_conn, idx, b0, &next0);
1889 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
1890 sctp_conn, idx, b0, &next0);
1895 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1896 sctp_conn, idx, b0, &next0);
1899 case OPERATION_ERROR:
1901 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1905 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1906 * are handled by the input-dispatcher function using the table-lookup
1907 * hence we should never get to the "default" case below.
1910 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1911 next0 = sctp_next_drop (is_ip4);
1916 b0->error = node->errors[error0];
1917 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1919 sctp_rx_trace_t *t0 =
1920 vlib_add_trace (vm, node, b0, sizeof (*t0));
1921 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1924 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1925 n_left_to_next, bi0, next0);
1928 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1931 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1934 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1935 sctp6_established_phase_node.index,
1936 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1937 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1939 return from_frame->n_vectors;
1943 sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1944 vlib_frame_t * from_frame)
1946 return sctp46_established_phase_inline (vm, node, from_frame,
1951 sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1952 vlib_frame_t * from_frame)
1954 return sctp46_established_phase_inline (vm, node, from_frame,
1959 format_sctp_rx_trace (u8 * s, va_list * args)
1961 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1962 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1963 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1964 u32 indent = format_get_indent (s);
1966 s = format (s, "%U\n%U%U",
1967 format_sctp_header, &t->sctp_header, 128,
1968 format_white_space, indent,
1969 format_sctp_connection, &t->sctp_connection, 1);
1975 VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1977 .function = sctp4_listen_phase,
1978 .name = "sctp4-listen",
1979 /* Takes a vector of packets. */
1980 .vector_size = sizeof (u32),
1981 .n_errors = SCTP_N_ERROR,
1982 .error_strings = sctp_error_strings,
1983 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1986 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1987 foreach_sctp_state_next
1990 .format_trace = format_sctp_rx_trace_short,
1994 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
1997 VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
1999 .function = sctp6_listen_phase,
2000 .name = "sctp6-listen",
2001 /* Takes a vector of packets. */
2002 .vector_size = sizeof (u32),
2003 .n_errors = SCTP_N_ERROR,
2004 .error_strings = sctp_error_strings,
2005 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2008 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2009 foreach_sctp_state_next
2012 .format_trace = format_sctp_rx_trace_short,
2016 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
2019 VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2021 .function = sctp4_established_phase,
2022 .name = "sctp4-established",
2023 /* Takes a vector of packets. */
2024 .vector_size = sizeof (u32),
2025 .n_errors = SCTP_N_ERROR,
2026 .error_strings = sctp_error_strings,
2027 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2030 #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2031 foreach_sctp_state_next
2034 .format_trace = format_sctp_rx_trace_short,
2038 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
2039 sctp4_established_phase);
2042 VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2044 .function = sctp6_established_phase,
2045 .name = "sctp6-established",
2046 /* Takes a vector of packets. */
2047 .vector_size = sizeof (u32),
2048 .n_errors = SCTP_N_ERROR,
2049 .error_strings = sctp_error_strings,
2050 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2053 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2054 foreach_sctp_state_next
2057 .format_trace = format_sctp_rx_trace_short,
2061 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2062 sctp6_established_phase);
2065 * This is the function executed first for the SCTP graph.
2066 * It takes care of doing the initial message parsing and
2067 * dispatch to the specialized function.
2070 sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2071 vlib_frame_t * from_frame, int is_ip4)
2073 u32 n_left_from, next_index, *from, *to_next;
2074 u32 my_thread_index = vm->thread_index;
2076 sctp_main_t *tm = vnet_get_sctp_main ();
2078 from = vlib_frame_vector_args (from_frame);
2079 n_left_from = from_frame->n_vectors;
2080 next_index = node->cached_next_index;
2081 sctp_set_time_now (my_thread_index);
2083 while (n_left_from > 0)
2087 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2089 while (n_left_from > 0 && n_left_to_next > 0)
2091 int n_advance_bytes0, n_data_bytes0;
2092 u32 bi0, fib_index0;
2094 sctp_header_t *sctp_hdr = 0;
2095 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2096 sctp_connection_t *sctp_conn;
2097 transport_connection_t *trans_conn;
2098 ip4_header_t *ip4_hdr;
2099 ip6_header_t *ip6_hdr;
2100 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2107 n_left_to_next -= 1;
2109 b0 = vlib_get_buffer (vm, bi0);
2110 vnet_buffer (b0)->sctp.flags = 0;
2111 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2113 /* Checksum computed by ipx_local no need to compute again */
2117 ip4_hdr = vlib_buffer_get_current (b0);
2118 sctp_hdr = ip4_next_header (ip4_hdr);
2120 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2121 sctp_chunk_hdr = &full_hdr->common_hdr;
2124 (ip4_header_bytes (ip4_hdr) +
2125 sizeof (sctp_payload_data_chunk_t));
2127 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2129 trans_conn = session_lookup_connection_wt4 (fib_index0,
2130 &ip4_hdr->dst_address,
2131 &ip4_hdr->src_address,
2134 TRANSPORT_PROTO_SCTP,
2140 ip6_hdr = vlib_buffer_get_current (b0);
2141 sctp_hdr = ip6_next_header (ip6_hdr);
2143 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2144 sctp_chunk_hdr = &full_hdr->common_hdr;
2146 n_advance_bytes0 = sctp_header_bytes ();
2148 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2150 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2152 trans_conn = session_lookup_connection_wt6 (fib_index0,
2153 &ip6_hdr->dst_address,
2154 &ip6_hdr->src_address,
2157 TRANSPORT_PROTO_SCTP,
2163 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2165 error0 = SCTP_ERROR_LENGTH;
2169 sctp_conn = sctp_get_connection_from_transport (trans_conn);
2170 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2172 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2173 if (chunk_type >= UNKNOWN)
2176 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2178 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
2179 b0, UNRECOGNIZED_CHUNK_TYPE);
2181 error0 = SCTP_ERROR_UNKOWN_CHUNK;
2182 next0 = sctp_next_output (is_ip4);
2186 vnet_buffer (b0)->sctp.hdr_offset =
2187 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2189 /* Session exists */
2190 if (PREDICT_TRUE (0 != sctp_conn))
2192 /* Save connection index */
2193 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
2194 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2195 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2197 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2198 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
2200 SCTP_DBG_STATE_MACHINE
2201 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
2202 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2203 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2205 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2206 connection.c_index, trans_conn, sctp_conn,
2207 sctp_state_to_string (sctp_conn->state),
2208 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
2210 if (chunk_type == DATA)
2211 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2212 n_advance_bytes0, n_data_bytes0);
2219 next0 = SCTP_INPUT_NEXT_DROP;
2220 error0 = SCTP_ERROR_FILTERED;
2222 else if ((is_ip4 && tm->punt_unknown4) ||
2223 (!is_ip4 && tm->punt_unknown6))
2225 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2226 error0 = SCTP_ERROR_PUNT;
2230 next0 = SCTP_INPUT_NEXT_DROP;
2231 error0 = SCTP_ERROR_NO_LISTENER;
2233 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2234 phase_to_string (next0));
2239 b0->error = error0 ? node->errors[error0] : 0;
2241 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2243 sctp_rx_trace_t *t0 =
2244 vlib_add_trace (vm, node, b0, sizeof (*t0));
2245 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2247 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2248 n_left_to_next, bi0, next0);
2251 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2253 return from_frame->n_vectors;
2257 sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2258 vlib_frame_t * from_frame)
2260 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2264 sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2265 vlib_frame_t * from_frame)
2267 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2271 VLIB_REGISTER_NODE (sctp4_input_node) =
2273 .function = sctp4_input_dispatcher,
2274 .name = "sctp4-input",
2275 /* Takes a vector of packets. */
2276 .vector_size = sizeof (u32),
2277 .n_errors = SCTP_N_ERROR,
2278 .error_strings = sctp_error_strings,
2279 .n_next_nodes = SCTP_INPUT_N_NEXT,
2282 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2283 foreach_sctp4_input_next
2286 .format_buffer = format_sctp_header,
2287 .format_trace = format_sctp_rx_trace,
2291 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2294 VLIB_REGISTER_NODE (sctp6_input_node) =
2296 .function = sctp6_input_dispatcher,
2297 .name = "sctp6-input",
2298 /* Takes a vector of packets. */
2299 .vector_size = sizeof (u32),
2300 .n_errors = SCTP_N_ERROR,
2301 .error_strings = sctp_error_strings,
2302 .n_next_nodes = SCTP_INPUT_N_NEXT,
2305 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2306 foreach_sctp6_input_next
2309 .format_buffer = format_sctp_header,
2310 .format_trace = format_sctp_rx_trace,
2314 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2316 vlib_node_registration_t sctp4_input_node;
2317 vlib_node_registration_t sctp6_input_node;
2320 sctp_dispatch_table_init (sctp_main_t * tm)
2323 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2324 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2326 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2327 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2330 #define _(t,f,n,e) \
2332 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2333 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2337 * SCTP STATE-MACHINE states:
2339 * _(CLOSED, "CLOSED") \
2340 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2341 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2342 * _(ESTABLISHED, "ESTABLISHED") \
2343 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2344 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2345 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2346 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2348 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2349 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2350 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2351 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2352 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2353 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2354 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2355 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2356 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2357 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2358 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2359 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2360 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2361 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2362 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2363 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2365 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2366 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2367 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2368 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2369 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2370 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2371 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2372 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2373 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2374 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2375 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2376 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2377 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2378 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2379 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2380 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2383 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2384 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2385 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2386 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2387 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2388 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2389 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2390 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2391 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2392 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2393 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2394 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2396 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2397 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2398 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2399 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2402 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2403 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2404 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2405 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2406 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2408 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2410 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2411 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2412 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2413 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2414 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2415 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2416 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2417 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2418 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2419 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2422 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2423 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2424 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2425 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2426 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2428 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2430 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2431 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2433 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2434 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2435 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2437 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2438 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2439 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2440 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2441 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2444 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2445 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2446 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2447 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2448 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2449 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2450 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2451 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2452 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2454 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2456 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2457 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2458 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2459 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2460 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2463 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2464 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2465 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2466 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2467 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2468 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2469 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2470 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2471 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2473 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2475 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2476 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2477 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2478 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2479 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2482 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2483 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
2484 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2485 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2486 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2487 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2488 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2489 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2490 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2491 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2493 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2494 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2495 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2496 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2498 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2501 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2507 sctp_input_init (vlib_main_t * vm)
2509 clib_error_t *error = 0;
2510 sctp_main_t *tm = vnet_get_sctp_main ();
2512 if ((error = vlib_call_init_function (vm, sctp_init)))
2515 /* Initialize dispatch table. */
2516 sctp_dispatch_table_init (tm);
2521 VLIB_INIT_FUNCTION (sctp_input_init);
2524 * fd.io coding-style-patch-verification: ON
2527 * eval: (c-set-style "gnu")