Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [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 |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 18 | * @brief IPv4 Full Reassembly. |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 19 | * |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 20 | * This file contains the source code for IPv4 full reassembly. |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <vppinfra/vec.h> |
| 24 | #include <vnet/vnet.h> |
| 25 | #include <vnet/ip/ip.h> |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 26 | #include <vnet/ip/ip.api_enum.h> |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 27 | #include <vppinfra/fifo.h> |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 28 | #include <vppinfra/bihash_16_8.h> |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 29 | #include <vnet/ip/reass/ip4_full_reass.h> |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 30 | #include <stddef.h> |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 31 | |
| 32 | #define MSEC_PER_SEC 1000 |
Vijayabhaskar Katamreddy | 8b874fc | 2022-05-13 13:07:19 +0000 | [diff] [blame] | 33 | #define IP4_REASS_TIMEOUT_DEFAULT_MS 200 |
| 34 | |
| 35 | /* As there are only 1024 reass context per thread, either the DDOS attacks |
| 36 | * or fractions of real timeouts, would consume these contexts quickly and |
| 37 | * running out context space and unable to perform reassembly */ |
| 38 | #define IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 50 // 50 ms default |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 39 | #define IP4_REASS_MAX_REASSEMBLIES_DEFAULT 1024 |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 40 | #define IP4_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3 |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 41 | #define IP4_REASS_HT_LOAD_FACTOR (0.75) |
| 42 | |
| 43 | #define IP4_REASS_DEBUG_BUFFERS 0 |
| 44 | #if IP4_REASS_DEBUG_BUFFERS |
| 45 | #define IP4_REASS_DEBUG_BUFFER(bi, what) \ |
| 46 | do \ |
| 47 | { \ |
| 48 | u32 _bi = bi; \ |
| 49 | printf (#what "buffer %u", _bi); \ |
| 50 | vlib_buffer_t *_b = vlib_get_buffer (vm, _bi); \ |
| 51 | while (_b->flags & VLIB_BUFFER_NEXT_PRESENT) \ |
| 52 | { \ |
| 53 | _bi = _b->next_buffer; \ |
| 54 | printf ("[%u]", _bi); \ |
| 55 | _b = vlib_get_buffer (vm, _bi); \ |
| 56 | } \ |
| 57 | printf ("\n"); \ |
| 58 | fflush (stdout); \ |
| 59 | } \ |
| 60 | while (0) |
| 61 | #else |
| 62 | #define IP4_REASS_DEBUG_BUFFER(...) |
| 63 | #endif |
| 64 | |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 65 | typedef enum |
| 66 | { |
| 67 | IP4_REASS_RC_OK, |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 68 | IP4_REASS_RC_TOO_MANY_FRAGMENTS, |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 69 | IP4_REASS_RC_INTERNAL_ERROR, |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame] | 70 | IP4_REASS_RC_NO_BUF, |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 71 | IP4_REASS_RC_HANDOFF, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 72 | } ip4_full_reass_rc_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 73 | |
| 74 | typedef struct |
| 75 | { |
Damjan Marion | 121a16a | 2022-09-14 16:00:09 +0200 | [diff] [blame] | 76 | struct |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 77 | { |
Damjan Marion | 121a16a | 2022-09-14 16:00:09 +0200 | [diff] [blame] | 78 | u16 frag_id; |
| 79 | u8 proto; |
| 80 | u8 unused; |
| 81 | u32 fib_index; |
| 82 | ip4_address_t src; |
| 83 | ip4_address_t dst; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 84 | }; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 85 | } ip4_full_reass_key_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 86 | |
Damjan Marion | 121a16a | 2022-09-14 16:00:09 +0200 | [diff] [blame] | 87 | STATIC_ASSERT_SIZEOF (ip4_full_reass_key_t, 16); |
| 88 | |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 89 | typedef union |
| 90 | { |
| 91 | struct |
| 92 | { |
| 93 | u32 reass_index; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 94 | u32 memory_owner_thread_index; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 95 | }; |
| 96 | u64 as_u64; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 97 | } ip4_full_reass_val_t; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 98 | |
| 99 | typedef union |
| 100 | { |
| 101 | struct |
| 102 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 103 | ip4_full_reass_key_t k; |
| 104 | ip4_full_reass_val_t v; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 105 | }; |
| 106 | clib_bihash_kv_16_8_t kv; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 107 | } ip4_full_reass_kv_t; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 108 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 109 | always_inline u32 |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 110 | ip4_full_reass_buffer_get_data_offset (vlib_buffer_t * b) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 111 | { |
| 112 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 113 | return vnb->ip.reass.range_first - vnb->ip.reass.fragment_first; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | always_inline u16 |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 117 | ip4_full_reass_buffer_get_data_len (vlib_buffer_t * b) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 118 | { |
| 119 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 120 | return clib_min (vnb->ip.reass.range_last, vnb->ip.reass.fragment_last) - |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 121 | (vnb->ip.reass.fragment_first + |
| 122 | ip4_full_reass_buffer_get_data_offset (b)) + 1; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | typedef struct |
| 126 | { |
| 127 | // hash table key |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 128 | ip4_full_reass_key_t key; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 129 | // time when last packet was received |
| 130 | f64 last_heard; |
| 131 | // internal id of this reassembly |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 132 | u64 id; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 133 | // buffer index of first buffer in this reassembly context |
| 134 | u32 first_bi; |
| 135 | // last octet of packet, ~0 until fragment without more_fragments arrives |
| 136 | u32 last_packet_octet; |
| 137 | // length of data collected so far |
| 138 | u32 data_len; |
| 139 | // trace operation counter |
| 140 | u32 trace_op_counter; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 141 | // next index - used by non-feature node |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 142 | u32 next_index; |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 143 | // error next index - used by custom apps (~0 if not used) |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 144 | u32 error_next_index; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 145 | // minimum fragment length for this reassembly - used to estimate MTU |
| 146 | u16 min_fragment_length; |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 147 | // number of fragments in this reassembly |
| 148 | u32 fragments_n; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 149 | // thread owning memory for this context (whose pool contains this ctx) |
| 150 | u32 memory_owner_thread_index; |
| 151 | // thread which received fragment with offset 0 and which sends out the |
| 152 | // completed reassembly |
| 153 | u32 sendout_thread_index; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 154 | } ip4_full_reass_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 155 | |
| 156 | typedef struct |
| 157 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 158 | ip4_full_reass_t *pool; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 159 | u32 reass_n; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 160 | u32 id_counter; |
Vijayabhaskar Katamreddy | 8b874fc | 2022-05-13 13:07:19 +0000 | [diff] [blame] | 161 | // for pacing the main thread timeouts |
| 162 | u32 last_id; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 163 | clib_spinlock_t lock; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 164 | } ip4_full_reass_per_thread_t; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 165 | |
| 166 | typedef struct |
| 167 | { |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 168 | // IPv4 config |
| 169 | u32 timeout_ms; |
| 170 | f64 timeout; |
| 171 | u32 expire_walk_interval_ms; |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 172 | // maximum number of fragments in one reassembly |
| 173 | u32 max_reass_len; |
| 174 | // maximum number of reassemblies |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 175 | u32 max_reass_n; |
| 176 | |
| 177 | // IPv4 runtime |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 178 | clib_bihash_16_8_t hash; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 179 | // per-thread data |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 180 | ip4_full_reass_per_thread_t *per_thread_data; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 181 | |
| 182 | // convenience |
| 183 | vlib_main_t *vlib_main; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 184 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 185 | u32 ip4_full_reass_expire_node_idx; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 186 | |
| 187 | /** Worker handoff */ |
| 188 | u32 fq_index; |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 189 | u32 fq_local_index; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 190 | u32 fq_feature_index; |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 191 | u32 fq_custom_index; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 192 | |
Klement Sekera | 7b2e9fb | 2019-10-01 13:00:22 +0000 | [diff] [blame] | 193 | // reference count for enabling/disabling feature - per interface |
| 194 | u32 *feature_use_refcount_per_intf; |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 195 | |
| 196 | // whether local fragmented packets are reassembled or not |
| 197 | int is_local_reass_enabled; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 198 | } ip4_full_reass_main_t; |
| 199 | |
| 200 | extern ip4_full_reass_main_t ip4_full_reass_main; |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 201 | |
| 202 | #ifndef CLIB_MARCH_VARIANT |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 203 | ip4_full_reass_main_t ip4_full_reass_main; |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 204 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 205 | |
| 206 | typedef enum |
| 207 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 208 | IP4_FULL_REASS_NEXT_INPUT, |
| 209 | IP4_FULL_REASS_NEXT_DROP, |
| 210 | IP4_FULL_REASS_NEXT_HANDOFF, |
| 211 | IP4_FULL_REASS_N_NEXT, |
| 212 | } ip4_full_reass_next_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 213 | |
| 214 | typedef enum |
| 215 | { |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 216 | NORMAL, |
| 217 | FEATURE, |
| 218 | CUSTOM |
| 219 | } ip4_full_reass_node_type_t; |
| 220 | |
| 221 | typedef enum |
| 222 | { |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 223 | RANGE_NEW, |
| 224 | RANGE_SHRINK, |
| 225 | RANGE_DISCARD, |
| 226 | RANGE_OVERLAP, |
| 227 | FINALIZE, |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 228 | HANDOFF, |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 229 | PASSTHROUGH, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 230 | } ip4_full_reass_trace_operation_e; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 231 | |
| 232 | typedef struct |
| 233 | { |
| 234 | u16 range_first; |
| 235 | u16 range_last; |
| 236 | u32 range_bi; |
| 237 | i32 data_offset; |
| 238 | u32 data_len; |
| 239 | u32 first_bi; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 240 | } ip4_full_reass_range_trace_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 241 | |
| 242 | typedef struct |
| 243 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 244 | ip4_full_reass_trace_operation_e action; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 245 | u32 reass_id; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 246 | ip4_full_reass_range_trace_t trace_range; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 247 | u32 size_diff; |
| 248 | u32 op_id; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 249 | u32 thread_id; |
| 250 | u32 thread_id_to; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 251 | u32 fragment_first; |
| 252 | u32 fragment_last; |
| 253 | u32 total_data_len; |
Klement Sekera | 8563cb3 | 2019-10-10 17:03:57 +0000 | [diff] [blame] | 254 | bool is_after_handoff; |
| 255 | ip4_header_t ip4_header; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 256 | } ip4_full_reass_trace_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 257 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 258 | extern vlib_node_registration_t ip4_full_reass_node; |
| 259 | extern vlib_node_registration_t ip4_full_reass_node_feature; |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 260 | extern vlib_node_registration_t ip4_full_reass_node_custom; |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 261 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 262 | static void |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 263 | ip4_full_reass_trace_details (vlib_main_t * vm, u32 bi, |
| 264 | ip4_full_reass_range_trace_t * trace) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 265 | { |
| 266 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 267 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
| 268 | trace->range_first = vnb->ip.reass.range_first; |
| 269 | trace->range_last = vnb->ip.reass.range_last; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 270 | trace->data_offset = ip4_full_reass_buffer_get_data_offset (b); |
| 271 | trace->data_len = ip4_full_reass_buffer_get_data_len (b); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 272 | trace->range_bi = bi; |
| 273 | } |
| 274 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 275 | static u8 * |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 276 | format_ip4_full_reass_range_trace (u8 * s, va_list * args) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 277 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 278 | ip4_full_reass_range_trace_t *trace = |
| 279 | va_arg (*args, ip4_full_reass_range_trace_t *); |
| 280 | s = |
| 281 | format (s, "range: [%u, %u], off %d, len %u, bi %u", trace->range_first, |
| 282 | trace->range_last, trace->data_offset, trace->data_len, |
| 283 | trace->range_bi); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 284 | return s; |
| 285 | } |
| 286 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 287 | static u8 * |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 288 | format_ip4_full_reass_trace (u8 * s, va_list * args) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 289 | { |
| 290 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 291 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 292 | ip4_full_reass_trace_t *t = va_arg (*args, ip4_full_reass_trace_t *); |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 293 | u32 indent = 0; |
| 294 | if (~0 != t->reass_id) |
| 295 | { |
Klement Sekera | 8563cb3 | 2019-10-10 17:03:57 +0000 | [diff] [blame] | 296 | if (t->is_after_handoff) |
| 297 | { |
| 298 | s = |
| 299 | format (s, "%U\n", format_ip4_header, &t->ip4_header, |
| 300 | sizeof (t->ip4_header)); |
| 301 | indent = 2; |
| 302 | } |
| 303 | s = |
| 304 | format (s, "%Ureass id: %u, op id: %u, ", format_white_space, indent, |
| 305 | t->reass_id, t->op_id); |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 306 | indent = format_get_indent (s); |
| 307 | s = |
| 308 | format (s, |
| 309 | "first bi: %u, data len: %u, ip/fragment[%u, %u]", |
| 310 | t->trace_range.first_bi, t->total_data_len, t->fragment_first, |
| 311 | t->fragment_last); |
| 312 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 313 | switch (t->action) |
| 314 | { |
| 315 | case RANGE_SHRINK: |
| 316 | s = format (s, "\n%Ushrink %U by %u", format_white_space, indent, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 317 | format_ip4_full_reass_range_trace, &t->trace_range, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 318 | t->size_diff); |
| 319 | break; |
| 320 | case RANGE_DISCARD: |
| 321 | s = format (s, "\n%Udiscard %U", format_white_space, indent, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 322 | format_ip4_full_reass_range_trace, &t->trace_range); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 323 | break; |
| 324 | case RANGE_NEW: |
| 325 | s = format (s, "\n%Unew %U", format_white_space, indent, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 326 | format_ip4_full_reass_range_trace, &t->trace_range); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 327 | break; |
| 328 | case RANGE_OVERLAP: |
| 329 | s = format (s, "\n%Uoverlapping/ignored %U", format_white_space, indent, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 330 | format_ip4_full_reass_range_trace, &t->trace_range); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 331 | break; |
| 332 | case FINALIZE: |
| 333 | s = format (s, "\n%Ufinalize reassembly", format_white_space, indent); |
| 334 | break; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 335 | case HANDOFF: |
| 336 | s = |
| 337 | format (s, "handoff from thread #%u to thread #%u", t->thread_id, |
| 338 | t->thread_id_to); |
| 339 | break; |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 340 | case PASSTHROUGH: |
| 341 | s = format (s, "passthrough - not a fragment"); |
| 342 | break; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 343 | } |
| 344 | return s; |
| 345 | } |
| 346 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 347 | static void |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 348 | ip4_full_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 349 | ip4_full_reass_t * reass, u32 bi, |
| 350 | ip4_full_reass_trace_operation_e action, |
| 351 | u32 size_diff, u32 thread_id_to) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 352 | { |
| 353 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 354 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
Klement Sekera | 53be16d | 2020-12-15 21:47:36 +0100 | [diff] [blame] | 355 | if (pool_is_free_index |
| 356 | (vm->trace_main.trace_buffer_pool, vlib_buffer_get_trace_index (b))) |
| 357 | { |
| 358 | // this buffer's trace is gone |
| 359 | b->flags &= ~VLIB_BUFFER_IS_TRACED; |
| 360 | return; |
| 361 | } |
Klement Sekera | 8563cb3 | 2019-10-10 17:03:57 +0000 | [diff] [blame] | 362 | bool is_after_handoff = false; |
| 363 | if (vlib_buffer_get_trace_thread (b) != vm->thread_index) |
| 364 | { |
| 365 | is_after_handoff = true; |
| 366 | } |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 367 | ip4_full_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0])); |
Klement Sekera | 8563cb3 | 2019-10-10 17:03:57 +0000 | [diff] [blame] | 368 | t->is_after_handoff = is_after_handoff; |
| 369 | if (t->is_after_handoff) |
| 370 | { |
| 371 | clib_memcpy (&t->ip4_header, vlib_buffer_get_current (b), |
| 372 | clib_min (sizeof (t->ip4_header), b->current_length)); |
| 373 | } |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 374 | if (reass) |
| 375 | { |
| 376 | t->reass_id = reass->id; |
| 377 | t->op_id = reass->trace_op_counter; |
| 378 | t->trace_range.first_bi = reass->first_bi; |
| 379 | t->total_data_len = reass->data_len; |
| 380 | ++reass->trace_op_counter; |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | t->reass_id = ~0; |
| 385 | t->op_id = 0; |
| 386 | t->trace_range.first_bi = 0; |
| 387 | t->total_data_len = 0; |
| 388 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 389 | t->action = action; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 390 | ip4_full_reass_trace_details (vm, bi, &t->trace_range); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 391 | t->size_diff = size_diff; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 392 | t->thread_id = vm->thread_index; |
| 393 | t->thread_id_to = thread_id_to; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 394 | t->fragment_first = vnb->ip.reass.fragment_first; |
| 395 | t->fragment_last = vnb->ip.reass.fragment_last; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 396 | #if 0 |
| 397 | static u8 *s = NULL; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 398 | s = format (s, "%U", format_ip4_full_reass_trace, NULL, NULL, t); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 399 | printf ("%.*s\n", vec_len (s), s); |
| 400 | fflush (stdout); |
| 401 | vec_reset_length (s); |
| 402 | #endif |
| 403 | } |
| 404 | |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 405 | always_inline void |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 406 | ip4_full_reass_free_ctx (ip4_full_reass_per_thread_t * rt, |
| 407 | ip4_full_reass_t * reass) |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 408 | { |
| 409 | pool_put (rt->pool, reass); |
| 410 | --rt->reass_n; |
| 411 | } |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 412 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 413 | always_inline void |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 414 | ip4_full_reass_free (ip4_full_reass_main_t * rm, |
| 415 | ip4_full_reass_per_thread_t * rt, |
| 416 | ip4_full_reass_t * reass) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 417 | { |
Damjan Marion | 121a16a | 2022-09-14 16:00:09 +0200 | [diff] [blame] | 418 | clib_bihash_kv_16_8_t kv = {}; |
| 419 | clib_memcpy_fast (&kv, &reass->key, sizeof (kv.key)); |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 420 | clib_bihash_add_del_16_8 (&rm->hash, &kv, 0); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 421 | return ip4_full_reass_free_ctx (rt, reass); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 424 | /* n_left_to_next, and to_next are taken as input params, as this function |
| 425 | * could be called from a graphnode, where its managing local copy of these |
| 426 | * variables, and ignoring those and still trying to enqueue the buffers |
| 427 | * with local variables would cause either buffer leak or corruption */ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 428 | always_inline void |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 429 | ip4_full_reass_drop_all (vlib_main_t *vm, vlib_node_runtime_t *node, |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 430 | ip4_full_reass_t *reass) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 431 | { |
| 432 | u32 range_bi = reass->first_bi; |
| 433 | vlib_buffer_t *range_b; |
| 434 | vnet_buffer_opaque_t *range_vnb; |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame] | 435 | u32 *to_free = NULL; |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 436 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 437 | while (~0 != range_bi) |
| 438 | { |
| 439 | range_b = vlib_get_buffer (vm, range_bi); |
| 440 | range_vnb = vnet_buffer (range_b); |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 441 | |
| 442 | if (~0 != range_bi) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 443 | { |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 444 | vec_add1 (to_free, range_bi); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 445 | } |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 446 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 447 | range_bi = range_vnb->ip.reass.next_range_bi; |
| 448 | } |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 449 | |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 450 | /* send to next_error_index */ |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 451 | if (~0 != reass->error_next_index && |
| 452 | reass->error_next_index < node->n_next_nodes) |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 453 | { |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 454 | u32 n_free = vec_len (to_free); |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 455 | |
Vijayabhaskar Katamreddy | 14a7442 | 2022-05-18 14:31:03 +0000 | [diff] [blame] | 456 | /* record number of packets sent to custom app */ |
| 457 | vlib_node_increment_counter (vm, node->node_index, |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 458 | IP4_ERROR_REASS_TO_CUSTOM_APP, n_free); |
Vijayabhaskar Katamreddy | 14a7442 | 2022-05-18 14:31:03 +0000 | [diff] [blame] | 459 | |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 460 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 461 | for (u32 i = 0; i < n_free; i++) |
| 462 | { |
| 463 | vlib_buffer_t *b = vlib_get_buffer (vm, to_free[i]); |
| 464 | if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED)) |
| 465 | ip4_full_reass_add_trace (vm, node, reass, to_free[i], |
| 466 | RANGE_DISCARD, 0, ~0); |
| 467 | } |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 468 | |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 469 | vlib_buffer_enqueue_to_single_next (vm, node, to_free, |
| 470 | reass->error_next_index, n_free); |
Klement Sekera | 21aa8f1 | 2019-05-20 12:27:33 +0200 | [diff] [blame] | 471 | } |
| 472 | else |
| 473 | { |
| 474 | vlib_buffer_free (vm, to_free, vec_len (to_free)); |
| 475 | } |
barryxie | 01e94db | 2020-12-04 19:21:23 +0800 | [diff] [blame] | 476 | vec_free (to_free); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 479 | always_inline void |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 480 | sanitize_reass_buffers_add_missing (vlib_main_t *vm, ip4_full_reass_t *reass, |
| 481 | u32 *bi0) |
| 482 | { |
| 483 | u32 range_bi = reass->first_bi; |
| 484 | vlib_buffer_t *range_b; |
| 485 | vnet_buffer_opaque_t *range_vnb; |
| 486 | |
| 487 | while (~0 != range_bi) |
| 488 | { |
| 489 | range_b = vlib_get_buffer (vm, range_bi); |
| 490 | range_vnb = vnet_buffer (range_b); |
| 491 | u32 bi = range_bi; |
| 492 | if (~0 != bi) |
| 493 | { |
| 494 | if (bi == *bi0) |
| 495 | *bi0 = ~0; |
| 496 | if (range_b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 497 | { |
| 498 | u32 _bi = bi; |
| 499 | vlib_buffer_t *_b = vlib_get_buffer (vm, _bi); |
| 500 | while (_b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 501 | { |
| 502 | if (_b->next_buffer != range_vnb->ip.reass.next_range_bi) |
| 503 | { |
| 504 | _bi = _b->next_buffer; |
| 505 | _b = vlib_get_buffer (vm, _bi); |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | _b->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 510 | break; |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | range_bi = range_vnb->ip.reass.next_range_bi; |
| 515 | } |
| 516 | } |
| 517 | if (*bi0 != ~0) |
| 518 | { |
| 519 | vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0); |
| 520 | vnet_buffer_opaque_t *fvnb = vnet_buffer (fb); |
| 521 | if (~0 != reass->first_bi) |
| 522 | { |
| 523 | fvnb->ip.reass.next_range_bi = reass->first_bi; |
| 524 | reass->first_bi = *bi0; |
| 525 | } |
| 526 | else |
| 527 | { |
| 528 | reass->first_bi = *bi0; |
| 529 | fvnb->ip.reass.next_range_bi = ~0; |
| 530 | } |
| 531 | *bi0 = ~0; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | always_inline void |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 536 | ip4_full_reass_init (ip4_full_reass_t * reass) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 537 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 538 | reass->first_bi = ~0; |
| 539 | reass->last_packet_octet = ~0; |
| 540 | reass->data_len = 0; |
| 541 | reass->next_index = ~0; |
| 542 | reass->error_next_index = ~0; |
| 543 | } |
| 544 | |
| 545 | always_inline ip4_full_reass_t * |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 546 | ip4_full_reass_find_or_create (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 547 | ip4_full_reass_main_t *rm, |
| 548 | ip4_full_reass_per_thread_t *rt, |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 549 | ip4_full_reass_kv_t *kv, u8 *do_handoff) |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 550 | { |
| 551 | ip4_full_reass_t *reass; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 552 | f64 now; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 553 | |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 554 | again: |
| 555 | |
| 556 | reass = NULL; |
| 557 | now = vlib_time_now (vm); |
Klement Sekera | c99c025 | 2019-12-18 12:17:06 +0000 | [diff] [blame] | 558 | if (!clib_bihash_search_16_8 (&rm->hash, &kv->kv, &kv->kv)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 559 | { |
Gao Feng | 9165e03 | 2020-04-26 09:57:18 +0800 | [diff] [blame] | 560 | if (vm->thread_index != kv->v.memory_owner_thread_index) |
| 561 | { |
| 562 | *do_handoff = 1; |
| 563 | return NULL; |
| 564 | } |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 565 | reass = |
| 566 | pool_elt_at_index (rm->per_thread_data |
| 567 | [kv->v.memory_owner_thread_index].pool, |
| 568 | kv->v.reass_index); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 569 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 570 | if (now > reass->last_heard + rm->timeout) |
| 571 | { |
Vijayabhaskar Katamreddy | 14a7442 | 2022-05-18 14:31:03 +0000 | [diff] [blame] | 572 | vlib_node_increment_counter (vm, node->node_index, |
| 573 | IP4_ERROR_REASS_TIMEOUT, 1); |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 574 | ip4_full_reass_drop_all (vm, node, reass); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 575 | ip4_full_reass_free (rm, rt, reass); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 576 | reass = NULL; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | if (reass) |
| 581 | { |
| 582 | reass->last_heard = now; |
| 583 | return reass; |
| 584 | } |
| 585 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 586 | if (rt->reass_n >= rm->max_reass_n) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 587 | { |
| 588 | reass = NULL; |
| 589 | return reass; |
| 590 | } |
| 591 | else |
| 592 | { |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 593 | pool_get (rt->pool, reass); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 594 | clib_memset (reass, 0, sizeof (*reass)); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 595 | reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 596 | reass->memory_owner_thread_index = vm->thread_index; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 597 | ++rt->id_counter; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 598 | ip4_full_reass_init (reass); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 599 | ++rt->reass_n; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Damjan Marion | 121a16a | 2022-09-14 16:00:09 +0200 | [diff] [blame] | 602 | clib_memcpy_fast (&reass->key, &kv->kv.key, sizeof (reass->key)); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 603 | kv->v.reass_index = (reass - rt->pool); |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 604 | kv->v.memory_owner_thread_index = vm->thread_index; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 605 | reass->last_heard = now; |
| 606 | |
Klement Sekera | c99c025 | 2019-12-18 12:17:06 +0000 | [diff] [blame] | 607 | int rv = clib_bihash_add_del_16_8 (&rm->hash, &kv->kv, 2); |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 608 | if (rv) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 609 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 610 | ip4_full_reass_free_ctx (rt, reass); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 611 | reass = NULL; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 612 | // if other worker created a context already work with the other copy |
| 613 | if (-2 == rv) |
| 614 | goto again; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | return reass; |
| 618 | } |
| 619 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 620 | always_inline ip4_full_reass_rc_t |
| 621 | ip4_full_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 622 | ip4_full_reass_main_t * rm, |
| 623 | ip4_full_reass_per_thread_t * rt, |
| 624 | ip4_full_reass_t * reass, u32 * bi0, |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 625 | u32 * next0, u32 * error0, bool is_custom) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 626 | { |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 627 | vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi); |
| 628 | vlib_buffer_t *last_b = NULL; |
| 629 | u32 sub_chain_bi = reass->first_bi; |
| 630 | u32 total_length = 0; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 631 | do |
| 632 | { |
| 633 | u32 tmp_bi = sub_chain_bi; |
| 634 | vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi); |
| 635 | ip4_header_t *ip = vlib_buffer_get_current (tmp); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 636 | vnet_buffer_opaque_t *vnb = vnet_buffer (tmp); |
| 637 | if (!(vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first) && |
| 638 | !(vnb->ip.reass.range_last > vnb->ip.reass.fragment_first)) |
| 639 | { |
| 640 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 641 | } |
| 642 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 643 | u32 data_len = ip4_full_reass_buffer_get_data_len (tmp); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 644 | u32 trim_front = |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 645 | ip4_header_bytes (ip) + ip4_full_reass_buffer_get_data_offset (tmp); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 646 | u32 trim_end = |
| 647 | vlib_buffer_length_in_chain (vm, tmp) - trim_front - data_len; |
| 648 | if (tmp_bi == reass->first_bi) |
| 649 | { |
| 650 | /* first buffer - keep ip4 header */ |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 651 | if (0 != ip4_full_reass_buffer_get_data_offset (tmp)) |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 652 | { |
| 653 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 654 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 655 | trim_front = 0; |
| 656 | trim_end = vlib_buffer_length_in_chain (vm, tmp) - data_len - |
| 657 | ip4_header_bytes (ip); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 658 | if (!(vlib_buffer_length_in_chain (vm, tmp) - trim_end > 0)) |
| 659 | { |
| 660 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 661 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 662 | } |
| 663 | u32 keep_data = |
| 664 | vlib_buffer_length_in_chain (vm, tmp) - trim_front - trim_end; |
| 665 | while (1) |
| 666 | { |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 667 | if (trim_front) |
| 668 | { |
| 669 | if (trim_front > tmp->current_length) |
| 670 | { |
| 671 | /* drop whole buffer */ |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 672 | u32 to_be_freed_bi = tmp_bi; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 673 | trim_front -= tmp->current_length; |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 674 | if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 675 | { |
| 676 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 677 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 678 | tmp->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 679 | tmp_bi = tmp->next_buffer; |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 680 | tmp->next_buffer = 0; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 681 | tmp = vlib_get_buffer (vm, tmp_bi); |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 682 | vlib_buffer_free_one (vm, to_be_freed_bi); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 683 | continue; |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | vlib_buffer_advance (tmp, trim_front); |
| 688 | trim_front = 0; |
| 689 | } |
| 690 | } |
| 691 | if (keep_data) |
| 692 | { |
| 693 | if (last_b) |
| 694 | { |
| 695 | last_b->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 696 | last_b->next_buffer = tmp_bi; |
| 697 | } |
| 698 | last_b = tmp; |
| 699 | if (keep_data <= tmp->current_length) |
| 700 | { |
| 701 | tmp->current_length = keep_data; |
| 702 | keep_data = 0; |
| 703 | } |
| 704 | else |
| 705 | { |
| 706 | keep_data -= tmp->current_length; |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 707 | if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 708 | { |
| 709 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 710 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 711 | } |
| 712 | total_length += tmp->current_length; |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 713 | if (tmp->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 714 | { |
| 715 | tmp_bi = tmp->next_buffer; |
| 716 | tmp = vlib_get_buffer (vm, tmp->next_buffer); |
| 717 | } |
| 718 | else |
| 719 | { |
| 720 | break; |
| 721 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 722 | } |
| 723 | else |
| 724 | { |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 725 | u32 to_be_freed_bi = tmp_bi; |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 726 | if (reass->first_bi == tmp_bi) |
| 727 | { |
| 728 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 729 | } |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 730 | if (tmp->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 731 | { |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 732 | tmp->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 733 | tmp_bi = tmp->next_buffer; |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 734 | tmp->next_buffer = 0; |
| 735 | tmp = vlib_get_buffer (vm, tmp_bi); |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 736 | vlib_buffer_free_one (vm, to_be_freed_bi); |
| 737 | } |
| 738 | else |
| 739 | { |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 740 | tmp->next_buffer = 0; |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 741 | vlib_buffer_free_one (vm, to_be_freed_bi); |
| 742 | break; |
| 743 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | sub_chain_bi = |
| 747 | vnet_buffer (vlib_get_buffer (vm, sub_chain_bi))->ip. |
| 748 | reass.next_range_bi; |
| 749 | } |
| 750 | while (~0 != sub_chain_bi); |
Chris Luke | 30684ac | 2018-03-29 12:56:58 -0700 | [diff] [blame] | 751 | |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 752 | if (!last_b) |
| 753 | { |
| 754 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 755 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 756 | last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 757 | |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 758 | if (total_length < first_b->current_length) |
| 759 | { |
| 760 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 761 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 762 | total_length -= first_b->current_length; |
| 763 | first_b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 764 | first_b->total_length_not_including_first_buffer = total_length; |
| 765 | ip4_header_t *ip = vlib_buffer_get_current (first_b); |
| 766 | ip->flags_and_fragment_offset = 0; |
| 767 | ip->length = clib_host_to_net_u16 (first_b->current_length + total_length); |
| 768 | ip->checksum = ip4_header_checksum (ip); |
Klement Sekera | f883f6a | 2019-02-13 11:01:32 +0100 | [diff] [blame] | 769 | if (!vlib_buffer_chain_linearize (vm, first_b)) |
| 770 | { |
| 771 | return IP4_REASS_RC_NO_BUF; |
| 772 | } |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 773 | // reset to reconstruct the mbuf linking |
| 774 | first_b->flags &= ~VLIB_BUFFER_EXT_HDR_VALID; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 775 | if (PREDICT_FALSE (first_b->flags & VLIB_BUFFER_IS_TRACED)) |
| 776 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 777 | ip4_full_reass_add_trace (vm, node, reass, reass->first_bi, FINALIZE, 0, |
| 778 | ~0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 779 | #if 0 |
| 780 | // following code does a hexdump of packet fragments to stdout ... |
| 781 | do |
| 782 | { |
| 783 | u32 bi = reass->first_bi; |
| 784 | u8 *s = NULL; |
| 785 | while (~0 != bi) |
| 786 | { |
| 787 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 788 | s = format (s, "%u: %U\n", bi, format_hexdump, |
| 789 | vlib_buffer_get_current (b), b->current_length); |
| 790 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 791 | { |
| 792 | bi = b->next_buffer; |
| 793 | } |
| 794 | else |
| 795 | { |
| 796 | break; |
| 797 | } |
| 798 | } |
| 799 | printf ("%.*s\n", vec_len (s), s); |
| 800 | fflush (stdout); |
| 801 | vec_free (s); |
| 802 | } |
| 803 | while (0); |
| 804 | #endif |
| 805 | } |
| 806 | *bi0 = reass->first_bi; |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 807 | if (!is_custom) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 808 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 809 | *next0 = IP4_FULL_REASS_NEXT_INPUT; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 810 | } |
| 811 | else |
| 812 | { |
| 813 | *next0 = reass->next_index; |
| 814 | } |
| 815 | vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length; |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 816 | |
Vijayabhaskar Katamreddy | 14a7442 | 2022-05-18 14:31:03 +0000 | [diff] [blame] | 817 | /* Keep track of number of successfully reassembled packets and number of |
| 818 | * fragments reassembled */ |
| 819 | vlib_node_increment_counter (vm, node->node_index, IP4_ERROR_REASS_SUCCESS, |
| 820 | 1); |
| 821 | |
| 822 | vlib_node_increment_counter (vm, node->node_index, |
| 823 | IP4_ERROR_REASS_FRAGMENTS_REASSEMBLED, |
| 824 | reass->fragments_n); |
| 825 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 826 | *error0 = IP4_ERROR_NONE; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 827 | ip4_full_reass_free (rm, rt, reass); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 828 | reass = NULL; |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 829 | return IP4_REASS_RC_OK; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 830 | } |
| 831 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 832 | always_inline ip4_full_reass_rc_t |
| 833 | ip4_full_reass_insert_range_in_chain (vlib_main_t * vm, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 834 | ip4_full_reass_t * reass, |
| 835 | u32 prev_range_bi, u32 new_next_bi) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 836 | { |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 837 | vlib_buffer_t *new_next_b = vlib_get_buffer (vm, new_next_bi); |
| 838 | vnet_buffer_opaque_t *new_next_vnb = vnet_buffer (new_next_b); |
| 839 | if (~0 != prev_range_bi) |
| 840 | { |
| 841 | vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi); |
| 842 | vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b); |
| 843 | new_next_vnb->ip.reass.next_range_bi = prev_vnb->ip.reass.next_range_bi; |
| 844 | prev_vnb->ip.reass.next_range_bi = new_next_bi; |
| 845 | } |
| 846 | else |
| 847 | { |
| 848 | if (~0 != reass->first_bi) |
| 849 | { |
| 850 | new_next_vnb->ip.reass.next_range_bi = reass->first_bi; |
| 851 | } |
| 852 | reass->first_bi = new_next_bi; |
| 853 | } |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 854 | vnet_buffer_opaque_t *vnb = vnet_buffer (new_next_b); |
| 855 | if (!(vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first) && |
| 856 | !(vnb->ip.reass.range_last > vnb->ip.reass.fragment_first)) |
| 857 | { |
| 858 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 859 | } |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 860 | reass->data_len += ip4_full_reass_buffer_get_data_len (new_next_b); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 861 | return IP4_REASS_RC_OK; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 862 | } |
| 863 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 864 | always_inline ip4_full_reass_rc_t |
| 865 | ip4_full_reass_remove_range_from_chain (vlib_main_t * vm, |
| 866 | vlib_node_runtime_t * node, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 867 | ip4_full_reass_t * reass, |
| 868 | u32 prev_range_bi, u32 discard_bi) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 869 | { |
| 870 | vlib_buffer_t *discard_b = vlib_get_buffer (vm, discard_bi); |
| 871 | vnet_buffer_opaque_t *discard_vnb = vnet_buffer (discard_b); |
| 872 | if (~0 != prev_range_bi) |
| 873 | { |
| 874 | vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi); |
| 875 | vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 876 | if (!(prev_vnb->ip.reass.next_range_bi == discard_bi)) |
| 877 | { |
| 878 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 879 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 880 | prev_vnb->ip.reass.next_range_bi = discard_vnb->ip.reass.next_range_bi; |
| 881 | } |
| 882 | else |
| 883 | { |
| 884 | reass->first_bi = discard_vnb->ip.reass.next_range_bi; |
| 885 | } |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 886 | vnet_buffer_opaque_t *vnb = vnet_buffer (discard_b); |
| 887 | if (!(vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first) && |
| 888 | !(vnb->ip.reass.range_last > vnb->ip.reass.fragment_first)) |
| 889 | { |
| 890 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 891 | } |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 892 | reass->data_len -= ip4_full_reass_buffer_get_data_len (discard_b); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 893 | while (1) |
| 894 | { |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 895 | u32 to_be_freed_bi = discard_bi; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 896 | if (PREDICT_FALSE (discard_b->flags & VLIB_BUFFER_IS_TRACED)) |
| 897 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 898 | ip4_full_reass_add_trace (vm, node, reass, discard_bi, RANGE_DISCARD, |
| 899 | 0, ~0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 900 | } |
| 901 | if (discard_b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 902 | { |
| 903 | discard_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 904 | discard_bi = discard_b->next_buffer; |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 905 | discard_b->next_buffer = 0; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 906 | discard_b = vlib_get_buffer (vm, discard_bi); |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 907 | vlib_buffer_free_one (vm, to_be_freed_bi); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 908 | } |
| 909 | else |
| 910 | { |
Vijayabhaskar Katamreddy | 90556d6 | 2019-05-23 13:02:28 -0700 | [diff] [blame] | 911 | discard_b->next_buffer = 0; |
Klement Sekera | f369e3a | 2019-04-30 13:01:08 +0200 | [diff] [blame] | 912 | vlib_buffer_free_one (vm, to_be_freed_bi); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 913 | break; |
| 914 | } |
| 915 | } |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 916 | return IP4_REASS_RC_OK; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 917 | } |
| 918 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 919 | always_inline ip4_full_reass_rc_t |
| 920 | ip4_full_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 921 | ip4_full_reass_main_t * rm, |
| 922 | ip4_full_reass_per_thread_t * rt, |
| 923 | ip4_full_reass_t * reass, u32 * bi0, u32 * next0, |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 924 | u32 * error0, bool is_custom, u32 * handoff_thread_idx) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 925 | { |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 926 | vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 927 | vnet_buffer_opaque_t *fvnb = vnet_buffer (fb); |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 928 | if (is_custom) |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 929 | { |
| 930 | // store (error_)next_index before it's overwritten |
| 931 | reass->next_index = fvnb->ip.reass.next_index; |
| 932 | reass->error_next_index = fvnb->ip.reass.error_next_index; |
| 933 | } |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 934 | ip4_full_reass_rc_t rc = IP4_REASS_RC_OK; |
| 935 | int consumed = 0; |
| 936 | ip4_header_t *fip = vlib_buffer_get_current (fb); |
Klement Sekera | 14d7e90 | 2018-12-10 13:46:09 +0100 | [diff] [blame] | 937 | const u32 fragment_first = ip4_get_fragment_offset_bytes (fip); |
| 938 | const u32 fragment_length = |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 939 | clib_net_to_host_u16 (fip->length) - ip4_header_bytes (fip); |
Klement Sekera | 14d7e90 | 2018-12-10 13:46:09 +0100 | [diff] [blame] | 940 | const u32 fragment_last = fragment_first + fragment_length - 1; |
| 941 | fvnb->ip.reass.fragment_first = fragment_first; |
| 942 | fvnb->ip.reass.fragment_last = fragment_last; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 943 | int more_fragments = ip4_get_fragment_more (fip); |
| 944 | u32 candidate_range_bi = reass->first_bi; |
| 945 | u32 prev_range_bi = ~0; |
| 946 | fvnb->ip.reass.range_first = fragment_first; |
| 947 | fvnb->ip.reass.range_last = fragment_last; |
| 948 | fvnb->ip.reass.next_range_bi = ~0; |
| 949 | if (!more_fragments) |
| 950 | { |
| 951 | reass->last_packet_octet = fragment_last; |
| 952 | } |
| 953 | if (~0 == reass->first_bi) |
| 954 | { |
| 955 | // starting a new reassembly |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 956 | rc = |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 957 | ip4_full_reass_insert_range_in_chain (vm, reass, prev_range_bi, *bi0); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 958 | if (IP4_REASS_RC_OK != rc) |
| 959 | { |
| 960 | return rc; |
| 961 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 962 | if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED)) |
| 963 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 964 | ip4_full_reass_add_trace (vm, node, reass, *bi0, RANGE_NEW, 0, ~0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 965 | } |
| 966 | *bi0 = ~0; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 967 | reass->min_fragment_length = clib_net_to_host_u16 (fip->length); |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 968 | reass->fragments_n = 1; |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 969 | return IP4_REASS_RC_OK; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 970 | } |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 971 | reass->min_fragment_length = |
| 972 | clib_min (clib_net_to_host_u16 (fip->length), |
| 973 | fvnb->ip.reass.estimated_mtu); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 974 | while (~0 != candidate_range_bi) |
| 975 | { |
| 976 | vlib_buffer_t *candidate_b = vlib_get_buffer (vm, candidate_range_bi); |
| 977 | vnet_buffer_opaque_t *candidate_vnb = vnet_buffer (candidate_b); |
| 978 | if (fragment_first > candidate_vnb->ip.reass.range_last) |
| 979 | { |
| 980 | // this fragments starts after candidate range |
| 981 | prev_range_bi = candidate_range_bi; |
| 982 | candidate_range_bi = candidate_vnb->ip.reass.next_range_bi; |
| 983 | if (candidate_vnb->ip.reass.range_last < fragment_last && |
| 984 | ~0 == candidate_range_bi) |
| 985 | { |
| 986 | // special case - this fragment falls beyond all known ranges |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 987 | rc = ip4_full_reass_insert_range_in_chain (vm, reass, |
| 988 | prev_range_bi, *bi0); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 989 | if (IP4_REASS_RC_OK != rc) |
| 990 | { |
| 991 | return rc; |
| 992 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 993 | consumed = 1; |
| 994 | break; |
| 995 | } |
| 996 | continue; |
| 997 | } |
| 998 | if (fragment_last < candidate_vnb->ip.reass.range_first) |
| 999 | { |
| 1000 | // this fragment ends before candidate range without any overlap |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1001 | rc = ip4_full_reass_insert_range_in_chain (vm, reass, prev_range_bi, |
| 1002 | *bi0); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1003 | if (IP4_REASS_RC_OK != rc) |
| 1004 | { |
| 1005 | return rc; |
| 1006 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1007 | consumed = 1; |
| 1008 | } |
| 1009 | else |
| 1010 | { |
| 1011 | if (fragment_first >= candidate_vnb->ip.reass.range_first && |
| 1012 | fragment_last <= candidate_vnb->ip.reass.range_last) |
| 1013 | { |
| 1014 | // this fragment is a (sub)part of existing range, ignore it |
| 1015 | if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED)) |
| 1016 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1017 | ip4_full_reass_add_trace (vm, node, reass, *bi0, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1018 | RANGE_OVERLAP, 0, ~0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1019 | } |
| 1020 | break; |
| 1021 | } |
| 1022 | int discard_candidate = 0; |
| 1023 | if (fragment_first < candidate_vnb->ip.reass.range_first) |
| 1024 | { |
| 1025 | u32 overlap = |
| 1026 | fragment_last - candidate_vnb->ip.reass.range_first + 1; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1027 | if (overlap < ip4_full_reass_buffer_get_data_len (candidate_b)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1028 | { |
| 1029 | candidate_vnb->ip.reass.range_first += overlap; |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1030 | if (reass->data_len < overlap) |
| 1031 | { |
| 1032 | return IP4_REASS_RC_INTERNAL_ERROR; |
| 1033 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1034 | reass->data_len -= overlap; |
| 1035 | if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED)) |
| 1036 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1037 | ip4_full_reass_add_trace (vm, node, reass, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1038 | candidate_range_bi, |
| 1039 | RANGE_SHRINK, 0, ~0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1040 | } |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1041 | rc = ip4_full_reass_insert_range_in_chain ( |
| 1042 | vm, reass, prev_range_bi, *bi0); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1043 | if (IP4_REASS_RC_OK != rc) |
| 1044 | { |
| 1045 | return rc; |
| 1046 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1047 | consumed = 1; |
| 1048 | } |
| 1049 | else |
| 1050 | { |
| 1051 | discard_candidate = 1; |
| 1052 | } |
| 1053 | } |
| 1054 | else if (fragment_last > candidate_vnb->ip.reass.range_last) |
| 1055 | { |
| 1056 | u32 overlap = |
| 1057 | candidate_vnb->ip.reass.range_last - fragment_first + 1; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1058 | if (overlap < ip4_full_reass_buffer_get_data_len (candidate_b)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1059 | { |
| 1060 | fvnb->ip.reass.range_first += overlap; |
| 1061 | if (~0 != candidate_vnb->ip.reass.next_range_bi) |
| 1062 | { |
| 1063 | prev_range_bi = candidate_range_bi; |
| 1064 | candidate_range_bi = |
| 1065 | candidate_vnb->ip.reass.next_range_bi; |
| 1066 | continue; |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | // special case - last range discarded |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1071 | rc = ip4_full_reass_insert_range_in_chain ( |
| 1072 | vm, reass, candidate_range_bi, *bi0); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1073 | if (IP4_REASS_RC_OK != rc) |
| 1074 | { |
| 1075 | return rc; |
| 1076 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1077 | consumed = 1; |
| 1078 | } |
| 1079 | } |
| 1080 | else |
| 1081 | { |
| 1082 | discard_candidate = 1; |
| 1083 | } |
| 1084 | } |
| 1085 | else |
| 1086 | { |
| 1087 | discard_candidate = 1; |
| 1088 | } |
| 1089 | if (discard_candidate) |
| 1090 | { |
| 1091 | u32 next_range_bi = candidate_vnb->ip.reass.next_range_bi; |
| 1092 | // discard candidate range, probe next range |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1093 | rc = ip4_full_reass_remove_range_from_chain ( |
| 1094 | vm, node, reass, prev_range_bi, candidate_range_bi); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1095 | if (IP4_REASS_RC_OK != rc) |
| 1096 | { |
| 1097 | return rc; |
| 1098 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1099 | if (~0 != next_range_bi) |
| 1100 | { |
| 1101 | candidate_range_bi = next_range_bi; |
| 1102 | continue; |
| 1103 | } |
| 1104 | else |
| 1105 | { |
| 1106 | // special case - last range discarded |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1107 | rc = ip4_full_reass_insert_range_in_chain ( |
| 1108 | vm, reass, prev_range_bi, *bi0); |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1109 | if (IP4_REASS_RC_OK != rc) |
| 1110 | { |
| 1111 | return rc; |
| 1112 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1113 | consumed = 1; |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | break; |
| 1118 | } |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1119 | ++reass->fragments_n; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1120 | if (consumed) |
| 1121 | { |
| 1122 | if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED)) |
| 1123 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1124 | ip4_full_reass_add_trace (vm, node, reass, *bi0, RANGE_NEW, 0, ~0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | if (~0 != reass->last_packet_octet && |
| 1128 | reass->data_len == reass->last_packet_octet + 1) |
| 1129 | { |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 1130 | *handoff_thread_idx = reass->sendout_thread_index; |
Benoît Ganne | 2d0ebd7 | 2019-07-19 13:42:12 +0200 | [diff] [blame] | 1131 | int handoff = |
| 1132 | reass->memory_owner_thread_index != reass->sendout_thread_index; |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 1133 | rc = |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1134 | ip4_full_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0, |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1135 | is_custom); |
Benoît Ganne | 2d0ebd7 | 2019-07-19 13:42:12 +0200 | [diff] [blame] | 1136 | if (IP4_REASS_RC_OK == rc && handoff) |
Klement Sekera | 630ab58 | 2019-07-19 09:14:19 +0000 | [diff] [blame] | 1137 | { |
| 1138 | rc = IP4_REASS_RC_HANDOFF; |
| 1139 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1140 | } |
| 1141 | else |
| 1142 | { |
| 1143 | if (consumed) |
| 1144 | { |
| 1145 | *bi0 = ~0; |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1146 | if (reass->fragments_n > rm->max_reass_len) |
| 1147 | { |
| 1148 | rc = IP4_REASS_RC_TOO_MANY_FRAGMENTS; |
| 1149 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1150 | } |
| 1151 | else |
| 1152 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1153 | *next0 = IP4_FULL_REASS_NEXT_DROP; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1154 | *error0 = IP4_ERROR_REASS_DUPLICATE_FRAGMENT; |
| 1155 | } |
| 1156 | } |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1157 | return rc; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | always_inline uword |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1161 | ip4_full_reass_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 1162 | vlib_frame_t *frame, ip4_full_reass_node_type_t type, |
| 1163 | bool is_local) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1164 | { |
| 1165 | u32 *from = vlib_frame_vector_args (frame); |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1166 | u32 n_left, n_next = 0, to_next[VLIB_FRAME_SIZE]; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1167 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
| 1168 | ip4_full_reass_per_thread_t *rt = &rm->per_thread_data[vm->thread_index]; |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1169 | u16 nexts[VLIB_FRAME_SIZE]; |
| 1170 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1171 | clib_spinlock_lock (&rt->lock); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1172 | |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1173 | n_left = frame->n_vectors; |
| 1174 | while (n_left > 0) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1175 | { |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1176 | u32 bi0; |
| 1177 | vlib_buffer_t *b0; |
| 1178 | u32 next0; |
| 1179 | u32 error0 = IP4_ERROR_NONE; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1180 | |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1181 | bi0 = from[0]; |
| 1182 | b0 = vlib_get_buffer (vm, bi0); |
| 1183 | |
| 1184 | ip4_header_t *ip0 = vlib_buffer_get_current (b0); |
| 1185 | if (!ip4_get_fragment_more (ip0) && !ip4_get_fragment_offset (ip0)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1186 | { |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1187 | // this is a whole packet - no fragmentation |
| 1188 | if (CUSTOM != type) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1189 | { |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1190 | next0 = IP4_FULL_REASS_NEXT_INPUT; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1191 | } |
| 1192 | else |
| 1193 | { |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1194 | next0 = vnet_buffer (b0)->ip.reass.next_index; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1195 | } |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1196 | ip4_full_reass_add_trace (vm, node, NULL, bi0, PASSTHROUGH, 0, ~0); |
| 1197 | goto packet_enqueue; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1200 | if (is_local && !rm->is_local_reass_enabled) |
| 1201 | { |
| 1202 | next0 = IP4_FULL_REASS_NEXT_DROP; |
| 1203 | goto packet_enqueue; |
| 1204 | } |
| 1205 | |
| 1206 | const u32 fragment_first = ip4_get_fragment_offset_bytes (ip0); |
| 1207 | const u32 fragment_length = |
| 1208 | clib_net_to_host_u16 (ip0->length) - ip4_header_bytes (ip0); |
| 1209 | const u32 fragment_last = fragment_first + fragment_length - 1; |
| 1210 | |
| 1211 | /* Keep track of received fragments */ |
| 1212 | vlib_node_increment_counter (vm, node->node_index, |
| 1213 | IP4_ERROR_REASS_FRAGMENTS_RCVD, 1); |
| 1214 | |
| 1215 | if (fragment_first > fragment_last || |
| 1216 | fragment_first + fragment_length > UINT16_MAX - 20 || |
| 1217 | (fragment_length < 8 && // 8 is minimum frag length per RFC 791 |
| 1218 | ip4_get_fragment_more (ip0))) |
| 1219 | { |
| 1220 | next0 = IP4_FULL_REASS_NEXT_DROP; |
| 1221 | error0 = IP4_ERROR_REASS_MALFORMED_PACKET; |
| 1222 | goto packet_enqueue; |
| 1223 | } |
| 1224 | |
| 1225 | u32 fib_index = vec_elt (ip4_main.fib_index_by_sw_if_index, |
| 1226 | vnet_buffer (b0)->sw_if_index[VLIB_RX]); |
| 1227 | |
| 1228 | ip4_full_reass_kv_t kv = { .k.fib_index = fib_index, |
| 1229 | .k.src.as_u32 = ip0->src_address.as_u32, |
| 1230 | .k.dst.as_u32 = ip0->dst_address.as_u32, |
| 1231 | .k.frag_id = ip0->fragment_id, |
| 1232 | .k.proto = ip0->protocol |
| 1233 | |
| 1234 | }; |
| 1235 | u8 do_handoff = 0; |
| 1236 | |
| 1237 | ip4_full_reass_t *reass = |
| 1238 | ip4_full_reass_find_or_create (vm, node, rm, rt, &kv, &do_handoff); |
| 1239 | |
| 1240 | if (reass) |
| 1241 | { |
| 1242 | const u32 fragment_first = ip4_get_fragment_offset_bytes (ip0); |
| 1243 | if (0 == fragment_first) |
| 1244 | { |
| 1245 | reass->sendout_thread_index = vm->thread_index; |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | if (PREDICT_FALSE (do_handoff)) |
| 1250 | { |
| 1251 | next0 = IP4_FULL_REASS_NEXT_HANDOFF; |
| 1252 | vnet_buffer (b0)->ip.reass.owner_thread_index = |
| 1253 | kv.v.memory_owner_thread_index; |
| 1254 | } |
| 1255 | else if (reass) |
| 1256 | { |
| 1257 | u32 handoff_thread_idx; |
| 1258 | u32 counter = ~0; |
| 1259 | switch (ip4_full_reass_update (vm, node, rm, rt, reass, &bi0, &next0, |
| 1260 | &error0, CUSTOM == type, |
| 1261 | &handoff_thread_idx)) |
| 1262 | { |
| 1263 | case IP4_REASS_RC_OK: |
| 1264 | /* nothing to do here */ |
| 1265 | break; |
| 1266 | case IP4_REASS_RC_HANDOFF: |
| 1267 | next0 = IP4_FULL_REASS_NEXT_HANDOFF; |
| 1268 | b0 = vlib_get_buffer (vm, bi0); |
| 1269 | vnet_buffer (b0)->ip.reass.owner_thread_index = |
| 1270 | handoff_thread_idx; |
| 1271 | break; |
| 1272 | case IP4_REASS_RC_TOO_MANY_FRAGMENTS: |
| 1273 | counter = IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG; |
| 1274 | break; |
| 1275 | case IP4_REASS_RC_NO_BUF: |
| 1276 | counter = IP4_ERROR_REASS_NO_BUF; |
| 1277 | break; |
| 1278 | case IP4_REASS_RC_INTERNAL_ERROR: |
| 1279 | counter = IP4_ERROR_REASS_INTERNAL_ERROR; |
| 1280 | /* Sanitization is needed in internal error cases only, as |
| 1281 | * the incoming packet is already dropped in other cases, |
| 1282 | * also adding bi0 back to the reassembly list, fixes the |
| 1283 | * leaking of buffers during internal errors. |
| 1284 | * |
| 1285 | * Also it doesnt make sense to send these buffers custom |
| 1286 | * app, these fragments are with internal errors */ |
| 1287 | sanitize_reass_buffers_add_missing (vm, reass, &bi0); |
| 1288 | reass->error_next_index = ~0; |
| 1289 | break; |
| 1290 | } |
| 1291 | |
| 1292 | if (~0 != counter) |
| 1293 | { |
| 1294 | vlib_node_increment_counter (vm, node->node_index, counter, 1); |
| 1295 | ip4_full_reass_drop_all (vm, node, reass); |
| 1296 | ip4_full_reass_free (rm, rt, reass); |
| 1297 | goto next_packet; |
| 1298 | } |
| 1299 | } |
| 1300 | else |
| 1301 | { |
| 1302 | next0 = IP4_FULL_REASS_NEXT_DROP; |
| 1303 | error0 = IP4_ERROR_REASS_LIMIT_REACHED; |
| 1304 | } |
| 1305 | |
| 1306 | packet_enqueue: |
| 1307 | |
| 1308 | if (bi0 != ~0) |
| 1309 | { |
| 1310 | /* bi0 might have been updated by reass_finalize, reload */ |
| 1311 | b0 = vlib_get_buffer (vm, bi0); |
| 1312 | if (IP4_ERROR_NONE != error0) |
| 1313 | { |
| 1314 | b0->error = node->errors[error0]; |
| 1315 | } |
| 1316 | |
| 1317 | if (next0 == IP4_FULL_REASS_NEXT_HANDOFF) |
| 1318 | { |
| 1319 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1320 | { |
| 1321 | ip4_full_reass_add_trace ( |
| 1322 | vm, node, NULL, bi0, HANDOFF, 0, |
| 1323 | vnet_buffer (b0)->ip.reass.owner_thread_index); |
| 1324 | } |
| 1325 | } |
| 1326 | else if (FEATURE == type && IP4_ERROR_NONE == error0) |
| 1327 | { |
| 1328 | vnet_feature_next (&next0, b0); |
| 1329 | } |
| 1330 | |
| 1331 | /* Increment the counter to-custom-app also as this fragment is |
| 1332 | * also going to application */ |
| 1333 | if (CUSTOM == type) |
| 1334 | { |
| 1335 | vlib_node_increment_counter (vm, node->node_index, |
| 1336 | IP4_ERROR_REASS_TO_CUSTOM_APP, 1); |
| 1337 | } |
| 1338 | |
| 1339 | to_next[n_next] = bi0; |
| 1340 | nexts[n_next] = next0; |
| 1341 | n_next++; |
| 1342 | IP4_REASS_DEBUG_BUFFER (bi0, enqueue_next); |
| 1343 | } |
| 1344 | |
| 1345 | next_packet: |
| 1346 | from += 1; |
| 1347 | n_left -= 1; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1350 | clib_spinlock_unlock (&rt->lock); |
Damjan Marion | 65d25b4 | 2022-09-14 18:59:47 +0200 | [diff] [blame] | 1351 | |
| 1352 | vlib_buffer_enqueue_to_next (vm, node, to_next, nexts, n_next); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1353 | return frame->n_vectors; |
| 1354 | } |
| 1355 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1356 | VLIB_NODE_FN (ip4_full_reass_node) (vlib_main_t * vm, |
| 1357 | vlib_node_runtime_t * node, |
| 1358 | vlib_frame_t * frame) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1359 | { |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1360 | return ip4_full_reass_inline (vm, node, frame, NORMAL, false /* is_local */); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1363 | VLIB_REGISTER_NODE (ip4_full_reass_node) = { |
| 1364 | .name = "ip4-full-reassembly", |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1365 | .vector_size = sizeof (u32), |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1366 | .format_trace = format_ip4_full_reass_trace, |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1367 | .n_errors = IP4_N_ERROR, |
| 1368 | .error_counters = ip4_error_counters, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1369 | .n_next_nodes = IP4_FULL_REASS_N_NEXT, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1370 | .next_nodes = |
| 1371 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1372 | [IP4_FULL_REASS_NEXT_INPUT] = "ip4-input", |
| 1373 | [IP4_FULL_REASS_NEXT_DROP] = "ip4-drop", |
| 1374 | [IP4_FULL_REASS_NEXT_HANDOFF] = "ip4-full-reassembly-handoff", |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1375 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1376 | }, |
| 1377 | }; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1378 | |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1379 | VLIB_NODE_FN (ip4_local_full_reass_node) |
| 1380 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
| 1381 | { |
| 1382 | return ip4_full_reass_inline (vm, node, frame, NORMAL, true /* is_local */); |
| 1383 | } |
| 1384 | |
| 1385 | VLIB_REGISTER_NODE (ip4_local_full_reass_node) = { |
| 1386 | .name = "ip4-local-full-reassembly", |
| 1387 | .vector_size = sizeof (u32), |
| 1388 | .format_trace = format_ip4_full_reass_trace, |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1389 | .n_errors = IP4_N_ERROR, |
| 1390 | .error_counters = ip4_error_counters, |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1391 | .n_next_nodes = IP4_FULL_REASS_N_NEXT, |
| 1392 | .next_nodes = |
| 1393 | { |
| 1394 | [IP4_FULL_REASS_NEXT_INPUT] = "ip4-input", |
| 1395 | [IP4_FULL_REASS_NEXT_DROP] = "ip4-drop", |
| 1396 | [IP4_FULL_REASS_NEXT_HANDOFF] = "ip4-local-full-reassembly-handoff", |
| 1397 | |
| 1398 | }, |
| 1399 | }; |
| 1400 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1401 | VLIB_NODE_FN (ip4_full_reass_node_feature) (vlib_main_t * vm, |
| 1402 | vlib_node_runtime_t * node, |
| 1403 | vlib_frame_t * frame) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1404 | { |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1405 | return ip4_full_reass_inline (vm, node, frame, FEATURE, |
| 1406 | false /* is_local */); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1409 | VLIB_REGISTER_NODE (ip4_full_reass_node_feature) = { |
| 1410 | .name = "ip4-full-reassembly-feature", |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1411 | .vector_size = sizeof (u32), |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1412 | .format_trace = format_ip4_full_reass_trace, |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1413 | .n_errors = IP4_N_ERROR, |
| 1414 | .error_counters = ip4_error_counters, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1415 | .n_next_nodes = IP4_FULL_REASS_N_NEXT, |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1416 | .next_nodes = |
| 1417 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1418 | [IP4_FULL_REASS_NEXT_INPUT] = "ip4-input", |
| 1419 | [IP4_FULL_REASS_NEXT_DROP] = "ip4-drop", |
| 1420 | [IP4_FULL_REASS_NEXT_HANDOFF] = "ip4-full-reass-feature-hoff", |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1421 | }, |
| 1422 | }; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1423 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1424 | VNET_FEATURE_INIT (ip4_full_reass_feature, static) = { |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1425 | .arc_name = "ip4-unicast", |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1426 | .node_name = "ip4-full-reassembly-feature", |
Neale Ranns | 1404698 | 2019-07-29 14:49:52 +0000 | [diff] [blame] | 1427 | .runs_before = VNET_FEATURES ("ip4-lookup", |
Neale Ranns | 2be3eb6 | 2019-08-02 01:17:13 -0700 | [diff] [blame] | 1428 | "ipsec4-input-feature"), |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1429 | .runs_after = 0, |
| 1430 | }; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1431 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1432 | VLIB_NODE_FN (ip4_full_reass_node_custom) (vlib_main_t * vm, |
| 1433 | vlib_node_runtime_t * node, |
| 1434 | vlib_frame_t * frame) |
| 1435 | { |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1436 | return ip4_full_reass_inline (vm, node, frame, CUSTOM, false /* is_local */); |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1439 | VLIB_REGISTER_NODE (ip4_full_reass_node_custom) = { |
| 1440 | .name = "ip4-full-reassembly-custom", |
| 1441 | .vector_size = sizeof (u32), |
| 1442 | .format_trace = format_ip4_full_reass_trace, |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1443 | .n_errors = IP4_N_ERROR, |
| 1444 | .error_counters = ip4_error_counters, |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1445 | .n_next_nodes = IP4_FULL_REASS_N_NEXT, |
| 1446 | .next_nodes = |
| 1447 | { |
| 1448 | [IP4_FULL_REASS_NEXT_INPUT] = "ip4-input", |
| 1449 | [IP4_FULL_REASS_NEXT_DROP] = "ip4-drop", |
| 1450 | [IP4_FULL_REASS_NEXT_HANDOFF] = "ip4-full-reass-custom-hoff", |
| 1451 | }, |
| 1452 | }; |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1453 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1454 | VNET_FEATURE_INIT (ip4_full_reass_custom, static) = { |
| 1455 | .arc_name = "ip4-unicast", |
| 1456 | .node_name = "ip4-full-reassembly-feature", |
| 1457 | .runs_before = VNET_FEATURES ("ip4-lookup", |
| 1458 | "ipsec4-input-feature"), |
| 1459 | .runs_after = 0, |
| 1460 | }; |
| 1461 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1462 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1463 | #ifndef CLIB_MARCH_VARIANT |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1464 | uword |
| 1465 | ip4_full_reass_custom_register_next_node (uword node_index) |
| 1466 | { |
| 1467 | return vlib_node_add_next (vlib_get_main (), |
| 1468 | ip4_full_reass_node_custom.index, node_index); |
| 1469 | } |
| 1470 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1471 | always_inline u32 |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1472 | ip4_full_reass_get_nbuckets () |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1473 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1474 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1475 | u32 nbuckets; |
| 1476 | u8 i; |
| 1477 | |
Vijayabhaskar Katamreddy | 3fda200 | 2022-05-16 22:18:37 +0000 | [diff] [blame] | 1478 | /* need more mem with more workers */ |
| 1479 | nbuckets = (u32) (rm->max_reass_n * (vlib_num_workers () + 1) / |
| 1480 | IP4_REASS_HT_LOAD_FACTOR); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1481 | |
| 1482 | for (i = 0; i < 31; i++) |
| 1483 | if ((1 << i) >= nbuckets) |
| 1484 | break; |
| 1485 | nbuckets = 1 << i; |
| 1486 | |
| 1487 | return nbuckets; |
| 1488 | } |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1489 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1490 | |
| 1491 | typedef enum |
| 1492 | { |
| 1493 | IP4_EVENT_CONFIG_CHANGED = 1, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1494 | } ip4_full_reass_event_t; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1495 | |
| 1496 | typedef struct |
| 1497 | { |
| 1498 | int failure; |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1499 | clib_bihash_16_8_t *new_hash; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1500 | } ip4_rehash_cb_ctx; |
| 1501 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1502 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 1503 | static int |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1504 | ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1505 | { |
| 1506 | ip4_rehash_cb_ctx *ctx = _ctx; |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1507 | if (clib_bihash_add_del_16_8 (ctx->new_hash, kv, 1)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1508 | { |
| 1509 | ctx->failure = 1; |
| 1510 | } |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 1511 | return (BIHASH_WALK_CONTINUE); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1514 | static void |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1515 | ip4_full_reass_set_params (u32 timeout_ms, u32 max_reassemblies, |
| 1516 | u32 max_reassembly_length, |
| 1517 | u32 expire_walk_interval_ms) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1518 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1519 | ip4_full_reass_main.timeout_ms = timeout_ms; |
| 1520 | ip4_full_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC; |
| 1521 | ip4_full_reass_main.max_reass_n = max_reassemblies; |
| 1522 | ip4_full_reass_main.max_reass_len = max_reassembly_length; |
| 1523 | ip4_full_reass_main.expire_walk_interval_ms = expire_walk_interval_ms; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1524 | } |
| 1525 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1526 | vnet_api_error_t |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1527 | ip4_full_reass_set (u32 timeout_ms, u32 max_reassemblies, |
| 1528 | u32 max_reassembly_length, u32 expire_walk_interval_ms) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1529 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1530 | u32 old_nbuckets = ip4_full_reass_get_nbuckets (); |
| 1531 | ip4_full_reass_set_params (timeout_ms, max_reassemblies, |
| 1532 | max_reassembly_length, expire_walk_interval_ms); |
| 1533 | vlib_process_signal_event (ip4_full_reass_main.vlib_main, |
| 1534 | ip4_full_reass_main.ip4_full_reass_expire_node_idx, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1535 | IP4_EVENT_CONFIG_CHANGED, 0); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1536 | u32 new_nbuckets = ip4_full_reass_get_nbuckets (); |
| 1537 | if (ip4_full_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1538 | { |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1539 | clib_bihash_16_8_t new_hash; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1540 | clib_memset (&new_hash, 0, sizeof (new_hash)); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1541 | ip4_rehash_cb_ctx ctx; |
| 1542 | ctx.failure = 0; |
| 1543 | ctx.new_hash = &new_hash; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1544 | clib_bihash_init_16_8 (&new_hash, "ip4-dr", new_nbuckets, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1545 | new_nbuckets * 1024); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1546 | clib_bihash_foreach_key_value_pair_16_8 (&ip4_full_reass_main.hash, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1547 | ip4_rehash_cb, &ctx); |
| 1548 | if (ctx.failure) |
| 1549 | { |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1550 | clib_bihash_free_16_8 (&new_hash); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1551 | return -1; |
| 1552 | } |
| 1553 | else |
| 1554 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1555 | clib_bihash_free_16_8 (&ip4_full_reass_main.hash); |
| 1556 | clib_memcpy_fast (&ip4_full_reass_main.hash, &new_hash, |
| 1557 | sizeof (ip4_full_reass_main.hash)); |
| 1558 | clib_bihash_copied (&ip4_full_reass_main.hash, &new_hash); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | return 0; |
| 1562 | } |
| 1563 | |
| 1564 | vnet_api_error_t |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1565 | ip4_full_reass_get (u32 * timeout_ms, u32 * max_reassemblies, |
| 1566 | u32 * max_reassembly_length, |
| 1567 | u32 * expire_walk_interval_ms) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1568 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1569 | *timeout_ms = ip4_full_reass_main.timeout_ms; |
| 1570 | *max_reassemblies = ip4_full_reass_main.max_reass_n; |
| 1571 | *max_reassembly_length = ip4_full_reass_main.max_reass_len; |
| 1572 | *expire_walk_interval_ms = ip4_full_reass_main.expire_walk_interval_ms; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1573 | return 0; |
| 1574 | } |
| 1575 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1576 | static clib_error_t * |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1577 | ip4_full_reass_init_function (vlib_main_t * vm) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1578 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1579 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1580 | clib_error_t *error = 0; |
| 1581 | u32 nbuckets; |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1582 | vlib_node_t *node; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1583 | |
| 1584 | rm->vlib_main = vm; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1585 | |
Juraj Sloboda | cd80692 | 2018-10-10 10:15:54 +0200 | [diff] [blame] | 1586 | vec_validate (rm->per_thread_data, vlib_num_workers ()); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1587 | ip4_full_reass_per_thread_t *rt; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1588 | vec_foreach (rt, rm->per_thread_data) |
| 1589 | { |
| 1590 | clib_spinlock_init (&rt->lock); |
| 1591 | pool_alloc (rt->pool, rm->max_reass_n); |
| 1592 | } |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1593 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1594 | node = vlib_get_node_by_name (vm, (u8 *) "ip4-full-reassembly-expire-walk"); |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1595 | ASSERT (node); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1596 | rm->ip4_full_reass_expire_node_idx = node->index; |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1597 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1598 | ip4_full_reass_set_params (IP4_REASS_TIMEOUT_DEFAULT_MS, |
| 1599 | IP4_REASS_MAX_REASSEMBLIES_DEFAULT, |
| 1600 | IP4_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT, |
| 1601 | IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS); |
Klement Sekera | 3ecc221 | 2018-03-27 10:34:43 +0200 | [diff] [blame] | 1602 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1603 | nbuckets = ip4_full_reass_get_nbuckets (); |
| 1604 | clib_bihash_init_16_8 (&rm->hash, "ip4-dr", nbuckets, nbuckets * 1024); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1605 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1606 | rm->fq_index = vlib_frame_queue_main_init (ip4_full_reass_node.index, 0); |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1607 | rm->fq_local_index = |
| 1608 | vlib_frame_queue_main_init (ip4_local_full_reass_node.index, 0); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1609 | rm->fq_feature_index = |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1610 | vlib_frame_queue_main_init (ip4_full_reass_node_feature.index, 0); |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1611 | rm->fq_custom_index = |
| 1612 | vlib_frame_queue_main_init (ip4_full_reass_node_custom.index, 0); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1613 | |
Klement Sekera | 7b2e9fb | 2019-10-01 13:00:22 +0000 | [diff] [blame] | 1614 | rm->feature_use_refcount_per_intf = NULL; |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1615 | rm->is_local_reass_enabled = 1; |
| 1616 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1617 | return error; |
| 1618 | } |
| 1619 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1620 | VLIB_INIT_FUNCTION (ip4_full_reass_init_function); |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1621 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1622 | |
| 1623 | static uword |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1624 | ip4_full_reass_walk_expired (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 1625 | CLIB_UNUSED (vlib_frame_t *f)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1626 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1627 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1628 | uword event_type, *event_data = 0; |
| 1629 | |
| 1630 | while (true) |
| 1631 | { |
| 1632 | vlib_process_wait_for_event_or_clock (vm, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1633 | (f64) |
| 1634 | rm->expire_walk_interval_ms / |
| 1635 | (f64) MSEC_PER_SEC); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1636 | event_type = vlib_process_get_events (vm, &event_data); |
| 1637 | |
| 1638 | switch (event_type) |
| 1639 | { |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1640 | case ~0: |
| 1641 | /* no events => timeout */ |
| 1642 | /* fallthrough */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1643 | case IP4_EVENT_CONFIG_CHANGED: |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1644 | /* nothing to do here */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1645 | break; |
| 1646 | default: |
| 1647 | clib_warning ("BUG: event type 0x%wx", event_type); |
| 1648 | break; |
| 1649 | } |
| 1650 | f64 now = vlib_time_now (vm); |
| 1651 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1652 | ip4_full_reass_t *reass; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1653 | int *pool_indexes_to_free = NULL; |
| 1654 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1655 | uword thread_index = 0; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1656 | int index; |
Juraj Sloboda | cd80692 | 2018-10-10 10:15:54 +0200 | [diff] [blame] | 1657 | const uword nthreads = vlib_num_workers () + 1; |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 1658 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1659 | for (thread_index = 0; thread_index < nthreads; ++thread_index) |
| 1660 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1661 | ip4_full_reass_per_thread_t *rt = |
| 1662 | &rm->per_thread_data[thread_index]; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1663 | clib_spinlock_lock (&rt->lock); |
| 1664 | |
| 1665 | vec_reset_length (pool_indexes_to_free); |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 1666 | |
Vijayabhaskar Katamreddy | 8b874fc | 2022-05-13 13:07:19 +0000 | [diff] [blame] | 1667 | /* Pace the number of timeouts handled per thread,to avoid barrier |
| 1668 | * sync issues in real world scenarios */ |
| 1669 | |
| 1670 | u32 beg = rt->last_id; |
| 1671 | /* to ensure we walk at least once per sec per context */ |
| 1672 | u32 end = |
| 1673 | beg + (IP4_REASS_MAX_REASSEMBLIES_DEFAULT * |
| 1674 | IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS / MSEC_PER_SEC + |
| 1675 | 1); |
| 1676 | if (end > vec_len (rt->pool)) |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 1677 | { |
Vijayabhaskar Katamreddy | 8b874fc | 2022-05-13 13:07:19 +0000 | [diff] [blame] | 1678 | end = vec_len (rt->pool); |
| 1679 | rt->last_id = 0; |
| 1680 | } |
| 1681 | else |
| 1682 | { |
| 1683 | rt->last_id = end; |
| 1684 | } |
| 1685 | |
Vijayabhaskar Katamreddy | beafecf | 2022-05-19 17:07:22 +0000 | [diff] [blame] | 1686 | pool_foreach_stepping_index (index, beg, end, rt->pool) |
| 1687 | { |
| 1688 | reass = pool_elt_at_index (rt->pool, index); |
| 1689 | if (now > reass->last_heard + rm->timeout) |
| 1690 | { |
| 1691 | vec_add1 (pool_indexes_to_free, index); |
| 1692 | } |
| 1693 | } |
Vijayabhaskar Katamreddy | e0f901a | 2022-05-09 14:13:07 +0000 | [diff] [blame] | 1694 | |
Vijayabhaskar Katamreddy | 14a7442 | 2022-05-18 14:31:03 +0000 | [diff] [blame] | 1695 | if (vec_len (pool_indexes_to_free)) |
| 1696 | vlib_node_increment_counter (vm, node->node_index, |
| 1697 | IP4_ERROR_REASS_TIMEOUT, |
| 1698 | vec_len (pool_indexes_to_free)); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1699 | int *i; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1700 | vec_foreach (i, pool_indexes_to_free) |
| 1701 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1702 | ip4_full_reass_t *reass = pool_elt_at_index (rt->pool, i[0]); |
Damjan Marion | 42ed836 | 2022-09-14 17:40:24 +0200 | [diff] [blame] | 1703 | ip4_full_reass_drop_all (vm, node, reass); |
Klement Sekera | 42cec0e | 2021-08-02 16:14:15 +0200 | [diff] [blame] | 1704 | ip4_full_reass_free (rm, rt, reass); |
| 1705 | } |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1706 | |
| 1707 | clib_spinlock_unlock (&rt->lock); |
| 1708 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1709 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1710 | vec_free (pool_indexes_to_free); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1711 | if (event_data) |
| 1712 | { |
Damjan Marion | 8bea589 | 2022-04-04 22:40:45 +0200 | [diff] [blame] | 1713 | vec_set_len (event_data, 0); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1720 | VLIB_REGISTER_NODE (ip4_full_reass_expire_node) = { |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1721 | .function = ip4_full_reass_walk_expired, |
| 1722 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1723 | .name = "ip4-full-reassembly-expire-walk", |
| 1724 | .format_trace = format_ip4_full_reass_trace, |
| 1725 | .n_errors = IP4_N_ERROR, |
| 1726 | .error_counters = ip4_error_counters, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1727 | }; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1728 | |
| 1729 | static u8 * |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1730 | format_ip4_full_reass_key (u8 * s, va_list * args) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1731 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1732 | ip4_full_reass_key_t *key = va_arg (*args, ip4_full_reass_key_t *); |
| 1733 | s = |
Damjan Marion | 121a16a | 2022-09-14 16:00:09 +0200 | [diff] [blame] | 1734 | format (s, "fib_index: %u, src: %U, dst: %U, frag_id: %u, proto: %u", |
| 1735 | key->fib_index, format_ip4_address, &key->src, format_ip4_address, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1736 | &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1737 | return s; |
| 1738 | } |
| 1739 | |
| 1740 | static u8 * |
| 1741 | format_ip4_reass (u8 * s, va_list * args) |
| 1742 | { |
| 1743 | vlib_main_t *vm = va_arg (*args, vlib_main_t *); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1744 | ip4_full_reass_t *reass = va_arg (*args, ip4_full_reass_t *); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1745 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1746 | s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, " |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1747 | "last_packet_octet: %u, trace_op_counter: %u\n", |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1748 | reass->id, format_ip4_full_reass_key, &reass->key, |
| 1749 | reass->first_bi, reass->data_len, |
| 1750 | reass->last_packet_octet, reass->trace_op_counter); |
| 1751 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1752 | u32 bi = reass->first_bi; |
| 1753 | u32 counter = 0; |
| 1754 | while (~0 != bi) |
| 1755 | { |
| 1756 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 1757 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1758 | s = |
| 1759 | format (s, |
| 1760 | " #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, " |
| 1761 | "fragment[%u, %u]\n", counter, vnb->ip.reass.range_first, |
| 1762 | vnb->ip.reass.range_last, bi, |
| 1763 | ip4_full_reass_buffer_get_data_offset (b), |
| 1764 | ip4_full_reass_buffer_get_data_len (b), |
| 1765 | vnb->ip.reass.fragment_first, vnb->ip.reass.fragment_last); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1766 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1767 | { |
| 1768 | bi = b->next_buffer; |
| 1769 | } |
| 1770 | else |
| 1771 | { |
| 1772 | bi = ~0; |
| 1773 | } |
| 1774 | } |
| 1775 | return s; |
| 1776 | } |
| 1777 | |
| 1778 | static clib_error_t * |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1779 | show_ip4_reass (vlib_main_t * vm, |
| 1780 | unformat_input_t * input, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1781 | CLIB_UNUSED (vlib_cli_command_t * lmd)) |
| 1782 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1783 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1784 | |
| 1785 | vlib_cli_output (vm, "---------------------"); |
| 1786 | vlib_cli_output (vm, "IP4 reassembly status"); |
| 1787 | vlib_cli_output (vm, "---------------------"); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1788 | bool details = false; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1789 | if (unformat (input, "details")) |
| 1790 | { |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1791 | details = true; |
| 1792 | } |
| 1793 | |
| 1794 | u32 sum_reass_n = 0; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1795 | ip4_full_reass_t *reass; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1796 | uword thread_index; |
Juraj Sloboda | cd80692 | 2018-10-10 10:15:54 +0200 | [diff] [blame] | 1797 | const uword nthreads = vlib_num_workers () + 1; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1798 | for (thread_index = 0; thread_index < nthreads; ++thread_index) |
| 1799 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1800 | ip4_full_reass_per_thread_t *rt = &rm->per_thread_data[thread_index]; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1801 | clib_spinlock_lock (&rt->lock); |
| 1802 | if (details) |
| 1803 | { |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1804 | pool_foreach (reass, rt->pool) { |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1805 | vlib_cli_output (vm, "%U", format_ip4_reass, vm, reass); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1806 | } |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1807 | } |
| 1808 | sum_reass_n += rt->reass_n; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1809 | clib_spinlock_unlock (&rt->lock); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1810 | } |
| 1811 | vlib_cli_output (vm, "---------------------"); |
Vladimir Ratnikov | a877cf9 | 2019-12-21 06:27:52 -0500 | [diff] [blame] | 1812 | vlib_cli_output (vm, "Current full IP4 reassemblies count: %lu\n", |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1813 | (long unsigned) sum_reass_n); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1814 | vlib_cli_output (vm, |
Vladimir Ratnikov | a877cf9 | 2019-12-21 06:27:52 -0500 | [diff] [blame] | 1815 | "Maximum configured concurrent full IP4 reassemblies per worker-thread: %lu\n", |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1816 | (long unsigned) rm->max_reass_n); |
Vladimir Ratnikov | a877cf9 | 2019-12-21 06:27:52 -0500 | [diff] [blame] | 1817 | vlib_cli_output (vm, |
Anton Nikolaev | 74a4a70 | 2021-02-17 14:45:40 +0500 | [diff] [blame] | 1818 | "Maximum configured amount of fragments " |
| 1819 | "per full IP4 reassembly: %lu\n", |
| 1820 | (long unsigned) rm->max_reass_len); |
| 1821 | vlib_cli_output (vm, |
Vladimir Ratnikov | a877cf9 | 2019-12-21 06:27:52 -0500 | [diff] [blame] | 1822 | "Maximum configured full IP4 reassembly timeout: %lums\n", |
| 1823 | (long unsigned) rm->timeout_ms); |
| 1824 | vlib_cli_output (vm, |
| 1825 | "Maximum configured full IP4 reassembly expire walk interval: %lums\n", |
| 1826 | (long unsigned) rm->expire_walk_interval_ms); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1827 | return 0; |
| 1828 | } |
| 1829 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1830 | VLIB_CLI_COMMAND (show_ip4_full_reass_cmd, static) = { |
| 1831 | .path = "show ip4-full-reassembly", |
| 1832 | .short_help = "show ip4-full-reassembly [details]", |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1833 | .function = show_ip4_reass, |
| 1834 | }; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1835 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1836 | #ifndef CLIB_MARCH_VARIANT |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1837 | vnet_api_error_t |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1838 | ip4_full_reass_enable_disable (u32 sw_if_index, u8 enable_disable) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1839 | { |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1840 | return vnet_feature_enable_disable ("ip4-unicast", |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1841 | "ip4-full-reassembly-feature", |
| 1842 | sw_if_index, enable_disable, 0, 0); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1843 | } |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1844 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1845 | |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1846 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1847 | #define foreach_ip4_full_reass_handoff_error \ |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1848 | _(CONGESTION_DROP, "congestion drop") |
| 1849 | |
| 1850 | |
| 1851 | typedef enum |
| 1852 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1853 | #define _(sym,str) IP4_FULL_REASS_HANDOFF_ERROR_##sym, |
| 1854 | foreach_ip4_full_reass_handoff_error |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1855 | #undef _ |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1856 | IP4_FULL_REASS_HANDOFF_N_ERROR, |
| 1857 | } ip4_full_reass_handoff_error_t; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1858 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1859 | static char *ip4_full_reass_handoff_error_strings[] = { |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1860 | #define _(sym,string) string, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1861 | foreach_ip4_full_reass_handoff_error |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1862 | #undef _ |
| 1863 | }; |
| 1864 | |
| 1865 | typedef struct |
| 1866 | { |
| 1867 | u32 next_worker_index; |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1868 | } ip4_full_reass_handoff_trace_t; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1869 | |
| 1870 | static u8 * |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1871 | format_ip4_full_reass_handoff_trace (u8 * s, va_list * args) |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1872 | { |
| 1873 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 1874 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1875 | ip4_full_reass_handoff_trace_t *t = |
| 1876 | va_arg (*args, ip4_full_reass_handoff_trace_t *); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1877 | |
| 1878 | s = |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1879 | format (s, "ip4-full-reassembly-handoff: next-worker %d", |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1880 | t->next_worker_index); |
| 1881 | |
| 1882 | return s; |
| 1883 | } |
| 1884 | |
| 1885 | always_inline uword |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1886 | ip4_full_reass_handoff_node_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 1887 | vlib_frame_t *frame, |
| 1888 | ip4_full_reass_node_type_t type, |
| 1889 | bool is_local) |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1890 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1891 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1892 | |
| 1893 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 1894 | u32 n_enq, n_left_from, *from; |
| 1895 | u16 thread_indices[VLIB_FRAME_SIZE], *ti; |
| 1896 | u32 fq_index; |
| 1897 | |
| 1898 | from = vlib_frame_vector_args (frame); |
| 1899 | n_left_from = frame->n_vectors; |
| 1900 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 1901 | |
| 1902 | b = bufs; |
| 1903 | ti = thread_indices; |
| 1904 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1905 | switch (type) |
| 1906 | { |
| 1907 | case NORMAL: |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1908 | if (is_local) |
| 1909 | { |
| 1910 | fq_index = rm->fq_local_index; |
| 1911 | } |
| 1912 | else |
| 1913 | { |
| 1914 | fq_index = rm->fq_index; |
| 1915 | } |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | case FEATURE: |
| 1918 | fq_index = rm->fq_feature_index; |
| 1919 | break; |
| 1920 | case CUSTOM: |
| 1921 | fq_index = rm->fq_custom_index; |
| 1922 | break; |
| 1923 | default: |
| 1924 | clib_warning ("Unexpected `type' (%d)!", type); |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 1925 | } |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1926 | |
| 1927 | while (n_left_from > 0) |
| 1928 | { |
Klement Sekera | de34c35 | 2019-06-25 11:19:22 +0000 | [diff] [blame] | 1929 | ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1930 | |
| 1931 | if (PREDICT_FALSE |
| 1932 | ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 1933 | && (b[0]->flags & VLIB_BUFFER_IS_TRACED))) |
| 1934 | { |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1935 | ip4_full_reass_handoff_trace_t *t = |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1936 | vlib_add_trace (vm, node, b[0], sizeof (*t)); |
| 1937 | t->next_worker_index = ti[0]; |
| 1938 | } |
| 1939 | |
| 1940 | n_left_from -= 1; |
| 1941 | ti += 1; |
| 1942 | b += 1; |
| 1943 | } |
Damjan Marion | 9e7a0b4 | 2021-05-14 14:50:01 +0200 | [diff] [blame] | 1944 | n_enq = vlib_buffer_enqueue_to_thread (vm, node, fq_index, from, |
| 1945 | thread_indices, frame->n_vectors, 1); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1946 | |
| 1947 | if (n_enq < frame->n_vectors) |
| 1948 | vlib_node_increment_counter (vm, node->node_index, |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1949 | IP4_FULL_REASS_HANDOFF_ERROR_CONGESTION_DROP, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1950 | frame->n_vectors - n_enq); |
| 1951 | return frame->n_vectors; |
| 1952 | } |
| 1953 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1954 | VLIB_NODE_FN (ip4_full_reass_handoff_node) (vlib_main_t * vm, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1955 | vlib_node_runtime_t * node, |
| 1956 | vlib_frame_t * frame) |
| 1957 | { |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1958 | return ip4_full_reass_handoff_node_inline (vm, node, frame, NORMAL, |
| 1959 | false /* is_local */); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1963 | VLIB_REGISTER_NODE (ip4_full_reass_handoff_node) = { |
| 1964 | .name = "ip4-full-reassembly-handoff", |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1965 | .vector_size = sizeof (u32), |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1966 | .n_errors = ARRAY_LEN(ip4_full_reass_handoff_error_strings), |
| 1967 | .error_strings = ip4_full_reass_handoff_error_strings, |
| 1968 | .format_trace = format_ip4_full_reass_handoff_trace, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1969 | |
| 1970 | .n_next_nodes = 1, |
| 1971 | |
| 1972 | .next_nodes = { |
| 1973 | [0] = "error-drop", |
| 1974 | }, |
| 1975 | }; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1976 | |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 1977 | VLIB_NODE_FN (ip4_local_full_reass_handoff_node) |
| 1978 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
| 1979 | { |
| 1980 | return ip4_full_reass_handoff_node_inline (vm, node, frame, NORMAL, |
| 1981 | true /* is_local */); |
| 1982 | } |
| 1983 | |
| 1984 | VLIB_REGISTER_NODE (ip4_local_full_reass_handoff_node) = { |
| 1985 | .name = "ip4-local-full-reassembly-handoff", |
| 1986 | .vector_size = sizeof (u32), |
| 1987 | .n_errors = ARRAY_LEN(ip4_full_reass_handoff_error_strings), |
| 1988 | .error_strings = ip4_full_reass_handoff_error_strings, |
| 1989 | .format_trace = format_ip4_full_reass_handoff_trace, |
| 1990 | |
| 1991 | .n_next_nodes = 1, |
| 1992 | |
| 1993 | .next_nodes = { |
| 1994 | [0] = "error-drop", |
| 1995 | }, |
| 1996 | }; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1997 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 1998 | VLIB_NODE_FN (ip4_full_reass_feature_handoff_node) (vlib_main_t * vm, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1999 | vlib_node_runtime_t * |
| 2000 | node, |
| 2001 | vlib_frame_t * frame) |
| 2002 | { |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 2003 | return ip4_full_reass_handoff_node_inline (vm, node, frame, FEATURE, |
| 2004 | false /* is_local */); |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 2005 | } |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 2006 | |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 2007 | VLIB_REGISTER_NODE (ip4_full_reass_feature_handoff_node) = { |
| 2008 | .name = "ip4-full-reass-feature-hoff", |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 2009 | .vector_size = sizeof (u32), |
Klement Sekera | 896c896 | 2019-06-24 11:52:49 +0000 | [diff] [blame] | 2010 | .n_errors = ARRAY_LEN(ip4_full_reass_handoff_error_strings), |
| 2011 | .error_strings = ip4_full_reass_handoff_error_strings, |
| 2012 | .format_trace = format_ip4_full_reass_handoff_trace, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 2013 | |
| 2014 | .n_next_nodes = 1, |
| 2015 | |
| 2016 | .next_nodes = { |
| 2017 | [0] = "error-drop", |
| 2018 | }, |
| 2019 | }; |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 2020 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 2021 | VLIB_NODE_FN (ip4_full_reass_custom_handoff_node) (vlib_main_t * vm, |
| 2022 | vlib_node_runtime_t * |
| 2023 | node, |
| 2024 | vlib_frame_t * frame) |
| 2025 | { |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 2026 | return ip4_full_reass_handoff_node_inline (vm, node, frame, CUSTOM, |
| 2027 | false /* is_local */); |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 2028 | } |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 2029 | |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 2030 | VLIB_REGISTER_NODE (ip4_full_reass_custom_handoff_node) = { |
| 2031 | .name = "ip4-full-reass-custom-hoff", |
| 2032 | .vector_size = sizeof (u32), |
| 2033 | .n_errors = ARRAY_LEN(ip4_full_reass_handoff_error_strings), |
| 2034 | .error_strings = ip4_full_reass_handoff_error_strings, |
| 2035 | .format_trace = format_ip4_full_reass_handoff_trace, |
| 2036 | |
| 2037 | .n_next_nodes = 1, |
| 2038 | |
| 2039 | .next_nodes = { |
| 2040 | [0] = "error-drop", |
| 2041 | }, |
| 2042 | }; |
Klement Sekera | fe8371f | 2020-09-10 12:03:54 +0000 | [diff] [blame] | 2043 | |
Klement Sekera | 7b2e9fb | 2019-10-01 13:00:22 +0000 | [diff] [blame] | 2044 | #ifndef CLIB_MARCH_VARIANT |
| 2045 | int |
| 2046 | ip4_full_reass_enable_disable_with_refcnt (u32 sw_if_index, int is_enable) |
| 2047 | { |
| 2048 | ip4_full_reass_main_t *rm = &ip4_full_reass_main; |
| 2049 | vec_validate (rm->feature_use_refcount_per_intf, sw_if_index); |
| 2050 | if (is_enable) |
| 2051 | { |
| 2052 | if (!rm->feature_use_refcount_per_intf[sw_if_index]) |
| 2053 | { |
| 2054 | ++rm->feature_use_refcount_per_intf[sw_if_index]; |
| 2055 | return vnet_feature_enable_disable ("ip4-unicast", |
| 2056 | "ip4-full-reassembly-feature", |
| 2057 | sw_if_index, 1, 0, 0); |
| 2058 | } |
| 2059 | ++rm->feature_use_refcount_per_intf[sw_if_index]; |
| 2060 | } |
| 2061 | else |
| 2062 | { |
| 2063 | --rm->feature_use_refcount_per_intf[sw_if_index]; |
| 2064 | if (!rm->feature_use_refcount_per_intf[sw_if_index]) |
| 2065 | return vnet_feature_enable_disable ("ip4-unicast", |
| 2066 | "ip4-full-reassembly-feature", |
| 2067 | sw_if_index, 0, 0, 0); |
| 2068 | } |
| 2069 | return -1; |
| 2070 | } |
Klement Sekera | 01c1fa4 | 2021-12-14 18:25:11 +0000 | [diff] [blame] | 2071 | |
| 2072 | void |
| 2073 | ip4_local_full_reass_enable_disable (int enable) |
| 2074 | { |
| 2075 | if (enable) |
| 2076 | { |
| 2077 | ip4_full_reass_main.is_local_reass_enabled = 1; |
| 2078 | } |
| 2079 | else |
| 2080 | { |
| 2081 | ip4_full_reass_main.is_local_reass_enabled = 0; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | int |
| 2086 | ip4_local_full_reass_enabled () |
| 2087 | { |
| 2088 | return ip4_full_reass_main.is_local_reass_enabled; |
| 2089 | } |
| 2090 | |
Klement Sekera | 7b2e9fb | 2019-10-01 13:00:22 +0000 | [diff] [blame] | 2091 | #endif |
| 2092 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 2093 | /* |
| 2094 | * fd.io coding-style-patch-verification: ON |
| 2095 | * |
| 2096 | * Local Variables: |
| 2097 | * eval: (c-set-style "gnu") |
| 2098 | * End: |
| 2099 | */ |