blob: c41e9ccdcae02ada12024d7a276cdf49171f48f0 [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
Filip Tehlara5a458f2019-03-05 06:50:19 -080087#ifndef CLIB_MARCH_VARIANT
Marco Varlese191a5942017-10-30 18:17:21 +010088char *
89phase_to_string (u8 phase)
90{
91 switch (phase)
92 {
93 case SCTP_INPUT_NEXT_DROP:
94 return "SCTP_INPUT_NEXT_DROP";
95 case SCTP_INPUT_NEXT_LISTEN_PHASE:
96 return "SCTP_INPUT_NEXT_LISTEN_PHASE";
97 case SCTP_INPUT_NEXT_RCV_PHASE:
98 return "SCTP_INPUT_NEXT_RCV_PHASE";
99 case SCTP_INPUT_NEXT_ESTABLISHED_PHASE:
100 return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
101 case SCTP_INPUT_NEXT_SHUTDOWN_PHASE:
102 return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
103 case SCTP_INPUT_NEXT_PUNT_PHASE:
104 return "SCTP_INPUT_NEXT_PUNT_PHASE";
105 }
106 return NULL;
107}
Filip Tehlara5a458f2019-03-05 06:50:19 -0800108#endif /* CLIB_MARCH_VARIANT */
Marco Varlese191a5942017-10-30 18:17:21 +0100109
110#define foreach_sctp4_input_next \
111 _ (DROP, "error-drop") \
112 _ (RCV_PHASE, "sctp4-rcv") \
113 _ (LISTEN_PHASE, "sctp4-listen") \
114 _ (ESTABLISHED_PHASE, "sctp4-established") \
115 _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
116 _ (PUNT_PHASE, "ip4-punt")
117
118
119#define foreach_sctp6_input_next \
120 _ (DROP, "error-drop") \
121 _ (RCV_PHASE, "sctp6-rcv") \
122 _ (LISTEN_PHASE, "sctp6-listen") \
123 _ (ESTABLISHED_PHASE, "sctp6-established") \
124 _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
125 _ (PUNT_PHASE, "ip6-punt")
126
127static u8
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100128sctp_lookup_is_valid (transport_connection_t * trans_conn,
Marco Varlese191a5942017-10-30 18:17:21 +0100129 sctp_header_t * sctp_hdr)
130{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100131 sctp_connection_t *sctp_conn =
132 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100133
134 if (!sctp_conn)
135 return 1;
136
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100137 u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
Marco Varlese191a5942017-10-30 18:17:21 +0100138 && (sctp_conn->state == SCTP_STATE_CLOSED
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100139 || trans_conn->rmt_port == sctp_hdr->src_port));
Marco Varlese191a5942017-10-30 18:17:21 +0100140
141 return is_valid;
142}
143
144/**
145 * Lookup transport connection
146 */
147static sctp_connection_t *
148sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
149 u8 is_ip4)
150{
151 sctp_main_t *tm = vnet_get_sctp_main ();
152 sctp_header_t *sctp_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100153 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100154 sctp_connection_t *sctp_conn;
155 u8 is_filtered, i;
156 if (is_ip4)
157 {
158 ip4_header_t *ip4_hdr;
159 ip4_hdr = vlib_buffer_get_current (b);
160 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100161 trans_conn = session_lookup_connection_wt4 (fib_index,
162 &ip4_hdr->dst_address,
163 &ip4_hdr->src_address,
164 sctp_hdr->dst_port,
165 sctp_hdr->src_port,
166 TRANSPORT_PROTO_SCTP,
167 thread_index, &is_filtered);
168 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100169 {
170 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
171 {
172 if ((tm->connections[thread_index]->sub_conn[i].
173 connection.lcl_ip.ip4.as_u32 ==
174 ip4_hdr->dst_address.as_u32)
175 && (tm->connections[thread_index]->sub_conn[i].
176 connection.rmt_ip.ip4.as_u32 ==
177 ip4_hdr->src_address.as_u32))
178 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100179 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100180 &tm->connections[thread_index]->sub_conn[i].connection;
181 break;
182 }
183 }
184 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100185 ASSERT (trans_conn != 0);
186 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100187 }
188 else
189 {
190 ip6_header_t *ip6_hdr;
191 ip6_hdr = vlib_buffer_get_current (b);
192 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100193 trans_conn = session_lookup_connection_wt6 (fib_index,
194 &ip6_hdr->dst_address,
195 &ip6_hdr->src_address,
196 sctp_hdr->dst_port,
197 sctp_hdr->src_port,
198 TRANSPORT_PROTO_SCTP,
199 thread_index, &is_filtered);
200 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100201 {
202 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
203 {
204 if ((tm->connections[thread_index]->sub_conn[i].
205 connection.lcl_ip.ip6.as_u64[0] ==
206 ip6_hdr->dst_address.as_u64[0]
207 && tm->connections[thread_index]->sub_conn[i].
208 connection.lcl_ip.ip6.as_u64[1] ==
209 ip6_hdr->dst_address.as_u64[1])
210 && (tm->connections[thread_index]->sub_conn[i].
211 connection.rmt_ip.ip6.as_u64[0] ==
212 ip6_hdr->src_address.as_u64[0]
213 && tm->connections[thread_index]->
214 sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
215 ip6_hdr->src_address.as_u64[1]))
216 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100217 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100218 &tm->connections[thread_index]->sub_conn[i].connection;
219 break;
220 }
221 }
222 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100223 ASSERT (trans_conn != 0);
224 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100225 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100226 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100227 return sctp_conn;
228}
229
230typedef struct
231{
232 sctp_header_t sctp_header;
233 sctp_connection_t sctp_connection;
234} sctp_rx_trace_t;
235
236#define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
237 : SCTP_NEXT_SCTP6_OUTPUT)
238
Marco Varlesefae40392018-02-14 15:38:35 +0100239#define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
240 : SCTP_NEXT_DROP6)
Marco Varlese191a5942017-10-30 18:17:21 +0100241
Filip Tehlara5a458f2019-03-05 06:50:19 -0800242static void
Marco Varlese191a5942017-10-30 18:17:21 +0100243sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
244 sctp_connection_t * sctp_conn,
245 sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
246 u8 is_ip4)
247{
248 if (sctp_conn)
249 {
Dave Barach178cf492018-11-13 16:34:13 -0500250 clib_memcpy_fast (&rx_trace->sctp_connection, sctp_conn,
251 sizeof (rx_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +0100252 }
253 else
254 {
255 sctp_hdr = sctp_buffer_hdr (b0);
256 }
Dave Barach178cf492018-11-13 16:34:13 -0500257 clib_memcpy_fast (&rx_trace->sctp_header, sctp_hdr,
258 sizeof (rx_trace->sctp_header));
Marco Varlese191a5942017-10-30 18:17:21 +0100259}
260
261always_inline u16
262sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
263 int is_ip4)
264{
265 u16 sctp_implied_packet_length = 0;
266
267 if (is_ip4)
268 sctp_implied_packet_length =
269 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
270 else
271 sctp_implied_packet_length =
272 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
273
274 return sctp_implied_packet_length;
275}
276
277always_inline u8
278sctp_is_bundling (u16 sctp_implied_length,
279 sctp_chunks_common_hdr_t * sctp_common_hdr)
280{
281 if (sctp_implied_length !=
282 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
283 return 1;
284 return 0;
285}
286
287always_inline u16
Marco Varlese200fa322018-02-26 16:33:54 +0100288sctp_handle_operation_err (sctp_header_t * sctp_hdr,
289 sctp_connection_t * sctp_conn, u8 idx,
290 vlib_buffer_t * b, u16 * next0)
291{
292 sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
293
294 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
295 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
296 {
297 return SCTP_ERROR_INVALID_TAG;
298 }
299
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100300 if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
301 STALE_COOKIE_ERROR)
Marco Varlese200fa322018-02-26 16:33:54 +0100302 {
303 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
304 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
305 else
306 {
307 sctp_connection_cleanup (sctp_conn);
308
Florin Coras5a2ec8f2018-12-27 11:53:11 -0800309 session_transport_closing_notify (&sctp_conn->
Marco Varlese200fa322018-02-26 16:33:54 +0100310 sub_conn[idx].connection);
311 }
312 }
313
314 return SCTP_ERROR_NONE;
315}
316
317always_inline u16
Marco Varlese191a5942017-10-30 18:17:21 +0100318sctp_handle_init (sctp_header_t * sctp_hdr,
319 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
320 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
321 u16 sctp_implied_length)
322{
323 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +0200324 ip4_address_t ip4_addr;
325 ip6_address_t ip6_addr;
326 u8 add_ip4 = 0;
327 u8 add_ip6 = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100328 char hostname[FQDN_MAX_LENGTH];
329
330 /* Check the current state of the connection
331 *
332 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
333 * in the code below and by the "sctp_prepare_initack_chunk" function.
334 * However, for debugging purposes it is nice to have a message printed out
335 * for these corner-case scenarios.
336 */
337 if (sctp_conn->state != SCTP_STATE_CLOSED)
338 { /* UNEXPECTED scenario */
339 switch (sctp_conn->state)
340 {
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100341 case SCTP_STATE_COOKIE_WAIT:
Marco Varlese191a5942017-10-30 18:17:21 +0100342 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100343 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100344 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200345 b0, &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100346 return SCTP_ERROR_NONE;
347 case SCTP_STATE_COOKIE_ECHOED:
348 case SCTP_STATE_SHUTDOWN_ACK_SENT:
Marco Varlese191a5942017-10-30 18:17:21 +0100349 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100350 if (sctp_conn->forming_association_changed == 0)
351 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100352 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200353 b0, &ip4_addr,
354 &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100355 else
356 sctp_prepare_abort_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100357 SCTP_PRIMARY_PATH_IDX, b0,
Marco Varlese216c35b2018-04-17 16:41:51 +0200358 &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100359 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100360 }
361 }
362
363 if (sctp_hdr->verification_tag != 0x0)
364 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
365
366 /*
367 * It is not possible to bundle any other CHUNK with the INIT chunk
368 */
369 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
370 return SCTP_ERROR_BUNDLING_VIOLATION;
371
372 /* Save the INITIATE_TAG of the remote peer for this connection:
373 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
374 sctp_conn->remote_tag = init_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100375 sctp_conn->remote_initial_tsn =
376 clib_net_to_host_u32 (init_chunk->initial_tsn);
377 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
378 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
379 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
380 sctp_conn->remote_initial_tsn);
381
Marco Varlese9e09ff32018-03-05 12:31:45 +0100382 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100383 /*
384 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
385 * optional parameters have been sent with the INIT chunk and we need to parse them.
386 */
387 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
388 if (length > sizeof (sctp_init_chunk_t))
389 {
390 /* There are optional parameters in the INIT chunk */
391 u16 pointer_offset = sizeof (sctp_init_chunk_t);
392 while (pointer_offset < length)
393 {
394 sctp_opt_params_hdr_t *opt_params_hdr =
395 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
396
397 switch (clib_net_to_host_u16 (opt_params_hdr->type))
398 {
399 case SCTP_IPV4_ADDRESS_TYPE:
400 {
401 sctp_ipv4_addr_param_t *ipv4 =
402 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500403 clib_memcpy_fast (&ip4_addr, &ipv4->address,
404 sizeof (ip4_address_t));
Marco Varlese191a5942017-10-30 18:17:21 +0100405
Marco Varlese216c35b2018-04-17 16:41:51 +0200406 if (sctp_sub_connection_add_ip4 (vlib_get_main (),
407 &sctp_conn->sub_conn
408 [SCTP_PRIMARY_PATH_IDX].connection.
409 lcl_ip.ip4,
410 &ipv4->address) ==
411 SCTP_ERROR_NONE)
412 add_ip4 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100413
414 break;
415 }
416 case SCTP_IPV6_ADDRESS_TYPE:
417 {
418 sctp_ipv6_addr_param_t *ipv6 =
419 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500420 clib_memcpy_fast (&ip6_addr, &ipv6->address,
421 sizeof (ip6_address_t));
Marco Varlese191a5942017-10-30 18:17:21 +0100422
Marco Varlese216c35b2018-04-17 16:41:51 +0200423 if (sctp_sub_connection_add_ip6 (vlib_get_main (),
424 &sctp_conn->sub_conn
425 [SCTP_PRIMARY_PATH_IDX].connection.
426 lcl_ip.ip6,
427 &ipv6->address) ==
428 SCTP_ERROR_NONE)
429 add_ip6 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100430
431 break;
432 }
433 case SCTP_COOKIE_PRESERVATIVE_TYPE:
434 {
435 sctp_cookie_preservative_param_t *cookie_pres =
436 (sctp_cookie_preservative_param_t *) opt_params_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100437 sctp_conn->peer_cookie_life_span_increment =
438 cookie_pres->life_span_inc;
Marco Varlese191a5942017-10-30 18:17:21 +0100439 break;
440 }
441 case SCTP_HOSTNAME_ADDRESS_TYPE:
442 {
443 sctp_hostname_param_t *hostname_addr =
444 (sctp_hostname_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500445 clib_memcpy_fast (hostname, hostname_addr->hostname,
446 FQDN_MAX_LENGTH);
Marco Varlese191a5942017-10-30 18:17:21 +0100447 break;
448 }
449 case SCTP_SUPPORTED_ADDRESS_TYPES:
450 {
451 /* TODO */
452 break;
453 }
454 }
455 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
456 }
457 }
458
459 /* Reuse buffer to make init-ack and send */
Marco Varlese216c35b2018-04-17 16:41:51 +0200460 sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
461 add_ip4, &ip6_addr, add_ip6);
Marco Varlese191a5942017-10-30 18:17:21 +0100462 return SCTP_ERROR_NONE;
463}
464
465always_inline u16
466sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
467 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
468 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
469 u16 sctp_implied_length)
470{
471 sctp_init_ack_chunk_t *init_ack_chunk =
472 (sctp_init_ack_chunk_t *) (sctp_hdr);
473
474 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
475 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
476 {
477 return SCTP_ERROR_INVALID_TAG;
478 }
479
480 /*
481 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
482 */
483 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
484 return SCTP_ERROR_BUNDLING_VIOLATION;
485
486 return SCTP_ERROR_NONE;
487}
488
489always_inline u16
490sctp_handle_init_ack (sctp_header_t * sctp_hdr,
491 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100492 sctp_connection_t * sctp_conn, u8 idx,
493 vlib_buffer_t * b0, u16 sctp_implied_length)
Marco Varlese191a5942017-10-30 18:17:21 +0100494{
495 sctp_init_ack_chunk_t *init_ack_chunk =
496 (sctp_init_ack_chunk_t *) (sctp_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100497
498 char hostname[FQDN_MAX_LENGTH];
499
500 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
501 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
502 {
503 return SCTP_ERROR_INVALID_TAG;
504 }
505
506 /*
507 * It is not possible to bundle any other CHUNK with the INIT chunk
508 */
509 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
510 return SCTP_ERROR_BUNDLING_VIOLATION;
511
Marco Varlese9e09ff32018-03-05 12:31:45 +0100512 /* Stop the T1_INIT timer */
513 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
514
Marco Varlese21c8baf2018-02-02 17:17:51 +0100515 sctp_calculate_rto (sctp_conn, idx);
516
Marco Varlese191a5942017-10-30 18:17:21 +0100517 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
518 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100519 sctp_conn->remote_initial_tsn =
520 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
521 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
522 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
523 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
524 sctp_conn->remote_initial_tsn);
Marco Varlese9e09ff32018-03-05 12:31:45 +0100525 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100526
527 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
528
529 if (length > sizeof (sctp_init_ack_chunk_t))
530 /*
531 * There are optional parameters in the INIT ACK chunk
532 */
533 {
534 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
535
536 while (pointer_offset < length)
537 {
538 sctp_opt_params_hdr_t *opt_params_hdr =
539 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
540 pointer_offset);
541
542 switch (clib_net_to_host_u16 (opt_params_hdr->type))
543 {
544 case SCTP_IPV4_ADDRESS_TYPE:
545 {
546 sctp_ipv4_addr_param_t *ipv4 =
547 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100548
Marco Varlese3c6a9762018-03-01 11:19:59 +0100549 sctp_sub_connection_add_ip4 (vlib_get_main (),
550 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100551 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100552 lcl_ip.ip4, &ipv4->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100553
554 break;
555 }
556 case SCTP_IPV6_ADDRESS_TYPE:
557 {
558 sctp_ipv6_addr_param_t *ipv6 =
559 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100560
Marco Varlese3c6a9762018-03-01 11:19:59 +0100561 sctp_sub_connection_add_ip6 (vlib_get_main (),
562 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100563 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100564 lcl_ip.ip6, &ipv6->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100565
566 break;
567 }
568 case SCTP_STATE_COOKIE_TYPE:
569 {
570 sctp_state_cookie_param_t *state_cookie_param =
571 (sctp_state_cookie_param_t *) opt_params_hdr;
572
Dave Barach178cf492018-11-13 16:34:13 -0500573 clib_memcpy_fast (&(sctp_conn->cookie_param),
574 state_cookie_param,
575 sizeof (sctp_state_cookie_param_t));
Marco Varlese63777e52018-04-18 08:50:57 +0200576
Marco Varlese191a5942017-10-30 18:17:21 +0100577 break;
578 }
579 case SCTP_HOSTNAME_ADDRESS_TYPE:
580 {
581 sctp_hostname_param_t *hostname_addr =
582 (sctp_hostname_param_t *) opt_params_hdr;
Dave Barach178cf492018-11-13 16:34:13 -0500583 clib_memcpy_fast (hostname, hostname_addr->hostname,
584 FQDN_MAX_LENGTH);
Marco Varlese191a5942017-10-30 18:17:21 +0100585 break;
586 }
587 case SCTP_UNRECOGNIZED_TYPE:
588 {
589 break;
590 }
591 }
592 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
593 /* This indicates something really bad happened */
594 if (increment == 0)
595 {
596 return SCTP_ERROR_INVALID_TAG;
597 }
598 pointer_offset += increment;
599 }
600 }
601
Marco Varlese9e09ff32018-03-05 12:31:45 +0100602 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100603
604 /* Start the T1_COOKIE timer */
Marco Varlese54432f82018-02-15 17:01:56 +0100605 sctp_timer_set (sctp_conn, idx,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100606 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
Marco Varlese191a5942017-10-30 18:17:21 +0100607
608 return SCTP_ERROR_NONE;
609}
610
Marco Varlese91389ac2018-01-31 11:00:01 +0100611/** Enqueue data out-of-order for delivery to application */
612always_inline int
613sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
614 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
615{
616 int written, error = SCTP_ERROR_ENQUEUED;
617
618 written =
619 session_enqueue_stream_connection (&sctp_conn->
620 sub_conn[conn_idx].connection, b, 0,
621 1 /* queue event */ ,
622 0);
623
624 /* Update next_tsn_expected */
625 if (PREDICT_TRUE (written == data_len))
626 {
627 sctp_conn->next_tsn_expected += written;
628
629 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
630 sctp_conn->sub_conn[conn_idx].connection.c_index,
631 written, data_len);
632 }
633 /* If more data written than expected, account for out-of-order bytes. */
634 else if (written > data_len)
635 {
636 sctp_conn->next_tsn_expected += written;
637
638 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
639 sctp_conn->sub_conn[conn_idx].connection.c_index,
640 written, data_len);
641 }
642 else if (written > 0)
643 {
644 /* We've written something but FIFO is probably full now */
645 sctp_conn->next_tsn_expected += written;
646
647 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
648
649 SCTP_ADV_DBG
650 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
651 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
652 }
653 else
654 {
655 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
656 sctp_conn->sub_conn[conn_idx].connection.c_index);
657
658 return SCTP_ERROR_FIFO_FULL;
659 }
660
661 /* TODO: Update out_of_order_map & SACK list */
662
663 return error;
664}
665
Marco Varlese191a5942017-10-30 18:17:21 +0100666/** Enqueue data for delivery to application */
667always_inline int
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100668sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100669 u16 data_len, u8 conn_idx)
670{
671 int written, error = SCTP_ERROR_ENQUEUED;
672
673 written =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100674 session_enqueue_stream_connection (&sctp_conn->
675 sub_conn[conn_idx].connection, b, 0,
676 1 /* queue event */ ,
677 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100678
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100679 /* Update next_tsn_expected */
Marco Varlese191a5942017-10-30 18:17:21 +0100680 if (PREDICT_TRUE (written == data_len))
681 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100682 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100683
684 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100685 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100686 written, data_len);
687 }
688 /* If more data written than expected, account for out-of-order bytes. */
689 else if (written > data_len)
690 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100691 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100692
693 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100694 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100695 written, data_len);
696 }
697 else if (written > 0)
698 {
699 /* We've written something but FIFO is probably full now */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100700 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100701
702 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
703
704 SCTP_ADV_DBG
705 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100706 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
Marco Varlese191a5942017-10-30 18:17:21 +0100707 }
708 else
709 {
710 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100711 sctp_conn->sub_conn[conn_idx].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100712
713 return SCTP_ERROR_FIFO_FULL;
714 }
715
716 return error;
717}
718
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100719always_inline u8
Marco Varlese54432f82018-02-15 17:01:56 +0100720sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100721{
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100722 if (sctp_conn->conn_config.never_delay_sack)
723 {
724 SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
725 return 0;
726 }
727
Marco Varlese9e09ff32018-03-05 12:31:45 +0100728 /* Section 4.4 of the RFC4960 */
729 if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
730 {
731 SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
732 sctp_state_to_string (sctp_conn->state));
733 return 0;
734 }
735
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100736 if (is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100737 {
738 SCTP_CONN_TRACKING_DBG
739 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
740 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100741 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100742 }
743
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100744 sctp_conn->ack_state += 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100745 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
746 {
747 SCTP_CONN_TRACKING_DBG
748 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
749 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100750 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100751 }
752
Marco Varlesea38783e2018-02-13 12:38:52 +0100753 return 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100754}
755
Marco Varlese91389ac2018-01-31 11:00:01 +0100756always_inline void
757sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
758 u8 * gapping)
759{
760 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
761 {
762 SCTP_CONN_TRACKING_DBG
763 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100764 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
Marco Varlese91389ac2018-01-31 11:00:01 +0100765 sctp_conn->next_tsn_expected, tsn,
766 sctp_conn->next_tsn_expected - tsn);
767
768 *gapping = 1;
769 }
770}
771
Marco Varlese191a5942017-10-30 18:17:21 +0100772always_inline u16
773sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100774 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100775 u16 * next0)
776{
777 u32 error = 0, n_data_bytes;
Marco Varlese91389ac2018-01-31 11:00:01 +0100778 u8 is_gapping = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100779
780 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
781 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
782 {
Marco Varlese87971682018-10-04 15:46:05 +0200783 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
784 sctp_conn->sub_conn[idx].enqueue_state = SCTP_ERROR_INVALID_TAG;
785 return sctp_conn->sub_conn[idx].enqueue_state;
Marco Varlese191a5942017-10-30 18:17:21 +0100786 }
787
788 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
789 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100790
791 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100792
793 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
Marco Varlese87971682018-10-04 15:46:05 +0200794 u32 chunk_len = vnet_sctp_get_chunk_length (&sctp_data_chunk->chunk_hdr) -
795 (sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_header_t));
796
797 ASSERT (vnet_buffer (b)->sctp.data_len);
798 ASSERT (chunk_len);
799
800 /* Padding was added: see RFC 4096 section 3.3.1 */
801 if (vnet_buffer (b)->sctp.data_len > chunk_len)
802 {
803 /* Let's change the data_len to the right amount calculated here now.
804 * We cannot do that in the generic sctp46_input_dispatcher node since
805 * that is common to all CHUNKS handling.
806 */
807 vnet_buffer (b)->sctp.data_len = chunk_len;
808 /* We need to change b->current_length so that downstream calls to
809 * session_enqueue_stream_connection (called by sctp_session_enqueue_data)
810 * push the correct amount of data to be enqueued.
811 */
812 b->current_length = chunk_len;
813 }
Marco Varlese191a5942017-10-30 18:17:21 +0100814 n_data_bytes = vnet_buffer (b)->sctp.data_len;
Marco Varlese191a5942017-10-30 18:17:21 +0100815
Marco Varlese91389ac2018-01-31 11:00:01 +0100816 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100817
818 sctp_conn->last_rcvd_tsn = tsn;
819
Marco Varlese191a5942017-10-30 18:17:21 +0100820 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
821
Marco Varlese91389ac2018-01-31 11:00:01 +0100822 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
823 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
824
825 if (bbit == 1 && ebit == 1) /* Unfragmented message */
826 {
827 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
828 * segments can be enqueued after fifo tail offset changes. */
Marco Varlese54432f82018-02-15 17:01:56 +0100829 if (PREDICT_FALSE (is_gapping == 1))
830 error =
831 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
832 else
833 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
Marco Varlese91389ac2018-01-31 11:00:01 +0100834 }
835 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
836 {
837 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
838 }
839 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
840 {
841 if (PREDICT_FALSE (is_gapping == 1))
842 error =
843 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
844 else
845 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
846 }
847 else /* Middle piece of a fragmented user message */
848 {
849 if (PREDICT_FALSE (is_gapping == 1))
850 error =
851 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
852 else
853 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
854 }
855 sctp_conn->last_rcvd_tsn = tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100856
Marco Varlese91389ac2018-01-31 11:00:01 +0100857 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
858
Marco Varlese54432f82018-02-15 17:01:56 +0100859 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100860 {
861 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
862 sctp_prepare_sack_chunk (sctp_conn, idx, b);
863 }
864 else
865 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese54432f82018-02-15 17:01:56 +0100866
867 sctp_conn->sub_conn[idx].enqueue_state = error;
Marco Varlese191a5942017-10-30 18:17:21 +0100868
869 return error;
870}
871
872always_inline u16
873sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
874 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100875 sctp_connection_t * sctp_conn, u8 idx,
876 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100877{
Marco Varlese93826732018-09-27 16:43:57 +0200878 u64 now = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +0100879
Marco Varlese91389ac2018-01-31 11:00:01 +0100880 sctp_cookie_echo_chunk_t *cookie_echo =
881 (sctp_cookie_echo_chunk_t *) sctp_hdr;
882
Marco Varlese191a5942017-10-30 18:17:21 +0100883 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
884 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
885 {
Marco Varlese87971682018-10-04 15:46:05 +0200886 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100887 return SCTP_ERROR_INVALID_TAG;
888 }
889
Marco Varlese21c8baf2018-02-02 17:17:51 +0100890 sctp_calculate_rto (sctp_conn, idx);
891
Marco Varlese93826732018-09-27 16:43:57 +0200892 u64 creation_time =
893 clib_net_to_host_u64 (cookie_echo->cookie.creation_time);
894 u64 cookie_lifespan =
Marco Varlese91389ac2018-01-31 11:00:01 +0100895 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
Marco Varlese93826732018-09-27 16:43:57 +0200896
Marco Varlese91389ac2018-01-31 11:00:01 +0100897 if (now > creation_time + cookie_lifespan)
898 {
899 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
900 now, creation_time, cookie_lifespan);
901 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
902 }
903
Marco Varlese54432f82018-02-15 17:01:56 +0100904 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +0100905
906 /* Change state */
907 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100908 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
Marco Varlesebe2251b2018-02-07 12:22:41 +0100909 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100910
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100911 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
912 sctp_conn->sub_conn[idx].RTO);
913
Florin Corasa27a46e2019-02-18 13:02:28 -0800914 session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese15cc6a82018-02-21 12:39:52 +0100915
Marco Varlese191a5942017-10-30 18:17:21 +0100916 return SCTP_ERROR_NONE;
917
918}
919
920always_inline u16
921sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
922 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100923 sctp_connection_t * sctp_conn, u8 idx,
924 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100925{
Marco Varlese191a5942017-10-30 18:17:21 +0100926 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
927 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
928 {
Marco Varlese87971682018-10-04 15:46:05 +0200929 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100930 return SCTP_ERROR_INVALID_TAG;
931 }
932
Marco Varlese21c8baf2018-02-02 17:17:51 +0100933 sctp_calculate_rto (sctp_conn, idx);
934
Marco Varlese191a5942017-10-30 18:17:21 +0100935 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
936 /* Change state */
937 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100938 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
939
Marco Varlesefae40392018-02-14 15:38:35 +0100940 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100941
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100942 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
943 sctp_conn->sub_conn[idx].RTO);
944
Florin Corasa27a46e2019-02-18 13:02:28 -0800945 session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese15cc6a82018-02-21 12:39:52 +0100946
Marco Varlese191a5942017-10-30 18:17:21 +0100947 return SCTP_ERROR_NONE;
948
949}
950
951always_inline uword
952sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
953 vlib_frame_t * from_frame, int is_ip4)
954{
955 sctp_main_t *tm = vnet_get_sctp_main ();
956
957 u32 n_left_from, next_index, *from, *to_next;
958 u32 my_thread_index = vm->thread_index;
959
960 from = vlib_frame_vector_args (from_frame);
961 n_left_from = from_frame->n_vectors;
962
963 next_index = node->cached_next_index;
964
965 while (n_left_from > 0)
966 {
967 u32 n_left_to_next;
968
969 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
970
971 while (n_left_from > 0 && n_left_to_next > 0)
972 {
973 u32 bi0;
974 vlib_buffer_t *b0;
975 sctp_header_t *sctp_hdr = 0;
976 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
977 ip4_header_t *ip4_hdr = 0;
978 ip6_header_t *ip6_hdr = 0;
979 sctp_connection_t *sctp_conn, *new_sctp_conn;
980 u16 sctp_implied_length = 0;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100981 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100982 u8 idx;
983
984 bi0 = from[0];
985 to_next[0] = bi0;
986 from += 1;
987 to_next += 1;
988 n_left_from -= 1;
989 n_left_to_next -= 1;
990
991 b0 = vlib_get_buffer (vm, bi0);
992
993 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
994 * will come from the half-open connections pool.
995 */
996 sctp_conn =
997 sctp_half_open_connection_get (vnet_buffer (b0)->
998 sctp.connection_index);
999
1000 if (PREDICT_FALSE (sctp_conn == 0))
1001 {
Marco Varlese191a5942017-10-30 18:17:21 +01001002 SCTP_ADV_DBG
1003 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1004 error0 = SCTP_ERROR_INVALID_CONNECTION;
1005 goto drop;
1006 }
1007 if (is_ip4)
1008 {
1009 ip4_hdr = vlib_buffer_get_current (b0);
1010 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001011 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001012 }
1013 else
1014 {
1015 ip6_hdr = vlib_buffer_get_current (b0);
1016 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001017 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001018 }
Marco Varlese191a5942017-10-30 18:17:21 +01001019
Marco Varlese04e5d642018-02-23 17:43:06 +01001020 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001021 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1022
Marco Varlese191a5942017-10-30 18:17:21 +01001023 sctp_chunk_hdr =
1024 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1025
1026 sctp_implied_length =
1027 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1028
1029 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1030
1031 switch (chunk_type)
1032 {
1033 case INIT_ACK:
1034 error0 =
1035 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1036 b0, sctp_implied_length);
1037
1038 if (error0 == SCTP_ERROR_NONE)
1039 {
1040 pool_get (tm->connections[my_thread_index], new_sctp_conn);
Dave Barach178cf492018-11-13 16:34:13 -05001041 clib_memcpy_fast (new_sctp_conn, sctp_conn,
1042 sizeof (*new_sctp_conn));
Marco Varlese191a5942017-10-30 18:17:21 +01001043 new_sctp_conn->sub_conn[idx].c_c_index =
1044 new_sctp_conn - tm->connections[my_thread_index];
1045 new_sctp_conn->sub_conn[idx].c_thread_index =
1046 my_thread_index;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001047 new_sctp_conn->sub_conn[idx].PMTU =
1048 sctp_conn->sub_conn[idx].PMTU;
Marco Varlese04e5d642018-02-23 17:43:06 +01001049 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001050
1051 if (sctp_half_open_connection_cleanup (sctp_conn))
1052 {
1053 SCTP_DBG
1054 ("Cannot cleanup half-open connection; not the owning thread");
1055 }
1056
1057 sctp_connection_timers_init (new_sctp_conn);
1058
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001059 sctp_init_cwnd (new_sctp_conn);
1060
Marco Varlese191a5942017-10-30 18:17:21 +01001061 error0 =
1062 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +01001063 new_sctp_conn, idx, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001064 sctp_implied_length);
1065
Marco Varlese191a5942017-10-30 18:17:21 +01001066 if (session_stream_connect_notify
1067 (&new_sctp_conn->sub_conn[idx].connection, 0))
1068 {
1069 SCTP_DBG
1070 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1071 new_sctp_conn->sub_conn[idx].connection.c_index);
1072 sctp_connection_cleanup (new_sctp_conn);
1073 goto drop;
1074 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001075 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001076 }
Marco Varlese191a5942017-10-30 18:17:21 +01001077 break;
1078
Marco Varlese200fa322018-02-26 16:33:54 +01001079 case OPERATION_ERROR:
1080 error0 =
1081 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1082 &next0);
1083 break;
1084
Marco Varlese191a5942017-10-30 18:17:21 +01001085 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1086 * are handled by the input-dispatcher function using the table-lookup
1087 * hence we should never get to the "default" case below.
1088 */
1089 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001090 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001091 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001092 goto drop;
1093 }
1094
1095 if (error0 != SCTP_ERROR_NONE)
1096 {
1097 clib_warning ("error while parsing chunk");
1098 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001099 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001100 goto drop;
1101 }
1102
1103 drop:
1104 b0->error = node->errors[error0];
1105 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1106 {
1107 sctp_rx_trace_t *t0 =
1108 vlib_add_trace (vm, node, b0, sizeof (*t0));
1109 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1110 }
1111
1112 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1113 n_left_to_next, bi0, next0);
1114 }
1115
1116 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1117 }
1118 return from_frame->n_vectors;
1119}
1120
Filip Tehlara5a458f2019-03-05 06:50:19 -08001121VLIB_NODE_FN (sctp4_rcv_phase_node) (vlib_main_t * vm,
1122 vlib_node_runtime_t * node,
1123 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001124{
1125 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1126}
1127
Filip Tehlara5a458f2019-03-05 06:50:19 -08001128VLIB_NODE_FN (sctp6_init_phase_node) (vlib_main_t * vm,
1129 vlib_node_runtime_t * node,
1130 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001131{
1132 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1133}
1134
Filip Tehlara5a458f2019-03-05 06:50:19 -08001135static u8 *
Marco Varlese191a5942017-10-30 18:17:21 +01001136format_sctp_rx_trace_short (u8 * s, va_list * args)
1137{
1138 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1139 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1140 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1141
1142 s = format (s, "%d -> %d (%U)",
1143 clib_net_to_host_u16 (t->sctp_header.src_port),
1144 clib_net_to_host_u16 (t->sctp_header.dst_port),
1145 format_sctp_state, t->sctp_connection.state);
1146
1147 return s;
1148}
1149
1150/* *INDENT-OFF* */
1151VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1152{
Marco Varlese191a5942017-10-30 18:17:21 +01001153 .name = "sctp4-rcv",
1154 /* Takes a vector of packets. */
1155 .vector_size = sizeof (u32),
1156 .n_errors = SCTP_N_ERROR,
1157 .error_strings = sctp_error_strings,
1158 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1159 .next_nodes =
1160 {
1161#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1162 foreach_sctp_state_next
1163#undef _
1164 },
1165 .format_trace = format_sctp_rx_trace_short,
1166};
1167/* *INDENT-ON* */
1168
Marco Varlese191a5942017-10-30 18:17:21 +01001169/* *INDENT-OFF* */
1170VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1171{
Marco Varlese191a5942017-10-30 18:17:21 +01001172 .name = "sctp6-rcv",
1173 /* Takes a vector of packets. */
1174 .vector_size = sizeof (u32),
1175 .n_errors = SCTP_N_ERROR,
1176 .error_strings = sctp_error_strings,
1177 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1178 .next_nodes =
1179 {
1180#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1181 foreach_sctp_state_next
1182#undef _
1183 },
1184 .format_trace = format_sctp_rx_trace_short,
1185};
1186/* *INDENT-ON* */
1187
Marco Varlese191a5942017-10-30 18:17:21 +01001188always_inline u16
1189sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1190 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001191 sctp_connection_t * sctp_conn, u8 idx,
1192 vlib_buffer_t * b0, u16 sctp_implied_length,
1193 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001194{
1195 sctp_shutdown_association_chunk_t *shutdown_chunk =
1196 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1197
1198 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1199 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1200 {
Marco Varlese87971682018-10-04 15:46:05 +02001201 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001202 return SCTP_ERROR_INVALID_TAG;
1203 }
1204
1205 /*
1206 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1207 */
1208 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1209 return SCTP_ERROR_BUNDLING_VIOLATION;
1210
1211 switch (sctp_conn->state)
1212 {
1213 case SCTP_STATE_ESTABLISHED:
1214 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1215 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
Marco Varlese54432f82018-02-15 17:01:56 +01001216 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001217 break;
1218
1219 case SCTP_STATE_SHUTDOWN_SENT:
Marco Varlese54432f82018-02-15 17:01:56 +01001220 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001221 break;
1222 }
1223
Marco Varlesebe2251b2018-02-07 12:22:41 +01001224 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1225
Marco Varlese191a5942017-10-30 18:17:21 +01001226 return SCTP_ERROR_NONE;
1227}
1228
1229always_inline u16
1230sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1231 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001232 sctp_connection_t * sctp_conn, u8 idx,
1233 vlib_buffer_t * b0, u16 sctp_implied_length,
1234 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001235{
1236 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1237 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1238
1239 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1240 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1241 {
Marco Varlese87971682018-10-04 15:46:05 +02001242 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001243 return SCTP_ERROR_INVALID_TAG;
1244 }
1245
1246 /*
1247 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1248 */
1249 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1250 return SCTP_ERROR_BUNDLING_VIOLATION;
1251
1252 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1253 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1254 * - STOP T2_SHUTDOWN timer
1255 * - SEND SHUTDOWN_COMPLETE chunk
1256 */
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001257 sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
Marco Varlesea38783e2018-02-13 12:38:52 +01001258
Marco Varlese54432f82018-02-15 17:01:56 +01001259 sctp_send_shutdown_complete (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001260
Marco Varlesebe2251b2018-02-07 12:22:41 +01001261 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1262
Marco Varlese191a5942017-10-30 18:17:21 +01001263 return SCTP_ERROR_NONE;
1264}
1265
1266always_inline u16
1267sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1268 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001269 sctp_connection_t * sctp_conn, u8 idx,
1270 vlib_buffer_t * b0, u16 sctp_implied_length,
1271 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001272{
1273 sctp_shutdown_complete_chunk_t *shutdown_complete =
1274 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1275
1276 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1277 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1278 {
Marco Varlese87971682018-10-04 15:46:05 +02001279 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001280 return SCTP_ERROR_INVALID_TAG;
1281 }
1282
1283 /*
1284 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1285 */
1286 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1287 return SCTP_ERROR_BUNDLING_VIOLATION;
1288
Marco Varlesef3ab4892018-02-19 15:23:13 +01001289 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1290
Florin Coras5a2ec8f2018-12-27 11:53:11 -08001291 session_transport_closing_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese191a5942017-10-30 18:17:21 +01001292
1293 sctp_conn->state = SCTP_STATE_CLOSED;
1294
Marco Varlesefae40392018-02-14 15:38:35 +01001295 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001296
Marco Varlese191a5942017-10-30 18:17:21 +01001297 return SCTP_ERROR_NONE;
1298}
1299
1300always_inline uword
1301sctp46_shutdown_phase_inline (vlib_main_t * vm,
1302 vlib_node_runtime_t * node,
1303 vlib_frame_t * from_frame, int is_ip4)
1304{
1305 u32 n_left_from, next_index, *from, *to_next;
1306 u32 my_thread_index = vm->thread_index;
1307
1308 from = vlib_frame_vector_args (from_frame);
1309 n_left_from = from_frame->n_vectors;
1310
1311 next_index = node->cached_next_index;
1312
1313 while (n_left_from > 0)
1314 {
1315 u32 n_left_to_next;
1316
1317 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1318
1319 while (n_left_from > 0 && n_left_to_next > 0)
1320 {
1321 u32 bi0;
1322 vlib_buffer_t *b0;
1323 sctp_rx_trace_t *sctp_trace;
1324 sctp_header_t *sctp_hdr = 0;
1325 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1326 ip4_header_t *ip4_hdr = 0;
1327 ip6_header_t *ip6_hdr = 0;
1328 sctp_connection_t *sctp_conn;
1329 u16 sctp_implied_length = 0;
1330 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
Marco Varlese54432f82018-02-15 17:01:56 +01001331 u8 idx = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001332
1333 bi0 = from[0];
1334 to_next[0] = bi0;
1335 from += 1;
1336 to_next += 1;
1337 n_left_from -= 1;
1338 n_left_to_next -= 1;
1339
1340 b0 = vlib_get_buffer (vm, bi0);
1341 sctp_conn =
1342 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1343 my_thread_index);
1344
1345 if (PREDICT_FALSE (sctp_conn == 0))
1346 {
1347 SCTP_DBG
1348 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1349 error0 = SCTP_ERROR_INVALID_CONNECTION;
1350 goto drop;
1351 }
1352
1353 if (is_ip4)
1354 {
1355 ip4_hdr = vlib_buffer_get_current (b0);
1356 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001357 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001358 }
1359 else
1360 {
1361 ip6_hdr = vlib_buffer_get_current (b0);
1362 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001363 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001364 }
1365
1366 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1367 sctp_chunk_hdr = &full_hdr->common_hdr;
1368
1369 sctp_implied_length =
1370 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1371
Marco Varlesebe2251b2018-02-07 12:22:41 +01001372 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1373 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001374 {
1375 case SHUTDOWN:
1376 error0 =
Marco Varlesebe2251b2018-02-07 12:22:41 +01001377 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1378 idx, b0, sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001379 break;
1380
1381 case SHUTDOWN_ACK:
1382 error0 =
1383 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001384 idx, b0, sctp_implied_length,
1385 &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001386 break;
1387
1388 case SHUTDOWN_COMPLETE:
1389 error0 =
1390 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001391 sctp_conn, idx, b0,
1392 sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001393
1394 sctp_connection_cleanup (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001395 break;
1396
1397 /*
1398 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1399 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1400 */
1401 case DATA:
1402 error0 =
1403 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001404 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001405 break;
1406
Marco Varlese200fa322018-02-26 16:33:54 +01001407 case OPERATION_ERROR:
1408 error0 =
1409 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1410 &next0);
1411 break;
1412
Marco Varlese8c5f67f2018-02-27 09:38:31 +01001413 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1414 sctp_prepare_operation_error (sctp_conn, idx, b0,
1415 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1416 error0 = SCTP_ERROR_NONE;
1417 next0 = sctp_next_output (is_ip4);
1418 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001419 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1420 * are handled by the input-dispatcher function using the table-lookup
1421 * hence we should never get to the "default" case below.
1422 */
1423 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001424 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001425 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001426 goto drop;
1427 }
1428
1429 if (error0 != SCTP_ERROR_NONE)
1430 {
1431 clib_warning ("error while parsing chunk");
1432 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001433 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001434 goto drop;
1435 }
1436
1437 drop:
1438 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1439 {
1440 sctp_trace =
1441 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
Marco Varlesef429a932018-02-06 17:31:06 +01001442
1443 if (sctp_hdr != NULL)
Dave Barach178cf492018-11-13 16:34:13 -05001444 clib_memcpy_fast (&sctp_trace->sctp_header, sctp_hdr,
1445 sizeof (sctp_trace->sctp_header));
Marco Varlesef429a932018-02-06 17:31:06 +01001446
1447 if (sctp_conn != NULL)
Dave Barach178cf492018-11-13 16:34:13 -05001448 clib_memcpy_fast (&sctp_trace->sctp_connection, sctp_conn,
1449 sizeof (sctp_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001450 }
1451
1452 b0->error = node->errors[error0];
1453
1454 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1455 n_left_to_next, bi0, next0);
1456 }
1457
1458 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1459 }
1460
1461 return from_frame->n_vectors;
1462
1463}
1464
Filip Tehlara5a458f2019-03-05 06:50:19 -08001465VLIB_NODE_FN (sctp4_shutdown_phase_node) (vlib_main_t * vm,
1466 vlib_node_runtime_t * node,
1467 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001468{
1469 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1470}
1471
Filip Tehlara5a458f2019-03-05 06:50:19 -08001472VLIB_NODE_FN (sctp6_shutdown_phase_node) (vlib_main_t * vm,
1473 vlib_node_runtime_t * node,
1474 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001475{
1476 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1477}
1478
1479/* *INDENT-OFF* */
1480VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1481{
Marco Varlese191a5942017-10-30 18:17:21 +01001482 .name = "sctp4-shutdown",
1483 /* Takes a vector of packets. */
1484 .vector_size = sizeof (u32),
1485 .n_errors = SCTP_N_ERROR,
1486 .error_strings = sctp_error_strings,
1487 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1488 .next_nodes =
1489 {
1490#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1491 foreach_sctp_state_next
1492#undef _
1493 },
1494 .format_trace = format_sctp_rx_trace_short,
1495};
1496/* *INDENT-ON* */
1497
Marco Varlese191a5942017-10-30 18:17:21 +01001498/* *INDENT-OFF* */
1499VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1500{
Marco Varlese191a5942017-10-30 18:17:21 +01001501 .name = "sctp6-shutdown",
1502 /* Takes a vector of packets. */
1503 .vector_size = sizeof (u32),
1504 .n_errors = SCTP_N_ERROR,
1505 .error_strings = sctp_error_strings,
1506 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1507 .next_nodes =
1508 {
1509#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1510 foreach_sctp_state_next
1511#undef _
1512 },
1513 .format_trace = format_sctp_rx_trace_short,
1514};
1515/* *INDENT-ON* */
1516
Marco Varlese191a5942017-10-30 18:17:21 +01001517always_inline u16
1518sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001519 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001520 u16 * next0)
1521{
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001522
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001523 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1524 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1525 {
Marco Varlese93826732018-09-27 16:43:57 +02001526 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001527 return SCTP_ERROR_INVALID_TAG;
1528 }
1529
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001530 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1531
Marco Varlese54432f82018-02-15 17:01:56 +01001532 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1533
Marco Varlesef3ab4892018-02-19 15:23:13 +01001534 /* Section 7.2.2; point (2) */
1535 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1536 sctp_conn->sub_conn[idx].partially_acked_bytes =
1537 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1538
1539 /* Section 7.2.2; point (5) */
1540 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1541 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1542
1543 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1544
Marco Varlese21c8baf2018-02-02 17:17:51 +01001545 sctp_calculate_rto (sctp_conn, idx);
1546
1547 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1548 sctp_conn->sub_conn[idx].RTO);
1549
1550 sctp_conn->sub_conn[idx].RTO_pending = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001551
Marco Varlesefae40392018-02-14 15:38:35 +01001552 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001553
1554 return SCTP_ERROR_NONE;
1555}
1556
1557always_inline u16
1558sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001559 sctp_connection_t * sctp_conn, u8 idx,
1560 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001561{
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001562 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1563 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1564 {
Marco Varlese87971682018-10-04 15:46:05 +02001565 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001566 return SCTP_ERROR_INVALID_TAG;
1567 }
1568
Marco Varlese54432f82018-02-15 17:01:56 +01001569 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001570
1571 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1572
Marco Varlese191a5942017-10-30 18:17:21 +01001573 return SCTP_ERROR_NONE;
1574}
1575
1576always_inline u16
1577sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001578 sctp_connection_t * sctp_conn, u8 idx,
1579 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001580{
Marco Varlese54432f82018-02-15 17:01:56 +01001581 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1582
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001583 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1584
1585 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1586 sctp_conn->sub_conn[idx].RTO);
1587
Marco Varlesefae40392018-02-14 15:38:35 +01001588 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001589
Marco Varlese191a5942017-10-30 18:17:21 +01001590 return SCTP_ERROR_NONE;
1591}
1592
1593always_inline void
Marco Varlese3c6a9762018-03-01 11:19:59 +01001594sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
Marco Varlese191a5942017-10-30 18:17:21 +01001595 u8 is_ip4, u8 evt, u8 val)
1596{
1597 if (PREDICT_TRUE (!val))
1598 return;
1599
1600 if (is_ip4)
Marco Varlese3c6a9762018-03-01 11:19:59 +01001601 vlib_node_increment_counter (vm, sctp4_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001602 else
Marco Varlese3c6a9762018-03-01 11:19:59 +01001603 vlib_node_increment_counter (vm, sctp6_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001604}
1605
1606always_inline uword
1607sctp46_listen_process_inline (vlib_main_t * vm,
1608 vlib_node_runtime_t * node,
1609 vlib_frame_t * from_frame, int is_ip4)
1610{
1611 u32 n_left_from, next_index, *from, *to_next;
1612 u32 my_thread_index = vm->thread_index;
1613
1614 from = vlib_frame_vector_args (from_frame);
1615 n_left_from = from_frame->n_vectors;
1616
1617 next_index = node->cached_next_index;
1618
1619 while (n_left_from > 0)
1620 {
1621 u32 n_left_to_next;
1622
1623 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1624
1625 while (n_left_from > 0 && n_left_to_next > 0)
1626 {
1627 u32 bi0;
1628 vlib_buffer_t *b0;
1629 sctp_header_t *sctp_hdr = 0;
1630 ip4_header_t *ip4_hdr;
1631 ip6_header_t *ip6_hdr;
1632 sctp_connection_t *child_conn;
1633 sctp_connection_t *sctp_listener;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001634 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
Marco Varlese191a5942017-10-30 18:17:21 +01001635
1636 bi0 = from[0];
1637 to_next[0] = bi0;
1638 from += 1;
1639 to_next += 1;
1640 n_left_from -= 1;
1641 n_left_to_next -= 1;
1642
1643 b0 = vlib_get_buffer (vm, bi0);
1644 sctp_listener =
1645 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1646
1647 if (is_ip4)
1648 {
1649 ip4_hdr = vlib_buffer_get_current (b0);
1650 sctp_hdr = ip4_next_header (ip4_hdr);
1651 }
1652 else
1653 {
1654 ip6_hdr = vlib_buffer_get_current (b0);
1655 sctp_hdr = ip6_next_header (ip6_hdr);
1656 }
1657
1658 child_conn =
1659 sctp_lookup_connection (sctp_listener->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001660 [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001661 my_thread_index, is_ip4);
1662
1663 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1664 {
1665 SCTP_DBG
1666 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001667 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001668 connection.c_index,
1669 sctp_state_to_string (child_conn->state));
1670 error0 = SCTP_ERROR_CREATE_EXISTS;
1671 goto drop;
1672 }
1673
1674 /* Create child session and send SYN-ACK */
1675 child_conn = sctp_connection_new (my_thread_index);
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001676 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1677 SCTP_PRIMARY_PATH_IDX;
1678 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001679 sctp_hdr->dst_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001680 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001681 sctp_hdr->src_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001682 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1683 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1684 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1685 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1686 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
Marco Varlese191a5942017-10-30 18:17:21 +01001687 child_conn->state = SCTP_STATE_CLOSED;
Marco Varlesee17bb712018-03-28 12:06:10 +02001688 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1689 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1690 connection.fib_index;
Marco Varlese191a5942017-10-30 18:17:21 +01001691
1692 if (is_ip4)
1693 {
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001694 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001695 ip4_hdr->dst_address.as_u32;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001696 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001697 ip4_hdr->src_address.as_u32;
1698 }
1699 else
1700 {
Dave Barach178cf492018-11-13 16:34:13 -05001701 clib_memcpy_fast (&child_conn->
1702 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
1703 &ip6_hdr->dst_address,
1704 sizeof (ip6_address_t));
1705 clib_memcpy_fast (&child_conn->
1706 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
1707 &ip6_hdr->src_address,
1708 sizeof (ip6_address_t));
Marco Varlese191a5942017-10-30 18:17:21 +01001709 }
1710
1711 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1712 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1713
1714 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +02001715 if (chunk_type != INIT && chunk_type != DATA
1716 && chunk_type != OPERATION_ERROR)
Marco Varlese191a5942017-10-30 18:17:21 +01001717 {
1718 SCTP_DBG
1719 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001720 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001721 connection.c_index, sctp_chunk_to_string (chunk_type));
1722
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001723 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001724 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001725 goto drop;
1726 }
1727
1728 u16 sctp_implied_length =
1729 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1730
1731 switch (chunk_type)
1732 {
1733 case INIT:
1734 sctp_connection_timers_init (child_conn);
1735
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001736 sctp_init_snd_vars (child_conn);
1737
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001738 sctp_init_cwnd (child_conn);
1739
Marco Varlese191a5942017-10-30 18:17:21 +01001740 error0 =
1741 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1742 sctp_implied_length);
1743
Marco Varlese191a5942017-10-30 18:17:21 +01001744 if (error0 == SCTP_ERROR_NONE)
1745 {
Florin Corasc9940fc2019-02-05 20:55:11 -08001746 if (session_stream_accept
Marco Varlese191a5942017-10-30 18:17:21 +01001747 (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001748 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
Marco Varlese191a5942017-10-30 18:17:21 +01001749 sctp_listener->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001750 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
Marco Varlese191a5942017-10-30 18:17:21 +01001751 {
1752 clib_warning ("session accept fail");
1753 sctp_connection_cleanup (child_conn);
1754 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1755 goto drop;
1756 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001757 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001758 }
Marco Varlese191a5942017-10-30 18:17:21 +01001759 break;
1760
1761 /* Reception of a DATA chunk whilst in the CLOSED state is called
1762 * "Out of the Blue" packet and handling of the chunk needs special treatment
1763 * as per RFC4960 section 8.4
1764 */
1765 case DATA:
1766 break;
Marco Varlese200fa322018-02-26 16:33:54 +01001767
1768 case OPERATION_ERROR:
1769 error0 =
1770 sctp_handle_operation_err (sctp_hdr, child_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001771 SCTP_PRIMARY_PATH_IDX, b0, &next0);
Marco Varlese200fa322018-02-26 16:33:54 +01001772 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001773 }
1774
1775 drop:
1776 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1777 {
1778 sctp_rx_trace_t *t0 =
1779 vlib_add_trace (vm, node, b0, sizeof (*t0));
Dave Barach178cf492018-11-13 16:34:13 -05001780 clib_memcpy_fast (&t0->sctp_header, sctp_hdr,
1781 sizeof (t0->sctp_header));
1782 clib_memcpy_fast (&t0->sctp_connection, sctp_listener,
1783 sizeof (t0->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001784 }
1785
1786 b0->error = node->errors[error0];
1787
1788 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1789 n_left_to_next, bi0, next0);
1790 }
1791 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1792
1793 }
1794 return from_frame->n_vectors;
1795}
1796
Filip Tehlara5a458f2019-03-05 06:50:19 -08001797VLIB_NODE_FN (sctp4_listen_phase_node) (vlib_main_t * vm,
1798 vlib_node_runtime_t * node,
1799 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001800{
1801 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1802}
1803
Filip Tehlara5a458f2019-03-05 06:50:19 -08001804VLIB_NODE_FN (sctp6_listen_phase_node) (vlib_main_t * vm,
1805 vlib_node_runtime_t * node,
1806 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001807{
1808 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1809}
1810
1811always_inline uword
1812sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1813 vlib_frame_t * from_frame, int is_ip4)
1814{
Filip Tehlara5a458f2019-03-05 06:50:19 -08001815 sctp_main_t *sm = vnet_get_sctp_main ();
Marco Varlese191a5942017-10-30 18:17:21 +01001816 u32 n_left_from, next_index, *from, *to_next;
1817 u32 my_thread_index = vm->thread_index, errors = 0;
1818
1819 from = vlib_frame_vector_args (from_frame);
1820 n_left_from = from_frame->n_vectors;
1821
1822 next_index = node->cached_next_index;
1823
1824 while (n_left_from > 0)
1825 {
1826 u32 n_left_to_next;
1827
1828 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1829
1830 while (n_left_from > 0 && n_left_to_next > 0)
1831 {
1832 u32 bi0;
1833 vlib_buffer_t *b0;
1834 sctp_header_t *sctp_hdr = 0;
1835 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1836 ip4_header_t *ip4_hdr = 0;
1837 ip6_header_t *ip6_hdr = 0;
1838 sctp_connection_t *sctp_conn;
Marco Varlesefae40392018-02-14 15:38:35 +01001839 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1840 SCTP_ESTABLISHED_PHASE_N_NEXT;
Marco Varlese191a5942017-10-30 18:17:21 +01001841 u8 idx;
1842
1843 bi0 = from[0];
1844 to_next[0] = bi0;
1845 from += 1;
1846 to_next += 1;
1847 n_left_from -= 1;
1848 n_left_to_next -= 1;
1849
1850 b0 = vlib_get_buffer (vm, bi0);
1851 sctp_conn =
1852 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1853 my_thread_index);
1854
1855 if (PREDICT_FALSE (sctp_conn == 0))
1856 {
1857 SCTP_DBG
1858 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1859 error0 = SCTP_ERROR_INVALID_CONNECTION;
1860 goto done;
1861 }
1862 if (is_ip4)
1863 {
1864 ip4_hdr = vlib_buffer_get_current (b0);
1865 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001866 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001867 }
1868 else
1869 {
1870 ip6_hdr = vlib_buffer_get_current (b0);
1871 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001872 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001873 }
1874
Marco Varlese04e5d642018-02-23 17:43:06 +01001875 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001876
Marco Varlese54432f82018-02-15 17:01:56 +01001877 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +01001878 sctp_chunk_hdr =
1879 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1880
1881 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1882
1883 switch (chunk_type)
1884 {
1885 case COOKIE_ECHO:
1886 error0 =
1887 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001888 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001889 break;
1890
1891 case COOKIE_ACK:
1892 error0 =
1893 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001894 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001895 break;
1896
1897 case SACK:
1898 error0 =
1899 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001900 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001901 break;
1902
1903 case HEARTBEAT:
1904 error0 =
1905 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001906 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001907 break;
1908
1909 case HEARTBEAT_ACK:
1910 error0 =
1911 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001912 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001913 break;
1914
1915 case DATA:
1916 error0 =
1917 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001918 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001919 break;
1920
Marco Varlese200fa322018-02-26 16:33:54 +01001921 case OPERATION_ERROR:
1922 error0 =
1923 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1924 &next0);
1925 break;
1926
Marco Varlese191a5942017-10-30 18:17:21 +01001927 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1928 * are handled by the input-dispatcher function using the table-lookup
1929 * hence we should never get to the "default" case below.
1930 */
1931 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001932 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001933 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001934 goto done;
1935 }
1936
1937 done:
1938 b0->error = node->errors[error0];
1939 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1940 {
1941 sctp_rx_trace_t *t0 =
1942 vlib_add_trace (vm, node, b0, sizeof (*t0));
1943 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1944 }
1945
1946 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1947 n_left_to_next, bi0, next0);
1948 }
1949
1950 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1951 }
1952
Florin Coras31c99552019-03-01 13:00:58 -08001953 errors = session_main_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1954 my_thread_index);
Marco Varlese191a5942017-10-30 18:17:21 +01001955
Filip Tehlara5a458f2019-03-05 06:50:19 -08001956 sctp_node_inc_counter (vm, is_ip4, sm->sctp4_established_phase_node_index,
1957 sm->sctp6_established_phase_node_index,
Marco Varlese191a5942017-10-30 18:17:21 +01001958 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1959 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1960
1961 return from_frame->n_vectors;
1962}
1963
Filip Tehlara5a458f2019-03-05 06:50:19 -08001964VLIB_NODE_FN (sctp4_established_phase_node) (vlib_main_t * vm,
1965 vlib_node_runtime_t * node,
1966 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001967{
1968 return sctp46_established_phase_inline (vm, node, from_frame,
1969 1 /* is_ip4 */ );
1970}
1971
Filip Tehlara5a458f2019-03-05 06:50:19 -08001972VLIB_NODE_FN (sctp6_established_phase_node) (vlib_main_t * vm,
1973 vlib_node_runtime_t * node,
1974 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01001975{
1976 return sctp46_established_phase_inline (vm, node, from_frame,
1977 0 /* is_ip4 */ );
1978}
1979
Filip Tehlara5a458f2019-03-05 06:50:19 -08001980static u8 *
Marco Varlese191a5942017-10-30 18:17:21 +01001981format_sctp_rx_trace (u8 * s, va_list * args)
1982{
1983 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1984 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1985 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1986 u32 indent = format_get_indent (s);
1987
1988 s = format (s, "%U\n%U%U",
1989 format_sctp_header, &t->sctp_header, 128,
1990 format_white_space, indent,
1991 format_sctp_connection, &t->sctp_connection, 1);
1992
1993 return s;
1994}
1995
1996/* *INDENT-OFF* */
1997VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1998{
Marco Varlese191a5942017-10-30 18:17:21 +01001999 .name = "sctp4-listen",
2000 /* Takes a vector of packets. */
2001 .vector_size = sizeof (u32),
2002 .n_errors = SCTP_N_ERROR,
2003 .error_strings = sctp_error_strings,
2004 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2005 .next_nodes =
2006 {
2007#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2008 foreach_sctp_state_next
2009#undef _
2010 },
2011 .format_trace = format_sctp_rx_trace_short,
2012};
2013/* *INDENT-ON* */
2014
Marco Varlese191a5942017-10-30 18:17:21 +01002015/* *INDENT-OFF* */
2016VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
2017{
Marco Varlese191a5942017-10-30 18:17:21 +01002018 .name = "sctp6-listen",
2019 /* Takes a vector of packets. */
2020 .vector_size = sizeof (u32),
2021 .n_errors = SCTP_N_ERROR,
2022 .error_strings = sctp_error_strings,
2023 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2024 .next_nodes =
2025 {
2026#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2027 foreach_sctp_state_next
2028#undef _
2029 },
2030 .format_trace = format_sctp_rx_trace_short,
2031};
2032/* *INDENT-ON* */
2033
Marco Varlese191a5942017-10-30 18:17:21 +01002034/* *INDENT-OFF* */
2035VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2036{
Marco Varlese191a5942017-10-30 18:17:21 +01002037 .name = "sctp4-established",
2038 /* Takes a vector of packets. */
2039 .vector_size = sizeof (u32),
2040 .n_errors = SCTP_N_ERROR,
2041 .error_strings = sctp_error_strings,
2042 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2043 .next_nodes =
2044 {
2045#define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2046 foreach_sctp_state_next
2047#undef _
2048 },
2049 .format_trace = format_sctp_rx_trace_short,
2050};
2051/* *INDENT-ON* */
2052
Marco Varlese191a5942017-10-30 18:17:21 +01002053/* *INDENT-OFF* */
2054VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2055{
Marco Varlese191a5942017-10-30 18:17:21 +01002056 .name = "sctp6-established",
2057 /* Takes a vector of packets. */
2058 .vector_size = sizeof (u32),
2059 .n_errors = SCTP_N_ERROR,
2060 .error_strings = sctp_error_strings,
2061 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2062 .next_nodes =
2063 {
2064#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2065 foreach_sctp_state_next
2066#undef _
2067 },
2068 .format_trace = format_sctp_rx_trace_short,
2069};
2070/* *INDENT-ON* */
2071
Marco Varlese191a5942017-10-30 18:17:21 +01002072/*
2073 * This is the function executed first for the SCTP graph.
2074 * It takes care of doing the initial message parsing and
2075 * dispatch to the specialized function.
2076 */
2077always_inline uword
2078sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2079 vlib_frame_t * from_frame, int is_ip4)
2080{
2081 u32 n_left_from, next_index, *from, *to_next;
2082 u32 my_thread_index = vm->thread_index;
Florin Corasb5e55a22019-01-10 12:42:47 -08002083 u8 result;
Marco Varlese191a5942017-10-30 18:17:21 +01002084 sctp_main_t *tm = vnet_get_sctp_main ();
2085
2086 from = vlib_frame_vector_args (from_frame);
2087 n_left_from = from_frame->n_vectors;
2088 next_index = node->cached_next_index;
2089 sctp_set_time_now (my_thread_index);
2090
2091 while (n_left_from > 0)
2092 {
2093 u32 n_left_to_next;
2094
2095 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2096
2097 while (n_left_from > 0 && n_left_to_next > 0)
2098 {
2099 int n_advance_bytes0, n_data_bytes0;
2100 u32 bi0, fib_index0;
2101 vlib_buffer_t *b0;
2102 sctp_header_t *sctp_hdr = 0;
2103 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2104 sctp_connection_t *sctp_conn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002105 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01002106 ip4_header_t *ip4_hdr;
2107 ip6_header_t *ip6_hdr;
2108 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2109
2110 bi0 = from[0];
2111 to_next[0] = bi0;
2112 from += 1;
2113 to_next += 1;
2114 n_left_from -= 1;
2115 n_left_to_next -= 1;
2116
2117 b0 = vlib_get_buffer (vm, bi0);
Marco Varlese3c6a9762018-03-01 11:19:59 +01002118 vnet_buffer (b0)->sctp.flags = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01002119 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2120
2121 /* Checksum computed by ipx_local no need to compute again */
2122
2123 if (is_ip4)
2124 {
2125 ip4_hdr = vlib_buffer_get_current (b0);
2126 sctp_hdr = ip4_next_header (ip4_hdr);
2127
2128 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2129 sctp_chunk_hdr = &full_hdr->common_hdr;
2130
2131 n_advance_bytes0 =
2132 (ip4_header_bytes (ip4_hdr) +
2133 sizeof (sctp_payload_data_chunk_t));
2134 n_data_bytes0 =
2135 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2136
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002137 trans_conn = session_lookup_connection_wt4 (fib_index0,
2138 &ip4_hdr->dst_address,
2139 &ip4_hdr->src_address,
2140 sctp_hdr->dst_port,
2141 sctp_hdr->src_port,
2142 TRANSPORT_PROTO_SCTP,
2143 my_thread_index,
Florin Corasb5e55a22019-01-10 12:42:47 -08002144 &result);
Marco Varlese191a5942017-10-30 18:17:21 +01002145 }
2146 else
2147 {
2148 ip6_hdr = vlib_buffer_get_current (b0);
2149 sctp_hdr = ip6_next_header (ip6_hdr);
2150
2151 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2152 sctp_chunk_hdr = &full_hdr->common_hdr;
2153
2154 n_advance_bytes0 = sctp_header_bytes ();
2155 n_data_bytes0 =
2156 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2157 n_advance_bytes0;
2158 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2159
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002160 trans_conn = session_lookup_connection_wt6 (fib_index0,
2161 &ip6_hdr->dst_address,
2162 &ip6_hdr->src_address,
2163 sctp_hdr->dst_port,
2164 sctp_hdr->src_port,
2165 TRANSPORT_PROTO_SCTP,
2166 my_thread_index,
Florin Corasb5e55a22019-01-10 12:42:47 -08002167 &result);
Marco Varlese191a5942017-10-30 18:17:21 +01002168 }
2169
2170 /* Length check */
2171 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2172 {
2173 error0 = SCTP_ERROR_LENGTH;
2174 goto done;
2175 }
2176
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002177 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01002178 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2179
Marco Varlesefae40392018-02-14 15:38:35 +01002180 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2181 if (chunk_type >= UNKNOWN)
2182 {
2183 clib_warning
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002184 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2185
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002186 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002187 b0, UNRECOGNIZED_CHUNK_TYPE);
2188
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03002189 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002190 next0 = sctp_next_output (is_ip4);
Marco Varlesefae40392018-02-14 15:38:35 +01002191 goto done;
2192 }
2193
Marco Varlese191a5942017-10-30 18:17:21 +01002194 vnet_buffer (b0)->sctp.hdr_offset =
2195 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2196
2197 /* Session exists */
2198 if (PREDICT_TRUE (0 != sctp_conn))
2199 {
2200 /* Save connection index */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002201 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
Marco Varlese191a5942017-10-30 18:17:21 +01002202 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2203 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2204
Marco Varlesefae40392018-02-14 15:38:35 +01002205 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2206 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
Marco Varlese191a5942017-10-30 18:17:21 +01002207
Marco Varlesef3ab4892018-02-19 15:23:13 +01002208 SCTP_DBG_STATE_MACHINE
Marco Varlese15cc6a82018-02-21 12:39:52 +01002209 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
Marco Varlesef3ab4892018-02-19 15:23:13 +01002210 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002211 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002212 connection.s_index,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002213 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002214 connection.c_index, trans_conn, sctp_conn,
2215 sctp_state_to_string (sctp_conn->state),
Marco Varlesef3ab4892018-02-19 15:23:13 +01002216 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
Marco Varlese191a5942017-10-30 18:17:21 +01002217
Marco Varlesefae40392018-02-14 15:38:35 +01002218 if (chunk_type == DATA)
Marco Varlese191a5942017-10-30 18:17:21 +01002219 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2220 n_advance_bytes0, n_data_bytes0);
2221
2222 }
2223 else
2224 {
Florin Corasb5e55a22019-01-10 12:42:47 -08002225 if (result)
Marco Varlese191a5942017-10-30 18:17:21 +01002226 {
2227 next0 = SCTP_INPUT_NEXT_DROP;
Florin Corasb5e55a22019-01-10 12:42:47 -08002228 error0 = SCTP_ERROR_NONE + result;
Marco Varlese191a5942017-10-30 18:17:21 +01002229 }
2230 else if ((is_ip4 && tm->punt_unknown4) ||
2231 (!is_ip4 && tm->punt_unknown6))
2232 {
2233 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2234 error0 = SCTP_ERROR_PUNT;
2235 }
2236 else
2237 {
2238 next0 = SCTP_INPUT_NEXT_DROP;
2239 error0 = SCTP_ERROR_NO_LISTENER;
2240 }
2241 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2242 phase_to_string (next0));
2243 sctp_conn = 0;
2244 }
2245
2246 done:
2247 b0->error = error0 ? node->errors[error0] : 0;
2248
2249 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2250 {
2251 sctp_rx_trace_t *t0 =
2252 vlib_add_trace (vm, node, b0, sizeof (*t0));
2253 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2254 }
2255 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2256 n_left_to_next, bi0, next0);
2257 }
2258
2259 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2260 }
2261 return from_frame->n_vectors;
2262}
2263
Filip Tehlara5a458f2019-03-05 06:50:19 -08002264VLIB_NODE_FN (sctp4_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
2265 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01002266{
2267 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2268}
2269
Filip Tehlara5a458f2019-03-05 06:50:19 -08002270VLIB_NODE_FN (sctp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
2271 vlib_frame_t * from_frame)
Marco Varlese191a5942017-10-30 18:17:21 +01002272{
2273 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2274}
2275
2276/* *INDENT-OFF* */
2277VLIB_REGISTER_NODE (sctp4_input_node) =
2278{
Marco Varlese191a5942017-10-30 18:17:21 +01002279 .name = "sctp4-input",
2280 /* Takes a vector of packets. */
2281 .vector_size = sizeof (u32),
2282 .n_errors = SCTP_N_ERROR,
2283 .error_strings = sctp_error_strings,
2284 .n_next_nodes = SCTP_INPUT_N_NEXT,
2285 .next_nodes =
2286 {
2287#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2288 foreach_sctp4_input_next
2289#undef _
2290 },
2291 .format_buffer = format_sctp_header,
2292 .format_trace = format_sctp_rx_trace,
2293};
2294/* *INDENT-ON* */
2295
Marco Varlese191a5942017-10-30 18:17:21 +01002296/* *INDENT-OFF* */
2297VLIB_REGISTER_NODE (sctp6_input_node) =
2298{
Marco Varlese191a5942017-10-30 18:17:21 +01002299 .name = "sctp6-input",
2300 /* Takes a vector of packets. */
2301 .vector_size = sizeof (u32),
2302 .n_errors = SCTP_N_ERROR,
2303 .error_strings = sctp_error_strings,
2304 .n_next_nodes = SCTP_INPUT_N_NEXT,
2305 .next_nodes =
2306 {
2307#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2308 foreach_sctp6_input_next
2309#undef _
2310 },
2311 .format_buffer = format_sctp_header,
2312 .format_trace = format_sctp_rx_trace,
2313};
2314/* *INDENT-ON* */
2315
Filip Tehlara5a458f2019-03-05 06:50:19 -08002316#ifndef CLIB_MARCH_VARIANT
Marco Varlese191a5942017-10-30 18:17:21 +01002317static void
2318sctp_dispatch_table_init (sctp_main_t * tm)
2319{
2320 int i, j;
2321 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2322 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2323 {
2324 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2325 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2326 }
2327
2328#define _(t,f,n,e) \
2329do { \
2330 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2331 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2332} while (0)
2333
2334 /*
2335 * SCTP STATE-MACHINE states:
2336 *
2337 * _(CLOSED, "CLOSED") \
2338 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2339 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2340 * _(ESTABLISHED, "ESTABLISHED") \
2341 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2342 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2343 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2344 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2345 */
Marco Varlesef3ab4892018-02-19 15:23:13 +01002346 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002347 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2348 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2349 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2350 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2351 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2352 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2353 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2354 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2355 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2356 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2357 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2358 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2359 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2360 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002361 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002362
Marco Varlese200fa322018-02-26 16:33:54 +01002363 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002364 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2365 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2366 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2367 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2368 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2369 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2370 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2371 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2372 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2373 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2374 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2375 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2376 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2377 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002378 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2379 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002380
2381 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2382 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2383 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2384 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2385 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2386 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2387 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2388 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2389 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2390 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2391 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2392 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2393 SCTP_ERROR_NONE);
2394 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2395 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2396 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002397 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2398 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002399
2400 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2401 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2402 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2403 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2404 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2405 SCTP_ERROR_NONE);
2406 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2407 SCTP_ERROR_NONE);
2408 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2409 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2410 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2411 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2412 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2413 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2414 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2415 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2416 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002417 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2418 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002419
2420 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2421 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2422 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2423 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2424 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2425 SCTP_ERROR_NONE);
2426 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2427 SCTP_ERROR_NONE);
2428 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2429 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2430 SCTP_ERROR_NONE);
2431 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2432 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002433 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2434 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002435 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2436 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2437 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2438 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002439 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2440 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002441
2442 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2443 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2444 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2445 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2446 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2447 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2448 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2449 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2450 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2451 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002452 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2453 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002454 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2455 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2456 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2457 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002458 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2459 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002460
2461 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2462 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2463 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2464 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2465 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2466 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2467 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2468 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2469 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2470 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002471 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2472 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002473 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2474 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2475 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2476 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002477 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2478 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002479
2480 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
Marco Varleseeacf3cf2018-02-26 14:52:25 +01002481 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
Marco Varlese191a5942017-10-30 18:17:21 +01002482 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2483 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2484 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2485 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2486 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2487 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2488 _(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 +01002489 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2490 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002491 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2492 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2493 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2494 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2495 SCTP_ERROR_NONE);
Marco Varlese200fa322018-02-26 16:33:54 +01002496 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2497 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002498
2499 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2500
2501#undef _
2502}
2503
2504clib_error_t *
2505sctp_input_init (vlib_main_t * vm)
2506{
2507 clib_error_t *error = 0;
2508 sctp_main_t *tm = vnet_get_sctp_main ();
2509
2510 if ((error = vlib_call_init_function (vm, sctp_init)))
2511 return error;
2512
2513 /* Initialize dispatch table. */
2514 sctp_dispatch_table_init (tm);
2515
2516 return error;
2517}
2518
2519VLIB_INIT_FUNCTION (sctp_input_init);
Filip Tehlara5a458f2019-03-05 06:50:19 -08002520#endif /* CLIB_MARCH_VARIANT */
Marco Varlese191a5942017-10-30 18:17:21 +01002521
2522/*
2523 * fd.io coding-style-patch-verification: ON
2524 *
2525 * Local Variables:
2526 * eval: (c-set-style "gnu")
2527 * End:
2528 */