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