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