blob: 0c2fee1bb6984e760e796fbe49217ab8e6565324 [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 <vnet/sctp/sctp.h>
16#include <vnet/sctp/sctp_debug.h>
17#include <vppinfra/random.h>
Marco Varlese91389ac2018-01-31 11:00:01 +010018#include <openssl/hmac.h>
Marco Varlese191a5942017-10-30 18:17:21 +010019
20vlib_node_registration_t sctp4_output_node;
21vlib_node_registration_t sctp6_output_node;
22
23typedef enum _sctp_output_next
24{
25 SCTP_OUTPUT_NEXT_DROP,
26 SCTP_OUTPUT_NEXT_IP_LOOKUP,
27 SCTP_OUTPUT_N_NEXT
28} sctp_output_next_t;
29
30#define foreach_sctp4_output_next \
31 _ (DROP, "error-drop") \
32 _ (IP_LOOKUP, "ip4-lookup")
33
34#define foreach_sctp6_output_next \
35 _ (DROP, "error-drop") \
36 _ (IP_LOOKUP, "ip6-lookup")
37
38static char *sctp_error_strings[] = {
39#define sctp_error(n,s) s,
40#include <vnet/sctp/sctp_error.def>
41#undef sctp_error
42};
43
44typedef struct
45{
46 sctp_header_t sctp_header;
47 sctp_connection_t sctp_connection;
48} sctp_tx_trace_t;
49
50/**
51 * Flush tx frame populated by retransmits and timer pops
52 */
53void
54sctp_flush_frame_to_output (vlib_main_t * vm, u8 thread_index, u8 is_ip4)
55{
56 if (sctp_main.tx_frames[!is_ip4][thread_index])
57 {
58 u32 next_index;
59 next_index = is_ip4 ? sctp4_output_node.index : sctp6_output_node.index;
60 vlib_put_frame_to_node (vm, next_index,
61 sctp_main.tx_frames[!is_ip4][thread_index]);
62 sctp_main.tx_frames[!is_ip4][thread_index] = 0;
63 }
64}
65
66/**
67 * Flush ip lookup tx frames populated by timer pops
68 */
69always_inline void
70sctp_flush_frame_to_ip_lookup (vlib_main_t * vm, u8 thread_index, u8 is_ip4)
71{
72 if (sctp_main.ip_lookup_tx_frames[!is_ip4][thread_index])
73 {
74 u32 next_index;
75 next_index = is_ip4 ? ip4_lookup_node.index : ip6_lookup_node.index;
76 vlib_put_frame_to_node (vm, next_index,
77 sctp_main.ip_lookup_tx_frames[!is_ip4]
78 [thread_index]);
79 sctp_main.ip_lookup_tx_frames[!is_ip4][thread_index] = 0;
80 }
81}
82
83/**
84 * Flush v4 and v6 sctp and ip-lookup tx frames for thread index
85 */
86void
87sctp_flush_frames_to_output (u8 thread_index)
88{
89 vlib_main_t *vm = vlib_get_main ();
90 sctp_flush_frame_to_output (vm, thread_index, 1);
91 sctp_flush_frame_to_output (vm, thread_index, 0);
92 sctp_flush_frame_to_ip_lookup (vm, thread_index, 1);
93 sctp_flush_frame_to_ip_lookup (vm, thread_index, 0);
94}
95
96u32
97ip4_sctp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
98 ip4_header_t * ip0)
99{
100 ip_csum_t checksum;
101 u32 ip_header_length, payload_length_host_byte_order;
102 u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
103 void *data_this_buffer;
104
105 /* Initialize checksum with ip header. */
106 ip_header_length = ip4_header_bytes (ip0);
107 payload_length_host_byte_order =
108 clib_net_to_host_u16 (ip0->length) - ip_header_length;
109 checksum =
110 clib_host_to_net_u32 (payload_length_host_byte_order +
111 (ip0->protocol << 16));
112
113 if (BITS (uword) == 32)
114 {
115 checksum =
116 ip_csum_with_carry (checksum,
117 clib_mem_unaligned (&ip0->src_address, u32));
118 checksum =
119 ip_csum_with_carry (checksum,
120 clib_mem_unaligned (&ip0->dst_address, u32));
121 }
122 else
123 checksum =
124 ip_csum_with_carry (checksum,
125 clib_mem_unaligned (&ip0->src_address, u64));
126
127 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
128 data_this_buffer = (void *) ip0 + ip_header_length;
129 n_ip_bytes_this_buffer =
130 p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data);
131 if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
132 {
133 n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
134 n_ip_bytes_this_buffer - ip_header_length : 0;
135 }
136 while (1)
137 {
138 checksum =
139 ip_incremental_checksum (checksum, data_this_buffer, n_this_buffer);
140 n_bytes_left -= n_this_buffer;
141 if (n_bytes_left == 0)
142 break;
143
144 ASSERT (p0->flags & VLIB_BUFFER_NEXT_PRESENT);
145 p0 = vlib_get_buffer (vm, p0->next_buffer);
146 data_this_buffer = vlib_buffer_get_current (p0);
147 n_this_buffer = p0->current_length;
148 }
149
150 return checksum;
151}
152
153u32
154ip6_sctp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
155 ip6_header_t * ip0, int *bogus_lengthp)
156{
157 ip_csum_t checksum;
158 u16 payload_length_host_byte_order;
159 u32 i, n_this_buffer, n_bytes_left;
160 u32 headers_size = sizeof (ip0[0]);
161 void *data_this_buffer;
162
163 ASSERT (bogus_lengthp);
164 *bogus_lengthp = 0;
165
166 /* Initialize checksum with ip header. */
167 checksum = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
168 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
169 data_this_buffer = (void *) (ip0 + 1);
170
171 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
172 {
173 checksum = ip_csum_with_carry (checksum,
174 clib_mem_unaligned (&ip0->
175 src_address.as_uword
176 [i], uword));
177 checksum =
178 ip_csum_with_carry (checksum,
179 clib_mem_unaligned (&ip0->dst_address.as_uword[i],
180 uword));
181 }
182
183 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets)
184 * or UDP-Ping packets */
185 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
186 {
187 u32 skip_bytes;
188 ip6_hop_by_hop_ext_t *ext_hdr =
189 (ip6_hop_by_hop_ext_t *) data_this_buffer;
190
191 /* validate really icmp6 next */
192 ASSERT ((ext_hdr->next_hdr == IP_PROTOCOL_SCTP));
193
194 skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
195 data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
196
197 payload_length_host_byte_order -= skip_bytes;
198 headers_size += skip_bytes;
199 }
200
201 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
202 if (p0 && n_this_buffer + headers_size > p0->current_length)
203 n_this_buffer =
204 p0->current_length >
205 headers_size ? p0->current_length - headers_size : 0;
206 while (1)
207 {
208 checksum =
209 ip_incremental_checksum (checksum, data_this_buffer, n_this_buffer);
210 n_bytes_left -= n_this_buffer;
211 if (n_bytes_left == 0)
212 break;
213
214 if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
215 {
216 *bogus_lengthp = 1;
217 return 0xfefe;
218 }
219 p0 = vlib_get_buffer (vm, p0->next_buffer);
220 data_this_buffer = vlib_buffer_get_current (p0);
221 n_this_buffer = p0->current_length;
222 }
223
224 return checksum;
225}
226
227void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100228sctp_push_ip_hdr (sctp_main_t * tm, sctp_sub_connection_t * sctp_sub_conn,
Marco Varlese191a5942017-10-30 18:17:21 +0100229 vlib_buffer_t * b)
230{
231 sctp_header_t *th = vlib_buffer_get_current (b);
232 vlib_main_t *vm = vlib_get_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100233 if (sctp_sub_conn->c_is_ip4)
Marco Varlese191a5942017-10-30 18:17:21 +0100234 {
235 ip4_header_t *ih;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100236 ih = vlib_buffer_push_ip4 (vm, b, &sctp_sub_conn->c_lcl_ip4,
237 &sctp_sub_conn->c_rmt_ip4, IP_PROTOCOL_SCTP,
238 1);
Marco Varlese191a5942017-10-30 18:17:21 +0100239 th->checksum = ip4_sctp_compute_checksum (vm, b, ih);
240 }
241 else
242 {
243 ip6_header_t *ih;
244 int bogus = ~0;
245
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100246 ih = vlib_buffer_push_ip6 (vm, b, &sctp_sub_conn->c_lcl_ip6,
247 &sctp_sub_conn->c_rmt_ip6, IP_PROTOCOL_SCTP);
Marco Varlese191a5942017-10-30 18:17:21 +0100248 th->checksum = ip6_sctp_compute_checksum (vm, b, ih, &bogus);
249 ASSERT (!bogus);
250 }
251}
252
253always_inline void *
254sctp_reuse_buffer (vlib_main_t * vm, vlib_buffer_t * b)
255{
256 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
257 vlib_buffer_free_one (vm, b->next_buffer);
258 /* Zero all flags but free list index and trace flag */
259 b->flags &= VLIB_BUFFER_NEXT_PRESENT - 1;
260 b->current_data = 0;
261 b->current_length = 0;
262 b->total_length_not_including_first_buffer = 0;
263 vnet_buffer (b)->sctp.flags = 0;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100264 vnet_buffer (b)->sctp.subconn_idx = MAX_SCTP_CONNECTIONS;
Marco Varlese191a5942017-10-30 18:17:21 +0100265
266 /* Leave enough space for headers */
267 return vlib_buffer_make_headroom (b, MAX_HDRS_LEN);
268}
269
270always_inline void *
271sctp_init_buffer (vlib_main_t * vm, vlib_buffer_t * b)
272{
273 ASSERT ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
Damjan Mariondac03522018-02-01 15:30:13 +0100274 b->flags &= VLIB_BUFFER_NON_DEFAULT_FREELIST;
Marco Varlese191a5942017-10-30 18:17:21 +0100275 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
276 b->total_length_not_including_first_buffer = 0;
277 vnet_buffer (b)->sctp.flags = 0;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100278 vnet_buffer (b)->sctp.subconn_idx = MAX_SCTP_CONNECTIONS;
Marco Varlese191a5942017-10-30 18:17:21 +0100279 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b);
280 /* Leave enough space for headers */
281 return vlib_buffer_make_headroom (b, MAX_HDRS_LEN);
282}
283
284always_inline int
285sctp_alloc_tx_buffers (sctp_main_t * tm, u8 thread_index, u32 n_free_buffers)
286{
287 vlib_main_t *vm = vlib_get_main ();
288 u32 current_length = vec_len (tm->tx_buffers[thread_index]);
289 u32 n_allocated;
290
291 vec_validate (tm->tx_buffers[thread_index],
292 current_length + n_free_buffers - 1);
293 n_allocated =
294 vlib_buffer_alloc (vm, &tm->tx_buffers[thread_index][current_length],
295 n_free_buffers);
296 _vec_len (tm->tx_buffers[thread_index]) = current_length + n_allocated;
297 /* buffer shortage, report failure */
298 if (vec_len (tm->tx_buffers[thread_index]) == 0)
299 {
300 clib_warning ("out of buffers");
301 return -1;
302 }
303 return 0;
304}
305
306always_inline int
307sctp_get_free_buffer_index (sctp_main_t * tm, u32 * bidx)
308{
309 u32 *my_tx_buffers;
310 u32 thread_index = vlib_get_thread_index ();
311 if (PREDICT_FALSE (vec_len (tm->tx_buffers[thread_index]) == 0))
312 {
313 if (sctp_alloc_tx_buffers (tm, thread_index, VLIB_FRAME_SIZE))
314 return -1;
315 }
316 my_tx_buffers = tm->tx_buffers[thread_index];
317 *bidx = my_tx_buffers[vec_len (my_tx_buffers) - 1];
318 _vec_len (my_tx_buffers) -= 1;
319 return 0;
320}
321
322always_inline void
323sctp_enqueue_to_output_i (vlib_main_t * vm, vlib_buffer_t * b, u32 bi,
324 u8 is_ip4, u8 flush)
325{
326 sctp_main_t *tm = vnet_get_sctp_main ();
327 u32 thread_index = vlib_get_thread_index ();
328 u32 *to_next, next_index;
329 vlib_frame_t *f;
330
331 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
332 b->error = 0;
333
334 /* Decide where to send the packet */
335 next_index = is_ip4 ? sctp4_output_node.index : sctp6_output_node.index;
336 sctp_trajectory_add_start (b, 2);
337
338 /* Get frame to v4/6 output node */
339 f = tm->tx_frames[!is_ip4][thread_index];
340 if (!f)
341 {
342 f = vlib_get_frame_to_node (vm, next_index);
343 ASSERT (f);
344 tm->tx_frames[!is_ip4][thread_index] = f;
345 }
346 to_next = vlib_frame_vector_args (f);
347 to_next[f->n_vectors] = bi;
348 f->n_vectors += 1;
349 if (flush || f->n_vectors == VLIB_FRAME_SIZE)
350 {
351 vlib_put_frame_to_node (vm, next_index, f);
352 tm->tx_frames[!is_ip4][thread_index] = 0;
353 }
354}
355
356always_inline void
357sctp_enqueue_to_output_now (vlib_main_t * vm, vlib_buffer_t * b, u32 bi,
358 u8 is_ip4)
359{
360 sctp_enqueue_to_output_i (vm, b, bi, is_ip4, 1);
361}
362
363always_inline void
364sctp_enqueue_to_ip_lookup_i (vlib_main_t * vm, vlib_buffer_t * b, u32 bi,
365 u8 is_ip4, u8 flush)
366{
367 sctp_main_t *tm = vnet_get_sctp_main ();
368 u32 thread_index = vlib_get_thread_index ();
369 u32 *to_next, next_index;
370 vlib_frame_t *f;
371
372 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
373 b->error = 0;
374
375 /* Default FIB for now */
376 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
377
378 /* Send to IP lookup */
379 next_index = is_ip4 ? ip4_lookup_node.index : ip6_lookup_node.index;
380 if (VLIB_BUFFER_TRACE_TRAJECTORY > 0)
381 {
382 b->pre_data[0] = 2;
383 b->pre_data[1] = next_index;
384 }
385
386 f = tm->ip_lookup_tx_frames[!is_ip4][thread_index];
387 if (!f)
388 {
389 f = vlib_get_frame_to_node (vm, next_index);
390 ASSERT (f);
391 tm->ip_lookup_tx_frames[!is_ip4][thread_index] = f;
392 }
393
394 to_next = vlib_frame_vector_args (f);
395 to_next[f->n_vectors] = bi;
396 f->n_vectors += 1;
397 if (flush || f->n_vectors == VLIB_FRAME_SIZE)
398 {
399 vlib_put_frame_to_node (vm, next_index, f);
400 tm->ip_lookup_tx_frames[!is_ip4][thread_index] = 0;
401 }
402}
403
404always_inline void
405sctp_enqueue_to_ip_lookup (vlib_main_t * vm, vlib_buffer_t * b, u32 bi,
406 u8 is_ip4)
407{
408 sctp_enqueue_to_ip_lookup_i (vm, b, bi, is_ip4, 0);
409}
410
Marco Varlese191a5942017-10-30 18:17:21 +0100411/**
412 * Convert buffer to INIT
413 */
414void
Marco Varlese54432f82018-02-15 17:01:56 +0100415sctp_prepare_init_chunk (sctp_connection_t * sctp_conn, u8 idx,
416 vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +0100417{
418 u32 random_seed = random_default_seed ();
419 u16 alloc_bytes = sizeof (sctp_init_chunk_t);
Marco Varlese54432f82018-02-15 17:01:56 +0100420 sctp_sub_connection_t *sub_conn = &sctp_conn->sub_conn[idx];
Marco Varlese191a5942017-10-30 18:17:21 +0100421
422 sctp_ipv4_addr_param_t *ip4_param = 0;
423 sctp_ipv6_addr_param_t *ip6_param = 0;
424
425 if (sub_conn->c_is_ip4)
426 alloc_bytes += sizeof (sctp_ipv4_addr_param_t);
427 else
428 alloc_bytes += sizeof (sctp_ipv6_addr_param_t);
429
430 /* As per RFC 4960 the chunk_length value does NOT contemplate
431 * the size of the first header (see sctp_header_t) and any padding
432 */
433 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
434
435 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
436
437 sctp_init_chunk_t *init_chunk = vlib_buffer_push_uninit (b, alloc_bytes);
438
439 u16 pointer_offset = sizeof (init_chunk);
440 if (sub_conn->c_is_ip4)
441 {
442 ip4_param = (sctp_ipv4_addr_param_t *) init_chunk + pointer_offset;
443 ip4_param->address.as_u32 = sub_conn->c_lcl_ip.ip4.as_u32;
444
445 pointer_offset += sizeof (sctp_ipv4_addr_param_t);
446 }
447 else
448 {
449 ip6_param = (sctp_ipv6_addr_param_t *) init_chunk + pointer_offset;
450 ip6_param->address.as_u64[0] = sub_conn->c_lcl_ip.ip6.as_u64[0];
451 ip6_param->address.as_u64[1] = sub_conn->c_lcl_ip.ip6.as_u64[1];
452
453 pointer_offset += sizeof (sctp_ipv6_addr_param_t);
454 }
455
456 init_chunk->sctp_hdr.src_port = sub_conn->c_lcl_port; /* No need of host_to_net conversion, already in net-byte order */
457 init_chunk->sctp_hdr.dst_port = sub_conn->c_rmt_port; /* No need of host_to_net conversion, already in net-byte order */
458 init_chunk->sctp_hdr.checksum = 0;
459 /* The sender of an INIT must set the VERIFICATION_TAG to 0 as per RFC 4960 Section 8.5.1 */
460 init_chunk->sctp_hdr.verification_tag = 0x0;
461
462 vnet_sctp_set_chunk_type (&init_chunk->chunk_hdr, INIT);
463 vnet_sctp_set_chunk_length (&init_chunk->chunk_hdr, chunk_len);
464 vnet_sctp_common_hdr_params_host_to_net (&init_chunk->chunk_hdr);
465
Marco Varlesef3ab4892018-02-19 15:23:13 +0100466 init_chunk->a_rwnd = clib_host_to_net_u32 (sctp_conn->sub_conn[idx].cwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100467 init_chunk->initiate_tag = clib_host_to_net_u32 (random_u32 (&random_seed));
468 init_chunk->inboud_streams_count =
469 clib_host_to_net_u16 (INBOUND_STREAMS_COUNT);
470 init_chunk->outbound_streams_count =
471 clib_host_to_net_u16 (OUTBOUND_STREAMS_COUNT);
472
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100473 init_chunk->initial_tsn =
474 clib_host_to_net_u32 (sctp_conn->local_initial_tsn);
475 SCTP_CONN_TRACKING_DBG ("sctp_conn->local_initial_tsn = %u",
476 sctp_conn->local_initial_tsn);
477
Marco Varlese191a5942017-10-30 18:17:21 +0100478 sctp_conn->local_tag = init_chunk->initiate_tag;
479
480 vnet_buffer (b)->sctp.connection_index = sub_conn->c_c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100481 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100482
483 SCTP_DBG_STATE_MACHINE ("CONN_INDEX = %u, CURR_CONN_STATE = %u (%s), "
484 "CHUNK_TYPE = %s, "
485 "SRC_PORT = %u, DST_PORT = %u",
486 sub_conn->connection.c_index,
487 sctp_conn->state,
488 sctp_state_to_string (sctp_conn->state),
489 sctp_chunk_to_string (INIT),
490 init_chunk->sctp_hdr.src_port,
491 init_chunk->sctp_hdr.dst_port);
492}
493
Marco Varlese91389ac2018-01-31 11:00:01 +0100494void
495sctp_compute_mac (sctp_connection_t * sctp_conn,
496 sctp_state_cookie_param_t * state_cookie)
Marco Varlese191a5942017-10-30 18:17:21 +0100497{
Marco Varlese91389ac2018-01-31 11:00:01 +0100498#if OPENSSL_VERSION_NUMBER >= 0x10100000L
499 HMAC_CTX *ctx;
500#else
501 HMAC_CTX ctx;
Marco Varlese91389ac2018-01-31 11:00:01 +0100502#endif
503 unsigned int len = 0;
Marco Varlese18b63152018-02-12 09:08:21 +0100504 const EVP_MD *md = EVP_sha1 ();
Marco Varlese91389ac2018-01-31 11:00:01 +0100505#if OPENSSL_VERSION_NUMBER >= 0x10100000L
506 ctx = HMAC_CTX_new ();
Marco Varlese18b63152018-02-12 09:08:21 +0100507 HMAC_Init_ex (ctx, &state_cookie->creation_time,
Marco Varlese91389ac2018-01-31 11:00:01 +0100508 sizeof (state_cookie->creation_time), md, NULL);
509 HMAC_Update (ctx, (const unsigned char *) &sctp_conn, sizeof (sctp_conn));
510 HMAC_Final (ctx, state_cookie->mac, &len);
511#else
512 HMAC_CTX_init (&ctx);
513 HMAC_Init_ex (&ctx, &state_cookie->creation_time,
514 sizeof (state_cookie->creation_time), md, NULL);
Marco Varlese91389ac2018-01-31 11:00:01 +0100515 HMAC_Update (&ctx, (const unsigned char *) &sctp_conn, sizeof (sctp_conn));
516 HMAC_Final (&ctx, state_cookie->mac, &len);
517 HMAC_CTX_cleanup (&ctx);
518#endif
519
520 ENDIANESS_SWAP (state_cookie->mac);
Marco Varlese191a5942017-10-30 18:17:21 +0100521}
522
523void
Marco Varlese54432f82018-02-15 17:01:56 +0100524sctp_prepare_cookie_ack_chunk (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100525 vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +0100526{
527 vlib_main_t *vm = vlib_get_main ();
Marco Varlese191a5942017-10-30 18:17:21 +0100528
529 sctp_reuse_buffer (vm, b);
530
531 u16 alloc_bytes = sizeof (sctp_cookie_ack_chunk_t);
532
533 /* As per RFC 4960 the chunk_length value does NOT contemplate
534 * the size of the first header (see sctp_header_t) and any padding
535 */
536 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
537
538 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
539
540 sctp_cookie_ack_chunk_t *cookie_ack_chunk =
541 vlib_buffer_push_uninit (b, alloc_bytes);
542
543 cookie_ack_chunk->sctp_hdr.checksum = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100544 cookie_ack_chunk->sctp_hdr.src_port =
545 sctp_conn->sub_conn[idx].connection.lcl_port;
546 cookie_ack_chunk->sctp_hdr.dst_port =
547 sctp_conn->sub_conn[idx].connection.rmt_port;
548 cookie_ack_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +0100549 vnet_sctp_set_chunk_type (&cookie_ack_chunk->chunk_hdr, COOKIE_ACK);
550 vnet_sctp_set_chunk_length (&cookie_ack_chunk->chunk_hdr, chunk_len);
551
552 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100553 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100554 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100555}
556
557void
Marco Varlese54432f82018-02-15 17:01:56 +0100558sctp_prepare_cookie_echo_chunk (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100559 vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +0100560 sctp_state_cookie_param_t * sc)
561{
562 vlib_main_t *vm = vlib_get_main ();
Marco Varlese191a5942017-10-30 18:17:21 +0100563
564 sctp_reuse_buffer (vm, b);
565
566 /* The minimum size of the message is given by the sctp_init_ack_chunk_t */
567 u16 alloc_bytes = sizeof (sctp_cookie_echo_chunk_t);
568 /* As per RFC 4960 the chunk_length value does NOT contemplate
569 * the size of the first header (see sctp_header_t) and any padding
570 */
571 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
572 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
573 sctp_cookie_echo_chunk_t *cookie_echo_chunk =
574 vlib_buffer_push_uninit (b, alloc_bytes);
575 cookie_echo_chunk->sctp_hdr.checksum = 0;
576 cookie_echo_chunk->sctp_hdr.src_port =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100577 sctp_conn->sub_conn[idx].connection.lcl_port;
Marco Varlese191a5942017-10-30 18:17:21 +0100578 cookie_echo_chunk->sctp_hdr.dst_port =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100579 sctp_conn->sub_conn[idx].connection.rmt_port;
580 cookie_echo_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +0100581 vnet_sctp_set_chunk_type (&cookie_echo_chunk->chunk_hdr, COOKIE_ECHO);
582 vnet_sctp_set_chunk_length (&cookie_echo_chunk->chunk_hdr, chunk_len);
583 clib_memcpy (&(cookie_echo_chunk->cookie), sc,
584 sizeof (sctp_state_cookie_param_t));
Marco Varlese21c8baf2018-02-02 17:17:51 +0100585
Marco Varlese191a5942017-10-30 18:17:21 +0100586 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100587 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100588 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100589}
590
591/**
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100592 * Convert buffer to ERROR
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100593 */
Marco Varlese200fa322018-02-26 16:33:54 +0100594void
595sctp_prepare_operation_error (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100596 vlib_buffer_t * b, u8 err_cause)
Marco Varlese200fa322018-02-26 16:33:54 +0100597{
598 vlib_main_t *vm = vlib_get_main ();
599
600 sctp_reuse_buffer (vm, b);
601
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100602 /* The minimum size of the message is given by the sctp_operation_error_t */
603 u16 alloc_bytes =
604 sizeof (sctp_operation_error_t) + sizeof (sctp_err_cause_param_t);
Marco Varlese200fa322018-02-26 16:33:54 +0100605
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100606 /* As per RFC 4960 the chunk_length value does NOT contemplate
607 * the size of the first header (see sctp_header_t) and any padding
608 */
Marco Varlese200fa322018-02-26 16:33:54 +0100609 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
610
611 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
612
613 sctp_operation_error_t *err_chunk =
614 vlib_buffer_push_uninit (b, alloc_bytes);
615
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100616 /* src_port & dst_port are already in network byte-order */
Marco Varlese200fa322018-02-26 16:33:54 +0100617 err_chunk->sctp_hdr.checksum = 0;
618 err_chunk->sctp_hdr.src_port = sctp_conn->sub_conn[idx].connection.lcl_port;
619 err_chunk->sctp_hdr.dst_port = sctp_conn->sub_conn[idx].connection.rmt_port;
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100620 /* As per RFC4960 Section 5.2.2: copy the INITIATE_TAG into the VERIFICATION_TAG of the ABORT chunk */
Marco Varlese200fa322018-02-26 16:33:54 +0100621 err_chunk->sctp_hdr.verification_tag = sctp_conn->local_tag;
622
Marco Varlese8c5f67f2018-02-27 09:38:31 +0100623 err_chunk->err_causes[0].param_hdr.length =
624 clib_host_to_net_u16 (sizeof (err_chunk->err_causes[0].param_hdr.type) +
625 sizeof (err_chunk->err_causes[0].param_hdr.length));
626 err_chunk->err_causes[0].param_hdr.type = clib_host_to_net_u16 (err_cause);
627
Marco Varlese200fa322018-02-26 16:33:54 +0100628 vnet_sctp_set_chunk_type (&err_chunk->chunk_hdr, OPERATION_ERROR);
629 vnet_sctp_set_chunk_length (&err_chunk->chunk_hdr, chunk_len);
630
631 vnet_buffer (b)->sctp.connection_index =
632 sctp_conn->sub_conn[idx].connection.c_index;
633 vnet_buffer (b)->sctp.subconn_idx = idx;
634}
Marco Varlese200fa322018-02-26 16:33:54 +0100635
636/**
637 * Convert buffer to ABORT
638 */
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100639void
640sctp_prepare_abort_for_collision (sctp_connection_t * sctp_conn, u8 idx,
641 vlib_buffer_t * b, ip4_address_t * ip4_addr,
642 ip6_address_t * ip6_addr)
643{
644 vlib_main_t *vm = vlib_get_main ();
645
646 sctp_reuse_buffer (vm, b);
647
648 /* The minimum size of the message is given by the sctp_abort_chunk_t */
649 u16 alloc_bytes = sizeof (sctp_abort_chunk_t);
650
651 /* As per RFC 4960 the chunk_length value does NOT contemplate
652 * the size of the first header (see sctp_header_t) and any padding
653 */
654 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
655
656 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
657
658 sctp_abort_chunk_t *abort_chunk = vlib_buffer_push_uninit (b, alloc_bytes);
659
660 /* src_port & dst_port are already in network byte-order */
661 abort_chunk->sctp_hdr.checksum = 0;
662 abort_chunk->sctp_hdr.src_port =
663 sctp_conn->sub_conn[idx].connection.lcl_port;
664 abort_chunk->sctp_hdr.dst_port =
665 sctp_conn->sub_conn[idx].connection.rmt_port;
666 /* As per RFC4960 Section 5.2.2: copy the INITIATE_TAG into the VERIFICATION_TAG of the ABORT chunk */
667 abort_chunk->sctp_hdr.verification_tag = sctp_conn->local_tag;
668
669 vnet_sctp_set_chunk_type (&abort_chunk->chunk_hdr, ABORT);
670 vnet_sctp_set_chunk_length (&abort_chunk->chunk_hdr, chunk_len);
671
672 vnet_buffer (b)->sctp.connection_index =
673 sctp_conn->sub_conn[idx].connection.c_index;
674 vnet_buffer (b)->sctp.subconn_idx = idx;
675}
676
677/**
678 * Convert buffer to INIT-ACK
679 */
680void
681sctp_prepare_initack_chunk_for_collision (sctp_connection_t * sctp_conn,
682 u8 idx, vlib_buffer_t * b,
683 ip4_address_t * ip4_addr,
684 ip6_address_t * ip6_addr)
685{
686 vlib_main_t *vm = vlib_get_main ();
687 sctp_ipv4_addr_param_t *ip4_param = 0;
688 sctp_ipv6_addr_param_t *ip6_param = 0;
689
690 sctp_reuse_buffer (vm, b);
691
692 /* The minimum size of the message is given by the sctp_init_ack_chunk_t */
693 u16 alloc_bytes =
694 sizeof (sctp_init_ack_chunk_t) + sizeof (sctp_state_cookie_param_t);
695
696 if (PREDICT_TRUE (ip4_addr != NULL))
697 {
698 /* Create room for variable-length fields in the INIT_ACK chunk */
699 alloc_bytes += SCTP_IPV4_ADDRESS_TYPE_LENGTH;
700 }
701 if (PREDICT_TRUE (ip6_addr != NULL))
702 {
703 /* Create room for variable-length fields in the INIT_ACK chunk */
704 alloc_bytes += SCTP_IPV6_ADDRESS_TYPE_LENGTH;
705 }
706
707 if (sctp_conn->sub_conn[idx].connection.is_ip4)
708 alloc_bytes += sizeof (sctp_ipv4_addr_param_t);
709 else
710 alloc_bytes += sizeof (sctp_ipv6_addr_param_t);
711
712 /* As per RFC 4960 the chunk_length value does NOT contemplate
713 * the size of the first header (see sctp_header_t) and any padding
714 */
715 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
716
717 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
718
719 sctp_init_ack_chunk_t *init_ack_chunk =
720 vlib_buffer_push_uninit (b, alloc_bytes);
721
722 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
723
724 /* Create State Cookie parameter */
725 sctp_state_cookie_param_t *state_cookie_param =
726 (sctp_state_cookie_param_t *) ((char *) init_ack_chunk + pointer_offset);
727
728 state_cookie_param->param_hdr.type =
729 clib_host_to_net_u16 (SCTP_STATE_COOKIE_TYPE);
730 state_cookie_param->param_hdr.length =
731 clib_host_to_net_u16 (sizeof (sctp_state_cookie_param_t));
732 state_cookie_param->creation_time = clib_host_to_net_u32 (sctp_time_now ());
733 state_cookie_param->cookie_lifespan =
734 clib_host_to_net_u32 (SCTP_VALID_COOKIE_LIFE);
735
736 sctp_compute_mac (sctp_conn, state_cookie_param);
737
738 pointer_offset += sizeof (sctp_state_cookie_param_t);
739
740 if (PREDICT_TRUE (ip4_addr != NULL))
741 {
742 sctp_ipv4_addr_param_t *ipv4_addr =
743 (sctp_ipv4_addr_param_t *) init_ack_chunk + pointer_offset;
744
745 ipv4_addr->param_hdr.type =
746 clib_host_to_net_u16 (SCTP_IPV4_ADDRESS_TYPE);
747 ipv4_addr->param_hdr.length =
748 clib_host_to_net_u16 (SCTP_IPV4_ADDRESS_TYPE_LENGTH);
749 ipv4_addr->address.as_u32 = ip4_addr->as_u32;
750
751 pointer_offset += SCTP_IPV4_ADDRESS_TYPE_LENGTH;
752 }
753 if (PREDICT_TRUE (ip6_addr != NULL))
754 {
755 sctp_ipv6_addr_param_t *ipv6_addr =
756 (sctp_ipv6_addr_param_t *) init_ack_chunk + pointer_offset;
757
758 ipv6_addr->param_hdr.type =
759 clib_host_to_net_u16 (SCTP_IPV6_ADDRESS_TYPE);
760 ipv6_addr->param_hdr.length =
761 clib_host_to_net_u16 (SCTP_IPV6_ADDRESS_TYPE_LENGTH);
762 ipv6_addr->address.as_u64[0] = ip6_addr->as_u64[0];
763 ipv6_addr->address.as_u64[1] = ip6_addr->as_u64[1];
764
765 pointer_offset += SCTP_IPV6_ADDRESS_TYPE_LENGTH;
766 }
767
768 if (sctp_conn->sub_conn[idx].connection.is_ip4)
769 {
770 ip4_param = (sctp_ipv4_addr_param_t *) init_ack_chunk + pointer_offset;
771 ip4_param->address.as_u32 =
772 sctp_conn->sub_conn[idx].connection.lcl_ip.ip4.as_u32;
773
774 pointer_offset += sizeof (sctp_ipv4_addr_param_t);
775 }
776 else
777 {
778 ip6_param = (sctp_ipv6_addr_param_t *) init_ack_chunk + pointer_offset;
779 ip6_param->address.as_u64[0] =
780 sctp_conn->sub_conn[idx].connection.lcl_ip.ip6.as_u64[0];
781 ip6_param->address.as_u64[1] =
782 sctp_conn->sub_conn[idx].connection.lcl_ip.ip6.as_u64[1];
783
784 pointer_offset += sizeof (sctp_ipv6_addr_param_t);
785 }
786
787 /* src_port & dst_port are already in network byte-order */
788 init_ack_chunk->sctp_hdr.checksum = 0;
789 init_ack_chunk->sctp_hdr.src_port =
790 sctp_conn->sub_conn[idx].connection.lcl_port;
791 init_ack_chunk->sctp_hdr.dst_port =
792 sctp_conn->sub_conn[idx].connection.rmt_port;
793 /* the sctp_conn->verification_tag is already in network byte-order (being a copy of the init_tag coming with the INIT chunk) */
794 init_ack_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
795 init_ack_chunk->initial_tsn =
796 clib_host_to_net_u32 (sctp_conn->local_initial_tsn);
797 SCTP_CONN_TRACKING_DBG ("init_ack_chunk->initial_tsn = %u",
798 init_ack_chunk->initial_tsn);
799
800 vnet_sctp_set_chunk_type (&init_ack_chunk->chunk_hdr, INIT_ACK);
801 vnet_sctp_set_chunk_length (&init_ack_chunk->chunk_hdr, chunk_len);
802
803 init_ack_chunk->initiate_tag = sctp_conn->local_tag;
804
805 init_ack_chunk->a_rwnd =
806 clib_host_to_net_u32 (sctp_conn->sub_conn[idx].cwnd);
807 init_ack_chunk->inboud_streams_count =
808 clib_host_to_net_u16 (INBOUND_STREAMS_COUNT);
809 init_ack_chunk->outbound_streams_count =
810 clib_host_to_net_u16 (OUTBOUND_STREAMS_COUNT);
811
812 vnet_buffer (b)->sctp.connection_index =
813 sctp_conn->sub_conn[idx].connection.c_index;
814 vnet_buffer (b)->sctp.subconn_idx = idx;
815}
816
817/**
Marco Varlese191a5942017-10-30 18:17:21 +0100818 * Convert buffer to INIT-ACK
819 */
820void
Marco Varlese54432f82018-02-15 17:01:56 +0100821sctp_prepare_initack_chunk (sctp_connection_t * sctp_conn, u8 idx,
822 vlib_buffer_t * b, ip4_address_t * ip4_addr,
Marco Varlese191a5942017-10-30 18:17:21 +0100823 ip6_address_t * ip6_addr)
824{
825 vlib_main_t *vm = vlib_get_main ();
826 sctp_ipv4_addr_param_t *ip4_param = 0;
827 sctp_ipv6_addr_param_t *ip6_param = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100828 u32 random_seed = random_default_seed ();
829
830 sctp_reuse_buffer (vm, b);
831
832 /* The minimum size of the message is given by the sctp_init_ack_chunk_t */
833 u16 alloc_bytes =
834 sizeof (sctp_init_ack_chunk_t) + sizeof (sctp_state_cookie_param_t);
835
836 if (PREDICT_TRUE (ip4_addr != NULL))
837 {
838 /* Create room for variable-length fields in the INIT_ACK chunk */
839 alloc_bytes += SCTP_IPV4_ADDRESS_TYPE_LENGTH;
840 }
841 if (PREDICT_TRUE (ip6_addr != NULL))
842 {
843 /* Create room for variable-length fields in the INIT_ACK chunk */
844 alloc_bytes += SCTP_IPV6_ADDRESS_TYPE_LENGTH;
845 }
846
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100847 if (sctp_conn->sub_conn[idx].connection.is_ip4)
Marco Varlese191a5942017-10-30 18:17:21 +0100848 alloc_bytes += sizeof (sctp_ipv4_addr_param_t);
849 else
850 alloc_bytes += sizeof (sctp_ipv6_addr_param_t);
851
852 /* As per RFC 4960 the chunk_length value does NOT contemplate
853 * the size of the first header (see sctp_header_t) and any padding
854 */
855 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
856
857 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
858
859 sctp_init_ack_chunk_t *init_ack_chunk =
860 vlib_buffer_push_uninit (b, alloc_bytes);
861
862 u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
863
864 /* Create State Cookie parameter */
865 sctp_state_cookie_param_t *state_cookie_param =
866 (sctp_state_cookie_param_t *) ((char *) init_ack_chunk + pointer_offset);
867
868 state_cookie_param->param_hdr.type =
869 clib_host_to_net_u16 (SCTP_STATE_COOKIE_TYPE);
870 state_cookie_param->param_hdr.length =
871 clib_host_to_net_u16 (sizeof (sctp_state_cookie_param_t));
872 state_cookie_param->creation_time = clib_host_to_net_u32 (sctp_time_now ());
873 state_cookie_param->cookie_lifespan =
874 clib_host_to_net_u32 (SCTP_VALID_COOKIE_LIFE);
Marco Varlese91389ac2018-01-31 11:00:01 +0100875
876 sctp_compute_mac (sctp_conn, state_cookie_param);
Marco Varlese191a5942017-10-30 18:17:21 +0100877
878 pointer_offset += sizeof (sctp_state_cookie_param_t);
879
880 if (PREDICT_TRUE (ip4_addr != NULL))
881 {
882 sctp_ipv4_addr_param_t *ipv4_addr =
883 (sctp_ipv4_addr_param_t *) init_ack_chunk + pointer_offset;
884
885 ipv4_addr->param_hdr.type =
886 clib_host_to_net_u16 (SCTP_IPV4_ADDRESS_TYPE);
887 ipv4_addr->param_hdr.length =
888 clib_host_to_net_u16 (SCTP_IPV4_ADDRESS_TYPE_LENGTH);
889 ipv4_addr->address.as_u32 = ip4_addr->as_u32;
890
891 pointer_offset += SCTP_IPV4_ADDRESS_TYPE_LENGTH;
892 }
893 if (PREDICT_TRUE (ip6_addr != NULL))
894 {
895 sctp_ipv6_addr_param_t *ipv6_addr =
Marco Varlesef429a932018-02-06 17:31:06 +0100896 (sctp_ipv6_addr_param_t *) init_ack_chunk + pointer_offset;
Marco Varlese191a5942017-10-30 18:17:21 +0100897
898 ipv6_addr->param_hdr.type =
899 clib_host_to_net_u16 (SCTP_IPV6_ADDRESS_TYPE);
900 ipv6_addr->param_hdr.length =
901 clib_host_to_net_u16 (SCTP_IPV6_ADDRESS_TYPE_LENGTH);
902 ipv6_addr->address.as_u64[0] = ip6_addr->as_u64[0];
903 ipv6_addr->address.as_u64[1] = ip6_addr->as_u64[1];
904
905 pointer_offset += SCTP_IPV6_ADDRESS_TYPE_LENGTH;
906 }
907
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100908 if (sctp_conn->sub_conn[idx].connection.is_ip4)
Marco Varlese191a5942017-10-30 18:17:21 +0100909 {
910 ip4_param = (sctp_ipv4_addr_param_t *) init_ack_chunk + pointer_offset;
911 ip4_param->address.as_u32 =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100912 sctp_conn->sub_conn[idx].connection.lcl_ip.ip4.as_u32;
Marco Varlese191a5942017-10-30 18:17:21 +0100913
914 pointer_offset += sizeof (sctp_ipv4_addr_param_t);
915 }
916 else
917 {
918 ip6_param = (sctp_ipv6_addr_param_t *) init_ack_chunk + pointer_offset;
919 ip6_param->address.as_u64[0] =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100920 sctp_conn->sub_conn[idx].connection.lcl_ip.ip6.as_u64[0];
Marco Varlese191a5942017-10-30 18:17:21 +0100921 ip6_param->address.as_u64[1] =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100922 sctp_conn->sub_conn[idx].connection.lcl_ip.ip6.as_u64[1];
Marco Varlese191a5942017-10-30 18:17:21 +0100923
924 pointer_offset += sizeof (sctp_ipv6_addr_param_t);
925 }
926
927 /* src_port & dst_port are already in network byte-order */
928 init_ack_chunk->sctp_hdr.checksum = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100929 init_ack_chunk->sctp_hdr.src_port =
930 sctp_conn->sub_conn[idx].connection.lcl_port;
931 init_ack_chunk->sctp_hdr.dst_port =
932 sctp_conn->sub_conn[idx].connection.rmt_port;
933 /* the sctp_conn->verification_tag is already in network byte-order (being a copy of the init_tag coming with the INIT chunk) */
934 init_ack_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
935 init_ack_chunk->initial_tsn =
936 clib_host_to_net_u32 (sctp_conn->local_initial_tsn);
937 SCTP_CONN_TRACKING_DBG ("init_ack_chunk->initial_tsn = %u",
938 init_ack_chunk->initial_tsn);
Marco Varlese191a5942017-10-30 18:17:21 +0100939
940 vnet_sctp_set_chunk_type (&init_ack_chunk->chunk_hdr, INIT_ACK);
941 vnet_sctp_set_chunk_length (&init_ack_chunk->chunk_hdr, chunk_len);
942
943 init_ack_chunk->initiate_tag =
944 clib_host_to_net_u32 (random_u32 (&random_seed));
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100945
Marco Varlesef3ab4892018-02-19 15:23:13 +0100946 init_ack_chunk->a_rwnd =
947 clib_host_to_net_u32 (sctp_conn->sub_conn[idx].cwnd);
Marco Varlese191a5942017-10-30 18:17:21 +0100948 init_ack_chunk->inboud_streams_count =
949 clib_host_to_net_u16 (INBOUND_STREAMS_COUNT);
950 init_ack_chunk->outbound_streams_count =
951 clib_host_to_net_u16 (OUTBOUND_STREAMS_COUNT);
952
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100953 sctp_conn->local_tag = init_ack_chunk->initiate_tag;
Marco Varlese191a5942017-10-30 18:17:21 +0100954
955 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100956 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100957 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100958}
959
960/**
961 * Convert buffer to SHUTDOWN
962 */
963void
Marco Varlese54432f82018-02-15 17:01:56 +0100964sctp_prepare_shutdown_chunk (sctp_connection_t * sctp_conn, u8 idx,
965 vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +0100966{
Marco Varlese191a5942017-10-30 18:17:21 +0100967 u16 alloc_bytes = sizeof (sctp_shutdown_association_chunk_t);
968
Marco Varlese191a5942017-10-30 18:17:21 +0100969 /* As per RFC 4960 the chunk_length value does NOT contemplate
970 * the size of the first header (see sctp_header_t) and any padding
971 */
972 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
973
974 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
975
976 sctp_shutdown_association_chunk_t *shutdown_chunk =
977 vlib_buffer_push_uninit (b, alloc_bytes);
978
979 shutdown_chunk->sctp_hdr.checksum = 0;
980 /* No need of host_to_net conversion, already in net-byte order */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100981 shutdown_chunk->sctp_hdr.src_port =
982 sctp_conn->sub_conn[idx].connection.lcl_port;
983 shutdown_chunk->sctp_hdr.dst_port =
984 sctp_conn->sub_conn[idx].connection.rmt_port;
985 shutdown_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +0100986 vnet_sctp_set_chunk_type (&shutdown_chunk->chunk_hdr, SHUTDOWN);
987 vnet_sctp_set_chunk_length (&shutdown_chunk->chunk_hdr, chunk_len);
988
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100989 shutdown_chunk->cumulative_tsn_ack = sctp_conn->last_rcvd_tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100990
991 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100992 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +0100993 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100994}
995
996/*
997 * Send SHUTDOWN
998 */
999void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001000sctp_send_shutdown (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +01001001{
1002 vlib_buffer_t *b;
1003 u32 bi;
1004 sctp_main_t *tm = vnet_get_sctp_main ();
1005 vlib_main_t *vm = vlib_get_main ();
1006
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001007 if (sctp_check_outstanding_data_chunks (sctp_conn) > 0)
Marco Varlese191a5942017-10-30 18:17:21 +01001008 return;
1009
1010 if (PREDICT_FALSE (sctp_get_free_buffer_index (tm, &bi)))
1011 return;
1012
Marco Varlese54432f82018-02-15 17:01:56 +01001013 u8 idx = MAIN_SCTP_SUB_CONN_IDX;
1014
Marco Varlese191a5942017-10-30 18:17:21 +01001015 b = vlib_get_buffer (vm, bi);
1016 sctp_init_buffer (vm, b);
Marco Varlese54432f82018-02-15 17:01:56 +01001017 sctp_prepare_shutdown_chunk (sctp_conn, idx, b);
Marco Varlese191a5942017-10-30 18:17:21 +01001018
Marco Varlesebe2251b2018-02-07 12:22:41 +01001019 sctp_enqueue_to_output_now (vm, b, bi,
1020 sctp_conn->sub_conn[idx].connection.is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001021}
1022
1023/**
1024 * Convert buffer to SHUTDOWN_ACK
1025 */
1026void
Marco Varlese54432f82018-02-15 17:01:56 +01001027sctp_prepare_shutdown_ack_chunk (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001028 vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +01001029{
Marco Varlese191a5942017-10-30 18:17:21 +01001030 u16 alloc_bytes = sizeof (sctp_shutdown_association_chunk_t);
1031 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
1032
1033 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
1034
1035 sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1036 vlib_buffer_push_uninit (b, alloc_bytes);
1037
1038 shutdown_ack_chunk->sctp_hdr.checksum = 0;
1039 /* No need of host_to_net conversion, already in net-byte order */
1040 shutdown_ack_chunk->sctp_hdr.src_port =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001041 sctp_conn->sub_conn[idx].connection.lcl_port;
Marco Varlese191a5942017-10-30 18:17:21 +01001042 shutdown_ack_chunk->sctp_hdr.dst_port =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001043 sctp_conn->sub_conn[idx].connection.rmt_port;
1044 shutdown_ack_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +01001045
1046 vnet_sctp_set_chunk_type (&shutdown_ack_chunk->chunk_hdr, SHUTDOWN_ACK);
1047 vnet_sctp_set_chunk_length (&shutdown_ack_chunk->chunk_hdr, chunk_len);
1048
1049 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001050 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +01001051 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001052}
1053
1054/*
1055 * Send SHUTDOWN_ACK
1056 */
1057void
Marco Varlese54432f82018-02-15 17:01:56 +01001058sctp_send_shutdown_ack (sctp_connection_t * sctp_conn, u8 idx,
1059 vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +01001060{
Marco Varlese191a5942017-10-30 18:17:21 +01001061 vlib_main_t *vm = vlib_get_main ();
1062
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001063 if (sctp_check_outstanding_data_chunks (sctp_conn) > 0)
Marco Varlese191a5942017-10-30 18:17:21 +01001064 return;
1065
Marco Varlesebe2251b2018-02-07 12:22:41 +01001066 sctp_reuse_buffer (vm, b);
Marco Varlese191a5942017-10-30 18:17:21 +01001067
Marco Varlese54432f82018-02-15 17:01:56 +01001068 sctp_prepare_shutdown_ack_chunk (sctp_conn, idx, b);
Marco Varlese191a5942017-10-30 18:17:21 +01001069}
1070
1071/**
1072 * Convert buffer to SACK
1073 */
1074void
Marco Varlese54432f82018-02-15 17:01:56 +01001075sctp_prepare_sack_chunk (sctp_connection_t * sctp_conn, u8 idx,
1076 vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +01001077{
1078 vlib_main_t *vm = vlib_get_main ();
Marco Varlese191a5942017-10-30 18:17:21 +01001079
1080 sctp_reuse_buffer (vm, b);
1081
1082 u16 alloc_bytes = sizeof (sctp_selective_ack_chunk_t);
1083
1084 /* As per RFC 4960 the chunk_length value does NOT contemplate
1085 * the size of the first header (see sctp_header_t) and any padding
1086 */
1087 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
1088
1089 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
1090
1091 sctp_selective_ack_chunk_t *sack = vlib_buffer_push_uninit (b, alloc_bytes);
1092
1093 sack->sctp_hdr.checksum = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001094 sack->sctp_hdr.src_port = sctp_conn->sub_conn[idx].connection.lcl_port;
1095 sack->sctp_hdr.dst_port = sctp_conn->sub_conn[idx].connection.rmt_port;
1096 sack->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +01001097 vnet_sctp_set_chunk_type (&sack->chunk_hdr, SACK);
1098 vnet_sctp_set_chunk_length (&sack->chunk_hdr, chunk_len);
1099
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001100 sack->cumulative_tsn_ack = sctp_conn->next_tsn_expected;
1101
1102 sctp_conn->ack_state = 0;
1103
Marco Varlese191a5942017-10-30 18:17:21 +01001104 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001105 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +01001106 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001107}
1108
1109/**
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001110 * Convert buffer to HEARTBEAT_ACK
1111 */
1112void
Marco Varlese54432f82018-02-15 17:01:56 +01001113sctp_prepare_heartbeat_ack_chunk (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001114 vlib_buffer_t * b)
1115{
1116 vlib_main_t *vm = vlib_get_main ();
1117
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001118 u16 alloc_bytes = sizeof (sctp_hb_ack_chunk_t);
1119
1120 sctp_reuse_buffer (vm, b);
1121
1122 /* As per RFC 4960 the chunk_length value does NOT contemplate
1123 * the size of the first header (see sctp_header_t) and any padding
1124 */
1125 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
1126
1127 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
1128
1129 sctp_hb_ack_chunk_t *hb_ack = vlib_buffer_push_uninit (b, alloc_bytes);
1130
1131 hb_ack->sctp_hdr.checksum = 0;
1132 /* No need of host_to_net conversion, already in net-byte order */
1133 hb_ack->sctp_hdr.src_port = sctp_conn->sub_conn[idx].connection.lcl_port;
1134 hb_ack->sctp_hdr.dst_port = sctp_conn->sub_conn[idx].connection.rmt_port;
1135 hb_ack->sctp_hdr.verification_tag = sctp_conn->remote_tag;
1136 hb_ack->hb_info.param_hdr.type = clib_host_to_net_u16 (1);
1137 hb_ack->hb_info.param_hdr.length =
1138 clib_host_to_net_u16 (sizeof (hb_ack->hb_info.hb_info));
1139
1140 vnet_sctp_set_chunk_type (&hb_ack->chunk_hdr, HEARTBEAT_ACK);
1141 vnet_sctp_set_chunk_length (&hb_ack->chunk_hdr, chunk_len);
1142
1143 vnet_buffer (b)->sctp.connection_index =
1144 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +01001145 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001146}
1147
1148/**
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001149 * Convert buffer to HEARTBEAT
1150 */
1151void
Marco Varlese54432f82018-02-15 17:01:56 +01001152sctp_prepare_heartbeat_chunk (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001153 vlib_buffer_t * b)
1154{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001155 u16 alloc_bytes = sizeof (sctp_hb_req_chunk_t);
1156
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001157 /* As per RFC 4960 the chunk_length value does NOT contemplate
1158 * the size of the first header (see sctp_header_t) and any padding
1159 */
1160 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
1161
1162 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
1163
1164 sctp_hb_req_chunk_t *hb_req = vlib_buffer_push_uninit (b, alloc_bytes);
1165
1166 hb_req->sctp_hdr.checksum = 0;
1167 /* No need of host_to_net conversion, already in net-byte order */
1168 hb_req->sctp_hdr.src_port = sctp_conn->sub_conn[idx].connection.lcl_port;
1169 hb_req->sctp_hdr.dst_port = sctp_conn->sub_conn[idx].connection.rmt_port;
1170 hb_req->sctp_hdr.verification_tag = sctp_conn->remote_tag;
1171 hb_req->hb_info.param_hdr.type = clib_host_to_net_u16 (1);
1172 hb_req->hb_info.param_hdr.length =
1173 clib_host_to_net_u16 (sizeof (hb_req->hb_info.hb_info));
1174
1175 vnet_sctp_set_chunk_type (&hb_req->chunk_hdr, HEARTBEAT);
1176 vnet_sctp_set_chunk_length (&hb_req->chunk_hdr, chunk_len);
1177
1178 vnet_buffer (b)->sctp.connection_index =
1179 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +01001180 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001181}
1182
1183void
1184sctp_send_heartbeat (sctp_connection_t * sctp_conn)
1185{
1186 vlib_buffer_t *b;
1187 u32 bi;
1188 sctp_main_t *tm = vnet_get_sctp_main ();
1189 vlib_main_t *vm = vlib_get_main ();
1190
Marco Varlese54432f82018-02-15 17:01:56 +01001191 u8 i;
1192 u32 now = sctp_time_now ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001193
Marco Varlese54432f82018-02-15 17:01:56 +01001194 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
1195 {
1196 if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN)
1197 continue;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001198
Marco Varlese54432f82018-02-15 17:01:56 +01001199 if (now > (sctp_conn->sub_conn[i].last_seen + SCTP_HB_INTERVAL))
1200 {
1201 if (PREDICT_FALSE (sctp_get_free_buffer_index (tm, &bi)))
1202 return;
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001203
Marco Varlese54432f82018-02-15 17:01:56 +01001204 b = vlib_get_buffer (vm, bi);
1205 sctp_init_buffer (vm, b);
1206 sctp_prepare_heartbeat_chunk (sctp_conn, i, b);
1207
1208 sctp_enqueue_to_output_now (vm, b, bi,
1209 sctp_conn->sub_conn[i].
1210 connection.is_ip4);
1211
1212 sctp_conn->sub_conn[i].unacknowledged_hb += 1;
1213 }
1214 }
Marco Varlese191a5942017-10-30 18:17:21 +01001215}
1216
1217/**
1218 * Convert buffer to SHUTDOWN_COMPLETE
1219 */
1220void
Marco Varlese54432f82018-02-15 17:01:56 +01001221sctp_prepare_shutdown_complete_chunk (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlese191a5942017-10-30 18:17:21 +01001222 vlib_buffer_t * b)
1223{
Marco Varlese191a5942017-10-30 18:17:21 +01001224 u16 alloc_bytes = sizeof (sctp_shutdown_association_chunk_t);
1225 alloc_bytes += vnet_sctp_calculate_padding (alloc_bytes);
1226
1227 u16 chunk_len = alloc_bytes - sizeof (sctp_header_t);
1228
1229 sctp_shutdown_complete_chunk_t *shutdown_complete =
1230 vlib_buffer_push_uninit (b, alloc_bytes);
1231
1232 shutdown_complete->sctp_hdr.checksum = 0;
1233 /* No need of host_to_net conversion, already in net-byte order */
1234 shutdown_complete->sctp_hdr.src_port =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001235 sctp_conn->sub_conn[idx].connection.lcl_port;
Marco Varlese191a5942017-10-30 18:17:21 +01001236 shutdown_complete->sctp_hdr.dst_port =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001237 sctp_conn->sub_conn[idx].connection.rmt_port;
1238 shutdown_complete->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +01001239
1240 vnet_sctp_set_chunk_type (&shutdown_complete->chunk_hdr, SHUTDOWN_COMPLETE);
1241 vnet_sctp_set_chunk_length (&shutdown_complete->chunk_hdr, chunk_len);
1242
1243 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001244 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese15cc6a82018-02-21 12:39:52 +01001245 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001246}
1247
1248void
Marco Varlese54432f82018-02-15 17:01:56 +01001249sctp_send_shutdown_complete (sctp_connection_t * sctp_conn, u8 idx,
Marco Varlesefae40392018-02-14 15:38:35 +01001250 vlib_buffer_t * b0)
Marco Varlese191a5942017-10-30 18:17:21 +01001251{
Marco Varlese191a5942017-10-30 18:17:21 +01001252 vlib_main_t *vm = vlib_get_main ();
1253
Marco Varlesefae40392018-02-14 15:38:35 +01001254 if (sctp_check_outstanding_data_chunks (sctp_conn) > 0)
Marco Varlese191a5942017-10-30 18:17:21 +01001255 return;
1256
Marco Varlesefae40392018-02-14 15:38:35 +01001257 sctp_reuse_buffer (vm, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001258
Marco Varlese54432f82018-02-15 17:01:56 +01001259 sctp_prepare_shutdown_complete_chunk (sctp_conn, idx, b0);
Marco Varlese191a5942017-10-30 18:17:21 +01001260}
1261
Marco Varlese191a5942017-10-30 18:17:21 +01001262/*
1263 * Send INIT
1264 */
1265void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001266sctp_send_init (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +01001267{
1268 vlib_buffer_t *b;
1269 u32 bi;
1270 sctp_main_t *tm = vnet_get_sctp_main ();
1271 vlib_main_t *vm = vlib_get_main ();
1272
1273 if (PREDICT_FALSE (sctp_get_free_buffer_index (tm, &bi)))
1274 return;
1275
1276 b = vlib_get_buffer (vm, bi);
Marco Varlese54432f82018-02-15 17:01:56 +01001277 u8 idx = MAIN_SCTP_SUB_CONN_IDX;
Marco Varlese191a5942017-10-30 18:17:21 +01001278
1279 sctp_init_buffer (vm, b);
Marco Varlese54432f82018-02-15 17:01:56 +01001280 sctp_prepare_init_chunk (sctp_conn, idx, b);
Marco Varlese191a5942017-10-30 18:17:21 +01001281
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001282 sctp_push_ip_hdr (tm, &sctp_conn->sub_conn[idx], b);
Marco Varlesedf5a99c2018-02-06 13:48:30 +01001283 sctp_enqueue_to_ip_lookup (vm, b, bi, sctp_conn->sub_conn[idx].c_is_ip4);
Marco Varlese191a5942017-10-30 18:17:21 +01001284
1285 /* Start the T1_INIT timer */
Marco Varlese21c8baf2018-02-02 17:17:51 +01001286 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T1_INIT,
1287 sctp_conn->sub_conn[idx].RTO);
1288
Marco Varlese191a5942017-10-30 18:17:21 +01001289 /* Change state to COOKIE_WAIT */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001290 sctp_conn->state = SCTP_STATE_COOKIE_WAIT;
Marco Varlesea38783e2018-02-13 12:38:52 +01001291
1292 /* Measure RTT with this */
1293 sctp_conn->sub_conn[idx].rtt_ts = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +01001294}
1295
Marco Varlese191a5942017-10-30 18:17:21 +01001296/**
1297 * Push SCTP header and update connection variables
1298 */
1299static void
Marco Varlesef3ab4892018-02-19 15:23:13 +01001300sctp_push_hdr_i (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
Marco Varlese191a5942017-10-30 18:17:21 +01001301 sctp_state_t next_state)
1302{
Marco Varlese191a5942017-10-30 18:17:21 +01001303 u16 data_len =
1304 b->current_length + b->total_length_not_including_first_buffer;
1305 ASSERT (!b->total_length_not_including_first_buffer
1306 || (b->flags & VLIB_BUFFER_NEXT_PRESENT));
1307
1308 SCTP_ADV_DBG_OUTPUT ("b->current_length = %u, "
1309 "b->current_data = %p "
1310 "data_len = %u",
1311 b->current_length, b->current_data, data_len);
1312
1313 u16 bytes_to_add = sizeof (sctp_payload_data_chunk_t);
1314 u16 chunk_length = data_len + bytes_to_add - sizeof (sctp_header_t);
1315
1316 bytes_to_add += vnet_sctp_calculate_padding (bytes_to_add + data_len);
1317
1318 sctp_payload_data_chunk_t *data_chunk =
1319 vlib_buffer_push_uninit (b, bytes_to_add);
1320
Marco Varlesef3ab4892018-02-19 15:23:13 +01001321 u8 idx = sctp_data_subconn_select (sctp_conn);
Marco Varlese15cc6a82018-02-21 12:39:52 +01001322 SCTP_DBG_OUTPUT
Marco Varlese04e5d642018-02-23 17:43:06 +01001323 ("SCTP_CONN = %p, IDX = %u, S_INDEX = %u, C_INDEX = %u, sctp_conn->[...].LCL_PORT = %u, sctp_conn->[...].RMT_PORT = %u",
Marco Varlese15cc6a82018-02-21 12:39:52 +01001324 sctp_conn, idx, sctp_conn->sub_conn[idx].connection.s_index,
1325 sctp_conn->sub_conn[idx].connection.c_index,
1326 sctp_conn->sub_conn[idx].connection.lcl_port,
1327 sctp_conn->sub_conn[idx].connection.rmt_port);
Marco Varlese191a5942017-10-30 18:17:21 +01001328 data_chunk->sctp_hdr.checksum = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001329 data_chunk->sctp_hdr.src_port =
1330 sctp_conn->sub_conn[idx].connection.lcl_port;
1331 data_chunk->sctp_hdr.dst_port =
1332 sctp_conn->sub_conn[idx].connection.rmt_port;
1333 data_chunk->sctp_hdr.verification_tag = sctp_conn->remote_tag;
Marco Varlese191a5942017-10-30 18:17:21 +01001334
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001335 data_chunk->tsn = clib_host_to_net_u32 (sctp_conn->next_tsn);
Marco Varlese191a5942017-10-30 18:17:21 +01001336 data_chunk->stream_id = clib_host_to_net_u16 (0);
1337 data_chunk->stream_seq = clib_host_to_net_u16 (0);
1338
1339 vnet_sctp_set_chunk_type (&data_chunk->chunk_hdr, DATA);
1340 vnet_sctp_set_chunk_length (&data_chunk->chunk_hdr, chunk_length);
1341
Marco Varlese91389ac2018-01-31 11:00:01 +01001342 vnet_sctp_set_bbit (&data_chunk->chunk_hdr);
1343 vnet_sctp_set_ebit (&data_chunk->chunk_hdr);
1344
Marco Varlese191a5942017-10-30 18:17:21 +01001345 SCTP_ADV_DBG_OUTPUT ("POINTER_WITH_DATA = %p, DATA_OFFSET = %u",
1346 b->data, b->current_data);
1347
Marco Varlesef3ab4892018-02-19 15:23:13 +01001348 sctp_conn->last_unacked_tsn = sctp_conn->next_tsn;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001349 sctp_conn->next_tsn += data_len;
1350
Marco Varlesef3ab4892018-02-19 15:23:13 +01001351 u32 inflight = sctp_conn->next_tsn - sctp_conn->last_unacked_tsn;
1352 /* Section 7.2.2; point (3) */
1353 if (sctp_conn->sub_conn[idx].partially_acked_bytes >=
1354 sctp_conn->sub_conn[idx].cwnd
1355 && inflight >= sctp_conn->sub_conn[idx].cwnd)
1356 {
1357 sctp_conn->sub_conn[idx].cwnd += sctp_conn->sub_conn[idx].PMTU;
1358 sctp_conn->sub_conn[idx].partially_acked_bytes -=
1359 sctp_conn->sub_conn[idx].cwnd;
1360 }
1361
1362 sctp_conn->sub_conn[idx].last_data_ts = sctp_time_now ();
1363
Marco Varlese191a5942017-10-30 18:17:21 +01001364 vnet_buffer (b)->sctp.connection_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001365 sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese54432f82018-02-15 17:01:56 +01001366
Marco Varlese15cc6a82018-02-21 12:39:52 +01001367 vnet_buffer (b)->sctp.subconn_idx = idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001368}
1369
1370u32
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001371sctp_push_header (transport_connection_t * trans_conn, vlib_buffer_t * b)
Marco Varlese191a5942017-10-30 18:17:21 +01001372{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001373 sctp_connection_t *sctp_conn =
1374 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +01001375
Marco Varlese15cc6a82018-02-21 12:39:52 +01001376 SCTP_DBG_OUTPUT ("TRANS_CONN = %p, SCTP_CONN = %p, "
1377 "S_INDEX = %u, C_INDEX = %u,"
Marco Varlese04e5d642018-02-23 17:43:06 +01001378 "trans_conn->LCL_PORT = %u, trans_conn->RMT_PORT = %u",
Marco Varlese15cc6a82018-02-21 12:39:52 +01001379 trans_conn,
1380 sctp_conn,
1381 trans_conn->s_index,
1382 trans_conn->c_index,
1383 trans_conn->lcl_port, trans_conn->rmt_port);
1384
Marco Varlesef3ab4892018-02-19 15:23:13 +01001385 sctp_push_hdr_i (sctp_conn, b, SCTP_STATE_ESTABLISHED);
Marco Varlese21c8baf2018-02-02 17:17:51 +01001386
Stevenb95bc052018-02-27 10:29:32 -08001387 sctp_trajectory_add_start (b, 3);
Marco Varlese191a5942017-10-30 18:17:21 +01001388
1389 return 0;
Marco Varlese191a5942017-10-30 18:17:21 +01001390}
1391
Marco Varlesefae40392018-02-14 15:38:35 +01001392#if SCTP_DEBUG_STATE_MACHINE
Marco Varlesea38783e2018-02-13 12:38:52 +01001393always_inline u8
1394sctp_validate_output_state_machine (sctp_connection_t * sctp_conn,
1395 u8 chunk_type)
1396{
1397 u8 result = 0;
1398 switch (sctp_conn->state)
1399 {
1400 case SCTP_STATE_CLOSED:
1401 if (chunk_type != INIT && chunk_type != INIT_ACK)
1402 result = 1;
1403 break;
1404 case SCTP_STATE_ESTABLISHED:
1405 if (chunk_type != DATA && chunk_type != HEARTBEAT &&
1406 chunk_type != HEARTBEAT_ACK && chunk_type != SACK &&
1407 chunk_type != COOKIE_ACK && chunk_type != SHUTDOWN)
1408 result = 1;
1409 break;
1410 case SCTP_STATE_COOKIE_WAIT:
1411 if (chunk_type != COOKIE_ECHO)
1412 result = 1;
1413 break;
1414 case SCTP_STATE_SHUTDOWN_SENT:
1415 if (chunk_type != SHUTDOWN_COMPLETE)
1416 result = 1;
1417 break;
1418 case SCTP_STATE_SHUTDOWN_RECEIVED:
1419 if (chunk_type != SHUTDOWN_ACK)
1420 result = 1;
1421 break;
1422 }
1423 return result;
1424}
Marco Varlesefae40392018-02-14 15:38:35 +01001425#endif
Marco Varlesea38783e2018-02-13 12:38:52 +01001426
1427always_inline u8
1428sctp_is_retransmitting (sctp_connection_t * sctp_conn, u8 idx)
1429{
1430 return sctp_conn->sub_conn[idx].is_retransmitting;
1431}
1432
Marco Varlese191a5942017-10-30 18:17:21 +01001433always_inline uword
1434sctp46_output_inline (vlib_main_t * vm,
1435 vlib_node_runtime_t * node,
1436 vlib_frame_t * from_frame, int is_ip4)
1437{
1438 u32 n_left_from, next_index, *from, *to_next;
1439 u32 my_thread_index = vm->thread_index;
1440
1441 from = vlib_frame_vector_args (from_frame);
1442 n_left_from = from_frame->n_vectors;
1443 next_index = node->cached_next_index;
1444 sctp_set_time_now (my_thread_index);
1445
1446 while (n_left_from > 0)
1447 {
1448 u32 n_left_to_next;
1449
1450 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1451
1452 while (n_left_from > 0 && n_left_to_next > 0)
1453 {
1454 u32 bi0;
1455 vlib_buffer_t *b0;
1456 sctp_header_t *sctp_hdr = 0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001457 sctp_connection_t *sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +01001458 sctp_tx_trace_t *t0;
1459 sctp_header_t *th0 = 0;
1460 u32 error0 = SCTP_ERROR_PKTS_SENT, next0 =
1461 SCTP_OUTPUT_NEXT_IP_LOOKUP;
1462
1463#if SCTP_DEBUG_STATE_MACHINE
1464 u16 packet_length = 0;
1465#endif
1466
1467 bi0 = from[0];
1468 to_next[0] = bi0;
1469 from += 1;
1470 to_next += 1;
1471 n_left_from -= 1;
1472 n_left_to_next -= 1;
1473
1474 b0 = vlib_get_buffer (vm, bi0);
Marco Varlesebe2251b2018-02-07 12:22:41 +01001475
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001476 sctp_conn =
1477 sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1478 my_thread_index);
Marco Varlese191a5942017-10-30 18:17:21 +01001479
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001480 if (PREDICT_FALSE (sctp_conn == 0))
Marco Varlese191a5942017-10-30 18:17:21 +01001481 {
1482 error0 = SCTP_ERROR_INVALID_CONNECTION;
1483 next0 = SCTP_OUTPUT_NEXT_DROP;
1484 goto done;
1485 }
1486
Marco Varlese15cc6a82018-02-21 12:39:52 +01001487 u8 idx = vnet_buffer (b0)->sctp.subconn_idx;
Marco Varlese191a5942017-10-30 18:17:21 +01001488
1489 th0 = vlib_buffer_get_current (b0);
1490
1491 if (is_ip4)
1492 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001493 ip4_header_t *iph4 = vlib_buffer_push_ip4 (vm,
1494 b0,
1495 &sctp_conn->sub_conn
1496 [idx].connection.
1497 lcl_ip.ip4,
1498 &sctp_conn->
1499 sub_conn
1500 [idx].connection.
1501 rmt_ip.ip4,
1502 IP_PROTOCOL_SCTP, 1);
Marco Varlese191a5942017-10-30 18:17:21 +01001503
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001504 u32 checksum = ip4_sctp_compute_checksum (vm, b0, iph4);
Marco Varlese191a5942017-10-30 18:17:21 +01001505
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001506 sctp_hdr = ip4_next_header (iph4);
Marco Varlese191a5942017-10-30 18:17:21 +01001507 sctp_hdr->checksum = checksum;
1508
1509 vnet_buffer (b0)->l4_hdr_offset = (u8 *) th0 - b0->data;
Marco Varlese191a5942017-10-30 18:17:21 +01001510
1511#if SCTP_DEBUG_STATE_MACHINE
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001512 packet_length = clib_net_to_host_u16 (iph4->length);
Marco Varlese191a5942017-10-30 18:17:21 +01001513#endif
1514 }
1515 else
1516 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001517 ip6_header_t *iph6 = vlib_buffer_push_ip6 (vm,
1518 b0,
1519 &sctp_conn->sub_conn
1520 [idx].
1521 connection.lcl_ip.
1522 ip6,
1523 &sctp_conn->sub_conn
1524 [idx].
1525 connection.rmt_ip.
1526 ip6,
1527 IP_PROTOCOL_SCTP);
Marco Varlese191a5942017-10-30 18:17:21 +01001528
1529 int bogus = ~0;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001530 u32 checksum = ip6_sctp_compute_checksum (vm, b0, iph6, &bogus);
Marco Varlese191a5942017-10-30 18:17:21 +01001531 ASSERT (!bogus);
1532
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001533 sctp_hdr = ip6_next_header (iph6);
Marco Varlese191a5942017-10-30 18:17:21 +01001534 sctp_hdr->checksum = checksum;
1535
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001536 vnet_buffer (b0)->l3_hdr_offset = (u8 *) iph6 - b0->data;
Marco Varlese191a5942017-10-30 18:17:21 +01001537 vnet_buffer (b0)->l4_hdr_offset = (u8 *) th0 - b0->data;
Marco Varlese191a5942017-10-30 18:17:21 +01001538
1539#if SCTP_DEBUG_STATE_MACHINE
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001540 packet_length = clib_net_to_host_u16 (iph6->payload_length);
Marco Varlese191a5942017-10-30 18:17:21 +01001541#endif
1542 }
1543
Marco Varlesefae40392018-02-14 15:38:35 +01001544 sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1545 u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1546 if (chunk_type >= UNKNOWN)
1547 {
1548 clib_warning
1549 ("Trying to send an unrecognized chunk... something is really bad.");
1550 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1551 next0 = SCTP_OUTPUT_NEXT_DROP;
1552 goto done;
1553 }
1554
1555#if SCTP_DEBUG_STATE_MACHINE
Marco Varlese191a5942017-10-30 18:17:21 +01001556 u8 is_valid =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001557 (sctp_conn->sub_conn[idx].connection.lcl_port ==
Marco Varlese191a5942017-10-30 18:17:21 +01001558 sctp_hdr->src_port
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001559 || sctp_conn->sub_conn[idx].connection.lcl_port ==
Marco Varlese191a5942017-10-30 18:17:21 +01001560 sctp_hdr->dst_port)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001561 && (sctp_conn->sub_conn[idx].connection.rmt_port ==
Marco Varlese191a5942017-10-30 18:17:21 +01001562 sctp_hdr->dst_port
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001563 || sctp_conn->sub_conn[idx].connection.rmt_port ==
Marco Varlese191a5942017-10-30 18:17:21 +01001564 sctp_hdr->src_port);
1565
Marco Varlese191a5942017-10-30 18:17:21 +01001566 if (!is_valid)
1567 {
1568 SCTP_DBG_STATE_MACHINE ("BUFFER IS INCORRECT: conn_index = %u, "
1569 "packet_length = %u, "
1570 "chunk_type = %u [%s], "
1571 "connection.lcl_port = %u, sctp_hdr->src_port = %u, "
1572 "connection.rmt_port = %u, sctp_hdr->dst_port = %u",
Marco Varlesefae40392018-02-14 15:38:35 +01001573 sctp_conn->sub_conn[idx].
1574 connection.c_index, packet_length,
Marco Varlese191a5942017-10-30 18:17:21 +01001575 chunk_type,
1576 sctp_chunk_to_string (chunk_type),
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001577 sctp_conn->sub_conn[idx].
1578 connection.lcl_port, sctp_hdr->src_port,
1579 sctp_conn->sub_conn[idx].
1580 connection.rmt_port,
Marco Varlese191a5942017-10-30 18:17:21 +01001581 sctp_hdr->dst_port);
1582
1583 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1584 next0 = SCTP_OUTPUT_NEXT_DROP;
1585 goto done;
1586 }
Marco Varlesefae40392018-02-14 15:38:35 +01001587#endif
Marco Varlese191a5942017-10-30 18:17:21 +01001588 SCTP_DBG_STATE_MACHINE
Marco Varlesef3ab4892018-02-19 15:23:13 +01001589 ("SESSION_INDEX = %u, CONN_INDEX = %u, CURR_CONN_STATE = %u (%s), "
Marco Varlese191a5942017-10-30 18:17:21 +01001590 "CHUNK_TYPE = %s, " "SRC_PORT = %u, DST_PORT = %u",
Marco Varlesef3ab4892018-02-19 15:23:13 +01001591 sctp_conn->sub_conn[idx].connection.s_index,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001592 sctp_conn->sub_conn[idx].connection.c_index,
1593 sctp_conn->state, sctp_state_to_string (sctp_conn->state),
Marco Varlese191a5942017-10-30 18:17:21 +01001594 sctp_chunk_to_string (chunk_type), full_hdr->hdr.src_port,
1595 full_hdr->hdr.dst_port);
1596
Marco Varlese191a5942017-10-30 18:17:21 +01001597 /* Let's make sure the state-machine does not send anything crazy */
Marco Varlesea38783e2018-02-13 12:38:52 +01001598#if SCTP_DEBUG_STATE_MACHINE
1599 if (sctp_validate_output_state_machine (sctp_conn, chunk_type) != 0)
Marco Varlese191a5942017-10-30 18:17:21 +01001600 {
Marco Varlese191a5942017-10-30 18:17:21 +01001601 SCTP_DBG_STATE_MACHINE
Marco Varlesea38783e2018-02-13 12:38:52 +01001602 ("Sending the wrong chunk (%s) based on state-machine status (%s)",
Marco Varlese191a5942017-10-30 18:17:21 +01001603 sctp_chunk_to_string (chunk_type),
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001604 sctp_state_to_string (sctp_conn->state));
Marco Varlesea38783e2018-02-13 12:38:52 +01001605
1606 error0 = SCTP_ERROR_UNKOWN_CHUNK;
1607 next0 = SCTP_OUTPUT_NEXT_DROP;
1608 goto done;
Marco Varlesef3ab4892018-02-19 15:23:13 +01001609
Marco Varlesea38783e2018-02-13 12:38:52 +01001610 }
1611#endif
1612
1613 /* Karn's algorithm: RTT measurements MUST NOT be made using
1614 * packets that were retransmitted
1615 */
1616 if (!sctp_is_retransmitting (sctp_conn, idx))
1617 {
1618 /* Measure RTT with this */
1619 if (chunk_type == DATA
1620 && sctp_conn->sub_conn[idx].RTO_pending == 0)
1621 {
1622 sctp_conn->sub_conn[idx].RTO_pending = 1;
1623 sctp_conn->sub_conn[idx].rtt_ts = sctp_time_now ();
1624 }
1625 else
1626 sctp_conn->sub_conn[idx].rtt_ts = sctp_time_now ();
Marco Varlese191a5942017-10-30 18:17:21 +01001627 }
1628
Marco Varlesea38783e2018-02-13 12:38:52 +01001629 /* Let's take care of TIMERS */
Marco Varlesebe2251b2018-02-07 12:22:41 +01001630 switch (chunk_type)
Marco Varlese191a5942017-10-30 18:17:21 +01001631 {
Marco Varlesea38783e2018-02-13 12:38:52 +01001632 case COOKIE_ECHO:
1633 {
1634 sctp_conn->state = SCTP_STATE_COOKIE_ECHOED;
1635 break;
1636 }
Marco Varlesebe2251b2018-02-07 12:22:41 +01001637 case DATA:
1638 {
Marco Varlesea38783e2018-02-13 12:38:52 +01001639 SCTP_ADV_DBG_OUTPUT ("PACKET_LENGTH = %u", packet_length);
1640
Marco Varlesebe2251b2018-02-07 12:22:41 +01001641 sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1642 sctp_conn->sub_conn[idx].RTO);
1643 break;
1644 }
1645 case SHUTDOWN:
1646 {
1647 /* Start the SCTP_TIMER_T2_SHUTDOWN timer */
1648 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN,
1649 sctp_conn->sub_conn[idx].RTO);
1650 sctp_conn->state = SCTP_STATE_SHUTDOWN_SENT;
1651 break;
1652 }
1653 case SHUTDOWN_ACK:
1654 {
1655 /* Start the SCTP_TIMER_T2_SHUTDOWN timer */
1656 sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN,
1657 sctp_conn->sub_conn[idx].RTO);
1658 sctp_conn->state = SCTP_STATE_SHUTDOWN_ACK_SENT;
1659 break;
1660 }
Marco Varlesea38783e2018-02-13 12:38:52 +01001661 case SHUTDOWN_COMPLETE:
1662 {
1663 sctp_conn->state = SCTP_STATE_CLOSED;
1664 break;
1665 }
Marco Varlese191a5942017-10-30 18:17:21 +01001666 }
1667
1668 vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
1669 vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
1670
1671 b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
1672
Marco Varlesef3ab4892018-02-19 15:23:13 +01001673 SCTP_DBG_STATE_MACHINE
1674 ("SESSION_INDEX = %u, CONNECTION_INDEX = %u, " "NEW_STATE = %s, "
1675 "CHUNK_SENT = %s", sctp_conn->sub_conn[idx].connection.s_index,
1676 sctp_conn->sub_conn[idx].connection.c_index,
1677 sctp_state_to_string (sctp_conn->state),
1678 sctp_chunk_to_string (chunk_type));
Marco Varlese191a5942017-10-30 18:17:21 +01001679
1680 vnet_sctp_common_hdr_params_host_to_net (&full_hdr->common_hdr);
1681
1682 done:
1683 b0->error = node->errors[error0];
1684 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1685 {
1686 t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
1687 if (th0)
1688 {
1689 clib_memcpy (&t0->sctp_header, th0,
1690 sizeof (t0->sctp_header));
1691 }
1692 else
1693 {
1694 memset (&t0->sctp_header, 0, sizeof (t0->sctp_header));
1695 }
Marco Varlese8ad6a2d2018-01-26 16:50:01 +01001696 clib_memcpy (&t0->sctp_connection, sctp_conn,
Marco Varlese191a5942017-10-30 18:17:21 +01001697 sizeof (t0->sctp_connection));
1698 }
1699
1700 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1701 n_left_to_next, bi0, next0);
1702 }
1703
1704 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1705 }
1706
1707 return from_frame->n_vectors;
1708}
1709
1710static uword
1711sctp4_output (vlib_main_t * vm, vlib_node_runtime_t * node,
1712 vlib_frame_t * from_frame)
1713{
1714 return sctp46_output_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1715}
1716
1717static uword
1718sctp6_output (vlib_main_t * vm, vlib_node_runtime_t * node,
1719 vlib_frame_t * from_frame)
1720{
1721 return sctp46_output_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1722}
1723
1724/* *INDENT-OFF* */
1725VLIB_REGISTER_NODE (sctp4_output_node) =
1726{
1727 .function = sctp4_output,.name = "sctp4-output",
1728 /* Takes a vector of packets. */
1729 .vector_size = sizeof (u32),
1730 .n_errors = SCTP_N_ERROR,
1731 .error_strings = sctp_error_strings,
1732 .n_next_nodes = SCTP_OUTPUT_N_NEXT,
1733 .next_nodes = {
1734#define _(s,n) [SCTP_OUTPUT_NEXT_##s] = n,
1735 foreach_sctp4_output_next
1736#undef _
1737 },
1738 .format_buffer = format_sctp_header,
1739 .format_trace = format_sctp_tx_trace,
1740};
1741/* *INDENT-ON* */
1742
1743VLIB_NODE_FUNCTION_MULTIARCH (sctp4_output_node, sctp4_output);
1744
1745/* *INDENT-OFF* */
1746VLIB_REGISTER_NODE (sctp6_output_node) =
1747{
1748 .function = sctp6_output,
1749 .name = "sctp6-output",
1750 /* Takes a vector of packets. */
1751 .vector_size = sizeof (u32),
1752 .n_errors = SCTP_N_ERROR,
1753 .error_strings = sctp_error_strings,
1754 .n_next_nodes = SCTP_OUTPUT_N_NEXT,
1755 .next_nodes = {
1756#define _(s,n) [SCTP_OUTPUT_NEXT_##s] = n,
1757 foreach_sctp6_output_next
1758#undef _
1759 },
1760 .format_buffer = format_sctp_header,
1761 .format_trace = format_sctp_tx_trace,
1762};
1763/* *INDENT-ON* */
1764
1765VLIB_NODE_FUNCTION_MULTIARCH (sctp6_output_node, sctp6_output);
1766
1767/*
1768 * fd.io coding-style-patch-verification: ON
1769 *
1770 * Local Variables:
1771 * eval: (c-set-style "gnu")
1772 * End:
1773 */