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