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; |
| 1673 | |
| 1674 | if (is_ip4) |
| 1675 | { |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1676 | 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] | 1677 | ip4_hdr->dst_address.as_u32; |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1678 | 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] | 1679 | ip4_hdr->src_address.as_u32; |
| 1680 | } |
| 1681 | else |
| 1682 | { |
| 1683 | clib_memcpy (&child_conn-> |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1684 | sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6, |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1685 | &ip6_hdr->dst_address, sizeof (ip6_address_t)); |
| 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_rmt_ip6, |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1688 | &ip6_hdr->src_address, sizeof (ip6_address_t)); |
| 1689 | } |
| 1690 | |
| 1691 | sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr; |
| 1692 | sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr; |
| 1693 | |
| 1694 | u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr); |
| 1695 | if (chunk_type != INIT) |
| 1696 | { |
| 1697 | SCTP_DBG |
| 1698 | ("conn_index = %u: chunk_type != INIT... chunk_type=%s", |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1699 | child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX]. |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1700 | connection.c_index, sctp_chunk_to_string (chunk_type)); |
| 1701 | |
| 1702 | error0 = SCTP_ERROR_UNKOWN_CHUNK; |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 1703 | next0 = sctp_next_drop (is_ip4); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1704 | goto drop; |
| 1705 | } |
| 1706 | |
| 1707 | u16 sctp_implied_length = |
| 1708 | sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4); |
| 1709 | |
| 1710 | switch (chunk_type) |
| 1711 | { |
| 1712 | case INIT: |
| 1713 | sctp_connection_timers_init (child_conn); |
| 1714 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 1715 | sctp_init_snd_vars (child_conn); |
| 1716 | |
Marco Varlese | 6e4d4a3 | 2018-03-12 12:36:59 +0100 | [diff] [blame^] | 1717 | sctp_init_cwnd (child_conn); |
| 1718 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1719 | error0 = |
| 1720 | sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0, |
| 1721 | sctp_implied_length); |
| 1722 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1723 | if (error0 == SCTP_ERROR_NONE) |
| 1724 | { |
| 1725 | if (stream_session_accept |
| 1726 | (&child_conn-> |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1727 | sub_conn[SCTP_PRIMARY_PATH_IDX].connection, |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1728 | sctp_listener-> |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1729 | sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0)) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1730 | { |
| 1731 | clib_warning ("session accept fail"); |
| 1732 | sctp_connection_cleanup (child_conn); |
| 1733 | error0 = SCTP_ERROR_CREATE_SESSION_FAIL; |
| 1734 | goto drop; |
| 1735 | } |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 1736 | next0 = sctp_next_output (is_ip4); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1737 | } |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1738 | break; |
| 1739 | |
| 1740 | /* Reception of a DATA chunk whilst in the CLOSED state is called |
| 1741 | * "Out of the Blue" packet and handling of the chunk needs special treatment |
| 1742 | * as per RFC4960 section 8.4 |
| 1743 | */ |
| 1744 | case DATA: |
| 1745 | break; |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 1746 | |
| 1747 | case OPERATION_ERROR: |
| 1748 | error0 = |
| 1749 | sctp_handle_operation_err (sctp_hdr, child_conn, |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 1750 | SCTP_PRIMARY_PATH_IDX, b0, &next0); |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 1751 | break; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | drop: |
| 1755 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1756 | { |
| 1757 | sctp_rx_trace_t *t0 = |
| 1758 | vlib_add_trace (vm, node, b0, sizeof (*t0)); |
| 1759 | clib_memcpy (&t0->sctp_header, sctp_hdr, |
| 1760 | sizeof (t0->sctp_header)); |
| 1761 | clib_memcpy (&t0->sctp_connection, sctp_listener, |
| 1762 | sizeof (t0->sctp_connection)); |
| 1763 | } |
| 1764 | |
| 1765 | b0->error = node->errors[error0]; |
| 1766 | |
| 1767 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 1768 | n_left_to_next, bi0, next0); |
| 1769 | } |
| 1770 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1771 | |
| 1772 | } |
| 1773 | return from_frame->n_vectors; |
| 1774 | } |
| 1775 | |
| 1776 | static uword |
| 1777 | sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1778 | vlib_frame_t * from_frame) |
| 1779 | { |
| 1780 | return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ ); |
| 1781 | } |
| 1782 | |
| 1783 | static uword |
| 1784 | sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1785 | vlib_frame_t * from_frame) |
| 1786 | { |
| 1787 | return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ ); |
| 1788 | } |
| 1789 | |
| 1790 | always_inline uword |
| 1791 | sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1792 | vlib_frame_t * from_frame, int is_ip4) |
| 1793 | { |
| 1794 | u32 n_left_from, next_index, *from, *to_next; |
| 1795 | u32 my_thread_index = vm->thread_index, errors = 0; |
| 1796 | |
| 1797 | from = vlib_frame_vector_args (from_frame); |
| 1798 | n_left_from = from_frame->n_vectors; |
| 1799 | |
| 1800 | next_index = node->cached_next_index; |
| 1801 | |
| 1802 | while (n_left_from > 0) |
| 1803 | { |
| 1804 | u32 n_left_to_next; |
| 1805 | |
| 1806 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1807 | |
| 1808 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1809 | { |
| 1810 | u32 bi0; |
| 1811 | vlib_buffer_t *b0; |
| 1812 | sctp_header_t *sctp_hdr = 0; |
| 1813 | sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0; |
| 1814 | ip4_header_t *ip4_hdr = 0; |
| 1815 | ip6_header_t *ip6_hdr = 0; |
| 1816 | sctp_connection_t *sctp_conn; |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 1817 | u16 error0 = SCTP_ERROR_ENQUEUED, next0 = |
| 1818 | SCTP_ESTABLISHED_PHASE_N_NEXT; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1819 | u8 idx; |
| 1820 | |
| 1821 | bi0 = from[0]; |
| 1822 | to_next[0] = bi0; |
| 1823 | from += 1; |
| 1824 | to_next += 1; |
| 1825 | n_left_from -= 1; |
| 1826 | n_left_to_next -= 1; |
| 1827 | |
| 1828 | b0 = vlib_get_buffer (vm, bi0); |
| 1829 | sctp_conn = |
| 1830 | sctp_connection_get (vnet_buffer (b0)->sctp.connection_index, |
| 1831 | my_thread_index); |
| 1832 | |
| 1833 | if (PREDICT_FALSE (sctp_conn == 0)) |
| 1834 | { |
| 1835 | SCTP_DBG |
| 1836 | ("sctp_conn == NULL; return SCTP_ERROR_INVALID_CONNECTION"); |
| 1837 | error0 = SCTP_ERROR_INVALID_CONNECTION; |
| 1838 | goto done; |
| 1839 | } |
| 1840 | if (is_ip4) |
| 1841 | { |
| 1842 | ip4_hdr = vlib_buffer_get_current (b0); |
| 1843 | sctp_hdr = ip4_next_header (ip4_hdr); |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 1844 | idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | ip6_hdr = vlib_buffer_get_current (b0); |
| 1849 | sctp_hdr = ip6_next_header (ip6_hdr); |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 1850 | idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1851 | } |
| 1852 | |
Marco Varlese | 04e5d64 | 2018-02-23 17:43:06 +0100 | [diff] [blame] | 1853 | sctp_conn->sub_conn[idx].subconn_idx = idx; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1854 | |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 1855 | sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1856 | sctp_chunk_hdr = |
| 1857 | (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr); |
| 1858 | |
| 1859 | u8 chunk_type = vnet_sctp_get_chunk_type (&full_hdr->common_hdr); |
| 1860 | |
| 1861 | switch (chunk_type) |
| 1862 | { |
| 1863 | case COOKIE_ECHO: |
| 1864 | error0 = |
| 1865 | sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn, |
Marco Varlese | be2251b | 2018-02-07 12:22:41 +0100 | [diff] [blame] | 1866 | idx, b0, &next0); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1867 | break; |
| 1868 | |
| 1869 | case COOKIE_ACK: |
| 1870 | error0 = |
| 1871 | sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn, |
Marco Varlese | be2251b | 2018-02-07 12:22:41 +0100 | [diff] [blame] | 1872 | idx, b0, &next0); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1873 | break; |
| 1874 | |
| 1875 | case SACK: |
| 1876 | error0 = |
| 1877 | sctp_handle_sack ((sctp_selective_ack_chunk_t *) sctp_hdr, |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 1878 | sctp_conn, idx, b0, &next0); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1879 | break; |
| 1880 | |
| 1881 | case HEARTBEAT: |
| 1882 | error0 = |
| 1883 | sctp_handle_heartbeat ((sctp_hb_req_chunk_t *) sctp_hdr, |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 1884 | sctp_conn, idx, b0, &next0); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1885 | break; |
| 1886 | |
| 1887 | case HEARTBEAT_ACK: |
| 1888 | error0 = |
| 1889 | sctp_handle_heartbeat_ack ((sctp_hb_ack_chunk_t *) sctp_hdr, |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 1890 | sctp_conn, idx, b0, &next0); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1891 | break; |
| 1892 | |
| 1893 | case DATA: |
| 1894 | error0 = |
| 1895 | sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr, |
Marco Varlese | be2251b | 2018-02-07 12:22:41 +0100 | [diff] [blame] | 1896 | sctp_conn, idx, b0, &next0); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1897 | break; |
| 1898 | |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 1899 | case OPERATION_ERROR: |
| 1900 | error0 = |
| 1901 | sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0, |
| 1902 | &next0); |
| 1903 | break; |
| 1904 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1905 | /* All UNEXPECTED scenarios (wrong chunk received per state-machine) |
| 1906 | * are handled by the input-dispatcher function using the table-lookup |
| 1907 | * hence we should never get to the "default" case below. |
| 1908 | */ |
| 1909 | default: |
| 1910 | error0 = SCTP_ERROR_UNKOWN_CHUNK; |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 1911 | next0 = sctp_next_drop (is_ip4); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1912 | goto done; |
| 1913 | } |
| 1914 | |
| 1915 | done: |
| 1916 | b0->error = node->errors[error0]; |
| 1917 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1918 | { |
| 1919 | sctp_rx_trace_t *t0 = |
| 1920 | vlib_add_trace (vm, node, b0, sizeof (*t0)); |
| 1921 | sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4); |
| 1922 | } |
| 1923 | |
| 1924 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 1925 | n_left_to_next, bi0, next0); |
| 1926 | } |
| 1927 | |
| 1928 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1929 | } |
| 1930 | |
| 1931 | errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP, |
| 1932 | my_thread_index); |
| 1933 | |
| 1934 | sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index, |
| 1935 | sctp6_established_phase_node.index, |
| 1936 | SCTP_ERROR_EVENT_FIFO_FULL, errors); |
| 1937 | sctp_flush_frame_to_output (vm, my_thread_index, is_ip4); |
| 1938 | |
| 1939 | return from_frame->n_vectors; |
| 1940 | } |
| 1941 | |
| 1942 | static uword |
| 1943 | sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1944 | vlib_frame_t * from_frame) |
| 1945 | { |
| 1946 | return sctp46_established_phase_inline (vm, node, from_frame, |
| 1947 | 1 /* is_ip4 */ ); |
| 1948 | } |
| 1949 | |
| 1950 | static uword |
| 1951 | sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1952 | vlib_frame_t * from_frame) |
| 1953 | { |
| 1954 | return sctp46_established_phase_inline (vm, node, from_frame, |
| 1955 | 0 /* is_ip4 */ ); |
| 1956 | } |
| 1957 | |
| 1958 | u8 * |
| 1959 | format_sctp_rx_trace (u8 * s, va_list * args) |
| 1960 | { |
| 1961 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 1962 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 1963 | sctp_rx_trace_t *t = va_arg (*args, sctp_rx_trace_t *); |
| 1964 | u32 indent = format_get_indent (s); |
| 1965 | |
| 1966 | s = format (s, "%U\n%U%U", |
| 1967 | format_sctp_header, &t->sctp_header, 128, |
| 1968 | format_white_space, indent, |
| 1969 | format_sctp_connection, &t->sctp_connection, 1); |
| 1970 | |
| 1971 | return s; |
| 1972 | } |
| 1973 | |
| 1974 | /* *INDENT-OFF* */ |
| 1975 | VLIB_REGISTER_NODE (sctp4_listen_phase_node) = |
| 1976 | { |
| 1977 | .function = sctp4_listen_phase, |
| 1978 | .name = "sctp4-listen", |
| 1979 | /* Takes a vector of packets. */ |
| 1980 | .vector_size = sizeof (u32), |
| 1981 | .n_errors = SCTP_N_ERROR, |
| 1982 | .error_strings = sctp_error_strings, |
| 1983 | .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT, |
| 1984 | .next_nodes = |
| 1985 | { |
| 1986 | #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n, |
| 1987 | foreach_sctp_state_next |
| 1988 | #undef _ |
| 1989 | }, |
| 1990 | .format_trace = format_sctp_rx_trace_short, |
| 1991 | }; |
| 1992 | /* *INDENT-ON* */ |
| 1993 | |
| 1994 | VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase); |
| 1995 | |
| 1996 | /* *INDENT-OFF* */ |
| 1997 | VLIB_REGISTER_NODE (sctp6_listen_phase_node) = |
| 1998 | { |
| 1999 | .function = sctp6_listen_phase, |
| 2000 | .name = "sctp6-listen", |
| 2001 | /* Takes a vector of packets. */ |
| 2002 | .vector_size = sizeof (u32), |
| 2003 | .n_errors = SCTP_N_ERROR, |
| 2004 | .error_strings = sctp_error_strings, |
| 2005 | .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT, |
| 2006 | .next_nodes = |
| 2007 | { |
| 2008 | #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n, |
| 2009 | foreach_sctp_state_next |
| 2010 | #undef _ |
| 2011 | }, |
| 2012 | .format_trace = format_sctp_rx_trace_short, |
| 2013 | }; |
| 2014 | /* *INDENT-ON* */ |
| 2015 | |
| 2016 | VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase); |
| 2017 | |
| 2018 | /* *INDENT-OFF* */ |
| 2019 | VLIB_REGISTER_NODE (sctp4_established_phase_node) = |
| 2020 | { |
| 2021 | .function = sctp4_established_phase, |
| 2022 | .name = "sctp4-established", |
| 2023 | /* Takes a vector of packets. */ |
| 2024 | .vector_size = sizeof (u32), |
| 2025 | .n_errors = SCTP_N_ERROR, |
| 2026 | .error_strings = sctp_error_strings, |
| 2027 | .n_next_nodes = SCTP_ESTABLISHED_PHASE_N_NEXT, |
| 2028 | .next_nodes = |
| 2029 | { |
| 2030 | #define _(s,n) [SCTP_ESTABLISHED_PHASE_NEXT_##s] = n, |
| 2031 | foreach_sctp_state_next |
| 2032 | #undef _ |
| 2033 | }, |
| 2034 | .format_trace = format_sctp_rx_trace_short, |
| 2035 | }; |
| 2036 | /* *INDENT-ON* */ |
| 2037 | |
| 2038 | VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node, |
| 2039 | sctp4_established_phase); |
| 2040 | |
| 2041 | /* *INDENT-OFF* */ |
| 2042 | VLIB_REGISTER_NODE (sctp6_established_phase_node) = |
| 2043 | { |
| 2044 | .function = sctp6_established_phase, |
| 2045 | .name = "sctp6-established", |
| 2046 | /* Takes a vector of packets. */ |
| 2047 | .vector_size = sizeof (u32), |
| 2048 | .n_errors = SCTP_N_ERROR, |
| 2049 | .error_strings = sctp_error_strings, |
| 2050 | .n_next_nodes = SCTP_LISTEN_PHASE_N_NEXT, |
| 2051 | .next_nodes = |
| 2052 | { |
| 2053 | #define _(s,n) [SCTP_LISTEN_PHASE_NEXT_##s] = n, |
| 2054 | foreach_sctp_state_next |
| 2055 | #undef _ |
| 2056 | }, |
| 2057 | .format_trace = format_sctp_rx_trace_short, |
| 2058 | }; |
| 2059 | /* *INDENT-ON* */ |
| 2060 | |
| 2061 | VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node, |
| 2062 | sctp6_established_phase); |
| 2063 | |
| 2064 | /* |
| 2065 | * This is the function executed first for the SCTP graph. |
| 2066 | * It takes care of doing the initial message parsing and |
| 2067 | * dispatch to the specialized function. |
| 2068 | */ |
| 2069 | always_inline uword |
| 2070 | sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 2071 | vlib_frame_t * from_frame, int is_ip4) |
| 2072 | { |
| 2073 | u32 n_left_from, next_index, *from, *to_next; |
| 2074 | u32 my_thread_index = vm->thread_index; |
| 2075 | u8 is_filtered; |
| 2076 | sctp_main_t *tm = vnet_get_sctp_main (); |
| 2077 | |
| 2078 | from = vlib_frame_vector_args (from_frame); |
| 2079 | n_left_from = from_frame->n_vectors; |
| 2080 | next_index = node->cached_next_index; |
| 2081 | sctp_set_time_now (my_thread_index); |
| 2082 | |
| 2083 | while (n_left_from > 0) |
| 2084 | { |
| 2085 | u32 n_left_to_next; |
| 2086 | |
| 2087 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 2088 | |
| 2089 | while (n_left_from > 0 && n_left_to_next > 0) |
| 2090 | { |
| 2091 | int n_advance_bytes0, n_data_bytes0; |
| 2092 | u32 bi0, fib_index0; |
| 2093 | vlib_buffer_t *b0; |
| 2094 | sctp_header_t *sctp_hdr = 0; |
| 2095 | sctp_chunks_common_hdr_t *sctp_chunk_hdr = 0; |
| 2096 | sctp_connection_t *sctp_conn; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 2097 | transport_connection_t *trans_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2098 | ip4_header_t *ip4_hdr; |
| 2099 | ip6_header_t *ip6_hdr; |
| 2100 | u32 error0 = SCTP_ERROR_NO_LISTENER, next0 = SCTP_INPUT_NEXT_DROP; |
| 2101 | |
| 2102 | bi0 = from[0]; |
| 2103 | to_next[0] = bi0; |
| 2104 | from += 1; |
| 2105 | to_next += 1; |
| 2106 | n_left_from -= 1; |
| 2107 | n_left_to_next -= 1; |
| 2108 | |
| 2109 | b0 = vlib_get_buffer (vm, bi0); |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 2110 | vnet_buffer (b0)->sctp.flags = 0; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2111 | fib_index0 = vnet_buffer (b0)->ip.fib_index; |
| 2112 | |
| 2113 | /* Checksum computed by ipx_local no need to compute again */ |
| 2114 | |
| 2115 | if (is_ip4) |
| 2116 | { |
| 2117 | ip4_hdr = vlib_buffer_get_current (b0); |
| 2118 | sctp_hdr = ip4_next_header (ip4_hdr); |
| 2119 | |
| 2120 | sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr; |
| 2121 | sctp_chunk_hdr = &full_hdr->common_hdr; |
| 2122 | |
| 2123 | n_advance_bytes0 = |
| 2124 | (ip4_header_bytes (ip4_hdr) + |
| 2125 | sizeof (sctp_payload_data_chunk_t)); |
| 2126 | n_data_bytes0 = |
| 2127 | clib_net_to_host_u16 (ip4_hdr->length) - n_advance_bytes0; |
| 2128 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 2129 | trans_conn = session_lookup_connection_wt4 (fib_index0, |
| 2130 | &ip4_hdr->dst_address, |
| 2131 | &ip4_hdr->src_address, |
| 2132 | sctp_hdr->dst_port, |
| 2133 | sctp_hdr->src_port, |
| 2134 | TRANSPORT_PROTO_SCTP, |
| 2135 | my_thread_index, |
| 2136 | &is_filtered); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2137 | } |
| 2138 | else |
| 2139 | { |
| 2140 | ip6_hdr = vlib_buffer_get_current (b0); |
| 2141 | sctp_hdr = ip6_next_header (ip6_hdr); |
| 2142 | |
| 2143 | sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr; |
| 2144 | sctp_chunk_hdr = &full_hdr->common_hdr; |
| 2145 | |
| 2146 | n_advance_bytes0 = sctp_header_bytes (); |
| 2147 | n_data_bytes0 = |
| 2148 | clib_net_to_host_u16 (ip6_hdr->payload_length) - |
| 2149 | n_advance_bytes0; |
| 2150 | n_advance_bytes0 += sizeof (ip6_hdr[0]); |
| 2151 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 2152 | trans_conn = session_lookup_connection_wt6 (fib_index0, |
| 2153 | &ip6_hdr->dst_address, |
| 2154 | &ip6_hdr->src_address, |
| 2155 | sctp_hdr->dst_port, |
| 2156 | sctp_hdr->src_port, |
| 2157 | TRANSPORT_PROTO_SCTP, |
| 2158 | my_thread_index, |
| 2159 | &is_filtered); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | /* Length check */ |
| 2163 | if (PREDICT_FALSE (n_advance_bytes0 < 0)) |
| 2164 | { |
| 2165 | error0 = SCTP_ERROR_LENGTH; |
| 2166 | goto done; |
| 2167 | } |
| 2168 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 2169 | sctp_conn = sctp_get_connection_from_transport (trans_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2170 | vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr); |
| 2171 | |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 2172 | u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr); |
| 2173 | if (chunk_type >= UNKNOWN) |
| 2174 | { |
| 2175 | clib_warning |
Marco Varlese | 8c5f67f | 2018-02-27 09:38:31 +0100 | [diff] [blame] | 2176 | ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk"); |
| 2177 | |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 2178 | sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX, |
Marco Varlese | 8c5f67f | 2018-02-27 09:38:31 +0100 | [diff] [blame] | 2179 | b0, UNRECOGNIZED_CHUNK_TYPE); |
| 2180 | |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 2181 | error0 = SCTP_ERROR_UNKOWN_CHUNK; |
Marco Varlese | 8c5f67f | 2018-02-27 09:38:31 +0100 | [diff] [blame] | 2182 | next0 = sctp_next_output (is_ip4); |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 2183 | goto done; |
| 2184 | } |
| 2185 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2186 | vnet_buffer (b0)->sctp.hdr_offset = |
| 2187 | (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0); |
| 2188 | |
| 2189 | /* Session exists */ |
| 2190 | if (PREDICT_TRUE (0 != sctp_conn)) |
| 2191 | { |
| 2192 | /* Save connection index */ |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 2193 | vnet_buffer (b0)->sctp.connection_index = trans_conn->c_index; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2194 | vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0; |
| 2195 | vnet_buffer (b0)->sctp.data_len = n_data_bytes0; |
| 2196 | |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 2197 | next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next; |
| 2198 | error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2199 | |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 2200 | SCTP_DBG_STATE_MACHINE |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 2201 | ("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] | 2202 | "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s", |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 2203 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX]. |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 2204 | connection.s_index, |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 2205 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX]. |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 2206 | connection.c_index, trans_conn, sctp_conn, |
| 2207 | sctp_state_to_string (sctp_conn->state), |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 2208 | sctp_chunk_to_string (chunk_type), phase_to_string (next0)); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2209 | |
Marco Varlese | fae4039 | 2018-02-14 15:38:35 +0100 | [diff] [blame] | 2210 | if (chunk_type == DATA) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2211 | SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u", |
| 2212 | n_advance_bytes0, n_data_bytes0); |
| 2213 | |
| 2214 | } |
| 2215 | else |
| 2216 | { |
| 2217 | if (is_filtered) |
| 2218 | { |
| 2219 | next0 = SCTP_INPUT_NEXT_DROP; |
| 2220 | error0 = SCTP_ERROR_FILTERED; |
| 2221 | } |
| 2222 | else if ((is_ip4 && tm->punt_unknown4) || |
| 2223 | (!is_ip4 && tm->punt_unknown6)) |
| 2224 | { |
| 2225 | next0 = SCTP_INPUT_NEXT_PUNT_PHASE; |
| 2226 | error0 = SCTP_ERROR_PUNT; |
| 2227 | } |
| 2228 | else |
| 2229 | { |
| 2230 | next0 = SCTP_INPUT_NEXT_DROP; |
| 2231 | error0 = SCTP_ERROR_NO_LISTENER; |
| 2232 | } |
| 2233 | SCTP_DBG_STATE_MACHINE ("sctp_conn == NULL, NEXT_PHASE = %s", |
| 2234 | phase_to_string (next0)); |
| 2235 | sctp_conn = 0; |
| 2236 | } |
| 2237 | |
| 2238 | done: |
| 2239 | b0->error = error0 ? node->errors[error0] : 0; |
| 2240 | |
| 2241 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 2242 | { |
| 2243 | sctp_rx_trace_t *t0 = |
| 2244 | vlib_add_trace (vm, node, b0, sizeof (*t0)); |
| 2245 | sctp_set_rx_trace_data (t0, sctp_conn, sctp_hdr, b0, is_ip4); |
| 2246 | } |
| 2247 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 2248 | n_left_to_next, bi0, next0); |
| 2249 | } |
| 2250 | |
| 2251 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 2252 | } |
| 2253 | return from_frame->n_vectors; |
| 2254 | } |
| 2255 | |
| 2256 | static uword |
| 2257 | sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 2258 | vlib_frame_t * from_frame) |
| 2259 | { |
| 2260 | return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ ); |
| 2261 | } |
| 2262 | |
| 2263 | static uword |
| 2264 | sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 2265 | vlib_frame_t * from_frame) |
| 2266 | { |
| 2267 | return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ ); |
| 2268 | } |
| 2269 | |
| 2270 | /* *INDENT-OFF* */ |
| 2271 | VLIB_REGISTER_NODE (sctp4_input_node) = |
| 2272 | { |
| 2273 | .function = sctp4_input_dispatcher, |
| 2274 | .name = "sctp4-input", |
| 2275 | /* Takes a vector of packets. */ |
| 2276 | .vector_size = sizeof (u32), |
| 2277 | .n_errors = SCTP_N_ERROR, |
| 2278 | .error_strings = sctp_error_strings, |
| 2279 | .n_next_nodes = SCTP_INPUT_N_NEXT, |
| 2280 | .next_nodes = |
| 2281 | { |
| 2282 | #define _(s,n) [SCTP_INPUT_NEXT_##s] = n, |
| 2283 | foreach_sctp4_input_next |
| 2284 | #undef _ |
| 2285 | }, |
| 2286 | .format_buffer = format_sctp_header, |
| 2287 | .format_trace = format_sctp_rx_trace, |
| 2288 | }; |
| 2289 | /* *INDENT-ON* */ |
| 2290 | |
| 2291 | VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher); |
| 2292 | |
| 2293 | /* *INDENT-OFF* */ |
| 2294 | VLIB_REGISTER_NODE (sctp6_input_node) = |
| 2295 | { |
| 2296 | .function = sctp6_input_dispatcher, |
| 2297 | .name = "sctp6-input", |
| 2298 | /* Takes a vector of packets. */ |
| 2299 | .vector_size = sizeof (u32), |
| 2300 | .n_errors = SCTP_N_ERROR, |
| 2301 | .error_strings = sctp_error_strings, |
| 2302 | .n_next_nodes = SCTP_INPUT_N_NEXT, |
| 2303 | .next_nodes = |
| 2304 | { |
| 2305 | #define _(s,n) [SCTP_INPUT_NEXT_##s] = n, |
| 2306 | foreach_sctp6_input_next |
| 2307 | #undef _ |
| 2308 | }, |
| 2309 | .format_buffer = format_sctp_header, |
| 2310 | .format_trace = format_sctp_rx_trace, |
| 2311 | }; |
| 2312 | /* *INDENT-ON* */ |
| 2313 | |
| 2314 | VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher); |
| 2315 | |
| 2316 | vlib_node_registration_t sctp4_input_node; |
| 2317 | vlib_node_registration_t sctp6_input_node; |
| 2318 | |
| 2319 | static void |
| 2320 | sctp_dispatch_table_init (sctp_main_t * tm) |
| 2321 | { |
| 2322 | int i, j; |
| 2323 | for (i = 0; i < ARRAY_LEN (tm->dispatch_table); i++) |
| 2324 | for (j = 0; j < ARRAY_LEN (tm->dispatch_table[i]); j++) |
| 2325 | { |
| 2326 | tm->dispatch_table[i][j].next = SCTP_INPUT_NEXT_DROP; |
| 2327 | tm->dispatch_table[i][j].error = SCTP_ERROR_DISPATCH; |
| 2328 | } |
| 2329 | |
| 2330 | #define _(t,f,n,e) \ |
| 2331 | do { \ |
| 2332 | tm->dispatch_table[SCTP_STATE_##t][f].next = (n); \ |
| 2333 | tm->dispatch_table[SCTP_STATE_##t][f].error = (e); \ |
| 2334 | } while (0) |
| 2335 | |
| 2336 | /* |
| 2337 | * SCTP STATE-MACHINE states: |
| 2338 | * |
| 2339 | * _(CLOSED, "CLOSED") \ |
| 2340 | * _(COOKIE_WAIT, "COOKIE_WAIT") \ |
| 2341 | * _(COOKIE_ECHOED, "COOKIE_ECHOED") \ |
| 2342 | * _(ESTABLISHED, "ESTABLISHED") \ |
| 2343 | * _(SHUTDOWN_PENDING, "SHUTDOWN_PENDING") \ |
| 2344 | * _(SHUTDOWN_SENT, "SHUTDOWN_SENT") \ |
| 2345 | * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED") \ |
| 2346 | * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT") |
| 2347 | */ |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 2348 | //_(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] | 2349 | _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); |
| 2350 | _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2351 | _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */ |
| 2352 | _(CLOSED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */ |
| 2353 | _(CLOSED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */ |
| 2354 | _(CLOSED, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); |
| 2355 | _(CLOSED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */ |
| 2356 | _(CLOSED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */ |
| 2357 | _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */ |
| 2358 | _(CLOSED, COOKIE_ECHO, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE); |
| 2359 | _(CLOSED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2360 | _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2361 | _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2362 | _(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] | 2363 | _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2364 | |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 2365 | _(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] | 2366 | _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */ |
| 2367 | _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); |
| 2368 | _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */ |
| 2369 | _(COOKIE_WAIT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */ |
| 2370 | _(COOKIE_WAIT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */ |
| 2371 | _(COOKIE_WAIT, ABORT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); |
| 2372 | _(COOKIE_WAIT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */ |
| 2373 | _(COOKIE_WAIT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */ |
| 2374 | _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */ |
| 2375 | _(COOKIE_WAIT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */ |
| 2376 | _(COOKIE_WAIT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2377 | _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2378 | _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2379 | _(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] | 2380 | _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2381 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2382 | |
| 2383 | _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); |
| 2384 | _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE); /* UNEXPECTED INIT chunk which requires special handling */ |
| 2385 | _(COOKIE_ECHOED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2386 | _(COOKIE_ECHOED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */ |
| 2387 | _(COOKIE_ECHOED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */ |
| 2388 | _(COOKIE_ECHOED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */ |
| 2389 | _(COOKIE_ECHOED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */ |
| 2390 | _(COOKIE_ECHOED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */ |
| 2391 | _(COOKIE_ECHOED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */ |
| 2392 | _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */ |
| 2393 | _(COOKIE_ECHOED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */ |
| 2394 | _(COOKIE_ECHOED, COOKIE_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, |
| 2395 | SCTP_ERROR_NONE); |
| 2396 | _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2397 | _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2398 | _(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] | 2399 | _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2400 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2401 | |
| 2402 | _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE); |
| 2403 | _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */ |
| 2404 | _(ESTABLISHED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2405 | _(ESTABLISHED, SACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE); |
| 2406 | _(ESTABLISHED, HEARTBEAT, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, |
| 2407 | SCTP_ERROR_NONE); |
| 2408 | _(ESTABLISHED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, |
| 2409 | SCTP_ERROR_NONE); |
| 2410 | _(ESTABLISHED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */ |
| 2411 | _(ESTABLISHED, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE); |
| 2412 | _(ESTABLISHED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */ |
| 2413 | _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION); /* UNEXPECTED OPERATION_ERROR chunk */ |
| 2414 | _(ESTABLISHED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION); /* UNEXPECTED COOKIE_ECHO chunk */ |
| 2415 | _(ESTABLISHED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2416 | _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2417 | _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2418 | _(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] | 2419 | _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2420 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2421 | |
| 2422 | _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE); |
| 2423 | _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */ |
| 2424 | _(SHUTDOWN_PENDING, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2425 | _(SHUTDOWN_PENDING, SACK, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE); |
| 2426 | _(SHUTDOWN_PENDING, HEARTBEAT, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2427 | SCTP_ERROR_NONE); |
| 2428 | _(SHUTDOWN_PENDING, HEARTBEAT_ACK, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2429 | SCTP_ERROR_NONE); |
| 2430 | _(SHUTDOWN_PENDING, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */ |
| 2431 | _(SHUTDOWN_PENDING, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2432 | SCTP_ERROR_NONE); |
| 2433 | _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN_ACK chunk */ |
| 2434 | _(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] | 2435 | _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2436 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2437 | _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2438 | _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2439 | _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2440 | _(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] | 2441 | _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2442 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2443 | |
| 2444 | _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE); |
| 2445 | _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */ |
| 2446 | _(SHUTDOWN_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2447 | _(SHUTDOWN_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */ |
| 2448 | _(SHUTDOWN_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */ |
| 2449 | _(SHUTDOWN_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */ |
| 2450 | _(SHUTDOWN_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */ |
| 2451 | _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE); |
| 2452 | _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2453 | SCTP_ERROR_NONE); |
Marco Varlese | 8c5f67f | 2018-02-27 09:38:31 +0100 | [diff] [blame] | 2454 | _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2455 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2456 | _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2457 | _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2458 | _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2459 | _(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] | 2460 | _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2461 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2462 | |
| 2463 | _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION); /* UNEXPECTED DATA chunk */ |
| 2464 | _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */ |
| 2465 | _(SHUTDOWN_RECEIVED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2466 | _(SHUTDOWN_RECEIVED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */ |
| 2467 | _(SHUTDOWN_RECEIVED, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */ |
| 2468 | _(SHUTDOWN_RECEIVED, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */ |
| 2469 | _(SHUTDOWN_RECEIVED, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */ |
| 2470 | _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */ |
| 2471 | _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2472 | SCTP_ERROR_NONE); |
Marco Varlese | 8c5f67f | 2018-02-27 09:38:31 +0100 | [diff] [blame] | 2473 | _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2474 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2475 | _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2476 | _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2477 | _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2478 | _(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] | 2479 | _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2480 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2481 | |
| 2482 | _(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] | 2483 | _(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] | 2484 | _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED INIT_ACK chunk */ |
| 2485 | _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */ |
| 2486 | _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */ |
| 2487 | _(SHUTDOWN_ACK_SENT, HEARTBEAT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_ACK_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT_ACK chunk */ |
| 2488 | _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */ |
| 2489 | _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION); /* UNEXPECTED SHUTDOWN chunk */ |
| 2490 | _(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] | 2491 | _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2492 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2493 | _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP); /* UNEXPECTED COOKIE_ACK chunk */ |
| 2494 | _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */ |
| 2495 | _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */ |
| 2496 | _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, |
| 2497 | SCTP_ERROR_NONE); |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 2498 | _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, |
| 2499 | SCTP_ERROR_NONE); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 2500 | |
| 2501 | /* TODO: Handle COOKIE ECHO when a TCB Exists */ |
| 2502 | |
| 2503 | #undef _ |
| 2504 | } |
| 2505 | |
| 2506 | clib_error_t * |
| 2507 | sctp_input_init (vlib_main_t * vm) |
| 2508 | { |
| 2509 | clib_error_t *error = 0; |
| 2510 | sctp_main_t *tm = vnet_get_sctp_main (); |
| 2511 | |
| 2512 | if ((error = vlib_call_init_function (vm, sctp_init))) |
| 2513 | return error; |
| 2514 | |
| 2515 | /* Initialize dispatch table. */ |
| 2516 | sctp_dispatch_table_init (tm); |
| 2517 | |
| 2518 | return error; |
| 2519 | } |
| 2520 | |
| 2521 | VLIB_INIT_FUNCTION (sctp_input_init); |
| 2522 | |
| 2523 | /* |
| 2524 | * fd.io coding-style-patch-verification: ON |
| 2525 | * |
| 2526 | * Local Variables: |
| 2527 | * eval: (c-set-style "gnu") |
| 2528 | * End: |
| 2529 | */ |