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