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