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 _ (DROP, "error-drop") \
31 _ (SCTP4_OUTPUT, "sctp4-output") \
32 _ (SCTP6_OUTPUT, "sctp6-output")
34 typedef enum _sctp_established_phase_next
36 #define _(s,n) SCTP_ESTABLISHED_PHASE_NEXT_##s,
37 foreach_sctp_state_next
39 SCTP_ESTABLISHED_PHASE_N_NEXT,
40 } sctp_established_phase_next_t;
42 typedef enum _sctp_rcv_phase_next
44 #define _(s,n) SCTP_RCV_PHASE_NEXT_##s,
45 foreach_sctp_state_next
47 SCTP_RCV_PHASE_N_NEXT,
48 } sctp_rcv_phase_next_t;
50 typedef enum _sctp_listen_phase_next
52 #define _(s,n) SCTP_LISTEN_PHASE_NEXT_##s,
53 foreach_sctp_state_next
55 SCTP_LISTEN_PHASE_N_NEXT,
56 } sctp_listen_phase_next_t;
58 typedef enum _sctp_shutdown_phase_next
60 #define _(s,n) SCTP_SHUTDOWN_PHASE_NEXT_##s,
61 foreach_sctp_state_next
63 SCTP_SHUTDOWN_PHASE_N_NEXT,
64 } sctp_shutdown_phase_next_t;
66 /* Generic, state independent indices */
67 typedef enum _sctp_state_next
69 #define _(s,n) SCTP_NEXT_##s,
70 foreach_sctp_state_next
75 typedef enum _sctp_input_next
78 SCTP_INPUT_NEXT_LISTEN_PHASE,
79 SCTP_INPUT_NEXT_RCV_PHASE,
80 SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
81 SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
82 SCTP_INPUT_NEXT_PUNT_PHASE,
87 phase_to_string (u8 phase)
91 case SCTP_INPUT_NEXT_DROP:
92 return "SCTP_INPUT_NEXT_DROP";
93 case SCTP_INPUT_NEXT_LISTEN_PHASE:
94 return "SCTP_INPUT_NEXT_LISTEN_PHASE";
95 case SCTP_INPUT_NEXT_RCV_PHASE:
96 return "SCTP_INPUT_NEXT_RCV_PHASE";
97 case SCTP_INPUT_NEXT_ESTABLISHED_PHASE:
98 return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
99 case SCTP_INPUT_NEXT_SHUTDOWN_PHASE:
100 return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
101 case SCTP_INPUT_NEXT_PUNT_PHASE:
102 return "SCTP_INPUT_NEXT_PUNT_PHASE";
107 #define foreach_sctp4_input_next \
108 _ (DROP, "error-drop") \
109 _ (RCV_PHASE, "sctp4-rcv") \
110 _ (LISTEN_PHASE, "sctp4-listen") \
111 _ (ESTABLISHED_PHASE, "sctp4-established") \
112 _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
113 _ (PUNT_PHASE, "ip4-punt")
116 #define foreach_sctp6_input_next \
117 _ (DROP, "error-drop") \
118 _ (RCV_PHASE, "sctp6-rcv") \
119 _ (LISTEN_PHASE, "sctp6-listen") \
120 _ (ESTABLISHED_PHASE, "sctp6-established") \
121 _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
122 _ (PUNT_PHASE, "ip6-punt")
125 sctp_lookup_is_valid (transport_connection_t * t_conn,
126 sctp_header_t * sctp_hdr)
128 sctp_connection_t *sctp_conn = sctp_get_connection_from_transport (t_conn);
133 u8 is_valid = (t_conn->lcl_port == sctp_hdr->dst_port
134 && (sctp_conn->state == SCTP_STATE_CLOSED
135 || t_conn->rmt_port == sctp_hdr->src_port));
141 * Lookup transport connection
143 static sctp_connection_t *
144 sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
147 sctp_main_t *tm = vnet_get_sctp_main ();
148 sctp_header_t *sctp_hdr;
149 transport_connection_t *tconn;
150 sctp_connection_t *sctp_conn;
154 ip4_header_t *ip4_hdr;
155 ip4_hdr = vlib_buffer_get_current (b);
156 sctp_hdr = ip4_next_header (ip4_hdr);
157 tconn = session_lookup_connection_wt4 (fib_index,
158 &ip4_hdr->dst_address,
159 &ip4_hdr->src_address,
162 TRANSPORT_PROTO_SCTP,
163 thread_index, &is_filtered);
164 if (tconn == 0) /* Not primary connection */
166 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
168 if ((tm->connections[thread_index]->sub_conn[i].
169 connection.lcl_ip.ip4.as_u32 ==
170 ip4_hdr->dst_address.as_u32)
171 && (tm->connections[thread_index]->sub_conn[i].
172 connection.rmt_ip.ip4.as_u32 ==
173 ip4_hdr->src_address.as_u32))
176 &tm->connections[thread_index]->sub_conn[i].connection;
182 ASSERT (sctp_lookup_is_valid (tconn, sctp_hdr));
186 ip6_header_t *ip6_hdr;
187 ip6_hdr = vlib_buffer_get_current (b);
188 sctp_hdr = ip6_next_header (ip6_hdr);
189 tconn = session_lookup_connection_wt6 (fib_index,
190 &ip6_hdr->dst_address,
191 &ip6_hdr->src_address,
194 TRANSPORT_PROTO_SCTP,
195 thread_index, &is_filtered);
196 if (tconn == 0) /* Not primary connection */
198 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
200 if ((tm->connections[thread_index]->sub_conn[i].
201 connection.lcl_ip.ip6.as_u64[0] ==
202 ip6_hdr->dst_address.as_u64[0]
203 && tm->connections[thread_index]->sub_conn[i].
204 connection.lcl_ip.ip6.as_u64[1] ==
205 ip6_hdr->dst_address.as_u64[1])
206 && (tm->connections[thread_index]->sub_conn[i].
207 connection.rmt_ip.ip6.as_u64[0] ==
208 ip6_hdr->src_address.as_u64[0]
209 && tm->connections[thread_index]->
210 sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
211 ip6_hdr->src_address.as_u64[1]))
214 &tm->connections[thread_index]->sub_conn[i].connection;
220 ASSERT (sctp_lookup_is_valid (tconn, sctp_hdr));
222 sctp_conn = sctp_get_connection_from_transport (tconn);
228 sctp_header_t sctp_header;
229 sctp_connection_t sctp_connection;
232 #define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
233 : SCTP_NEXT_SCTP6_OUTPUT)
237 sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
238 sctp_connection_t * sctp_conn,
239 sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
244 clib_memcpy (&rx_trace->sctp_connection, sctp_conn,
245 sizeof (rx_trace->sctp_connection));
249 sctp_hdr = sctp_buffer_hdr (b0);
251 clib_memcpy (&rx_trace->sctp_header, sctp_hdr,
252 sizeof (rx_trace->sctp_header));
256 sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
259 u16 sctp_implied_packet_length = 0;
262 sctp_implied_packet_length =
263 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
265 sctp_implied_packet_length =
266 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
268 return sctp_implied_packet_length;
272 sctp_is_bundling (u16 sctp_implied_length,
273 sctp_chunks_common_hdr_t * sctp_common_hdr)
275 if (sctp_implied_length !=
276 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
282 sctp_handle_init (sctp_header_t * sctp_hdr,
283 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
284 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
285 u16 sctp_implied_length)
287 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
288 ip4_address_t *ip4_addr = 0;
289 ip6_address_t *ip6_addr = 0;
290 char hostname[FQDN_MAX_LENGTH];
292 /* Check the current state of the connection
294 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
295 * in the code below and by the "sctp_prepare_initack_chunk" function.
296 * However, for debugging purposes it is nice to have a message printed out
297 * for these corner-case scenarios.
299 if (sctp_conn->state != SCTP_STATE_CLOSED)
300 { /* UNEXPECTED scenario */
301 switch (sctp_conn->state)
303 case SCTP_STATE_COOKIE_WAIT: /* TODO */
304 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
306 case SCTP_STATE_COOKIE_ECHOED: /* TODO */
307 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
312 if (sctp_hdr->verification_tag != 0x0)
313 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
316 * It is not possible to bundle any other CHUNK with the INIT chunk
318 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
319 return SCTP_ERROR_BUNDLING_VIOLATION;
321 /* Save the INITIATE_TAG of the remote peer for this connection:
322 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
323 sctp_conn->remote_tag = init_chunk->initiate_tag;
324 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
327 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
328 * optional parameters have been sent with the INIT chunk and we need to parse them.
330 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
331 if (length > sizeof (sctp_init_chunk_t))
333 /* There are optional parameters in the INIT chunk */
334 u16 pointer_offset = sizeof (sctp_init_chunk_t);
335 while (pointer_offset < length)
337 sctp_opt_params_hdr_t *opt_params_hdr =
338 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
340 switch (clib_net_to_host_u16 (opt_params_hdr->type))
342 case SCTP_IPV4_ADDRESS_TYPE:
344 sctp_ipv4_addr_param_t *ipv4 =
345 (sctp_ipv4_addr_param_t *) opt_params_hdr;
346 clib_memcpy (ip4_addr, &ipv4->address,
347 sizeof (ip4_address_t));
349 sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
353 case SCTP_IPV6_ADDRESS_TYPE:
355 sctp_ipv6_addr_param_t *ipv6 =
356 (sctp_ipv6_addr_param_t *) opt_params_hdr;
357 clib_memcpy (ip6_addr, &ipv6->address,
358 sizeof (ip6_address_t));
360 sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
364 case SCTP_COOKIE_PRESERVATIVE_TYPE:
366 sctp_cookie_preservative_param_t *cookie_pres =
367 (sctp_cookie_preservative_param_t *) opt_params_hdr;
368 sctp_conn->life_span_inc = cookie_pres->life_span_inc;
371 case SCTP_HOSTNAME_ADDRESS_TYPE:
373 sctp_hostname_param_t *hostname_addr =
374 (sctp_hostname_param_t *) opt_params_hdr;
375 clib_memcpy (hostname, hostname_addr->hostname,
379 case SCTP_SUPPORTED_ADDRESS_TYPES:
385 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
389 /* Reuse buffer to make init-ack and send */
390 sctp_prepare_initack_chunk (sctp_conn, b0, ip4_addr, ip6_addr);
391 return SCTP_ERROR_NONE;
395 sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
396 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
397 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
398 u16 sctp_implied_length)
400 sctp_init_ack_chunk_t *init_ack_chunk =
401 (sctp_init_ack_chunk_t *) (sctp_hdr);
403 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
404 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
406 return SCTP_ERROR_INVALID_TAG;
410 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
412 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
413 return SCTP_ERROR_BUNDLING_VIOLATION;
415 return SCTP_ERROR_NONE;
419 sctp_handle_init_ack (sctp_header_t * sctp_hdr,
420 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
421 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
422 u16 sctp_implied_length)
424 sctp_init_ack_chunk_t *init_ack_chunk =
425 (sctp_init_ack_chunk_t *) (sctp_hdr);
426 ip4_address_t *ip4_addr = 0;
427 ip6_address_t *ip6_addr = 0;
428 sctp_state_cookie_param_t state_cookie;
430 char hostname[FQDN_MAX_LENGTH];
432 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
433 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
435 return SCTP_ERROR_INVALID_TAG;
439 * It is not possible to bundle any other CHUNK with the INIT chunk
441 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
442 return SCTP_ERROR_BUNDLING_VIOLATION;
444 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
445 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
446 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
448 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
450 if (length > sizeof (sctp_init_ack_chunk_t))
452 * There are optional parameters in the INIT ACK chunk
455 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
457 while (pointer_offset < length)
459 sctp_opt_params_hdr_t *opt_params_hdr =
460 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
463 switch (clib_net_to_host_u16 (opt_params_hdr->type))
465 case SCTP_IPV4_ADDRESS_TYPE:
467 sctp_ipv4_addr_param_t *ipv4 =
468 (sctp_ipv4_addr_param_t *) opt_params_hdr;
469 clib_memcpy (ip4_addr, &ipv4->address,
470 sizeof (ip4_address_t));
472 sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
476 case SCTP_IPV6_ADDRESS_TYPE:
478 sctp_ipv6_addr_param_t *ipv6 =
479 (sctp_ipv6_addr_param_t *) opt_params_hdr;
480 clib_memcpy (ip6_addr, &ipv6->address,
481 sizeof (ip6_address_t));
483 sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
487 case SCTP_STATE_COOKIE_TYPE:
489 sctp_state_cookie_param_t *state_cookie_param =
490 (sctp_state_cookie_param_t *) opt_params_hdr;
492 clib_memcpy (&state_cookie, state_cookie_param,
493 sizeof (sctp_state_cookie_param_t));
496 case SCTP_HOSTNAME_ADDRESS_TYPE:
498 sctp_hostname_param_t *hostname_addr =
499 (sctp_hostname_param_t *) opt_params_hdr;
500 clib_memcpy (hostname, hostname_addr->hostname,
504 case SCTP_UNRECOGNIZED_TYPE:
509 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
510 /* This indicates something really bad happened */
513 return SCTP_ERROR_INVALID_TAG;
515 pointer_offset += increment;
519 sctp_prepare_cookie_echo_chunk (sctp_conn, b0, &state_cookie);
521 /* Start the T1_COOKIE timer */
522 sctp_timer_set (sctp_conn, sctp_pick_conn_idx_on_chunk (COOKIE_ECHO),
523 SCTP_TIMER_T1_COOKIE, SCTP_RTO_INIT);
525 return SCTP_ERROR_NONE;
528 /** Enqueue data for delivery to application */
530 sctp_session_enqueue_data (sctp_connection_t * tc, vlib_buffer_t * b,
531 u16 data_len, u8 conn_idx)
533 int written, error = SCTP_ERROR_ENQUEUED;
536 session_enqueue_stream_connection (&tc->sub_conn[conn_idx].connection, b,
537 0, 1 /* queue event */ , 1);
540 if (PREDICT_TRUE (written == data_len))
542 tc->rcv_nxt += written;
544 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
545 tc->sub_conn[conn_idx].connection.c_index,
548 /* If more data written than expected, account for out-of-order bytes. */
549 else if (written > data_len)
551 tc->rcv_nxt += written;
553 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
554 tc->sub_conn[conn_idx].connection.c_index,
557 else if (written > 0)
559 /* We've written something but FIFO is probably full now */
560 tc->rcv_nxt += written;
562 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
565 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
566 tc->sub_conn[conn_idx].connection.c_index, written);
570 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
571 tc->sub_conn[conn_idx].connection.c_index);
573 return SCTP_ERROR_FIFO_FULL;
580 sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
581 sctp_connection_t * sctp_conn, vlib_buffer_t * b,
584 u32 error = 0, n_data_bytes;
585 u8 idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
587 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
588 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
590 return SCTP_ERROR_INVALID_TAG;
593 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
594 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
595 vnet_buffer (b)->sctp.tsn = sctp_data_chunk->tsn;
597 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
598 n_data_bytes = vnet_buffer (b)->sctp.data_len;
599 ASSERT (n_data_bytes);
601 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
603 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
604 * segments can be enqueued after fifo tail offset changes. */
605 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
607 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX, SCTP_RTO_INIT);
609 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
610 sctp_prepare_sack_chunk (sctp_conn, b);
616 sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
617 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
618 sctp_connection_t * sctp_conn, vlib_buffer_t * b0)
622 u8 idx = sctp_pick_conn_idx_on_chunk (COOKIE_ECHO);
624 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
625 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
627 return SCTP_ERROR_INVALID_TAG;
630 sctp_prepare_cookie_ack_chunk (sctp_conn, b0);
633 sctp_conn->state = SCTP_STATE_ESTABLISHED;
635 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
637 return SCTP_ERROR_NONE;
642 sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
643 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
644 sctp_connection_t * sctp_conn, vlib_buffer_t * b0)
647 /* Stop T1_COOKIE timer */
648 u8 idx = sctp_pick_conn_idx_on_chunk (COOKIE_ACK);
650 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
651 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
653 return SCTP_ERROR_INVALID_TAG;
656 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
658 sctp_conn->state = SCTP_STATE_ESTABLISHED;
660 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
662 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T3_RXTX, SCTP_RTO_INIT);
664 return SCTP_ERROR_NONE;
669 sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
670 vlib_frame_t * from_frame, int is_ip4)
672 sctp_main_t *tm = vnet_get_sctp_main ();
674 u32 n_left_from, next_index, *from, *to_next;
675 u32 my_thread_index = vm->thread_index;
677 from = vlib_frame_vector_args (from_frame);
678 n_left_from = from_frame->n_vectors;
680 next_index = node->cached_next_index;
682 while (n_left_from > 0)
686 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
688 while (n_left_from > 0 && n_left_to_next > 0)
692 sctp_header_t *sctp_hdr = 0;
693 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
694 ip4_header_t *ip4_hdr = 0;
695 ip6_header_t *ip6_hdr = 0;
696 sctp_connection_t *sctp_conn, *new_sctp_conn;
697 u16 sctp_implied_length = 0;
698 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
708 b0 = vlib_get_buffer (vm, bi0);
710 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
711 * will come from the half-open connections pool.
714 sctp_half_open_connection_get (vnet_buffer (b0)->
715 sctp.connection_index);
717 if (PREDICT_FALSE (sctp_conn == 0))
719 error0 = SCTP_ERROR_INVALID_CONNECTION;
723 if (PREDICT_FALSE (sctp_conn == 0))
726 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
727 error0 = SCTP_ERROR_INVALID_CONNECTION;
732 ip4_hdr = vlib_buffer_get_current (b0);
733 sctp_hdr = ip4_next_header (ip4_hdr);
737 ip6_hdr = vlib_buffer_get_current (b0);
738 sctp_hdr = ip6_next_header (ip6_hdr);
740 idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
742 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
744 transport_connection_t *t_conn =
745 &sctp_conn->sub_conn[idx].connection;
747 t_conn->lcl_port = sctp_hdr->dst_port;
748 t_conn->rmt_port = sctp_hdr->src_port;
749 t_conn->is_ip4 = is_ip4;
753 t_conn->lcl_ip.ip4.as_u32 = ip4_hdr->dst_address.as_u32;
754 t_conn->rmt_ip.ip4.as_u32 = ip4_hdr->src_address.as_u32;
758 clib_memcpy (&t_conn->lcl_ip.ip6, &ip6_hdr->dst_address,
759 sizeof (ip6_address_t));
760 clib_memcpy (&t_conn->rmt_ip.ip6, &ip6_hdr->src_address,
761 sizeof (ip6_address_t));
765 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
767 sctp_implied_length =
768 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
770 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
776 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
777 b0, sctp_implied_length);
779 if (error0 == SCTP_ERROR_NONE)
781 pool_get (tm->connections[my_thread_index], new_sctp_conn);
782 clib_memcpy (new_sctp_conn, sctp_conn,
783 sizeof (*new_sctp_conn));
784 new_sctp_conn->sub_conn[idx].c_c_index =
785 new_sctp_conn - tm->connections[my_thread_index];
786 new_sctp_conn->sub_conn[idx].c_thread_index =
788 new_sctp_conn->sub_conn[idx].parent = new_sctp_conn;
790 if (sctp_half_open_connection_cleanup (sctp_conn))
793 ("Cannot cleanup half-open connection; not the owning thread");
796 sctp_connection_timers_init (new_sctp_conn);
799 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
801 sctp_implied_length);
803 sctp_connection_init_vars (new_sctp_conn);
805 if (session_stream_connect_notify
806 (&new_sctp_conn->sub_conn[idx].connection, 0))
809 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
810 new_sctp_conn->sub_conn[idx].connection.c_index);
811 sctp_connection_cleanup (new_sctp_conn);
815 next0 = sctp_next_output (is_ip4);
818 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
819 * are handled by the input-dispatcher function using the table-lookup
820 * hence we should never get to the "default" case below.
823 error0 = SCTP_ERROR_UNKOWN_CHUNK;
824 next0 = SCTP_NEXT_DROP;
828 if (error0 != SCTP_ERROR_NONE)
830 clib_warning ("error while parsing chunk");
831 sctp_connection_cleanup (sctp_conn);
832 next0 = SCTP_NEXT_DROP;
837 b0->error = node->errors[error0];
838 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
840 sctp_rx_trace_t *t0 =
841 vlib_add_trace (vm, node, b0, sizeof (*t0));
842 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
845 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
846 n_left_to_next, bi0, next0);
849 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
851 return from_frame->n_vectors;
855 sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
856 vlib_frame_t * from_frame)
858 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
862 sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
863 vlib_frame_t * from_frame)
865 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
869 format_sctp_rx_trace_short (u8 * s, va_list * args)
871 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
872 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
873 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
875 s = format (s, "%d -> %d (%U)",
876 clib_net_to_host_u16 (t->sctp_header.src_port),
877 clib_net_to_host_u16 (t->sctp_header.dst_port),
878 format_sctp_state, t->sctp_connection.state);
884 VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
886 .function = sctp4_rcv_phase,
888 /* Takes a vector of packets. */
889 .vector_size = sizeof (u32),
890 .n_errors = SCTP_N_ERROR,
891 .error_strings = sctp_error_strings,
892 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
895 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
896 foreach_sctp_state_next
899 .format_trace = format_sctp_rx_trace_short,
903 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
906 VLIB_REGISTER_NODE (sctp6_init_phase_node) =
908 .function = sctp6_rcv_phase,
910 /* Takes a vector of packets. */
911 .vector_size = sizeof (u32),
912 .n_errors = SCTP_N_ERROR,
913 .error_strings = sctp_error_strings,
914 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
917 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
918 foreach_sctp_state_next
921 .format_trace = format_sctp_rx_trace_short,
925 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
927 vlib_node_registration_t sctp4_shutdown_phase_node;
928 vlib_node_registration_t sctp6_shutdown_phase_node;
931 sctp_handle_shutdown (sctp_header_t * sctp_hdr,
932 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
933 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
934 u16 sctp_implied_length)
936 sctp_shutdown_association_chunk_t *shutdown_chunk =
937 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
939 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
940 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
942 return SCTP_ERROR_INVALID_TAG;
946 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
948 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
949 return SCTP_ERROR_BUNDLING_VIOLATION;
951 switch (sctp_conn->state)
953 case SCTP_STATE_ESTABLISHED:
954 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
955 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
958 case SCTP_STATE_SHUTDOWN_SENT:
959 sctp_send_shutdown_ack (sctp_conn);
963 return SCTP_ERROR_NONE;
967 sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
968 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
969 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
970 u16 sctp_implied_length)
972 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
973 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
975 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
976 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
978 return SCTP_ERROR_INVALID_TAG;
982 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
984 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
985 return SCTP_ERROR_BUNDLING_VIOLATION;
987 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
988 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
989 * - STOP T2_SHUTDOWN timer
990 * - SEND SHUTDOWN_COMPLETE chunk
992 sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
993 SCTP_TIMER_T2_SHUTDOWN);
994 sctp_send_shutdown_complete (sctp_conn);
996 return SCTP_ERROR_NONE;
1000 sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1001 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1002 sctp_connection_t * sctp_conn,
1003 vlib_buffer_t * b0, u16 sctp_implied_length)
1005 sctp_shutdown_complete_chunk_t *shutdown_complete =
1006 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1008 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1009 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1011 return SCTP_ERROR_INVALID_TAG;
1015 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1017 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1018 return SCTP_ERROR_BUNDLING_VIOLATION;
1020 sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
1021 SCTP_TIMER_T2_SHUTDOWN);
1023 sctp_conn->state = SCTP_STATE_CLOSED;
1025 stream_session_disconnect_notify (&sctp_conn->sub_conn
1026 [MAIN_SCTP_SUB_CONN_IDX].connection);
1028 return SCTP_ERROR_NONE;
1032 sctp46_shutdown_phase_inline (vlib_main_t * vm,
1033 vlib_node_runtime_t * node,
1034 vlib_frame_t * from_frame, int is_ip4)
1036 u32 n_left_from, next_index, *from, *to_next;
1037 u32 my_thread_index = vm->thread_index;
1039 from = vlib_frame_vector_args (from_frame);
1040 n_left_from = from_frame->n_vectors;
1042 next_index = node->cached_next_index;
1044 while (n_left_from > 0)
1048 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1050 while (n_left_from > 0 && n_left_to_next > 0)
1054 sctp_rx_trace_t *sctp_trace;
1055 sctp_header_t *sctp_hdr = 0;
1056 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1057 ip4_header_t *ip4_hdr = 0;
1058 ip6_header_t *ip6_hdr = 0;
1059 sctp_connection_t *sctp_conn;
1060 u16 sctp_implied_length = 0;
1061 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
1068 n_left_to_next -= 1;
1070 b0 = vlib_get_buffer (vm, bi0);
1072 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1075 if (PREDICT_FALSE (sctp_conn == 0))
1078 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1079 error0 = SCTP_ERROR_INVALID_CONNECTION;
1085 ip4_hdr = vlib_buffer_get_current (b0);
1086 sctp_hdr = ip4_next_header (ip4_hdr);
1090 ip6_hdr = vlib_buffer_get_current (b0);
1091 sctp_hdr = ip6_next_header (ip6_hdr);
1094 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1095 sctp_chunk_hdr = &full_hdr->common_hdr;
1097 sctp_implied_length =
1098 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1100 switch (vnet_sctp_get_chunk_type (sctp_chunk_hdr))
1104 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn, b0,
1105 sctp_implied_length);
1106 next0 = sctp_next_output (is_ip4);
1111 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1112 b0, sctp_implied_length);
1113 next0 = sctp_next_output (is_ip4);
1116 case SHUTDOWN_COMPLETE:
1118 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
1120 sctp_implied_length);
1122 sctp_connection_cleanup (sctp_conn);
1123 next0 = sctp_next_output (is_ip4);
1127 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1128 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1132 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1133 sctp_conn, b0, &next0);
1134 next0 = sctp_next_output (is_ip4);
1137 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1138 * are handled by the input-dispatcher function using the table-lookup
1139 * hence we should never get to the "default" case below.
1142 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1143 next0 = SCTP_NEXT_DROP;
1147 if (error0 != SCTP_ERROR_NONE)
1149 clib_warning ("error while parsing chunk");
1150 sctp_connection_cleanup (sctp_conn);
1151 next0 = SCTP_NEXT_DROP;
1156 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1159 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
1160 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1161 sizeof (sctp_trace->sctp_header));
1162 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1163 sizeof (sctp_trace->sctp_connection));
1166 b0->error = node->errors[error0];
1168 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1169 n_left_to_next, bi0, next0);
1172 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1175 return from_frame->n_vectors;
1180 sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1181 vlib_frame_t * from_frame)
1183 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1187 sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1188 vlib_frame_t * from_frame)
1190 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1194 VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1196 .function = sctp4_shutdown_phase,
1197 .name = "sctp4-shutdown",
1198 /* Takes a vector of packets. */
1199 .vector_size = sizeof (u32),
1200 .n_errors = SCTP_N_ERROR,
1201 .error_strings = sctp_error_strings,
1202 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1205 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1206 foreach_sctp_state_next
1209 .format_trace = format_sctp_rx_trace_short,
1213 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1214 sctp4_shutdown_phase);
1217 VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1219 .function = sctp6_shutdown_phase,
1220 .name = "sctp6-shutdown",
1221 /* Takes a vector of packets. */
1222 .vector_size = sizeof (u32),
1223 .n_errors = SCTP_N_ERROR,
1224 .error_strings = sctp_error_strings,
1225 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1228 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1229 foreach_sctp_state_next
1232 .format_trace = format_sctp_rx_trace_short,
1236 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1237 sctp6_shutdown_phase);
1239 vlib_node_registration_t sctp4_listen_phase_node;
1240 vlib_node_registration_t sctp6_listen_phase_node;
1242 vlib_node_registration_t sctp4_established_phase_node;
1243 vlib_node_registration_t sctp6_established_phase_node;
1246 sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
1247 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
1251 sctp_next_output (sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1254 return SCTP_ERROR_NONE;
1258 sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
1259 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
1262 return SCTP_ERROR_NONE;
1266 sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
1267 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
1270 return SCTP_ERROR_NONE;
1274 sctp_node_inc_counter (vlib_main_t * vm, u32 tcp4_node, u32 tcp6_node,
1275 u8 is_ip4, u8 evt, u8 val)
1277 if (PREDICT_TRUE (!val))
1281 vlib_node_increment_counter (vm, tcp4_node, evt, val);
1283 vlib_node_increment_counter (vm, tcp6_node, evt, val);
1287 sctp46_listen_process_inline (vlib_main_t * vm,
1288 vlib_node_runtime_t * node,
1289 vlib_frame_t * from_frame, int is_ip4)
1291 u32 n_left_from, next_index, *from, *to_next;
1292 u32 my_thread_index = vm->thread_index;
1294 from = vlib_frame_vector_args (from_frame);
1295 n_left_from = from_frame->n_vectors;
1297 next_index = node->cached_next_index;
1299 while (n_left_from > 0)
1303 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1305 while (n_left_from > 0 && n_left_to_next > 0)
1309 sctp_header_t *sctp_hdr = 0;
1310 ip4_header_t *ip4_hdr;
1311 ip6_header_t *ip6_hdr;
1312 sctp_connection_t *child_conn;
1313 sctp_connection_t *sctp_listener;
1314 u16 next0 = SCTP_LISTEN_PHASE_N_NEXT, error0 = SCTP_ERROR_ENQUEUED;
1321 n_left_to_next -= 1;
1323 b0 = vlib_get_buffer (vm, bi0);
1325 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1329 ip4_hdr = vlib_buffer_get_current (b0);
1330 sctp_hdr = ip4_next_header (ip4_hdr);
1334 ip6_hdr = vlib_buffer_get_current (b0);
1335 sctp_hdr = ip6_next_header (ip6_hdr);
1339 sctp_lookup_connection (sctp_listener->sub_conn
1340 [MAIN_SCTP_SUB_CONN_IDX].c_fib_index, b0,
1341 my_thread_index, is_ip4);
1343 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1346 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1347 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1349 sctp_state_to_string (child_conn->state));
1350 error0 = SCTP_ERROR_CREATE_EXISTS;
1354 /* Create child session and send SYN-ACK */
1355 child_conn = sctp_connection_new (my_thread_index);
1356 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].parent = child_conn;
1357 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_port =
1359 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_port =
1361 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_is_ip4 = is_ip4;
1362 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto =
1363 sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto;
1364 child_conn->state = SCTP_STATE_CLOSED;
1368 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip4.as_u32 =
1369 ip4_hdr->dst_address.as_u32;
1370 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip4.as_u32 =
1371 ip4_hdr->src_address.as_u32;
1375 clib_memcpy (&child_conn->
1376 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip6,
1377 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1378 clib_memcpy (&child_conn->
1379 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip6,
1380 &ip6_hdr->src_address, sizeof (ip6_address_t));
1383 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1384 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1386 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1387 if (chunk_type != INIT)
1390 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1391 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1392 connection.c_index, sctp_chunk_to_string (chunk_type));
1394 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1395 next0 = SCTP_NEXT_DROP;
1399 u16 sctp_implied_length =
1400 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1405 sctp_connection_timers_init (child_conn);
1408 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1409 sctp_implied_length);
1411 sctp_connection_init_vars (child_conn);
1414 if (error0 == SCTP_ERROR_NONE)
1416 if (stream_session_accept
1418 sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection,
1420 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index, 0))
1422 clib_warning ("session accept fail");
1423 sctp_connection_cleanup (child_conn);
1424 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1428 next0 = sctp_next_output (is_ip4);
1431 /* Reception of a DATA chunk whilst in the CLOSED state is called
1432 * "Out of the Blue" packet and handling of the chunk needs special treatment
1433 * as per RFC4960 section 8.4
1440 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1442 sctp_rx_trace_t *t0 =
1443 vlib_add_trace (vm, node, b0, sizeof (*t0));
1444 clib_memcpy (&t0->sctp_header, sctp_hdr,
1445 sizeof (t0->sctp_header));
1446 clib_memcpy (&t0->sctp_connection, sctp_listener,
1447 sizeof (t0->sctp_connection));
1450 b0->error = node->errors[error0];
1452 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1453 n_left_to_next, bi0, next0);
1455 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1458 return from_frame->n_vectors;
1462 sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1463 vlib_frame_t * from_frame)
1465 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1469 sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1470 vlib_frame_t * from_frame)
1472 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1476 sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1477 vlib_frame_t * from_frame, int is_ip4)
1479 u32 n_left_from, next_index, *from, *to_next;
1480 u32 my_thread_index = vm->thread_index, errors = 0;
1482 from = vlib_frame_vector_args (from_frame);
1483 n_left_from = from_frame->n_vectors;
1485 next_index = node->cached_next_index;
1487 while (n_left_from > 0)
1491 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1493 while (n_left_from > 0 && n_left_to_next > 0)
1497 sctp_header_t *sctp_hdr = 0;
1498 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1499 ip4_header_t *ip4_hdr = 0;
1500 ip6_header_t *ip6_hdr = 0;
1501 sctp_connection_t *sctp_conn;
1502 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_ESTABLISHED_PHASE_N_NEXT;
1510 n_left_to_next -= 1;
1512 b0 = vlib_get_buffer (vm, bi0);
1514 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1517 if (PREDICT_FALSE (sctp_conn == 0))
1520 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1521 error0 = SCTP_ERROR_INVALID_CONNECTION;
1526 ip4_hdr = vlib_buffer_get_current (b0);
1527 sctp_hdr = ip4_next_header (ip4_hdr);
1531 ip6_hdr = vlib_buffer_get_current (b0);
1532 sctp_hdr = ip6_next_header (ip6_hdr);
1535 idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
1537 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1539 transport_connection_t *t_conn =
1540 &sctp_conn->sub_conn[idx].connection;
1542 t_conn->lcl_port = sctp_hdr->dst_port;
1543 t_conn->rmt_port = sctp_hdr->src_port;
1544 t_conn->is_ip4 = is_ip4;
1546 sctp_conn->sub_conn[idx].parent = sctp_conn;
1550 t_conn->lcl_ip.ip4.as_u32 = ip4_hdr->dst_address.as_u32;
1551 t_conn->rmt_ip.ip4.as_u32 = ip4_hdr->src_address.as_u32;
1555 clib_memcpy (&t_conn->lcl_ip.ip6, &ip6_hdr->dst_address,
1556 sizeof (ip6_address_t));
1557 clib_memcpy (&t_conn->rmt_ip.ip6, &ip6_hdr->src_address,
1558 sizeof (ip6_address_t));
1562 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1564 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1570 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1572 next0 = sctp_next_output (is_ip4);
1577 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1579 next0 = sctp_next_output (is_ip4);
1584 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
1585 sctp_conn, b0, &next0);
1590 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
1591 sctp_conn, b0, &next0);
1596 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
1597 sctp_conn, b0, &next0);
1602 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
1603 sctp_conn, b0, &next0);
1606 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1607 * are handled by the input-dispatcher function using the table-lookup
1608 * hence we should never get to the "default" case below.
1611 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1612 next0 = SCTP_NEXT_DROP;
1617 b0->error = node->errors[error0];
1618 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1620 sctp_rx_trace_t *t0 =
1621 vlib_add_trace (vm, node, b0, sizeof (*t0));
1622 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1625 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1626 n_left_to_next, bi0, next0);
1629 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1632 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1635 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1636 sctp6_established_phase_node.index,
1637 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1638 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1640 return from_frame->n_vectors;
1644 sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1645 vlib_frame_t * from_frame)
1647 return sctp46_established_phase_inline (vm, node, from_frame,
1652 sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1653 vlib_frame_t * from_frame)
1655 return sctp46_established_phase_inline (vm, node, from_frame,
1660 format_sctp_rx_trace (u8 * s, va_list * args)
1662 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1663 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1664 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1665 u32 indent = format_get_indent (s);
1667 s = format (s, "%U\n%U%U",
1668 format_sctp_header, &t->sctp_header, 128,
1669 format_white_space, indent,
1670 format_sctp_connection, &t->sctp_connection, 1);
1676 VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1678 .function = sctp4_listen_phase,
1679 .name = "sctp4-listen",
1680 /* Takes a vector of packets. */
1681 .vector_size = sizeof (u32),
1682 .n_errors = SCTP_N_ERROR,
1683 .error_strings = sctp_error_strings,
1684 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1687 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1688 foreach_sctp_state_next
1691 .format_trace = format_sctp_rx_trace_short,
1695 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
1698 VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
1700 .function = sctp6_listen_phase,
1701 .name = "sctp6-listen",
1702 /* Takes a vector of packets. */
1703 .vector_size = sizeof (u32),
1704 .n_errors = SCTP_N_ERROR,
1705 .error_strings = sctp_error_strings,
1706 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1709 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1710 foreach_sctp_state_next
1713 .format_trace = format_sctp_rx_trace_short,
1717 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
1720 VLIB_REGISTER_NODE (sctp4_established_phase_node) =
1722 .function = sctp4_established_phase,
1723 .name = "sctp4-established",
1724 /* Takes a vector of packets. */
1725 .vector_size = sizeof (u32),
1726 .n_errors = SCTP_N_ERROR,
1727 .error_strings = sctp_error_strings,
1728 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
1731 #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
1732 foreach_sctp_state_next
1735 .format_trace = format_sctp_rx_trace_short,
1739 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
1740 sctp4_established_phase);
1743 VLIB_REGISTER_NODE (sctp6_established_phase_node) =
1745 .function = sctp6_established_phase,
1746 .name = "sctp6-established",
1747 /* Takes a vector of packets. */
1748 .vector_size = sizeof (u32),
1749 .n_errors = SCTP_N_ERROR,
1750 .error_strings = sctp_error_strings,
1751 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1754 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1755 foreach_sctp_state_next
1758 .format_trace = format_sctp_rx_trace_short,
1762 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
1763 sctp6_established_phase);
1766 * This is the function executed first for the SCTP graph.
1767 * It takes care of doing the initial message parsing and
1768 * dispatch to the specialized function.
1771 sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
1772 vlib_frame_t * from_frame, int is_ip4)
1774 u32 n_left_from, next_index, *from, *to_next;
1775 u32 my_thread_index = vm->thread_index;
1777 sctp_main_t *tm = vnet_get_sctp_main ();
1779 from = vlib_frame_vector_args (from_frame);
1780 n_left_from = from_frame->n_vectors;
1781 next_index = node->cached_next_index;
1782 sctp_set_time_now (my_thread_index);
1784 while (n_left_from > 0)
1788 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1790 while (n_left_from > 0 && n_left_to_next > 0)
1792 int n_advance_bytes0, n_data_bytes0;
1793 u32 bi0, fib_index0;
1795 sctp_header_t *sctp_hdr = 0;
1796 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1797 sctp_connection_t *sctp_conn;
1798 transport_connection_t *tconn;
1799 ip4_header_t *ip4_hdr;
1800 ip6_header_t *ip6_hdr;
1801 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
1808 n_left_to_next -= 1;
1810 b0 = vlib_get_buffer (vm, bi0);
1811 vnet_buffer (b0)->tcp.flags = 0;
1812 fib_index0 = vnet_buffer (b0)->ip.fib_index;
1814 /* Checksum computed by ipx_local no need to compute again */
1818 ip4_hdr = vlib_buffer_get_current (b0);
1819 sctp_hdr = ip4_next_header (ip4_hdr);
1821 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1822 sctp_chunk_hdr = &full_hdr->common_hdr;
1825 (ip4_header_bytes (ip4_hdr) +
1826 sizeof (sctp_payload_data_chunk_t));
1828 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
1830 tconn = session_lookup_connection_wt4 (fib_index0,
1831 &ip4_hdr->dst_address,
1832 &ip4_hdr->src_address,
1835 TRANSPORT_PROTO_SCTP,
1841 ip6_hdr = vlib_buffer_get_current (b0);
1842 sctp_hdr = ip6_next_header (ip6_hdr);
1844 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1845 sctp_chunk_hdr = &full_hdr->common_hdr;
1847 n_advance_bytes0 = sctp_header_bytes ();
1849 clib_net_to_host_u16 (ip6_hdr->payload_length) -
1851 n_advance_bytes0 += sizeof (ip6_hdr[0]);
1853 tconn = session_lookup_connection_wt6 (fib_index0,
1854 &ip6_hdr->dst_address,
1855 &ip6_hdr->src_address,
1858 TRANSPORT_PROTO_SCTP,
1864 if (PREDICT_FALSE (n_advance_bytes0 < 0))
1866 error0 = SCTP_ERROR_LENGTH;
1870 sctp_conn = sctp_get_connection_from_transport (tconn);
1871 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
1873 u8 type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1875 #if SCTP_DEBUG_STATE_MACHINE
1876 u8 idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
1878 vnet_buffer (b0)->sctp.hdr_offset =
1879 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
1881 /* Session exists */
1882 if (PREDICT_TRUE (0 != sctp_conn))
1884 /* Save connection index */
1885 vnet_buffer (b0)->sctp.connection_index = tconn->c_index;
1886 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
1887 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
1889 next0 = tm->dispatch_table[sctp_conn->state][type].next;
1890 error0 = tm->dispatch_table[sctp_conn->state][type].error;
1892 SCTP_DBG_STATE_MACHINE ("CONNECTION_INDEX = %u: "
1893 "CURRENT_CONNECTION_STATE = %s,"
1894 "CHUNK_TYPE_RECEIVED = %s "
1897 [idx].connection.c_index,
1898 sctp_state_to_string (sctp_conn->state),
1899 sctp_chunk_to_string (type),
1900 phase_to_string (next0));
1903 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
1904 n_advance_bytes0, n_data_bytes0);
1911 next0 = SCTP_INPUT_NEXT_DROP;
1912 error0 = SCTP_ERROR_FILTERED;
1914 else if ((is_ip4 && tm->punt_unknown4) ||
1915 (!is_ip4 && tm->punt_unknown6))
1917 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
1918 error0 = SCTP_ERROR_PUNT;
1922 next0 = SCTP_INPUT_NEXT_DROP;
1923 error0 = SCTP_ERROR_NO_LISTENER;
1925 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
1926 phase_to_string (next0));
1931 b0->error = error0 ? node->errors[error0] : 0;
1933 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1935 sctp_rx_trace_t *t0 =
1936 vlib_add_trace (vm, node, b0, sizeof (*t0));
1937 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1939 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1940 n_left_to_next, bi0, next0);
1943 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1945 return from_frame->n_vectors;
1949 sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
1950 vlib_frame_t * from_frame)
1952 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
1956 sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
1957 vlib_frame_t * from_frame)
1959 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
1963 VLIB_REGISTER_NODE (sctp4_input_node) =
1965 .function = sctp4_input_dispatcher,
1966 .name = "sctp4-input",
1967 /* Takes a vector of packets. */
1968 .vector_size = sizeof (u32),
1969 .n_errors = SCTP_N_ERROR,
1970 .error_strings = sctp_error_strings,
1971 .n_next_nodes = SCTP_INPUT_N_NEXT,
1974 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
1975 foreach_sctp4_input_next
1978 .format_buffer = format_sctp_header,
1979 .format_trace = format_sctp_rx_trace,
1983 VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
1986 VLIB_REGISTER_NODE (sctp6_input_node) =
1988 .function = sctp6_input_dispatcher,
1989 .name = "sctp6-input",
1990 /* Takes a vector of packets. */
1991 .vector_size = sizeof (u32),
1992 .n_errors = SCTP_N_ERROR,
1993 .error_strings = sctp_error_strings,
1994 .n_next_nodes = SCTP_INPUT_N_NEXT,
1997 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
1998 foreach_sctp6_input_next
2001 .format_buffer = format_sctp_header,
2002 .format_trace = format_sctp_rx_trace,
2006 VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2008 vlib_node_registration_t sctp4_input_node;
2009 vlib_node_registration_t sctp6_input_node;
2012 sctp_dispatch_table_init (sctp_main_t * tm)
2015 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2016 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2018 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2019 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2022 #define _(t,f,n,e) \
2024 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2025 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2029 * SCTP STATE-MACHINE states:
2031 * _(CLOSED, "CLOSED") \
2032 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2033 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2034 * _(ESTABLISHED, "ESTABLISHED") \
2035 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2036 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2037 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2038 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2040 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2041 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2042 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2043 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2044 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2045 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2046 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2047 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2048 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2049 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2050 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2051 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2052 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2053 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2054 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2056 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2057 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2058 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2059 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2060 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2061 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2062 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2063 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2064 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2065 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2066 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2067 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2068 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2069 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2070 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2072 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2073 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2074 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2075 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2076 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2077 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2078 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2079 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2080 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2081 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2082 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2083 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2085 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2086 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2087 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2089 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2090 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2091 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2092 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2093 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2095 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2097 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2098 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2099 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2100 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2101 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2102 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2103 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2104 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2105 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2107 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2108 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2109 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2110 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2111 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2113 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2115 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2116 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2118 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2119 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2120 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2121 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2122 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2123 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2124 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2126 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2127 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2128 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2129 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2130 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2131 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2132 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2133 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2134 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2136 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2137 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2138 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2139 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2140 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2142 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2143 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2144 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2145 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2146 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2147 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2148 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2149 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2150 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2152 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2153 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2154 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2155 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2156 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2158 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2159 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2160 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2161 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2162 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2163 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2164 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2165 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2166 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2167 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2168 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2169 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2170 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2171 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2174 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2180 sctp_input_init (vlib_main_t * vm)
2182 clib_error_t *error = 0;
2183 sctp_main_t *tm = vnet_get_sctp_main ();
2185 if ((error = vlib_call_init_function (vm, sctp_init)))
2188 /* Initialize dispatch table. */
2189 sctp_dispatch_table_init (tm);
2194 VLIB_INIT_FUNCTION (sctp_input_init);
2197 * fd.io coding-style-patch-verification: ON
2200 * eval: (c-set-style "gnu")