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