blob: 00d0a61feff1fa23ee79597d52a31a88821d621a [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);
322 ip4_address_t *ip4_addr = 0;
323 ip6_address_t *ip6_addr = 0;
324 char hostname[FQDN_MAX_LENGTH];
325
326 /* Check the current state of the connection
327 *
328 * The logic required by the RFC4960 Section 5.2.2 is already taken care of
329 * in the code below and by the "sctp_prepare_initack_chunk" function.
330 * However, for debugging purposes it is nice to have a message printed out
331 * for these corner-case scenarios.
332 */
333 if (sctp_conn->state != SCTP_STATE_CLOSED)
334 { /* UNEXPECTED scenario */
335 switch (sctp_conn->state)
336 {
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100337 case SCTP_STATE_COOKIE_WAIT:
Marco Varlese191a5942017-10-30 18:17:21 +0100338 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100339 sctp_prepare_initack_chunk_for_collision (sctp_conn,
340 MAIN_SCTP_SUB_CONN_IDX,
341 b0, ip4_addr, ip6_addr);
342 return SCTP_ERROR_NONE;
343 case SCTP_STATE_COOKIE_ECHOED:
344 case SCTP_STATE_SHUTDOWN_ACK_SENT:
Marco Varlese191a5942017-10-30 18:17:21 +0100345 SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100346 if (sctp_conn->forming_association_changed == 0)
347 sctp_prepare_initack_chunk_for_collision (sctp_conn,
348 MAIN_SCTP_SUB_CONN_IDX,
349 b0, ip4_addr, ip6_addr);
350 else
351 sctp_prepare_abort_for_collision (sctp_conn,
352 MAIN_SCTP_SUB_CONN_IDX, b0,
353 ip4_addr, ip6_addr);
354 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100355 }
356 }
357
358 if (sctp_hdr->verification_tag != 0x0)
359 return SCTP_ERROR_INVALID_TAG_FOR_INIT;
360
361 /*
362 * It is not possible to bundle any other CHUNK with the INIT chunk
363 */
364 if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
365 return SCTP_ERROR_BUNDLING_VIOLATION;
366
367 /* Save the INITIATE_TAG of the remote peer for this connection:
368 * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
369 sctp_conn->remote_tag = init_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100370 sctp_conn->remote_initial_tsn =
371 clib_net_to_host_u32 (init_chunk->initial_tsn);
372 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
373 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
374 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
375 sctp_conn->remote_initial_tsn);
376
Marco Varlese191a5942017-10-30 18:17:21 +0100377 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
378
379 /*
380 * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
381 * optional parameters have been sent with the INIT chunk and we need to parse them.
382 */
383 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
384 if (length > sizeof (sctp_init_chunk_t))
385 {
386 /* There are optional parameters in the INIT chunk */
387 u16 pointer_offset = sizeof (sctp_init_chunk_t);
388 while (pointer_offset < length)
389 {
390 sctp_opt_params_hdr_t *opt_params_hdr =
391 (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
392
393 switch (clib_net_to_host_u16 (opt_params_hdr->type))
394 {
395 case SCTP_IPV4_ADDRESS_TYPE:
396 {
397 sctp_ipv4_addr_param_t *ipv4 =
398 (sctp_ipv4_addr_param_t *) opt_params_hdr;
399 clib_memcpy (ip4_addr, &ipv4->address,
400 sizeof (ip4_address_t));
401
Marco Varlese3c6a9762018-03-01 11:19:59 +0100402 sctp_sub_connection_add_ip4 (vlib_get_main (),
403 &sctp_conn->sub_conn
404 [MAIN_SCTP_SUB_CONN_IDX].connection.
405 lcl_ip.ip4, &ipv4->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100406
407 break;
408 }
409 case SCTP_IPV6_ADDRESS_TYPE:
410 {
411 sctp_ipv6_addr_param_t *ipv6 =
412 (sctp_ipv6_addr_param_t *) opt_params_hdr;
413 clib_memcpy (ip6_addr, &ipv6->address,
414 sizeof (ip6_address_t));
415
Marco Varlese3c6a9762018-03-01 11:19:59 +0100416 sctp_sub_connection_add_ip6 (vlib_get_main (),
417 &sctp_conn->sub_conn
418 [MAIN_SCTP_SUB_CONN_IDX].connection.
419 lcl_ip.ip6, &ipv6->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100420
421 break;
422 }
423 case SCTP_COOKIE_PRESERVATIVE_TYPE:
424 {
425 sctp_cookie_preservative_param_t *cookie_pres =
426 (sctp_cookie_preservative_param_t *) opt_params_hdr;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100427 sctp_conn->peer_cookie_life_span_increment =
428 cookie_pres->life_span_inc;
Marco Varlese191a5942017-10-30 18:17:21 +0100429 break;
430 }
431 case SCTP_HOSTNAME_ADDRESS_TYPE:
432 {
433 sctp_hostname_param_t *hostname_addr =
434 (sctp_hostname_param_t *) opt_params_hdr;
435 clib_memcpy (hostname, hostname_addr->hostname,
436 FQDN_MAX_LENGTH);
437 break;
438 }
439 case SCTP_SUPPORTED_ADDRESS_TYPES:
440 {
441 /* TODO */
442 break;
443 }
444 }
445 pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
446 }
447 }
448
449 /* Reuse buffer to make init-ack and send */
Marco Varlese54432f82018-02-15 17:01:56 +0100450 sctp_prepare_initack_chunk (sctp_conn, MAIN_SCTP_SUB_CONN_IDX, b0, ip4_addr,
451 ip6_addr);
Marco Varlese191a5942017-10-30 18:17:21 +0100452 return SCTP_ERROR_NONE;
453}
454
455always_inline u16
456sctp_is_valid_init_ack (sctp_header_t * sctp_hdr,
457 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
458 sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
459 u16 sctp_implied_length)
460{
461 sctp_init_ack_chunk_t *init_ack_chunk =
462 (sctp_init_ack_chunk_t *) (sctp_hdr);
463
464 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
465 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
466 {
467 return SCTP_ERROR_INVALID_TAG;
468 }
469
470 /*
471 * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
472 */
473 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
474 return SCTP_ERROR_BUNDLING_VIOLATION;
475
476 return SCTP_ERROR_NONE;
477}
478
479always_inline u16
480sctp_handle_init_ack (sctp_header_t * sctp_hdr,
481 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100482 sctp_connection_t * sctp_conn, u8 idx,
483 vlib_buffer_t * b0, u16 sctp_implied_length)
Marco Varlese191a5942017-10-30 18:17:21 +0100484{
485 sctp_init_ack_chunk_t *init_ack_chunk =
486 (sctp_init_ack_chunk_t *) (sctp_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100487 sctp_state_cookie_param_t state_cookie;
488
489 char hostname[FQDN_MAX_LENGTH];
490
491 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
492 if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
493 {
494 return SCTP_ERROR_INVALID_TAG;
495 }
496
497 /*
498 * It is not possible to bundle any other CHUNK with the INIT chunk
499 */
500 if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
501 return SCTP_ERROR_BUNDLING_VIOLATION;
502
Marco Varlese21c8baf2018-02-02 17:17:51 +0100503 sctp_calculate_rto (sctp_conn, idx);
504
Marco Varlese191a5942017-10-30 18:17:21 +0100505 /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
506 sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100507 sctp_conn->remote_initial_tsn =
508 clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
509 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
510 sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
511 SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
512 sctp_conn->remote_initial_tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100513 sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
514
515 u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
516
517 if (length > sizeof (sctp_init_ack_chunk_t))
518 /*
519 * There are optional parameters in the INIT ACK chunk
520 */
521 {
522 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
523
524 while (pointer_offset < length)
525 {
526 sctp_opt_params_hdr_t *opt_params_hdr =
527 (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
528 pointer_offset);
529
530 switch (clib_net_to_host_u16 (opt_params_hdr->type))
531 {
532 case SCTP_IPV4_ADDRESS_TYPE:
533 {
534 sctp_ipv4_addr_param_t *ipv4 =
535 (sctp_ipv4_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100536
Marco Varlese3c6a9762018-03-01 11:19:59 +0100537 sctp_sub_connection_add_ip4 (vlib_get_main (),
538 &sctp_conn->sub_conn
539 [MAIN_SCTP_SUB_CONN_IDX].connection.
540 lcl_ip.ip4, &ipv4->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100541
542 break;
543 }
544 case SCTP_IPV6_ADDRESS_TYPE:
545 {
546 sctp_ipv6_addr_param_t *ipv6 =
547 (sctp_ipv6_addr_param_t *) opt_params_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +0100548
Marco Varlese3c6a9762018-03-01 11:19:59 +0100549 sctp_sub_connection_add_ip6 (vlib_get_main (),
550 &sctp_conn->sub_conn
551 [MAIN_SCTP_SUB_CONN_IDX].connection.
552 lcl_ip.ip6, &ipv6->address);
Marco Varlese191a5942017-10-30 18:17:21 +0100553
554 break;
555 }
556 case SCTP_STATE_COOKIE_TYPE:
557 {
558 sctp_state_cookie_param_t *state_cookie_param =
559 (sctp_state_cookie_param_t *) opt_params_hdr;
560
561 clib_memcpy (&state_cookie, state_cookie_param,
562 sizeof (sctp_state_cookie_param_t));
563 break;
564 }
565 case SCTP_HOSTNAME_ADDRESS_TYPE:
566 {
567 sctp_hostname_param_t *hostname_addr =
568 (sctp_hostname_param_t *) opt_params_hdr;
569 clib_memcpy (hostname, hostname_addr->hostname,
570 FQDN_MAX_LENGTH);
571 break;
572 }
573 case SCTP_UNRECOGNIZED_TYPE:
574 {
575 break;
576 }
577 }
578 u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
579 /* This indicates something really bad happened */
580 if (increment == 0)
581 {
582 return SCTP_ERROR_INVALID_TAG;
583 }
584 pointer_offset += increment;
585 }
586 }
587
Marco Varlese54432f82018-02-15 17:01:56 +0100588 sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, &state_cookie);
Marco Varlese191a5942017-10-30 18:17:21 +0100589
590 /* Start the T1_COOKIE timer */
Marco Varlese54432f82018-02-15 17:01:56 +0100591 sctp_timer_set (sctp_conn, idx,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100592 SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
Marco Varlese191a5942017-10-30 18:17:21 +0100593
594 return SCTP_ERROR_NONE;
595}
596
Marco Varlese91389ac2018-01-31 11:00:01 +0100597/** Enqueue data out-of-order for delivery to application */
598always_inline int
599sctp_session_enqueue_data_ooo (sctp_connection_t * sctp_conn,
600 vlib_buffer_t * b, u16 data_len, u8 conn_idx)
601{
602 int written, error = SCTP_ERROR_ENQUEUED;
603
604 written =
605 session_enqueue_stream_connection (&sctp_conn->
606 sub_conn[conn_idx].connection, b, 0,
607 1 /* queue event */ ,
608 0);
609
610 /* Update next_tsn_expected */
611 if (PREDICT_TRUE (written == data_len))
612 {
613 sctp_conn->next_tsn_expected += written;
614
615 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
616 sctp_conn->sub_conn[conn_idx].connection.c_index,
617 written, data_len);
618 }
619 /* If more data written than expected, account for out-of-order bytes. */
620 else if (written > data_len)
621 {
622 sctp_conn->next_tsn_expected += written;
623
624 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
625 sctp_conn->sub_conn[conn_idx].connection.c_index,
626 written, data_len);
627 }
628 else if (written > 0)
629 {
630 /* We've written something but FIFO is probably full now */
631 sctp_conn->next_tsn_expected += written;
632
633 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
634
635 SCTP_ADV_DBG
636 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
637 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
638 }
639 else
640 {
641 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
642 sctp_conn->sub_conn[conn_idx].connection.c_index);
643
644 return SCTP_ERROR_FIFO_FULL;
645 }
646
647 /* TODO: Update out_of_order_map & SACK list */
648
649 return error;
650}
651
Marco Varlese191a5942017-10-30 18:17:21 +0100652/** Enqueue data for delivery to application */
653always_inline int
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100654sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100655 u16 data_len, u8 conn_idx)
656{
657 int written, error = SCTP_ERROR_ENQUEUED;
658
659 written =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100660 session_enqueue_stream_connection (&sctp_conn->
661 sub_conn[conn_idx].connection, b, 0,
662 1 /* queue event */ ,
663 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100664
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100665 /* Update next_tsn_expected */
Marco Varlese191a5942017-10-30 18:17:21 +0100666 if (PREDICT_TRUE (written == data_len))
667 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100668 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100669
670 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100671 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100672 written, data_len);
673 }
674 /* If more data written than expected, account for out-of-order bytes. */
675 else if (written > data_len)
676 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100677 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100678
679 SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100680 sctp_conn->sub_conn[conn_idx].connection.c_index,
Marco Varlese191a5942017-10-30 18:17:21 +0100681 written, data_len);
682 }
683 else if (written > 0)
684 {
685 /* We've written something but FIFO is probably full now */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100686 sctp_conn->next_tsn_expected += written;
Marco Varlese191a5942017-10-30 18:17:21 +0100687
688 error = SCTP_ERROR_PARTIALLY_ENQUEUED;
689
690 SCTP_ADV_DBG
691 ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100692 sctp_conn->sub_conn[conn_idx].connection.c_index, written);
Marco Varlese191a5942017-10-30 18:17:21 +0100693 }
694 else
695 {
696 SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100697 sctp_conn->sub_conn[conn_idx].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100698
699 return SCTP_ERROR_FIFO_FULL;
700 }
701
702 return error;
703}
704
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100705always_inline u8
Marco Varlese54432f82018-02-15 17:01:56 +0100706sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100707{
Marco Varlesea38783e2018-02-13 12:38:52 +0100708 if (is_gapping != 0)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100709 {
710 SCTP_CONN_TRACKING_DBG
711 ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
712 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100713 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100714 }
715
716 if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
717 {
718 SCTP_CONN_TRACKING_DBG
719 ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
720 sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
Marco Varlesea38783e2018-02-13 12:38:52 +0100721 return 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100722 }
723
724 sctp_conn->ack_state += 1;
725
Marco Varlesea38783e2018-02-13 12:38:52 +0100726 return 1;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100727}
728
Marco Varlese91389ac2018-01-31 11:00:01 +0100729always_inline void
730sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
731 u8 * gapping)
732{
733 if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
734 {
735 SCTP_CONN_TRACKING_DBG
736 ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
Marco Varlese54432f82018-02-15 17:01:56 +0100737 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.c_index,
Marco Varlese91389ac2018-01-31 11:00:01 +0100738 sctp_conn->next_tsn_expected, tsn,
739 sctp_conn->next_tsn_expected - tsn);
740
741 *gapping = 1;
742 }
743}
744
Marco Varlese191a5942017-10-30 18:17:21 +0100745always_inline u16
746sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100747 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100748 u16 * next0)
749{
750 u32 error = 0, n_data_bytes;
Marco Varlese91389ac2018-01-31 11:00:01 +0100751 u8 is_gapping = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100752
753 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
754 if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
755 {
756 return SCTP_ERROR_INVALID_TAG;
757 }
758
759 vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
760 vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100761
762 u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100763
764 vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
765 n_data_bytes = vnet_buffer (b)->sctp.data_len;
766 ASSERT (n_data_bytes);
767
Marco Varlese91389ac2018-01-31 11:00:01 +0100768 sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100769
770 sctp_conn->last_rcvd_tsn = tsn;
771
Marco Varlese191a5942017-10-30 18:17:21 +0100772 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
773
Marco Varlese91389ac2018-01-31 11:00:01 +0100774 u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
775 u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
776
777 if (bbit == 1 && ebit == 1) /* Unfragmented message */
778 {
779 /* In order data, enqueue. Fifo figures out by itself if any out-of-order
780 * segments can be enqueued after fifo tail offset changes. */
Marco Varlese54432f82018-02-15 17:01:56 +0100781 if (PREDICT_FALSE (is_gapping == 1))
782 error =
783 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
784 else
785 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
Marco Varlese91389ac2018-01-31 11:00:01 +0100786 }
787 else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
788 {
789 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
790 }
791 else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
792 {
793 if (PREDICT_FALSE (is_gapping == 1))
794 error =
795 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
796 else
797 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
798 }
799 else /* Middle piece of a fragmented user message */
800 {
801 if (PREDICT_FALSE (is_gapping == 1))
802 error =
803 sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
804 else
805 error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
806 }
807 sctp_conn->last_rcvd_tsn = tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100808
Marco Varlesefae40392018-02-14 15:38:35 +0100809 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100810
Marco Varlese91389ac2018-01-31 11:00:01 +0100811 SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
812
Marco Varlese54432f82018-02-15 17:01:56 +0100813 if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
814 sctp_prepare_sack_chunk (sctp_conn, idx, b);
815
816 sctp_conn->sub_conn[idx].enqueue_state = error;
Marco Varlese191a5942017-10-30 18:17:21 +0100817
818 return error;
819}
820
821always_inline u16
822sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
823 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100824 sctp_connection_t * sctp_conn, u8 idx,
825 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100826{
Marco Varlese21c8baf2018-02-02 17:17:51 +0100827 u32 now = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +0100828
Marco Varlese91389ac2018-01-31 11:00:01 +0100829 sctp_cookie_echo_chunk_t *cookie_echo =
830 (sctp_cookie_echo_chunk_t *) sctp_hdr;
831
Marco Varlese191a5942017-10-30 18:17:21 +0100832 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
833 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
834 {
835 return SCTP_ERROR_INVALID_TAG;
836 }
837
Marco Varlese21c8baf2018-02-02 17:17:51 +0100838 sctp_calculate_rto (sctp_conn, idx);
839
Marco Varlese91389ac2018-01-31 11:00:01 +0100840 u32 creation_time =
841 clib_net_to_host_u32 (cookie_echo->cookie.creation_time);
842 u32 cookie_lifespan =
843 clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
844 if (now > creation_time + cookie_lifespan)
845 {
846 SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
847 now, creation_time, cookie_lifespan);
848 return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
849 }
850
Marco Varlese54432f82018-02-15 17:01:56 +0100851 sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +0100852
853 /* Change state */
854 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100855 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
Marco Varlesebe2251b2018-02-07 12:22:41 +0100856 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100857
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100858 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
859 sctp_conn->sub_conn[idx].RTO);
860
Marco Varlese15cc6a82018-02-21 12:39:52 +0100861 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
862
Marco Varlese191a5942017-10-30 18:17:21 +0100863 return SCTP_ERROR_NONE;
864
865}
866
867always_inline u16
868sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
869 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +0100870 sctp_connection_t * sctp_conn, u8 idx,
871 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +0100872{
Marco Varlese191a5942017-10-30 18:17:21 +0100873 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
874 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
875 {
876 return SCTP_ERROR_INVALID_TAG;
877 }
878
Marco Varlese21c8baf2018-02-02 17:17:51 +0100879 sctp_calculate_rto (sctp_conn, idx);
880
Marco Varlese191a5942017-10-30 18:17:21 +0100881 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
882 /* Change state */
883 sctp_conn->state = SCTP_STATE_ESTABLISHED;
Marco Varlese54432f82018-02-15 17:01:56 +0100884 sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
885
Marco Varlesefae40392018-02-14 15:38:35 +0100886 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100887
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100888 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
889 sctp_conn->sub_conn[idx].RTO);
890
Marco Varlese15cc6a82018-02-21 12:39:52 +0100891 stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
892
Marco Varlese191a5942017-10-30 18:17:21 +0100893 return SCTP_ERROR_NONE;
894
895}
896
897always_inline uword
898sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
899 vlib_frame_t * from_frame, int is_ip4)
900{
901 sctp_main_t *tm = vnet_get_sctp_main ();
902
903 u32 n_left_from, next_index, *from, *to_next;
904 u32 my_thread_index = vm->thread_index;
905
906 from = vlib_frame_vector_args (from_frame);
907 n_left_from = from_frame->n_vectors;
908
909 next_index = node->cached_next_index;
910
911 while (n_left_from > 0)
912 {
913 u32 n_left_to_next;
914
915 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
916
917 while (n_left_from > 0 && n_left_to_next > 0)
918 {
919 u32 bi0;
920 vlib_buffer_t *b0;
921 sctp_header_t *sctp_hdr = 0;
922 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
923 ip4_header_t *ip4_hdr = 0;
924 ip6_header_t *ip6_hdr = 0;
925 sctp_connection_t *sctp_conn, *new_sctp_conn;
926 u16 sctp_implied_length = 0;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100927 u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +0100928 u8 idx;
929
930 bi0 = from[0];
931 to_next[0] = bi0;
932 from += 1;
933 to_next += 1;
934 n_left_from -= 1;
935 n_left_to_next -= 1;
936
937 b0 = vlib_get_buffer (vm, bi0);
938
939 /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
940 * will come from the half-open connections pool.
941 */
942 sctp_conn =
943 sctp_half_open_connection_get (vnet_buffer (b0)->
944 sctp.connection_index);
945
946 if (PREDICT_FALSE (sctp_conn == 0))
947 {
Marco Varlese191a5942017-10-30 18:17:21 +0100948 SCTP_ADV_DBG
949 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
950 error0 = SCTP_ERROR_INVALID_CONNECTION;
951 goto drop;
952 }
953 if (is_ip4)
954 {
955 ip4_hdr = vlib_buffer_get_current (b0);
956 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +0100957 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100958 }
959 else
960 {
961 ip6_hdr = vlib_buffer_get_current (b0);
962 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +0100963 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +0100964 }
Marco Varlese191a5942017-10-30 18:17:21 +0100965
Marco Varlese04e5d642018-02-23 17:43:06 +0100966 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100967 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
968
Marco Varlese191a5942017-10-30 18:17:21 +0100969 sctp_chunk_hdr =
970 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
971
972 sctp_implied_length =
973 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
974
975 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
976
977 switch (chunk_type)
978 {
979 case INIT_ACK:
980 error0 =
981 sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
982 b0, sctp_implied_length);
983
984 if (error0 == SCTP_ERROR_NONE)
985 {
986 pool_get (tm->connections[my_thread_index], new_sctp_conn);
987 clib_memcpy (new_sctp_conn, sctp_conn,
988 sizeof (*new_sctp_conn));
989 new_sctp_conn->sub_conn[idx].c_c_index =
990 new_sctp_conn - tm->connections[my_thread_index];
991 new_sctp_conn->sub_conn[idx].c_thread_index =
992 my_thread_index;
Marco Varlesef3ab4892018-02-19 15:23:13 +0100993 new_sctp_conn->sub_conn[idx].PMTU =
994 sctp_conn->sub_conn[idx].PMTU;
Marco Varlese04e5d642018-02-23 17:43:06 +0100995 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100996
997 if (sctp_half_open_connection_cleanup (sctp_conn))
998 {
999 SCTP_DBG
1000 ("Cannot cleanup half-open connection; not the owning thread");
1001 }
1002
1003 sctp_connection_timers_init (new_sctp_conn);
1004
1005 error0 =
1006 sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
Marco Varlese21c8baf2018-02-02 17:17:51 +01001007 new_sctp_conn, idx, b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001008 sctp_implied_length);
1009
Marco Varlesef3ab4892018-02-19 15:23:13 +01001010 sctp_init_cwnd (new_sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001011
1012 if (session_stream_connect_notify
1013 (&new_sctp_conn->sub_conn[idx].connection, 0))
1014 {
1015 SCTP_DBG
1016 ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1017 new_sctp_conn->sub_conn[idx].connection.c_index);
1018 sctp_connection_cleanup (new_sctp_conn);
1019 goto drop;
1020 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001021 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001022 }
Marco Varlese191a5942017-10-30 18:17:21 +01001023 break;
1024
Marco Varlese200fa322018-02-26 16:33:54 +01001025 case OPERATION_ERROR:
1026 error0 =
1027 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1028 &next0);
1029 break;
1030
Marco Varlese191a5942017-10-30 18:17:21 +01001031 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1032 * are handled by the input-dispatcher function using the table-lookup
1033 * hence we should never get to the "default" case below.
1034 */
1035 default:
1036 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001037 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001038 goto drop;
1039 }
1040
1041 if (error0 != SCTP_ERROR_NONE)
1042 {
1043 clib_warning ("error while parsing chunk");
1044 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001045 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001046 goto drop;
1047 }
1048
1049 drop:
1050 b0->error = node->errors[error0];
1051 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1052 {
1053 sctp_rx_trace_t *t0 =
1054 vlib_add_trace (vm, node, b0, sizeof (*t0));
1055 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1056 }
1057
1058 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1059 n_left_to_next, bi0, next0);
1060 }
1061
1062 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1063 }
1064 return from_frame->n_vectors;
1065}
1066
1067static uword
1068sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1069 vlib_frame_t * from_frame)
1070{
1071 return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1072}
1073
1074static uword
1075sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1076 vlib_frame_t * from_frame)
1077{
1078 return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1079}
1080
1081u8 *
1082format_sctp_rx_trace_short (u8 * s, va_list * args)
1083{
1084 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1085 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1086 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1087
1088 s = format (s, "%d -> %d (%U)",
1089 clib_net_to_host_u16 (t->sctp_header.src_port),
1090 clib_net_to_host_u16 (t->sctp_header.dst_port),
1091 format_sctp_state, t->sctp_connection.state);
1092
1093 return s;
1094}
1095
1096/* *INDENT-OFF* */
1097VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
1098{
1099 .function = sctp4_rcv_phase,
1100 .name = "sctp4-rcv",
1101 /* Takes a vector of packets. */
1102 .vector_size = sizeof (u32),
1103 .n_errors = SCTP_N_ERROR,
1104 .error_strings = sctp_error_strings,
1105 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1106 .next_nodes =
1107 {
1108#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1109 foreach_sctp_state_next
1110#undef _
1111 },
1112 .format_trace = format_sctp_rx_trace_short,
1113};
1114/* *INDENT-ON* */
1115
1116VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
1117
1118/* *INDENT-OFF* */
1119VLIB_REGISTER_NODE (sctp6_init_phase_node) =
1120{
1121 .function = sctp6_rcv_phase,
1122 .name = "sctp6-rcv",
1123 /* Takes a vector of packets. */
1124 .vector_size = sizeof (u32),
1125 .n_errors = SCTP_N_ERROR,
1126 .error_strings = sctp_error_strings,
1127 .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1128 .next_nodes =
1129 {
1130#define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1131 foreach_sctp_state_next
1132#undef _
1133 },
1134 .format_trace = format_sctp_rx_trace_short,
1135};
1136/* *INDENT-ON* */
1137
1138VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
1139
1140vlib_node_registration_t sctp4_shutdown_phase_node;
1141vlib_node_registration_t sctp6_shutdown_phase_node;
1142
1143always_inline u16
1144sctp_handle_shutdown (sctp_header_t * sctp_hdr,
1145 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001146 sctp_connection_t * sctp_conn, u8 idx,
1147 vlib_buffer_t * b0, u16 sctp_implied_length,
1148 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001149{
1150 sctp_shutdown_association_chunk_t *shutdown_chunk =
1151 (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1152
1153 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1154 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1155 {
1156 return SCTP_ERROR_INVALID_TAG;
1157 }
1158
1159 /*
1160 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1161 */
1162 if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1163 return SCTP_ERROR_BUNDLING_VIOLATION;
1164
1165 switch (sctp_conn->state)
1166 {
1167 case SCTP_STATE_ESTABLISHED:
1168 if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1169 sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
Marco Varlese54432f82018-02-15 17:01:56 +01001170 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001171 break;
1172
1173 case SCTP_STATE_SHUTDOWN_SENT:
Marco Varlese54432f82018-02-15 17:01:56 +01001174 sctp_send_shutdown_ack (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001175 break;
1176 }
1177
Marco Varlesebe2251b2018-02-07 12:22:41 +01001178 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1179
Marco Varlese191a5942017-10-30 18:17:21 +01001180 return SCTP_ERROR_NONE;
1181}
1182
1183always_inline u16
1184sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
1185 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001186 sctp_connection_t * sctp_conn, u8 idx,
1187 vlib_buffer_t * b0, u16 sctp_implied_length,
1188 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001189{
1190 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1191 (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1192
1193 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1194 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1195 {
1196 return SCTP_ERROR_INVALID_TAG;
1197 }
1198
1199 /*
1200 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1201 */
1202 if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1203 return SCTP_ERROR_BUNDLING_VIOLATION;
1204
1205 /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1206 * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1207 * - STOP T2_SHUTDOWN timer
1208 * - SEND SHUTDOWN_COMPLETE chunk
1209 */
1210 sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
1211 SCTP_TIMER_T2_SHUTDOWN);
Marco Varlesea38783e2018-02-13 12:38:52 +01001212
Marco Varlese54432f82018-02-15 17:01:56 +01001213 sctp_send_shutdown_complete (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001214
Marco Varlesebe2251b2018-02-07 12:22:41 +01001215 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1216
Marco Varlese191a5942017-10-30 18:17:21 +01001217 return SCTP_ERROR_NONE;
1218}
1219
1220always_inline u16
1221sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
1222 sctp_chunks_common_hdr_t * sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001223 sctp_connection_t * sctp_conn, u8 idx,
1224 vlib_buffer_t * b0, u16 sctp_implied_length,
1225 u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001226{
1227 sctp_shutdown_complete_chunk_t *shutdown_complete =
1228 (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1229
1230 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1231 if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1232 {
1233 return SCTP_ERROR_INVALID_TAG;
1234 }
1235
1236 /*
1237 * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1238 */
1239 if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1240 return SCTP_ERROR_BUNDLING_VIOLATION;
1241
Marco Varlesef3ab4892018-02-19 15:23:13 +01001242 sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1243
1244 stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
Marco Varlese191a5942017-10-30 18:17:21 +01001245
1246 sctp_conn->state = SCTP_STATE_CLOSED;
1247
Marco Varlesefae40392018-02-14 15:38:35 +01001248 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001249
Marco Varlese191a5942017-10-30 18:17:21 +01001250 return SCTP_ERROR_NONE;
1251}
1252
1253always_inline uword
1254sctp46_shutdown_phase_inline (vlib_main_t * vm,
1255 vlib_node_runtime_t * node,
1256 vlib_frame_t * from_frame, int is_ip4)
1257{
1258 u32 n_left_from, next_index, *from, *to_next;
1259 u32 my_thread_index = vm->thread_index;
1260
1261 from = vlib_frame_vector_args (from_frame);
1262 n_left_from = from_frame->n_vectors;
1263
1264 next_index = node->cached_next_index;
1265
1266 while (n_left_from > 0)
1267 {
1268 u32 n_left_to_next;
1269
1270 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1271
1272 while (n_left_from > 0 && n_left_to_next > 0)
1273 {
1274 u32 bi0;
1275 vlib_buffer_t *b0;
1276 sctp_rx_trace_t *sctp_trace;
1277 sctp_header_t *sctp_hdr = 0;
1278 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1279 ip4_header_t *ip4_hdr = 0;
1280 ip6_header_t *ip6_hdr = 0;
1281 sctp_connection_t *sctp_conn;
1282 u16 sctp_implied_length = 0;
1283 u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
Marco Varlese54432f82018-02-15 17:01:56 +01001284 u8 idx = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001285
1286 bi0 = from[0];
1287 to_next[0] = bi0;
1288 from += 1;
1289 to_next += 1;
1290 n_left_from -= 1;
1291 n_left_to_next -= 1;
1292
1293 b0 = vlib_get_buffer (vm, bi0);
1294 sctp_conn =
1295 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1296 my_thread_index);
1297
1298 if (PREDICT_FALSE (sctp_conn == 0))
1299 {
1300 SCTP_DBG
1301 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1302 error0 = SCTP_ERROR_INVALID_CONNECTION;
1303 goto drop;
1304 }
1305
1306 if (is_ip4)
1307 {
1308 ip4_hdr = vlib_buffer_get_current (b0);
1309 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001310 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001311 }
1312 else
1313 {
1314 ip6_hdr = vlib_buffer_get_current (b0);
1315 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001316 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001317 }
1318
1319 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1320 sctp_chunk_hdr = &full_hdr->common_hdr;
1321
1322 sctp_implied_length =
1323 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1324
Marco Varlesebe2251b2018-02-07 12:22:41 +01001325 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1326 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001327 {
1328 case SHUTDOWN:
1329 error0 =
Marco Varlesebe2251b2018-02-07 12:22:41 +01001330 sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1331 idx, b0, sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001332 break;
1333
1334 case SHUTDOWN_ACK:
1335 error0 =
1336 sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001337 idx, b0, sctp_implied_length,
1338 &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001339 break;
1340
1341 case SHUTDOWN_COMPLETE:
1342 error0 =
1343 sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001344 sctp_conn, idx, b0,
1345 sctp_implied_length, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001346
1347 sctp_connection_cleanup (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001348 break;
1349
1350 /*
1351 * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1352 * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1353 */
1354 case DATA:
1355 error0 =
1356 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001357 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001358 break;
1359
Marco Varlese200fa322018-02-26 16:33:54 +01001360 case OPERATION_ERROR:
1361 error0 =
1362 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1363 &next0);
1364 break;
1365
Marco Varlese8c5f67f2018-02-27 09:38:31 +01001366 case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1367 sctp_prepare_operation_error (sctp_conn, idx, b0,
1368 COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
1369 error0 = SCTP_ERROR_NONE;
1370 next0 = sctp_next_output (is_ip4);
1371 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001372 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1373 * are handled by the input-dispatcher function using the table-lookup
1374 * hence we should never get to the "default" case below.
1375 */
1376 default:
1377 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001378 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001379 goto drop;
1380 }
1381
1382 if (error0 != SCTP_ERROR_NONE)
1383 {
1384 clib_warning ("error while parsing chunk");
1385 sctp_connection_cleanup (sctp_conn);
Marco Varlesefae40392018-02-14 15:38:35 +01001386 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001387 goto drop;
1388 }
1389
1390 drop:
1391 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1392 {
1393 sctp_trace =
1394 vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
Marco Varlesef429a932018-02-06 17:31:06 +01001395
1396 if (sctp_hdr != NULL)
1397 clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
1398 sizeof (sctp_trace->sctp_header));
1399
1400 if (sctp_conn != NULL)
1401 clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
1402 sizeof (sctp_trace->sctp_connection));
Marco Varlese191a5942017-10-30 18:17:21 +01001403 }
1404
1405 b0->error = node->errors[error0];
1406
1407 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1408 n_left_to_next, bi0, next0);
1409 }
1410
1411 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1412 }
1413
1414 return from_frame->n_vectors;
1415
1416}
1417
1418static uword
1419sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1420 vlib_frame_t * from_frame)
1421{
1422 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1423}
1424
1425static uword
1426sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1427 vlib_frame_t * from_frame)
1428{
1429 return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1430}
1431
1432/* *INDENT-OFF* */
1433VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
1434{
1435 .function = sctp4_shutdown_phase,
1436 .name = "sctp4-shutdown",
1437 /* Takes a vector of packets. */
1438 .vector_size = sizeof (u32),
1439 .n_errors = SCTP_N_ERROR,
1440 .error_strings = sctp_error_strings,
1441 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1442 .next_nodes =
1443 {
1444#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1445 foreach_sctp_state_next
1446#undef _
1447 },
1448 .format_trace = format_sctp_rx_trace_short,
1449};
1450/* *INDENT-ON* */
1451
1452VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
1453 sctp4_shutdown_phase);
1454
1455/* *INDENT-OFF* */
1456VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
1457{
1458 .function = sctp6_shutdown_phase,
1459 .name = "sctp6-shutdown",
1460 /* Takes a vector of packets. */
1461 .vector_size = sizeof (u32),
1462 .n_errors = SCTP_N_ERROR,
1463 .error_strings = sctp_error_strings,
1464 .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1465 .next_nodes =
1466 {
1467#define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1468 foreach_sctp_state_next
1469#undef _
1470 },
1471 .format_trace = format_sctp_rx_trace_short,
1472};
1473/* *INDENT-ON* */
1474
1475VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
1476 sctp6_shutdown_phase);
1477
1478vlib_node_registration_t sctp4_listen_phase_node;
1479vlib_node_registration_t sctp6_listen_phase_node;
1480
1481vlib_node_registration_t sctp4_established_phase_node;
1482vlib_node_registration_t sctp6_established_phase_node;
1483
1484always_inline u16
1485sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001486 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
Marco Varlese191a5942017-10-30 18:17:21 +01001487 u16 * next0)
1488{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001489 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1490 if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1491 {
1492 return SCTP_ERROR_INVALID_TAG;
1493 }
1494
Marco Varlese54432f82018-02-15 17:01:56 +01001495 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1496
Marco Varlesef3ab4892018-02-19 15:23:13 +01001497 /* Section 7.2.2; point (2) */
1498 if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1499 sctp_conn->sub_conn[idx].partially_acked_bytes =
1500 sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1501
1502 /* Section 7.2.2; point (5) */
1503 if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1504 sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1505
1506 sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1507
Marco Varlese21c8baf2018-02-02 17:17:51 +01001508 sctp_calculate_rto (sctp_conn, idx);
1509
1510 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1511 sctp_conn->sub_conn[idx].RTO);
1512
1513 sctp_conn->sub_conn[idx].RTO_pending = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001514
Marco Varlesefae40392018-02-14 15:38:35 +01001515 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001516
1517 return SCTP_ERROR_NONE;
1518}
1519
1520always_inline u16
1521sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001522 sctp_connection_t * sctp_conn, u8 idx,
1523 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001524{
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001525 /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1526 if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1527 {
1528 return SCTP_ERROR_INVALID_TAG;
1529 }
1530
Marco Varlese54432f82018-02-15 17:01:56 +01001531 sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001532
1533 *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1534
Marco Varlese191a5942017-10-30 18:17:21 +01001535 return SCTP_ERROR_NONE;
1536}
1537
1538always_inline u16
1539sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001540 sctp_connection_t * sctp_conn, u8 idx,
1541 vlib_buffer_t * b0, u16 * next0)
Marco Varlese191a5942017-10-30 18:17:21 +01001542{
Marco Varlese54432f82018-02-15 17:01:56 +01001543 sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1544
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001545 sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1546
1547 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1548 sctp_conn->sub_conn[idx].RTO);
1549
Marco Varlesefae40392018-02-14 15:38:35 +01001550 *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001551
Marco Varlese191a5942017-10-30 18:17:21 +01001552 return SCTP_ERROR_NONE;
1553}
1554
1555always_inline void
Marco Varlese3c6a9762018-03-01 11:19:59 +01001556sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
Marco Varlese191a5942017-10-30 18:17:21 +01001557 u8 is_ip4, u8 evt, u8 val)
1558{
1559 if (PREDICT_TRUE (!val))
1560 return;
1561
1562 if (is_ip4)
Marco Varlese3c6a9762018-03-01 11:19:59 +01001563 vlib_node_increment_counter (vm, sctp4_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001564 else
Marco Varlese3c6a9762018-03-01 11:19:59 +01001565 vlib_node_increment_counter (vm, sctp6_node, evt, val);
Marco Varlese191a5942017-10-30 18:17:21 +01001566}
1567
1568always_inline uword
1569sctp46_listen_process_inline (vlib_main_t * vm,
1570 vlib_node_runtime_t * node,
1571 vlib_frame_t * from_frame, int is_ip4)
1572{
1573 u32 n_left_from, next_index, *from, *to_next;
1574 u32 my_thread_index = vm->thread_index;
1575
1576 from = vlib_frame_vector_args (from_frame);
1577 n_left_from = from_frame->n_vectors;
1578
1579 next_index = node->cached_next_index;
1580
1581 while (n_left_from > 0)
1582 {
1583 u32 n_left_to_next;
1584
1585 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1586
1587 while (n_left_from > 0 && n_left_to_next > 0)
1588 {
1589 u32 bi0;
1590 vlib_buffer_t *b0;
1591 sctp_header_t *sctp_hdr = 0;
1592 ip4_header_t *ip4_hdr;
1593 ip6_header_t *ip6_hdr;
1594 sctp_connection_t *child_conn;
1595 sctp_connection_t *sctp_listener;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001596 u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
Marco Varlese191a5942017-10-30 18:17:21 +01001597
1598 bi0 = from[0];
1599 to_next[0] = bi0;
1600 from += 1;
1601 to_next += 1;
1602 n_left_from -= 1;
1603 n_left_to_next -= 1;
1604
1605 b0 = vlib_get_buffer (vm, bi0);
1606 sctp_listener =
1607 sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1608
1609 if (is_ip4)
1610 {
1611 ip4_hdr = vlib_buffer_get_current (b0);
1612 sctp_hdr = ip4_next_header (ip4_hdr);
1613 }
1614 else
1615 {
1616 ip6_hdr = vlib_buffer_get_current (b0);
1617 sctp_hdr = ip6_next_header (ip6_hdr);
1618 }
1619
1620 child_conn =
1621 sctp_lookup_connection (sctp_listener->sub_conn
1622 [MAIN_SCTP_SUB_CONN_IDX].c_fib_index, b0,
1623 my_thread_index, is_ip4);
1624
1625 if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1626 {
1627 SCTP_DBG
1628 ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1629 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1630 connection.c_index,
1631 sctp_state_to_string (child_conn->state));
1632 error0 = SCTP_ERROR_CREATE_EXISTS;
1633 goto drop;
1634 }
1635
1636 /* Create child session and send SYN-ACK */
1637 child_conn = sctp_connection_new (my_thread_index);
Marco Varlese04e5d642018-02-23 17:43:06 +01001638 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].subconn_idx =
1639 MAIN_SCTP_SUB_CONN_IDX;
Marco Varlese191a5942017-10-30 18:17:21 +01001640 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_port =
1641 sctp_hdr->dst_port;
1642 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_port =
1643 sctp_hdr->src_port;
1644 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_is_ip4 = is_ip4;
1645 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto =
1646 sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001647 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU =
1648 sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU;
Marco Varlese191a5942017-10-30 18:17:21 +01001649 child_conn->state = SCTP_STATE_CLOSED;
1650
1651 if (is_ip4)
1652 {
1653 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip4.as_u32 =
1654 ip4_hdr->dst_address.as_u32;
1655 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip4.as_u32 =
1656 ip4_hdr->src_address.as_u32;
1657 }
1658 else
1659 {
1660 clib_memcpy (&child_conn->
1661 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip6,
1662 &ip6_hdr->dst_address, sizeof (ip6_address_t));
1663 clib_memcpy (&child_conn->
1664 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip6,
1665 &ip6_hdr->src_address, sizeof (ip6_address_t));
1666 }
1667
1668 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1669 sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1670
1671 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1672 if (chunk_type != INIT)
1673 {
1674 SCTP_DBG
1675 ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1676 child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
1677 connection.c_index, sctp_chunk_to_string (chunk_type));
1678
1679 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001680 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001681 goto drop;
1682 }
1683
1684 u16 sctp_implied_length =
1685 sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1686
1687 switch (chunk_type)
1688 {
1689 case INIT:
1690 sctp_connection_timers_init (child_conn);
1691
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001692 sctp_init_snd_vars (child_conn);
1693
Marco Varlese191a5942017-10-30 18:17:21 +01001694 error0 =
1695 sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1696 sctp_implied_length);
1697
Marco Varlesef3ab4892018-02-19 15:23:13 +01001698 sctp_init_cwnd (child_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001699
1700 if (error0 == SCTP_ERROR_NONE)
1701 {
1702 if (stream_session_accept
1703 (&child_conn->
1704 sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection,
1705 sctp_listener->
1706 sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index, 0))
1707 {
1708 clib_warning ("session accept fail");
1709 sctp_connection_cleanup (child_conn);
1710 error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1711 goto drop;
1712 }
Marco Varlesef3ab4892018-02-19 15:23:13 +01001713 next0 = sctp_next_output (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001714 }
Marco Varlese191a5942017-10-30 18:17:21 +01001715 break;
1716
1717 /* Reception of a DATA chunk whilst in the CLOSED state is called
1718 * "Out of the Blue" packet and handling of the chunk needs special treatment
1719 * as per RFC4960 section 8.4
1720 */
1721 case DATA:
1722 break;
Marco Varlese200fa322018-02-26 16:33:54 +01001723
1724 case OPERATION_ERROR:
1725 error0 =
1726 sctp_handle_operation_err (sctp_hdr, child_conn,
1727 MAIN_SCTP_SUB_CONN_IDX, b0,
1728 &next0);
1729 break;
Marco Varlese191a5942017-10-30 18:17:21 +01001730 }
1731
1732 drop:
1733 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1734 {
1735 sctp_rx_trace_t *t0 =
1736 vlib_add_trace (vm, node, b0, sizeof (*t0));
1737 clib_memcpy (&t0->sctp_header, sctp_hdr,
1738 sizeof (t0->sctp_header));
1739 clib_memcpy (&t0->sctp_connection, sctp_listener,
1740 sizeof (t0->sctp_connection));
1741 }
1742
1743 b0->error = node->errors[error0];
1744
1745 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1746 n_left_to_next, bi0, next0);
1747 }
1748 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1749
1750 }
1751 return from_frame->n_vectors;
1752}
1753
1754static uword
1755sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1756 vlib_frame_t * from_frame)
1757{
1758 return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1759}
1760
1761static uword
1762sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1763 vlib_frame_t * from_frame)
1764{
1765 return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1766}
1767
1768always_inline uword
1769sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1770 vlib_frame_t * from_frame, int is_ip4)
1771{
1772 u32 n_left_from, next_index, *from, *to_next;
1773 u32 my_thread_index = vm->thread_index, errors = 0;
1774
1775 from = vlib_frame_vector_args (from_frame);
1776 n_left_from = from_frame->n_vectors;
1777
1778 next_index = node->cached_next_index;
1779
1780 while (n_left_from > 0)
1781 {
1782 u32 n_left_to_next;
1783
1784 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1785
1786 while (n_left_from > 0 && n_left_to_next > 0)
1787 {
1788 u32 bi0;
1789 vlib_buffer_t *b0;
1790 sctp_header_t *sctp_hdr = 0;
1791 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1792 ip4_header_t *ip4_hdr = 0;
1793 ip6_header_t *ip6_hdr = 0;
1794 sctp_connection_t *sctp_conn;
Marco Varlesefae40392018-02-14 15:38:35 +01001795 u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1796 SCTP_ESTABLISHED_PHASE_N_NEXT;
Marco Varlese191a5942017-10-30 18:17:21 +01001797 u8 idx;
1798
1799 bi0 = from[0];
1800 to_next[0] = bi0;
1801 from += 1;
1802 to_next += 1;
1803 n_left_from -= 1;
1804 n_left_to_next -= 1;
1805
1806 b0 = vlib_get_buffer (vm, bi0);
1807 sctp_conn =
1808 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1809 my_thread_index);
1810
1811 if (PREDICT_FALSE (sctp_conn == 0))
1812 {
1813 SCTP_DBG
1814 ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1815 error0 = SCTP_ERROR_INVALID_CONNECTION;
1816 goto done;
1817 }
1818 if (is_ip4)
1819 {
1820 ip4_hdr = vlib_buffer_get_current (b0);
1821 sctp_hdr = ip4_next_header (ip4_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001822 idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001823 }
1824 else
1825 {
1826 ip6_hdr = vlib_buffer_get_current (b0);
1827 sctp_hdr = ip6_next_header (ip6_hdr);
Marco Varlese54432f82018-02-15 17:01:56 +01001828 idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
Marco Varlese191a5942017-10-30 18:17:21 +01001829 }
1830
Marco Varlese04e5d642018-02-23 17:43:06 +01001831 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001832
Marco Varlese54432f82018-02-15 17:01:56 +01001833 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
Marco Varlese191a5942017-10-30 18:17:21 +01001834 sctp_chunk_hdr =
1835 (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1836
1837 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1838
1839 switch (chunk_type)
1840 {
1841 case COOKIE_ECHO:
1842 error0 =
1843 sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001844 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001845 break;
1846
1847 case COOKIE_ACK:
1848 error0 =
1849 sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001850 idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001851 break;
1852
1853 case SACK:
1854 error0 =
1855 sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001856 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001857 break;
1858
1859 case HEARTBEAT:
1860 error0 =
1861 sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001862 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001863 break;
1864
1865 case HEARTBEAT_ACK:
1866 error0 =
1867 sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001868 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001869 break;
1870
1871 case DATA:
1872 error0 =
1873 sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
Marco Varlesebe2251b2018-02-07 12:22:41 +01001874 sctp_conn, idx, b0, &next0);
Marco Varlese191a5942017-10-30 18:17:21 +01001875 break;
1876
Marco Varlese200fa322018-02-26 16:33:54 +01001877 case OPERATION_ERROR:
1878 error0 =
1879 sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1880 &next0);
1881 break;
1882
Marco Varlese191a5942017-10-30 18:17:21 +01001883 /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1884 * are handled by the input-dispatcher function using the table-lookup
1885 * hence we should never get to the "default" case below.
1886 */
1887 default:
1888 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlesefae40392018-02-14 15:38:35 +01001889 next0 = sctp_next_drop (is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001890 goto done;
1891 }
1892
1893 done:
1894 b0->error = node->errors[error0];
1895 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1896 {
1897 sctp_rx_trace_t *t0 =
1898 vlib_add_trace (vm, node, b0, sizeof (*t0));
1899 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1900 }
1901
1902 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1903 n_left_to_next, bi0, next0);
1904 }
1905
1906 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1907 }
1908
1909 errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
1910 my_thread_index);
1911
1912 sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
1913 sctp6_established_phase_node.index,
1914 SCTP_ERROR_EVENT_FIFO_FULL, errors);
1915 sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1916
1917 return from_frame->n_vectors;
1918}
1919
1920static uword
1921sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1922 vlib_frame_t * from_frame)
1923{
1924 return sctp46_established_phase_inline (vm, node, from_frame,
1925 1 /* is_ip4 */ );
1926}
1927
1928static uword
1929sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
1930 vlib_frame_t * from_frame)
1931{
1932 return sctp46_established_phase_inline (vm, node, from_frame,
1933 0 /* is_ip4 */ );
1934}
1935
1936u8 *
1937format_sctp_rx_trace (u8 * s, va_list * args)
1938{
1939 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1940 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1941 sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1942 u32 indent = format_get_indent (s);
1943
1944 s = format (s, "%U\n%U%U",
1945 format_sctp_header, &t->sctp_header, 128,
1946 format_white_space, indent,
1947 format_sctp_connection, &t->sctp_connection, 1);
1948
1949 return s;
1950}
1951
1952/* *INDENT-OFF* */
1953VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
1954{
1955 .function = sctp4_listen_phase,
1956 .name = "sctp4-listen",
1957 /* Takes a vector of packets. */
1958 .vector_size = sizeof (u32),
1959 .n_errors = SCTP_N_ERROR,
1960 .error_strings = sctp_error_strings,
1961 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1962 .next_nodes =
1963 {
1964#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1965 foreach_sctp_state_next
1966#undef _
1967 },
1968 .format_trace = format_sctp_rx_trace_short,
1969};
1970/* *INDENT-ON* */
1971
1972VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
1973
1974/* *INDENT-OFF* */
1975VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
1976{
1977 .function = sctp6_listen_phase,
1978 .name = "sctp6-listen",
1979 /* Takes a vector of packets. */
1980 .vector_size = sizeof (u32),
1981 .n_errors = SCTP_N_ERROR,
1982 .error_strings = sctp_error_strings,
1983 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
1984 .next_nodes =
1985 {
1986#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
1987 foreach_sctp_state_next
1988#undef _
1989 },
1990 .format_trace = format_sctp_rx_trace_short,
1991};
1992/* *INDENT-ON* */
1993
1994VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
1995
1996/* *INDENT-OFF* */
1997VLIB_REGISTER_NODE (sctp4_established_phase_node) =
1998{
1999 .function = sctp4_established_phase,
2000 .name = "sctp4-established",
2001 /* Takes a vector of packets. */
2002 .vector_size = sizeof (u32),
2003 .n_errors = SCTP_N_ERROR,
2004 .error_strings = sctp_error_strings,
2005 .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2006 .next_nodes =
2007 {
2008#define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2009 foreach_sctp_state_next
2010#undef _
2011 },
2012 .format_trace = format_sctp_rx_trace_short,
2013};
2014/* *INDENT-ON* */
2015
2016VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
2017 sctp4_established_phase);
2018
2019/* *INDENT-OFF* */
2020VLIB_REGISTER_NODE (sctp6_established_phase_node) =
2021{
2022 .function = sctp6_established_phase,
2023 .name = "sctp6-established",
2024 /* Takes a vector of packets. */
2025 .vector_size = sizeof (u32),
2026 .n_errors = SCTP_N_ERROR,
2027 .error_strings = sctp_error_strings,
2028 .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2029 .next_nodes =
2030 {
2031#define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2032 foreach_sctp_state_next
2033#undef _
2034 },
2035 .format_trace = format_sctp_rx_trace_short,
2036};
2037/* *INDENT-ON* */
2038
2039VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
2040 sctp6_established_phase);
2041
2042/*
2043 * This is the function executed first for the SCTP graph.
2044 * It takes care of doing the initial message parsing and
2045 * dispatch to the specialized function.
2046 */
2047always_inline uword
2048sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2049 vlib_frame_t * from_frame, int is_ip4)
2050{
2051 u32 n_left_from, next_index, *from, *to_next;
2052 u32 my_thread_index = vm->thread_index;
2053 u8 is_filtered;
2054 sctp_main_t *tm = vnet_get_sctp_main ();
2055
2056 from = vlib_frame_vector_args (from_frame);
2057 n_left_from = from_frame->n_vectors;
2058 next_index = node->cached_next_index;
2059 sctp_set_time_now (my_thread_index);
2060
2061 while (n_left_from > 0)
2062 {
2063 u32 n_left_to_next;
2064
2065 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2066
2067 while (n_left_from > 0 && n_left_to_next > 0)
2068 {
2069 int n_advance_bytes0, n_data_bytes0;
2070 u32 bi0, fib_index0;
2071 vlib_buffer_t *b0;
2072 sctp_header_t *sctp_hdr = 0;
2073 sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2074 sctp_connection_t *sctp_conn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002075 transport_connection_t *trans_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01002076 ip4_header_t *ip4_hdr;
2077 ip6_header_t *ip6_hdr;
2078 u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2079
2080 bi0 = from[0];
2081 to_next[0] = bi0;
2082 from += 1;
2083 to_next += 1;
2084 n_left_from -= 1;
2085 n_left_to_next -= 1;
2086
2087 b0 = vlib_get_buffer (vm, bi0);
Marco Varlese3c6a9762018-03-01 11:19:59 +01002088 vnet_buffer (b0)->sctp.flags = 0;
Marco Varlese191a5942017-10-30 18:17:21 +01002089 fib_index0 = vnet_buffer (b0)->ip.fib_index;
2090
2091 /* Checksum computed by ipx_local no need to compute again */
2092
2093 if (is_ip4)
2094 {
2095 ip4_hdr = vlib_buffer_get_current (b0);
2096 sctp_hdr = ip4_next_header (ip4_hdr);
2097
2098 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2099 sctp_chunk_hdr = &full_hdr->common_hdr;
2100
2101 n_advance_bytes0 =
2102 (ip4_header_bytes (ip4_hdr) +
2103 sizeof (sctp_payload_data_chunk_t));
2104 n_data_bytes0 =
2105 clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2106
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002107 trans_conn = session_lookup_connection_wt4 (fib_index0,
2108 &ip4_hdr->dst_address,
2109 &ip4_hdr->src_address,
2110 sctp_hdr->dst_port,
2111 sctp_hdr->src_port,
2112 TRANSPORT_PROTO_SCTP,
2113 my_thread_index,
2114 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002115 }
2116 else
2117 {
2118 ip6_hdr = vlib_buffer_get_current (b0);
2119 sctp_hdr = ip6_next_header (ip6_hdr);
2120
2121 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2122 sctp_chunk_hdr = &full_hdr->common_hdr;
2123
2124 n_advance_bytes0 = sctp_header_bytes ();
2125 n_data_bytes0 =
2126 clib_net_to_host_u16 (ip6_hdr->payload_length) -
2127 n_advance_bytes0;
2128 n_advance_bytes0 += sizeof (ip6_hdr[0]);
2129
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002130 trans_conn = session_lookup_connection_wt6 (fib_index0,
2131 &ip6_hdr->dst_address,
2132 &ip6_hdr->src_address,
2133 sctp_hdr->dst_port,
2134 sctp_hdr->src_port,
2135 TRANSPORT_PROTO_SCTP,
2136 my_thread_index,
2137 &is_filtered);
Marco Varlese191a5942017-10-30 18:17:21 +01002138 }
2139
2140 /* Length check */
2141 if (PREDICT_FALSE (n_advance_bytes0 < 0))
2142 {
2143 error0 = SCTP_ERROR_LENGTH;
2144 goto done;
2145 }
2146
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002147 sctp_conn = sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01002148 vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2149
Marco Varlesefae40392018-02-14 15:38:35 +01002150 u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2151 if (chunk_type >= UNKNOWN)
2152 {
2153 clib_warning
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002154 ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2155
2156 sctp_prepare_operation_error (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
2157 b0, UNRECOGNIZED_CHUNK_TYPE);
2158
Marco Varlesefae40392018-02-14 15:38:35 +01002159 error0 = SCTP_ERROR_UNKOWN_CHUNK;
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002160 next0 = sctp_next_output (is_ip4);
Marco Varlesefae40392018-02-14 15:38:35 +01002161 goto done;
2162 }
2163
Marco Varlese191a5942017-10-30 18:17:21 +01002164 vnet_buffer (b0)->sctp.hdr_offset =
2165 (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2166
2167 /* Session exists */
2168 if (PREDICT_TRUE (0 != sctp_conn))
2169 {
2170 /* Save connection index */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01002171 vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
Marco Varlese191a5942017-10-30 18:17:21 +01002172 vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2173 vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2174
Marco Varlesefae40392018-02-14 15:38:35 +01002175 next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2176 error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
Marco Varlese191a5942017-10-30 18:17:21 +01002177
Marco Varlesef3ab4892018-02-19 15:23:13 +01002178 SCTP_DBG_STATE_MACHINE
Marco Varlese15cc6a82018-02-21 12:39:52 +01002179 ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
Marco Varlesef3ab4892018-02-19 15:23:13 +01002180 "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2181 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
Marco Varlese15cc6a82018-02-21 12:39:52 +01002182 connection.s_index,
2183 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
2184 connection.c_index, trans_conn, sctp_conn,
2185 sctp_state_to_string (sctp_conn->state),
Marco Varlesef3ab4892018-02-19 15:23:13 +01002186 sctp_chunk_to_string (chunk_type), phase_to_string (next0));
Marco Varlese191a5942017-10-30 18:17:21 +01002187
Marco Varlesefae40392018-02-14 15:38:35 +01002188 if (chunk_type == DATA)
Marco Varlese191a5942017-10-30 18:17:21 +01002189 SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2190 n_advance_bytes0, n_data_bytes0);
2191
2192 }
2193 else
2194 {
2195 if (is_filtered)
2196 {
2197 next0 = SCTP_INPUT_NEXT_DROP;
2198 error0 = SCTP_ERROR_FILTERED;
2199 }
2200 else if ((is_ip4 && tm->punt_unknown4) ||
2201 (!is_ip4 && tm->punt_unknown6))
2202 {
2203 next0 = SCTP_INPUT_NEXT_PUNT_PHASE;
2204 error0 = SCTP_ERROR_PUNT;
2205 }
2206 else
2207 {
2208 next0 = SCTP_INPUT_NEXT_DROP;
2209 error0 = SCTP_ERROR_NO_LISTENER;
2210 }
2211 SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2212 phase_to_string (next0));
2213 sctp_conn = 0;
2214 }
2215
2216 done:
2217 b0->error = error0 ? node->errors[error0] : 0;
2218
2219 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2220 {
2221 sctp_rx_trace_t *t0 =
2222 vlib_add_trace (vm, node, b0, sizeof (*t0));
2223 sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2224 }
2225 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2226 n_left_to_next, bi0, next0);
2227 }
2228
2229 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2230 }
2231 return from_frame->n_vectors;
2232}
2233
2234static uword
2235sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2236 vlib_frame_t * from_frame)
2237{
2238 return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2239}
2240
2241static uword
2242sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
2243 vlib_frame_t * from_frame)
2244{
2245 return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2246}
2247
2248/* *INDENT-OFF* */
2249VLIB_REGISTER_NODE (sctp4_input_node) =
2250{
2251 .function = sctp4_input_dispatcher,
2252 .name = "sctp4-input",
2253 /* Takes a vector of packets. */
2254 .vector_size = sizeof (u32),
2255 .n_errors = SCTP_N_ERROR,
2256 .error_strings = sctp_error_strings,
2257 .n_next_nodes = SCTP_INPUT_N_NEXT,
2258 .next_nodes =
2259 {
2260#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2261 foreach_sctp4_input_next
2262#undef _
2263 },
2264 .format_buffer = format_sctp_header,
2265 .format_trace = format_sctp_rx_trace,
2266};
2267/* *INDENT-ON* */
2268
2269VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
2270
2271/* *INDENT-OFF* */
2272VLIB_REGISTER_NODE (sctp6_input_node) =
2273{
2274 .function = sctp6_input_dispatcher,
2275 .name = "sctp6-input",
2276 /* Takes a vector of packets. */
2277 .vector_size = sizeof (u32),
2278 .n_errors = SCTP_N_ERROR,
2279 .error_strings = sctp_error_strings,
2280 .n_next_nodes = SCTP_INPUT_N_NEXT,
2281 .next_nodes =
2282 {
2283#define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2284 foreach_sctp6_input_next
2285#undef _
2286 },
2287 .format_buffer = format_sctp_header,
2288 .format_trace = format_sctp_rx_trace,
2289};
2290/* *INDENT-ON* */
2291
2292VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
2293
2294vlib_node_registration_t sctp4_input_node;
2295vlib_node_registration_t sctp6_input_node;
2296
2297static void
2298sctp_dispatch_table_init (sctp_main_t * tm)
2299{
2300 int i, j;
2301 for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2302 for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2303 {
2304 tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2305 tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2306 }
2307
2308#define _(t,f,n,e) \
2309do { \
2310 tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2311 tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2312} while (0)
2313
2314 /*
2315 * SCTP STATE-MACHINE states:
2316 *
2317 * _(CLOSED, "CLOSED") \
2318 * _(COOKIE_WAIT, "COOKIE_WAIT") \
2319 * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2320 * _(ESTABLISHED, "ESTABLISHED") \
2321 * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2322 * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2323 * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2324 * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2325 */
Marco Varlesef3ab4892018-02-19 15:23:13 +01002326 //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002327 _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2328 _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2329 _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2330 _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2331 _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2332 _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2333 _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2334 _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2335 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2336 _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2337 _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2338 _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2339 _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2340 _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002341 _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002342
Marco Varlese200fa322018-02-26 16:33:54 +01002343 _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
Marco Varlese191a5942017-10-30 18:17:21 +01002344 _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2345 _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2346 _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2347 _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2348 _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2349 _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2350 _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2351 _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2352 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2353 _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2354 _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2355 _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2356 _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2357 _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002358 _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2359 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002360
2361 _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2362 _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2363 _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2364 _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2365 _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2366 _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2367 _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2368 _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2369 _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2370 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2371 _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2372 _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2373 SCTP_ERROR_NONE);
2374 _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2375 _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2376 _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002377 _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2378 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002379
2380 _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2381 _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2382 _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2383 _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2384 _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2385 SCTP_ERROR_NONE);
2386 _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE,
2387 SCTP_ERROR_NONE);
2388 _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2389 _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2390 _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2391 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2392 _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2393 _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2394 _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2395 _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2396 _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002397 _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2398 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002399
2400 _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2401 _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2402 _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2403 _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2404 _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2405 SCTP_ERROR_NONE);
2406 _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2407 SCTP_ERROR_NONE);
2408 _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2409 _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2410 SCTP_ERROR_NONE);
2411 _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2412 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002413 _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2414 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002415 _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2416 _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2417 _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2418 _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002419 _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2420 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002421
2422 _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2423 _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2424 _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2425 _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2426 _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2427 _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2428 _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2429 _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2430 _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2431 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002432 _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2433 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002434 _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2435 _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2436 _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2437 _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002438 _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2439 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002440
2441 _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2442 _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2443 _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2444 _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2445 _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2446 _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2447 _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2448 _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2449 _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2450 SCTP_ERROR_NONE);
Marco Varlese8c5f67f2018-02-27 09:38:31 +01002451 _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2452 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002453 _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2454 _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2455 _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2456 _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
Marco Varlese200fa322018-02-26 16:33:54 +01002457 _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2458 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002459
2460 _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
Marco Varleseeacf3cf2018-02-26 14:52:25 +01002461 _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
Marco Varlese191a5942017-10-30 18:17:21 +01002462 _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2463 _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2464 _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2465 _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2466 _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2467 _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2468 _(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 +01002469 _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2470 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002471 _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2472 _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2473 _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2474 _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2475 SCTP_ERROR_NONE);
Marco Varlese200fa322018-02-26 16:33:54 +01002476 _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2477 SCTP_ERROR_NONE);
Marco Varlese191a5942017-10-30 18:17:21 +01002478
2479 /* TODO: Handle COOKIE ECHO when a TCB Exists */
2480
2481#undef _
2482}
2483
2484clib_error_t *
2485sctp_input_init (vlib_main_t * vm)
2486{
2487 clib_error_t *error = 0;
2488 sctp_main_t *tm = vnet_get_sctp_main ();
2489
2490 if ((error = vlib_call_init_function (vm, sctp_init)))
2491 return error;
2492
2493 /* Initialize dispatch table. */
2494 sctp_dispatch_table_init (tm);
2495
2496 return error;
2497}
2498
2499VLIB_INIT_FUNCTION (sctp_input_init);
2500
2501/*
2502 * fd.io coding-style-patch-verification: ON
2503 *
2504 * Local Variables:
2505 * eval: (c-set-style "gnu")
2506 * End:
2507 */