Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 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 | |
| 16 | /** |
| 17 | * @file |
| 18 | * @brief IPv6 Shallow Virtual Reassembly. |
| 19 | * |
| 20 | * This file contains the source code for IPv6 Shallow Virtual reassembly. |
| 21 | */ |
| 22 | |
| 23 | #include <vppinfra/vec.h> |
| 24 | #include <vnet/vnet.h> |
| 25 | #include <vnet/ip/ip.h> |
| 26 | #include <vnet/ip/ip6_to_ip4.h> |
| 27 | #include <vppinfra/bihash_48_8.h> |
| 28 | #include <vnet/ip/reass/ip6_sv_reass.h> |
| 29 | |
| 30 | #define MSEC_PER_SEC 1000 |
| 31 | #define IP6_SV_REASS_TIMEOUT_DEFAULT_MS 100 |
| 32 | #define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default |
| 33 | #define IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT 1024 |
| 34 | #define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3 |
| 35 | #define IP6_SV_REASS_HT_LOAD_FACTOR (0.75) |
| 36 | |
| 37 | typedef enum |
| 38 | { |
| 39 | IP6_SV_REASS_RC_OK, |
| 40 | IP6_SV_REASS_RC_TOO_MANY_FRAGMENTS, |
| 41 | IP6_SV_REASS_RC_INTERNAL_ERROR, |
| 42 | IP6_SV_REASS_RC_UNSUPP_IP_PROTO, |
| 43 | } ip6_sv_reass_rc_t; |
| 44 | |
| 45 | typedef struct |
| 46 | { |
| 47 | union |
| 48 | { |
| 49 | struct |
| 50 | { |
| 51 | ip6_address_t src; |
| 52 | ip6_address_t dst; |
| 53 | u32 xx_id; |
| 54 | u32 frag_id; |
| 55 | u8 unused[7]; |
| 56 | u8 proto; |
| 57 | }; |
| 58 | u64 as_u64[6]; |
| 59 | }; |
| 60 | } ip6_sv_reass_key_t; |
| 61 | |
| 62 | typedef union |
| 63 | { |
| 64 | struct |
| 65 | { |
| 66 | u32 reass_index; |
| 67 | u32 thread_index; |
| 68 | }; |
| 69 | u64 as_u64; |
| 70 | } ip6_sv_reass_val_t; |
| 71 | |
| 72 | typedef union |
| 73 | { |
| 74 | struct |
| 75 | { |
| 76 | ip6_sv_reass_key_t k; |
| 77 | ip6_sv_reass_val_t v; |
| 78 | }; |
| 79 | clib_bihash_kv_48_8_t kv; |
| 80 | } ip6_sv_reass_kv_t; |
| 81 | |
| 82 | typedef struct |
| 83 | { |
| 84 | // hash table key |
| 85 | ip6_sv_reass_key_t key; |
| 86 | // time when last packet was received |
| 87 | f64 last_heard; |
| 88 | // internal id of this reassembly |
| 89 | u64 id; |
| 90 | // trace operation counter |
| 91 | u32 trace_op_counter; |
| 92 | // buffer indexes of buffers in this reassembly in chronological order - |
| 93 | // including overlaps and duplicate fragments |
| 94 | u32 *cached_buffers; |
| 95 | // set to true when this reassembly is completed |
| 96 | bool is_complete; |
| 97 | // ip protocol |
| 98 | u8 ip_proto; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 99 | u8 icmp_type_or_tcp_flags; |
| 100 | u32 tcp_ack_number; |
| 101 | u32 tcp_seq_number; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 102 | // l4 src port |
| 103 | u16 l4_src_port; |
| 104 | // l4 dst port |
| 105 | u16 l4_dst_port; |
| 106 | // lru indexes |
| 107 | u32 lru_prev; |
| 108 | u32 lru_next; |
| 109 | } ip6_sv_reass_t; |
| 110 | |
| 111 | typedef struct |
| 112 | { |
| 113 | ip6_sv_reass_t *pool; |
| 114 | u32 reass_n; |
| 115 | u32 id_counter; |
| 116 | clib_spinlock_t lock; |
| 117 | // lru indexes |
| 118 | u32 lru_first; |
| 119 | u32 lru_last; |
| 120 | } ip6_sv_reass_per_thread_t; |
| 121 | |
| 122 | typedef struct |
| 123 | { |
| 124 | // IPv6 config |
| 125 | u32 timeout_ms; |
| 126 | f64 timeout; |
| 127 | u32 expire_walk_interval_ms; |
| 128 | // maximum number of fragments in one reassembly |
| 129 | u32 max_reass_len; |
| 130 | // maximum number of reassemblies |
| 131 | u32 max_reass_n; |
| 132 | |
| 133 | // IPv6 runtime |
| 134 | clib_bihash_48_8_t hash; |
| 135 | |
| 136 | // per-thread data |
| 137 | ip6_sv_reass_per_thread_t *per_thread_data; |
| 138 | |
| 139 | // convenience |
| 140 | vlib_main_t *vlib_main; |
| 141 | vnet_main_t *vnet_main; |
| 142 | |
| 143 | // node index of ip6-drop node |
| 144 | u32 ip6_drop_idx; |
| 145 | u32 ip6_icmp_error_idx; |
| 146 | u32 ip6_sv_reass_expire_node_idx; |
| 147 | |
| 148 | /** Worker handoff */ |
| 149 | u32 fq_index; |
| 150 | u32 fq_feature_index; |
| 151 | |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 152 | // reference count for enabling/disabling feature - per interface |
| 153 | u32 *feature_use_refcount_per_intf; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 154 | } ip6_sv_reass_main_t; |
| 155 | |
| 156 | extern ip6_sv_reass_main_t ip6_sv_reass_main; |
| 157 | |
| 158 | #ifndef CLIB_MARCH_VARIANT |
| 159 | ip6_sv_reass_main_t ip6_sv_reass_main; |
| 160 | #endif /* CLIB_MARCH_VARIANT */ |
| 161 | |
| 162 | typedef enum |
| 163 | { |
| 164 | IP6_SV_REASSEMBLY_NEXT_INPUT, |
| 165 | IP6_SV_REASSEMBLY_NEXT_DROP, |
| 166 | IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR, |
| 167 | IP6_SV_REASSEMBLY_NEXT_HANDOFF, |
| 168 | IP6_SV_REASSEMBLY_N_NEXT, |
| 169 | } ip6_sv_reass_next_t; |
| 170 | |
| 171 | typedef enum |
| 172 | { |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 173 | REASS_FRAGMENT_CACHE, |
| 174 | REASS_FINISH, |
| 175 | REASS_FRAGMENT_FORWARD, |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 176 | REASS_PASSTHROUGH, |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 177 | } ip6_sv_reass_trace_operation_e; |
| 178 | |
| 179 | typedef struct |
| 180 | { |
| 181 | ip6_sv_reass_trace_operation_e action; |
| 182 | u32 reass_id; |
| 183 | u32 op_id; |
| 184 | u8 ip_proto; |
| 185 | u16 l4_src_port; |
| 186 | u16 l4_dst_port; |
| 187 | } ip6_sv_reass_trace_t; |
| 188 | |
| 189 | static u8 * |
| 190 | format_ip6_sv_reass_trace (u8 * s, va_list * args) |
| 191 | { |
| 192 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 193 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 194 | ip6_sv_reass_trace_t *t = va_arg (*args, ip6_sv_reass_trace_t *); |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 195 | if (REASS_PASSTHROUGH != t->action) |
| 196 | { |
| 197 | s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id); |
| 198 | } |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 199 | switch (t->action) |
| 200 | { |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 201 | case REASS_FRAGMENT_CACHE: |
| 202 | s = format (s, "[cached]"); |
| 203 | break; |
| 204 | case REASS_FINISH: |
| 205 | s = |
| 206 | format (s, "[finish, ip proto=%u, src_port=%u, dst_port=%u]", |
| 207 | t->ip_proto, clib_net_to_host_u16 (t->l4_src_port), |
| 208 | clib_net_to_host_u16 (t->l4_dst_port)); |
| 209 | break; |
| 210 | case REASS_FRAGMENT_FORWARD: |
| 211 | s = |
| 212 | format (s, "[forward, ip proto=%u, src_port=%u, dst_port=%u]", |
| 213 | t->ip_proto, clib_net_to_host_u16 (t->l4_src_port), |
| 214 | clib_net_to_host_u16 (t->l4_dst_port)); |
| 215 | break; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 216 | case REASS_PASSTHROUGH: |
| 217 | s = format (s, "[not-fragmented]"); |
| 218 | break; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 219 | } |
| 220 | return s; |
| 221 | } |
| 222 | |
| 223 | static void |
| 224 | ip6_sv_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 225 | ip6_sv_reass_main_t * rm, |
| 226 | ip6_sv_reass_t * reass, u32 bi, |
| 227 | ip6_sv_reass_trace_operation_e action, |
| 228 | u32 ip_proto, u16 l4_src_port, u16 l4_dst_port) |
| 229 | { |
| 230 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 231 | ip6_sv_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0])); |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 232 | if (reass) |
| 233 | { |
| 234 | t->reass_id = reass->id; |
| 235 | t->op_id = reass->trace_op_counter; |
| 236 | ++reass->trace_op_counter; |
| 237 | } |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 238 | t->action = action; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 239 | t->ip_proto = ip_proto; |
| 240 | t->l4_src_port = l4_src_port; |
| 241 | t->l4_dst_port = l4_dst_port; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 242 | #if 0 |
| 243 | static u8 *s = NULL; |
| 244 | s = format (s, "%U", format_ip6_sv_reass_trace, NULL, NULL, t); |
| 245 | printf ("%.*s\n", vec_len (s), s); |
| 246 | fflush (stdout); |
| 247 | vec_reset_length (s); |
| 248 | #endif |
| 249 | } |
| 250 | |
| 251 | always_inline void |
| 252 | ip6_sv_reass_free (vlib_main_t * vm, ip6_sv_reass_main_t * rm, |
| 253 | ip6_sv_reass_per_thread_t * rt, ip6_sv_reass_t * reass) |
| 254 | { |
| 255 | clib_bihash_kv_48_8_t kv; |
| 256 | kv.key[0] = reass->key.as_u64[0]; |
| 257 | kv.key[1] = reass->key.as_u64[1]; |
| 258 | kv.key[2] = reass->key.as_u64[2]; |
| 259 | kv.key[3] = reass->key.as_u64[3]; |
| 260 | kv.key[4] = reass->key.as_u64[4]; |
| 261 | kv.key[5] = reass->key.as_u64[5]; |
| 262 | clib_bihash_add_del_48_8 (&rm->hash, &kv, 0); |
| 263 | vlib_buffer_free (vm, reass->cached_buffers, |
| 264 | vec_len (reass->cached_buffers)); |
| 265 | vec_free (reass->cached_buffers); |
| 266 | reass->cached_buffers = NULL; |
| 267 | if (~0 != reass->lru_prev) |
| 268 | { |
| 269 | ip6_sv_reass_t *lru_prev = |
| 270 | pool_elt_at_index (rt->pool, reass->lru_prev); |
| 271 | lru_prev->lru_next = reass->lru_next; |
| 272 | } |
| 273 | if (~0 != reass->lru_next) |
| 274 | { |
| 275 | ip6_sv_reass_t *lru_next = |
| 276 | pool_elt_at_index (rt->pool, reass->lru_next); |
| 277 | lru_next->lru_prev = reass->lru_prev; |
| 278 | } |
| 279 | if (rt->lru_first == reass - rt->pool) |
| 280 | { |
| 281 | rt->lru_first = reass->lru_next; |
| 282 | } |
| 283 | if (rt->lru_last == reass - rt->pool) |
| 284 | { |
| 285 | rt->lru_last = reass->lru_prev; |
| 286 | } |
| 287 | pool_put (rt->pool, reass); |
| 288 | --rt->reass_n; |
| 289 | } |
| 290 | |
| 291 | always_inline void |
| 292 | ip6_sv_reass_init (ip6_sv_reass_t * reass) |
| 293 | { |
| 294 | reass->cached_buffers = NULL; |
| 295 | reass->is_complete = false; |
| 296 | } |
| 297 | |
| 298 | always_inline ip6_sv_reass_t * |
| 299 | ip6_sv_reass_find_or_create (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 300 | ip6_sv_reass_main_t * rm, |
| 301 | ip6_sv_reass_per_thread_t * rt, |
| 302 | ip6_sv_reass_kv_t * kv, u32 * icmp_bi, |
| 303 | u8 * do_handoff) |
| 304 | { |
| 305 | ip6_sv_reass_t *reass = NULL; |
Tom Seidenberg | 5a7f2f1 | 2020-04-28 17:58:12 -0400 | [diff] [blame] | 306 | f64 now = vlib_time_now (vm); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 307 | |
Klement Sekera | c99c025 | 2019-12-18 12:17:06 +0000 | [diff] [blame] | 308 | if (!clib_bihash_search_48_8 (&rm->hash, &kv->kv, &kv->kv)) |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 309 | { |
| 310 | if (vm->thread_index != kv->v.thread_index) |
| 311 | { |
| 312 | *do_handoff = 1; |
| 313 | return NULL; |
| 314 | } |
| 315 | reass = pool_elt_at_index (rt->pool, kv->v.reass_index); |
| 316 | |
| 317 | if (now > reass->last_heard + rm->timeout) |
| 318 | { |
| 319 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 320 | reass = NULL; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | if (reass) |
| 325 | { |
| 326 | reass->last_heard = now; |
| 327 | return reass; |
| 328 | } |
| 329 | |
| 330 | if (rt->reass_n >= rm->max_reass_n) |
| 331 | { |
zhengdelun | ce53363 | 2020-05-22 15:42:28 +0800 | [diff] [blame] | 332 | reass = pool_elt_at_index (rt->pool, rt->lru_first); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 333 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 334 | } |
| 335 | |
| 336 | pool_get (rt->pool, reass); |
| 337 | clib_memset (reass, 0, sizeof (*reass)); |
| 338 | reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter; |
| 339 | ++rt->id_counter; |
| 340 | ip6_sv_reass_init (reass); |
| 341 | ++rt->reass_n; |
| 342 | |
| 343 | reass->lru_prev = reass->lru_next = ~0; |
| 344 | |
| 345 | if (~0 != rt->lru_last) |
| 346 | { |
| 347 | ip6_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last); |
| 348 | reass->lru_prev = rt->lru_last; |
| 349 | lru_last->lru_next = rt->lru_last = reass - rt->pool; |
| 350 | } |
| 351 | |
| 352 | if (~0 == rt->lru_first) |
| 353 | { |
| 354 | rt->lru_first = rt->lru_last = reass - rt->pool; |
| 355 | } |
| 356 | |
Klement Sekera | c99c025 | 2019-12-18 12:17:06 +0000 | [diff] [blame] | 357 | reass->key.as_u64[0] = kv->kv.key[0]; |
| 358 | reass->key.as_u64[1] = kv->kv.key[1]; |
| 359 | reass->key.as_u64[2] = kv->kv.key[2]; |
| 360 | reass->key.as_u64[3] = kv->kv.key[3]; |
| 361 | reass->key.as_u64[4] = kv->kv.key[4]; |
| 362 | reass->key.as_u64[5] = kv->kv.key[5]; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 363 | kv->v.reass_index = (reass - rt->pool); |
| 364 | kv->v.thread_index = vm->thread_index; |
| 365 | reass->last_heard = now; |
| 366 | |
Klement Sekera | c99c025 | 2019-12-18 12:17:06 +0000 | [diff] [blame] | 367 | if (clib_bihash_add_del_48_8 (&rm->hash, &kv->kv, 1)) |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 368 | { |
| 369 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 370 | reass = NULL; |
| 371 | } |
| 372 | |
| 373 | return reass; |
| 374 | } |
| 375 | |
| 376 | always_inline ip6_sv_reass_rc_t |
| 377 | ip6_sv_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 378 | ip6_sv_reass_main_t * rm, ip6_sv_reass_per_thread_t * rt, |
| 379 | ip6_sv_reass_t * reass, u32 bi0, |
| 380 | ip6_frag_hdr_t * frag_hdr) |
| 381 | { |
| 382 | vlib_buffer_t *fb = vlib_get_buffer (vm, bi0); |
| 383 | vnet_buffer_opaque_t *fvnb = vnet_buffer (fb); |
| 384 | fvnb->ip.reass.ip6_frag_hdr_offset = |
| 385 | (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb); |
| 386 | ip6_header_t *fip = vlib_buffer_get_current (fb); |
| 387 | if (fb->current_length < sizeof (*fip) || |
| 388 | fvnb->ip.reass.ip6_frag_hdr_offset == 0 || |
| 389 | fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length) |
| 390 | { |
| 391 | return IP6_SV_REASS_RC_INTERNAL_ERROR; |
| 392 | } |
| 393 | |
| 394 | u32 fragment_first = fvnb->ip.reass.fragment_first = |
| 395 | ip6_frag_hdr_offset_bytes (frag_hdr); |
| 396 | u32 fragment_length = |
| 397 | vlib_buffer_length_in_chain (vm, fb) - |
| 398 | (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr)); |
| 399 | u32 fragment_last = fvnb->ip.reass.fragment_last = |
| 400 | fragment_first + fragment_length - 1; |
| 401 | fvnb->ip.reass.range_first = fragment_first; |
| 402 | fvnb->ip.reass.range_last = fragment_last; |
| 403 | fvnb->ip.reass.next_range_bi = ~0; |
| 404 | if (0 == fragment_first) |
| 405 | { |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 406 | if (!ip6_get_port |
| 407 | (vm, fb, fip, fb->current_length, &reass->ip_proto, |
| 408 | &reass->l4_src_port, &reass->l4_dst_port, |
| 409 | &reass->icmp_type_or_tcp_flags, &reass->tcp_ack_number, |
| 410 | &reass->tcp_seq_number)) |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 411 | return IP6_SV_REASS_RC_UNSUPP_IP_PROTO; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 412 | |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 413 | reass->is_complete = true; |
| 414 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
| 415 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 416 | { |
| 417 | ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, REASS_FINISH, |
| 418 | reass->ip_proto, reass->l4_src_port, |
| 419 | reass->l4_dst_port); |
| 420 | } |
| 421 | } |
| 422 | vec_add1 (reass->cached_buffers, bi0); |
| 423 | if (!reass->is_complete) |
| 424 | { |
| 425 | if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED)) |
| 426 | { |
| 427 | ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, |
| 428 | REASS_FRAGMENT_CACHE, reass->ip_proto, |
| 429 | reass->l4_src_port, reass->l4_dst_port); |
| 430 | } |
| 431 | if (vec_len (reass->cached_buffers) > rm->max_reass_len) |
| 432 | { |
| 433 | return IP6_SV_REASS_RC_TOO_MANY_FRAGMENTS; |
| 434 | } |
| 435 | } |
| 436 | return IP6_SV_REASS_RC_OK; |
| 437 | } |
| 438 | |
| 439 | always_inline bool |
| 440 | ip6_sv_reass_verify_upper_layer_present (vlib_node_runtime_t * node, |
| 441 | vlib_buffer_t * b, |
| 442 | ip6_frag_hdr_t * frag_hdr) |
| 443 | { |
| 444 | ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr; |
| 445 | while (ip6_ext_hdr (tmp->next_hdr)) |
| 446 | { |
| 447 | tmp = ip6_ext_next_header (tmp); |
| 448 | } |
| 449 | if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr) |
| 450 | { |
| 451 | icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem, |
| 452 | ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain, |
| 453 | 0); |
| 454 | b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER]; |
| 455 | |
| 456 | return false; |
| 457 | } |
| 458 | return true; |
| 459 | } |
| 460 | |
| 461 | always_inline bool |
| 462 | ip6_sv_reass_verify_fragment_multiple_8 (vlib_main_t * vm, |
| 463 | vlib_node_runtime_t * node, |
| 464 | vlib_buffer_t * b, |
| 465 | ip6_frag_hdr_t * frag_hdr) |
| 466 | { |
| 467 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
| 468 | ip6_header_t *ip = vlib_buffer_get_current (b); |
| 469 | int more_fragments = ip6_frag_hdr_more (frag_hdr); |
| 470 | u32 fragment_length = |
| 471 | vlib_buffer_length_in_chain (vm, b) - |
| 472 | (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr)); |
| 473 | if (more_fragments && 0 != fragment_length % 8) |
| 474 | { |
| 475 | icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem, |
| 476 | ICMP6_parameter_problem_erroneous_header_field, |
| 477 | (u8 *) & ip->payload_length - (u8 *) ip); |
| 478 | return false; |
| 479 | } |
| 480 | return true; |
| 481 | } |
| 482 | |
| 483 | always_inline bool |
| 484 | ip6_sv_reass_verify_packet_size_lt_64k (vlib_main_t * vm, |
| 485 | vlib_node_runtime_t * node, |
| 486 | vlib_buffer_t * b, |
| 487 | ip6_frag_hdr_t * frag_hdr) |
| 488 | { |
| 489 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
| 490 | u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr); |
| 491 | u32 fragment_length = |
| 492 | vlib_buffer_length_in_chain (vm, b) - |
| 493 | (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr)); |
| 494 | if (fragment_first + fragment_length > 65535) |
| 495 | { |
| 496 | ip6_header_t *ip0 = vlib_buffer_get_current (b); |
| 497 | icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem, |
| 498 | ICMP6_parameter_problem_erroneous_header_field, |
| 499 | (u8 *) & frag_hdr->fragment_offset_and_more |
| 500 | - (u8 *) ip0); |
| 501 | return false; |
| 502 | } |
| 503 | return true; |
| 504 | } |
| 505 | |
| 506 | always_inline uword |
| 507 | ip6_sv_reassembly_inline (vlib_main_t * vm, |
| 508 | vlib_node_runtime_t * node, |
| 509 | vlib_frame_t * frame, bool is_feature) |
| 510 | { |
| 511 | u32 *from = vlib_frame_vector_args (frame); |
| 512 | u32 n_left_from, n_left_to_next, *to_next, next_index; |
| 513 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
| 514 | ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[vm->thread_index]; |
| 515 | clib_spinlock_lock (&rt->lock); |
| 516 | |
| 517 | n_left_from = frame->n_vectors; |
| 518 | next_index = node->cached_next_index; |
| 519 | |
| 520 | while (n_left_from > 0) |
| 521 | { |
| 522 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 523 | |
| 524 | while (n_left_from > 0 && n_left_to_next > 0) |
| 525 | { |
| 526 | u32 bi0; |
| 527 | vlib_buffer_t *b0; |
| 528 | u32 next0 = IP6_SV_REASSEMBLY_NEXT_DROP; |
| 529 | u32 error0 = IP6_ERROR_NONE; |
| 530 | u32 icmp_bi = ~0; |
| 531 | |
| 532 | bi0 = from[0]; |
| 533 | b0 = vlib_get_buffer (vm, bi0); |
| 534 | |
| 535 | ip6_header_t *ip0 = vlib_buffer_get_current (b0); |
| 536 | ip6_frag_hdr_t *frag_hdr = NULL; |
| 537 | ip6_ext_header_t *prev_hdr; |
| 538 | if (ip6_ext_hdr (ip0->protocol)) |
| 539 | { |
| 540 | frag_hdr = |
| 541 | ip6_ext_header_find (vm, b0, ip0, |
| 542 | IP_PROTOCOL_IPV6_FRAGMENTATION, |
| 543 | &prev_hdr); |
| 544 | } |
| 545 | if (!frag_hdr) |
| 546 | { |
| 547 | // this is a regular packet - no fragmentation |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 548 | if (!ip6_get_port |
| 549 | (vm, b0, ip0, b0->current_length, |
| 550 | &(vnet_buffer (b0)->ip.reass.ip_proto), |
| 551 | &(vnet_buffer (b0)->ip.reass.l4_src_port), |
| 552 | &(vnet_buffer (b0)->ip.reass.l4_dst_port), |
| 553 | &(vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags), |
| 554 | &(vnet_buffer (b0)->ip.reass.tcp_ack_number), |
| 555 | &(vnet_buffer (b0)->ip.reass.tcp_seq_number))) |
| 556 | { |
| 557 | error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO; |
Klement Sekera | 1766ddc | 2020-03-30 16:59:38 +0200 | [diff] [blame] | 558 | b0->error = node->errors[error0]; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 559 | next0 = IP6_SV_REASSEMBLY_NEXT_DROP; |
| 560 | goto packet_enqueue; |
| 561 | } |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 562 | vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 563 | next0 = IP6_SV_REASSEMBLY_NEXT_INPUT; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 564 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 565 | { |
| 566 | ip6_sv_reass_add_trace (vm, node, rm, NULL, bi0, |
| 567 | REASS_PASSTHROUGH, |
| 568 | vnet_buffer (b0)->ip.reass.ip_proto, |
| 569 | vnet_buffer (b0)->ip. |
| 570 | reass.l4_src_port, |
| 571 | vnet_buffer (b0)->ip. |
| 572 | reass.l4_dst_port); |
| 573 | } |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 574 | goto packet_enqueue; |
| 575 | } |
Klement Sekera | 38f7ccb | 2019-10-28 11:26:28 +0000 | [diff] [blame] | 576 | vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset = |
| 577 | (u8 *) frag_hdr - (u8 *) ip0; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 578 | if (0 == ip6_frag_hdr_offset (frag_hdr)) |
| 579 | { |
| 580 | // first fragment - verify upper-layer is present |
| 581 | if (!ip6_sv_reass_verify_upper_layer_present |
| 582 | (node, b0, frag_hdr)) |
| 583 | { |
| 584 | next0 = IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR; |
| 585 | goto packet_enqueue; |
| 586 | } |
| 587 | } |
| 588 | if (!ip6_sv_reass_verify_fragment_multiple_8 |
| 589 | (vm, node, b0, frag_hdr) |
| 590 | || !ip6_sv_reass_verify_packet_size_lt_64k (vm, node, b0, |
| 591 | frag_hdr)) |
| 592 | { |
| 593 | next0 = IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR; |
| 594 | goto packet_enqueue; |
| 595 | } |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 596 | |
| 597 | ip6_sv_reass_kv_t kv; |
| 598 | u8 do_handoff = 0; |
| 599 | |
| 600 | kv.k.as_u64[0] = ip0->src_address.as_u64[0]; |
| 601 | kv.k.as_u64[1] = ip0->src_address.as_u64[1]; |
| 602 | kv.k.as_u64[2] = ip0->dst_address.as_u64[0]; |
| 603 | kv.k.as_u64[3] = ip0->dst_address.as_u64[1]; |
| 604 | kv.k.as_u64[4] = |
| 605 | ((u64) vec_elt (ip6_main.fib_index_by_sw_if_index, |
| 606 | vnet_buffer (b0)->sw_if_index[VLIB_RX])) << 32 | |
| 607 | (u64) frag_hdr->identification; |
| 608 | kv.k.as_u64[5] = ip0->protocol; |
| 609 | |
| 610 | ip6_sv_reass_t *reass = |
| 611 | ip6_sv_reass_find_or_create (vm, node, rm, rt, &kv, &icmp_bi, |
| 612 | &do_handoff); |
| 613 | |
| 614 | if (PREDICT_FALSE (do_handoff)) |
| 615 | { |
| 616 | next0 = IP6_SV_REASSEMBLY_NEXT_HANDOFF; |
| 617 | vnet_buffer (b0)->ip.reass.owner_thread_index = |
| 618 | kv.v.thread_index; |
Klement Sekera | 364b20a | 2019-10-07 09:48:06 +0000 | [diff] [blame] | 619 | goto packet_enqueue; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | if (!reass) |
| 623 | { |
| 624 | next0 = IP6_SV_REASSEMBLY_NEXT_DROP; |
| 625 | error0 = IP6_ERROR_REASS_LIMIT_REACHED; |
Klement Sekera | 1766ddc | 2020-03-30 16:59:38 +0200 | [diff] [blame] | 626 | b0->error = node->errors[error0]; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 627 | goto packet_enqueue; |
| 628 | } |
| 629 | |
| 630 | if (reass->is_complete) |
| 631 | { |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 632 | vnet_buffer (b0)->ip.reass.is_non_first_fragment = |
| 633 | ! !ip6_frag_hdr_offset (frag_hdr); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 634 | vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 635 | vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags = |
| 636 | reass->icmp_type_or_tcp_flags; |
| 637 | vnet_buffer (b0)->ip.reass.tcp_ack_number = |
| 638 | reass->tcp_ack_number; |
| 639 | vnet_buffer (b0)->ip.reass.tcp_seq_number = |
| 640 | reass->tcp_seq_number; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 641 | vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port; |
| 642 | vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port; |
| 643 | next0 = IP6_SV_REASSEMBLY_NEXT_INPUT; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 644 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 645 | { |
| 646 | ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, |
| 647 | REASS_FRAGMENT_FORWARD, |
| 648 | reass->ip_proto, |
| 649 | reass->l4_src_port, |
| 650 | reass->l4_dst_port); |
| 651 | } |
| 652 | goto packet_enqueue; |
| 653 | } |
| 654 | |
| 655 | switch (ip6_sv_reass_update |
| 656 | (vm, node, rm, rt, reass, bi0, frag_hdr)) |
| 657 | { |
| 658 | case IP6_SV_REASS_RC_OK: |
| 659 | /* nothing to do here */ |
| 660 | break; |
| 661 | case IP6_SV_REASS_RC_TOO_MANY_FRAGMENTS: |
| 662 | vlib_node_increment_counter (vm, node->node_index, |
| 663 | IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG, |
| 664 | 1); |
| 665 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 666 | goto next_packet; |
| 667 | break; |
| 668 | case IP6_SV_REASS_RC_UNSUPP_IP_PROTO: |
| 669 | vlib_node_increment_counter (vm, node->node_index, |
| 670 | IP6_ERROR_REASS_UNSUPP_IP_PROTO, |
| 671 | 1); |
| 672 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 673 | goto next_packet; |
| 674 | break; |
| 675 | case IP6_SV_REASS_RC_INTERNAL_ERROR: |
| 676 | vlib_node_increment_counter (vm, node->node_index, |
| 677 | IP6_ERROR_REASS_INTERNAL_ERROR, 1); |
| 678 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 679 | goto next_packet; |
| 680 | break; |
| 681 | } |
| 682 | |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 683 | if (reass->is_complete) |
| 684 | { |
| 685 | u32 idx; |
| 686 | vec_foreach_index (idx, reass->cached_buffers) |
| 687 | { |
| 688 | u32 bi0 = vec_elt (reass->cached_buffers, idx); |
| 689 | if (0 == n_left_to_next) |
| 690 | { |
| 691 | vlib_put_next_frame (vm, node, next_index, |
| 692 | n_left_to_next); |
| 693 | vlib_get_next_frame (vm, node, next_index, to_next, |
| 694 | n_left_to_next); |
| 695 | } |
| 696 | to_next[0] = bi0; |
| 697 | to_next += 1; |
| 698 | n_left_to_next -= 1; |
| 699 | b0 = vlib_get_buffer (vm, bi0); |
| 700 | if (is_feature) |
| 701 | { |
| 702 | vnet_feature_next (&next0, b0); |
| 703 | } |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 704 | frag_hdr = |
| 705 | vlib_buffer_get_current (b0) + |
| 706 | vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 707 | vnet_buffer (b0)->ip.reass.is_non_first_fragment = |
| 708 | ! !ip6_frag_hdr_offset (frag_hdr); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 709 | vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto; |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 710 | vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags = |
| 711 | reass->icmp_type_or_tcp_flags; |
| 712 | vnet_buffer (b0)->ip.reass.tcp_ack_number = |
| 713 | reass->tcp_ack_number; |
| 714 | vnet_buffer (b0)->ip.reass.tcp_seq_number = |
| 715 | reass->tcp_seq_number; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 716 | vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port; |
| 717 | vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port; |
| 718 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 719 | { |
| 720 | ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, |
| 721 | REASS_FRAGMENT_FORWARD, |
| 722 | reass->ip_proto, |
| 723 | reass->l4_src_port, |
| 724 | reass->l4_dst_port); |
| 725 | } |
| 726 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 727 | to_next, n_left_to_next, bi0, |
| 728 | next0); |
| 729 | } |
| 730 | _vec_len (reass->cached_buffers) = 0; // buffers are owned by frame now |
| 731 | } |
| 732 | goto next_packet; |
| 733 | |
| 734 | packet_enqueue: |
| 735 | to_next[0] = bi0; |
| 736 | to_next += 1; |
| 737 | n_left_to_next -= 1; |
| 738 | if (is_feature && IP6_ERROR_NONE == error0) |
| 739 | { |
| 740 | b0 = vlib_get_buffer (vm, bi0); |
| 741 | vnet_feature_next (&next0, b0); |
| 742 | } |
| 743 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 744 | n_left_to_next, bi0, next0); |
| 745 | |
| 746 | if (~0 != icmp_bi) |
| 747 | { |
| 748 | next0 = IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR; |
| 749 | to_next[0] = icmp_bi; |
| 750 | to_next += 1; |
| 751 | n_left_to_next -= 1; |
| 752 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 753 | n_left_to_next, icmp_bi, |
| 754 | next0); |
| 755 | } |
| 756 | |
| 757 | next_packet: |
| 758 | from += 1; |
| 759 | n_left_from -= 1; |
| 760 | } |
| 761 | |
| 762 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 763 | } |
| 764 | |
| 765 | clib_spinlock_unlock (&rt->lock); |
| 766 | return frame->n_vectors; |
| 767 | } |
| 768 | |
| 769 | static char *ip6_sv_reassembly_error_strings[] = { |
| 770 | #define _(sym, string) string, |
| 771 | foreach_ip6_error |
| 772 | #undef _ |
| 773 | }; |
| 774 | |
| 775 | VLIB_NODE_FN (ip6_sv_reass_node) (vlib_main_t * vm, |
| 776 | vlib_node_runtime_t * node, |
| 777 | vlib_frame_t * frame) |
| 778 | { |
| 779 | return ip6_sv_reassembly_inline (vm, node, frame, false /* is_feature */ ); |
| 780 | } |
| 781 | |
| 782 | /* *INDENT-OFF* */ |
| 783 | VLIB_REGISTER_NODE (ip6_sv_reass_node) = { |
| 784 | .name = "ip6-sv-reassembly", |
| 785 | .vector_size = sizeof (u32), |
| 786 | .format_trace = format_ip6_sv_reass_trace, |
| 787 | .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings), |
| 788 | .error_strings = ip6_sv_reassembly_error_strings, |
| 789 | .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT, |
| 790 | .next_nodes = |
| 791 | { |
| 792 | [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input", |
| 793 | [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop", |
| 794 | [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error", |
| 795 | [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reassembly-handoff", |
| 796 | }, |
| 797 | }; |
| 798 | /* *INDENT-ON* */ |
| 799 | |
| 800 | VLIB_NODE_FN (ip6_sv_reass_node_feature) (vlib_main_t * vm, |
| 801 | vlib_node_runtime_t * node, |
| 802 | vlib_frame_t * frame) |
| 803 | { |
| 804 | return ip6_sv_reassembly_inline (vm, node, frame, true /* is_feature */ ); |
| 805 | } |
| 806 | |
| 807 | /* *INDENT-OFF* */ |
| 808 | VLIB_REGISTER_NODE (ip6_sv_reass_node_feature) = { |
| 809 | .name = "ip6-sv-reassembly-feature", |
| 810 | .vector_size = sizeof (u32), |
| 811 | .format_trace = format_ip6_sv_reass_trace, |
| 812 | .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings), |
| 813 | .error_strings = ip6_sv_reassembly_error_strings, |
| 814 | .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT, |
| 815 | .next_nodes = |
| 816 | { |
| 817 | [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input", |
| 818 | [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop", |
| 819 | [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error", |
| 820 | [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reass-feature-hoff", |
| 821 | }, |
| 822 | }; |
| 823 | /* *INDENT-ON* */ |
| 824 | |
| 825 | /* *INDENT-OFF* */ |
| 826 | VNET_FEATURE_INIT (ip6_sv_reassembly_feature) = { |
| 827 | .arc_name = "ip6-unicast", |
| 828 | .node_name = "ip6-sv-reassembly-feature", |
| 829 | .runs_before = VNET_FEATURES ("ip6-lookup"), |
| 830 | .runs_after = 0, |
| 831 | }; |
| 832 | /* *INDENT-ON* */ |
| 833 | |
| 834 | #ifndef CLIB_MARCH_VARIANT |
| 835 | static u32 |
| 836 | ip6_sv_reass_get_nbuckets () |
| 837 | { |
| 838 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
| 839 | u32 nbuckets; |
| 840 | u8 i; |
| 841 | |
| 842 | nbuckets = (u32) (rm->max_reass_n / IP6_SV_REASS_HT_LOAD_FACTOR); |
| 843 | |
| 844 | for (i = 0; i < 31; i++) |
| 845 | if ((1 << i) >= nbuckets) |
| 846 | break; |
| 847 | nbuckets = 1 << i; |
| 848 | |
| 849 | return nbuckets; |
| 850 | } |
| 851 | #endif /* CLIB_MARCH_VARIANT */ |
| 852 | |
| 853 | typedef enum |
| 854 | { |
| 855 | IP6_EVENT_CONFIG_CHANGED = 1, |
| 856 | } ip6_sv_reass_event_t; |
| 857 | |
| 858 | #ifndef CLIB_MARCH_VARIANT |
| 859 | typedef struct |
| 860 | { |
| 861 | int failure; |
| 862 | clib_bihash_48_8_t *new_hash; |
| 863 | } ip6_rehash_cb_ctx; |
| 864 | |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 865 | static int |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 866 | ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx) |
| 867 | { |
| 868 | ip6_rehash_cb_ctx *ctx = _ctx; |
| 869 | if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1)) |
| 870 | { |
| 871 | ctx->failure = 1; |
| 872 | } |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 873 | return (BIHASH_WALK_CONTINUE); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | static void |
| 877 | ip6_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies, |
| 878 | u32 max_reassembly_length, |
| 879 | u32 expire_walk_interval_ms) |
| 880 | { |
| 881 | ip6_sv_reass_main.timeout_ms = timeout_ms; |
| 882 | ip6_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC; |
| 883 | ip6_sv_reass_main.max_reass_n = max_reassemblies; |
| 884 | ip6_sv_reass_main.max_reass_len = max_reassembly_length; |
| 885 | ip6_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms; |
| 886 | } |
| 887 | |
| 888 | vnet_api_error_t |
| 889 | ip6_sv_reass_set (u32 timeout_ms, u32 max_reassemblies, |
| 890 | u32 max_reassembly_length, u32 expire_walk_interval_ms) |
| 891 | { |
| 892 | u32 old_nbuckets = ip6_sv_reass_get_nbuckets (); |
| 893 | ip6_sv_reass_set_params (timeout_ms, max_reassemblies, |
| 894 | max_reassembly_length, expire_walk_interval_ms); |
| 895 | vlib_process_signal_event (ip6_sv_reass_main.vlib_main, |
| 896 | ip6_sv_reass_main.ip6_sv_reass_expire_node_idx, |
| 897 | IP6_EVENT_CONFIG_CHANGED, 0); |
| 898 | u32 new_nbuckets = ip6_sv_reass_get_nbuckets (); |
| 899 | if (ip6_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets) |
| 900 | { |
| 901 | clib_bihash_48_8_t new_hash; |
| 902 | clib_memset (&new_hash, 0, sizeof (new_hash)); |
| 903 | ip6_rehash_cb_ctx ctx; |
| 904 | ctx.failure = 0; |
| 905 | ctx.new_hash = &new_hash; |
| 906 | clib_bihash_init_48_8 (&new_hash, "ip6-sv-reass", new_nbuckets, |
| 907 | new_nbuckets * 1024); |
| 908 | clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.hash, |
| 909 | ip6_rehash_cb, &ctx); |
| 910 | if (ctx.failure) |
| 911 | { |
| 912 | clib_bihash_free_48_8 (&new_hash); |
| 913 | return -1; |
| 914 | } |
| 915 | else |
| 916 | { |
| 917 | clib_bihash_free_48_8 (&ip6_sv_reass_main.hash); |
| 918 | clib_memcpy_fast (&ip6_sv_reass_main.hash, &new_hash, |
| 919 | sizeof (ip6_sv_reass_main.hash)); |
| 920 | clib_bihash_copied (&ip6_sv_reass_main.hash, &new_hash); |
| 921 | } |
| 922 | } |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | vnet_api_error_t |
| 927 | ip6_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies, |
| 928 | u32 * max_reassembly_length, u32 * expire_walk_interval_ms) |
| 929 | { |
| 930 | *timeout_ms = ip6_sv_reass_main.timeout_ms; |
| 931 | *max_reassemblies = ip6_sv_reass_main.max_reass_n; |
| 932 | *max_reassembly_length = ip6_sv_reass_main.max_reass_len; |
| 933 | *expire_walk_interval_ms = ip6_sv_reass_main.expire_walk_interval_ms; |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | static clib_error_t * |
| 938 | ip6_sv_reass_init_function (vlib_main_t * vm) |
| 939 | { |
| 940 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
| 941 | clib_error_t *error = 0; |
| 942 | u32 nbuckets; |
| 943 | vlib_node_t *node; |
| 944 | |
| 945 | rm->vlib_main = vm; |
| 946 | rm->vnet_main = vnet_get_main (); |
| 947 | |
| 948 | vec_validate (rm->per_thread_data, vlib_num_workers ()); |
| 949 | ip6_sv_reass_per_thread_t *rt; |
| 950 | vec_foreach (rt, rm->per_thread_data) |
| 951 | { |
| 952 | clib_spinlock_init (&rt->lock); |
| 953 | pool_alloc (rt->pool, rm->max_reass_n); |
| 954 | rt->lru_first = rt->lru_last = ~0; |
| 955 | } |
| 956 | |
| 957 | node = vlib_get_node_by_name (vm, (u8 *) "ip6-sv-reassembly-expire-walk"); |
| 958 | ASSERT (node); |
| 959 | rm->ip6_sv_reass_expire_node_idx = node->index; |
| 960 | |
| 961 | ip6_sv_reass_set_params (IP6_SV_REASS_TIMEOUT_DEFAULT_MS, |
| 962 | IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT, |
| 963 | IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT, |
| 964 | IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS); |
| 965 | |
| 966 | nbuckets = ip6_sv_reass_get_nbuckets (); |
| 967 | clib_bihash_init_48_8 (&rm->hash, "ip6-sv-reass", nbuckets, |
| 968 | nbuckets * 1024); |
| 969 | |
| 970 | node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop"); |
| 971 | ASSERT (node); |
| 972 | rm->ip6_drop_idx = node->index; |
| 973 | node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error"); |
| 974 | ASSERT (node); |
| 975 | rm->ip6_icmp_error_idx = node->index; |
| 976 | |
| 977 | if ((error = vlib_call_init_function (vm, ip_main_init))) |
| 978 | return error; |
| 979 | ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION, |
| 980 | ip6_sv_reass_node.index); |
| 981 | |
| 982 | rm->fq_index = vlib_frame_queue_main_init (ip6_sv_reass_node.index, 0); |
| 983 | rm->fq_feature_index = |
| 984 | vlib_frame_queue_main_init (ip6_sv_reass_node_feature.index, 0); |
| 985 | |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 986 | rm->feature_use_refcount_per_intf = NULL; |
| 987 | |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 988 | return error; |
| 989 | } |
| 990 | |
| 991 | VLIB_INIT_FUNCTION (ip6_sv_reass_init_function); |
| 992 | #endif /* CLIB_MARCH_VARIANT */ |
| 993 | |
| 994 | static uword |
| 995 | ip6_sv_reass_walk_expired (vlib_main_t * vm, |
| 996 | vlib_node_runtime_t * node, vlib_frame_t * f) |
| 997 | { |
| 998 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
| 999 | uword event_type, *event_data = 0; |
| 1000 | |
| 1001 | while (true) |
| 1002 | { |
| 1003 | vlib_process_wait_for_event_or_clock (vm, |
| 1004 | (f64) rm->expire_walk_interval_ms |
| 1005 | / (f64) MSEC_PER_SEC); |
| 1006 | event_type = vlib_process_get_events (vm, &event_data); |
| 1007 | |
| 1008 | switch (event_type) |
| 1009 | { |
| 1010 | case ~0: /* no events => timeout */ |
| 1011 | /* nothing to do here */ |
| 1012 | break; |
| 1013 | case IP6_EVENT_CONFIG_CHANGED: |
| 1014 | break; |
| 1015 | default: |
| 1016 | clib_warning ("BUG: event type 0x%wx", event_type); |
| 1017 | break; |
| 1018 | } |
| 1019 | f64 now = vlib_time_now (vm); |
| 1020 | |
| 1021 | ip6_sv_reass_t *reass; |
| 1022 | int *pool_indexes_to_free = NULL; |
| 1023 | |
| 1024 | uword thread_index = 0; |
| 1025 | int index; |
| 1026 | const uword nthreads = vlib_num_workers () + 1; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1027 | for (thread_index = 0; thread_index < nthreads; ++thread_index) |
| 1028 | { |
| 1029 | ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index]; |
| 1030 | clib_spinlock_lock (&rt->lock); |
| 1031 | |
| 1032 | vec_reset_length (pool_indexes_to_free); |
| 1033 | /* *INDENT-OFF* */ |
| 1034 | pool_foreach_index (index, rt->pool, ({ |
| 1035 | reass = pool_elt_at_index (rt->pool, index); |
| 1036 | if (now > reass->last_heard + rm->timeout) |
| 1037 | { |
| 1038 | vec_add1 (pool_indexes_to_free, index); |
| 1039 | } |
| 1040 | })); |
| 1041 | /* *INDENT-ON* */ |
| 1042 | int *i; |
| 1043 | /* *INDENT-OFF* */ |
| 1044 | vec_foreach (i, pool_indexes_to_free) |
| 1045 | { |
| 1046 | ip6_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]); |
| 1047 | ip6_sv_reass_free (vm, rm, rt, reass); |
| 1048 | } |
| 1049 | /* *INDENT-ON* */ |
| 1050 | |
| 1051 | clib_spinlock_unlock (&rt->lock); |
| 1052 | } |
| 1053 | |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1054 | vec_free (pool_indexes_to_free); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1055 | if (event_data) |
| 1056 | { |
| 1057 | _vec_len (event_data) = 0; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | /* *INDENT-OFF* */ |
| 1065 | VLIB_REGISTER_NODE (ip6_sv_reass_expire_node) = { |
| 1066 | .function = ip6_sv_reass_walk_expired, |
| 1067 | .format_trace = format_ip6_sv_reass_trace, |
| 1068 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1069 | .name = "ip6-sv-reassembly-expire-walk", |
| 1070 | |
| 1071 | .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings), |
| 1072 | .error_strings = ip6_sv_reassembly_error_strings, |
| 1073 | |
| 1074 | }; |
| 1075 | /* *INDENT-ON* */ |
| 1076 | |
| 1077 | static u8 * |
| 1078 | format_ip6_sv_reass_key (u8 * s, va_list * args) |
| 1079 | { |
| 1080 | ip6_sv_reass_key_t *key = va_arg (*args, ip6_sv_reass_key_t *); |
| 1081 | s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u", |
| 1082 | key->xx_id, format_ip6_address, &key->src, format_ip6_address, |
| 1083 | &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto); |
| 1084 | return s; |
| 1085 | } |
| 1086 | |
| 1087 | static u8 * |
| 1088 | format_ip6_sv_reass (u8 * s, va_list * args) |
| 1089 | { |
| 1090 | vlib_main_t *vm = va_arg (*args, vlib_main_t *); |
| 1091 | ip6_sv_reass_t *reass = va_arg (*args, ip6_sv_reass_t *); |
| 1092 | |
| 1093 | s = format (s, "ID: %lu, key: %U, trace_op_counter: %u\n", |
| 1094 | reass->id, format_ip6_sv_reass_key, &reass->key, |
| 1095 | reass->trace_op_counter); |
| 1096 | vlib_buffer_t *b; |
| 1097 | u32 *bip; |
| 1098 | u32 counter = 0; |
| 1099 | vec_foreach (bip, reass->cached_buffers) |
| 1100 | { |
| 1101 | u32 bi = *bip; |
| 1102 | do |
| 1103 | { |
| 1104 | b = vlib_get_buffer (vm, bi); |
| 1105 | s = format (s, " #%03u: bi: %u\n", counter, bi); |
| 1106 | ++counter; |
| 1107 | bi = b->next_buffer; |
| 1108 | } |
| 1109 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 1110 | } |
| 1111 | return s; |
| 1112 | } |
| 1113 | |
| 1114 | static clib_error_t * |
| 1115 | show_ip6_sv_reass (vlib_main_t * vm, unformat_input_t * input, |
| 1116 | CLIB_UNUSED (vlib_cli_command_t * lmd)) |
| 1117 | { |
| 1118 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
| 1119 | |
| 1120 | vlib_cli_output (vm, "---------------------"); |
| 1121 | vlib_cli_output (vm, "IP6 reassembly status"); |
| 1122 | vlib_cli_output (vm, "---------------------"); |
| 1123 | bool details = false; |
| 1124 | if (unformat (input, "details")) |
| 1125 | { |
| 1126 | details = true; |
| 1127 | } |
| 1128 | |
| 1129 | u32 sum_reass_n = 0; |
| 1130 | u64 sum_buffers_n = 0; |
| 1131 | ip6_sv_reass_t *reass; |
| 1132 | uword thread_index; |
| 1133 | const uword nthreads = vlib_num_workers () + 1; |
| 1134 | for (thread_index = 0; thread_index < nthreads; ++thread_index) |
| 1135 | { |
| 1136 | ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index]; |
| 1137 | clib_spinlock_lock (&rt->lock); |
| 1138 | if (details) |
| 1139 | { |
| 1140 | /* *INDENT-OFF* */ |
| 1141 | pool_foreach (reass, rt->pool, { |
| 1142 | vlib_cli_output (vm, "%U", format_ip6_sv_reass, vm, reass); |
| 1143 | }); |
| 1144 | /* *INDENT-ON* */ |
| 1145 | } |
| 1146 | sum_reass_n += rt->reass_n; |
| 1147 | clib_spinlock_unlock (&rt->lock); |
| 1148 | } |
| 1149 | vlib_cli_output (vm, "---------------------"); |
| 1150 | vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n", |
| 1151 | (long unsigned) sum_reass_n); |
Vladimir Ratnikov | a877cf9 | 2019-12-21 06:27:52 -0500 | [diff] [blame] | 1152 | vlib_cli_output (vm, |
| 1153 | "Maximum configured concurrent shallow virtual IP6 reassemblies per worker-thread: %lu\n", |
| 1154 | (long unsigned) rm->max_reass_n); |
| 1155 | vlib_cli_output (vm, |
| 1156 | "Maximum configured shallow virtual IP6 reassembly timeout: %lums\n", |
| 1157 | (long unsigned) rm->timeout_ms); |
| 1158 | vlib_cli_output (vm, |
| 1159 | "Maximum configured shallow virtual IP6 reassembly expire walk interval: %lums\n", |
| 1160 | (long unsigned) rm->expire_walk_interval_ms); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1161 | vlib_cli_output (vm, "Buffers in use: %lu\n", |
| 1162 | (long unsigned) sum_buffers_n); |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | /* *INDENT-OFF* */ |
| 1167 | VLIB_CLI_COMMAND (show_ip6_sv_reassembly_cmd, static) = { |
| 1168 | .path = "show ip6-sv-reassembly", |
| 1169 | .short_help = "show ip6-sv-reassembly [details]", |
| 1170 | .function = show_ip6_sv_reass, |
| 1171 | }; |
| 1172 | /* *INDENT-ON* */ |
| 1173 | |
| 1174 | #ifndef CLIB_MARCH_VARIANT |
| 1175 | vnet_api_error_t |
| 1176 | ip6_sv_reass_enable_disable (u32 sw_if_index, u8 enable_disable) |
| 1177 | { |
Klement Sekera | f126e74 | 2019-10-10 09:46:06 +0000 | [diff] [blame] | 1178 | return ip6_sv_reass_enable_disable_with_refcnt (sw_if_index, |
| 1179 | enable_disable); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1180 | } |
| 1181 | #endif /* CLIB_MARCH_VARIANT */ |
| 1182 | |
| 1183 | #define foreach_ip6_sv_reassembly_handoff_error \ |
| 1184 | _(CONGESTION_DROP, "congestion drop") |
| 1185 | |
| 1186 | |
| 1187 | typedef enum |
| 1188 | { |
| 1189 | #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym, |
| 1190 | foreach_ip6_sv_reassembly_handoff_error |
| 1191 | #undef _ |
| 1192 | IP6_SV_REASSEMBLY_HANDOFF_N_ERROR, |
| 1193 | } ip6_sv_reassembly_handoff_error_t; |
| 1194 | |
| 1195 | static char *ip6_sv_reassembly_handoff_error_strings[] = { |
| 1196 | #define _(sym,string) string, |
| 1197 | foreach_ip6_sv_reassembly_handoff_error |
| 1198 | #undef _ |
| 1199 | }; |
| 1200 | |
| 1201 | typedef struct |
| 1202 | { |
| 1203 | u32 next_worker_index; |
| 1204 | } ip6_sv_reassembly_handoff_trace_t; |
| 1205 | |
| 1206 | static u8 * |
| 1207 | format_ip6_sv_reassembly_handoff_trace (u8 * s, va_list * args) |
| 1208 | { |
| 1209 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 1210 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 1211 | ip6_sv_reassembly_handoff_trace_t *t = |
| 1212 | va_arg (*args, ip6_sv_reassembly_handoff_trace_t *); |
| 1213 | |
| 1214 | s = |
| 1215 | format (s, "ip6-sv-reassembly-handoff: next-worker %d", |
| 1216 | t->next_worker_index); |
| 1217 | |
| 1218 | return s; |
| 1219 | } |
| 1220 | |
| 1221 | always_inline uword |
| 1222 | ip6_sv_reassembly_handoff_inline (vlib_main_t * vm, |
| 1223 | vlib_node_runtime_t * node, |
| 1224 | vlib_frame_t * frame, bool is_feature) |
| 1225 | { |
| 1226 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
| 1227 | |
| 1228 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 1229 | u32 n_enq, n_left_from, *from; |
| 1230 | u16 thread_indices[VLIB_FRAME_SIZE], *ti; |
| 1231 | u32 fq_index; |
| 1232 | |
| 1233 | from = vlib_frame_vector_args (frame); |
| 1234 | n_left_from = frame->n_vectors; |
| 1235 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 1236 | |
| 1237 | b = bufs; |
| 1238 | ti = thread_indices; |
| 1239 | |
| 1240 | fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index; |
| 1241 | |
| 1242 | while (n_left_from > 0) |
| 1243 | { |
| 1244 | ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index; |
| 1245 | |
| 1246 | if (PREDICT_FALSE |
| 1247 | ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 1248 | && (b[0]->flags & VLIB_BUFFER_IS_TRACED))) |
| 1249 | { |
| 1250 | ip6_sv_reassembly_handoff_trace_t *t = |
| 1251 | vlib_add_trace (vm, node, b[0], sizeof (*t)); |
| 1252 | t->next_worker_index = ti[0]; |
| 1253 | } |
| 1254 | |
| 1255 | n_left_from -= 1; |
| 1256 | ti += 1; |
| 1257 | b += 1; |
| 1258 | } |
| 1259 | n_enq = |
| 1260 | vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices, |
| 1261 | frame->n_vectors, 1); |
| 1262 | |
| 1263 | if (n_enq < frame->n_vectors) |
| 1264 | vlib_node_increment_counter (vm, node->node_index, |
| 1265 | IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP, |
| 1266 | frame->n_vectors - n_enq); |
| 1267 | return frame->n_vectors; |
| 1268 | } |
| 1269 | |
| 1270 | VLIB_NODE_FN (ip6_sv_reassembly_handoff_node) (vlib_main_t * vm, |
| 1271 | vlib_node_runtime_t * node, |
| 1272 | vlib_frame_t * frame) |
| 1273 | { |
| 1274 | return ip6_sv_reassembly_handoff_inline (vm, node, frame, |
| 1275 | false /* is_feature */ ); |
| 1276 | } |
| 1277 | |
| 1278 | /* *INDENT-OFF* */ |
| 1279 | VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node) = { |
| 1280 | .name = "ip6-sv-reassembly-handoff", |
| 1281 | .vector_size = sizeof (u32), |
| 1282 | .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings), |
| 1283 | .error_strings = ip6_sv_reassembly_handoff_error_strings, |
| 1284 | .format_trace = format_ip6_sv_reassembly_handoff_trace, |
| 1285 | |
| 1286 | .n_next_nodes = 1, |
| 1287 | |
| 1288 | .next_nodes = { |
| 1289 | [0] = "error-drop", |
| 1290 | }, |
| 1291 | }; |
| 1292 | |
| 1293 | |
| 1294 | VLIB_NODE_FN (ip6_sv_reassembly_feature_handoff_node) (vlib_main_t * vm, |
| 1295 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 1296 | { |
| 1297 | return ip6_sv_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ ); |
| 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | /* *INDENT-OFF* */ |
| 1302 | VLIB_REGISTER_NODE (ip6_sv_reassembly_feature_handoff_node) = { |
| 1303 | .name = "ip6-sv-reass-feature-hoff", |
| 1304 | .vector_size = sizeof (u32), |
| 1305 | .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings), |
| 1306 | .error_strings = ip6_sv_reassembly_handoff_error_strings, |
| 1307 | .format_trace = format_ip6_sv_reassembly_handoff_trace, |
| 1308 | |
| 1309 | .n_next_nodes = 1, |
| 1310 | |
| 1311 | .next_nodes = { |
| 1312 | [0] = "error-drop", |
| 1313 | }, |
| 1314 | }; |
| 1315 | /* *INDENT-ON* */ |
| 1316 | |
| 1317 | #ifndef CLIB_MARCH_VARIANT |
| 1318 | int |
| 1319 | ip6_sv_reass_enable_disable_with_refcnt (u32 sw_if_index, int is_enable) |
| 1320 | { |
| 1321 | ip6_sv_reass_main_t *rm = &ip6_sv_reass_main; |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 1322 | vec_validate (rm->feature_use_refcount_per_intf, sw_if_index); |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1323 | if (is_enable) |
| 1324 | { |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 1325 | if (!rm->feature_use_refcount_per_intf[sw_if_index]) |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1326 | { |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 1327 | ++rm->feature_use_refcount_per_intf[sw_if_index]; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1328 | return vnet_feature_enable_disable ("ip6-unicast", |
| 1329 | "ip6-sv-reassembly-feature", |
| 1330 | sw_if_index, 1, 0, 0); |
| 1331 | } |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 1332 | ++rm->feature_use_refcount_per_intf[sw_if_index]; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1333 | } |
| 1334 | else |
| 1335 | { |
Klement Sekera | 63c7353 | 2019-09-30 14:35:36 +0000 | [diff] [blame] | 1336 | --rm->feature_use_refcount_per_intf[sw_if_index]; |
| 1337 | if (!rm->feature_use_refcount_per_intf[sw_if_index]) |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1338 | return vnet_feature_enable_disable ("ip6-unicast", |
| 1339 | "ip6-sv-reassembly-feature", |
| 1340 | sw_if_index, 0, 0, 0); |
| 1341 | } |
Klement Sekera | 407f593 | 2019-12-11 13:06:27 +0000 | [diff] [blame] | 1342 | return 0; |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1343 | } |
| 1344 | #endif |
| 1345 | |
| 1346 | /* |
| 1347 | * fd.io coding-style-patch-verification: ON |
| 1348 | * |
| 1349 | * Local Variables: |
| 1350 | * eval: (c-set-style "gnu") |
| 1351 | * End: |
| 1352 | */ |