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