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