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