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