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