blob: 88e4eab754d5f6ffef0a1bebf371c35f432f4598 [file] [log] [blame]
Marco Varlese191a5942017-10-30 18:17:21 +01001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
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>
20#include <math.h>
21
22static char *sctp_error_strings[] = {
23#define sctp_error(n,s) s,
24#include <vnet/sctp/sctp_error.def>
25#undef sctp_error
26};
27
28/* All SCTP nodes have the same outgoing arcs */
29#define foreach_sctp_state_next \
Marco Varlesefae40392018-02-14 15:38:35 +010030 _ (DROP4, "ip4-drop") \
31 _ (DROP6, "ip6-drop") \
Marco Varlese191a5942017-10-30 18:17:21 +010032 _ (SCTP4_OUTPUT, "sctp4-output") \
33 _ (SCTP6_OUTPUT, "sctp6-output")
34
35typedef enum _sctp_established_phase_next
36{
37#define _(s,n) SCTP_ESTABLISHED_PHASE_NEXT_##s,
38 foreach_sctp_state_next
39#undef _
40 SCTP_ESTABLISHED_PHASE_N_NEXT,
41} sctp_established_phase_next_t;
42
43typedef enum _sctp_rcv_phase_next
44{
45#define _(s,n) SCTP_RCV_PHASE_NEXT_##s,
46 foreach_sctp_state_next
47#undef _
48 SCTP_RCV_PHASE_N_NEXT,
49} sctp_rcv_phase_next_t;
50
51typedef enum _sctp_listen_phase_next
52{
53#define _(s,n) SCTP_LISTEN_PHASE_NEXT_##s,
54 foreach_sctp_state_next
55#undef _
56 SCTP_LISTEN_PHASE_N_NEXT,
57} sctp_listen_phase_next_t;
58
59typedef enum _sctp_shutdown_phase_next
60{
61#define _(s,n) SCTP_SHUTDOWN_PHASE_NEXT_##s,
62 foreach_sctp_state_next
63#undef _
64 SCTP_SHUTDOWN_PHASE_N_NEXT,
65} sctp_shutdown_phase_next_t;
66
67/* Generic, state independent indices */
68typedef enum _sctp_state_next
69{
70#define _(s,n) SCTP_NEXT_##s,
71 foreach_sctp_state_next
72#undef _
73 SCTP_STATE_N_NEXT,
74} sctp_state_next_t;
75
76typedef enum _sctp_input_next
77{
78 SCTP_INPUT_NEXT_DROP,
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,
84 SCTP_INPUT_N_NEXT
85} sctp_input_next_t;
86
87char *
88phase_to_string (u8 phase)
89{
90 switch (phase)
91 {
92 case SCTP_INPUT_NEXT_DROP:
93 return "SCTP_INPUT_NEXT_DROP";
94 case SCTP_INPUT_NEXT_LISTEN_PHASE:
95 return "SCTP_INPUT_NEXT_LISTEN_PHASE";
96 case SCTP_INPUT_NEXT_RCV_PHASE:
97 return "SCTP_INPUT_NEXT_RCV_PHASE";
98 case SCTP_INPUT_NEXT_ESTABLISHED_PHASE:
99 return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
100 case SCTP_INPUT_NEXT_SHUTDOWN_PHASE:
101 return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
102 case SCTP_INPUT_NEXT_PUNT_PHASE:
103 return "SCTP_INPUT_NEXT_PUNT_PHASE";
104 }
105 return NULL;
106}
107
108#define foreach_sctp4_input_next \
109 _ (DROP, "error-drop") \
110 _ (RCV_PHASE, "sctp4-rcv") \
111 _ (LISTEN_PHASE, "sctp4-listen") \
112 _ (ESTABLISHED_PHASE, "sctp4-established") \
113 _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
114 _ (PUNT_PHASE, "ip4-punt")
115
116
117#define foreach_sctp6_input_next \
118 _ (DROP, "error-drop") \
119 _ (RCV_PHASE, "sctp6-rcv") \
120 _ (LISTEN_PHASE, "sctp6-listen") \
121 _ (ESTABLISHED_PHASE, "sctp6-established") \
122 _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
123 _ (PUNT_PHASE, "ip6-punt")
124
125static u8
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100126sctp_lookup_is_valid (transport_connection_t * trans_conn,
Marco Varlese191a5942017-10-30 18:17:21 +0100127 sctp_header_t * sctp_hdr)
128{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100129 sctp_connection_t *sctp_conn =
130 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100131
132 if (!sctp_conn)
133 return 1;
134
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100135 u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
Marco Varlese191a5942017-10-30 18:17:21 +0100136 && (sctp_conn->state == SCTP_STATE_CLOSED
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100137 || trans_conn->rmt_port == sctp_hdr->src_port));
Marco Varlese191a5942017-10-30 18:17:21 +0100138
139 return is_valid;
140}
141
142/**
143 * Lookup transport connection
144 */
145static sctp_connection_t *
146sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
147 u8 is_ip4)
148{
149 sctp_main_t *tm = vnet_get_sctp_main ();
150 sctp_header_t *sctp_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100151 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100152 sctp_connection_t *sctp_conn;
153 u8 is_filtered, i;
154 if (is_ip4)
155 {
156 ip4_header_t *ip4_hdr;
157 ip4_hdr = vlib_buffer_get_current (b);
158 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100159 trans_conn = session_lookup_connection_wt4 (fib_index,
160 &ip4_hdr->dst_address,
161 &ip4_hdr->src_address,
162 sctp_hdr->dst_port,
163 sctp_hdr->src_port,
164 TRANSPORT_PROTO_SCTP,
165 thread_index, &is_filtered);
166 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100167 {
168 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
169 {
170 if ((tm->connections[thread_index]->sub_conn[i].
171 connection.lcl_ip.ip4.as_u32 ==
172 ip4_hdr->dst_address.as_u32)
173 && (tm->connections[thread_index]->sub_conn[i].
174 connection.rmt_ip.ip4.as_u32 ==
175 ip4_hdr->src_address.as_u32))
176 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100177 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100178 &tm->connections[thread_index]->sub_conn[i].connection;
179 break;
180 }
181 }
182 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100183 ASSERT (trans_conn != 0);
184 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100185 }
186 else
187 {
188 ip6_header_t *ip6_hdr;
189 ip6_hdr = vlib_buffer_get_current (b);
190 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100191 trans_conn = session_lookup_connection_wt6 (fib_index,
192 &ip6_hdr->dst_address,
193 &ip6_hdr->src_address,
194 sctp_hdr->dst_port,
195 sctp_hdr->src_port,
196 TRANSPORT_PROTO_SCTP,
197 thread_index, &is_filtered);
198 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100199 {
200 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
201 {
202 if ((tm->connections[thread_index]->sub_conn[i].
203 connection.lcl_ip.ip6.as_u64[0] ==
204 ip6_hdr->dst_address.as_u64[0]
205 && tm->connections[thread_index]->sub_conn[i].
206 connection.lcl_ip.ip6.as_u64[1] ==
207 ip6_hdr->dst_address.as_u64[1])
208 && (tm->connections[thread_index]->sub_conn[i].
209 connection.rmt_ip.ip6.as_u64[0] ==
210 ip6_hdr->src_address.as_u64[0]
211 && tm->connections[thread_index]->
212 sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
213 ip6_hdr->src_address.as_u64[1]))
214 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100215 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100216 &tm->connections[thread_index]->sub_conn[i].connection;
217 break;
218 }
219 }
220 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100221 ASSERT (trans_conn != 0);
222 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100223 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100224 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100225 return sctp_conn;
226}
227
228typedef struct
229{
230 sctp_header_t sctp_header;
231 sctp_connection_t sctp_connection;
232} sctp_rx_trace_t;
233
234#define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
235 : SCTP_NEXT_SCTP6_OUTPUT)
236
Marco Varlesefae40392018-02-14 15:38:35 +0100237#define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
238 : SCTP_NEXT_DROP6)
Marco Varlese191a5942017-10-30 18:17:21 +0100239
240void
241sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
242 sctp_connection_t * sctp_conn,
243 sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
244 u8 is_ip4)
245{
246 if (sctp_conn)
247 {
Dave Barach178cf492018-11-13 16:34:13 -0500248 clib_memcpy_fast (&rx_trace->sctp_connection, sctp_conn,
249 sizeof (rx_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +0100250 }
251 else
252 {
253 sctp_hdr = sctp_buffer_hdr (b0);
254 }
Dave Barach178cf492018-11-13 16:34:13 -0500255 clib_memcpy_fast (&rx_trace->sctp_header, sctp_hdr,
256 sizeof (rx_trace->sctp_header));
Marco Varlese191a5942017-10-30 18:17:21 +0100257}
258
259always_inline u16
260sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
261 int is_ip4)
262{
263 u16 sctp_implied_packet_length = 0;
264
265 if (is_ip4)
266 sctp_implied_packet_length =
267 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
268 else
269 sctp_implied_packet_length =
270 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
271
272 return sctp_implied_packet_length;
273}
274
275always_inline u8
276sctp_is_bundling (u16 sctp_implied_length,
277 sctp_chunks_common_hdr_t * sctp_common_hdr)
278{
279 if (sctp_implied_length !=
280 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
281 return 1;
282 return 0;
283}
284
285always_inline u16
Marco Varlese200fa322018-02-26 16:33:54 +0100286sctp_handle_operation_err (sctp_header_t * sctp_hdr,
287 sctp_connection_t * sctp_conn, u8 idx,
288 vlib_buffer_t * b, u16 * next0)
289{
290 sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
291
292 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
293 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
294 {
295 return SCTP_ERROR_INVALID_TAG;
296 }
297
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100298 if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
299 STALE_COOKIE_ERROR)
Marco Varlese200fa322018-02-26 16:33:54 +0100300 {
301 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
302 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
303 else
304 {
305 sctp_connection_cleanup (sctp_conn);
306
Florin Coras5a2ec8f2018-12-27 11:53:11 -0800307 session_transport_closing_notify (&sctp_conn->
Marco Varlese200fa322018-02-26 16:33:54 +0100308 sub_conn[idx].connection);
309 }
310 }
311
312 return SCTP_ERROR_NONE;
313}
314
315always_inline u16
Marco Varlese191a5942017-10-30 18:17:21 +0100316sctp_handle_init (sctp_header_t * sctp_hdr,
317 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
318 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
319 u16 sctp_implied_length)
320{
321 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +0200322 ip4_address_t ip4_addr;
323 ip6_address_t ip6_addr;
324 u8 add_ip4 = 0;
325 u8 add_ip6 = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100326 char hostname[FQDN_MAX_LENGTH];
327
328 /* Check the current state of the connection
329 *
330 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
331 * in the code below and by the "sctp_prepare_initack_chunk" function.
332 * However, for debugging purposes it is nice to have a message printed out
333 * for these corner-case scenarios.
334 */
335 if (sctp_conn->state != SCTP_STATE_CLOSED)
336 { /* UNEXPECTED scenario */
337 switch (sctp_conn->state)
338 {
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100339 case SCTP_STATE_COOKIE_WAIT:
Marco Varlese191a5942017-10-30 18:17:21 +0100340 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100341 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100342 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200343 b0, &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100344 return SCTP_ERROR_NONE;
345 case SCTP_STATE_COOKIE_ECHOED:
346 case SCTP_STATE_SHUTDOWN_ACK_SENT:
Marco Varlese191a5942017-10-30 18:17:21 +0100347 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100348 if (sctp_conn->forming_association_changed == 0)
349 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100350 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200351 b0, &ip4_addr,
352 &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100353 else
354 sctp_prepare_abort_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100355 SCTP_PRIMARY_PATH_IDX, b0,
Marco Varlese216c35b2018-04-17 16:41:51 +0200356 &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100357 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100358 }
359 }
360
361 if (sctp_hdr->verification_tag != 0x0)
362 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
363
364 /*
365 * It is not possible to bundle any other CHUNK with the INIT chunk
366 */
367 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
368 return SCTP_ERROR_BUNDLING_VIOLATION;
369
370 /* Save the INITIATE_TAG of the remote peer for this connection:
371 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
372 sctp_conn->remote_tag = init_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100373 sctp_conn->remote_initial_tsn =
374 clib_net_to_host_u32 (init_chunk->initial_tsn);
375 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
376 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
377 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
378 sctp_conn->remote_initial_tsn);
379
Marco Varlese9e09ff32018-03-05 12:31:45 +0100380 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100381 /*
382 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
383 * optional parameters have been sent with the INIT chunk and we need to parse them.
384 */
385 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
386 if (length > sizeof (sctp_init_chunk_t))
387 {
388 /* There are optional parameters in the INIT chunk */
389 u16 pointer_offset = sizeof (sctp_init_chunk_t);
390 while (pointer_offset < length)
391 {
392 sctp_opt_params_hdr_t *opt_params_hdr =
393 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
394
395 switch (clib_net_to_host_u16 (opt_params_hdr->type))
396 {
397 case SCTP_IPV4_ADDRESS_TYPE:
398 {
399 sctp_ipv4_addr_param_t *ipv4 =
400 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500401 clib_memcpy_fast (&ip4_addr, &ipv4->address,
402 sizeof (ip4_address_t));
Marco Varlese191a5942017-10-30 18:17:21 +0100403
Marco Varlese216c35b2018-04-17 16:41:51 +0200404 if (sctp_sub_connection_add_ip4 (vlib_get_main (),
405 &sctp_conn->sub_conn
406 [SCTP_PRIMARY_PATH_IDX].connection.
407 lcl_ip.ip4,
408 &ipv4->address) ==
409 SCTP_ERROR_NONE)
410 add_ip4 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100411
412 break;
413 }
414 case SCTP_IPV6_ADDRESS_TYPE:
415 {
416 sctp_ipv6_addr_param_t *ipv6 =
417 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500418 clib_memcpy_fast (&ip6_addr, &ipv6->address,
419 sizeof (ip6_address_t));
Marco Varlese191a5942017-10-30 18:17:21 +0100420
Marco Varlese216c35b2018-04-17 16:41:51 +0200421 if (sctp_sub_connection_add_ip6 (vlib_get_main (),
422 &sctp_conn->sub_conn
423 [SCTP_PRIMARY_PATH_IDX].connection.
424 lcl_ip.ip6,
425 &ipv6->address) ==
426 SCTP_ERROR_NONE)
427 add_ip6 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100428
429 break;
430 }
431 case SCTP_COOKIE_PRESERVATIVE_TYPE:
432 {
433 sctp_cookie_preservative_param_t *cookie_pres =
434 (sctp_cookie_preservative_param_t *) opt_params_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100435 sctp_conn->peer_cookie_life_span_increment =
436 cookie_pres->life_span_inc;
Marco Varlese191a5942017-10-30 18:17:21 +0100437 break;
438 }
439 case SCTP_HOSTNAME_ADDRESS_TYPE:
440 {
441 sctp_hostname_param_t *hostname_addr =
442 (sctp_hostname_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500443 clib_memcpy_fast (hostname, hostname_addr->hostname,
444 FQDN_MAX_LENGTH);
Marco Varlese191a5942017-10-30 18:17:21 +0100445 break;
446 }
447 case SCTP_SUPPORTED_ADDRESS_TYPES:
448 {
449 /* TODO */
450 break;
451 }
452 }
453 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
454 }
455 }
456
457 /* Reuse buffer to make init-ack and send */
Marco Varlese216c35b2018-04-17 16:41:51 +0200458 sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
459 add_ip4, &ip6_addr, add_ip6);
Marco Varlese191a5942017-10-30 18:17:21 +0100460 return SCTP_ERROR_NONE;
461}
462
463always_inline u16
464sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
465 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
466 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
467 u16 sctp_implied_length)
468{
469 sctp_init_ack_chunk_t *init_ack_chunk =
470 (sctp_init_ack_chunk_t *) (sctp_hdr);
471
472 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
473 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
474 {
475 return SCTP_ERROR_INVALID_TAG;
476 }
477
478 /*
479 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
480 */
481 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
482 return SCTP_ERROR_BUNDLING_VIOLATION;
483
484 return SCTP_ERROR_NONE;
485}
486
487always_inline u16
488sctp_handle_init_ack (sctp_header_t * sctp_hdr,
489 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100490 sctp_connection_t * sctp_conn, u8 idx,
491 vlib_buffer_t * b0, u16 sctp_implied_length)
Marco Varlese191a5942017-10-30 18:17:21 +0100492{
493 sctp_init_ack_chunk_t *init_ack_chunk =
494 (sctp_init_ack_chunk_t *) (sctp_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100495
496 char hostname[FQDN_MAX_LENGTH];
497
498 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
499 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
500 {
501 return SCTP_ERROR_INVALID_TAG;
502 }
503
504 /*
505 * It is not possible to bundle any other CHUNK with the INIT chunk
506 */
507 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
508 return SCTP_ERROR_BUNDLING_VIOLATION;
509
Marco Varlese9e09ff32018-03-05 12:31:45 +0100510 /* Stop the T1_INIT timer */
511 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
512
Marco Varlese21c8baf2018-02-02 17:17:51 +0100513 sctp_calculate_rto (sctp_conn, idx);
514
Marco Varlese191a5942017-10-30 18:17:21 +0100515 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
516 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100517 sctp_conn->remote_initial_tsn =
518 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
519 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
520 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
521 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
522 sctp_conn->remote_initial_tsn);
Marco Varlese9e09ff32018-03-05 12:31:45 +0100523 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100524
525 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
526
527 if (length > sizeof (sctp_init_ack_chunk_t))
528 /*
529 * There are optional parameters in the INIT ACK chunk
530 */
531 {
532 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
533
534 while (pointer_offset < length)
535 {
536 sctp_opt_params_hdr_t *opt_params_hdr =
537 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
538 pointer_offset);
539
540 switch (clib_net_to_host_u16 (opt_params_hdr->type))
541 {
542 case SCTP_IPV4_ADDRESS_TYPE:
543 {
544 sctp_ipv4_addr_param_t *ipv4 =
545 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100546
Marco Varlese3c6a9762018-03-01 11:19:59 +0100547 sctp_sub_connection_add_ip4 (vlib_get_main (),
548 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100549 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100550 lcl_ip.ip4, &ipv4->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100551
552 break;
553 }
554 case SCTP_IPV6_ADDRESS_TYPE:
555 {
556 sctp_ipv6_addr_param_t *ipv6 =
557 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100558
Marco Varlese3c6a9762018-03-01 11:19:59 +0100559 sctp_sub_connection_add_ip6 (vlib_get_main (),
560 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100561 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100562 lcl_ip.ip6, &ipv6->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100563
564 break;
565 }
566 case SCTP_STATE_COOKIE_TYPE:
567 {
568 sctp_state_cookie_param_t *state_cookie_param =
569 (sctp_state_cookie_param_t *) opt_params_hdr;
570
Dave Barach178cf492018-11-13 16:34:13 -0500571 clib_memcpy_fast (&(sctp_conn->cookie_param),
572 state_cookie_param,
573 sizeof (sctp_state_cookie_param_t));
Marco Varlese63777e52018-04-18 08:50:57 +0200574
Marco Varlese191a5942017-10-30 18:17:21 +0100575 break;
576 }
577 case SCTP_HOSTNAME_ADDRESS_TYPE:
578 {
579 sctp_hostname_param_t *hostname_addr =
580 (sctp_hostname_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500581 clib_memcpy_fast (hostname, hostname_addr->hostname,
582 FQDN_MAX_LENGTH);
Marco Varlese191a5942017-10-30 18:17:21 +0100583 break;
584 }
585 case SCTP_UNRECOGNIZED_TYPE:
586 {
587 break;
588 }
589 }
590 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
591 /* This indicates something really bad happened */
592 if (increment == 0)
593 {
594 return SCTP_ERROR_INVALID_TAG;
595 }
596 pointer_offset += increment;
597 }
598 }
599
Marco Varlese9e09ff32018-03-05 12:31:45 +0100600 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100601
602 /* Start the T1_COOKIE timer */
Marco Varlese54432f82018-02-15 17:01:56 +0100603 sctp_timer_set (sctp_conn, idx,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100604 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
Marco Varlese191a5942017-10-30 18:17:21 +0100605
606 return SCTP_ERROR_NONE;
607}
608
Marco Varlese91389ac2018-01-31 11:00:01 +0100609/** Enqueue data out-of-order for delivery to application */
610always_inline int
611sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
612 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
613{
614 int written, error = SCTP_ERROR_ENQUEUED;
615
616 written =
617 session_enqueue_stream_connection (&sctp_conn->
618 sub_conn[conn_idx].connection, b, 0,
619 1 /* queue event */ ,
620 0);
621
622 /* Update next_tsn_expected */
623 if (PREDICT_TRUE (written == data_len))
624 {
625 sctp_conn->next_tsn_expected += written;
626
627 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
628 sctp_conn->sub_conn[conn_idx].connection.c_index,
629 written, data_len);
630 }
631 /* If more data written than expected, account for out-of-order bytes. */
632 else if (written > data_len)
633 {
634 sctp_conn->next_tsn_expected += written;
635
636 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
637 sctp_conn->sub_conn[conn_idx].connection.c_index,
638 written, data_len);
639 }
640 else if (written > 0)
641 {
642 /* We've written something but FIFO is probably full now */
643 sctp_conn->next_tsn_expected += written;
644
645 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
646
647 SCTP_ADV_DBG
648 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
649 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
650 }
651 else
652 {
653 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
654 sctp_conn->sub_conn[conn_idx].connection.c_index);
655
656 return SCTP_ERROR_FIFO_FULL;
657 }
658
659 /* TODO: Update out_of_order_map & SACK list */
660
661 return error;
662}
663
Marco Varlese191a5942017-10-30 18:17:21 +0100664/** Enqueue data for delivery to application */
665always_inline int
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100666sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100667 u16 data_len, u8 conn_idx)
668{
669 int written, error = SCTP_ERROR_ENQUEUED;
670
671 written =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100672 session_enqueue_stream_connection (&sctp_conn->
673 sub_conn[conn_idx].connection, b, 0,
674 1 /* queue event */ ,
675 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100676
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100677 /* Update next_tsn_expected */
Marco Varlese191a5942017-10-30 18:17:21 +0100678 if (PREDICT_TRUE (written == data_len))
679 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100680 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100681
682 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100683 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100684 written, data_len);
685 }
686 /* If more data written than expected, account for out-of-order bytes. */
687 else if (written > data_len)
688 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100689 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100690
691 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100692 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100693 written, data_len);
694 }
695 else if (written > 0)
696 {
697 /* We've written something but FIFO is probably full now */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100698 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100699
700 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
701
702 SCTP_ADV_DBG
703 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100704 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
Marco Varlese191a5942017-10-30 18:17:21 +0100705 }
706 else
707 {
708 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100709 sctp_conn->sub_conn[conn_idx].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100710
711 return SCTP_ERROR_FIFO_FULL;
712 }
713
714 return error;
715}
716
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100717always_inline u8
Marco Varlese54432f82018-02-15 17:01:56 +0100718sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100719{
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100720 if (sctp_conn->conn_config.never_delay_sack)
721 {
722 SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
723 return 0;
724 }
725
Marco Varlese9e09ff32018-03-05 12:31:45 +0100726 /* Section 4.4 of the RFC4960 */
727 if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
728 {
729 SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
730 sctp_state_to_string (sctp_conn->state));
731 return 0;
732 }
733
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100734 if (is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100735 {
736 SCTP_CONN_TRACKING_DBG
737 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
738 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100739 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100740 }
741
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100742 sctp_conn->ack_state += 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100743 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
744 {
745 SCTP_CONN_TRACKING_DBG
746 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
747 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100748 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100749 }
750
Marco Varlesea38783e2018-02-13 12:38:52 +0100751 return 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100752}
753
Marco Varlese91389ac2018-01-31 11:00:01 +0100754always_inline void
755sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
756 u8 * gapping)
757{
758 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
759 {
760 SCTP_CONN_TRACKING_DBG
761 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100762 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
Marco Varlese91389ac2018-01-31 11:00:01 +0100763 sctp_conn->next_tsn_expected, tsn,
764 sctp_conn->next_tsn_expected - tsn);
765
766 *gapping = 1;
767 }
768}
769
Marco Varlese191a5942017-10-30 18:17:21 +0100770always_inline u16
771sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100772 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100773 u16 * next0)
774{
775 u32 error = 0, n_data_bytes;
Marco Varlese91389ac2018-01-31 11:00:01 +0100776 u8 is_gapping = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100777
778 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
779 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
780 {
Marco Varlese87971682018-10-04 15:46:05 +0200781 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
782 sctp_conn->sub_conn[idx].enqueue_state = SCTP_ERROR_INVALID_TAG;
783 return sctp_conn->sub_conn[idx].enqueue_state;
Marco Varlese191a5942017-10-30 18:17:21 +0100784 }
785
786 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
787 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100788
789 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100790
791 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
Marco Varlese87971682018-10-04 15:46:05 +0200792 u32 chunk_len = vnet_sctp_get_chunk_length (&sctp_data_chunk->chunk_hdr) -
793 (sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_header_t));
794
795 ASSERT (vnet_buffer (b)->sctp.data_len);
796 ASSERT (chunk_len);
797
798 /* Padding was added: see RFC 4096 section 3.3.1 */
799 if (vnet_buffer (b)->sctp.data_len > chunk_len)
800 {
801 /* Let's change the data_len to the right amount calculated here now.
802 * We cannot do that in the generic sctp46_input_dispatcher node since
803 * that is common to all CHUNKS handling.
804 */
805 vnet_buffer (b)->sctp.data_len = chunk_len;
806 /* We need to change b->current_length so that downstream calls to
807 * session_enqueue_stream_connection (called by sctp_session_enqueue_data)
808 * push the correct amount of data to be enqueued.
809 */
810 b->current_length = chunk_len;
811 }
Marco Varlese191a5942017-10-30 18:17:21 +0100812 n_data_bytes = vnet_buffer (b)->sctp.data_len;
Marco Varlese191a5942017-10-30 18:17:21 +0100813
Marco Varlese91389ac2018-01-31 11:00:01 +0100814 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100815
816 sctp_conn->last_rcvd_tsn = tsn;
817
Marco Varlese191a5942017-10-30 18:17:21 +0100818 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
819
Marco Varlese91389ac2018-01-31 11:00:01 +0100820 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
821 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
822
823 if (bbit == 1 && ebit == 1) /* Unfragmented message */
824 {
825 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
826 * segments can be enqueued after fifo tail offset changes. */
Marco Varlese54432f82018-02-15 17:01:56 +0100827 if (PREDICT_FALSE (is_gapping == 1))
828 error =
829 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
830 else
831 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
Marco Varlese91389ac2018-01-31 11:00:01 +0100832 }
833 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
834 {
835 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
836 }
837 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
838 {
839 if (PREDICT_FALSE (is_gapping == 1))
840 error =
841 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
842 else
843 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
844 }
845 else /* Middle piece of a fragmented user message */
846 {
847 if (PREDICT_FALSE (is_gapping == 1))
848 error =
849 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
850 else
851 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
852 }
853 sctp_conn->last_rcvd_tsn = tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100854
Marco Varlese91389ac2018-01-31 11:00:01 +0100855 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
856
Marco Varlese54432f82018-02-15 17:01:56 +0100857 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100858 {
859 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
860 sctp_prepare_sack_chunk (sctp_conn, idx, b);
861 }
862 else
863 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese54432f82018-02-15 17:01:56 +0100864
865 sctp_conn->sub_conn[idx].enqueue_state = error;
Marco Varlese191a5942017-10-30 18:17:21 +0100866
867 return error;
868}
869
870always_inline u16
871sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
872 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100873 sctp_connection_t * sctp_conn, u8 idx,
874 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100875{
Marco Varlese93826732018-09-27 16:43:57 +0200876 u64 now = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +0100877
Marco Varlese91389ac2018-01-31 11:00:01 +0100878 sctp_cookie_echo_chunk_t *cookie_echo =
879 (sctp_cookie_echo_chunk_t *) sctp_hdr;
880
Marco Varlese191a5942017-10-30 18:17:21 +0100881 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
882 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
883 {
Marco Varlese87971682018-10-04 15:46:05 +0200884 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100885 return SCTP_ERROR_INVALID_TAG;
886 }
887
Marco Varlese21c8baf2018-02-02 17:17:51 +0100888 sctp_calculate_rto (sctp_conn, idx);
889
Marco Varlese93826732018-09-27 16:43:57 +0200890 u64 creation_time =
891 clib_net_to_host_u64 (cookie_echo->cookie.creation_time);
892 u64 cookie_lifespan =
Marco Varlese91389ac2018-01-31 11:00:01 +0100893 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
Marco Varlese93826732018-09-27 16:43:57 +0200894
Marco Varlese91389ac2018-01-31 11:00:01 +0100895 if (now > creation_time + cookie_lifespan)
896 {
897 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
898 now, creation_time, cookie_lifespan);
899 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
900 }
901
Marco Varlese54432f82018-02-15 17:01:56 +0100902 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +0100903
904 /* Change state */
905 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100906 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
Marco Varlesebe2251b2018-02-07 12:22:41 +0100907 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100908
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100909 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
910 sctp_conn->sub_conn[idx].RTO);
911
Marco Varlese15cc6a82018-02-21 12:39:52 +0100912 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
913
Marco Varlese191a5942017-10-30 18:17:21 +0100914 return SCTP_ERROR_NONE;
915
916}
917
918always_inline u16
919sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
920 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100921 sctp_connection_t * sctp_conn, u8 idx,
922 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100923{
Marco Varlese191a5942017-10-30 18:17:21 +0100924 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
925 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
926 {
Marco Varlese87971682018-10-04 15:46:05 +0200927 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100928 return SCTP_ERROR_INVALID_TAG;
929 }
930
Marco Varlese21c8baf2018-02-02 17:17:51 +0100931 sctp_calculate_rto (sctp_conn, idx);
932
Marco Varlese191a5942017-10-30 18:17:21 +0100933 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
934 /* Change state */
935 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100936 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
937
Marco Varlesefae40392018-02-14 15:38:35 +0100938 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100939
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100940 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
941 sctp_conn->sub_conn[idx].RTO);
942
Marco Varlese15cc6a82018-02-21 12:39:52 +0100943 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
944
Marco Varlese191a5942017-10-30 18:17:21 +0100945 return SCTP_ERROR_NONE;
946
947}
948
949always_inline uword
950sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
951 vlib_frame_t * from_frame, int is_ip4)
952{
953 sctp_main_t *tm = vnet_get_sctp_main ();
954
955 u32 n_left_from, next_index, *from, *to_next;
956 u32 my_thread_index = vm->thread_index;
957
958 from = vlib_frame_vector_args (from_frame);
959 n_left_from = from_frame->n_vectors;
960
961 next_index = node->cached_next_index;
962
963 while (n_left_from > 0)
964 {
965 u32 n_left_to_next;
966
967 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
968
969 while (n_left_from > 0 && n_left_to_next > 0)
970 {
971 u32 bi0;
972 vlib_buffer_t *b0;
973 sctp_header_t *sctp_hdr = 0;
974 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
975 ip4_header_t *ip4_hdr = 0;
976 ip6_header_t *ip6_hdr = 0;
977 sctp_connection_t *sctp_conn, *new_sctp_conn;
978 u16 sctp_implied_length = 0;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100979 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100980 u8 idx;
981
982 bi0 = from[0];
983 to_next[0] = bi0;
984 from += 1;
985 to_next += 1;
986 n_left_from -= 1;
987 n_left_to_next -= 1;
988
989 b0 = vlib_get_buffer (vm, bi0);
990
991 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
992 * will come from the half-open connections pool.
993 */
994 sctp_conn =
995 sctp_half_open_connection_get (vnet_buffer (b0)->
996 sctp.connection_index);
997
998 if (PREDICT_FALSE (sctp_conn == 0))
999 {
Marco Varlese191a5942017-10-30 18:17:21 +01001000 SCTP_ADV_DBG
1001 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1002 error0 = SCTP_ERROR_INVALID_CONNECTION;
1003 goto drop;
1004 }
1005 if (is_ip4)
1006 {
1007 ip4_hdr = vlib_buffer_get_current (b0);
1008 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001009 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001010 }
1011 else
1012 {
1013 ip6_hdr = vlib_buffer_get_current (b0);
1014 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001015 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001016 }
Marco Varlese191a5942017-10-30 18:17:21 +01001017
Marco Varlese04e5d642018-02-23 17:43:06 +01001018 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001019 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1020
Marco Varlese191a5942017-10-30 18:17:21 +01001021 sctp_chunk_hdr =
1022 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1023
1024 sctp_implied_length =
1025 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1026
1027 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1028
1029 switch (chunk_type)
1030 {
1031 case INIT_ACK:
1032 error0 =
1033 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1034 b0, sctp_implied_length);
1035
1036 if (error0 == SCTP_ERROR_NONE)
1037 {
1038 pool_get (tm->connections[my_thread_index], new_sctp_conn);
Dave Barach178cf492018-11-13 16:34:13 -05001039 clib_memcpy_fast (new_sctp_conn, sctp_conn,
1040 sizeof (*new_sctp_conn));
Marco Varlese191a5942017-10-30 18:17:21 +01001041 new_sctp_conn->sub_conn[idx].c_c_index =
1042 new_sctp_conn - tm->connections[my_thread_index];
1043 new_sctp_conn->sub_conn[idx].c_thread_index =
1044 my_thread_index;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001045 new_sctp_conn->sub_conn[idx].PMTU =
1046 sctp_conn->sub_conn[idx].PMTU;
Marco Varlese04e5d642018-02-23 17:43:06 +01001047 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001048
1049 if (sctp_half_open_connection_cleanup (sctp_conn))
1050 {
1051 SCTP_DBG
1052 ("Cannot cleanup half-open connection; not the owning thread");
1053 }
1054
1055 sctp_connection_timers_init (new_sctp_conn);
1056
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001057 sctp_init_cwnd (new_sctp_conn);
1058
Marco Varlese191a5942017-10-30 18:17:21 +01001059 error0 =
1060 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +01001061 new_sctp_conn, idx, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001062 sctp_implied_length);
1063
Marco Varlese191a5942017-10-30 18:17:21 +01001064 if (session_stream_connect_notify
1065 (&new_sctp_conn->sub_conn[idx].connection, 0))
1066 {
1067 SCTP_DBG
1068 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1069 new_sctp_conn->sub_conn[idx].connection.c_index);
1070 sctp_connection_cleanup (new_sctp_conn);
1071 goto drop;
1072 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001073 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001074 }
Marco Varlese191a5942017-10-30 18:17:21 +01001075 break;
1076
Marco Varlese200fa322018-02-26 16:33:54 +01001077 case OPERATION_ERROR:
1078 error0 =
1079 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1080 &next0);
1081 break;
1082
Marco Varlese191a5942017-10-30 18:17:21 +01001083 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1084 * are handled by the input-dispatcher function using the table-lookup
1085 * hence we should never get to the "default" case below.
1086 */
1087 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001088 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001089 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001090 goto drop;
1091 }
1092
1093 if (error0 != SCTP_ERROR_NONE)
1094 {
1095 clib_warning ("error while parsing chunk");
1096 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001097 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001098 goto drop;
1099 }
1100
1101 drop:
1102 b0->error = node->errors[error0];
1103 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1104 {
1105 sctp_rx_trace_t *t0 =
1106 vlib_add_trace (vm, node, b0, sizeof (*t0));
1107 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1108 }
1109
1110 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1111 n_left_to_next, bi0, next0);
1112 }
1113
1114 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1115 }
1116 return from_frame->n_vectors;
1117}
1118
1119static uword
1120sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1121 vlib_frame_t * from_frame)
1122{
1123 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1124}
1125
1126static uword
1127sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1128 vlib_frame_t * from_frame)
1129{
1130 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1131}
1132
1133u8 *
1134format_sctp_rx_trace_short (u8 * s, va_list * args)
1135{
1136 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1137 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1138 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1139
1140 s = format (s, "%d -> %d (%U)",
1141 clib_net_to_host_u16 (t->sctp_header.src_port),
1142 clib_net_to_host_u16 (t->sctp_header.dst_port),
1143 format_sctp_state, t->sctp_connection.state);
1144
1145 return s;
1146}
1147
1148/* *INDENT-OFF* */
1149VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1150{
1151 .function = sctp4_rcv_phase,
1152 .name = "sctp4-rcv",
1153 /* Takes a vector of packets. */
1154 .vector_size = sizeof (u32),
1155 .n_errors = SCTP_N_ERROR,
1156 .error_strings = sctp_error_strings,
1157 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1158 .next_nodes =
1159 {
1160#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1161 foreach_sctp_state_next
1162#undef _
1163 },
1164 .format_trace = format_sctp_rx_trace_short,
1165};
1166/* *INDENT-ON* */
1167
1168VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1169
1170/* *INDENT-OFF* */
1171VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1172{
1173 .function = sctp6_rcv_phase,
1174 .name = "sctp6-rcv",
1175 /* Takes a vector of packets. */
1176 .vector_size = sizeof (u32),
1177 .n_errors = SCTP_N_ERROR,
1178 .error_strings = sctp_error_strings,
1179 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1180 .next_nodes =
1181 {
1182#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1183 foreach_sctp_state_next
1184#undef _
1185 },
1186 .format_trace = format_sctp_rx_trace_short,
1187};
1188/* *INDENT-ON* */
1189
1190VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1191
1192vlib_node_registration_t sctp4_shutdown_phase_node;
1193vlib_node_registration_t sctp6_shutdown_phase_node;
1194
1195always_inline u16
1196sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1197 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001198 sctp_connection_t * sctp_conn, u8 idx,
1199 vlib_buffer_t * b0, u16 sctp_implied_length,
1200 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001201{
1202 sctp_shutdown_association_chunk_t *shutdown_chunk =
1203 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1204
1205 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1206 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1207 {
Marco Varlese87971682018-10-04 15:46:05 +02001208 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001209 return SCTP_ERROR_INVALID_TAG;
1210 }
1211
1212 /*
1213 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1214 */
1215 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1216 return SCTP_ERROR_BUNDLING_VIOLATION;
1217
1218 switch (sctp_conn->state)
1219 {
1220 case SCTP_STATE_ESTABLISHED:
1221 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1222 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
Marco Varlese54432f82018-02-15 17:01:56 +01001223 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001224 break;
1225
1226 case SCTP_STATE_SHUTDOWN_SENT:
Marco Varlese54432f82018-02-15 17:01:56 +01001227 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001228 break;
1229 }
1230
Marco Varlesebe2251b2018-02-07 12:22:41 +01001231 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1232
Marco Varlese191a5942017-10-30 18:17:21 +01001233 return SCTP_ERROR_NONE;
1234}
1235
1236always_inline u16
1237sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1238 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001239 sctp_connection_t * sctp_conn, u8 idx,
1240 vlib_buffer_t * b0, u16 sctp_implied_length,
1241 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001242{
1243 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1244 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1245
1246 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1247 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1248 {
Marco Varlese87971682018-10-04 15:46:05 +02001249 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001250 return SCTP_ERROR_INVALID_TAG;
1251 }
1252
1253 /*
1254 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1255 */
1256 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1257 return SCTP_ERROR_BUNDLING_VIOLATION;
1258
1259 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1260 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1261 * - STOP T2_SHUTDOWN timer
1262 * - SEND SHUTDOWN_COMPLETE chunk
1263 */
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001264 sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
Marco Varlesea38783e2018-02-13 12:38:52 +01001265
Marco Varlese54432f82018-02-15 17:01:56 +01001266 sctp_send_shutdown_complete (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001267
Marco Varlesebe2251b2018-02-07 12:22:41 +01001268 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1269
Marco Varlese191a5942017-10-30 18:17:21 +01001270 return SCTP_ERROR_NONE;
1271}
1272
1273always_inline u16
1274sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1275 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001276 sctp_connection_t * sctp_conn, u8 idx,
1277 vlib_buffer_t * b0, u16 sctp_implied_length,
1278 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001279{
1280 sctp_shutdown_complete_chunk_t *shutdown_complete =
1281 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1282
1283 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1284 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1285 {
Marco Varlese87971682018-10-04 15:46:05 +02001286 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001287 return SCTP_ERROR_INVALID_TAG;
1288 }
1289
1290 /*
1291 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1292 */
1293 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1294 return SCTP_ERROR_BUNDLING_VIOLATION;
1295
Marco Varlesef3ab4892018-02-19 15:23:13 +01001296 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1297
Florin Coras5a2ec8f2018-12-27 11:53:11 -08001298 session_transport_closing_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese191a5942017-10-30 18:17:21 +01001299
1300 sctp_conn->state = SCTP_STATE_CLOSED;
1301
Marco Varlesefae40392018-02-14 15:38:35 +01001302 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001303
Marco Varlese191a5942017-10-30 18:17:21 +01001304 return SCTP_ERROR_NONE;
1305}
1306
1307always_inline uword
1308sctp46_shutdown_phase_inline (vlib_main_t * vm,
1309 vlib_node_runtime_t * node,
1310 vlib_frame_t * from_frame, int is_ip4)
1311{
1312 u32 n_left_from, next_index, *from, *to_next;
1313 u32 my_thread_index = vm->thread_index;
1314
1315 from = vlib_frame_vector_args (from_frame);
1316 n_left_from = from_frame->n_vectors;
1317
1318 next_index = node->cached_next_index;
1319
1320 while (n_left_from > 0)
1321 {
1322 u32 n_left_to_next;
1323
1324 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1325
1326 while (n_left_from > 0 && n_left_to_next > 0)
1327 {
1328 u32 bi0;
1329 vlib_buffer_t *b0;
1330 sctp_rx_trace_t *sctp_trace;
1331 sctp_header_t *sctp_hdr = 0;
1332 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1333 ip4_header_t *ip4_hdr = 0;
1334 ip6_header_t *ip6_hdr = 0;
1335 sctp_connection_t *sctp_conn;
1336 u16 sctp_implied_length = 0;
1337 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
Marco Varlese54432f82018-02-15 17:01:56 +01001338 u8 idx = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001339
1340 bi0 = from[0];
1341 to_next[0] = bi0;
1342 from += 1;
1343 to_next += 1;
1344 n_left_from -= 1;
1345 n_left_to_next -= 1;
1346
1347 b0 = vlib_get_buffer (vm, bi0);
1348 sctp_conn =
1349 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1350 my_thread_index);
1351
1352 if (PREDICT_FALSE (sctp_conn == 0))
1353 {
1354 SCTP_DBG
1355 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1356 error0 = SCTP_ERROR_INVALID_CONNECTION;
1357 goto drop;
1358 }
1359
1360 if (is_ip4)
1361 {
1362 ip4_hdr = vlib_buffer_get_current (b0);
1363 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001364 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001365 }
1366 else
1367 {
1368 ip6_hdr = vlib_buffer_get_current (b0);
1369 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001370 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001371 }
1372
1373 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1374 sctp_chunk_hdr = &full_hdr->common_hdr;
1375
1376 sctp_implied_length =
1377 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1378
Marco Varlesebe2251b2018-02-07 12:22:41 +01001379 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1380 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001381 {
1382 case SHUTDOWN:
1383 error0 =
Marco Varlesebe2251b2018-02-07 12:22:41 +01001384 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1385 idx, b0, sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001386 break;
1387
1388 case SHUTDOWN_ACK:
1389 error0 =
1390 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001391 idx, b0, sctp_implied_length,
1392 &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001393 break;
1394
1395 case SHUTDOWN_COMPLETE:
1396 error0 =
1397 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001398 sctp_conn, idx, b0,
1399 sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001400
1401 sctp_connection_cleanup (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001402 break;
1403
1404 /*
1405 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1406 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1407 */
1408 case DATA:
1409 error0 =
1410 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001411 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001412 break;
1413
Marco Varlese200fa322018-02-26 16:33:54 +01001414 case OPERATION_ERROR:
1415 error0 =
1416 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1417 &next0);
1418 break;
1419
Marco Varlese8c5f67f2018-02-27 09:38:31 +01001420 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1421 sctp_prepare_operation_error (sctp_conn, idx, b0,
1422 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1423 error0 = SCTP_ERROR_NONE;
1424 next0 = sctp_next_output (is_ip4);
1425 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001426 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1427 * are handled by the input-dispatcher function using the table-lookup
1428 * hence we should never get to the "default" case below.
1429 */
1430 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001431 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001432 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001433 goto drop;
1434 }
1435
1436 if (error0 != SCTP_ERROR_NONE)
1437 {
1438 clib_warning ("error while parsing chunk");
1439 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001440 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001441 goto drop;
1442 }
1443
1444 drop:
1445 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1446 {
1447 sctp_trace =
1448 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
Marco Varlesef429a932018-02-06 17:31:06 +01001449
1450 if (sctp_hdr != NULL)
Dave Barach178cf492018-11-13 16:34:13 -05001451 clib_memcpy_fast (&sctp_trace->sctp_header, sctp_hdr,
1452 sizeof (sctp_trace->sctp_header));
Marco Varlesef429a932018-02-06 17:31:06 +01001453
1454 if (sctp_conn != NULL)
Dave Barach178cf492018-11-13 16:34:13 -05001455 clib_memcpy_fast (&sctp_trace->sctp_connection, sctp_conn,
1456 sizeof (sctp_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001457 }
1458
1459 b0->error = node->errors[error0];
1460
1461 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1462 n_left_to_next, bi0, next0);
1463 }
1464
1465 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1466 }
1467
1468 return from_frame->n_vectors;
1469
1470}
1471
1472static uword
1473sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1474 vlib_frame_t * from_frame)
1475{
1476 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1477}
1478
1479static uword
1480sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1481 vlib_frame_t * from_frame)
1482{
1483 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1484}
1485
1486/* *INDENT-OFF* */
1487VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1488{
1489 .function = sctp4_shutdown_phase,
1490 .name = "sctp4-shutdown",
1491 /* Takes a vector of packets. */
1492 .vector_size = sizeof (u32),
1493 .n_errors = SCTP_N_ERROR,
1494 .error_strings = sctp_error_strings,
1495 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1496 .next_nodes =
1497 {
1498#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1499 foreach_sctp_state_next
1500#undef _
1501 },
1502 .format_trace = format_sctp_rx_trace_short,
1503};
1504/* *INDENT-ON* */
1505
1506VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1507 sctp4_shutdown_phase);
1508
1509/* *INDENT-OFF* */
1510VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1511{
1512 .function = sctp6_shutdown_phase,
1513 .name = "sctp6-shutdown",
1514 /* Takes a vector of packets. */
1515 .vector_size = sizeof (u32),
1516 .n_errors = SCTP_N_ERROR,
1517 .error_strings = sctp_error_strings,
1518 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1519 .next_nodes =
1520 {
1521#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1522 foreach_sctp_state_next
1523#undef _
1524 },
1525 .format_trace = format_sctp_rx_trace_short,
1526};
1527/* *INDENT-ON* */
1528
1529VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1530 sctp6_shutdown_phase);
1531
1532vlib_node_registration_t sctp4_listen_phase_node;
1533vlib_node_registration_t sctp6_listen_phase_node;
1534
1535vlib_node_registration_t sctp4_established_phase_node;
1536vlib_node_registration_t sctp6_established_phase_node;
1537
1538always_inline u16
1539sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001540 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001541 u16 * next0)
1542{
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001543
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001544 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1545 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1546 {
Marco Varlese93826732018-09-27 16:43:57 +02001547 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001548 return SCTP_ERROR_INVALID_TAG;
1549 }
1550
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001551 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1552
Marco Varlese54432f82018-02-15 17:01:56 +01001553 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1554
Marco Varlesef3ab4892018-02-19 15:23:13 +01001555 /* Section 7.2.2; point (2) */
1556 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1557 sctp_conn->sub_conn[idx].partially_acked_bytes =
1558 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1559
1560 /* Section 7.2.2; point (5) */
1561 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1562 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1563
1564 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1565
Marco Varlese21c8baf2018-02-02 17:17:51 +01001566 sctp_calculate_rto (sctp_conn, idx);
1567
1568 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1569 sctp_conn->sub_conn[idx].RTO);
1570
1571 sctp_conn->sub_conn[idx].RTO_pending = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001572
Marco Varlesefae40392018-02-14 15:38:35 +01001573 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001574
1575 return SCTP_ERROR_NONE;
1576}
1577
1578always_inline u16
1579sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001580 sctp_connection_t * sctp_conn, u8 idx,
1581 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001582{
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001583 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1584 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1585 {
Marco Varlese87971682018-10-04 15:46:05 +02001586 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001587 return SCTP_ERROR_INVALID_TAG;
1588 }
1589
Marco Varlese54432f82018-02-15 17:01:56 +01001590 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001591
1592 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1593
Marco Varlese191a5942017-10-30 18:17:21 +01001594 return SCTP_ERROR_NONE;
1595}
1596
1597always_inline u16
1598sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001599 sctp_connection_t * sctp_conn, u8 idx,
1600 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001601{
Marco Varlese54432f82018-02-15 17:01:56 +01001602 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1603
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001604 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1605
1606 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1607 sctp_conn->sub_conn[idx].RTO);
1608
Marco Varlesefae40392018-02-14 15:38:35 +01001609 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001610
Marco Varlese191a5942017-10-30 18:17:21 +01001611 return SCTP_ERROR_NONE;
1612}
1613
1614always_inline void
Marco Varlese3c6a9762018-03-01 11:19:59 +01001615sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
Marco Varlese191a5942017-10-30 18:17:21 +01001616 u8 is_ip4, u8 evt, u8 val)
1617{
1618 if (PREDICT_TRUE (!val))
1619 return;
1620
1621 if (is_ip4)
Marco Varlese3c6a9762018-03-01 11:19:59 +01001622 vlib_node_increment_counter (vm, sctp4_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001623 else
Marco Varlese3c6a9762018-03-01 11:19:59 +01001624 vlib_node_increment_counter (vm, sctp6_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001625}
1626
1627always_inline uword
1628sctp46_listen_process_inline (vlib_main_t * vm,
1629 vlib_node_runtime_t * node,
1630 vlib_frame_t * from_frame, int is_ip4)
1631{
1632 u32 n_left_from, next_index, *from, *to_next;
1633 u32 my_thread_index = vm->thread_index;
1634
1635 from = vlib_frame_vector_args (from_frame);
1636 n_left_from = from_frame->n_vectors;
1637
1638 next_index = node->cached_next_index;
1639
1640 while (n_left_from > 0)
1641 {
1642 u32 n_left_to_next;
1643
1644 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1645
1646 while (n_left_from > 0 && n_left_to_next > 0)
1647 {
1648 u32 bi0;
1649 vlib_buffer_t *b0;
1650 sctp_header_t *sctp_hdr = 0;
1651 ip4_header_t *ip4_hdr;
1652 ip6_header_t *ip6_hdr;
1653 sctp_connection_t *child_conn;
1654 sctp_connection_t *sctp_listener;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001655 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
Marco Varlese191a5942017-10-30 18:17:21 +01001656
1657 bi0 = from[0];
1658 to_next[0] = bi0;
1659 from += 1;
1660 to_next += 1;
1661 n_left_from -= 1;
1662 n_left_to_next -= 1;
1663
1664 b0 = vlib_get_buffer (vm, bi0);
1665 sctp_listener =
1666 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1667
1668 if (is_ip4)
1669 {
1670 ip4_hdr = vlib_buffer_get_current (b0);
1671 sctp_hdr = ip4_next_header (ip4_hdr);
1672 }
1673 else
1674 {
1675 ip6_hdr = vlib_buffer_get_current (b0);
1676 sctp_hdr = ip6_next_header (ip6_hdr);
1677 }
1678
1679 child_conn =
1680 sctp_lookup_connection (sctp_listener->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001681 [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001682 my_thread_index, is_ip4);
1683
1684 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1685 {
1686 SCTP_DBG
1687 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001688 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001689 connection.c_index,
1690 sctp_state_to_string (child_conn->state));
1691 error0 = SCTP_ERROR_CREATE_EXISTS;
1692 goto drop;
1693 }
1694
1695 /* Create child session and send SYN-ACK */
1696 child_conn = sctp_connection_new (my_thread_index);
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001697 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1698 SCTP_PRIMARY_PATH_IDX;
1699 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001700 sctp_hdr->dst_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001701 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001702 sctp_hdr->src_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001703 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1704 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1705 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1706 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1707 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
Marco Varlese191a5942017-10-30 18:17:21 +01001708 child_conn->state = SCTP_STATE_CLOSED;
Marco Varlesee17bb712018-03-28 12:06:10 +02001709 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1710 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1711 connection.fib_index;
Marco Varlese191a5942017-10-30 18:17:21 +01001712
1713 if (is_ip4)
1714 {
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001715 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001716 ip4_hdr->dst_address.as_u32;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001717 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001718 ip4_hdr->src_address.as_u32;
1719 }
1720 else
1721 {
Dave Barach178cf492018-11-13 16:34:13 -05001722 clib_memcpy_fast (&child_conn->
1723 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
1724 &ip6_hdr->dst_address,
1725 sizeof (ip6_address_t));
1726 clib_memcpy_fast (&child_conn->
1727 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
1728 &ip6_hdr->src_address,
1729 sizeof (ip6_address_t));
Marco Varlese191a5942017-10-30 18:17:21 +01001730 }
1731
1732 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1733 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1734
1735 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +02001736 if (chunk_type != INIT && chunk_type != DATA
1737 && chunk_type != OPERATION_ERROR)
Marco Varlese191a5942017-10-30 18:17:21 +01001738 {
1739 SCTP_DBG
1740 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001741 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001742 connection.c_index, sctp_chunk_to_string (chunk_type));
1743
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001744 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001745 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001746 goto drop;
1747 }
1748
1749 u16 sctp_implied_length =
1750 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1751
1752 switch (chunk_type)
1753 {
1754 case INIT:
1755 sctp_connection_timers_init (child_conn);
1756
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001757 sctp_init_snd_vars (child_conn);
1758
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001759 sctp_init_cwnd (child_conn);
1760
Marco Varlese191a5942017-10-30 18:17:21 +01001761 error0 =
1762 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1763 sctp_implied_length);
1764
Marco Varlese191a5942017-10-30 18:17:21 +01001765 if (error0 == SCTP_ERROR_NONE)
1766 {
1767 if (stream_session_accept
1768 (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001769 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
Marco Varlese191a5942017-10-30 18:17:21 +01001770 sctp_listener->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001771 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
Marco Varlese191a5942017-10-30 18:17:21 +01001772 {
1773 clib_warning ("session accept fail");
1774 sctp_connection_cleanup (child_conn);
1775 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1776 goto drop;
1777 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001778 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001779 }
Marco Varlese191a5942017-10-30 18:17:21 +01001780 break;
1781
1782 /* Reception of a DATA chunk whilst in the CLOSED state is called
1783 * "Out of the Blue" packet and handling of the chunk needs special treatment
1784 * as per RFC4960 section 8.4
1785 */
1786 case DATA:
1787 break;
Marco Varlese200fa322018-02-26 16:33:54 +01001788
1789 case OPERATION_ERROR:
1790 error0 =
1791 sctp_handle_operation_err (sctp_hdr, child_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001792 SCTP_PRIMARY_PATH_IDX, b0, &next0);
Marco Varlese200fa322018-02-26 16:33:54 +01001793 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001794 }
1795
1796 drop:
1797 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1798 {
1799 sctp_rx_trace_t *t0 =
1800 vlib_add_trace (vm, node, b0, sizeof (*t0));
Dave Barach178cf492018-11-13 16:34:13 -05001801 clib_memcpy_fast (&t0->sctp_header, sctp_hdr,
1802 sizeof (t0->sctp_header));
1803 clib_memcpy_fast (&t0->sctp_connection, sctp_listener,
1804 sizeof (t0->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001805 }
1806
1807 b0->error = node->errors[error0];
1808
1809 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1810 n_left_to_next, bi0, next0);
1811 }
1812 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1813
1814 }
1815 return from_frame->n_vectors;
1816}
1817
1818static uword
1819sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1820 vlib_frame_t * from_frame)
1821{
1822 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1823}
1824
1825static uword
1826sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1827 vlib_frame_t * from_frame)
1828{
1829 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1830}
1831
1832always_inline uword
1833sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1834 vlib_frame_t * from_frame, int is_ip4)
1835{
1836 u32 n_left_from, next_index, *from, *to_next;
1837 u32 my_thread_index = vm->thread_index, errors = 0;
1838
1839 from = vlib_frame_vector_args (from_frame);
1840 n_left_from = from_frame->n_vectors;
1841
1842 next_index = node->cached_next_index;
1843
1844 while (n_left_from > 0)
1845 {
1846 u32 n_left_to_next;
1847
1848 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1849
1850 while (n_left_from > 0 && n_left_to_next > 0)
1851 {
1852 u32 bi0;
1853 vlib_buffer_t *b0;
1854 sctp_header_t *sctp_hdr = 0;
1855 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1856 ip4_header_t *ip4_hdr = 0;
1857 ip6_header_t *ip6_hdr = 0;
1858 sctp_connection_t *sctp_conn;
Marco Varlesefae40392018-02-14 15:38:35 +01001859 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1860 SCTP_ESTABLISHED_PHASE_N_NEXT;
Marco Varlese191a5942017-10-30 18:17:21 +01001861 u8 idx;
1862
1863 bi0 = from[0];
1864 to_next[0] = bi0;
1865 from += 1;
1866 to_next += 1;
1867 n_left_from -= 1;
1868 n_left_to_next -= 1;
1869
1870 b0 = vlib_get_buffer (vm, bi0);
1871 sctp_conn =
1872 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1873 my_thread_index);
1874
1875 if (PREDICT_FALSE (sctp_conn == 0))
1876 {
1877 SCTP_DBG
1878 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1879 error0 = SCTP_ERROR_INVALID_CONNECTION;
1880 goto done;
1881 }
1882 if (is_ip4)
1883 {
1884 ip4_hdr = vlib_buffer_get_current (b0);
1885 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001886 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001887 }
1888 else
1889 {
1890 ip6_hdr = vlib_buffer_get_current (b0);
1891 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001892 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001893 }
1894
Marco Varlese04e5d642018-02-23 17:43:06 +01001895 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001896
Marco Varlese54432f82018-02-15 17:01:56 +01001897 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +01001898 sctp_chunk_hdr =
1899 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1900
1901 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1902
1903 switch (chunk_type)
1904 {
1905 case COOKIE_ECHO:
1906 error0 =
1907 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001908 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001909 break;
1910
1911 case COOKIE_ACK:
1912 error0 =
1913 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001914 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001915 break;
1916
1917 case SACK:
1918 error0 =
1919 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001920 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001921 break;
1922
1923 case HEARTBEAT:
1924 error0 =
1925 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001926 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001927 break;
1928
1929 case HEARTBEAT_ACK:
1930 error0 =
1931 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001932 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001933 break;
1934
1935 case DATA:
1936 error0 =
1937 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001938 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001939 break;
1940
Marco Varlese200fa322018-02-26 16:33:54 +01001941 case OPERATION_ERROR:
1942 error0 =
1943 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1944 &next0);
1945 break;
1946
Marco Varlese191a5942017-10-30 18:17:21 +01001947 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1948 * are handled by the input-dispatcher function using the table-lookup
1949 * hence we should never get to the "default" case below.
1950 */
1951 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001952 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001953 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001954 goto done;
1955 }
1956
1957 done:
1958 b0->error = node->errors[error0];
1959 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1960 {
1961 sctp_rx_trace_t *t0 =
1962 vlib_add_trace (vm, node, b0, sizeof (*t0));
1963 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1964 }
1965
1966 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1967 n_left_to_next, bi0, next0);
1968 }
1969
1970 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1971 }
1972
1973 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1974 my_thread_index);
1975
1976 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1977 sctp6_established_phase_node.index,
1978 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1979 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1980
1981 return from_frame->n_vectors;
1982}
1983
1984static uword
1985sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1986 vlib_frame_t * from_frame)
1987{
1988 return sctp46_established_phase_inline (vm, node, from_frame,
1989 1 /* is_ip4 */ );
1990}
1991
1992static uword
1993sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1994 vlib_frame_t * from_frame)
1995{
1996 return sctp46_established_phase_inline (vm, node, from_frame,
1997 0 /* is_ip4 */ );
1998}
1999
2000u8 *
2001format_sctp_rx_trace (u8 * s, va_list * args)
2002{
2003 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2004 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2005 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
2006 u32 indent = format_get_indent (s);
2007
2008 s = format (s, "%U\n%U%U",
2009 format_sctp_header, &t->sctp_header, 128,
2010 format_white_space, indent,
2011 format_sctp_connection, &t->sctp_connection, 1);
2012
2013 return s;
2014}
2015
2016/* *INDENT-OFF* */
2017VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
2018{
2019 .function = sctp4_listen_phase,
2020 .name = "sctp4-listen",
2021 /* Takes a vector of packets. */
2022 .vector_size = sizeof (u32),
2023 .n_errors = SCTP_N_ERROR,
2024 .error_strings = sctp_error_strings,
2025 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2026 .next_nodes =
2027 {
2028#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2029 foreach_sctp_state_next
2030#undef _
2031 },
2032 .format_trace = format_sctp_rx_trace_short,
2033};
2034/* *INDENT-ON* */
2035
2036VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
2037
2038/* *INDENT-OFF* */
2039VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
2040{
2041 .function = sctp6_listen_phase,
2042 .name = "sctp6-listen",
2043 /* Takes a vector of packets. */
2044 .vector_size = sizeof (u32),
2045 .n_errors = SCTP_N_ERROR,
2046 .error_strings = sctp_error_strings,
2047 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2048 .next_nodes =
2049 {
2050#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2051 foreach_sctp_state_next
2052#undef _
2053 },
2054 .format_trace = format_sctp_rx_trace_short,
2055};
2056/* *INDENT-ON* */
2057
2058VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
2059
2060/* *INDENT-OFF* */
2061VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2062{
2063 .function = sctp4_established_phase,
2064 .name = "sctp4-established",
2065 /* Takes a vector of packets. */
2066 .vector_size = sizeof (u32),
2067 .n_errors = SCTP_N_ERROR,
2068 .error_strings = sctp_error_strings,
2069 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2070 .next_nodes =
2071 {
2072#define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2073 foreach_sctp_state_next
2074#undef _
2075 },
2076 .format_trace = format_sctp_rx_trace_short,
2077};
2078/* *INDENT-ON* */
2079
2080VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
2081 sctp4_established_phase);
2082
2083/* *INDENT-OFF* */
2084VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2085{
2086 .function = sctp6_established_phase,
2087 .name = "sctp6-established",
2088 /* Takes a vector of packets. */
2089 .vector_size = sizeof (u32),
2090 .n_errors = SCTP_N_ERROR,
2091 .error_strings = sctp_error_strings,
2092 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2093 .next_nodes =
2094 {
2095#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2096 foreach_sctp_state_next
2097#undef _
2098 },
2099 .format_trace = format_sctp_rx_trace_short,
2100};
2101/* *INDENT-ON* */
2102
2103VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2104 sctp6_established_phase);
2105
2106/*
2107 * This is the function executed first for the SCTP graph.
2108 * It takes care of doing the initial message parsing and
2109 * dispatch to the specialized function.
2110 */
2111always_inline uword
2112sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2113 vlib_frame_t * from_frame, int is_ip4)
2114{
2115 u32 n_left_from, next_index, *from, *to_next;
2116 u32 my_thread_index = vm->thread_index;
Florin Corasb5e55a22019-01-10 12:42:47 -08002117 u8 result;
Marco Varlese191a5942017-10-30 18:17:21 +01002118 sctp_main_t *tm = vnet_get_sctp_main ();
2119
2120 from = vlib_frame_vector_args (from_frame);
2121 n_left_from = from_frame->n_vectors;
2122 next_index = node->cached_next_index;
2123 sctp_set_time_now (my_thread_index);
2124
2125 while (n_left_from > 0)
2126 {
2127 u32 n_left_to_next;
2128
2129 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2130
2131 while (n_left_from > 0 && n_left_to_next > 0)
2132 {
2133 int n_advance_bytes0, n_data_bytes0;
2134 u32 bi0, fib_index0;
2135 vlib_buffer_t *b0;
2136 sctp_header_t *sctp_hdr = 0;
2137 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2138 sctp_connection_t *sctp_conn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002139 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01002140 ip4_header_t *ip4_hdr;
2141 ip6_header_t *ip6_hdr;
2142 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2143
2144 bi0 = from[0];
2145 to_next[0] = bi0;
2146 from += 1;
2147 to_next += 1;
2148 n_left_from -= 1;
2149 n_left_to_next -= 1;
2150
2151 b0 = vlib_get_buffer (vm, bi0);
Marco Varlese3c6a9762018-03-01 11:19:59 +01002152 vnet_buffer (b0)->sctp.flags = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01002153 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2154
2155 /* Checksum computed by ipx_local no need to compute again */
2156
2157 if (is_ip4)
2158 {
2159 ip4_hdr = vlib_buffer_get_current (b0);
2160 sctp_hdr = ip4_next_header (ip4_hdr);
2161
2162 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2163 sctp_chunk_hdr = &full_hdr->common_hdr;
2164
2165 n_advance_bytes0 =
2166 (ip4_header_bytes (ip4_hdr) +
2167 sizeof (sctp_payload_data_chunk_t));
2168 n_data_bytes0 =
2169 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2170
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002171 trans_conn = session_lookup_connection_wt4 (fib_index0,
2172 &ip4_hdr->dst_address,
2173 &ip4_hdr->src_address,
2174 sctp_hdr->dst_port,
2175 sctp_hdr->src_port,
2176 TRANSPORT_PROTO_SCTP,
2177 my_thread_index,
Florin Corasb5e55a22019-01-10 12:42:47 -08002178 &result);
Marco Varlese191a5942017-10-30 18:17:21 +01002179 }
2180 else
2181 {
2182 ip6_hdr = vlib_buffer_get_current (b0);
2183 sctp_hdr = ip6_next_header (ip6_hdr);
2184
2185 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2186 sctp_chunk_hdr = &full_hdr->common_hdr;
2187
2188 n_advance_bytes0 = sctp_header_bytes ();
2189 n_data_bytes0 =
2190 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2191 n_advance_bytes0;
2192 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2193
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002194 trans_conn = session_lookup_connection_wt6 (fib_index0,
2195 &ip6_hdr->dst_address,
2196 &ip6_hdr->src_address,
2197 sctp_hdr->dst_port,
2198 sctp_hdr->src_port,
2199 TRANSPORT_PROTO_SCTP,
2200 my_thread_index,
Florin Corasb5e55a22019-01-10 12:42:47 -08002201 &result);
Marco Varlese191a5942017-10-30 18:17:21 +01002202 }
2203
2204 /* Length check */
2205 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2206 {
2207 error0 = SCTP_ERROR_LENGTH;
2208 goto done;
2209 }
2210
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002211 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01002212 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2213
Marco Varlesefae40392018-02-14 15:38:35 +01002214 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2215 if (chunk_type >= UNKNOWN)
2216 {
2217 clib_warning
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002218 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2219
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002220 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002221 b0, UNRECOGNIZED_CHUNK_TYPE);
2222
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03002223 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002224 next0 = sctp_next_output (is_ip4);
Marco Varlesefae40392018-02-14 15:38:35 +01002225 goto done;
2226 }
2227
Marco Varlese191a5942017-10-30 18:17:21 +01002228 vnet_buffer (b0)->sctp.hdr_offset =
2229 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2230
2231 /* Session exists */
2232 if (PREDICT_TRUE (0 != sctp_conn))
2233 {
2234 /* Save connection index */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002235 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
Marco Varlese191a5942017-10-30 18:17:21 +01002236 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2237 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2238
Marco Varlesefae40392018-02-14 15:38:35 +01002239 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2240 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
Marco Varlese191a5942017-10-30 18:17:21 +01002241
Marco Varlesef3ab4892018-02-19 15:23:13 +01002242 SCTP_DBG_STATE_MACHINE
Marco Varlese15cc6a82018-02-21 12:39:52 +01002243 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
Marco Varlesef3ab4892018-02-19 15:23:13 +01002244 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002245 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002246 connection.s_index,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002247 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002248 connection.c_index, trans_conn, sctp_conn,
2249 sctp_state_to_string (sctp_conn->state),
Marco Varlesef3ab4892018-02-19 15:23:13 +01002250 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
Marco Varlese191a5942017-10-30 18:17:21 +01002251
Marco Varlesefae40392018-02-14 15:38:35 +01002252 if (chunk_type == DATA)
Marco Varlese191a5942017-10-30 18:17:21 +01002253 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2254 n_advance_bytes0, n_data_bytes0);
2255
2256 }
2257 else
2258 {
Florin Corasb5e55a22019-01-10 12:42:47 -08002259 if (result)
Marco Varlese191a5942017-10-30 18:17:21 +01002260 {
2261 next0 = SCTP_INPUT_NEXT_DROP;
Florin Corasb5e55a22019-01-10 12:42:47 -08002262 error0 = SCTP_ERROR_NONE + result;
Marco Varlese191a5942017-10-30 18:17:21 +01002263 }
2264 else if ((is_ip4 && tm->punt_unknown4) ||
2265 (!is_ip4 && tm->punt_unknown6))
2266 {
2267 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2268 error0 = SCTP_ERROR_PUNT;
2269 }
2270 else
2271 {
2272 next0 = SCTP_INPUT_NEXT_DROP;
2273 error0 = SCTP_ERROR_NO_LISTENER;
2274 }
2275 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2276 phase_to_string (next0));
2277 sctp_conn = 0;
2278 }
2279
2280 done:
2281 b0->error = error0 ? node->errors[error0] : 0;
2282
2283 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2284 {
2285 sctp_rx_trace_t *t0 =
2286 vlib_add_trace (vm, node, b0, sizeof (*t0));
2287 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2288 }
2289 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2290 n_left_to_next, bi0, next0);
2291 }
2292
2293 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2294 }
2295 return from_frame->n_vectors;
2296}
2297
2298static uword
2299sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2300 vlib_frame_t * from_frame)
2301{
2302 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2303}
2304
2305static uword
2306sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2307 vlib_frame_t * from_frame)
2308{
2309 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2310}
2311
2312/* *INDENT-OFF* */
2313VLIB_REGISTER_NODE (sctp4_input_node) =
2314{
2315 .function = sctp4_input_dispatcher,
2316 .name = "sctp4-input",
2317 /* Takes a vector of packets. */
2318 .vector_size = sizeof (u32),
2319 .n_errors = SCTP_N_ERROR,
2320 .error_strings = sctp_error_strings,
2321 .n_next_nodes = SCTP_INPUT_N_NEXT,
2322 .next_nodes =
2323 {
2324#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2325 foreach_sctp4_input_next
2326#undef _
2327 },
2328 .format_buffer = format_sctp_header,
2329 .format_trace = format_sctp_rx_trace,
2330};
2331/* *INDENT-ON* */
2332
2333VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2334
2335/* *INDENT-OFF* */
2336VLIB_REGISTER_NODE (sctp6_input_node) =
2337{
2338 .function = sctp6_input_dispatcher,
2339 .name = "sctp6-input",
2340 /* Takes a vector of packets. */
2341 .vector_size = sizeof (u32),
2342 .n_errors = SCTP_N_ERROR,
2343 .error_strings = sctp_error_strings,
2344 .n_next_nodes = SCTP_INPUT_N_NEXT,
2345 .next_nodes =
2346 {
2347#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2348 foreach_sctp6_input_next
2349#undef _
2350 },
2351 .format_buffer = format_sctp_header,
2352 .format_trace = format_sctp_rx_trace,
2353};
2354/* *INDENT-ON* */
2355
2356VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2357
2358vlib_node_registration_t sctp4_input_node;
2359vlib_node_registration_t sctp6_input_node;
2360
2361static void
2362sctp_dispatch_table_init (sctp_main_t * tm)
2363{
2364 int i, j;
2365 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2366 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2367 {
2368 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2369 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2370 }
2371
2372#define _(t,f,n,e) \
2373do { \
2374 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2375 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2376} while (0)
2377
2378 /*
2379 * SCTP STATE-MACHINE states:
2380 *
2381 * _(CLOSED, "CLOSED") \
2382 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2383 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2384 * _(ESTABLISHED, "ESTABLISHED") \
2385 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2386 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2387 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2388 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2389 */
Marco Varlesef3ab4892018-02-19 15:23:13 +01002390 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002391 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2392 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2393 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2394 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2395 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2396 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2397 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2398 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2399 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2400 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2401 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2402 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2403 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2404 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002405 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002406
Marco Varlese200fa322018-02-26 16:33:54 +01002407 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002408 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2409 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2410 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2411 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2412 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2413 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2414 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2415 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2416 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2417 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2418 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2419 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2420 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2421 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002422 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2423 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002424
2425 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2426 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2427 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2428 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2429 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2430 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2431 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2432 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2433 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2434 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2435 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2436 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2437 SCTP_ERROR_NONE);
2438 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2439 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2440 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002441 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2442 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002443
2444 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2445 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2446 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2447 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2448 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2449 SCTP_ERROR_NONE);
2450 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2451 SCTP_ERROR_NONE);
2452 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2453 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2454 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2455 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2456 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2457 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2458 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2459 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2460 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002461 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2462 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002463
2464 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2465 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2466 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2467 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2468 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2469 SCTP_ERROR_NONE);
2470 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2471 SCTP_ERROR_NONE);
2472 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2473 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2474 SCTP_ERROR_NONE);
2475 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2476 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002477 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2478 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002479 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2480 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2481 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2482 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002483 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2484 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002485
2486 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2487 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2488 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2489 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2490 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2491 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2492 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2493 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2494 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2495 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002496 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2497 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002498 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2499 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2500 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2501 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002502 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2503 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002504
2505 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2506 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2507 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2508 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2509 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2510 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2511 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2512 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2513 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2514 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002515 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2516 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002517 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2518 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2519 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2520 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002521 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2522 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002523
2524 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
Marco Varleseeacf3cf2018-02-26 14:52:25 +01002525 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
Marco Varlese191a5942017-10-30 18:17:21 +01002526 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2527 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2528 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2529 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2530 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2531 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2532 _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002533 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2534 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002535 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2536 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2537 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2538 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2539 SCTP_ERROR_NONE);
Marco Varlese200fa322018-02-26 16:33:54 +01002540 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2541 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002542
2543 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2544
2545#undef _
2546}
2547
2548clib_error_t *
2549sctp_input_init (vlib_main_t * vm)
2550{
2551 clib_error_t *error = 0;
2552 sctp_main_t *tm = vnet_get_sctp_main ();
2553
2554 if ((error = vlib_call_init_function (vm, sctp_init)))
2555 return error;
2556
2557 /* Initialize dispatch table. */
2558 sctp_dispatch_table_init (tm);
2559
2560 return error;
2561}
2562
2563VLIB_INIT_FUNCTION (sctp_input_init);
2564
2565/*
2566 * fd.io coding-style-patch-verification: ON
2567 *
2568 * Local Variables:
2569 * eval: (c-set-style "gnu")
2570 * End:
2571 */