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 <sctp/sctp.h>
17 #include <sctp/sctp_packet.h>
18 #include <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 <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,
87 #ifndef CLIB_MARCH_VARIANT
89 phase_to_string (u8 phase)
93 case SCTP_INPUT_NEXT_DROP:
94 return "SCTP_INPUT_NEXT_DROP";
95 case SCTP_INPUT_NEXT_LISTEN_PHASE:
96 return "SCTP_INPUT_NEXT_LISTEN_PHASE";
97 case SCTP_INPUT_NEXT_RCV_PHASE:
98 return "SCTP_INPUT_NEXT_RCV_PHASE";
99 case SCTP_INPUT_NEXT_ESTABLISHED_PHASE:
100 return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
101 case SCTP_INPUT_NEXT_SHUTDOWN_PHASE:
102 return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
103 case SCTP_INPUT_NEXT_PUNT_PHASE:
104 return "SCTP_INPUT_NEXT_PUNT_PHASE";
108 #endif /* CLIB_MARCH_VARIANT */
110 #define foreach_sctp4_input_next \
111 _ (DROP, "error-drop") \
112 _ (RCV_PHASE, "sctp4-rcv") \
113 _ (LISTEN_PHASE, "sctp4-listen") \
114 _ (ESTABLISHED_PHASE, "sctp4-established") \
115 _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
116 _ (PUNT_PHASE, "ip4-punt")
119 #define foreach_sctp6_input_next \
120 _ (DROP, "error-drop") \
121 _ (RCV_PHASE, "sctp6-rcv") \
122 _ (LISTEN_PHASE, "sctp6-listen") \
123 _ (ESTABLISHED_PHASE, "sctp6-established") \
124 _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
125 _ (PUNT_PHASE, "ip6-punt")
128 sctp_lookup_is_valid (transport_connection_t * trans_conn,
129 sctp_header_t * sctp_hdr)
131 sctp_connection_t *sctp_conn =
132 sctp_get_connection_from_transport (trans_conn);
137 u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
138 && (sctp_conn->state == SCTP_STATE_CLOSED
139 || trans_conn->rmt_port == sctp_hdr->src_port));
145 * Lookup transport connection
147 static sctp_connection_t *
148 sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
151 sctp_main_t *tm = vnet_get_sctp_main ();
152 sctp_header_t *sctp_hdr;
153 transport_connection_t *trans_conn;
154 sctp_connection_t *sctp_conn;
158 ip4_header_t *ip4_hdr;
159 ip4_hdr = vlib_buffer_get_current (b);
160 sctp_hdr = ip4_next_header (ip4_hdr);
161 trans_conn = session_lookup_connection_wt4 (fib_index,
162 &ip4_hdr->dst_address,
163 &ip4_hdr->src_address,
166 TRANSPORT_PROTO_SCTP,
167 thread_index, &is_filtered);
168 if (trans_conn == 0) /* Not primary connection */
170 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
172 if ((tm->connections[thread_index]->sub_conn[i].
173 connection.lcl_ip.ip4.as_u32 ==
174 ip4_hdr->dst_address.as_u32)
175 && (tm->connections[thread_index]->sub_conn[i].
176 connection.rmt_ip.ip4.as_u32 ==
177 ip4_hdr->src_address.as_u32))
180 &tm->connections[thread_index]->sub_conn[i].connection;
185 ASSERT (trans_conn != 0);
186 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
190 ip6_header_t *ip6_hdr;
191 ip6_hdr = vlib_buffer_get_current (b);
192 sctp_hdr = ip6_next_header (ip6_hdr);
193 trans_conn = session_lookup_connection_wt6 (fib_index,
194 &ip6_hdr->dst_address,
195 &ip6_hdr->src_address,
198 TRANSPORT_PROTO_SCTP,
199 thread_index, &is_filtered);
200 if (trans_conn == 0) /* Not primary connection */
202 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
204 if ((tm->connections[thread_index]->sub_conn[i].
205 connection.lcl_ip.ip6.as_u64[0] ==
206 ip6_hdr->dst_address.as_u64[0]
207 && tm->connections[thread_index]->sub_conn[i].
208 connection.lcl_ip.ip6.as_u64[1] ==
209 ip6_hdr->dst_address.as_u64[1])
210 && (tm->connections[thread_index]->sub_conn[i].
211 connection.rmt_ip.ip6.as_u64[0] ==
212 ip6_hdr->src_address.as_u64[0]
213 && tm->connections[thread_index]->
214 sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
215 ip6_hdr->src_address.as_u64[1]))
218 &tm->connections[thread_index]->sub_conn[i].connection;
223 ASSERT (trans_conn != 0);
224 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
226 sctp_conn = sctp_get_connection_from_transport (trans_conn);
232 sctp_header_t sctp_header;
233 sctp_connection_t sctp_connection;
236 #define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
237 : SCTP_NEXT_SCTP6_OUTPUT)
239 #define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
243 sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
244 sctp_connection_t * sctp_conn,
245 sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
250 clib_memcpy_fast (&rx_trace->sctp_connection, sctp_conn,
251 sizeof (rx_trace->sctp_connection));
255 sctp_hdr = sctp_buffer_hdr (b0);
257 clib_memcpy_fast (&rx_trace->sctp_header, sctp_hdr,
258 sizeof (rx_trace->sctp_header));
262 sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
265 u16 sctp_implied_packet_length = 0;
268 sctp_implied_packet_length =
269 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
271 sctp_implied_packet_length =
272 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
274 return sctp_implied_packet_length;
278 sctp_is_bundling (u16 sctp_implied_length,
279 sctp_chunks_common_hdr_t * sctp_common_hdr)
281 if (sctp_implied_length !=
282 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
288 sctp_handle_operation_err (sctp_header_t * sctp_hdr,
289 sctp_connection_t * sctp_conn, u8 idx,
290 vlib_buffer_t * b, u16 * next0)
292 sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
294 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
295 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
297 return SCTP_ERROR_INVALID_TAG;
300 if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
303 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
304 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
307 sctp_connection_cleanup (sctp_conn);
309 session_transport_closing_notify (&sctp_conn->
310 sub_conn[idx].connection);
314 return SCTP_ERROR_NONE;
318 sctp_handle_init (sctp_header_t * sctp_hdr,
319 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
320 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
321 u16 sctp_implied_length)
323 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
324 ip4_address_t ip4_addr;
325 ip6_address_t ip6_addr;
328 char hostname[FQDN_MAX_LENGTH];
330 /* Check the current state of the connection
332 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
333 * in the code below and by the "sctp_prepare_initack_chunk" function.
334 * However, for debugging purposes it is nice to have a message printed out
335 * for these corner-case scenarios.
337 if (sctp_conn->state != SCTP_STATE_CLOSED)
338 { /* UNEXPECTED scenario */
339 switch (sctp_conn->state)
341 case SCTP_STATE_COOKIE_WAIT:
342 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
343 sctp_prepare_initack_chunk_for_collision (sctp_conn,
344 SCTP_PRIMARY_PATH_IDX,
345 b0, &ip4_addr, &ip6_addr);
346 return SCTP_ERROR_NONE;
347 case SCTP_STATE_COOKIE_ECHOED:
348 case SCTP_STATE_SHUTDOWN_ACK_SENT:
349 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
350 if (sctp_conn->forming_association_changed == 0)
351 sctp_prepare_initack_chunk_for_collision (sctp_conn,
352 SCTP_PRIMARY_PATH_IDX,
356 sctp_prepare_abort_for_collision (sctp_conn,
357 SCTP_PRIMARY_PATH_IDX, b0,
358 &ip4_addr, &ip6_addr);
359 return SCTP_ERROR_NONE;
363 if (sctp_hdr->verification_tag != 0x0)
364 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
367 * It is not possible to bundle any other CHUNK with the INIT chunk
369 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
370 return SCTP_ERROR_BUNDLING_VIOLATION;
372 /* Save the INITIATE_TAG of the remote peer for this connection:
373 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
374 sctp_conn->remote_tag = init_chunk->initiate_tag;
375 sctp_conn->remote_initial_tsn =
376 clib_net_to_host_u32 (init_chunk->initial_tsn);
377 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
378 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
379 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
380 sctp_conn->remote_initial_tsn);
382 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
384 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
385 * optional parameters have been sent with the INIT chunk and we need to parse them.
387 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
388 if (length > sizeof (sctp_init_chunk_t))
390 /* There are optional parameters in the INIT chunk */
391 u16 pointer_offset = sizeof (sctp_init_chunk_t);
392 while (pointer_offset < length)
394 sctp_opt_params_hdr_t *opt_params_hdr =
395 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
397 switch (clib_net_to_host_u16 (opt_params_hdr->type))
399 case SCTP_IPV4_ADDRESS_TYPE:
401 sctp_ipv4_addr_param_t *ipv4 =
402 (sctp_ipv4_addr_param_t *) opt_params_hdr;
403 clib_memcpy_fast (&ip4_addr, &ipv4->address,
404 sizeof (ip4_address_t));
406 if (sctp_sub_connection_add_ip4 (vlib_get_main (),
408 [SCTP_PRIMARY_PATH_IDX].connection.
416 case SCTP_IPV6_ADDRESS_TYPE:
418 sctp_ipv6_addr_param_t *ipv6 =
419 (sctp_ipv6_addr_param_t *) opt_params_hdr;
420 clib_memcpy_fast (&ip6_addr, &ipv6->address,
421 sizeof (ip6_address_t));
423 if (sctp_sub_connection_add_ip6 (vlib_get_main (),
425 [SCTP_PRIMARY_PATH_IDX].connection.
433 case SCTP_COOKIE_PRESERVATIVE_TYPE:
435 sctp_cookie_preservative_param_t *cookie_pres =
436 (sctp_cookie_preservative_param_t *) opt_params_hdr;
437 sctp_conn->peer_cookie_life_span_increment =
438 cookie_pres->life_span_inc;
441 case SCTP_HOSTNAME_ADDRESS_TYPE:
443 sctp_hostname_param_t *hostname_addr =
444 (sctp_hostname_param_t *) opt_params_hdr;
445 clib_memcpy_fast (hostname, hostname_addr->hostname,
449 case SCTP_SUPPORTED_ADDRESS_TYPES:
455 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
459 /* Reuse buffer to make init-ack and send */
460 sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
461 add_ip4, &ip6_addr, add_ip6);
462 return SCTP_ERROR_NONE;
466 sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
467 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
468 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
469 u16 sctp_implied_length)
471 sctp_init_ack_chunk_t *init_ack_chunk =
472 (sctp_init_ack_chunk_t *) (sctp_hdr);
474 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
475 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
477 return SCTP_ERROR_INVALID_TAG;
481 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
483 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
484 return SCTP_ERROR_BUNDLING_VIOLATION;
486 return SCTP_ERROR_NONE;
490 sctp_handle_init_ack (sctp_header_t * sctp_hdr,
491 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
492 sctp_connection_t * sctp_conn, u8 idx,
493 vlib_buffer_t * b0, u16 sctp_implied_length)
495 sctp_init_ack_chunk_t *init_ack_chunk =
496 (sctp_init_ack_chunk_t *) (sctp_hdr);
498 char hostname[FQDN_MAX_LENGTH];
500 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
501 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
503 return SCTP_ERROR_INVALID_TAG;
507 * It is not possible to bundle any other CHUNK with the INIT chunk
509 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
510 return SCTP_ERROR_BUNDLING_VIOLATION;
512 /* Stop the T1_INIT timer */
513 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
515 sctp_calculate_rto (sctp_conn, idx);
517 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
518 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
519 sctp_conn->remote_initial_tsn =
520 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
521 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
522 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
523 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
524 sctp_conn->remote_initial_tsn);
525 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
527 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
529 if (length > sizeof (sctp_init_ack_chunk_t))
531 * There are optional parameters in the INIT ACK chunk
534 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
536 while (pointer_offset < length)
538 sctp_opt_params_hdr_t *opt_params_hdr =
539 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
542 switch (clib_net_to_host_u16 (opt_params_hdr->type))
544 case SCTP_IPV4_ADDRESS_TYPE:
546 sctp_ipv4_addr_param_t *ipv4 =
547 (sctp_ipv4_addr_param_t *) opt_params_hdr;
549 sctp_sub_connection_add_ip4 (vlib_get_main (),
551 [SCTP_PRIMARY_PATH_IDX].connection.
552 lcl_ip.ip4, &ipv4->address);
556 case SCTP_IPV6_ADDRESS_TYPE:
558 sctp_ipv6_addr_param_t *ipv6 =
559 (sctp_ipv6_addr_param_t *) opt_params_hdr;
561 sctp_sub_connection_add_ip6 (vlib_get_main (),
563 [SCTP_PRIMARY_PATH_IDX].connection.
564 lcl_ip.ip6, &ipv6->address);
568 case SCTP_STATE_COOKIE_TYPE:
570 sctp_state_cookie_param_t *state_cookie_param =
571 (sctp_state_cookie_param_t *) opt_params_hdr;
573 clib_memcpy_fast (&(sctp_conn->cookie_param),
575 sizeof (sctp_state_cookie_param_t));
579 case SCTP_HOSTNAME_ADDRESS_TYPE:
581 sctp_hostname_param_t *hostname_addr =
582 (sctp_hostname_param_t *) opt_params_hdr;
583 clib_memcpy_fast (hostname, hostname_addr->hostname,
587 case SCTP_UNRECOGNIZED_TYPE:
592 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
593 /* This indicates something really bad happened */
596 return SCTP_ERROR_INVALID_TAG;
598 pointer_offset += increment;
602 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
604 /* Start the T1_COOKIE timer */
605 sctp_timer_set (sctp_conn, idx,
606 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
608 return SCTP_ERROR_NONE;
611 /** Enqueue data out-of-order for delivery to application */
613 sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
614 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
616 int written, error = SCTP_ERROR_ENQUEUED;
619 session_enqueue_stream_connection (&sctp_conn->
620 sub_conn[conn_idx].connection, b, 0,
621 1 /* queue event */ ,
624 /* Update next_tsn_expected */
625 if (PREDICT_TRUE (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 /* If more data written than expected, account for out-of-order bytes. */
634 else if (written > data_len)
636 sctp_conn->next_tsn_expected += written;
638 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
639 sctp_conn->sub_conn[conn_idx].connection.c_index,
642 else if (written > 0)
644 /* We've written something but FIFO is probably full now */
645 sctp_conn->next_tsn_expected += written;
647 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
650 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
651 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
655 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
656 sctp_conn->sub_conn[conn_idx].connection.c_index);
658 return SCTP_ERROR_FIFO_FULL;
661 /* TODO: Update out_of_order_map & SACK list */
666 /** Enqueue data for delivery to application */
668 sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
669 u16 data_len, u8 conn_idx)
671 int written, error = SCTP_ERROR_ENQUEUED;
674 session_enqueue_stream_connection (&sctp_conn->
675 sub_conn[conn_idx].connection, b, 0,
676 1 /* queue event */ ,
679 /* Update next_tsn_expected */
680 if (PREDICT_TRUE (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 /* If more data written than expected, account for out-of-order bytes. */
689 else if (written > data_len)
691 sctp_conn->next_tsn_expected += written;
693 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
694 sctp_conn->sub_conn[conn_idx].connection.c_index,
697 else if (written > 0)
699 /* We've written something but FIFO is probably full now */
700 sctp_conn->next_tsn_expected += written;
702 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
705 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
706 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
710 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
711 sctp_conn->sub_conn[conn_idx].connection.c_index);
713 return SCTP_ERROR_FIFO_FULL;
720 sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
722 if (sctp_conn->conn_config.never_delay_sack)
724 SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
728 /* Section 4.4 of the RFC4960 */
729 if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
731 SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
732 sctp_state_to_string (sctp_conn->state));
738 SCTP_CONN_TRACKING_DBG
739 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
740 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
744 sctp_conn->ack_state += 1;
745 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
747 SCTP_CONN_TRACKING_DBG
748 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
749 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
757 sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
760 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
762 SCTP_CONN_TRACKING_DBG
763 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
764 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
765 sctp_conn->next_tsn_expected, tsn,
766 sctp_conn->next_tsn_expected - tsn);
773 sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
774 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
777 u32 error = 0, n_data_bytes;
780 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
781 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
783 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
784 sctp_conn->sub_conn[idx].enqueue_state = SCTP_ERROR_INVALID_TAG;
785 return sctp_conn->sub_conn[idx].enqueue_state;
788 sctp_buffer_opaque (b)->sctp.sid = sctp_data_chunk->stream_id;
789 sctp_buffer_opaque (b)->sctp.ssn = sctp_data_chunk->stream_seq;
791 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
793 vlib_buffer_advance (b, sctp_buffer_opaque (b)->sctp.data_offset);
794 u32 chunk_len = vnet_sctp_get_chunk_length (&sctp_data_chunk->chunk_hdr) -
795 (sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_header_t));
797 ASSERT (sctp_buffer_opaque (b)->sctp.data_len);
800 /* Padding was added: see RFC 4096 section 3.3.1 */
801 if (sctp_buffer_opaque (b)->sctp.data_len > chunk_len)
803 /* Let's change the data_len to the right amount calculated here now.
804 * We cannot do that in the generic sctp46_input_dispatcher node since
805 * that is common to all CHUNKS handling.
807 sctp_buffer_opaque (b)->sctp.data_len = chunk_len;
808 /* We need to change b->current_length so that downstream calls to
809 * session_enqueue_stream_connection (called by sctp_session_enqueue_data)
810 * push the correct amount of data to be enqueued.
812 b->current_length = chunk_len;
814 n_data_bytes = sctp_buffer_opaque (b)->sctp.data_len;
816 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
818 sctp_conn->last_rcvd_tsn = tsn;
820 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
822 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
823 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
825 if (bbit == 1 && ebit == 1) /* Unfragmented message */
827 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
828 * segments can be enqueued after fifo tail offset changes. */
829 if (PREDICT_FALSE (is_gapping == 1))
831 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
833 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
835 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
837 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
839 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
841 if (PREDICT_FALSE (is_gapping == 1))
843 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
845 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
847 else /* Middle piece of a fragmented user message */
849 if (PREDICT_FALSE (is_gapping == 1))
851 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
853 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
855 sctp_conn->last_rcvd_tsn = tsn;
857 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
859 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
861 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
862 sctp_prepare_sack_chunk (sctp_conn, idx, b);
865 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
867 sctp_conn->sub_conn[idx].enqueue_state = error;
873 sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
874 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
875 sctp_connection_t * sctp_conn, u8 idx,
876 vlib_buffer_t * b0, u16 * next0)
878 u64 now = sctp_time_now ();
880 sctp_cookie_echo_chunk_t *cookie_echo =
881 (sctp_cookie_echo_chunk_t *) sctp_hdr;
883 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
884 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
886 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
887 return SCTP_ERROR_INVALID_TAG;
890 sctp_calculate_rto (sctp_conn, idx);
893 clib_net_to_host_u64 (cookie_echo->cookie.creation_time);
894 u64 cookie_lifespan =
895 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
897 if (now > creation_time + cookie_lifespan)
899 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
900 now, creation_time, cookie_lifespan);
901 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
904 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
907 sctp_conn->state = SCTP_STATE_ESTABLISHED;
908 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
909 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
911 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
912 sctp_conn->sub_conn[idx].RTO);
914 session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
916 return SCTP_ERROR_NONE;
921 sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
922 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
923 sctp_connection_t * sctp_conn, u8 idx,
924 vlib_buffer_t * b0, u16 * next0)
926 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
927 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
929 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
930 return SCTP_ERROR_INVALID_TAG;
933 sctp_calculate_rto (sctp_conn, idx);
935 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
937 sctp_conn->state = SCTP_STATE_ESTABLISHED;
938 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
940 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
942 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
943 sctp_conn->sub_conn[idx].RTO);
945 session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
947 return SCTP_ERROR_NONE;
952 sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
953 vlib_frame_t * from_frame, int is_ip4)
955 sctp_main_t *tm = vnet_get_sctp_main ();
957 u32 n_left_from, next_index, *from, *to_next;
958 u32 my_thread_index = vm->thread_index;
960 from = vlib_frame_vector_args (from_frame);
961 n_left_from = from_frame->n_vectors;
963 next_index = node->cached_next_index;
965 while (n_left_from > 0)
969 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
971 while (n_left_from > 0 && n_left_to_next > 0)
975 sctp_header_t *sctp_hdr = 0;
976 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
977 ip4_header_t *ip4_hdr = 0;
978 ip6_header_t *ip6_hdr = 0;
979 sctp_connection_t *sctp_conn, *new_sctp_conn;
980 u16 sctp_implied_length = 0;
981 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
991 b0 = vlib_get_buffer (vm, bi0);
993 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
994 * will come from the half-open connections pool.
997 sctp_half_open_connection_get (sctp_buffer_opaque (b0)->
998 sctp.connection_index);
1000 if (PREDICT_FALSE (sctp_conn == 0))
1003 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1004 error0 = SCTP_ERROR_INVALID_CONNECTION;
1009 ip4_hdr = vlib_buffer_get_current (b0);
1010 sctp_hdr = ip4_next_header (ip4_hdr);
1011 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1015 ip6_hdr = vlib_buffer_get_current (b0);
1016 sctp_hdr = ip6_next_header (ip6_hdr);
1017 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1020 sctp_conn->sub_conn[idx].subconn_idx = idx;
1021 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1024 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1026 sctp_implied_length =
1027 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1029 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1035 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1036 b0, sctp_implied_length);
1038 if (error0 == SCTP_ERROR_NONE)
1040 pool_get (tm->connections[my_thread_index], new_sctp_conn);
1041 clib_memcpy_fast (new_sctp_conn, sctp_conn,
1042 sizeof (*new_sctp_conn));
1043 new_sctp_conn->sub_conn[idx].c_c_index =
1044 new_sctp_conn - tm->connections[my_thread_index];
1045 new_sctp_conn->sub_conn[idx].c_thread_index =
1047 new_sctp_conn->sub_conn[idx].PMTU =
1048 sctp_conn->sub_conn[idx].PMTU;
1049 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
1051 if (sctp_half_open_connection_cleanup (sctp_conn))
1054 ("Cannot cleanup half-open connection; not the owning thread");
1057 sctp_connection_timers_init (new_sctp_conn);
1059 sctp_init_cwnd (new_sctp_conn);
1062 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
1063 new_sctp_conn, idx, b0,
1064 sctp_implied_length);
1066 if (session_stream_connect_notify
1067 (&new_sctp_conn->sub_conn[idx].connection, 0))
1070 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1071 new_sctp_conn->sub_conn[idx].connection.c_index);
1072 sctp_connection_cleanup (new_sctp_conn);
1075 next0 = sctp_next_output (is_ip4);
1079 case OPERATION_ERROR:
1081 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1085 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1086 * are handled by the input-dispatcher function using the table-lookup
1087 * hence we should never get to the "default" case below.
1090 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1091 next0 = sctp_next_drop (is_ip4);
1095 if (error0 != SCTP_ERROR_NONE)
1097 clib_warning ("error while parsing chunk");
1098 sctp_connection_cleanup (sctp_conn);
1099 next0 = sctp_next_drop (is_ip4);
1104 b0->error = node->errors[error0];
1105 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1107 sctp_rx_trace_t *t0 =
1108 vlib_add_trace (vm, node, b0, sizeof (*t0));
1109 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1112 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1113 n_left_to_next, bi0, next0);
1116 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1118 return from_frame->n_vectors;
1121 VLIB_NODE_FN (sctp4_rcv_phase_node) (vlib_main_t * vm,
1122 vlib_node_runtime_t * node,
1123 vlib_frame_t * from_frame)
1125 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1128 VLIB_NODE_FN (sctp6_init_phase_node) (vlib_main_t * vm,
1129 vlib_node_runtime_t * node,
1130 vlib_frame_t * from_frame)
1132 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1136 format_sctp_rx_trace_short (u8 * s, va_list * args)
1138 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1139 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1140 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1142 s = format (s, "%d -> %d (%U)",
1143 clib_net_to_host_u16 (t->sctp_header.src_port),
1144 clib_net_to_host_u16 (t->sctp_header.dst_port),
1145 format_sctp_state, t->sctp_connection.state);
1151 VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1153 .name = "sctp4-rcv",
1154 /* Takes a vector of packets. */
1155 .vector_size = sizeof (u32),
1156 .n_errors = SCTP_N_ERROR,
1157 .error_strings = sctp_error_strings,
1158 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1161 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1162 foreach_sctp_state_next
1165 .format_trace = format_sctp_rx_trace_short,
1170 VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1172 .name = "sctp6-rcv",
1173 /* Takes a vector of packets. */
1174 .vector_size = sizeof (u32),
1175 .n_errors = SCTP_N_ERROR,
1176 .error_strings = sctp_error_strings,
1177 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1180 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1181 foreach_sctp_state_next
1184 .format_trace = format_sctp_rx_trace_short,
1189 sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1190 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1191 sctp_connection_t * sctp_conn, u8 idx,
1192 vlib_buffer_t * b0, u16 sctp_implied_length,
1195 sctp_shutdown_association_chunk_t *shutdown_chunk =
1196 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1198 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1199 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1201 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1202 return SCTP_ERROR_INVALID_TAG;
1206 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1208 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1209 return SCTP_ERROR_BUNDLING_VIOLATION;
1211 switch (sctp_conn->state)
1213 case SCTP_STATE_ESTABLISHED:
1214 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1215 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
1216 sctp_send_shutdown_ack (sctp_conn, idx, b0);
1219 case SCTP_STATE_SHUTDOWN_SENT:
1220 sctp_send_shutdown_ack (sctp_conn, idx, b0);
1224 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1226 return SCTP_ERROR_NONE;
1230 sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1231 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1232 sctp_connection_t * sctp_conn, u8 idx,
1233 vlib_buffer_t * b0, u16 sctp_implied_length,
1236 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1237 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1239 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1240 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1242 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1243 return SCTP_ERROR_INVALID_TAG;
1247 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1249 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1250 return SCTP_ERROR_BUNDLING_VIOLATION;
1252 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1253 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1254 * - STOP T2_SHUTDOWN timer
1255 * - SEND SHUTDOWN_COMPLETE chunk
1257 sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
1259 sctp_send_shutdown_complete (sctp_conn, idx, b0);
1261 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1263 return SCTP_ERROR_NONE;
1267 sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1268 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1269 sctp_connection_t * sctp_conn, u8 idx,
1270 vlib_buffer_t * b0, u16 sctp_implied_length,
1273 sctp_shutdown_complete_chunk_t *shutdown_complete =
1274 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1276 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1277 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1279 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1280 return SCTP_ERROR_INVALID_TAG;
1284 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1286 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1287 return SCTP_ERROR_BUNDLING_VIOLATION;
1289 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1291 session_transport_closing_notify (&sctp_conn->sub_conn[idx].connection);
1293 sctp_conn->state = SCTP_STATE_CLOSED;
1295 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1297 return SCTP_ERROR_NONE;
1301 sctp46_shutdown_phase_inline (vlib_main_t * vm,
1302 vlib_node_runtime_t * node,
1303 vlib_frame_t * from_frame, int is_ip4)
1305 u32 n_left_from, next_index, *from, *to_next;
1306 u32 my_thread_index = vm->thread_index;
1308 from = vlib_frame_vector_args (from_frame);
1309 n_left_from = from_frame->n_vectors;
1311 next_index = node->cached_next_index;
1313 while (n_left_from > 0)
1317 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1319 while (n_left_from > 0 && n_left_to_next > 0)
1323 sctp_rx_trace_t *sctp_trace;
1324 sctp_header_t *sctp_hdr = 0;
1325 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1326 ip4_header_t *ip4_hdr = 0;
1327 ip6_header_t *ip6_hdr = 0;
1328 sctp_connection_t *sctp_conn;
1329 u16 sctp_implied_length = 0;
1330 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
1338 n_left_to_next -= 1;
1340 b0 = vlib_get_buffer (vm, bi0);
1342 sctp_connection_get (sctp_buffer_opaque (b0)->
1343 sctp.connection_index, my_thread_index);
1345 if (PREDICT_FALSE (sctp_conn == 0))
1348 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1349 error0 = SCTP_ERROR_INVALID_CONNECTION;
1355 ip4_hdr = vlib_buffer_get_current (b0);
1356 sctp_hdr = ip4_next_header (ip4_hdr);
1357 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1361 ip6_hdr = vlib_buffer_get_current (b0);
1362 sctp_hdr = ip6_next_header (ip6_hdr);
1363 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1366 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1367 sctp_chunk_hdr = &full_hdr->common_hdr;
1369 sctp_implied_length =
1370 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1372 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1377 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1378 idx, b0, sctp_implied_length, &next0);
1383 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1384 idx, b0, sctp_implied_length,
1388 case SHUTDOWN_COMPLETE:
1390 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
1392 sctp_implied_length, &next0);
1394 sctp_connection_cleanup (sctp_conn);
1398 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1399 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1403 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1404 sctp_conn, idx, b0, &next0);
1407 case OPERATION_ERROR:
1409 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1413 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1414 sctp_prepare_operation_error (sctp_conn, idx, b0,
1415 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1416 error0 = SCTP_ERROR_NONE;
1417 next0 = sctp_next_output (is_ip4);
1419 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1420 * are handled by the input-dispatcher function using the table-lookup
1421 * hence we should never get to the "default" case below.
1424 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1425 next0 = sctp_next_drop (is_ip4);
1429 if (error0 != SCTP_ERROR_NONE)
1431 clib_warning ("error while parsing chunk");
1432 sctp_connection_cleanup (sctp_conn);
1433 next0 = sctp_next_drop (is_ip4);
1438 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1441 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
1443 if (sctp_hdr != NULL)
1444 clib_memcpy_fast (&sctp_trace->sctp_header, sctp_hdr,
1445 sizeof (sctp_trace->sctp_header));
1447 if (sctp_conn != NULL)
1448 clib_memcpy_fast (&sctp_trace->sctp_connection, sctp_conn,
1449 sizeof (sctp_trace->sctp_connection));
1452 b0->error = node->errors[error0];
1454 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1455 n_left_to_next, bi0, next0);
1458 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1461 return from_frame->n_vectors;
1465 VLIB_NODE_FN (sctp4_shutdown_phase_node) (vlib_main_t * vm,
1466 vlib_node_runtime_t * node,
1467 vlib_frame_t * from_frame)
1469 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1472 VLIB_NODE_FN (sctp6_shutdown_phase_node) (vlib_main_t * vm,
1473 vlib_node_runtime_t * node,
1474 vlib_frame_t * from_frame)
1476 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1480 VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1482 .name = "sctp4-shutdown",
1483 /* Takes a vector of packets. */
1484 .vector_size = sizeof (u32),
1485 .n_errors = SCTP_N_ERROR,
1486 .error_strings = sctp_error_strings,
1487 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1490 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1491 foreach_sctp_state_next
1494 .format_trace = format_sctp_rx_trace_short,
1499 VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1501 .name = "sctp6-shutdown",
1502 /* Takes a vector of packets. */
1503 .vector_size = sizeof (u32),
1504 .n_errors = SCTP_N_ERROR,
1505 .error_strings = sctp_error_strings,
1506 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1509 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1510 foreach_sctp_state_next
1513 .format_trace = format_sctp_rx_trace_short,
1518 sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
1519 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
1523 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1524 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1526 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1527 return SCTP_ERROR_INVALID_TAG;
1530 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1532 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1534 /* Section 7.2.2; point (2) */
1535 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1536 sctp_conn->sub_conn[idx].partially_acked_bytes =
1537 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1539 /* Section 7.2.2; point (5) */
1540 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1541 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1543 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1545 sctp_calculate_rto (sctp_conn, idx);
1547 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1548 sctp_conn->sub_conn[idx].RTO);
1550 sctp_conn->sub_conn[idx].RTO_pending = 0;
1552 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1554 return SCTP_ERROR_NONE;
1558 sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
1559 sctp_connection_t * sctp_conn, u8 idx,
1560 vlib_buffer_t * b0, u16 * next0)
1562 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1563 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1565 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1566 return SCTP_ERROR_INVALID_TAG;
1569 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
1571 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1573 return SCTP_ERROR_NONE;
1577 sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
1578 sctp_connection_t * sctp_conn, u8 idx,
1579 vlib_buffer_t * b0, u16 * next0)
1581 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1583 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1585 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1586 sctp_conn->sub_conn[idx].RTO);
1588 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1590 return SCTP_ERROR_NONE;
1594 sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
1595 u8 is_ip4, u8 evt, u8 val)
1597 if (PREDICT_TRUE (!val))
1601 vlib_node_increment_counter (vm, sctp4_node, evt, val);
1603 vlib_node_increment_counter (vm, sctp6_node, evt, val);
1607 sctp46_listen_process_inline (vlib_main_t * vm,
1608 vlib_node_runtime_t * node,
1609 vlib_frame_t * from_frame, int is_ip4)
1611 u32 n_left_from, next_index, *from, *to_next;
1612 u32 my_thread_index = vm->thread_index;
1614 from = vlib_frame_vector_args (from_frame);
1615 n_left_from = from_frame->n_vectors;
1617 next_index = node->cached_next_index;
1619 while (n_left_from > 0)
1623 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1625 while (n_left_from > 0 && n_left_to_next > 0)
1629 sctp_header_t *sctp_hdr = 0;
1630 ip4_header_t *ip4_hdr;
1631 ip6_header_t *ip6_hdr;
1632 sctp_connection_t *child_conn;
1633 sctp_connection_t *sctp_listener;
1634 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
1641 n_left_to_next -= 1;
1643 b0 = vlib_get_buffer (vm, bi0);
1645 sctp_listener_get (sctp_buffer_opaque (b0)->
1646 sctp.connection_index);
1650 ip4_hdr = vlib_buffer_get_current (b0);
1651 sctp_hdr = ip4_next_header (ip4_hdr);
1655 ip6_hdr = vlib_buffer_get_current (b0);
1656 sctp_hdr = ip6_next_header (ip6_hdr);
1660 sctp_lookup_connection (sctp_listener->sub_conn
1661 [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
1662 my_thread_index, is_ip4);
1664 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1667 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1668 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1670 sctp_state_to_string (child_conn->state));
1671 error0 = SCTP_ERROR_CREATE_EXISTS;
1675 /* Create child session and send SYN-ACK */
1676 child_conn = sctp_connection_new (my_thread_index);
1677 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1678 SCTP_PRIMARY_PATH_IDX;
1679 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
1681 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
1683 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1684 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1685 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1686 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1687 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
1688 child_conn->state = SCTP_STATE_CLOSED;
1689 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1690 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1691 connection.fib_index;
1695 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
1696 ip4_hdr->dst_address.as_u32;
1697 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
1698 ip4_hdr->src_address.as_u32;
1702 clib_memcpy_fast (&child_conn->
1703 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
1704 &ip6_hdr->dst_address,
1705 sizeof (ip6_address_t));
1706 clib_memcpy_fast (&child_conn->
1707 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
1708 &ip6_hdr->src_address,
1709 sizeof (ip6_address_t));
1712 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1713 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1715 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1716 if (chunk_type != INIT && chunk_type != DATA
1717 && chunk_type != OPERATION_ERROR)
1720 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1721 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1722 connection.c_index, sctp_chunk_to_string (chunk_type));
1724 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1725 next0 = sctp_next_drop (is_ip4);
1729 u16 sctp_implied_length =
1730 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1735 sctp_connection_timers_init (child_conn);
1737 sctp_init_snd_vars (child_conn);
1739 sctp_init_cwnd (child_conn);
1742 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1743 sctp_implied_length);
1745 if (error0 == SCTP_ERROR_NONE)
1747 if (session_stream_accept
1749 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
1751 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index,
1753 sub_conn[SCTP_PRIMARY_PATH_IDX].c_thread_index, 0))
1755 clib_warning ("session accept fail");
1756 sctp_connection_cleanup (child_conn);
1757 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1760 next0 = sctp_next_output (is_ip4);
1764 /* Reception of a DATA chunk whilst in the CLOSED state is called
1765 * "Out of the Blue" packet and handling of the chunk needs special treatment
1766 * as per RFC4960 section 8.4
1771 case OPERATION_ERROR:
1773 sctp_handle_operation_err (sctp_hdr, child_conn,
1774 SCTP_PRIMARY_PATH_IDX, b0, &next0);
1779 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1781 sctp_rx_trace_t *t0 =
1782 vlib_add_trace (vm, node, b0, sizeof (*t0));
1783 clib_memcpy_fast (&t0->sctp_header, sctp_hdr,
1784 sizeof (t0->sctp_header));
1785 clib_memcpy_fast (&t0->sctp_connection, sctp_listener,
1786 sizeof (t0->sctp_connection));
1789 b0->error = node->errors[error0];
1791 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1792 n_left_to_next, bi0, next0);
1794 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1797 return from_frame->n_vectors;
1800 VLIB_NODE_FN (sctp4_listen_phase_node) (vlib_main_t * vm,
1801 vlib_node_runtime_t * node,
1802 vlib_frame_t * from_frame)
1804 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1807 VLIB_NODE_FN (sctp6_listen_phase_node) (vlib_main_t * vm,
1808 vlib_node_runtime_t * node,
1809 vlib_frame_t * from_frame)
1811 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1815 sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1816 vlib_frame_t * from_frame, int is_ip4)
1818 sctp_main_t *sm = vnet_get_sctp_main ();
1819 u32 n_left_from, next_index, *from, *to_next;
1820 u32 my_thread_index = vm->thread_index, errors = 0;
1822 from = vlib_frame_vector_args (from_frame);
1823 n_left_from = from_frame->n_vectors;
1825 next_index = node->cached_next_index;
1827 while (n_left_from > 0)
1831 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1833 while (n_left_from > 0 && n_left_to_next > 0)
1837 sctp_header_t *sctp_hdr = 0;
1838 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1839 ip4_header_t *ip4_hdr = 0;
1840 ip6_header_t *ip6_hdr = 0;
1841 sctp_connection_t *sctp_conn;
1842 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1843 SCTP_ESTABLISHED_PHASE_N_NEXT;
1851 n_left_to_next -= 1;
1853 b0 = vlib_get_buffer (vm, bi0);
1855 sctp_connection_get (sctp_buffer_opaque (b0)->
1856 sctp.connection_index, my_thread_index);
1858 if (PREDICT_FALSE (sctp_conn == 0))
1861 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1862 error0 = SCTP_ERROR_INVALID_CONNECTION;
1867 ip4_hdr = vlib_buffer_get_current (b0);
1868 sctp_hdr = ip4_next_header (ip4_hdr);
1869 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1873 ip6_hdr = vlib_buffer_get_current (b0);
1874 sctp_hdr = ip6_next_header (ip6_hdr);
1875 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1878 sctp_conn->sub_conn[idx].subconn_idx = idx;
1880 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1882 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1884 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1890 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1896 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1902 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
1903 sctp_conn, idx, b0, &next0);
1908 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
1909 sctp_conn, idx, b0, &next0);
1914 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
1915 sctp_conn, idx, b0, &next0);
1920 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1921 sctp_conn, idx, b0, &next0);
1924 case OPERATION_ERROR:
1926 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1930 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1931 * are handled by the input-dispatcher function using the table-lookup
1932 * hence we should never get to the "default" case below.
1935 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1936 next0 = sctp_next_drop (is_ip4);
1941 b0->error = node->errors[error0];
1942 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1944 sctp_rx_trace_t *t0 =
1945 vlib_add_trace (vm, node, b0, sizeof (*t0));
1946 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1949 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1950 n_left_to_next, bi0, next0);
1953 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1956 errors = session_main_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1959 sctp_node_inc_counter (vm, is_ip4, sm->sctp4_established_phase_node_index,
1960 sm->sctp6_established_phase_node_index,
1961 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1962 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1964 return from_frame->n_vectors;
1967 VLIB_NODE_FN (sctp4_established_phase_node) (vlib_main_t * vm,
1968 vlib_node_runtime_t * node,
1969 vlib_frame_t * from_frame)
1971 return sctp46_established_phase_inline (vm, node, from_frame,
1975 VLIB_NODE_FN (sctp6_established_phase_node) (vlib_main_t * vm,
1976 vlib_node_runtime_t * node,
1977 vlib_frame_t * from_frame)
1979 return sctp46_established_phase_inline (vm, node, from_frame,
1984 format_sctp_rx_trace (u8 * s, va_list * args)
1986 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1987 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1988 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1989 u32 indent = format_get_indent (s);
1991 s = format (s, "%U\n%U%U",
1992 format_sctp_header, &t->sctp_header, 128,
1993 format_white_space, indent,
1994 format_sctp_connection, &t->sctp_connection, 1);
2000 VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
2002 .name = "sctp4-listen",
2003 /* Takes a vector of packets. */
2004 .vector_size = sizeof (u32),
2005 .n_errors = SCTP_N_ERROR,
2006 .error_strings = sctp_error_strings,
2007 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2010 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2011 foreach_sctp_state_next
2014 .format_trace = format_sctp_rx_trace_short,
2019 VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
2021 .name = "sctp6-listen",
2022 /* Takes a vector of packets. */
2023 .vector_size = sizeof (u32),
2024 .n_errors = SCTP_N_ERROR,
2025 .error_strings = sctp_error_strings,
2026 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2029 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2030 foreach_sctp_state_next
2033 .format_trace = format_sctp_rx_trace_short,
2038 VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2040 .name = "sctp4-established",
2041 /* Takes a vector of packets. */
2042 .vector_size = sizeof (u32),
2043 .n_errors = SCTP_N_ERROR,
2044 .error_strings = sctp_error_strings,
2045 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2048 #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2049 foreach_sctp_state_next
2052 .format_trace = format_sctp_rx_trace_short,
2057 VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2059 .name = "sctp6-established",
2060 /* Takes a vector of packets. */
2061 .vector_size = sizeof (u32),
2062 .n_errors = SCTP_N_ERROR,
2063 .error_strings = sctp_error_strings,
2064 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2067 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2068 foreach_sctp_state_next
2071 .format_trace = format_sctp_rx_trace_short,
2076 * This is the function executed first for the SCTP graph.
2077 * It takes care of doing the initial message parsing and
2078 * dispatch to the specialized function.
2081 sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2082 vlib_frame_t * from_frame, int is_ip4)
2084 u32 n_left_from, next_index, *from, *to_next;
2085 u32 my_thread_index = vm->thread_index;
2087 sctp_main_t *tm = vnet_get_sctp_main ();
2089 from = vlib_frame_vector_args (from_frame);
2090 n_left_from = from_frame->n_vectors;
2091 next_index = node->cached_next_index;
2092 sctp_set_time_now (my_thread_index);
2094 while (n_left_from > 0)
2098 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2100 while (n_left_from > 0 && n_left_to_next > 0)
2102 int n_advance_bytes0, n_data_bytes0;
2103 u32 bi0, fib_index0;
2105 sctp_header_t *sctp_hdr = 0;
2106 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2107 sctp_connection_t *sctp_conn;
2108 transport_connection_t *trans_conn;
2109 ip4_header_t *ip4_hdr;
2110 ip6_header_t *ip6_hdr;
2111 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2118 n_left_to_next -= 1;
2120 b0 = vlib_get_buffer (vm, bi0);
2121 sctp_buffer_opaque (b0)->sctp.flags = 0;
2122 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2124 /* Checksum computed by ipx_local no need to compute again */
2128 ip4_hdr = vlib_buffer_get_current (b0);
2129 sctp_hdr = ip4_next_header (ip4_hdr);
2131 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2132 sctp_chunk_hdr = &full_hdr->common_hdr;
2135 (ip4_header_bytes (ip4_hdr) +
2136 sizeof (sctp_payload_data_chunk_t));
2138 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2140 trans_conn = session_lookup_connection_wt4 (fib_index0,
2141 &ip4_hdr->dst_address,
2142 &ip4_hdr->src_address,
2145 TRANSPORT_PROTO_SCTP,
2151 ip6_hdr = vlib_buffer_get_current (b0);
2152 sctp_hdr = ip6_next_header (ip6_hdr);
2154 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2155 sctp_chunk_hdr = &full_hdr->common_hdr;
2157 n_advance_bytes0 = sctp_header_bytes ();
2159 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2161 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2163 trans_conn = session_lookup_connection_wt6 (fib_index0,
2164 &ip6_hdr->dst_address,
2165 &ip6_hdr->src_address,
2168 TRANSPORT_PROTO_SCTP,
2174 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2176 error0 = SCTP_ERROR_LENGTH;
2180 sctp_conn = sctp_get_connection_from_transport (trans_conn);
2181 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2183 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2184 if (chunk_type >= UNKNOWN)
2187 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2189 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
2190 b0, UNRECOGNIZED_CHUNK_TYPE);
2192 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
2193 next0 = sctp_next_output (is_ip4);
2197 sctp_buffer_opaque (b0)->sctp.hdr_offset =
2198 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2200 /* Session exists */
2201 if (PREDICT_TRUE (0 != sctp_conn))
2203 /* Save connection index */
2204 sctp_buffer_opaque (b0)->sctp.connection_index
2205 = trans_conn->c_index;
2206 sctp_buffer_opaque (b0)->sctp.data_offset = n_advance_bytes0;
2207 sctp_buffer_opaque (b0)->sctp.data_len = n_data_bytes0;
2209 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2210 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
2212 SCTP_DBG_STATE_MACHINE
2213 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
2214 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2215 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2217 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2218 connection.c_index, trans_conn, sctp_conn,
2219 sctp_state_to_string (sctp_conn->state),
2220 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
2222 if (chunk_type == DATA)
2223 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2224 n_advance_bytes0, n_data_bytes0);
2231 next0 = SCTP_INPUT_NEXT_DROP;
2232 error0 = SCTP_ERROR_NONE + result;
2234 else if ((is_ip4 && tm->punt_unknown4) ||
2235 (!is_ip4 && tm->punt_unknown6))
2237 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2238 error0 = SCTP_ERROR_PUNT;
2242 next0 = SCTP_INPUT_NEXT_DROP;
2243 error0 = SCTP_ERROR_NO_LISTENER;
2245 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2246 phase_to_string (next0));
2251 b0->error = error0 ? node->errors[error0] : 0;
2253 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2255 sctp_rx_trace_t *t0 =
2256 vlib_add_trace (vm, node, b0, sizeof (*t0));
2257 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2259 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2260 n_left_to_next, bi0, next0);
2263 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2265 return from_frame->n_vectors;
2268 VLIB_NODE_FN (sctp4_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
2269 vlib_frame_t * from_frame)
2271 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2274 VLIB_NODE_FN (sctp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
2275 vlib_frame_t * from_frame)
2277 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2281 VLIB_REGISTER_NODE (sctp4_input_node) =
2283 .name = "sctp4-input",
2284 /* Takes a vector of packets. */
2285 .vector_size = sizeof (u32),
2286 .n_errors = SCTP_N_ERROR,
2287 .error_strings = sctp_error_strings,
2288 .n_next_nodes = SCTP_INPUT_N_NEXT,
2291 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2292 foreach_sctp4_input_next
2295 .format_buffer = format_sctp_header,
2296 .format_trace = format_sctp_rx_trace,
2301 VLIB_REGISTER_NODE (sctp6_input_node) =
2303 .name = "sctp6-input",
2304 /* Takes a vector of packets. */
2305 .vector_size = sizeof (u32),
2306 .n_errors = SCTP_N_ERROR,
2307 .error_strings = sctp_error_strings,
2308 .n_next_nodes = SCTP_INPUT_N_NEXT,
2311 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2312 foreach_sctp6_input_next
2315 .format_buffer = format_sctp_header,
2316 .format_trace = format_sctp_rx_trace,
2320 #ifndef CLIB_MARCH_VARIANT
2322 sctp_dispatch_table_init (sctp_main_t * tm)
2325 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2326 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2328 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2329 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2332 #define _(t,f,n,e) \
2334 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2335 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2339 * SCTP STATE-MACHINE states:
2341 * _(CLOSED, "CLOSED") \
2342 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2343 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2344 * _(ESTABLISHED, "ESTABLISHED") \
2345 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2346 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2347 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2348 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2350 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2351 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2352 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2353 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2354 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2355 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2356 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2357 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2358 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2359 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2360 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2361 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2362 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2363 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2364 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2365 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2367 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2368 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2369 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2370 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2371 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2372 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2373 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2374 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2375 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2376 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2377 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2378 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2379 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2380 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2381 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2382 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2385 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2386 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2387 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2388 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2389 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2390 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2391 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2392 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2393 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2394 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2395 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2396 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2398 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2399 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2400 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2401 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2404 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2405 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2406 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2407 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2408 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2410 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2412 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2413 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2414 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2415 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2416 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2417 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2418 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2419 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2420 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2421 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2424 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2425 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2426 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2427 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2428 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2430 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2432 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2433 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2435 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2436 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2437 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2439 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2440 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2441 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2442 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2443 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2446 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2447 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2448 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2449 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2450 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2451 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2452 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2453 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2454 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2456 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2458 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2459 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2460 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2461 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2462 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2465 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2466 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2467 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2468 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2469 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2470 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2471 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2472 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2473 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2475 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2477 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2478 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2479 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2480 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2481 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2484 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2485 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
2486 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2487 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2488 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2489 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2490 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2491 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2492 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2493 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2495 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2496 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2497 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2498 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2500 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2503 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2509 sctp_input_init (vlib_main_t * vm)
2511 clib_error_t *error = 0;
2512 sctp_main_t *tm = vnet_get_sctp_main ();
2514 if ((error = vlib_call_init_function (vm, sctp_init)))
2517 /* Initialize dispatch table. */
2518 sctp_dispatch_table_init (tm);
2523 VLIB_INIT_FUNCTION (sctp_input_init);
2524 #endif /* CLIB_MARCH_VARIANT */
2527 * fd.io coding-style-patch-verification: ON
2530 * eval: (c-set-style "gnu")