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