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