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