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