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