FD.io VPP  v19.04.1-1-ge4a0f9f
Vector Packet Processing
sctp_input.c
Go to the documentation of this file.
1 /*
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 
22 static 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 \
30  _ (DROP4, "ip4-drop") \
31  _ (DROP6, "ip6-drop") \
32  _ (SCTP4_OUTPUT, "sctp4-output") \
33  _ (SCTP6_OUTPUT, "sctp6-output")
34 
35 typedef enum _sctp_established_phase_next
36 {
37 #define _(s,n) SCTP_ESTABLISHED_PHASE_NEXT_##s,
39 #undef _
42 
43 typedef enum _sctp_rcv_phase_next
44 {
45 #define _(s,n) SCTP_RCV_PHASE_NEXT_##s,
47 #undef _
50 
51 typedef enum _sctp_listen_phase_next
52 {
53 #define _(s,n) SCTP_LISTEN_PHASE_NEXT_##s,
55 #undef _
58 
59 typedef enum _sctp_shutdown_phase_next
60 {
61 #define _(s,n) SCTP_SHUTDOWN_PHASE_NEXT_##s,
63 #undef _
66 
67 /* Generic, state independent indices */
68 typedef enum _sctp_state_next
69 {
70 #define _(s,n) SCTP_NEXT_##s,
72 #undef _
75 
76 typedef enum _sctp_input_next
77 {
86 
87 #ifndef CLIB_MARCH_VARIANT
88 char *
90 {
91  switch (phase)
92  {
94  return "SCTP_INPUT_NEXT_DROP";
96  return "SCTP_INPUT_NEXT_LISTEN_PHASE";
98  return "SCTP_INPUT_NEXT_RCV_PHASE";
100  return "SCTP_INPUT_NEXT_ESTABLISHED_PHASE";
102  return "SCTP_INPUT_NEXT_SHUTDOWN_PHASE";
104  return "SCTP_INPUT_NEXT_PUNT_PHASE";
105  }
106  return NULL;
107 }
108 #endif /* CLIB_MARCH_VARIANT */
109 
110 #define foreach_sctp4_input_next \
111  _ (DROP, "error-drop") \
112  _ (RCV_PHASE, "sctp4-rcv") \
113  _ (LISTEN_PHASE, "sctp4-listen") \
114  _ (ESTABLISHED_PHASE, "sctp4-established") \
115  _ (SHUTDOWN_PHASE, "sctp4-shutdown") \
116  _ (PUNT_PHASE, "ip4-punt")
117 
118 
119 #define foreach_sctp6_input_next \
120  _ (DROP, "error-drop") \
121  _ (RCV_PHASE, "sctp6-rcv") \
122  _ (LISTEN_PHASE, "sctp6-listen") \
123  _ (ESTABLISHED_PHASE, "sctp6-established") \
124  _ (SHUTDOWN_PHASE, "sctp6-shutdown") \
125  _ (PUNT_PHASE, "ip6-punt")
126 
127 static u8
129  sctp_header_t * sctp_hdr)
130 {
131  sctp_connection_t *sctp_conn =
133 
134  if (!sctp_conn)
135  return 1;
136 
137  u8 is_valid = (trans_conn->lcl_port == sctp_hdr->dst_port
138  && (sctp_conn->state == SCTP_STATE_CLOSED
139  || trans_conn->rmt_port == sctp_hdr->src_port));
140 
141  return is_valid;
142 }
143 
144 /**
145  * Lookup transport connection
146  */
147 static sctp_connection_t *
148 sctp_lookup_connection (u32 fib_index, vlib_buffer_t * b, u8 thread_index,
149  u8 is_ip4)
150 {
152  sctp_header_t *sctp_hdr;
153  transport_connection_t *trans_conn;
154  sctp_connection_t *sctp_conn;
155  u8 is_filtered, i;
156  if (is_ip4)
157  {
158  ip4_header_t *ip4_hdr;
159  ip4_hdr = vlib_buffer_get_current (b);
160  sctp_hdr = ip4_next_header (ip4_hdr);
161  trans_conn = session_lookup_connection_wt4 (fib_index,
162  &ip4_hdr->dst_address,
163  &ip4_hdr->src_address,
164  sctp_hdr->dst_port,
165  sctp_hdr->src_port,
167  thread_index, &is_filtered);
168  if (trans_conn == 0) /* Not primary connection */
169  {
170  for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
171  {
172  if ((tm->connections[thread_index]->sub_conn[i].
173  connection.lcl_ip.ip4.as_u32 ==
174  ip4_hdr->dst_address.as_u32)
175  && (tm->connections[thread_index]->sub_conn[i].
176  connection.rmt_ip.ip4.as_u32 ==
177  ip4_hdr->src_address.as_u32))
178  {
179  trans_conn =
180  &tm->connections[thread_index]->sub_conn[i].connection;
181  break;
182  }
183  }
184  }
185  ASSERT (trans_conn != 0);
186  ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
187  }
188  else
189  {
190  ip6_header_t *ip6_hdr;
191  ip6_hdr = vlib_buffer_get_current (b);
192  sctp_hdr = ip6_next_header (ip6_hdr);
193  trans_conn = session_lookup_connection_wt6 (fib_index,
194  &ip6_hdr->dst_address,
195  &ip6_hdr->src_address,
196  sctp_hdr->dst_port,
197  sctp_hdr->src_port,
199  thread_index, &is_filtered);
200  if (trans_conn == 0) /* Not primary connection */
201  {
202  for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
203  {
204  if ((tm->connections[thread_index]->sub_conn[i].
205  connection.lcl_ip.ip6.as_u64[0] ==
206  ip6_hdr->dst_address.as_u64[0]
207  && tm->connections[thread_index]->sub_conn[i].
208  connection.lcl_ip.ip6.as_u64[1] ==
209  ip6_hdr->dst_address.as_u64[1])
210  && (tm->connections[thread_index]->sub_conn[i].
211  connection.rmt_ip.ip6.as_u64[0] ==
212  ip6_hdr->src_address.as_u64[0]
213  && tm->connections[thread_index]->
214  sub_conn[i].connection.rmt_ip.ip6.as_u64[1] ==
215  ip6_hdr->src_address.as_u64[1]))
216  {
217  trans_conn =
218  &tm->connections[thread_index]->sub_conn[i].connection;
219  break;
220  }
221  }
222  }
223  ASSERT (trans_conn != 0);
224  ASSERT (sctp_lookup_is_valid (trans_conn, sctp_hdr));
225  }
226  sctp_conn = sctp_get_connection_from_transport (trans_conn);
227  return sctp_conn;
228 }
229 
230 typedef struct
231 {
235 
236 #define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT \
237  : SCTP_NEXT_SCTP6_OUTPUT)
238 
239 #define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4 \
240  : SCTP_NEXT_DROP6)
241 
242 static void
244  sctp_connection_t * sctp_conn,
245  sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
246  u8 is_ip4)
247 {
248  if (sctp_conn)
249  {
250  clib_memcpy_fast (&rx_trace->sctp_connection, sctp_conn,
251  sizeof (rx_trace->sctp_connection));
252  }
253  else
254  {
255  sctp_hdr = sctp_buffer_hdr (b0);
256  }
257  clib_memcpy_fast (&rx_trace->sctp_header, sctp_hdr,
258  sizeof (rx_trace->sctp_header));
259 }
260 
263  int is_ip4)
264 {
265  u16 sctp_implied_packet_length = 0;
266 
267  if (is_ip4)
268  sctp_implied_packet_length =
269  clib_net_to_host_u16 (ip4_hdr->length) - ip4_header_bytes (ip4_hdr);
270  else
271  sctp_implied_packet_length =
272  clib_net_to_host_u16 (ip6_hdr->payload_length) - sizeof (ip6_hdr);
273 
274  return sctp_implied_packet_length;
275 }
276 
278 sctp_is_bundling (u16 sctp_implied_length,
279  sctp_chunks_common_hdr_t * sctp_common_hdr)
280 {
281  if (sctp_implied_length !=
282  sizeof (sctp_header_t) + vnet_sctp_get_chunk_length (sctp_common_hdr))
283  return 1;
284  return 0;
285 }
286 
289  sctp_connection_t * sctp_conn, u8 idx,
290  vlib_buffer_t * b, u16 * next0)
291 {
292  sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
293 
294  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
295  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
296  {
297  return SCTP_ERROR_INVALID_TAG;
298  }
299 
300  if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
302  {
303  if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
304  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
305  else
306  {
307  sctp_connection_cleanup (sctp_conn);
308 
310  sub_conn[idx].connection);
311  }
312  }
313 
314  return SCTP_ERROR_NONE;
315 }
316 
319  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
320  sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
321  u16 sctp_implied_length)
322 {
323  sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
324  ip4_address_t ip4_addr;
325  ip6_address_t ip6_addr;
326  u8 add_ip4 = 0;
327  u8 add_ip6 = 0;
328  char hostname[FQDN_MAX_LENGTH];
329 
330  /* Check the current state of the connection
331  *
332  * The logic required by the RFC4960 Section 5.2.2 is already taken care of
333  * in the code below and by the "sctp_prepare_initack_chunk" function.
334  * However, for debugging purposes it is nice to have a message printed out
335  * for these corner-case scenarios.
336  */
337  if (sctp_conn->state != SCTP_STATE_CLOSED)
338  { /* UNEXPECTED scenario */
339  switch (sctp_conn->state)
340  {
341  case SCTP_STATE_COOKIE_WAIT:
342  SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
345  b0, &ip4_addr, &ip6_addr);
346  return SCTP_ERROR_NONE;
347  case SCTP_STATE_COOKIE_ECHOED:
348  case SCTP_STATE_SHUTDOWN_ACK_SENT:
349  SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
350  if (sctp_conn->forming_association_changed == 0)
353  b0, &ip4_addr,
354  &ip6_addr);
355  else
358  &ip4_addr, &ip6_addr);
359  return SCTP_ERROR_NONE;
360  }
361  }
362 
363  if (sctp_hdr->verification_tag != 0x0)
364  return SCTP_ERROR_INVALID_TAG_FOR_INIT;
365 
366  /*
367  * It is not possible to bundle any other CHUNK with the INIT chunk
368  */
369  if (sctp_is_bundling (sctp_implied_length, &init_chunk->chunk_hdr))
370  return SCTP_ERROR_BUNDLING_VIOLATION;
371 
372  /* Save the INITIATE_TAG of the remote peer for this connection:
373  * it MUST be used for the VERIFICATION_TAG parameter in the SCTP HEADER */
374  sctp_conn->remote_tag = init_chunk->initiate_tag;
375  sctp_conn->remote_initial_tsn =
376  clib_net_to_host_u32 (init_chunk->initial_tsn);
377  sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
378  sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
379  SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
380  sctp_conn->remote_initial_tsn);
381 
382  sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
383  /*
384  * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
385  * optional parameters have been sent with the INIT chunk and we need to parse them.
386  */
387  u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
388  if (length > sizeof (sctp_init_chunk_t))
389  {
390  /* There are optional parameters in the INIT chunk */
391  u16 pointer_offset = sizeof (sctp_init_chunk_t);
392  while (pointer_offset < length)
393  {
394  sctp_opt_params_hdr_t *opt_params_hdr =
395  (sctp_opt_params_hdr_t *) init_chunk + pointer_offset;
396 
397  switch (clib_net_to_host_u16 (opt_params_hdr->type))
398  {
400  {
401  sctp_ipv4_addr_param_t *ipv4 =
402  (sctp_ipv4_addr_param_t *) opt_params_hdr;
403  clib_memcpy_fast (&ip4_addr, &ipv4->address,
404  sizeof (ip4_address_t));
405 
407  &sctp_conn->sub_conn
408  [SCTP_PRIMARY_PATH_IDX].connection.
409  lcl_ip.ip4,
410  &ipv4->address) ==
411  SCTP_ERROR_NONE)
412  add_ip4 = 1;
413 
414  break;
415  }
417  {
418  sctp_ipv6_addr_param_t *ipv6 =
419  (sctp_ipv6_addr_param_t *) opt_params_hdr;
420  clib_memcpy_fast (&ip6_addr, &ipv6->address,
421  sizeof (ip6_address_t));
422 
424  &sctp_conn->sub_conn
425  [SCTP_PRIMARY_PATH_IDX].connection.
426  lcl_ip.ip6,
427  &ipv6->address) ==
428  SCTP_ERROR_NONE)
429  add_ip6 = 1;
430 
431  break;
432  }
434  {
435  sctp_cookie_preservative_param_t *cookie_pres =
436  (sctp_cookie_preservative_param_t *) opt_params_hdr;
437  sctp_conn->peer_cookie_life_span_increment =
438  cookie_pres->life_span_inc;
439  break;
440  }
442  {
443  sctp_hostname_param_t *hostname_addr =
444  (sctp_hostname_param_t *) opt_params_hdr;
445  clib_memcpy_fast (hostname, hostname_addr->hostname,
447  break;
448  }
450  {
451  /* TODO */
452  break;
453  }
454  }
455  pointer_offset += clib_net_to_host_u16 (opt_params_hdr->length);
456  }
457  }
458 
459  /* Reuse buffer to make init-ack and send */
460  sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
461  add_ip4, &ip6_addr, add_ip6);
462  return SCTP_ERROR_NONE;
463 }
464 
467  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
468  sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
469  u16 sctp_implied_length)
470 {
471  sctp_init_ack_chunk_t *init_ack_chunk =
472  (sctp_init_ack_chunk_t *) (sctp_hdr);
473 
474  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
475  if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
476  {
477  return SCTP_ERROR_INVALID_TAG;
478  }
479 
480  /*
481  * It is not possible to bundle any other CHUNK with the INIT_ACK chunk
482  */
483  if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
484  return SCTP_ERROR_BUNDLING_VIOLATION;
485 
486  return SCTP_ERROR_NONE;
487 }
488 
491  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
492  sctp_connection_t * sctp_conn, u8 idx,
493  vlib_buffer_t * b0, u16 sctp_implied_length)
494 {
495  sctp_init_ack_chunk_t *init_ack_chunk =
496  (sctp_init_ack_chunk_t *) (sctp_hdr);
497 
498  char hostname[FQDN_MAX_LENGTH];
499 
500  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
501  if (sctp_conn->local_tag != init_ack_chunk->sctp_hdr.verification_tag)
502  {
503  return SCTP_ERROR_INVALID_TAG;
504  }
505 
506  /*
507  * It is not possible to bundle any other CHUNK with the INIT chunk
508  */
509  if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
510  return SCTP_ERROR_BUNDLING_VIOLATION;
511 
512  /* Stop the T1_INIT timer */
513  sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
514 
515  sctp_calculate_rto (sctp_conn, idx);
516 
517  /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
518  sctp_conn->remote_tag = init_ack_chunk->initiate_tag;
519  sctp_conn->remote_initial_tsn =
520  clib_net_to_host_u32 (init_ack_chunk->initial_tsn);
521  sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
522  sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
523  SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
524  sctp_conn->remote_initial_tsn);
525  sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
526 
527  u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
528 
529  if (length > sizeof (sctp_init_ack_chunk_t))
530  /*
531  * There are optional parameters in the INIT ACK chunk
532  */
533  {
534  u16 pointer_offset = sizeof (sctp_init_ack_chunk_t);
535 
536  while (pointer_offset < length)
537  {
538  sctp_opt_params_hdr_t *opt_params_hdr =
539  (sctp_opt_params_hdr_t *) ((char *) init_ack_chunk +
540  pointer_offset);
541 
542  switch (clib_net_to_host_u16 (opt_params_hdr->type))
543  {
545  {
546  sctp_ipv4_addr_param_t *ipv4 =
547  (sctp_ipv4_addr_param_t *) opt_params_hdr;
548 
550  &sctp_conn->sub_conn
551  [SCTP_PRIMARY_PATH_IDX].connection.
552  lcl_ip.ip4, &ipv4->address);
553 
554  break;
555  }
557  {
558  sctp_ipv6_addr_param_t *ipv6 =
559  (sctp_ipv6_addr_param_t *) opt_params_hdr;
560 
562  &sctp_conn->sub_conn
563  [SCTP_PRIMARY_PATH_IDX].connection.
564  lcl_ip.ip6, &ipv6->address);
565 
566  break;
567  }
569  {
570  sctp_state_cookie_param_t *state_cookie_param =
571  (sctp_state_cookie_param_t *) opt_params_hdr;
572 
573  clib_memcpy_fast (&(sctp_conn->cookie_param),
574  state_cookie_param,
575  sizeof (sctp_state_cookie_param_t));
576 
577  break;
578  }
580  {
581  sctp_hostname_param_t *hostname_addr =
582  (sctp_hostname_param_t *) opt_params_hdr;
583  clib_memcpy_fast (hostname, hostname_addr->hostname,
585  break;
586  }
588  {
589  break;
590  }
591  }
592  u16 increment = clib_net_to_host_u16 (opt_params_hdr->length);
593  /* This indicates something really bad happened */
594  if (increment == 0)
595  {
596  return SCTP_ERROR_INVALID_TAG;
597  }
598  pointer_offset += increment;
599  }
600  }
601 
602  sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
603 
604  /* Start the T1_COOKIE timer */
605  sctp_timer_set (sctp_conn, idx,
606  SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
607 
608  return SCTP_ERROR_NONE;
609 }
610 
611 /** Enqueue data out-of-order for delivery to application */
612 always_inline int
614  vlib_buffer_t * b, u16 data_len, u8 conn_idx)
615 {
616  int written, error = SCTP_ERROR_ENQUEUED;
617 
618  written =
620  sub_conn[conn_idx].connection, b, 0,
621  1 /* queue event */ ,
622  0);
623 
624  /* Update next_tsn_expected */
625  if (PREDICT_TRUE (written == data_len))
626  {
627  sctp_conn->next_tsn_expected += written;
628 
629  SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
630  sctp_conn->sub_conn[conn_idx].connection.c_index,
631  written, data_len);
632  }
633  /* If more data written than expected, account for out-of-order bytes. */
634  else if (written > data_len)
635  {
636  sctp_conn->next_tsn_expected += written;
637 
638  SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
639  sctp_conn->sub_conn[conn_idx].connection.c_index,
640  written, data_len);
641  }
642  else if (written > 0)
643  {
644  /* We've written something but FIFO is probably full now */
645  sctp_conn->next_tsn_expected += written;
646 
647  error = SCTP_ERROR_PARTIALLY_ENQUEUED;
648 
650  ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
651  sctp_conn->sub_conn[conn_idx].connection.c_index, written);
652  }
653  else
654  {
655  SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
656  sctp_conn->sub_conn[conn_idx].connection.c_index);
657 
658  return SCTP_ERROR_FIFO_FULL;
659  }
660 
661  /* TODO: Update out_of_order_map & SACK list */
662 
663  return error;
664 }
665 
666 /** Enqueue data for delivery to application */
667 always_inline int
669  u16 data_len, u8 conn_idx)
670 {
671  int written, error = SCTP_ERROR_ENQUEUED;
672 
673  written =
675  sub_conn[conn_idx].connection, b, 0,
676  1 /* queue event */ ,
677  1);
678 
679  /* Update next_tsn_expected */
680  if (PREDICT_TRUE (written == data_len))
681  {
682  sctp_conn->next_tsn_expected += written;
683 
684  SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] == DATA_LEN [%d]",
685  sctp_conn->sub_conn[conn_idx].connection.c_index,
686  written, data_len);
687  }
688  /* If more data written than expected, account for out-of-order bytes. */
689  else if (written > data_len)
690  {
691  sctp_conn->next_tsn_expected += written;
692 
693  SCTP_ADV_DBG ("CONN = %u, WRITTEN [%u] > DATA_LEN [%d]",
694  sctp_conn->sub_conn[conn_idx].connection.c_index,
695  written, data_len);
696  }
697  else if (written > 0)
698  {
699  /* We've written something but FIFO is probably full now */
700  sctp_conn->next_tsn_expected += written;
701 
702  error = SCTP_ERROR_PARTIALLY_ENQUEUED;
703 
705  ("CONN = %u, WRITTEN [%u] > 0 (SCTP_ERROR_PARTIALLY_ENQUEUED)",
706  sctp_conn->sub_conn[conn_idx].connection.c_index, written);
707  }
708  else
709  {
710  SCTP_ADV_DBG ("CONN = %u, WRITTEN == 0 (SCTP_ERROR_FIFO_FULL)",
711  sctp_conn->sub_conn[conn_idx].connection.c_index);
712 
713  return SCTP_ERROR_FIFO_FULL;
714  }
715 
716  return error;
717 }
718 
720 sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
721 {
722  if (sctp_conn->conn_config.never_delay_sack)
723  {
724  SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
725  return 0;
726  }
727 
728  /* Section 4.4 of the RFC4960 */
729  if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
730  {
731  SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
732  sctp_state_to_string (sctp_conn->state));
733  return 0;
734  }
735 
736  if (is_gapping)
737  {
739  ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
740  sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
741  return 0;
742  }
743 
744  sctp_conn->ack_state += 1;
745  if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
746  {
748  ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
749  sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
750  return 0;
751  }
752 
753  return 1;
754 }
755 
756 always_inline void
758  u8 * gapping)
759 {
760  if (sctp_conn->next_tsn_expected != tsn) // It means data transmission is GAPPING
761  {
763  ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
764  sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
765  sctp_conn->next_tsn_expected, tsn,
766  sctp_conn->next_tsn_expected - tsn);
767 
768  *gapping = 1;
769  }
770 }
771 
774  sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
775  u16 * next0)
776 {
777  u32 error = 0, n_data_bytes;
778  u8 is_gapping = 0;
779 
780  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
781  if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
782  {
783  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
784  sctp_conn->sub_conn[idx].enqueue_state = SCTP_ERROR_INVALID_TAG;
785  return sctp_conn->sub_conn[idx].enqueue_state;
786  }
787 
788  vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
789  vnet_buffer (b)->sctp.ssn = sctp_data_chunk->stream_seq;
790 
791  u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
792 
793  vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
794  u32 chunk_len = vnet_sctp_get_chunk_length (&sctp_data_chunk->chunk_hdr) -
795  (sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_header_t));
796 
797  ASSERT (vnet_buffer (b)->sctp.data_len);
798  ASSERT (chunk_len);
799 
800  /* Padding was added: see RFC 4096 section 3.3.1 */
801  if (vnet_buffer (b)->sctp.data_len > chunk_len)
802  {
803  /* Let's change the data_len to the right amount calculated here now.
804  * We cannot do that in the generic sctp46_input_dispatcher node since
805  * that is common to all CHUNKS handling.
806  */
807  vnet_buffer (b)->sctp.data_len = chunk_len;
808  /* We need to change b->current_length so that downstream calls to
809  * session_enqueue_stream_connection (called by sctp_session_enqueue_data)
810  * push the correct amount of data to be enqueued.
811  */
812  b->current_length = chunk_len;
813  }
814  n_data_bytes = vnet_buffer (b)->sctp.data_len;
815 
816  sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
817 
818  sctp_conn->last_rcvd_tsn = tsn;
819 
820  SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
821 
822  u8 bbit = vnet_sctp_get_bbit (&sctp_data_chunk->chunk_hdr);
823  u8 ebit = vnet_sctp_get_ebit (&sctp_data_chunk->chunk_hdr);
824 
825  if (bbit == 1 && ebit == 1) /* Unfragmented message */
826  {
827  /* In order data, enqueue. Fifo figures out by itself if any out-of-order
828  * segments can be enqueued after fifo tail offset changes. */
829  if (PREDICT_FALSE (is_gapping == 1))
830  error =
831  sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
832  else
833  error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
834  }
835  else if (bbit == 1 && ebit == 0) /* First piece of a fragmented user message */
836  {
837  error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
838  }
839  else if (bbit == 0 && ebit == 1) /* Last piece of a fragmented user message */
840  {
841  if (PREDICT_FALSE (is_gapping == 1))
842  error =
843  sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
844  else
845  error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
846  }
847  else /* Middle piece of a fragmented user message */
848  {
849  if (PREDICT_FALSE (is_gapping == 1))
850  error =
851  sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
852  else
853  error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
854  }
855  sctp_conn->last_rcvd_tsn = tsn;
856 
857  SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
858 
859  if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
860  {
861  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
862  sctp_prepare_sack_chunk (sctp_conn, idx, b);
863  }
864  else
865  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
866 
867  sctp_conn->sub_conn[idx].enqueue_state = error;
868 
869  return error;
870 }
871 
874  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
875  sctp_connection_t * sctp_conn, u8 idx,
876  vlib_buffer_t * b0, u16 * next0)
877 {
878  u64 now = sctp_time_now ();
879 
880  sctp_cookie_echo_chunk_t *cookie_echo =
881  (sctp_cookie_echo_chunk_t *) sctp_hdr;
882 
883  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
884  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
885  {
886  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
887  return SCTP_ERROR_INVALID_TAG;
888  }
889 
890  sctp_calculate_rto (sctp_conn, idx);
891 
892  u64 creation_time =
893  clib_net_to_host_u64 (cookie_echo->cookie.creation_time);
894  u64 cookie_lifespan =
895  clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
896 
897  if (now > creation_time + cookie_lifespan)
898  {
899  SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
900  now, creation_time, cookie_lifespan);
901  return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
902  }
903 
904  sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
905 
906  /* Change state */
907  sctp_conn->state = SCTP_STATE_ESTABLISHED;
908  sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
909  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
910 
911  sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
912  sctp_conn->sub_conn[idx].RTO);
913 
914  session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
915 
916  return SCTP_ERROR_NONE;
917 
918 }
919 
922  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
923  sctp_connection_t * sctp_conn, u8 idx,
924  vlib_buffer_t * b0, u16 * next0)
925 {
926  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
927  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
928  {
929  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
930  return SCTP_ERROR_INVALID_TAG;
931  }
932 
933  sctp_calculate_rto (sctp_conn, idx);
934 
935  sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
936  /* Change state */
937  sctp_conn->state = SCTP_STATE_ESTABLISHED;
938  sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
939 
940  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
941 
942  sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
943  sctp_conn->sub_conn[idx].RTO);
944 
945  session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
946 
947  return SCTP_ERROR_NONE;
948 
949 }
950 
953  vlib_frame_t * from_frame, int is_ip4)
954 {
956 
957  u32 n_left_from, next_index, *from, *to_next;
958  u32 my_thread_index = vm->thread_index;
959 
960  from = vlib_frame_vector_args (from_frame);
961  n_left_from = from_frame->n_vectors;
962 
963  next_index = node->cached_next_index;
964 
965  while (n_left_from > 0)
966  {
967  u32 n_left_to_next;
968 
969  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
970 
971  while (n_left_from > 0 && n_left_to_next > 0)
972  {
973  u32 bi0;
974  vlib_buffer_t *b0;
975  sctp_header_t *sctp_hdr = 0;
976  sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
977  ip4_header_t *ip4_hdr = 0;
978  ip6_header_t *ip6_hdr = 0;
979  sctp_connection_t *sctp_conn, *new_sctp_conn;
980  u16 sctp_implied_length = 0;
981  u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
982  u8 idx;
983 
984  bi0 = from[0];
985  to_next[0] = bi0;
986  from += 1;
987  to_next += 1;
988  n_left_from -= 1;
989  n_left_to_next -= 1;
990 
991  b0 = vlib_get_buffer (vm, bi0);
992 
993  /* If we are in SCTP_COOKIE_WAIT_STATE then the connection
994  * will come from the half-open connections pool.
995  */
996  sctp_conn =
998  sctp.connection_index);
999 
1000  if (PREDICT_FALSE (sctp_conn == 0))
1001  {
1002  SCTP_ADV_DBG
1003  ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1004  error0 = SCTP_ERROR_INVALID_CONNECTION;
1005  goto drop;
1006  }
1007  if (is_ip4)
1008  {
1009  ip4_hdr = vlib_buffer_get_current (b0);
1010  sctp_hdr = ip4_next_header (ip4_hdr);
1011  idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1012  }
1013  else
1014  {
1015  ip6_hdr = vlib_buffer_get_current (b0);
1016  sctp_hdr = ip6_next_header (ip6_hdr);
1017  idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1018  }
1019 
1020  sctp_conn->sub_conn[idx].subconn_idx = idx;
1021  sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1022 
1023  sctp_chunk_hdr =
1024  (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1025 
1026  sctp_implied_length =
1027  sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1028 
1029  u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1030 
1031  switch (chunk_type)
1032  {
1033  case INIT_ACK:
1034  error0 =
1035  sctp_is_valid_init_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1036  b0, sctp_implied_length);
1037 
1038  if (error0 == SCTP_ERROR_NONE)
1039  {
1040  pool_get (tm->connections[my_thread_index], new_sctp_conn);
1041  clib_memcpy_fast (new_sctp_conn, sctp_conn,
1042  sizeof (*new_sctp_conn));
1043  new_sctp_conn->sub_conn[idx].c_c_index =
1044  new_sctp_conn - tm->connections[my_thread_index];
1045  new_sctp_conn->sub_conn[idx].c_thread_index =
1046  my_thread_index;
1047  new_sctp_conn->sub_conn[idx].PMTU =
1048  sctp_conn->sub_conn[idx].PMTU;
1049  new_sctp_conn->sub_conn[idx].subconn_idx = idx;
1050 
1051  if (sctp_half_open_connection_cleanup (sctp_conn))
1052  {
1053  SCTP_DBG
1054  ("Cannot cleanup half-open connection; not the owning thread");
1055  }
1056 
1057  sctp_connection_timers_init (new_sctp_conn);
1058 
1059  sctp_init_cwnd (new_sctp_conn);
1060 
1061  error0 =
1062  sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
1063  new_sctp_conn, idx, b0,
1064  sctp_implied_length);
1065 
1067  (&new_sctp_conn->sub_conn[idx].connection, 0))
1068  {
1069  SCTP_DBG
1070  ("conn_index = %u: session_stream_connect_notify error; cleaning up connection",
1071  new_sctp_conn->sub_conn[idx].connection.c_index);
1072  sctp_connection_cleanup (new_sctp_conn);
1073  goto drop;
1074  }
1075  next0 = sctp_next_output (is_ip4);
1076  }
1077  break;
1078 
1079  case OPERATION_ERROR:
1080  error0 =
1081  sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1082  &next0);
1083  break;
1084 
1085  /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1086  * are handled by the input-dispatcher function using the table-lookup
1087  * hence we should never get to the "default" case below.
1088  */
1089  default:
1090  error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1091  next0 = sctp_next_drop (is_ip4);
1092  goto drop;
1093  }
1094 
1095  if (error0 != SCTP_ERROR_NONE)
1096  {
1097  clib_warning ("error while parsing chunk");
1098  sctp_connection_cleanup (sctp_conn);
1099  next0 = sctp_next_drop (is_ip4);
1100  goto drop;
1101  }
1102 
1103  drop:
1104  b0->error = node->errors[error0];
1105  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1106  {
1107  sctp_rx_trace_t *t0 =
1108  vlib_add_trace (vm, node, b0, sizeof (*t0));
1109  sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1110  }
1111 
1112  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1113  n_left_to_next, bi0, next0);
1114  }
1115 
1116  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1117  }
1118  return from_frame->n_vectors;
1119 }
1120 
1122  vlib_node_runtime_t * node,
1123  vlib_frame_t * from_frame)
1124 {
1125  return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1126 }
1127 
1129  vlib_node_runtime_t * node,
1130  vlib_frame_t * from_frame)
1131 {
1132  return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1133 }
1134 
1135 static u8 *
1136 format_sctp_rx_trace_short (u8 * s, va_list * args)
1137 {
1138  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1139  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1140  sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1141 
1142  s = format (s, "%d -> %d (%U)",
1143  clib_net_to_host_u16 (t->sctp_header.src_port),
1144  clib_net_to_host_u16 (t->sctp_header.dst_port),
1146 
1147  return s;
1148 }
1149 
1150 /* *INDENT-OFF* */
1152 {
1153  .name = "sctp4-rcv",
1154  /* Takes a vector of packets. */
1155  .vector_size = sizeof (u32),
1156  .n_errors = SCTP_N_ERROR,
1157  .error_strings = sctp_error_strings,
1158  .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1159  .next_nodes =
1160  {
1161 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1163 #undef _
1164  },
1165  .format_trace = format_sctp_rx_trace_short,
1166 };
1167 /* *INDENT-ON* */
1168 
1169 /* *INDENT-OFF* */
1171 {
1172  .name = "sctp6-rcv",
1173  /* Takes a vector of packets. */
1174  .vector_size = sizeof (u32),
1175  .n_errors = SCTP_N_ERROR,
1176  .error_strings = sctp_error_strings,
1177  .n_next_nodes = SCTP_RCV_PHASE_N_NEXT,
1178  .next_nodes =
1179  {
1180 #define _(s,n) [SCTP_RCV_PHASE_NEXT_##s] = n,
1182 #undef _
1183  },
1184  .format_trace = format_sctp_rx_trace_short,
1185 };
1186 /* *INDENT-ON* */
1187 
1190  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1191  sctp_connection_t * sctp_conn, u8 idx,
1192  vlib_buffer_t * b0, u16 sctp_implied_length,
1193  u16 * next0)
1194 {
1195  sctp_shutdown_association_chunk_t *shutdown_chunk =
1196  (sctp_shutdown_association_chunk_t *) (sctp_hdr);
1197 
1198  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1199  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1200  {
1201  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1202  return SCTP_ERROR_INVALID_TAG;
1203  }
1204 
1205  /*
1206  * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1207  */
1208  if (sctp_is_bundling (sctp_implied_length, &shutdown_chunk->chunk_hdr))
1209  return SCTP_ERROR_BUNDLING_VIOLATION;
1210 
1211  switch (sctp_conn->state)
1212  {
1213  case SCTP_STATE_ESTABLISHED:
1214  if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
1215  sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
1216  sctp_send_shutdown_ack (sctp_conn, idx, b0);
1217  break;
1218 
1219  case SCTP_STATE_SHUTDOWN_SENT:
1220  sctp_send_shutdown_ack (sctp_conn, idx, b0);
1221  break;
1222  }
1223 
1224  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1225 
1226  return SCTP_ERROR_NONE;
1227 }
1228 
1231  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1232  sctp_connection_t * sctp_conn, u8 idx,
1233  vlib_buffer_t * b0, u16 sctp_implied_length,
1234  u16 * next0)
1235 {
1236  sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
1237  (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
1238 
1239  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1240  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1241  {
1242  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1243  return SCTP_ERROR_INVALID_TAG;
1244  }
1245 
1246  /*
1247  * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1248  */
1249  if (sctp_is_bundling (sctp_implied_length, &shutdown_ack_chunk->chunk_hdr))
1250  return SCTP_ERROR_BUNDLING_VIOLATION;
1251 
1252  /* Whether we are in SCTP_STATE_SHUTDOWN_SENT or SCTP_STATE_SHUTDOWN_ACK_SENT
1253  * the reception of a SHUTDOWN_ACK chunk leads to the same actions:
1254  * - STOP T2_SHUTDOWN timer
1255  * - SEND SHUTDOWN_COMPLETE chunk
1256  */
1257  sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
1258 
1259  sctp_send_shutdown_complete (sctp_conn, idx, b0);
1260 
1261  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
1262 
1263  return SCTP_ERROR_NONE;
1264 }
1265 
1268  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
1269  sctp_connection_t * sctp_conn, u8 idx,
1270  vlib_buffer_t * b0, u16 sctp_implied_length,
1271  u16 * next0)
1272 {
1273  sctp_shutdown_complete_chunk_t *shutdown_complete =
1274  (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
1275 
1276  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1277  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
1278  {
1279  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1280  return SCTP_ERROR_INVALID_TAG;
1281  }
1282 
1283  /*
1284  * It is not possible to bundle any other CHUNK with the SHUTDOWN chunk
1285  */
1286  if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
1287  return SCTP_ERROR_BUNDLING_VIOLATION;
1288 
1289  sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
1290 
1291  session_transport_closing_notify (&sctp_conn->sub_conn[idx].connection);
1292 
1293  sctp_conn->state = SCTP_STATE_CLOSED;
1294 
1295  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1296 
1297  return SCTP_ERROR_NONE;
1298 }
1299 
1302  vlib_node_runtime_t * node,
1303  vlib_frame_t * from_frame, int is_ip4)
1304 {
1305  u32 n_left_from, next_index, *from, *to_next;
1306  u32 my_thread_index = vm->thread_index;
1307 
1308  from = vlib_frame_vector_args (from_frame);
1309  n_left_from = from_frame->n_vectors;
1310 
1311  next_index = node->cached_next_index;
1312 
1313  while (n_left_from > 0)
1314  {
1315  u32 n_left_to_next;
1316 
1317  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1318 
1319  while (n_left_from > 0 && n_left_to_next > 0)
1320  {
1321  u32 bi0;
1322  vlib_buffer_t *b0;
1323  sctp_rx_trace_t *sctp_trace;
1324  sctp_header_t *sctp_hdr = 0;
1325  sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1326  ip4_header_t *ip4_hdr = 0;
1327  ip6_header_t *ip6_hdr = 0;
1328  sctp_connection_t *sctp_conn;
1329  u16 sctp_implied_length = 0;
1330  u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
1331  u8 idx = 0;
1332 
1333  bi0 = from[0];
1334  to_next[0] = bi0;
1335  from += 1;
1336  to_next += 1;
1337  n_left_from -= 1;
1338  n_left_to_next -= 1;
1339 
1340  b0 = vlib_get_buffer (vm, bi0);
1341  sctp_conn =
1342  sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1343  my_thread_index);
1344 
1345  if (PREDICT_FALSE (sctp_conn == 0))
1346  {
1347  SCTP_DBG
1348  ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1349  error0 = SCTP_ERROR_INVALID_CONNECTION;
1350  goto drop;
1351  }
1352 
1353  if (is_ip4)
1354  {
1355  ip4_hdr = vlib_buffer_get_current (b0);
1356  sctp_hdr = ip4_next_header (ip4_hdr);
1357  idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1358  }
1359  else
1360  {
1361  ip6_hdr = vlib_buffer_get_current (b0);
1362  sctp_hdr = ip6_next_header (ip6_hdr);
1363  idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1364  }
1365 
1366  sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1367  sctp_chunk_hdr = &full_hdr->common_hdr;
1368 
1369  sctp_implied_length =
1370  sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1371 
1372  u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1373  switch (chunk_type)
1374  {
1375  case SHUTDOWN:
1376  error0 =
1377  sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1378  idx, b0, sctp_implied_length, &next0);
1379  break;
1380 
1381  case SHUTDOWN_ACK:
1382  error0 =
1383  sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1384  idx, b0, sctp_implied_length,
1385  &next0);
1386  break;
1387 
1388  case SHUTDOWN_COMPLETE:
1389  error0 =
1390  sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
1391  sctp_conn, idx, b0,
1392  sctp_implied_length, &next0);
1393 
1394  sctp_connection_cleanup (sctp_conn);
1395  break;
1396 
1397  /*
1398  * DATA chunks can still be transmitted/received in the SHUTDOWN-PENDING
1399  * and SHUTDOWN-SENT states (as per RFC4960 Section 6)
1400  */
1401  case DATA:
1402  error0 =
1404  sctp_conn, idx, b0, &next0);
1405  break;
1406 
1407  case OPERATION_ERROR:
1408  error0 =
1409  sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1410  &next0);
1411  break;
1412 
1413  case COOKIE_ECHO: /* Cookie Received While Shutting Down */
1414  sctp_prepare_operation_error (sctp_conn, idx, b0,
1416  error0 = SCTP_ERROR_NONE;
1417  next0 = sctp_next_output (is_ip4);
1418  break;
1419  /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1420  * are handled by the input-dispatcher function using the table-lookup
1421  * hence we should never get to the "default" case below.
1422  */
1423  default:
1424  error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1425  next0 = sctp_next_drop (is_ip4);
1426  goto drop;
1427  }
1428 
1429  if (error0 != SCTP_ERROR_NONE)
1430  {
1431  clib_warning ("error while parsing chunk");
1432  sctp_connection_cleanup (sctp_conn);
1433  next0 = sctp_next_drop (is_ip4);
1434  goto drop;
1435  }
1436 
1437  drop:
1438  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1439  {
1440  sctp_trace =
1441  vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
1442 
1443  if (sctp_hdr != NULL)
1444  clib_memcpy_fast (&sctp_trace->sctp_header, sctp_hdr,
1445  sizeof (sctp_trace->sctp_header));
1446 
1447  if (sctp_conn != NULL)
1448  clib_memcpy_fast (&sctp_trace->sctp_connection, sctp_conn,
1449  sizeof (sctp_trace->sctp_connection));
1450  }
1451 
1452  b0->error = node->errors[error0];
1453 
1454  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1455  n_left_to_next, bi0, next0);
1456  }
1457 
1458  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1459  }
1460 
1461  return from_frame->n_vectors;
1462 
1463 }
1464 
1466  vlib_node_runtime_t * node,
1467  vlib_frame_t * from_frame)
1468 {
1469  return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1470 }
1471 
1473  vlib_node_runtime_t * node,
1474  vlib_frame_t * from_frame)
1475 {
1476  return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1477 }
1478 
1479 /* *INDENT-OFF* */
1481 {
1482  .name = "sctp4-shutdown",
1483  /* Takes a vector of packets. */
1484  .vector_size = sizeof (u32),
1485  .n_errors = SCTP_N_ERROR,
1486  .error_strings = sctp_error_strings,
1487  .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1488  .next_nodes =
1489  {
1490 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1492 #undef _
1493  },
1494  .format_trace = format_sctp_rx_trace_short,
1495 };
1496 /* *INDENT-ON* */
1497 
1498 /* *INDENT-OFF* */
1500 {
1501  .name = "sctp6-shutdown",
1502  /* Takes a vector of packets. */
1503  .vector_size = sizeof (u32),
1504  .n_errors = SCTP_N_ERROR,
1505  .error_strings = sctp_error_strings,
1506  .n_next_nodes = SCTP_SHUTDOWN_PHASE_N_NEXT,
1507  .next_nodes =
1508  {
1509 #define _(s,n) [SCTP_SHUTDOWN_PHASE_NEXT_##s] = n,
1511 #undef _
1512  },
1513  .format_trace = format_sctp_rx_trace_short,
1514 };
1515 /* *INDENT-ON* */
1516 
1519  sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
1520  u16 * next0)
1521 {
1522 
1523  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1524  if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
1525  {
1526  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1527  return SCTP_ERROR_INVALID_TAG;
1528  }
1529 
1530  sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
1531 
1532  sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1533 
1534  /* Section 7.2.2; point (2) */
1535  if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
1536  sctp_conn->sub_conn[idx].partially_acked_bytes =
1537  sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
1538 
1539  /* Section 7.2.2; point (5) */
1540  if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
1541  sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
1542 
1543  sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
1544 
1545  sctp_calculate_rto (sctp_conn, idx);
1546 
1547  sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
1548  sctp_conn->sub_conn[idx].RTO);
1549 
1550  sctp_conn->sub_conn[idx].RTO_pending = 0;
1551 
1552  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1553 
1554  return SCTP_ERROR_NONE;
1555 }
1556 
1559  sctp_connection_t * sctp_conn, u8 idx,
1560  vlib_buffer_t * b0, u16 * next0)
1561 {
1562  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
1563  if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
1564  {
1565  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1566  return SCTP_ERROR_INVALID_TAG;
1567  }
1568 
1569  sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
1570 
1571  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
1572 
1573  return SCTP_ERROR_NONE;
1574 }
1575 
1578  sctp_connection_t * sctp_conn, u8 idx,
1579  vlib_buffer_t * b0, u16 * next0)
1580 {
1581  sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
1582 
1583  sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
1584 
1585  sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
1586  sctp_conn->sub_conn[idx].RTO);
1587 
1588  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
1589 
1590  return SCTP_ERROR_NONE;
1591 }
1592 
1593 always_inline void
1594 sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
1595  u8 is_ip4, u8 evt, u8 val)
1596 {
1597  if (PREDICT_TRUE (!val))
1598  return;
1599 
1600  if (is_ip4)
1601  vlib_node_increment_counter (vm, sctp4_node, evt, val);
1602  else
1603  vlib_node_increment_counter (vm, sctp6_node, evt, val);
1604 }
1605 
1608  vlib_node_runtime_t * node,
1609  vlib_frame_t * from_frame, int is_ip4)
1610 {
1611  u32 n_left_from, next_index, *from, *to_next;
1612  u32 my_thread_index = vm->thread_index;
1613 
1614  from = vlib_frame_vector_args (from_frame);
1615  n_left_from = from_frame->n_vectors;
1616 
1617  next_index = node->cached_next_index;
1618 
1619  while (n_left_from > 0)
1620  {
1621  u32 n_left_to_next;
1622 
1623  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1624 
1625  while (n_left_from > 0 && n_left_to_next > 0)
1626  {
1627  u32 bi0;
1628  vlib_buffer_t *b0;
1629  sctp_header_t *sctp_hdr = 0;
1630  ip4_header_t *ip4_hdr;
1631  ip6_header_t *ip6_hdr;
1632  sctp_connection_t *child_conn;
1633  sctp_connection_t *sctp_listener;
1634  u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
1635 
1636  bi0 = from[0];
1637  to_next[0] = bi0;
1638  from += 1;
1639  to_next += 1;
1640  n_left_from -= 1;
1641  n_left_to_next -= 1;
1642 
1643  b0 = vlib_get_buffer (vm, bi0);
1644  sctp_listener =
1645  sctp_listener_get (vnet_buffer (b0)->sctp.connection_index);
1646 
1647  if (is_ip4)
1648  {
1649  ip4_hdr = vlib_buffer_get_current (b0);
1650  sctp_hdr = ip4_next_header (ip4_hdr);
1651  }
1652  else
1653  {
1654  ip6_hdr = vlib_buffer_get_current (b0);
1655  sctp_hdr = ip6_next_header (ip6_hdr);
1656  }
1657 
1658  child_conn =
1659  sctp_lookup_connection (sctp_listener->sub_conn
1660  [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
1661  my_thread_index, is_ip4);
1662 
1663  if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
1664  {
1665  SCTP_DBG
1666  ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
1667  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1668  connection.c_index,
1669  sctp_state_to_string (child_conn->state));
1670  error0 = SCTP_ERROR_CREATE_EXISTS;
1671  goto drop;
1672  }
1673 
1674  /* Create child session and send SYN-ACK */
1675  child_conn = sctp_connection_new (my_thread_index);
1676  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
1678  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
1679  sctp_hdr->dst_port;
1680  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
1681  sctp_hdr->src_port;
1682  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
1683  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
1684  sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
1685  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
1686  sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
1687  child_conn->state = SCTP_STATE_CLOSED;
1688  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
1689  sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
1690  connection.fib_index;
1691 
1692  if (is_ip4)
1693  {
1694  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
1695  ip4_hdr->dst_address.as_u32;
1696  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
1697  ip4_hdr->src_address.as_u32;
1698  }
1699  else
1700  {
1701  clib_memcpy_fast (&child_conn->
1702  sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
1703  &ip6_hdr->dst_address,
1704  sizeof (ip6_address_t));
1705  clib_memcpy_fast (&child_conn->
1706  sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
1707  &ip6_hdr->src_address,
1708  sizeof (ip6_address_t));
1709  }
1710 
1711  sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1712  sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
1713 
1714  u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
1715  if (chunk_type != INIT && chunk_type != DATA
1716  && chunk_type != OPERATION_ERROR)
1717  {
1718  SCTP_DBG
1719  ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
1720  child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
1721  connection.c_index, sctp_chunk_to_string (chunk_type));
1722 
1723  error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1724  next0 = sctp_next_drop (is_ip4);
1725  goto drop;
1726  }
1727 
1728  u16 sctp_implied_length =
1729  sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
1730 
1731  switch (chunk_type)
1732  {
1733  case INIT:
1734  sctp_connection_timers_init (child_conn);
1735 
1736  sctp_init_snd_vars (child_conn);
1737 
1738  sctp_init_cwnd (child_conn);
1739 
1740  error0 =
1741  sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
1742  sctp_implied_length);
1743 
1744  if (error0 == SCTP_ERROR_NONE)
1745  {
1747  (&child_conn->
1748  sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
1749  sctp_listener->
1750  sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
1751  {
1752  clib_warning ("session accept fail");
1753  sctp_connection_cleanup (child_conn);
1754  error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
1755  goto drop;
1756  }
1757  next0 = sctp_next_output (is_ip4);
1758  }
1759  break;
1760 
1761  /* Reception of a DATA chunk whilst in the CLOSED state is called
1762  * "Out of the Blue" packet and handling of the chunk needs special treatment
1763  * as per RFC4960 section 8.4
1764  */
1765  case DATA:
1766  break;
1767 
1768  case OPERATION_ERROR:
1769  error0 =
1770  sctp_handle_operation_err (sctp_hdr, child_conn,
1771  SCTP_PRIMARY_PATH_IDX, b0, &next0);
1772  break;
1773  }
1774 
1775  drop:
1776  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1777  {
1778  sctp_rx_trace_t *t0 =
1779  vlib_add_trace (vm, node, b0, sizeof (*t0));
1780  clib_memcpy_fast (&t0->sctp_header, sctp_hdr,
1781  sizeof (t0->sctp_header));
1782  clib_memcpy_fast (&t0->sctp_connection, sctp_listener,
1783  sizeof (t0->sctp_connection));
1784  }
1785 
1786  b0->error = node->errors[error0];
1787 
1788  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1789  n_left_to_next, bi0, next0);
1790  }
1791  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1792 
1793  }
1794  return from_frame->n_vectors;
1795 }
1796 
1798  vlib_node_runtime_t * node,
1799  vlib_frame_t * from_frame)
1800 {
1801  return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
1802 }
1803 
1805  vlib_node_runtime_t * node,
1806  vlib_frame_t * from_frame)
1807 {
1808  return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
1809 }
1810 
1813  vlib_frame_t * from_frame, int is_ip4)
1814 {
1816  u32 n_left_from, next_index, *from, *to_next;
1817  u32 my_thread_index = vm->thread_index, errors = 0;
1818 
1819  from = vlib_frame_vector_args (from_frame);
1820  n_left_from = from_frame->n_vectors;
1821 
1822  next_index = node->cached_next_index;
1823 
1824  while (n_left_from > 0)
1825  {
1826  u32 n_left_to_next;
1827 
1828  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1829 
1830  while (n_left_from > 0 && n_left_to_next > 0)
1831  {
1832  u32 bi0;
1833  vlib_buffer_t *b0;
1834  sctp_header_t *sctp_hdr = 0;
1835  sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
1836  ip4_header_t *ip4_hdr = 0;
1837  ip6_header_t *ip6_hdr = 0;
1838  sctp_connection_t *sctp_conn;
1839  u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
1841  u8 idx;
1842 
1843  bi0 = from[0];
1844  to_next[0] = bi0;
1845  from += 1;
1846  to_next += 1;
1847  n_left_from -= 1;
1848  n_left_to_next -= 1;
1849 
1850  b0 = vlib_get_buffer (vm, bi0);
1851  sctp_conn =
1852  sctp_connection_get (vnet_buffer (b0)->sctp.connection_index,
1853  my_thread_index);
1854 
1855  if (PREDICT_FALSE (sctp_conn == 0))
1856  {
1857  SCTP_DBG
1858  ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION");
1859  error0 = SCTP_ERROR_INVALID_CONNECTION;
1860  goto done;
1861  }
1862  if (is_ip4)
1863  {
1864  ip4_hdr = vlib_buffer_get_current (b0);
1865  sctp_hdr = ip4_next_header (ip4_hdr);
1866  idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
1867  }
1868  else
1869  {
1870  ip6_hdr = vlib_buffer_get_current (b0);
1871  sctp_hdr = ip6_next_header (ip6_hdr);
1872  idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
1873  }
1874 
1875  sctp_conn->sub_conn[idx].subconn_idx = idx;
1876 
1877  sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
1878  sctp_chunk_hdr =
1879  (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
1880 
1881  u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr);
1882 
1883  switch (chunk_type)
1884  {
1885  case COOKIE_ECHO:
1886  error0 =
1887  sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1888  idx, b0, &next0);
1889  break;
1890 
1891  case COOKIE_ACK:
1892  error0 =
1893  sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
1894  idx, b0, &next0);
1895  break;
1896 
1897  case SACK:
1898  error0 =
1900  sctp_conn, idx, b0, &next0);
1901  break;
1902 
1903  case HEARTBEAT:
1904  error0 =
1906  sctp_conn, idx, b0, &next0);
1907  break;
1908 
1909  case HEARTBEAT_ACK:
1910  error0 =
1912  sctp_conn, idx, b0, &next0);
1913  break;
1914 
1915  case DATA:
1916  error0 =
1918  sctp_conn, idx, b0, &next0);
1919  break;
1920 
1921  case OPERATION_ERROR:
1922  error0 =
1923  sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
1924  &next0);
1925  break;
1926 
1927  /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
1928  * are handled by the input-dispatcher function using the table-lookup
1929  * hence we should never get to the "default" case below.
1930  */
1931  default:
1932  error0 = SCTP_ERROR_UNKNOWN_CHUNK;
1933  next0 = sctp_next_drop (is_ip4);
1934  goto done;
1935  }
1936 
1937  done:
1938  b0->error = node->errors[error0];
1939  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1940  {
1941  sctp_rx_trace_t *t0 =
1942  vlib_add_trace (vm, node, b0, sizeof (*t0));
1943  sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
1944  }
1945 
1946  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1947  n_left_to_next, bi0, next0);
1948  }
1949 
1950  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1951  }
1952 
1954  my_thread_index);
1955 
1956  sctp_node_inc_counter (vm, is_ip4, sm->sctp4_established_phase_node_index,
1957  sm->sctp6_established_phase_node_index,
1958  SCTP_ERROR_EVENT_FIFO_FULL, errors);
1959  sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
1960 
1961  return from_frame->n_vectors;
1962 }
1963 
1965  vlib_node_runtime_t * node,
1966  vlib_frame_t * from_frame)
1967 {
1968  return sctp46_established_phase_inline (vm, node, from_frame,
1969  1 /* is_ip4 */ );
1970 }
1971 
1973  vlib_node_runtime_t * node,
1974  vlib_frame_t * from_frame)
1975 {
1976  return sctp46_established_phase_inline (vm, node, from_frame,
1977  0 /* is_ip4 */ );
1978 }
1979 
1980 static u8 *
1981 format_sctp_rx_trace (u8 * s, va_list * args)
1982 {
1983  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1984  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1985  sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *);
1986  u32 indent = format_get_indent (s);
1987 
1988  s = format (s, "%U\n%U%U",
1989  format_sctp_header, &t->sctp_header, 128,
1990  format_white_space, indent,
1992 
1993  return s;
1994 }
1995 
1996 /* *INDENT-OFF* */
1998 {
1999  .name = "sctp4-listen",
2000  /* Takes a vector of packets. */
2001  .vector_size = sizeof (u32),
2002  .n_errors = SCTP_N_ERROR,
2003  .error_strings = sctp_error_strings,
2004  .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2005  .next_nodes =
2006  {
2007 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2009 #undef _
2010  },
2011  .format_trace = format_sctp_rx_trace_short,
2012 };
2013 /* *INDENT-ON* */
2014 
2015 /* *INDENT-OFF* */
2017 {
2018  .name = "sctp6-listen",
2019  /* Takes a vector of packets. */
2020  .vector_size = sizeof (u32),
2021  .n_errors = SCTP_N_ERROR,
2022  .error_strings = sctp_error_strings,
2023  .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2024  .next_nodes =
2025  {
2026 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2028 #undef _
2029  },
2030  .format_trace = format_sctp_rx_trace_short,
2031 };
2032 /* *INDENT-ON* */
2033 
2034 /* *INDENT-OFF* */
2036 {
2037  .name = "sctp4-established",
2038  /* Takes a vector of packets. */
2039  .vector_size = sizeof (u32),
2040  .n_errors = SCTP_N_ERROR,
2041  .error_strings = sctp_error_strings,
2042  .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT,
2043  .next_nodes =
2044  {
2045 #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n,
2047 #undef _
2048  },
2049  .format_trace = format_sctp_rx_trace_short,
2050 };
2051 /* *INDENT-ON* */
2052 
2053 /* *INDENT-OFF* */
2055 {
2056  .name = "sctp6-established",
2057  /* Takes a vector of packets. */
2058  .vector_size = sizeof (u32),
2059  .n_errors = SCTP_N_ERROR,
2060  .error_strings = sctp_error_strings,
2061  .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT,
2062  .next_nodes =
2063  {
2064 #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n,
2066 #undef _
2067  },
2068  .format_trace = format_sctp_rx_trace_short,
2069 };
2070 /* *INDENT-ON* */
2071 
2072 /*
2073  * This is the function executed first for the SCTP graph.
2074  * It takes care of doing the initial message parsing and
2075  * dispatch to the specialized function.
2076  */
2079  vlib_frame_t * from_frame, int is_ip4)
2080 {
2081  u32 n_left_from, next_index, *from, *to_next;
2082  u32 my_thread_index = vm->thread_index;
2083  u8 result;
2085 
2086  from = vlib_frame_vector_args (from_frame);
2087  n_left_from = from_frame->n_vectors;
2088  next_index = node->cached_next_index;
2089  sctp_set_time_now (my_thread_index);
2090 
2091  while (n_left_from > 0)
2092  {
2093  u32 n_left_to_next;
2094 
2095  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2096 
2097  while (n_left_from > 0 && n_left_to_next > 0)
2098  {
2099  int n_advance_bytes0, n_data_bytes0;
2100  u32 bi0, fib_index0;
2101  vlib_buffer_t *b0;
2102  sctp_header_t *sctp_hdr = 0;
2103  sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0;
2104  sctp_connection_t *sctp_conn;
2105  transport_connection_t *trans_conn;
2106  ip4_header_t *ip4_hdr;
2107  ip6_header_t *ip6_hdr;
2108  u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP;
2109 
2110  bi0 = from[0];
2111  to_next[0] = bi0;
2112  from += 1;
2113  to_next += 1;
2114  n_left_from -= 1;
2115  n_left_to_next -= 1;
2116 
2117  b0 = vlib_get_buffer (vm, bi0);
2118  vnet_buffer (b0)->sctp.flags = 0;
2119  fib_index0 = vnet_buffer (b0)->ip.fib_index;
2120 
2121  /* Checksum computed by ipx_local no need to compute again */
2122 
2123  if (is_ip4)
2124  {
2125  ip4_hdr = vlib_buffer_get_current (b0);
2126  sctp_hdr = ip4_next_header (ip4_hdr);
2127 
2128  sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2129  sctp_chunk_hdr = &full_hdr->common_hdr;
2130 
2131  n_advance_bytes0 =
2132  (ip4_header_bytes (ip4_hdr) +
2133  sizeof (sctp_payload_data_chunk_t));
2134  n_data_bytes0 =
2135  clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0;
2136 
2137  trans_conn = session_lookup_connection_wt4 (fib_index0,
2138  &ip4_hdr->dst_address,
2139  &ip4_hdr->src_address,
2140  sctp_hdr->dst_port,
2141  sctp_hdr->src_port,
2143  my_thread_index,
2144  &result);
2145  }
2146  else
2147  {
2148  ip6_hdr = vlib_buffer_get_current (b0);
2149  sctp_hdr = ip6_next_header (ip6_hdr);
2150 
2151  sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
2152  sctp_chunk_hdr = &full_hdr->common_hdr;
2153 
2154  n_advance_bytes0 = sctp_header_bytes ();
2155  n_data_bytes0 =
2156  clib_net_to_host_u16 (ip6_hdr->payload_length) -
2157  n_advance_bytes0;
2158  n_advance_bytes0 += sizeof (ip6_hdr[0]);
2159 
2160  trans_conn = session_lookup_connection_wt6 (fib_index0,
2161  &ip6_hdr->dst_address,
2162  &ip6_hdr->src_address,
2163  sctp_hdr->dst_port,
2164  sctp_hdr->src_port,
2166  my_thread_index,
2167  &result);
2168  }
2169 
2170  /* Length check */
2171  if (PREDICT_FALSE (n_advance_bytes0 < 0))
2172  {
2173  error0 = SCTP_ERROR_LENGTH;
2174  goto done;
2175  }
2176 
2177  sctp_conn = sctp_get_connection_from_transport (trans_conn);
2178  vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
2179 
2180  u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
2181  if (chunk_type >= UNKNOWN)
2182  {
2183  clib_warning
2184  ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
2185 
2188 
2189  error0 = SCTP_ERROR_UNKNOWN_CHUNK;
2190  next0 = sctp_next_output (is_ip4);
2191  goto done;
2192  }
2193 
2194  vnet_buffer (b0)->sctp.hdr_offset =
2195  (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
2196 
2197  /* Session exists */
2198  if (PREDICT_TRUE (0 != sctp_conn))
2199  {
2200  /* Save connection index */
2201  vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index;
2202  vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
2203  vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
2204 
2205  next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
2206  error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
2207 
2209  ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
2210  "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
2211  sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2212  connection.s_index,
2213  sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
2214  connection.c_index, trans_conn, sctp_conn,
2215  sctp_state_to_string (sctp_conn->state),
2216  sctp_chunk_to_string (chunk_type), phase_to_string (next0));
2217 
2218  if (chunk_type == DATA)
2219  SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
2220  n_advance_bytes0, n_data_bytes0);
2221 
2222  }
2223  else
2224  {
2225  if (result)
2226  {
2227  next0 = SCTP_INPUT_NEXT_DROP;
2228  error0 = SCTP_ERROR_NONE + result;
2229  }
2230  else if ((is_ip4 && tm->punt_unknown4) ||
2231  (!is_ip4 && tm->punt_unknown6))
2232  {
2234  error0 = SCTP_ERROR_PUNT;
2235  }
2236  else
2237  {
2238  next0 = SCTP_INPUT_NEXT_DROP;
2239  error0 = SCTP_ERROR_NO_LISTENER;
2240  }
2241  SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s",
2242  phase_to_string (next0));
2243  sctp_conn = 0;
2244  }
2245 
2246  done:
2247  b0->error = error0 ? node->errors[error0] : 0;
2248 
2249  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2250  {
2251  sctp_rx_trace_t *t0 =
2252  vlib_add_trace (vm, node, b0, sizeof (*t0));
2253  sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4);
2254  }
2255  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2256  n_left_to_next, bi0, next0);
2257  }
2258 
2259  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2260  }
2261  return from_frame->n_vectors;
2262 }
2263 
2265  vlib_frame_t * from_frame)
2266 {
2267  return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
2268 }
2269 
2271  vlib_frame_t * from_frame)
2272 {
2273  return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
2274 }
2275 
2276 /* *INDENT-OFF* */
2278 {
2279  .name = "sctp4-input",
2280  /* Takes a vector of packets. */
2281  .vector_size = sizeof (u32),
2282  .n_errors = SCTP_N_ERROR,
2283  .error_strings = sctp_error_strings,
2284  .n_next_nodes = SCTP_INPUT_N_NEXT,
2285  .next_nodes =
2286  {
2287 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2289 #undef _
2290  },
2291  .format_buffer = format_sctp_header,
2292  .format_trace = format_sctp_rx_trace,
2293 };
2294 /* *INDENT-ON* */
2295 
2296 /* *INDENT-OFF* */
2298 {
2299  .name = "sctp6-input",
2300  /* Takes a vector of packets. */
2301  .vector_size = sizeof (u32),
2302  .n_errors = SCTP_N_ERROR,
2303  .error_strings = sctp_error_strings,
2304  .n_next_nodes = SCTP_INPUT_N_NEXT,
2305  .next_nodes =
2306  {
2307 #define _(s,n) [SCTP_INPUT_NEXT_##s] = n,
2309 #undef _
2310  },
2311  .format_buffer = format_sctp_header,
2312  .format_trace = format_sctp_rx_trace,
2313 };
2314 /* *INDENT-ON* */
2315 
2316 #ifndef CLIB_MARCH_VARIANT
2317 static void
2319 {
2320  int i, j;
2321  for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++)
2322  for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++)
2323  {
2324  tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP;
2325  tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH;
2326  }
2327 
2328 #define _(t,f,n,e) \
2329 do { \
2330  tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \
2331  tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \
2332 } while (0)
2333 
2334  /*
2335  * SCTP STATE-MACHINE states:
2336  *
2337  * _(CLOSED, "CLOSED") \
2338  * _(COOKIE_WAIT, "COOKIE_WAIT") \
2339  * _(COOKIE_ECHOED, "COOKIE_ECHOED") \
2340  * _(ESTABLISHED, "ESTABLISHED") \
2341  * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \
2342  * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \
2343  * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \
2344  * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
2345  */
2346  //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2347  _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2348  _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2349  _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2350  _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2351  _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2352  _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2353  _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2354  _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2355  _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2356  _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2357  _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2358  _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2359  _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2360  _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2361  _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2362 
2363  _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
2364  _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2365  _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2366  _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2367  _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2368  _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2369  _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
2370  _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2371  _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2372  _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2373  _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2374  _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2375  _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2376  _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2377  _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2379  SCTP_ERROR_NONE);
2380 
2381  _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
2382  _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */
2383  _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2384  _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2385  _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2386  _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2387  _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2388  _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2389  _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2390  _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2391  _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2393  SCTP_ERROR_NONE);
2394  _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2395  _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2396  _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2398  SCTP_ERROR_NONE);
2399 
2400  _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2401  _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2402  _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2403  _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
2405  SCTP_ERROR_NONE);
2407  SCTP_ERROR_NONE);
2408  _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2409  _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2410  _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2411  _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2412  _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */
2413  _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2414  _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2415  _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2416  _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2418  SCTP_ERROR_NONE);
2419 
2420  _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2421  _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2422  _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2423  _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
2424  _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE,
2425  SCTP_ERROR_NONE);
2426  _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE,
2427  SCTP_ERROR_NONE);
2428  _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2429  _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2430  SCTP_ERROR_NONE);
2431  _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2432  _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */
2433  _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2434  SCTP_ERROR_NONE);
2435  _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2436  _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2437  _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2438  _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2439  _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2440  SCTP_ERROR_NONE);
2441 
2442  _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2443  _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2444  _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2445  _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
2446  _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2447  _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2448  _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2449  _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
2450  _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2451  SCTP_ERROR_NONE);
2452  _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2453  SCTP_ERROR_NONE);
2454  _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2455  _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2456  _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2457  _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2459  SCTP_ERROR_NONE);
2460 
2461  _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2462  _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2463  _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2464  _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2465  _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2466  _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2467  _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2468  _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2469  _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2470  SCTP_ERROR_NONE);
2471  _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2472  SCTP_ERROR_NONE);
2473  _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2474  _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2475  _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2476  _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION); /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
2477  _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2478  SCTP_ERROR_NONE);
2479 
2480  _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */
2481  _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk */
2482  _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */
2483  _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
2484  _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
2485  _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */
2486  _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
2487  _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */
2488  _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */
2489  _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2490  SCTP_ERROR_NONE);
2491  _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */
2492  _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
2493  _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
2494  _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
2495  SCTP_ERROR_NONE);
2496  _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
2497  SCTP_ERROR_NONE);
2498 
2499  /* TODO: Handle COOKIE ECHO when a TCB Exists */
2500 
2501 #undef _
2502 }
2503 
2504 clib_error_t *
2506 {
2507  clib_error_t *error = 0;
2509 
2510  if ((error = vlib_call_init_function (vm, sctp_init)))
2511  return error;
2512 
2513  /* Initialize dispatch table. */
2515 
2516  return error;
2517 }
2518 
2520 #endif /* CLIB_MARCH_VARIANT */
2521 
2522 /*
2523  * fd.io coding-style-patch-verification: ON
2524  *
2525  * Local Variables:
2526  * eval: (c-set-style "gnu")
2527  * End:
2528  */
void sctp_flush_frame_to_output(vlib_main_t *vm, u8 thread_index, u8 is_ip4)
Flush tx frame populated by retransmits and timer pops.
Definition: sctp_output.c:24
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
static u16 sctp_handle_shutdown_complete(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 sctp_implied_length, u16 *next0)
Definition: sctp_input.c:1267
u16 sctp_check_outstanding_data_chunks(sctp_connection_t *sctp_conn)
Definition: sctp.c:558
static sctp_connection_t * sctp_lookup_connection(u32 fib_index, vlib_buffer_t *b, u8 thread_index, u8 is_ip4)
Lookup transport connection.
Definition: sctp_input.c:148
struct _sctp_main sctp_main_t
static void sctp_timer_set(sctp_connection_t *tc, u8 conn_idx, u8 timer_id, u32 interval)
Definition: sctp.h:596
void sctp_connection_timers_init(sctp_connection_t *sctp_conn)
Initialize all connection timers as invalid.
Definition: sctp.c:140
static void sctp_is_connection_gapping(sctp_connection_t *sctp_conn, u32 tsn, u8 *gapping)
Definition: sctp_input.c:757
static u8 sctp_sub_conn_id_via_ip4h(sctp_connection_t *sctp_conn, ip4_header_t *ip4h)
Definition: sctp.h:809
#define SCTP_DBG(_fmt, _args...)
Definition: sctp_debug.h:38
void sctp_init_snd_vars(sctp_connection_t *sctp_conn)
Initialize connection send variables.
Definition: sctp.c:255
#define CLIB_UNUSED(x)
Definition: clib.h:82
static u16 sctp_handle_init(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, vlib_buffer_t *b0, u16 sctp_implied_length)
Definition: sctp_input.c:318
static u16 sctp_is_valid_init_ack(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, vlib_buffer_t *b0, u16 sctp_implied_length)
Definition: sctp_input.c:466
static u8 * format_sctp_rx_trace_short(u8 *s, va_list *args)
Definition: sctp_input.c:1136
ip4_address_t src_address
Definition: ip4_packet.h:170
transport_connection_t * session_lookup_connection_wt6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto, u32 thread_index, u8 *result)
Lookup connection with ip6 and transport layer information.
static u8 sctp_lookup_is_valid(transport_connection_t *trans_conn, sctp_header_t *sctp_hdr)
Definition: sctp_input.c:128
enum _sctp_listen_phase_next sctp_listen_phase_next_t
static uword sctp46_established_phase_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip4)
Definition: sctp_input.c:1812
#define COOKIE_RECEIVED_WHILE_SHUTTING_DOWN
Definition: sctp_packet.h:1007
#define PREDICT_TRUE(x)
Definition: clib.h:112
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned long u64
Definition: types.h:89
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
sctp_header_t sctp_header
Definition: sctp_input.c:232
#define NULL
Definition: clib.h:58
sctp_chunks_common_hdr_t chunk_hdr
Definition: sctp_packet.h:591
static u8 vnet_sctp_get_ebit(sctp_chunks_common_hdr_t *h)
Definition: sctp_packet.h:329
static u64 sctp_time_now(void)
Definition: sctp.h:671
enum _sctp_rcv_phase_next sctp_rcv_phase_next_t
u32 thread_index
Definition: main.h:197
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
int session_main_flush_enqueue_events(u8 transport_proto, u32 thread_index)
Flushes queue of sessions that are to be notified of new data enqueued events.
Definition: session.c:559
#define SCTP_ADV_DBG(_fmt, _args...)
Definition: sctp_debug.h:45
u8 data[0]
Packet data.
Definition: buffer.h:181
static u16 sctp_handle_cookie_echo(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 *next0)
Definition: sctp_input.c:873
sctp_chunks_common_hdr_t chunk_hdr
Definition: sctp_packet.h:412
int i
#define SCTP_HOSTNAME_ADDRESS_TYPE
Definition: sctp_packet.h:784
void sctp_prepare_cookie_ack_chunk(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b)
Definition: sctp_output.c:497
static u32 format_get_indent(u8 *s)
Definition: format.h:72
void sctp_prepare_abort_for_collision(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, ip4_address_t *ip4_addr, ip6_address_t *ip6_addr)
Convert buffer to ABORT.
Definition: sctp_output.c:659
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static u16 sctp_handle_shutdown_ack(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 sctp_implied_length, u16 *next0)
Definition: sctp_input.c:1230
#define VLIB_NODE_FN(node)
Definition: node.h:201
static void sctp_calculate_rto(sctp_connection_t *sctp_conn, u8 conn_idx)
Definition: sctp.h:679
int session_enqueue_stream_connection(transport_connection_t *tc, vlib_buffer_t *b, u32 offset, u8 queue_event, u8 is_in_order)
Definition: session.c:355
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:469
static char * sctp_error_strings[]
Definition: sctp_input.c:22
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
ip6_address_t src_address
Definition: ip6_packet.h:385
unsigned char u8
Definition: types.h:56
static sctp_main_t * vnet_get_sctp_main()
Definition: sctp.h:544
vlib_node_registration_t sctp4_established_phase_node
(constructor) VLIB_REGISTER_NODE (sctp4_established_phase_node)
Definition: sctp_input.c:2035
static void sctp_dispatch_table_init(sctp_main_t *tm)
Definition: sctp_input.c:2318
enum _sctp_input_next sctp_input_next_t
sctp_chunks_common_hdr_t chunk_hdr
Definition: sctp_packet.h:1411
enum _sctp_shutdown_phase_next sctp_shutdown_phase_next_t
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
Definition: session.c:724
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
static u8 * format_sctp_rx_trace(u8 *s, va_list *args)
Definition: sctp_input.c:1981
static void sctp_init_cwnd(sctp_connection_t *sctp_conn)
Definition: sctp.h:903
#define always_inline
Definition: clib.h:98
ip4_address_t dst_address
Definition: ip4_packet.h:170
void sctp_prepare_initack_chunk_for_collision(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, ip4_address_t *ip4_addr, ip6_address_t *ip6_addr)
Convert buffer to INIT-ACK.
Definition: sctp_output.c:700
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
transport_connection_t * session_lookup_connection_wt4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto, u32 thread_index, u8 *result)
Lookup connection with ip4 and transport layer information.
#define FQDN_MAX_LENGTH
Definition: sctp_packet.h:914
vlib_node_registration_t sctp6_input_node
(constructor) VLIB_REGISTER_NODE (sctp6_input_node)
Definition: sctp_input.c:2297
#define STALE_COOKIE_ERROR
Definition: sctp_packet.h:1000
#define UNRECOGNIZED_CHUNK_TYPE
Definition: sctp_packet.h:1003
vlib_node_registration_t sctp4_input_node
(constructor) VLIB_REGISTER_NODE (sctp4_input_node)
Definition: sctp_input.c:2277
static void vnet_sctp_common_hdr_params_net_to_host(sctp_chunks_common_hdr_t *h)
Definition: sctp_packet.h:290
static void * ip4_next_header(ip4_header_t *i)
Definition: ip4_packet.h:241
void sctp_prepare_sack_chunk(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b)
Convert buffer to SACK.
Definition: sctp_output.c:1094
static int sctp_half_open_connection_cleanup(sctp_connection_t *tc)
Try to cleanup half-open connection.
Definition: sctp.h:634
unsigned int u32
Definition: types.h:88
sctp_connection_t * sctp_connection_new(u8 thread_index)
Definition: sctp.c:426
#define vlib_call_init_function(vm, x)
Definition: init.h:260
#define SCTP_STATE_COOKIE_TYPE
Definition: sctp_packet.h:780
static uword sctp46_input_dispatcher(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip4)
Definition: sctp_input.c:2078
#define SCTP_UNRECOGNIZED_TYPE
Definition: sctp_packet.h:781
vlib_node_registration_t sctp4_shutdown_phase_node
(constructor) VLIB_REGISTER_NODE (sctp4_shutdown_phase_node)
Definition: sctp_input.c:1480
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
static u16 sctp_handle_shutdown(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 sctp_implied_length, u16 *next0)
Definition: sctp_input.c:1189
ip6_address_t address
Definition: sctp_packet.h:842
void sctp_prepare_heartbeat_ack_chunk(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b)
Convert buffer to HEARTBEAT_ACK.
Definition: sctp_output.c:1132
static void sctp_timer_reset(sctp_connection_t *tc, u8 conn_idx, u8 timer_id)
Definition: sctp.h:611
static u16 sctp_calculate_implied_length(ip4_header_t *ip4_hdr, ip6_header_t *ip6_hdr, int is_ip4)
Definition: sctp_input.c:262
static sctp_connection_t * sctp_get_connection_from_transport(transport_connection_t *tconn)
Definition: sctp.h:652
sctp_init_chunk_t sctp_init_ack_chunk_t
Definition: sctp_packet.h:690
vlib_node_registration_t sctp6_listen_phase_node
(constructor) VLIB_REGISTER_NODE (sctp6_listen_phase_node)
Definition: sctp_input.c:2016
unsigned short u16
Definition: types.h:57
vlib_node_registration_t sctp4_rcv_phase_node
(constructor) VLIB_REGISTER_NODE (sctp4_rcv_phase_node)
Definition: sctp_input.c:1151
vlib_node_registration_t sctp6_shutdown_phase_node
(constructor) VLIB_REGISTER_NODE (sctp6_shutdown_phase_node)
Definition: sctp_input.c:1499
static u8 vnet_sctp_get_bbit(sctp_chunks_common_hdr_t *h)
Definition: sctp_packet.h:316
u8 sctp_sub_connection_add_ip4(vlib_main_t *vm, ip4_address_t *lcl_addr, ip4_address_t *rmt_addr)
Definition: sctp.c:295
static u8 sctp_is_bundling(u16 sctp_implied_length, sctp_chunks_common_hdr_t *sctp_common_hdr)
Definition: sctp_input.c:278
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
sctp_header_t sctp_hdr
Definition: sctp_packet.h:1253
static int sctp_session_enqueue_data(sctp_connection_t *sctp_conn, vlib_buffer_t *b, u16 data_len, u8 conn_idx)
Enqueue data for delivery to application.
Definition: sctp_input.c:668
static uword sctp46_rcv_phase_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip4)
Definition: sctp_input.c:952
#define PREDICT_FALSE(x)
Definition: clib.h:111
static u16 sctp_handle_heartbeat(sctp_hb_req_chunk_t *sctp_hb_chunk, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 *next0)
Definition: sctp_input.c:1558
struct _sctp_connection sctp_connection_t
#define SCTP_IPV6_ADDRESS_TYPE
Definition: sctp_packet.h:778
static u64 sctp_set_time_now(u32 thread_index)
Definition: sctp.h:588
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:368
#define MAX_SCTP_CONNECTIONS
Definition: sctp.h:80
u32 verification_tag
Definition: sctp_packet.h:73
static char * sctp_state_to_string(u8 state)
Definition: sctp.h:365
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1180
static u16 sctp_handle_init_ack(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 sctp_implied_length)
Definition: sctp_input.c:490
static u8 vnet_sctp_get_chunk_type(sctp_chunks_common_hdr_t *h)
Definition: sctp_packet.h:342
#define MAX_ENQUEABLE_SACKS
Definition: sctp.h:178
sctp_chunks_common_hdr_t common_hdr
Definition: sctp_packet.h:261
ip4_address_t address
Definition: sctp_packet.h:804
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:395
vlib_main_t * vm
Definition: buffer.c:312
u8 * format_sctp_connection(u8 *s, va_list *args)
Definition: sctp.c:233
#define clib_warning(format, args...)
Definition: error.h:59
struct _transport_connection transport_connection_t
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:465
int session_stream_accept(transport_connection_t *tc, u32 listener_index, u8 notify)
Accept a stream session.
Definition: session.c:868
#define foreach_sctp4_input_next
Definition: sctp_input.c:110
static u32 sctp_header_bytes()
Definition: sctp.h:646
clib_error_t * sctp_input_init(vlib_main_t *vm)
Definition: sctp_input.c:2505
#define sctp_next_drop(is_ip4)
Definition: sctp_input.c:239
static void * ip6_next_header(ip6_header_t *i)
Definition: ip6_packet.h:412
char hostname[FQDN_MAX_LENGTH]
Definition: sctp_packet.h:945
static u16 sctp_handle_heartbeat_ack(sctp_hb_ack_chunk_t *sctp_hb_ack_chunk, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 *next0)
Definition: sctp_input.c:1577
void sctp_send_shutdown_complete(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0)
Definition: sctp_output.c:1268
vlib_node_registration_t sctp6_established_phase_node
(constructor) VLIB_REGISTER_NODE (sctp6_established_phase_node)
Definition: sctp_input.c:2054
vlib_node_registration_t sctp6_init_phase_node
(constructor) VLIB_REGISTER_NODE (sctp6_init_phase_node)
Definition: sctp_input.c:1170
void sctp_prepare_operation_error(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, u8 err_cause)
Convert buffer to ERROR.
Definition: sctp_output.c:614
sctp_header_t sctp_hdr
Definition: sctp_packet.h:590
static sctp_connection_t * sctp_half_open_connection_get(u32 conn_index)
Definition: sctp.h:560
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:514
static u16 sctp_handle_operation_err(sctp_header_t *sctp_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, u16 *next0)
Definition: sctp_input.c:288
#define ASSERT(truth)
sctp_opt_params_hdr_t param_hdr
Definition: sctp_packet.h:1313
static int sctp_session_enqueue_data_ooo(sctp_connection_t *sctp_conn, vlib_buffer_t *b, u16 data_len, u8 conn_idx)
Enqueue data out-of-order for delivery to application.
Definition: sctp_input.c:613
#define SCTP_PRIMARY_PATH_IDX
Definition: sctp.h:81
static uword sctp46_shutdown_phase_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip4)
Definition: sctp_input.c:1301
#define SCTP_CONN_TRACKING_DBG(_fmt, _args...)
Definition: sctp_debug.h:66
sctp_connection_t sctp_connection
Definition: sctp_input.c:233
format_function_t format_sctp_header
Definition: format.h:101
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
sctp_chunks_common_hdr_t chunk_hdr
Definition: sctp_packet.h:1452
void sctp_connection_cleanup(sctp_connection_t *sctp_conn)
Cleans up connection state.
Definition: sctp.c:528
int session_stream_accept_notify(transport_connection_t *tc)
Definition: session.c:851
enum _sctp_established_phase_next sctp_established_phase_next_t
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
void sctp_prepare_initack_chunk(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, ip4_address_t *ip4_addr, u8 add_ip4, ip6_address_t *ip6_addr, u8 add_ip6)
Convert buffer to INIT-ACK.
Definition: sctp_output.c:840
void sctp_prepare_cookie_echo_chunk(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, u8 reuse_buffer)
Definition: sctp_output.c:531
static void sctp_timer_update(sctp_connection_t *tc, u8 conn_idx, u8 timer_id, u32 interval)
Definition: sctp.h:732
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
static u16 sctp_handle_sack(sctp_selective_ack_chunk_t *sack_chunk, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 *next0)
Definition: sctp_input.c:1518
static sctp_connection_t * sctp_connection_get(u32 conn_index, u32 thread_index)
Definition: sctp.h:757
u16 payload_length
Definition: ip6_packet.h:376
#define SCTP_IPV4_ADDRESS_TYPE
Definition: sctp_packet.h:776
static uword sctp46_listen_process_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip4)
Definition: sctp_input.c:1607
static u16 sctp_handle_data(sctp_payload_data_chunk_t *sctp_data_chunk, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b, u16 *next0)
Definition: sctp_input.c:773
sctp_err_cause_param_t err_causes[]
Definition: sctp_packet.h:1340
static u16 sctp_handle_cookie_ack(sctp_header_t *sctp_hdr, sctp_chunks_common_hdr_t *sctp_chunk_hdr, sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b0, u16 *next0)
Definition: sctp_input.c:921
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:274
#define sctp_next_output(is_ip4)
Definition: sctp_input.c:236
static u8 sctp_is_sack_delayable(sctp_connection_t *sctp_conn, u8 idx, u8 is_gapping)
Definition: sctp_input.c:720
static void sctp_set_rx_trace_data(sctp_rx_trace_t *rx_trace, sctp_connection_t *sctp_conn, sctp_header_t *sctp_hdr, vlib_buffer_t *b0, u8 is_ip4)
Definition: sctp_input.c:243
clib_error_t * sctp_init(vlib_main_t *vm)
Definition: sctp.c:968
sctp_chunks_common_hdr_t chunk_hdr
Definition: sctp_packet.h:771
#define vnet_buffer(b)
Definition: buffer.h:369
static u16 vnet_sctp_get_chunk_length(sctp_chunks_common_hdr_t *h)
Definition: sctp_packet.h:355
static char * sctp_chunk_to_string(u8 type)
Definition: sctp.h:390
int session_stream_connect_notify(transport_connection_t *tc, u8 is_fail)
Definition: session.c:598
static u8 sctp_sub_conn_id_via_ip6h(sctp_connection_t *sctp_conn, ip6_header_t *ip6h)
Definition: sctp.h:787
#define SCTP_COOKIE_PRESERVATIVE_TYPE
Definition: sctp_packet.h:782
static sctp_connection_t * sctp_listener_get(u32 tli)
Definition: sctp.h:749
static int ip4_header_bytes(const ip4_header_t *i)
Definition: ip4_packet.h:235
vlib_node_registration_t sctp4_listen_phase_node
(constructor) VLIB_REGISTER_NODE (sctp4_listen_phase_node)
Definition: sctp_input.c:1997
#define foreach_sctp6_input_next
Definition: sctp_input.c:119
static sctp_header_t * sctp_buffer_hdr(vlib_buffer_t *b)
Definition: sctp.h:550
u8 sctp_sub_connection_add_ip6(vlib_main_t *vm, ip6_address_t *lcl_addr, ip6_address_t *rmt_addr)
Definition: sctp.c:352
enum _sctp_state_next sctp_state_next_t
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
#define foreach_sctp_state_next
Definition: sctp_input.c:29
static void sctp_node_inc_counter(vlib_main_t *vm, u32 sctp4_node, u32 sctp6_node, u8 is_ip4, u8 evt, u8 val)
Definition: sctp_input.c:1594
#define SCTP_DBG_STATE_MACHINE(_fmt, _args...)
Definition: sctp_debug.h:31
void sctp_send_shutdown_ack(sctp_connection_t *sctp_conn, u8 idx, vlib_buffer_t *b)
Definition: sctp_output.c:1077
format_function_t format_sctp_state
Definition: sctp.h:302
ip6_address_t dst_address
Definition: ip6_packet.h:385
char * phase_to_string(u8 phase)
Definition: sctp_input.c:89
#define SCTP_SUPPORTED_ADDRESS_TYPES
Definition: sctp_packet.h:785