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", |
Neale Ranns | 1404698 | 2019-07-29 14:49:52 +0000 | [diff] [blame] | 1205 | .runs_before = VNET_FEATURES ("ip4-lookup", |
Neale Ranns | 2be3eb6 | 2019-08-02 01:17:13 -0700 | [diff] [blame] | 1206 | "ipsec4-input-feature"), |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1207 | .runs_after = 0, |
| 1208 | }; |
| 1209 | /* *INDENT-ON* */ |
| 1210 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1211 | #ifndef CLIB_MARCH_VARIANT |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1212 | always_inline u32 |
| 1213 | ip4_reass_get_nbuckets () |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1214 | { |
| 1215 | ip4_reass_main_t *rm = &ip4_reass_main; |
| 1216 | u32 nbuckets; |
| 1217 | u8 i; |
| 1218 | |
| 1219 | nbuckets = (u32) (rm->max_reass_n / IP4_REASS_HT_LOAD_FACTOR); |
| 1220 | |
| 1221 | for (i = 0; i < 31; i++) |
| 1222 | if ((1 << i) >= nbuckets) |
| 1223 | break; |
| 1224 | nbuckets = 1 << i; |
| 1225 | |
| 1226 | return nbuckets; |
| 1227 | } |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1228 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1229 | |
| 1230 | typedef enum |
| 1231 | { |
| 1232 | IP4_EVENT_CONFIG_CHANGED = 1, |
| 1233 | } ip4_reass_event_t; |
| 1234 | |
| 1235 | typedef struct |
| 1236 | { |
| 1237 | int failure; |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1238 | clib_bihash_16_8_t *new_hash; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1239 | } ip4_rehash_cb_ctx; |
| 1240 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1241 | #ifndef CLIB_MARCH_VARIANT |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1242 | static void |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1243 | ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1244 | { |
| 1245 | ip4_rehash_cb_ctx *ctx = _ctx; |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1246 | if (clib_bihash_add_del_16_8 (ctx->new_hash, kv, 1)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1247 | { |
| 1248 | ctx->failure = 1; |
| 1249 | } |
| 1250 | } |
| 1251 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1252 | static void |
| 1253 | ip4_reass_set_params (u32 timeout_ms, u32 max_reassemblies, |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1254 | u32 max_reassembly_length, u32 expire_walk_interval_ms) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1255 | { |
| 1256 | ip4_reass_main.timeout_ms = timeout_ms; |
| 1257 | ip4_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC; |
| 1258 | ip4_reass_main.max_reass_n = max_reassemblies; |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1259 | ip4_reass_main.max_reass_len = max_reassembly_length; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1260 | ip4_reass_main.expire_walk_interval_ms = expire_walk_interval_ms; |
| 1261 | } |
| 1262 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1263 | vnet_api_error_t |
| 1264 | ip4_reass_set (u32 timeout_ms, u32 max_reassemblies, |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1265 | u32 max_reassembly_length, u32 expire_walk_interval_ms) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1266 | { |
| 1267 | u32 old_nbuckets = ip4_reass_get_nbuckets (); |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1268 | ip4_reass_set_params (timeout_ms, max_reassemblies, max_reassembly_length, |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1269 | expire_walk_interval_ms); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1270 | vlib_process_signal_event (ip4_reass_main.vlib_main, |
| 1271 | ip4_reass_main.ip4_reass_expire_node_idx, |
| 1272 | IP4_EVENT_CONFIG_CHANGED, 0); |
| 1273 | u32 new_nbuckets = ip4_reass_get_nbuckets (); |
Klement Sekera | 3ecc221 | 2018-03-27 10:34:43 +0200 | [diff] [blame] | 1274 | if (ip4_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1275 | { |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1276 | clib_bihash_16_8_t new_hash; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1277 | clib_memset (&new_hash, 0, sizeof (new_hash)); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1278 | ip4_rehash_cb_ctx ctx; |
| 1279 | ctx.failure = 0; |
| 1280 | ctx.new_hash = &new_hash; |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1281 | clib_bihash_init_16_8 (&new_hash, "ip4-reass", new_nbuckets, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1282 | new_nbuckets * 1024); |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1283 | clib_bihash_foreach_key_value_pair_16_8 (&ip4_reass_main.hash, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1284 | ip4_rehash_cb, &ctx); |
| 1285 | if (ctx.failure) |
| 1286 | { |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1287 | clib_bihash_free_16_8 (&new_hash); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1288 | return -1; |
| 1289 | } |
| 1290 | else |
| 1291 | { |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1292 | clib_bihash_free_16_8 (&ip4_reass_main.hash); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1293 | clib_memcpy_fast (&ip4_reass_main.hash, &new_hash, |
| 1294 | sizeof (ip4_reass_main.hash)); |
Dave Barach | 32dcd3b | 2019-07-08 12:25:38 -0400 | [diff] [blame] | 1295 | clib_bihash_copied (&ip4_reass_main.hash, &new_hash); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | vnet_api_error_t |
| 1302 | ip4_reass_get (u32 * timeout_ms, u32 * max_reassemblies, |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1303 | u32 * max_reassembly_length, u32 * expire_walk_interval_ms) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1304 | { |
| 1305 | *timeout_ms = ip4_reass_main.timeout_ms; |
| 1306 | *max_reassemblies = ip4_reass_main.max_reass_n; |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1307 | *max_reassembly_length = ip4_reass_main.max_reass_len; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1308 | *expire_walk_interval_ms = ip4_reass_main.expire_walk_interval_ms; |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1312 | static clib_error_t * |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1313 | ip4_reass_init_function (vlib_main_t * vm) |
| 1314 | { |
| 1315 | ip4_reass_main_t *rm = &ip4_reass_main; |
| 1316 | clib_error_t *error = 0; |
| 1317 | u32 nbuckets; |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1318 | vlib_node_t *node; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1319 | |
| 1320 | rm->vlib_main = vm; |
| 1321 | rm->vnet_main = vnet_get_main (); |
| 1322 | |
Juraj Sloboda | cd80692 | 2018-10-10 10:15:54 +0200 | [diff] [blame] | 1323 | vec_validate (rm->per_thread_data, vlib_num_workers ()); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1324 | ip4_reass_per_thread_t *rt; |
| 1325 | vec_foreach (rt, rm->per_thread_data) |
| 1326 | { |
| 1327 | clib_spinlock_init (&rt->lock); |
| 1328 | pool_alloc (rt->pool, rm->max_reass_n); |
| 1329 | } |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1330 | |
| 1331 | node = vlib_get_node_by_name (vm, (u8 *) "ip4-reassembly-expire-walk"); |
| 1332 | ASSERT (node); |
| 1333 | rm->ip4_reass_expire_node_idx = node->index; |
| 1334 | |
Klement Sekera | 3ecc221 | 2018-03-27 10:34:43 +0200 | [diff] [blame] | 1335 | ip4_reass_set_params (IP4_REASS_TIMEOUT_DEFAULT_MS, |
| 1336 | IP4_REASS_MAX_REASSEMBLIES_DEFAULT, |
Klement Sekera | 3a343d4 | 2019-05-16 14:35:46 +0200 | [diff] [blame] | 1337 | IP4_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT, |
Klement Sekera | 3ecc221 | 2018-03-27 10:34:43 +0200 | [diff] [blame] | 1338 | IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS); |
| 1339 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1340 | nbuckets = ip4_reass_get_nbuckets (); |
Klement Sekera | 8dcfed5 | 2018-06-28 11:16:15 +0200 | [diff] [blame] | 1341 | clib_bihash_init_16_8 (&rm->hash, "ip4-reass", nbuckets, nbuckets * 1024); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1342 | |
Dave Barach | 1403fcd | 2018-02-05 09:45:43 -0500 | [diff] [blame] | 1343 | node = vlib_get_node_by_name (vm, (u8 *) "ip4-drop"); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1344 | ASSERT (node); |
| 1345 | rm->ip4_drop_idx = node->index; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1346 | |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1347 | rm->fq_index = vlib_frame_queue_main_init (ip4_reass_node.index, 0); |
| 1348 | rm->fq_feature_index = |
| 1349 | vlib_frame_queue_main_init (ip4_reass_node_feature.index, 0); |
| 1350 | |
| 1351 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1352 | return error; |
| 1353 | } |
| 1354 | |
| 1355 | VLIB_INIT_FUNCTION (ip4_reass_init_function); |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1356 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1357 | |
| 1358 | static uword |
| 1359 | ip4_reass_walk_expired (vlib_main_t * vm, |
| 1360 | vlib_node_runtime_t * node, vlib_frame_t * f) |
| 1361 | { |
| 1362 | ip4_reass_main_t *rm = &ip4_reass_main; |
| 1363 | uword event_type, *event_data = 0; |
| 1364 | |
| 1365 | while (true) |
| 1366 | { |
| 1367 | vlib_process_wait_for_event_or_clock (vm, |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1368 | (f64) |
| 1369 | rm->expire_walk_interval_ms / |
| 1370 | (f64) MSEC_PER_SEC); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1371 | event_type = vlib_process_get_events (vm, &event_data); |
| 1372 | |
| 1373 | switch (event_type) |
| 1374 | { |
| 1375 | case ~0: /* no events => timeout */ |
| 1376 | /* nothing to do here */ |
| 1377 | break; |
| 1378 | case IP4_EVENT_CONFIG_CHANGED: |
| 1379 | break; |
| 1380 | default: |
| 1381 | clib_warning ("BUG: event type 0x%wx", event_type); |
| 1382 | break; |
| 1383 | } |
| 1384 | f64 now = vlib_time_now (vm); |
| 1385 | |
| 1386 | ip4_reass_t *reass; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1387 | int *pool_indexes_to_free = NULL; |
| 1388 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1389 | uword thread_index = 0; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1390 | int index; |
Juraj Sloboda | cd80692 | 2018-10-10 10:15:54 +0200 | [diff] [blame] | 1391 | const uword nthreads = vlib_num_workers () + 1; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1392 | for (thread_index = 0; thread_index < nthreads; ++thread_index) |
| 1393 | { |
| 1394 | ip4_reass_per_thread_t *rt = &rm->per_thread_data[thread_index]; |
| 1395 | clib_spinlock_lock (&rt->lock); |
| 1396 | |
| 1397 | vec_reset_length (pool_indexes_to_free); |
| 1398 | /* *INDENT-OFF* */ |
| 1399 | pool_foreach_index (index, rt->pool, ({ |
| 1400 | reass = pool_elt_at_index (rt->pool, index); |
| 1401 | if (now > reass->last_heard + rm->timeout) |
| 1402 | { |
| 1403 | vec_add1 (pool_indexes_to_free, index); |
| 1404 | } |
| 1405 | })); |
| 1406 | /* *INDENT-ON* */ |
| 1407 | int *i; |
| 1408 | /* *INDENT-OFF* */ |
| 1409 | vec_foreach (i, pool_indexes_to_free) |
| 1410 | { |
| 1411 | ip4_reass_t *reass = pool_elt_at_index (rt->pool, i[0]); |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 1412 | ip4_reass_drop_all (vm, node, rm, reass); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1413 | ip4_reass_free (rm, rt, reass); |
| 1414 | } |
| 1415 | /* *INDENT-ON* */ |
| 1416 | |
| 1417 | clib_spinlock_unlock (&rt->lock); |
| 1418 | } |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1419 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1420 | vec_free (pool_indexes_to_free); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1421 | if (event_data) |
| 1422 | { |
| 1423 | _vec_len (event_data) = 0; |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1430 | /* *INDENT-OFF* */ |
| 1431 | VLIB_REGISTER_NODE (ip4_reass_expire_node, static) = { |
| 1432 | .function = ip4_reass_walk_expired, |
| 1433 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1434 | .name = "ip4-reassembly-expire-walk", |
| 1435 | .format_trace = format_ip4_reass_trace, |
| 1436 | .n_errors = ARRAY_LEN (ip4_reassembly_error_strings), |
| 1437 | .error_strings = ip4_reassembly_error_strings, |
| 1438 | |
| 1439 | }; |
| 1440 | /* *INDENT-ON* */ |
| 1441 | |
| 1442 | static u8 * |
| 1443 | format_ip4_reass_key (u8 * s, va_list * args) |
| 1444 | { |
| 1445 | ip4_reass_key_t *key = va_arg (*args, ip4_reass_key_t *); |
| 1446 | s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u", |
| 1447 | key->xx_id, format_ip4_address, &key->src, format_ip4_address, |
| 1448 | &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto); |
| 1449 | return s; |
| 1450 | } |
| 1451 | |
| 1452 | static u8 * |
| 1453 | format_ip4_reass (u8 * s, va_list * args) |
| 1454 | { |
| 1455 | vlib_main_t *vm = va_arg (*args, vlib_main_t *); |
| 1456 | ip4_reass_t *reass = va_arg (*args, ip4_reass_t *); |
| 1457 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1458 | 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] | 1459 | "last_packet_octet: %u, trace_op_counter: %u\n", |
| 1460 | reass->id, format_ip4_reass_key, &reass->key, reass->first_bi, |
| 1461 | reass->data_len, reass->last_packet_octet, |
| 1462 | reass->trace_op_counter); |
| 1463 | u32 bi = reass->first_bi; |
| 1464 | u32 counter = 0; |
| 1465 | while (~0 != bi) |
| 1466 | { |
| 1467 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 1468 | vnet_buffer_opaque_t *vnb = vnet_buffer (b); |
| 1469 | s = format (s, " #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, " |
| 1470 | "fragment[%u, %u]\n", |
| 1471 | counter, vnb->ip.reass.range_first, |
| 1472 | vnb->ip.reass.range_last, bi, |
Klement Sekera | d0f70a3 | 2018-12-14 17:24:13 +0100 | [diff] [blame] | 1473 | ip4_reass_buffer_get_data_offset (b), |
| 1474 | ip4_reass_buffer_get_data_len (b), |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1475 | vnb->ip.reass.fragment_first, vnb->ip.reass.fragment_last); |
| 1476 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1477 | { |
| 1478 | bi = b->next_buffer; |
| 1479 | } |
| 1480 | else |
| 1481 | { |
| 1482 | bi = ~0; |
| 1483 | } |
| 1484 | } |
| 1485 | return s; |
| 1486 | } |
| 1487 | |
| 1488 | static clib_error_t * |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1489 | show_ip4_reass (vlib_main_t * vm, |
| 1490 | unformat_input_t * input, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1491 | CLIB_UNUSED (vlib_cli_command_t * lmd)) |
| 1492 | { |
| 1493 | ip4_reass_main_t *rm = &ip4_reass_main; |
| 1494 | |
| 1495 | vlib_cli_output (vm, "---------------------"); |
| 1496 | vlib_cli_output (vm, "IP4 reassembly status"); |
| 1497 | vlib_cli_output (vm, "---------------------"); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1498 | bool details = false; |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1499 | if (unformat (input, "details")) |
| 1500 | { |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1501 | details = true; |
| 1502 | } |
| 1503 | |
| 1504 | u32 sum_reass_n = 0; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1505 | ip4_reass_t *reass; |
| 1506 | uword thread_index; |
Juraj Sloboda | cd80692 | 2018-10-10 10:15:54 +0200 | [diff] [blame] | 1507 | const uword nthreads = vlib_num_workers () + 1; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1508 | for (thread_index = 0; thread_index < nthreads; ++thread_index) |
| 1509 | { |
| 1510 | ip4_reass_per_thread_t *rt = &rm->per_thread_data[thread_index]; |
| 1511 | clib_spinlock_lock (&rt->lock); |
| 1512 | if (details) |
| 1513 | { |
| 1514 | /* *INDENT-OFF* */ |
| 1515 | pool_foreach (reass, rt->pool, { |
| 1516 | vlib_cli_output (vm, "%U", format_ip4_reass, vm, reass); |
| 1517 | }); |
| 1518 | /* *INDENT-ON* */ |
| 1519 | } |
| 1520 | sum_reass_n += rt->reass_n; |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1521 | clib_spinlock_unlock (&rt->lock); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1522 | } |
| 1523 | vlib_cli_output (vm, "---------------------"); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1524 | vlib_cli_output (vm, "Current IP4 reassemblies count: %lu\n", |
| 1525 | (long unsigned) sum_reass_n); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1526 | vlib_cli_output (vm, |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1527 | "Maximum configured concurrent IP4 reassemblies per worker-thread: %lu\n", |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1528 | (long unsigned) rm->max_reass_n); |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1529 | return 0; |
| 1530 | } |
| 1531 | |
| 1532 | /* *INDENT-OFF* */ |
| 1533 | VLIB_CLI_COMMAND (show_ip4_reassembly_cmd, static) = { |
| 1534 | .path = "show ip4-reassembly", |
| 1535 | .short_help = "show ip4-reassembly [details]", |
| 1536 | .function = show_ip4_reass, |
| 1537 | }; |
| 1538 | /* *INDENT-ON* */ |
| 1539 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1540 | #ifndef CLIB_MARCH_VARIANT |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1541 | vnet_api_error_t |
| 1542 | ip4_reass_enable_disable (u32 sw_if_index, u8 enable_disable) |
| 1543 | { |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1544 | return vnet_feature_enable_disable ("ip4-unicast", |
| 1545 | "ip4-reassembly-feature", sw_if_index, |
| 1546 | enable_disable, 0, 0); |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1547 | } |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 1548 | #endif /* CLIB_MARCH_VARIANT */ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 1549 | |
Vijayabhaskar Katamreddy | 470a370 | 2019-03-01 19:57:06 -0800 | [diff] [blame] | 1550 | |
| 1551 | #define foreach_ip4_reassembly_handoff_error \ |
| 1552 | _(CONGESTION_DROP, "congestion drop") |
| 1553 | |
| 1554 | |
| 1555 | typedef enum |
| 1556 | { |
| 1557 | #define _(sym,str) IP4_REASSEMBLY_HANDOFF_ERROR_##sym, |
| 1558 | foreach_ip4_reassembly_handoff_error |
| 1559 | #undef _ |
| 1560 | IP4_REASSEMBLY_HANDOFF_N_ERROR, |
| 1561 | } ip4_reassembly_handoff_error_t; |
| 1562 | |
| 1563 | static char *ip4_reassembly_handoff_error_strings[] = { |
| 1564 | #define _(sym,string) string, |
| 1565 | foreach_ip4_reassembly_handoff_error |
| 1566 | #undef _ |
| 1567 | }; |
| 1568 | |
| 1569 | typedef struct |
| 1570 | { |
| 1571 | u32 next_worker_index; |
| 1572 | } ip4_reassembly_handoff_trace_t; |
| 1573 | |
| 1574 | static u8 * |
| 1575 | format_ip4_reassembly_handoff_trace (u8 * s, va_list * args) |
| 1576 | { |
| 1577 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 1578 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 1579 | ip4_reassembly_handoff_trace_t *t = |
| 1580 | va_arg (*args, ip4_reassembly_handoff_trace_t *); |
| 1581 | |
| 1582 | s = |
| 1583 | format (s, "ip4-reassembly-handoff: next-worker %d", |
| 1584 | t->next_worker_index); |
| 1585 | |
| 1586 | return s; |
| 1587 | } |
| 1588 | |
| 1589 | always_inline uword |
| 1590 | ip4_reassembly_handoff_node_inline (vlib_main_t * vm, |
| 1591 | vlib_node_runtime_t * node, |
| 1592 | vlib_frame_t * frame, bool is_feature) |
| 1593 | { |
| 1594 | ip4_reass_main_t *rm = &ip4_reass_main; |
| 1595 | |
| 1596 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 1597 | u32 n_enq, n_left_from, *from; |
| 1598 | u16 thread_indices[VLIB_FRAME_SIZE], *ti; |
| 1599 | u32 fq_index; |
| 1600 | |
| 1601 | from = vlib_frame_vector_args (frame); |
| 1602 | n_left_from = frame->n_vectors; |
| 1603 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 1604 | |
| 1605 | b = bufs; |
| 1606 | ti = thread_indices; |
| 1607 | |
| 1608 | fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index; |
| 1609 | |
| 1610 | while (n_left_from > 0) |
| 1611 | { |
| 1612 | ti[0] = |
| 1613 | (is_feature) ? vnet_buffer (b[0])->ip. |
| 1614 | reass.owner_feature_thread_index : vnet_buffer (b[0])->ip. |
| 1615 | reass.owner_thread_index; |
| 1616 | |
| 1617 | if (PREDICT_FALSE |
| 1618 | ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 1619 | && (b[0]->flags & VLIB_BUFFER_IS_TRACED))) |
| 1620 | { |
| 1621 | ip4_reassembly_handoff_trace_t *t = |
| 1622 | vlib_add_trace (vm, node, b[0], sizeof (*t)); |
| 1623 | t->next_worker_index = ti[0]; |
| 1624 | } |
| 1625 | |
| 1626 | n_left_from -= 1; |
| 1627 | ti += 1; |
| 1628 | b += 1; |
| 1629 | } |
| 1630 | n_enq = |
| 1631 | vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices, |
| 1632 | frame->n_vectors, 1); |
| 1633 | |
| 1634 | if (n_enq < frame->n_vectors) |
| 1635 | vlib_node_increment_counter (vm, node->node_index, |
| 1636 | IP4_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP, |
| 1637 | frame->n_vectors - n_enq); |
| 1638 | return frame->n_vectors; |
| 1639 | } |
| 1640 | |
| 1641 | VLIB_NODE_FN (ip4_reassembly_handoff_node) (vlib_main_t * vm, |
| 1642 | vlib_node_runtime_t * node, |
| 1643 | vlib_frame_t * frame) |
| 1644 | { |
| 1645 | return ip4_reassembly_handoff_node_inline (vm, node, frame, |
| 1646 | false /* is_feature */ ); |
| 1647 | } |
| 1648 | |
| 1649 | |
| 1650 | /* *INDENT-OFF* */ |
| 1651 | VLIB_REGISTER_NODE (ip4_reassembly_handoff_node) = { |
| 1652 | .name = "ip4-reassembly-handoff", |
| 1653 | .vector_size = sizeof (u32), |
| 1654 | .n_errors = ARRAY_LEN(ip4_reassembly_handoff_error_strings), |
| 1655 | .error_strings = ip4_reassembly_handoff_error_strings, |
| 1656 | .format_trace = format_ip4_reassembly_handoff_trace, |
| 1657 | |
| 1658 | .n_next_nodes = 1, |
| 1659 | |
| 1660 | .next_nodes = { |
| 1661 | [0] = "error-drop", |
| 1662 | }, |
| 1663 | }; |
| 1664 | /* *INDENT-ON* */ |
| 1665 | |
| 1666 | |
| 1667 | /* *INDENT-OFF* */ |
| 1668 | VLIB_NODE_FN (ip4_reassembly_feature_handoff_node) (vlib_main_t * vm, |
| 1669 | vlib_node_runtime_t * |
| 1670 | node, |
| 1671 | vlib_frame_t * frame) |
| 1672 | { |
| 1673 | return ip4_reassembly_handoff_node_inline (vm, node, frame, |
| 1674 | true /* is_feature */ ); |
| 1675 | } |
| 1676 | /* *INDENT-ON* */ |
| 1677 | |
| 1678 | |
| 1679 | /* *INDENT-OFF* */ |
| 1680 | VLIB_REGISTER_NODE (ip4_reassembly_feature_handoff_node) = { |
| 1681 | .name = "ip4-reass-feature-hoff", |
| 1682 | .vector_size = sizeof (u32), |
| 1683 | .n_errors = ARRAY_LEN(ip4_reassembly_handoff_error_strings), |
| 1684 | .error_strings = ip4_reassembly_handoff_error_strings, |
| 1685 | .format_trace = format_ip4_reassembly_handoff_trace, |
| 1686 | |
| 1687 | .n_next_nodes = 1, |
| 1688 | |
| 1689 | .next_nodes = { |
| 1690 | [0] = "error-drop", |
| 1691 | }, |
| 1692 | }; |
| 1693 | /* *INDENT-ON* */ |
| 1694 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1695 | /* |
| 1696 | * fd.io coding-style-patch-verification: ON |
| 1697 | * |
| 1698 | * Local Variables: |
| 1699 | * eval: (c-set-style "gnu") |
| 1700 | * End: |
| 1701 | */ |