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