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