blob: e548707d32af334f77a0e7666ffdbb291ccdb073 [file] [log] [blame]
Marco Varlese191a5942017-10-30 18:17:21 +01001/*
2 * Copyright (c) 2017 SUSE LLC.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include <vppinfra/sparse_vec.h>
16#include <vnet/sctp/sctp.h>
17#include <vnet/sctp/sctp_packet.h>
18#include <vnet/sctp/sctp_debug.h>
19#include <vnet/session/session.h>
20#include <math.h>
21
22static char *sctp_error_strings[] = {
23#define sctp_error(n,s) s,
24#include <vnet/sctp/sctp_error.def>
25#undef sctp_error
26};
27
28/* All SCTP nodes have the same outgoing arcs */
29#define foreach_sctp_state_next \
Marco Varlesefae40392018-02-14 15:38:35 +010030 _ (DROP4, "ip4-drop") \
31 _ (DROP6, "ip6-drop") \
Marco Varlese191a5942017-10-30 18:17:21 +010032 _ (SCTP4_OUTPUT, "sctp4-output") \
33 _ (SCTP6_OUTPUT, "sctp6-output")
34
35typedef enum _sctp_established_phase_next
36{
37#define _(s,n) SCTP_ESTABLISHED_PHASE_NEXT_##s,
38 foreach_sctp_state_next
39#undef _
40 SCTP_ESTABLISHED_PHASE_N_NEXT,
41} sctp_established_phase_next_t;
42
43typedef enum _sctp_rcv_phase_next
44{
45#define _(s,n) SCTP_RCV_PHASE_NEXT_##s,
46 foreach_sctp_state_next
47#undef _
48 SCTP_RCV_PHASE_N_NEXT,
49} sctp_rcv_phase_next_t;
50
51typedef enum _sctp_listen_phase_next
52{
53#define _(s,n) SCTP_LISTEN_PHASE_NEXT_##s,
54 foreach_sctp_state_next
55#undef _
56 SCTP_LISTEN_PHASE_N_NEXT,
57} sctp_listen_phase_next_t;
58
59typedef enum _sctp_shutdown_phase_next
60{
61#define _(s,n) SCTP_SHUTDOWN_PHASE_NEXT_##s,
62 foreach_sctp_state_next
63#undef _
64 SCTP_SHUTDOWN_PHASE_N_NEXT,
65} sctp_shutdown_phase_next_t;
66
67/* Generic, state independent indices */
68typedef enum _sctp_state_next
69{
70#define _(s,n) SCTP_NEXT_##s,
71 foreach_sctp_state_next
72#undef _
73 SCTP_STATE_N_NEXT,
74} sctp_state_next_t;
75
76typedef enum _sctp_input_next
77{
78 SCTP_INPUT_NEXT_DROP,
79 SCTP_INPUT_NEXT_LISTEN_PHASE,
80 SCTP_INPUT_NEXT_RCV_PHASE,
81 SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
82 SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
83 SCTP_INPUT_NEXT_PUNT_PHASE,
84 SCTP_INPUT_N_NEXT
85} sctp_input_next_t;
86
87char *
88phase_to_string (u8 phase)
89{
90 switch (phase)
91 {
92 case SCTP_INPUT_NEXT_DROP:
93 return "SCTP_INPUT_NEXT_DROP";
94 case SCTP_INPUT_NEXT_LISTEN_PHASE:
95 return "SCTP_INPUT_NEXT_LISTEN_PHASE";
96 case SCTP_INPUT_NEXT_RCV_PHASE:
97 return "SCTP_INPUT_NEXT_RCV_PHASE";
98 case SCTP_INPUT_NEXT_ESTABLISHED_PHASE:
99 return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
100 case SCTP_INPUT_NEXT_SHUTDOWN_PHASE:
101 return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
102 case SCTP_INPUT_NEXT_PUNT_PHASE:
103 return "SCTP_INPUT_NEXT_PUNT_PHASE";
104 }
105 return NULL;
106}
107
108#define foreach_sctp4_input_next \
109 _ (DROP, "error-drop") \
110 _ (RCV_PHASE, "sctp4-rcv") \
111 _ (LISTEN_PHASE, "sctp4-listen") \
112 _ (ESTABLISHED_PHASE, "sctp4-established") \
113 _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
114 _ (PUNT_PHASE, "ip4-punt")
115
116
117#define foreach_sctp6_input_next \
118 _ (DROP, "error-drop") \
119 _ (RCV_PHASE, "sctp6-rcv") \
120 _ (LISTEN_PHASE, "sctp6-listen") \
121 _ (ESTABLISHED_PHASE, "sctp6-established") \
122 _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
123 _ (PUNT_PHASE, "ip6-punt")
124
125static u8
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100126sctp_lookup_is_valid (transport_connection_t * trans_conn,
Marco Varlese191a5942017-10-30 18:17:21 +0100127 sctp_header_t * sctp_hdr)
128{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100129 sctp_connection_t *sctp_conn =
130 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100131
132 if (!sctp_conn)
133 return 1;
134
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100135 u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
Marco Varlese191a5942017-10-30 18:17:21 +0100136 && (sctp_conn->state == SCTP_STATE_CLOSED
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100137 || trans_conn->rmt_port == sctp_hdr->src_port));
Marco Varlese191a5942017-10-30 18:17:21 +0100138
139 return is_valid;
140}
141
142/**
143 * Lookup transport connection
144 */
145static sctp_connection_t *
146sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
147 u8 is_ip4)
148{
149 sctp_main_t *tm = vnet_get_sctp_main ();
150 sctp_header_t *sctp_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100151 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100152 sctp_connection_t *sctp_conn;
153 u8 is_filtered, i;
154 if (is_ip4)
155 {
156 ip4_header_t *ip4_hdr;
157 ip4_hdr = vlib_buffer_get_current (b);
158 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100159 trans_conn = session_lookup_connection_wt4 (fib_index,
160 &ip4_hdr->dst_address,
161 &ip4_hdr->src_address,
162 sctp_hdr->dst_port,
163 sctp_hdr->src_port,
164 TRANSPORT_PROTO_SCTP,
165 thread_index, &is_filtered);
166 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100167 {
168 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
169 {
170 if ((tm->connections[thread_index]->sub_conn[i].
171 connection.lcl_ip.ip4.as_u32 ==
172 ip4_hdr->dst_address.as_u32)
173 && (tm->connections[thread_index]->sub_conn[i].
174 connection.rmt_ip.ip4.as_u32 ==
175 ip4_hdr->src_address.as_u32))
176 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100177 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100178 &tm->connections[thread_index]->sub_conn[i].connection;
179 break;
180 }
181 }
182 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100183 ASSERT (trans_conn != 0);
184 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100185 }
186 else
187 {
188 ip6_header_t *ip6_hdr;
189 ip6_hdr = vlib_buffer_get_current (b);
190 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100191 trans_conn = session_lookup_connection_wt6 (fib_index,
192 &ip6_hdr->dst_address,
193 &ip6_hdr->src_address,
194 sctp_hdr->dst_port,
195 sctp_hdr->src_port,
196 TRANSPORT_PROTO_SCTP,
197 thread_index, &is_filtered);
198 if (trans_conn == 0) /* Not primary connection */
Marco Varlese191a5942017-10-30 18:17:21 +0100199 {
200 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
201 {
202 if ((tm->connections[thread_index]->sub_conn[i].
203 connection.lcl_ip.ip6.as_u64[0] ==
204 ip6_hdr->dst_address.as_u64[0]
205 && tm->connections[thread_index]->sub_conn[i].
206 connection.lcl_ip.ip6.as_u64[1] ==
207 ip6_hdr->dst_address.as_u64[1])
208 && (tm->connections[thread_index]->sub_conn[i].
209 connection.rmt_ip.ip6.as_u64[0] ==
210 ip6_hdr->src_address.as_u64[0]
211 && tm->connections[thread_index]->
212 sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
213 ip6_hdr->src_address.as_u64[1]))
214 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100215 trans_conn =
Marco Varlese191a5942017-10-30 18:17:21 +0100216 &tm->connections[thread_index]->sub_conn[i].connection;
217 break;
218 }
219 }
220 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100221 ASSERT (trans_conn != 0);
222 ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
Marco Varlese191a5942017-10-30 18:17:21 +0100223 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100224 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100225 return sctp_conn;
226}
227
228typedef struct
229{
230 sctp_header_t sctp_header;
231 sctp_connection_t sctp_connection;
232} sctp_rx_trace_t;
233
234#define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
235 : SCTP_NEXT_SCTP6_OUTPUT)
236
Marco Varlesefae40392018-02-14 15:38:35 +0100237#define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
238 : SCTP_NEXT_DROP6)
Marco Varlese191a5942017-10-30 18:17:21 +0100239
240void
241sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
242 sctp_connection_t * sctp_conn,
243 sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
244 u8 is_ip4)
245{
246 if (sctp_conn)
247 {
248 clib_memcpy (&rx_trace->sctp_connection, sctp_conn,
249 sizeof (rx_trace->sctp_connection));
250 }
251 else
252 {
253 sctp_hdr = sctp_buffer_hdr (b0);
254 }
255 clib_memcpy (&rx_trace->sctp_header, sctp_hdr,
256 sizeof (rx_trace->sctp_header));
257}
258
259always_inline u16
260sctp_calculate_implied_length (ip4_header_t * ip4_hdr, ip6_header_t * ip6_hdr,
261 int is_ip4)
262{
263 u16 sctp_implied_packet_length = 0;
264
265 if (is_ip4)
266 sctp_implied_packet_length =
267 clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
268 else
269 sctp_implied_packet_length =
270 clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
271
272 return sctp_implied_packet_length;
273}
274
275always_inline u8
276sctp_is_bundling (u16 sctp_implied_length,
277 sctp_chunks_common_hdr_t * sctp_common_hdr)
278{
279 if (sctp_implied_length !=
280 sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
281 return 1;
282 return 0;
283}
284
285always_inline u16
Marco Varlese200fa322018-02-26 16:33:54 +0100286sctp_handle_operation_err (sctp_header_t * sctp_hdr,
287 sctp_connection_t * sctp_conn, u8 idx,
288 vlib_buffer_t * b, u16 * next0)
289{
290 sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
291
292 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
293 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
294 {
295 return SCTP_ERROR_INVALID_TAG;
296 }
297
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100298 if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
299 STALE_COOKIE_ERROR)
Marco Varlese200fa322018-02-26 16:33:54 +0100300 {
301 if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
302 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
303 else
304 {
305 sctp_connection_cleanup (sctp_conn);
306
307 stream_session_disconnect_notify (&sctp_conn->
308 sub_conn[idx].connection);
309 }
310 }
311
312 return SCTP_ERROR_NONE;
313}
314
315always_inline u16
Marco Varlese191a5942017-10-30 18:17:21 +0100316sctp_handle_init (sctp_header_t * sctp_hdr,
317 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
318 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
319 u16 sctp_implied_length)
320{
321 sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +0200322 ip4_address_t ip4_addr;
323 ip6_address_t ip6_addr;
324 u8 add_ip4 = 0;
325 u8 add_ip6 = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100326 char hostname[FQDN_MAX_LENGTH];
327
328 /* Check the current state of the connection
329 *
330 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
331 * in the code below and by the "sctp_prepare_initack_chunk" function.
332 * However, for debugging purposes it is nice to have a message printed out
333 * for these corner-case scenarios.
334 */
335 if (sctp_conn->state != SCTP_STATE_CLOSED)
336 { /* UNEXPECTED scenario */
337 switch (sctp_conn->state)
338 {
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100339 case SCTP_STATE_COOKIE_WAIT:
Marco Varlese191a5942017-10-30 18:17:21 +0100340 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100341 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100342 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200343 b0, &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100344 return SCTP_ERROR_NONE;
345 case SCTP_STATE_COOKIE_ECHOED:
346 case SCTP_STATE_SHUTDOWN_ACK_SENT:
Marco Varlese191a5942017-10-30 18:17:21 +0100347 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100348 if (sctp_conn->forming_association_changed == 0)
349 sctp_prepare_initack_chunk_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100350 SCTP_PRIMARY_PATH_IDX,
Marco Varlese216c35b2018-04-17 16:41:51 +0200351 b0, &ip4_addr,
352 &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100353 else
354 sctp_prepare_abort_for_collision (sctp_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100355 SCTP_PRIMARY_PATH_IDX, b0,
Marco Varlese216c35b2018-04-17 16:41:51 +0200356 &ip4_addr, &ip6_addr);
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100357 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100358 }
359 }
360
361 if (sctp_hdr->verification_tag != 0x0)
362 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
363
364 /*
365 * It is not possible to bundle any other CHUNK with the INIT chunk
366 */
367 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
368 return SCTP_ERROR_BUNDLING_VIOLATION;
369
370 /* Save the INITIATE_TAG of the remote peer for this connection:
371 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
372 sctp_conn->remote_tag = init_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100373 sctp_conn->remote_initial_tsn =
374 clib_net_to_host_u32 (init_chunk->initial_tsn);
375 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
376 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
377 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
378 sctp_conn->remote_initial_tsn);
379
Marco Varlese9e09ff32018-03-05 12:31:45 +0100380 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100381 /*
382 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
383 * optional parameters have been sent with the INIT chunk and we need to parse them.
384 */
385 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
386 if (length > sizeof (sctp_init_chunk_t))
387 {
388 /* There are optional parameters in the INIT chunk */
389 u16 pointer_offset = sizeof (sctp_init_chunk_t);
390 while (pointer_offset < length)
391 {
392 sctp_opt_params_hdr_t *opt_params_hdr =
393 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
394
395 switch (clib_net_to_host_u16 (opt_params_hdr->type))
396 {
397 case SCTP_IPV4_ADDRESS_TYPE:
398 {
399 sctp_ipv4_addr_param_t *ipv4 =
400 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese216c35b2018-04-17 16:41:51 +0200401 clib_memcpy (&ip4_addr, &ipv4->address,
Marco Varlese191a5942017-10-30 18:17:21 +0100402 sizeof (ip4_address_t));
403
Marco Varlese216c35b2018-04-17 16:41:51 +0200404 if (sctp_sub_connection_add_ip4 (vlib_get_main (),
405 &sctp_conn->sub_conn
406 [SCTP_PRIMARY_PATH_IDX].connection.
407 lcl_ip.ip4,
408 &ipv4->address) ==
409 SCTP_ERROR_NONE)
410 add_ip4 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100411
412 break;
413 }
414 case SCTP_IPV6_ADDRESS_TYPE:
415 {
416 sctp_ipv6_addr_param_t *ipv6 =
417 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese216c35b2018-04-17 16:41:51 +0200418 clib_memcpy (&ip6_addr, &ipv6->address,
Marco Varlese191a5942017-10-30 18:17:21 +0100419 sizeof (ip6_address_t));
420
Marco Varlese216c35b2018-04-17 16:41:51 +0200421 if (sctp_sub_connection_add_ip6 (vlib_get_main (),
422 &sctp_conn->sub_conn
423 [SCTP_PRIMARY_PATH_IDX].connection.
424 lcl_ip.ip6,
425 &ipv6->address) ==
426 SCTP_ERROR_NONE)
427 add_ip6 = 1;
Marco Varlese191a5942017-10-30 18:17:21 +0100428
429 break;
430 }
431 case SCTP_COOKIE_PRESERVATIVE_TYPE:
432 {
433 sctp_cookie_preservative_param_t *cookie_pres =
434 (sctp_cookie_preservative_param_t *) opt_params_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100435 sctp_conn->peer_cookie_life_span_increment =
436 cookie_pres->life_span_inc;
Marco Varlese191a5942017-10-30 18:17:21 +0100437 break;
438 }
439 case SCTP_HOSTNAME_ADDRESS_TYPE:
440 {
441 sctp_hostname_param_t *hostname_addr =
442 (sctp_hostname_param_t *) opt_params_hdr;
443 clib_memcpy (hostname, hostname_addr->hostname,
444 FQDN_MAX_LENGTH);
445 break;
446 }
447 case SCTP_SUPPORTED_ADDRESS_TYPES:
448 {
449 /* TODO */
450 break;
451 }
452 }
453 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
454 }
455 }
456
457 /* Reuse buffer to make init-ack and send */
Marco Varlese216c35b2018-04-17 16:41:51 +0200458 sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
459 add_ip4, &ip6_addr, add_ip6);
Marco Varlese191a5942017-10-30 18:17:21 +0100460 return SCTP_ERROR_NONE;
461}
462
463always_inline u16
464sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
465 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
466 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
467 u16 sctp_implied_length)
468{
469 sctp_init_ack_chunk_t *init_ack_chunk =
470 (sctp_init_ack_chunk_t *) (sctp_hdr);
471
472 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
473 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
474 {
475 return SCTP_ERROR_INVALID_TAG;
476 }
477
478 /*
479 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
480 */
481 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
482 return SCTP_ERROR_BUNDLING_VIOLATION;
483
484 return SCTP_ERROR_NONE;
485}
486
487always_inline u16
488sctp_handle_init_ack (sctp_header_t * sctp_hdr,
489 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100490 sctp_connection_t * sctp_conn, u8 idx,
491 vlib_buffer_t * b0, u16 sctp_implied_length)
Marco Varlese191a5942017-10-30 18:17:21 +0100492{
493 sctp_init_ack_chunk_t *init_ack_chunk =
494 (sctp_init_ack_chunk_t *) (sctp_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100495
496 char hostname[FQDN_MAX_LENGTH];
497
498 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
499 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
500 {
501 return SCTP_ERROR_INVALID_TAG;
502 }
503
504 /*
505 * It is not possible to bundle any other CHUNK with the INIT chunk
506 */
507 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
508 return SCTP_ERROR_BUNDLING_VIOLATION;
509
Marco Varlese9e09ff32018-03-05 12:31:45 +0100510 /* Stop the T1_INIT timer */
511 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
512
Marco Varlese21c8baf2018-02-02 17:17:51 +0100513 sctp_calculate_rto (sctp_conn, idx);
514
Marco Varlese191a5942017-10-30 18:17:21 +0100515 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
516 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100517 sctp_conn->remote_initial_tsn =
518 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
519 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
520 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
521 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
522 sctp_conn->remote_initial_tsn);
Marco Varlese9e09ff32018-03-05 12:31:45 +0100523 sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100524
525 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
526
527 if (length > sizeof (sctp_init_ack_chunk_t))
528 /*
529 * There are optional parameters in the INIT ACK chunk
530 */
531 {
532 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
533
534 while (pointer_offset < length)
535 {
536 sctp_opt_params_hdr_t *opt_params_hdr =
537 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
538 pointer_offset);
539
540 switch (clib_net_to_host_u16 (opt_params_hdr->type))
541 {
542 case SCTP_IPV4_ADDRESS_TYPE:
543 {
544 sctp_ipv4_addr_param_t *ipv4 =
545 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100546
Marco Varlese3c6a9762018-03-01 11:19:59 +0100547 sctp_sub_connection_add_ip4 (vlib_get_main (),
548 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100549 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100550 lcl_ip.ip4, &ipv4->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100551
552 break;
553 }
554 case SCTP_IPV6_ADDRESS_TYPE:
555 {
556 sctp_ipv6_addr_param_t *ipv6 =
557 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100558
Marco Varlese3c6a9762018-03-01 11:19:59 +0100559 sctp_sub_connection_add_ip6 (vlib_get_main (),
560 &sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100561 [SCTP_PRIMARY_PATH_IDX].connection.
Marco Varlese3c6a9762018-03-01 11:19:59 +0100562 lcl_ip.ip6, &ipv6->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100563
564 break;
565 }
566 case SCTP_STATE_COOKIE_TYPE:
567 {
568 sctp_state_cookie_param_t *state_cookie_param =
569 (sctp_state_cookie_param_t *) opt_params_hdr;
570
Marco Varlese63777e52018-04-18 08:50:57 +0200571 clib_memcpy (&(sctp_conn->cookie_param), state_cookie_param,
Marco Varlese191a5942017-10-30 18:17:21 +0100572 sizeof (sctp_state_cookie_param_t));
Marco Varlese63777e52018-04-18 08:50:57 +0200573
Marco Varlese191a5942017-10-30 18:17:21 +0100574 break;
575 }
576 case SCTP_HOSTNAME_ADDRESS_TYPE:
577 {
578 sctp_hostname_param_t *hostname_addr =
579 (sctp_hostname_param_t *) opt_params_hdr;
580 clib_memcpy (hostname, hostname_addr->hostname,
581 FQDN_MAX_LENGTH);
582 break;
583 }
584 case SCTP_UNRECOGNIZED_TYPE:
585 {
586 break;
587 }
588 }
589 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
590 /* This indicates something really bad happened */
591 if (increment == 0)
592 {
593 return SCTP_ERROR_INVALID_TAG;
594 }
595 pointer_offset += increment;
596 }
597 }
598
Marco Varlese9e09ff32018-03-05 12:31:45 +0100599 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100600
601 /* Start the T1_COOKIE timer */
Marco Varlese54432f82018-02-15 17:01:56 +0100602 sctp_timer_set (sctp_conn, idx,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100603 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
Marco Varlese191a5942017-10-30 18:17:21 +0100604
605 return SCTP_ERROR_NONE;
606}
607
Marco Varlese91389ac2018-01-31 11:00:01 +0100608/** Enqueue data out-of-order for delivery to application */
609always_inline int
610sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
611 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
612{
613 int written, error = SCTP_ERROR_ENQUEUED;
614
615 written =
616 session_enqueue_stream_connection (&sctp_conn->
617 sub_conn[conn_idx].connection, b, 0,
618 1 /* queue event */ ,
619 0);
620
621 /* Update next_tsn_expected */
622 if (PREDICT_TRUE (written == data_len))
623 {
624 sctp_conn->next_tsn_expected += written;
625
626 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
627 sctp_conn->sub_conn[conn_idx].connection.c_index,
628 written, data_len);
629 }
630 /* If more data written than expected, account for out-of-order bytes. */
631 else if (written > data_len)
632 {
633 sctp_conn->next_tsn_expected += written;
634
635 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
636 sctp_conn->sub_conn[conn_idx].connection.c_index,
637 written, data_len);
638 }
639 else if (written > 0)
640 {
641 /* We've written something but FIFO is probably full now */
642 sctp_conn->next_tsn_expected += written;
643
644 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
645
646 SCTP_ADV_DBG
647 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
648 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
649 }
650 else
651 {
652 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
653 sctp_conn->sub_conn[conn_idx].connection.c_index);
654
655 return SCTP_ERROR_FIFO_FULL;
656 }
657
658 /* TODO: Update out_of_order_map & SACK list */
659
660 return error;
661}
662
Marco Varlese191a5942017-10-30 18:17:21 +0100663/** Enqueue data for delivery to application */
664always_inline int
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100665sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100666 u16 data_len, u8 conn_idx)
667{
668 int written, error = SCTP_ERROR_ENQUEUED;
669
670 written =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100671 session_enqueue_stream_connection (&sctp_conn->
672 sub_conn[conn_idx].connection, b, 0,
673 1 /* queue event */ ,
674 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100675
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100676 /* Update next_tsn_expected */
Marco Varlese191a5942017-10-30 18:17:21 +0100677 if (PREDICT_TRUE (written == data_len))
678 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100679 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100680
681 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100682 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100683 written, data_len);
684 }
685 /* If more data written than expected, account for out-of-order bytes. */
686 else if (written > data_len)
687 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100688 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100689
690 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100691 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100692 written, data_len);
693 }
694 else if (written > 0)
695 {
696 /* We've written something but FIFO is probably full now */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100697 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100698
699 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
700
701 SCTP_ADV_DBG
702 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100703 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
Marco Varlese191a5942017-10-30 18:17:21 +0100704 }
705 else
706 {
707 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100708 sctp_conn->sub_conn[conn_idx].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100709
710 return SCTP_ERROR_FIFO_FULL;
711 }
712
713 return error;
714}
715
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100716always_inline u8
Marco Varlese54432f82018-02-15 17:01:56 +0100717sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100718{
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100719 if (sctp_conn->conn_config.never_delay_sack)
720 {
721 SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
722 return 0;
723 }
724
Marco Varlese9e09ff32018-03-05 12:31:45 +0100725 /* Section 4.4 of the RFC4960 */
726 if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
727 {
728 SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
729 sctp_state_to_string (sctp_conn->state));
730 return 0;
731 }
732
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100733 if (is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100734 {
735 SCTP_CONN_TRACKING_DBG
736 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
737 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100738 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100739 }
740
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100741 sctp_conn->ack_state += 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100742 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
743 {
744 SCTP_CONN_TRACKING_DBG
745 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
746 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100747 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100748 }
749
Marco Varlesea38783e2018-02-13 12:38:52 +0100750 return 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100751}
752
Marco Varlese91389ac2018-01-31 11:00:01 +0100753always_inline void
754sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
755 u8 * gapping)
756{
757 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
758 {
759 SCTP_CONN_TRACKING_DBG
760 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100761 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
Marco Varlese91389ac2018-01-31 11:00:01 +0100762 sctp_conn->next_tsn_expected, tsn,
763 sctp_conn->next_tsn_expected - tsn);
764
765 *gapping = 1;
766 }
767}
768
Marco Varlese191a5942017-10-30 18:17:21 +0100769always_inline u16
770sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100771 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100772 u16 * next0)
773{
774 u32 error = 0, n_data_bytes;
Marco Varlese91389ac2018-01-31 11:00:01 +0100775 u8 is_gapping = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100776
777 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
778 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
779 {
Marco Varlese87971682018-10-04 15:46:05 +0200780 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
781 sctp_conn->sub_conn[idx].enqueue_state = SCTP_ERROR_INVALID_TAG;
782 return sctp_conn->sub_conn[idx].enqueue_state;
Marco Varlese191a5942017-10-30 18:17:21 +0100783 }
784
785 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
786 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100787
788 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100789
790 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
Marco Varlese87971682018-10-04 15:46:05 +0200791 u32 chunk_len = vnet_sctp_get_chunk_length (&sctp_data_chunk->chunk_hdr) -
792 (sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_header_t));
793
794 ASSERT (vnet_buffer (b)->sctp.data_len);
795 ASSERT (chunk_len);
796
797 /* Padding was added: see RFC 4096 section 3.3.1 */
798 if (vnet_buffer (b)->sctp.data_len > chunk_len)
799 {
800 /* Let's change the data_len to the right amount calculated here now.
801 * We cannot do that in the generic sctp46_input_dispatcher node since
802 * that is common to all CHUNKS handling.
803 */
804 vnet_buffer (b)->sctp.data_len = chunk_len;
805 /* We need to change b->current_length so that downstream calls to
806 * session_enqueue_stream_connection (called by sctp_session_enqueue_data)
807 * push the correct amount of data to be enqueued.
808 */
809 b->current_length = chunk_len;
810 }
Marco Varlese191a5942017-10-30 18:17:21 +0100811 n_data_bytes = vnet_buffer (b)->sctp.data_len;
Marco Varlese191a5942017-10-30 18:17:21 +0100812
Marco Varlese91389ac2018-01-31 11:00:01 +0100813 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100814
815 sctp_conn->last_rcvd_tsn = tsn;
816
Marco Varlese191a5942017-10-30 18:17:21 +0100817 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
818
Marco Varlese91389ac2018-01-31 11:00:01 +0100819 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
820 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
821
822 if (bbit == 1 && ebit == 1) /* Unfragmented message */
823 {
824 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
825 * segments can be enqueued after fifo tail offset changes. */
Marco Varlese54432f82018-02-15 17:01:56 +0100826 if (PREDICT_FALSE (is_gapping == 1))
827 error =
828 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
829 else
830 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
Marco Varlese91389ac2018-01-31 11:00:01 +0100831 }
832 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
833 {
834 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
835 }
836 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
837 {
838 if (PREDICT_FALSE (is_gapping == 1))
839 error =
840 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
841 else
842 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
843 }
844 else /* Middle piece of a fragmented user message */
845 {
846 if (PREDICT_FALSE (is_gapping == 1))
847 error =
848 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
849 else
850 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
851 }
852 sctp_conn->last_rcvd_tsn = tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100853
Marco Varlese91389ac2018-01-31 11:00:01 +0100854 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
855
Marco Varlese54432f82018-02-15 17:01:56 +0100856 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100857 {
858 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
859 sctp_prepare_sack_chunk (sctp_conn, idx, b);
860 }
861 else
862 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese54432f82018-02-15 17:01:56 +0100863
864 sctp_conn->sub_conn[idx].enqueue_state = error;
Marco Varlese191a5942017-10-30 18:17:21 +0100865
866 return error;
867}
868
869always_inline u16
870sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
871 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100872 sctp_connection_t * sctp_conn, u8 idx,
873 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100874{
Marco Varlese93826732018-09-27 16:43:57 +0200875 u64 now = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +0100876
Marco Varlese91389ac2018-01-31 11:00:01 +0100877 sctp_cookie_echo_chunk_t *cookie_echo =
878 (sctp_cookie_echo_chunk_t *) sctp_hdr;
879
Marco Varlese191a5942017-10-30 18:17:21 +0100880 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
881 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
882 {
Marco Varlese87971682018-10-04 15:46:05 +0200883 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100884 return SCTP_ERROR_INVALID_TAG;
885 }
886
Marco Varlese21c8baf2018-02-02 17:17:51 +0100887 sctp_calculate_rto (sctp_conn, idx);
888
Marco Varlese93826732018-09-27 16:43:57 +0200889 u64 creation_time =
890 clib_net_to_host_u64 (cookie_echo->cookie.creation_time);
891 u64 cookie_lifespan =
Marco Varlese91389ac2018-01-31 11:00:01 +0100892 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
Marco Varlese93826732018-09-27 16:43:57 +0200893
Marco Varlese91389ac2018-01-31 11:00:01 +0100894 if (now > creation_time + cookie_lifespan)
895 {
896 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
897 now, creation_time, cookie_lifespan);
898 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
899 }
900
Marco Varlese54432f82018-02-15 17:01:56 +0100901 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +0100902
903 /* Change state */
904 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100905 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
Marco Varlesebe2251b2018-02-07 12:22:41 +0100906 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100907
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100908 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
909 sctp_conn->sub_conn[idx].RTO);
910
Marco Varlese15cc6a82018-02-21 12:39:52 +0100911 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
912
Marco Varlese191a5942017-10-30 18:17:21 +0100913 return SCTP_ERROR_NONE;
914
915}
916
917always_inline u16
918sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
919 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100920 sctp_connection_t * sctp_conn, u8 idx,
921 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100922{
Marco Varlese191a5942017-10-30 18:17:21 +0100923 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
924 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
925 {
Marco Varlese87971682018-10-04 15:46:05 +0200926 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100927 return SCTP_ERROR_INVALID_TAG;
928 }
929
Marco Varlese21c8baf2018-02-02 17:17:51 +0100930 sctp_calculate_rto (sctp_conn, idx);
931
Marco Varlese191a5942017-10-30 18:17:21 +0100932 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
933 /* Change state */
934 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100935 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
936
Marco Varlesefae40392018-02-14 15:38:35 +0100937 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100938
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100939 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
940 sctp_conn->sub_conn[idx].RTO);
941
Marco Varlese15cc6a82018-02-21 12:39:52 +0100942 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
943
Marco Varlese191a5942017-10-30 18:17:21 +0100944 return SCTP_ERROR_NONE;
945
946}
947
948always_inline uword
949sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
950 vlib_frame_t * from_frame, int is_ip4)
951{
952 sctp_main_t *tm = vnet_get_sctp_main ();
953
954 u32 n_left_from, next_index, *from, *to_next;
955 u32 my_thread_index = vm->thread_index;
956
957 from = vlib_frame_vector_args (from_frame);
958 n_left_from = from_frame->n_vectors;
959
960 next_index = node->cached_next_index;
961
962 while (n_left_from > 0)
963 {
964 u32 n_left_to_next;
965
966 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
967
968 while (n_left_from > 0 && n_left_to_next > 0)
969 {
970 u32 bi0;
971 vlib_buffer_t *b0;
972 sctp_header_t *sctp_hdr = 0;
973 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
974 ip4_header_t *ip4_hdr = 0;
975 ip6_header_t *ip6_hdr = 0;
976 sctp_connection_t *sctp_conn, *new_sctp_conn;
977 u16 sctp_implied_length = 0;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100978 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100979 u8 idx;
980
981 bi0 = from[0];
982 to_next[0] = bi0;
983 from += 1;
984 to_next += 1;
985 n_left_from -= 1;
986 n_left_to_next -= 1;
987
988 b0 = vlib_get_buffer (vm, bi0);
989
990 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
991 * will come from the half-open connections pool.
992 */
993 sctp_conn =
994 sctp_half_open_connection_get (vnet_buffer (b0)->
995 sctp.connection_index);
996
997 if (PREDICT_FALSE (sctp_conn == 0))
998 {
Marco Varlese191a5942017-10-30 18:17:21 +0100999 SCTP_ADV_DBG
1000 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1001 error0 = SCTP_ERROR_INVALID_CONNECTION;
1002 goto drop;
1003 }
1004 if (is_ip4)
1005 {
1006 ip4_hdr = vlib_buffer_get_current (b0);
1007 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001008 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001009 }
1010 else
1011 {
1012 ip6_hdr = vlib_buffer_get_current (b0);
1013 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001014 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001015 }
Marco Varlese191a5942017-10-30 18:17:21 +01001016
Marco Varlese04e5d642018-02-23 17:43:06 +01001017 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001018 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1019
Marco Varlese191a5942017-10-30 18:17:21 +01001020 sctp_chunk_hdr =
1021 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1022
1023 sctp_implied_length =
1024 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1025
1026 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1027
1028 switch (chunk_type)
1029 {
1030 case INIT_ACK:
1031 error0 =
1032 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1033 b0, sctp_implied_length);
1034
1035 if (error0 == SCTP_ERROR_NONE)
1036 {
1037 pool_get (tm->connections[my_thread_index], new_sctp_conn);
1038 clib_memcpy (new_sctp_conn, sctp_conn,
1039 sizeof (*new_sctp_conn));
1040 new_sctp_conn->sub_conn[idx].c_c_index =
1041 new_sctp_conn - tm->connections[my_thread_index];
1042 new_sctp_conn->sub_conn[idx].c_thread_index =
1043 my_thread_index;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001044 new_sctp_conn->sub_conn[idx].PMTU =
1045 sctp_conn->sub_conn[idx].PMTU;
Marco Varlese04e5d642018-02-23 17:43:06 +01001046 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001047
1048 if (sctp_half_open_connection_cleanup (sctp_conn))
1049 {
1050 SCTP_DBG
1051 ("Cannot cleanup half-open connection; not the owning thread");
1052 }
1053
1054 sctp_connection_timers_init (new_sctp_conn);
1055
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001056 sctp_init_cwnd (new_sctp_conn);
1057
Marco Varlese191a5942017-10-30 18:17:21 +01001058 error0 =
1059 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +01001060 new_sctp_conn, idx, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001061 sctp_implied_length);
1062
Marco Varlese191a5942017-10-30 18:17:21 +01001063 if (session_stream_connect_notify
1064 (&new_sctp_conn->sub_conn[idx].connection, 0))
1065 {
1066 SCTP_DBG
1067 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1068 new_sctp_conn->sub_conn[idx].connection.c_index);
1069 sctp_connection_cleanup (new_sctp_conn);
1070 goto drop;
1071 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001072 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001073 }
Marco Varlese191a5942017-10-30 18:17:21 +01001074 break;
1075
Marco Varlese200fa322018-02-26 16:33:54 +01001076 case OPERATION_ERROR:
1077 error0 =
1078 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1079 &next0);
1080 break;
1081
Marco Varlese191a5942017-10-30 18:17:21 +01001082 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1083 * are handled by the input-dispatcher function using the table-lookup
1084 * hence we should never get to the "default" case below.
1085 */
1086 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001087 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001088 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001089 goto drop;
1090 }
1091
1092 if (error0 != SCTP_ERROR_NONE)
1093 {
1094 clib_warning ("error while parsing chunk");
1095 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001096 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001097 goto drop;
1098 }
1099
1100 drop:
1101 b0->error = node->errors[error0];
1102 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1103 {
1104 sctp_rx_trace_t *t0 =
1105 vlib_add_trace (vm, node, b0, sizeof (*t0));
1106 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1107 }
1108
1109 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1110 n_left_to_next, bi0, next0);
1111 }
1112
1113 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1114 }
1115 return from_frame->n_vectors;
1116}
1117
1118static uword
1119sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1120 vlib_frame_t * from_frame)
1121{
1122 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1123}
1124
1125static uword
1126sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1127 vlib_frame_t * from_frame)
1128{
1129 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1130}
1131
1132u8 *
1133format_sctp_rx_trace_short (u8 * s, va_list * args)
1134{
1135 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1136 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1137 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1138
1139 s = format (s, "%d -> %d (%U)",
1140 clib_net_to_host_u16 (t->sctp_header.src_port),
1141 clib_net_to_host_u16 (t->sctp_header.dst_port),
1142 format_sctp_state, t->sctp_connection.state);
1143
1144 return s;
1145}
1146
1147/* *INDENT-OFF* */
1148VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1149{
1150 .function = sctp4_rcv_phase,
1151 .name = "sctp4-rcv",
1152 /* Takes a vector of packets. */
1153 .vector_size = sizeof (u32),
1154 .n_errors = SCTP_N_ERROR,
1155 .error_strings = sctp_error_strings,
1156 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1157 .next_nodes =
1158 {
1159#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1160 foreach_sctp_state_next
1161#undef _
1162 },
1163 .format_trace = format_sctp_rx_trace_short,
1164};
1165/* *INDENT-ON* */
1166
1167VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1168
1169/* *INDENT-OFF* */
1170VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1171{
1172 .function = sctp6_rcv_phase,
1173 .name = "sctp6-rcv",
1174 /* Takes a vector of packets. */
1175 .vector_size = sizeof (u32),
1176 .n_errors = SCTP_N_ERROR,
1177 .error_strings = sctp_error_strings,
1178 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1179 .next_nodes =
1180 {
1181#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1182 foreach_sctp_state_next
1183#undef _
1184 },
1185 .format_trace = format_sctp_rx_trace_short,
1186};
1187/* *INDENT-ON* */
1188
1189VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1190
1191vlib_node_registration_t sctp4_shutdown_phase_node;
1192vlib_node_registration_t sctp6_shutdown_phase_node;
1193
1194always_inline u16
1195sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1196 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001197 sctp_connection_t * sctp_conn, u8 idx,
1198 vlib_buffer_t * b0, u16 sctp_implied_length,
1199 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001200{
1201 sctp_shutdown_association_chunk_t *shutdown_chunk =
1202 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1203
1204 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1205 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1206 {
Marco Varlese87971682018-10-04 15:46:05 +02001207 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001208 return SCTP_ERROR_INVALID_TAG;
1209 }
1210
1211 /*
1212 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1213 */
1214 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1215 return SCTP_ERROR_BUNDLING_VIOLATION;
1216
1217 switch (sctp_conn->state)
1218 {
1219 case SCTP_STATE_ESTABLISHED:
1220 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1221 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
Marco Varlese54432f82018-02-15 17:01:56 +01001222 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001223 break;
1224
1225 case SCTP_STATE_SHUTDOWN_SENT:
Marco Varlese54432f82018-02-15 17:01:56 +01001226 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001227 break;
1228 }
1229
Marco Varlesebe2251b2018-02-07 12:22:41 +01001230 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1231
Marco Varlese191a5942017-10-30 18:17:21 +01001232 return SCTP_ERROR_NONE;
1233}
1234
1235always_inline u16
1236sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1237 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001238 sctp_connection_t * sctp_conn, u8 idx,
1239 vlib_buffer_t * b0, u16 sctp_implied_length,
1240 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001241{
1242 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1243 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1244
1245 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1246 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1247 {
Marco Varlese87971682018-10-04 15:46:05 +02001248 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001249 return SCTP_ERROR_INVALID_TAG;
1250 }
1251
1252 /*
1253 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1254 */
1255 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1256 return SCTP_ERROR_BUNDLING_VIOLATION;
1257
1258 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1259 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1260 * - STOP T2_SHUTDOWN timer
1261 * - SEND SHUTDOWN_COMPLETE chunk
1262 */
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001263 sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
Marco Varlesea38783e2018-02-13 12:38:52 +01001264
Marco Varlese54432f82018-02-15 17:01:56 +01001265 sctp_send_shutdown_complete (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001266
Marco Varlesebe2251b2018-02-07 12:22:41 +01001267 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1268
Marco Varlese191a5942017-10-30 18:17:21 +01001269 return SCTP_ERROR_NONE;
1270}
1271
1272always_inline u16
1273sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1274 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001275 sctp_connection_t * sctp_conn, u8 idx,
1276 vlib_buffer_t * b0, u16 sctp_implied_length,
1277 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001278{
1279 sctp_shutdown_complete_chunk_t *shutdown_complete =
1280 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1281
1282 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1283 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1284 {
Marco Varlese87971682018-10-04 15:46:05 +02001285 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001286 return SCTP_ERROR_INVALID_TAG;
1287 }
1288
1289 /*
1290 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1291 */
1292 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1293 return SCTP_ERROR_BUNDLING_VIOLATION;
1294
Marco Varlesef3ab4892018-02-19 15:23:13 +01001295 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1296
1297 stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese191a5942017-10-30 18:17:21 +01001298
1299 sctp_conn->state = SCTP_STATE_CLOSED;
1300
Marco Varlesefae40392018-02-14 15:38:35 +01001301 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001302
Marco Varlese191a5942017-10-30 18:17:21 +01001303 return SCTP_ERROR_NONE;
1304}
1305
1306always_inline uword
1307sctp46_shutdown_phase_inline (vlib_main_t * vm,
1308 vlib_node_runtime_t * node,
1309 vlib_frame_t * from_frame, int is_ip4)
1310{
1311 u32 n_left_from, next_index, *from, *to_next;
1312 u32 my_thread_index = vm->thread_index;
1313
1314 from = vlib_frame_vector_args (from_frame);
1315 n_left_from = from_frame->n_vectors;
1316
1317 next_index = node->cached_next_index;
1318
1319 while (n_left_from > 0)
1320 {
1321 u32 n_left_to_next;
1322
1323 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1324
1325 while (n_left_from > 0 && n_left_to_next > 0)
1326 {
1327 u32 bi0;
1328 vlib_buffer_t *b0;
1329 sctp_rx_trace_t *sctp_trace;
1330 sctp_header_t *sctp_hdr = 0;
1331 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1332 ip4_header_t *ip4_hdr = 0;
1333 ip6_header_t *ip6_hdr = 0;
1334 sctp_connection_t *sctp_conn;
1335 u16 sctp_implied_length = 0;
1336 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
Marco Varlese54432f82018-02-15 17:01:56 +01001337 u8 idx = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001338
1339 bi0 = from[0];
1340 to_next[0] = bi0;
1341 from += 1;
1342 to_next += 1;
1343 n_left_from -= 1;
1344 n_left_to_next -= 1;
1345
1346 b0 = vlib_get_buffer (vm, bi0);
1347 sctp_conn =
1348 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1349 my_thread_index);
1350
1351 if (PREDICT_FALSE (sctp_conn == 0))
1352 {
1353 SCTP_DBG
1354 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1355 error0 = SCTP_ERROR_INVALID_CONNECTION;
1356 goto drop;
1357 }
1358
1359 if (is_ip4)
1360 {
1361 ip4_hdr = vlib_buffer_get_current (b0);
1362 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001363 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001364 }
1365 else
1366 {
1367 ip6_hdr = vlib_buffer_get_current (b0);
1368 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001369 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001370 }
1371
1372 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1373 sctp_chunk_hdr = &full_hdr->common_hdr;
1374
1375 sctp_implied_length =
1376 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1377
Marco Varlesebe2251b2018-02-07 12:22:41 +01001378 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1379 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001380 {
1381 case SHUTDOWN:
1382 error0 =
Marco Varlesebe2251b2018-02-07 12:22:41 +01001383 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1384 idx, b0, sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001385 break;
1386
1387 case SHUTDOWN_ACK:
1388 error0 =
1389 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001390 idx, b0, sctp_implied_length,
1391 &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001392 break;
1393
1394 case SHUTDOWN_COMPLETE:
1395 error0 =
1396 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001397 sctp_conn, idx, b0,
1398 sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001399
1400 sctp_connection_cleanup (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001401 break;
1402
1403 /*
1404 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1405 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1406 */
1407 case DATA:
1408 error0 =
1409 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001410 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001411 break;
1412
Marco Varlese200fa322018-02-26 16:33:54 +01001413 case OPERATION_ERROR:
1414 error0 =
1415 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1416 &next0);
1417 break;
1418
Marco Varlese8c5f67f2018-02-27 09:38:31 +01001419 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1420 sctp_prepare_operation_error (sctp_conn, idx, b0,
1421 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1422 error0 = SCTP_ERROR_NONE;
1423 next0 = sctp_next_output (is_ip4);
1424 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001425 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1426 * are handled by the input-dispatcher function using the table-lookup
1427 * hence we should never get to the "default" case below.
1428 */
1429 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001430 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001431 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001432 goto drop;
1433 }
1434
1435 if (error0 != SCTP_ERROR_NONE)
1436 {
1437 clib_warning ("error while parsing chunk");
1438 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001439 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001440 goto drop;
1441 }
1442
1443 drop:
1444 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1445 {
1446 sctp_trace =
1447 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
Marco Varlesef429a932018-02-06 17:31:06 +01001448
1449 if (sctp_hdr != NULL)
1450 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1451 sizeof (sctp_trace->sctp_header));
1452
1453 if (sctp_conn != NULL)
1454 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1455 sizeof (sctp_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001456 }
1457
1458 b0->error = node->errors[error0];
1459
1460 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1461 n_left_to_next, bi0, next0);
1462 }
1463
1464 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1465 }
1466
1467 return from_frame->n_vectors;
1468
1469}
1470
1471static uword
1472sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1473 vlib_frame_t * from_frame)
1474{
1475 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1476}
1477
1478static uword
1479sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1480 vlib_frame_t * from_frame)
1481{
1482 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1483}
1484
1485/* *INDENT-OFF* */
1486VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1487{
1488 .function = sctp4_shutdown_phase,
1489 .name = "sctp4-shutdown",
1490 /* Takes a vector of packets. */
1491 .vector_size = sizeof (u32),
1492 .n_errors = SCTP_N_ERROR,
1493 .error_strings = sctp_error_strings,
1494 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1495 .next_nodes =
1496 {
1497#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1498 foreach_sctp_state_next
1499#undef _
1500 },
1501 .format_trace = format_sctp_rx_trace_short,
1502};
1503/* *INDENT-ON* */
1504
1505VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1506 sctp4_shutdown_phase);
1507
1508/* *INDENT-OFF* */
1509VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1510{
1511 .function = sctp6_shutdown_phase,
1512 .name = "sctp6-shutdown",
1513 /* Takes a vector of packets. */
1514 .vector_size = sizeof (u32),
1515 .n_errors = SCTP_N_ERROR,
1516 .error_strings = sctp_error_strings,
1517 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1518 .next_nodes =
1519 {
1520#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1521 foreach_sctp_state_next
1522#undef _
1523 },
1524 .format_trace = format_sctp_rx_trace_short,
1525};
1526/* *INDENT-ON* */
1527
1528VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1529 sctp6_shutdown_phase);
1530
1531vlib_node_registration_t sctp4_listen_phase_node;
1532vlib_node_registration_t sctp6_listen_phase_node;
1533
1534vlib_node_registration_t sctp4_established_phase_node;
1535vlib_node_registration_t sctp6_established_phase_node;
1536
1537always_inline u16
1538sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001539 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001540 u16 * next0)
1541{
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001542
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001543 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1544 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1545 {
Marco Varlese93826732018-09-27 16:43:57 +02001546 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001547 return SCTP_ERROR_INVALID_TAG;
1548 }
1549
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001550 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1551
Marco Varlese54432f82018-02-15 17:01:56 +01001552 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1553
Marco Varlesef3ab4892018-02-19 15:23:13 +01001554 /* Section 7.2.2; point (2) */
1555 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1556 sctp_conn->sub_conn[idx].partially_acked_bytes =
1557 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1558
1559 /* Section 7.2.2; point (5) */
1560 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1561 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1562
1563 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1564
Marco Varlese21c8baf2018-02-02 17:17:51 +01001565 sctp_calculate_rto (sctp_conn, idx);
1566
1567 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1568 sctp_conn->sub_conn[idx].RTO);
1569
1570 sctp_conn->sub_conn[idx].RTO_pending = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001571
Marco Varlesefae40392018-02-14 15:38:35 +01001572 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001573
1574 return SCTP_ERROR_NONE;
1575}
1576
1577always_inline u16
1578sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001579 sctp_connection_t * sctp_conn, u8 idx,
1580 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001581{
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001582 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1583 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1584 {
Marco Varlese87971682018-10-04 15:46:05 +02001585 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001586 return SCTP_ERROR_INVALID_TAG;
1587 }
1588
Marco Varlese54432f82018-02-15 17:01:56 +01001589 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001590
1591 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1592
Marco Varlese191a5942017-10-30 18:17:21 +01001593 return SCTP_ERROR_NONE;
1594}
1595
1596always_inline u16
1597sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001598 sctp_connection_t * sctp_conn, u8 idx,
1599 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001600{
Marco Varlese54432f82018-02-15 17:01:56 +01001601 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1602
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001603 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1604
1605 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1606 sctp_conn->sub_conn[idx].RTO);
1607
Marco Varlesefae40392018-02-14 15:38:35 +01001608 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001609
Marco Varlese191a5942017-10-30 18:17:21 +01001610 return SCTP_ERROR_NONE;
1611}
1612
1613always_inline void
Marco Varlese3c6a9762018-03-01 11:19:59 +01001614sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
Marco Varlese191a5942017-10-30 18:17:21 +01001615 u8 is_ip4, u8 evt, u8 val)
1616{
1617 if (PREDICT_TRUE (!val))
1618 return;
1619
1620 if (is_ip4)
Marco Varlese3c6a9762018-03-01 11:19:59 +01001621 vlib_node_increment_counter (vm, sctp4_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001622 else
Marco Varlese3c6a9762018-03-01 11:19:59 +01001623 vlib_node_increment_counter (vm, sctp6_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001624}
1625
1626always_inline uword
1627sctp46_listen_process_inline (vlib_main_t * vm,
1628 vlib_node_runtime_t * node,
1629 vlib_frame_t * from_frame, int is_ip4)
1630{
1631 u32 n_left_from, next_index, *from, *to_next;
1632 u32 my_thread_index = vm->thread_index;
1633
1634 from = vlib_frame_vector_args (from_frame);
1635 n_left_from = from_frame->n_vectors;
1636
1637 next_index = node->cached_next_index;
1638
1639 while (n_left_from > 0)
1640 {
1641 u32 n_left_to_next;
1642
1643 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1644
1645 while (n_left_from > 0 && n_left_to_next > 0)
1646 {
1647 u32 bi0;
1648 vlib_buffer_t *b0;
1649 sctp_header_t *sctp_hdr = 0;
1650 ip4_header_t *ip4_hdr;
1651 ip6_header_t *ip6_hdr;
1652 sctp_connection_t *child_conn;
1653 sctp_connection_t *sctp_listener;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001654 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
Marco Varlese191a5942017-10-30 18:17:21 +01001655
1656 bi0 = from[0];
1657 to_next[0] = bi0;
1658 from += 1;
1659 to_next += 1;
1660 n_left_from -= 1;
1661 n_left_to_next -= 1;
1662
1663 b0 = vlib_get_buffer (vm, bi0);
1664 sctp_listener =
1665 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1666
1667 if (is_ip4)
1668 {
1669 ip4_hdr = vlib_buffer_get_current (b0);
1670 sctp_hdr = ip4_next_header (ip4_hdr);
1671 }
1672 else
1673 {
1674 ip6_hdr = vlib_buffer_get_current (b0);
1675 sctp_hdr = ip6_next_header (ip6_hdr);
1676 }
1677
1678 child_conn =
1679 sctp_lookup_connection (sctp_listener->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001680 [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001681 my_thread_index, is_ip4);
1682
1683 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1684 {
1685 SCTP_DBG
1686 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001687 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001688 connection.c_index,
1689 sctp_state_to_string (child_conn->state));
1690 error0 = SCTP_ERROR_CREATE_EXISTS;
1691 goto drop;
1692 }
1693
1694 /* Create child session and send SYN-ACK */
1695 child_conn = sctp_connection_new (my_thread_index);
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001696 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1697 SCTP_PRIMARY_PATH_IDX;
1698 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001699 sctp_hdr->dst_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001700 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
Marco Varlese191a5942017-10-30 18:17:21 +01001701 sctp_hdr->src_port;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001702 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1703 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1704 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1705 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1706 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
Marco Varlese191a5942017-10-30 18:17:21 +01001707 child_conn->state = SCTP_STATE_CLOSED;
Marco Varlesee17bb712018-03-28 12:06:10 +02001708 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1709 sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1710 connection.fib_index;
Marco Varlese191a5942017-10-30 18:17:21 +01001711
1712 if (is_ip4)
1713 {
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001714 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001715 ip4_hdr->dst_address.as_u32;
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001716 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
Marco Varlese191a5942017-10-30 18:17:21 +01001717 ip4_hdr->src_address.as_u32;
1718 }
1719 else
1720 {
1721 clib_memcpy (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001722 sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
Marco Varlese191a5942017-10-30 18:17:21 +01001723 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1724 clib_memcpy (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001725 sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
Marco Varlese191a5942017-10-30 18:17:21 +01001726 &ip6_hdr->src_address, sizeof (ip6_address_t));
1727 }
1728
1729 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1730 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1731
1732 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
Marco Varlese216c35b2018-04-17 16:41:51 +02001733 if (chunk_type != INIT && chunk_type != DATA
1734 && chunk_type != OPERATION_ERROR)
Marco Varlese191a5942017-10-30 18:17:21 +01001735 {
1736 SCTP_DBG
1737 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001738 child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese191a5942017-10-30 18:17:21 +01001739 connection.c_index, sctp_chunk_to_string (chunk_type));
1740
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001741 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001742 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001743 goto drop;
1744 }
1745
1746 u16 sctp_implied_length =
1747 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1748
1749 switch (chunk_type)
1750 {
1751 case INIT:
1752 sctp_connection_timers_init (child_conn);
1753
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001754 sctp_init_snd_vars (child_conn);
1755
Marco Varlese6e4d4a32018-03-12 12:36:59 +01001756 sctp_init_cwnd (child_conn);
1757
Marco Varlese191a5942017-10-30 18:17:21 +01001758 error0 =
1759 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1760 sctp_implied_length);
1761
Marco Varlese191a5942017-10-30 18:17:21 +01001762 if (error0 == SCTP_ERROR_NONE)
1763 {
1764 if (stream_session_accept
1765 (&child_conn->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001766 sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
Marco Varlese191a5942017-10-30 18:17:21 +01001767 sctp_listener->
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001768 sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
Marco Varlese191a5942017-10-30 18:17:21 +01001769 {
1770 clib_warning ("session accept fail");
1771 sctp_connection_cleanup (child_conn);
1772 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1773 goto drop;
1774 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001775 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001776 }
Marco Varlese191a5942017-10-30 18:17:21 +01001777 break;
1778
1779 /* Reception of a DATA chunk whilst in the CLOSED state is called
1780 * "Out of the Blue" packet and handling of the chunk needs special treatment
1781 * as per RFC4960 section 8.4
1782 */
1783 case DATA:
1784 break;
Marco Varlese200fa322018-02-26 16:33:54 +01001785
1786 case OPERATION_ERROR:
1787 error0 =
1788 sctp_handle_operation_err (sctp_hdr, child_conn,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01001789 SCTP_PRIMARY_PATH_IDX, b0, &next0);
Marco Varlese200fa322018-02-26 16:33:54 +01001790 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001791 }
1792
1793 drop:
1794 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1795 {
1796 sctp_rx_trace_t *t0 =
1797 vlib_add_trace (vm, node, b0, sizeof (*t0));
1798 clib_memcpy (&t0->sctp_header, sctp_hdr,
1799 sizeof (t0->sctp_header));
1800 clib_memcpy (&t0->sctp_connection, sctp_listener,
1801 sizeof (t0->sctp_connection));
1802 }
1803
1804 b0->error = node->errors[error0];
1805
1806 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1807 n_left_to_next, bi0, next0);
1808 }
1809 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1810
1811 }
1812 return from_frame->n_vectors;
1813}
1814
1815static uword
1816sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1817 vlib_frame_t * from_frame)
1818{
1819 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1820}
1821
1822static uword
1823sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1824 vlib_frame_t * from_frame)
1825{
1826 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1827}
1828
1829always_inline uword
1830sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1831 vlib_frame_t * from_frame, int is_ip4)
1832{
1833 u32 n_left_from, next_index, *from, *to_next;
1834 u32 my_thread_index = vm->thread_index, errors = 0;
1835
1836 from = vlib_frame_vector_args (from_frame);
1837 n_left_from = from_frame->n_vectors;
1838
1839 next_index = node->cached_next_index;
1840
1841 while (n_left_from > 0)
1842 {
1843 u32 n_left_to_next;
1844
1845 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1846
1847 while (n_left_from > 0 && n_left_to_next > 0)
1848 {
1849 u32 bi0;
1850 vlib_buffer_t *b0;
1851 sctp_header_t *sctp_hdr = 0;
1852 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1853 ip4_header_t *ip4_hdr = 0;
1854 ip6_header_t *ip6_hdr = 0;
1855 sctp_connection_t *sctp_conn;
Marco Varlesefae40392018-02-14 15:38:35 +01001856 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1857 SCTP_ESTABLISHED_PHASE_N_NEXT;
Marco Varlese191a5942017-10-30 18:17:21 +01001858 u8 idx;
1859
1860 bi0 = from[0];
1861 to_next[0] = bi0;
1862 from += 1;
1863 to_next += 1;
1864 n_left_from -= 1;
1865 n_left_to_next -= 1;
1866
1867 b0 = vlib_get_buffer (vm, bi0);
1868 sctp_conn =
1869 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1870 my_thread_index);
1871
1872 if (PREDICT_FALSE (sctp_conn == 0))
1873 {
1874 SCTP_DBG
1875 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1876 error0 = SCTP_ERROR_INVALID_CONNECTION;
1877 goto done;
1878 }
1879 if (is_ip4)
1880 {
1881 ip4_hdr = vlib_buffer_get_current (b0);
1882 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001883 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001884 }
1885 else
1886 {
1887 ip6_hdr = vlib_buffer_get_current (b0);
1888 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001889 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001890 }
1891
Marco Varlese04e5d642018-02-23 17:43:06 +01001892 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001893
Marco Varlese54432f82018-02-15 17:01:56 +01001894 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +01001895 sctp_chunk_hdr =
1896 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1897
1898 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1899
1900 switch (chunk_type)
1901 {
1902 case COOKIE_ECHO:
1903 error0 =
1904 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001905 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001906 break;
1907
1908 case COOKIE_ACK:
1909 error0 =
1910 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001911 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001912 break;
1913
1914 case SACK:
1915 error0 =
1916 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001917 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001918 break;
1919
1920 case HEARTBEAT:
1921 error0 =
1922 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001923 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001924 break;
1925
1926 case HEARTBEAT_ACK:
1927 error0 =
1928 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001929 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001930 break;
1931
1932 case DATA:
1933 error0 =
1934 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001935 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001936 break;
1937
Marco Varlese200fa322018-02-26 16:33:54 +01001938 case OPERATION_ERROR:
1939 error0 =
1940 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1941 &next0);
1942 break;
1943
Marco Varlese191a5942017-10-30 18:17:21 +01001944 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1945 * are handled by the input-dispatcher function using the table-lookup
1946 * hence we should never get to the "default" case below.
1947 */
1948 default:
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03001949 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001950 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001951 goto done;
1952 }
1953
1954 done:
1955 b0->error = node->errors[error0];
1956 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1957 {
1958 sctp_rx_trace_t *t0 =
1959 vlib_add_trace (vm, node, b0, sizeof (*t0));
1960 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1961 }
1962
1963 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1964 n_left_to_next, bi0, next0);
1965 }
1966
1967 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1968 }
1969
1970 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1971 my_thread_index);
1972
1973 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1974 sctp6_established_phase_node.index,
1975 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1976 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1977
1978 return from_frame->n_vectors;
1979}
1980
1981static uword
1982sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1983 vlib_frame_t * from_frame)
1984{
1985 return sctp46_established_phase_inline (vm, node, from_frame,
1986 1 /* is_ip4 */ );
1987}
1988
1989static uword
1990sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1991 vlib_frame_t * from_frame)
1992{
1993 return sctp46_established_phase_inline (vm, node, from_frame,
1994 0 /* is_ip4 */ );
1995}
1996
1997u8 *
1998format_sctp_rx_trace (u8 * s, va_list * args)
1999{
2000 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2001 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2002 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
2003 u32 indent = format_get_indent (s);
2004
2005 s = format (s, "%U\n%U%U",
2006 format_sctp_header, &t->sctp_header, 128,
2007 format_white_space, indent,
2008 format_sctp_connection, &t->sctp_connection, 1);
2009
2010 return s;
2011}
2012
2013/* *INDENT-OFF* */
2014VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
2015{
2016 .function = sctp4_listen_phase,
2017 .name = "sctp4-listen",
2018 /* Takes a vector of packets. */
2019 .vector_size = sizeof (u32),
2020 .n_errors = SCTP_N_ERROR,
2021 .error_strings = sctp_error_strings,
2022 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2023 .next_nodes =
2024 {
2025#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2026 foreach_sctp_state_next
2027#undef _
2028 },
2029 .format_trace = format_sctp_rx_trace_short,
2030};
2031/* *INDENT-ON* */
2032
2033VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
2034
2035/* *INDENT-OFF* */
2036VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
2037{
2038 .function = sctp6_listen_phase,
2039 .name = "sctp6-listen",
2040 /* Takes a vector of packets. */
2041 .vector_size = sizeof (u32),
2042 .n_errors = SCTP_N_ERROR,
2043 .error_strings = sctp_error_strings,
2044 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2045 .next_nodes =
2046 {
2047#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2048 foreach_sctp_state_next
2049#undef _
2050 },
2051 .format_trace = format_sctp_rx_trace_short,
2052};
2053/* *INDENT-ON* */
2054
2055VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
2056
2057/* *INDENT-OFF* */
2058VLIB_REGISTER_NODE (sctp4_established_phase_node) =
2059{
2060 .function = sctp4_established_phase,
2061 .name = "sctp4-established",
2062 /* Takes a vector of packets. */
2063 .vector_size = sizeof (u32),
2064 .n_errors = SCTP_N_ERROR,
2065 .error_strings = sctp_error_strings,
2066 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2067 .next_nodes =
2068 {
2069#define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2070 foreach_sctp_state_next
2071#undef _
2072 },
2073 .format_trace = format_sctp_rx_trace_short,
2074};
2075/* *INDENT-ON* */
2076
2077VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
2078 sctp4_established_phase);
2079
2080/* *INDENT-OFF* */
2081VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2082{
2083 .function = sctp6_established_phase,
2084 .name = "sctp6-established",
2085 /* Takes a vector of packets. */
2086 .vector_size = sizeof (u32),
2087 .n_errors = SCTP_N_ERROR,
2088 .error_strings = sctp_error_strings,
2089 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2090 .next_nodes =
2091 {
2092#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2093 foreach_sctp_state_next
2094#undef _
2095 },
2096 .format_trace = format_sctp_rx_trace_short,
2097};
2098/* *INDENT-ON* */
2099
2100VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2101 sctp6_established_phase);
2102
2103/*
2104 * This is the function executed first for the SCTP graph.
2105 * It takes care of doing the initial message parsing and
2106 * dispatch to the specialized function.
2107 */
2108always_inline uword
2109sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2110 vlib_frame_t * from_frame, int is_ip4)
2111{
2112 u32 n_left_from, next_index, *from, *to_next;
2113 u32 my_thread_index = vm->thread_index;
2114 u8 is_filtered;
2115 sctp_main_t *tm = vnet_get_sctp_main ();
2116
2117 from = vlib_frame_vector_args (from_frame);
2118 n_left_from = from_frame->n_vectors;
2119 next_index = node->cached_next_index;
2120 sctp_set_time_now (my_thread_index);
2121
2122 while (n_left_from > 0)
2123 {
2124 u32 n_left_to_next;
2125
2126 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2127
2128 while (n_left_from > 0 && n_left_to_next > 0)
2129 {
2130 int n_advance_bytes0, n_data_bytes0;
2131 u32 bi0, fib_index0;
2132 vlib_buffer_t *b0;
2133 sctp_header_t *sctp_hdr = 0;
2134 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2135 sctp_connection_t *sctp_conn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002136 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01002137 ip4_header_t *ip4_hdr;
2138 ip6_header_t *ip6_hdr;
2139 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2140
2141 bi0 = from[0];
2142 to_next[0] = bi0;
2143 from += 1;
2144 to_next += 1;
2145 n_left_from -= 1;
2146 n_left_to_next -= 1;
2147
2148 b0 = vlib_get_buffer (vm, bi0);
Marco Varlese3c6a9762018-03-01 11:19:59 +01002149 vnet_buffer (b0)->sctp.flags = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01002150 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2151
2152 /* Checksum computed by ipx_local no need to compute again */
2153
2154 if (is_ip4)
2155 {
2156 ip4_hdr = vlib_buffer_get_current (b0);
2157 sctp_hdr = ip4_next_header (ip4_hdr);
2158
2159 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2160 sctp_chunk_hdr = &full_hdr->common_hdr;
2161
2162 n_advance_bytes0 =
2163 (ip4_header_bytes (ip4_hdr) +
2164 sizeof (sctp_payload_data_chunk_t));
2165 n_data_bytes0 =
2166 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2167
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002168 trans_conn = session_lookup_connection_wt4 (fib_index0,
2169 &ip4_hdr->dst_address,
2170 &ip4_hdr->src_address,
2171 sctp_hdr->dst_port,
2172 sctp_hdr->src_port,
2173 TRANSPORT_PROTO_SCTP,
2174 my_thread_index,
2175 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002176 }
2177 else
2178 {
2179 ip6_hdr = vlib_buffer_get_current (b0);
2180 sctp_hdr = ip6_next_header (ip6_hdr);
2181
2182 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2183 sctp_chunk_hdr = &full_hdr->common_hdr;
2184
2185 n_advance_bytes0 = sctp_header_bytes ();
2186 n_data_bytes0 =
2187 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2188 n_advance_bytes0;
2189 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2190
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002191 trans_conn = session_lookup_connection_wt6 (fib_index0,
2192 &ip6_hdr->dst_address,
2193 &ip6_hdr->src_address,
2194 sctp_hdr->dst_port,
2195 sctp_hdr->src_port,
2196 TRANSPORT_PROTO_SCTP,
2197 my_thread_index,
2198 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002199 }
2200
2201 /* Length check */
2202 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2203 {
2204 error0 = SCTP_ERROR_LENGTH;
2205 goto done;
2206 }
2207
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002208 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01002209 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2210
Marco Varlesefae40392018-02-14 15:38:35 +01002211 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2212 if (chunk_type >= UNKNOWN)
2213 {
2214 clib_warning
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002215 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2216
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002217 sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002218 b0, UNRECOGNIZED_CHUNK_TYPE);
2219
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +03002220 error0 = SCTP_ERROR_UNKNOWN_CHUNK;
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002221 next0 = sctp_next_output (is_ip4);
Marco Varlesefae40392018-02-14 15:38:35 +01002222 goto done;
2223 }
2224
Marco Varlese191a5942017-10-30 18:17:21 +01002225 vnet_buffer (b0)->sctp.hdr_offset =
2226 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2227
2228 /* Session exists */
2229 if (PREDICT_TRUE (0 != sctp_conn))
2230 {
2231 /* Save connection index */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002232 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
Marco Varlese191a5942017-10-30 18:17:21 +01002233 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2234 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2235
Marco Varlesefae40392018-02-14 15:38:35 +01002236 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2237 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
Marco Varlese191a5942017-10-30 18:17:21 +01002238
Marco Varlesef3ab4892018-02-19 15:23:13 +01002239 SCTP_DBG_STATE_MACHINE
Marco Varlese15cc6a82018-02-21 12:39:52 +01002240 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
Marco Varlesef3ab4892018-02-19 15:23:13 +01002241 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002242 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002243 connection.s_index,
Marco Varlesec7fe4f32018-03-05 15:12:29 +01002244 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002245 connection.c_index, trans_conn, sctp_conn,
2246 sctp_state_to_string (sctp_conn->state),
Marco Varlesef3ab4892018-02-19 15:23:13 +01002247 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
Marco Varlese191a5942017-10-30 18:17:21 +01002248
Marco Varlesefae40392018-02-14 15:38:35 +01002249 if (chunk_type == DATA)
Marco Varlese191a5942017-10-30 18:17:21 +01002250 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2251 n_advance_bytes0, n_data_bytes0);
2252
2253 }
2254 else
2255 {
2256 if (is_filtered)
2257 {
2258 next0 = SCTP_INPUT_NEXT_DROP;
2259 error0 = SCTP_ERROR_FILTERED;
2260 }
2261 else if ((is_ip4 && tm->punt_unknown4) ||
2262 (!is_ip4 && tm->punt_unknown6))
2263 {
2264 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2265 error0 = SCTP_ERROR_PUNT;
2266 }
2267 else
2268 {
2269 next0 = SCTP_INPUT_NEXT_DROP;
2270 error0 = SCTP_ERROR_NO_LISTENER;
2271 }
2272 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2273 phase_to_string (next0));
2274 sctp_conn = 0;
2275 }
2276
2277 done:
2278 b0->error = error0 ? node->errors[error0] : 0;
2279
2280 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2281 {
2282 sctp_rx_trace_t *t0 =
2283 vlib_add_trace (vm, node, b0, sizeof (*t0));
2284 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2285 }
2286 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2287 n_left_to_next, bi0, next0);
2288 }
2289
2290 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2291 }
2292 return from_frame->n_vectors;
2293}
2294
2295static uword
2296sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2297 vlib_frame_t * from_frame)
2298{
2299 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2300}
2301
2302static uword
2303sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2304 vlib_frame_t * from_frame)
2305{
2306 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2307}
2308
2309/* *INDENT-OFF* */
2310VLIB_REGISTER_NODE (sctp4_input_node) =
2311{
2312 .function = sctp4_input_dispatcher,
2313 .name = "sctp4-input",
2314 /* Takes a vector of packets. */
2315 .vector_size = sizeof (u32),
2316 .n_errors = SCTP_N_ERROR,
2317 .error_strings = sctp_error_strings,
2318 .n_next_nodes = SCTP_INPUT_N_NEXT,
2319 .next_nodes =
2320 {
2321#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2322 foreach_sctp4_input_next
2323#undef _
2324 },
2325 .format_buffer = format_sctp_header,
2326 .format_trace = format_sctp_rx_trace,
2327};
2328/* *INDENT-ON* */
2329
2330VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2331
2332/* *INDENT-OFF* */
2333VLIB_REGISTER_NODE (sctp6_input_node) =
2334{
2335 .function = sctp6_input_dispatcher,
2336 .name = "sctp6-input",
2337 /* Takes a vector of packets. */
2338 .vector_size = sizeof (u32),
2339 .n_errors = SCTP_N_ERROR,
2340 .error_strings = sctp_error_strings,
2341 .n_next_nodes = SCTP_INPUT_N_NEXT,
2342 .next_nodes =
2343 {
2344#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2345 foreach_sctp6_input_next
2346#undef _
2347 },
2348 .format_buffer = format_sctp_header,
2349 .format_trace = format_sctp_rx_trace,
2350};
2351/* *INDENT-ON* */
2352
2353VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2354
2355vlib_node_registration_t sctp4_input_node;
2356vlib_node_registration_t sctp6_input_node;
2357
2358static void
2359sctp_dispatch_table_init (sctp_main_t * tm)
2360{
2361 int i, j;
2362 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2363 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2364 {
2365 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2366 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2367 }
2368
2369#define _(t,f,n,e) \
2370do { \
2371 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2372 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2373} while (0)
2374
2375 /*
2376 * SCTP STATE-MACHINE states:
2377 *
2378 * _(CLOSED, "CLOSED") \
2379 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2380 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2381 * _(ESTABLISHED, "ESTABLISHED") \
2382 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2383 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2384 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2385 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2386 */
Marco Varlesef3ab4892018-02-19 15:23:13 +01002387 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002388 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2389 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2390 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2391 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2392 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2393 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2394 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2395 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2396 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2397 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2398 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2399 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2400 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2401 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002402 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002403
Marco Varlese200fa322018-02-26 16:33:54 +01002404 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002405 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2406 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2407 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2408 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2409 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2410 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2411 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2412 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2413 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2414 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2415 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2416 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2417 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2418 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002419 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2420 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002421
2422 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2423 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2424 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2425 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2426 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2427 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2428 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2429 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2430 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2431 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2432 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2433 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2434 SCTP_ERROR_NONE);
2435 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2436 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2437 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002438 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2439 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002440
2441 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2442 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2443 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2444 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2445 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2446 SCTP_ERROR_NONE);
2447 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2448 SCTP_ERROR_NONE);
2449 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2450 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2451 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2452 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2453 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2454 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2455 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2456 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2457 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002458 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2459 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002460
2461 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2462 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2463 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2464 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2465 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2466 SCTP_ERROR_NONE);
2467 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2468 SCTP_ERROR_NONE);
2469 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2470 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2471 SCTP_ERROR_NONE);
2472 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2473 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002474 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2475 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002476 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2477 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2478 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2479 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002480 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2481 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002482
2483 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2484 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2485 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2486 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2487 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2488 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2489 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2490 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2491 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2492 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002493 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2494 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002495 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2496 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2497 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2498 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002499 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2500 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002501
2502 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2503 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2504 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2505 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2506 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2507 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2508 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2509 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2510 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2511 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002512 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2513 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002514 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2515 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2516 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2517 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002518 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2519 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002520
2521 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
Marco Varleseeacf3cf2018-02-26 14:52:25 +01002522 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
Marco Varlese191a5942017-10-30 18:17:21 +01002523 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2524 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2525 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2526 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2527 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2528 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2529 _(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 +01002530 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2531 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002532 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2533 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2534 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2535 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2536 SCTP_ERROR_NONE);
Marco Varlese200fa322018-02-26 16:33:54 +01002537 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2538 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002539
2540 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2541
2542#undef _
2543}
2544
2545clib_error_t *
2546sctp_input_init (vlib_main_t * vm)
2547{
2548 clib_error_t *error = 0;
2549 sctp_main_t *tm = vnet_get_sctp_main ();
2550
2551 if ((error = vlib_call_init_function (vm, sctp_init)))
2552 return error;
2553
2554 /* Initialize dispatch table. */
2555 sctp_dispatch_table_init (tm);
2556
2557 return error;
2558}
2559
2560VLIB_INIT_FUNCTION (sctp_input_init);
2561
2562/*
2563 * fd.io coding-style-patch-verification: ON
2564 *
2565 * Local Variables:
2566 * eval: (c-set-style "gnu")
2567 * End:
2568 */