blob: ff877ca75670ddb9fa9cdd885750b05235a7cb87 [file] [log] [blame]
Klement Sekera75e7d132017-09-20 08:26:30 +02001/*
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
Klement Sekera896c8962019-06-24 11:52:49 +000018 * @brief IPv6 Full Reassembly.
Klement Sekera75e7d132017-09-20 08:26:30 +020019 *
Klement Sekera896c8962019-06-24 11:52:49 +000020 * This file contains the source code for IPv6 full reassembly.
Klement Sekera75e7d132017-09-20 08:26:30 +020021 */
22
23#include <vppinfra/vec.h>
24#include <vnet/vnet.h>
25#include <vnet/ip/ip.h>
26#include <vppinfra/bihash_48_8.h>
Klement Sekera896c8962019-06-24 11:52:49 +000027#include <vnet/ip/reass/ip6_full_reass.h>
Ole Troan03092c12021-11-23 15:55:39 +010028#include <vnet/ip/ip6_inlines.h>
Klement Sekera75e7d132017-09-20 08:26:30 +020029
30#define MSEC_PER_SEC 1000
Klement Sekera896c8962019-06-24 11:52:49 +000031#define IP6_FULL_REASS_TIMEOUT_DEFAULT_MS 100
32#define IP6_FULL_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
33#define IP6_FULL_REASS_MAX_REASSEMBLIES_DEFAULT 1024
34#define IP6_FULL_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3
35#define IP6_FULL_REASS_HT_LOAD_FACTOR (0.75)
Klement Sekera75e7d132017-09-20 08:26:30 +020036
Klement Sekerad0f70a32018-12-14 17:24:13 +010037typedef enum
38{
Klement Sekera896c8962019-06-24 11:52:49 +000039 IP6_FULL_REASS_RC_OK,
40 IP6_FULL_REASS_RC_INTERNAL_ERROR,
41 IP6_FULL_REASS_RC_TOO_MANY_FRAGMENTS,
42 IP6_FULL_REASS_RC_NO_BUF,
43 IP6_FULL_REASS_RC_HANDOFF,
Klement Sekera755042d2021-12-01 10:14:38 +000044 IP6_FULL_REASS_RC_INVALID_FRAG_LEN,
Klement Sekerae63a2d42021-05-20 12:23:00 +020045 IP6_FULL_REASS_RC_OVERLAP,
Klement Sekera896c8962019-06-24 11:52:49 +000046} ip6_full_reass_rc_t;
Klement Sekera75e7d132017-09-20 08:26:30 +020047
48typedef struct
49{
50 union
51 {
52 struct
53 {
54 ip6_address_t src;
55 ip6_address_t dst;
Klement Sekera75e7d132017-09-20 08:26:30 +020056 u32 xx_id;
Klement Sekera75e7d132017-09-20 08:26:30 +020057 u32 frag_id;
Klement Sekera8dcfed52018-06-28 11:16:15 +020058 u8 unused[7];
59 u8 proto;
Klement Sekera75e7d132017-09-20 08:26:30 +020060 };
61 u64 as_u64[6];
62 };
Klement Sekera896c8962019-06-24 11:52:49 +000063} ip6_full_reass_key_t;
Klement Sekera75e7d132017-09-20 08:26:30 +020064
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -080065typedef union
66{
67 struct
68 {
69 u32 reass_index;
Klement Sekera630ab582019-07-19 09:14:19 +000070 u32 memory_owner_thread_index;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -080071 };
72 u64 as_u64;
Klement Sekera896c8962019-06-24 11:52:49 +000073} ip6_full_reass_val_t;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -080074
75typedef union
76{
77 struct
78 {
Klement Sekera896c8962019-06-24 11:52:49 +000079 ip6_full_reass_key_t k;
80 ip6_full_reass_val_t v;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -080081 };
82 clib_bihash_kv_48_8_t kv;
Klement Sekera896c8962019-06-24 11:52:49 +000083} ip6_full_reass_kv_t;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -080084
85
Klement Sekera75e7d132017-09-20 08:26:30 +020086always_inline u32
Klement Sekera896c8962019-06-24 11:52:49 +000087ip6_full_reass_buffer_get_data_offset (vlib_buffer_t * b)
Klement Sekera75e7d132017-09-20 08:26:30 +020088{
89 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
Klement Sekerad0f70a32018-12-14 17:24:13 +010090 return vnb->ip.reass.range_first - vnb->ip.reass.fragment_first;
Klement Sekera75e7d132017-09-20 08:26:30 +020091}
92
93always_inline u16
Klement Sekera896c8962019-06-24 11:52:49 +000094ip6_full_reass_buffer_get_data_len (vlib_buffer_t * b)
Klement Sekera75e7d132017-09-20 08:26:30 +020095{
96 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
Klement Sekerad0f70a32018-12-14 17:24:13 +010097 return clib_min (vnb->ip.reass.range_last, vnb->ip.reass.fragment_last) -
Klement Sekera896c8962019-06-24 11:52:49 +000098 (vnb->ip.reass.fragment_first +
99 ip6_full_reass_buffer_get_data_offset (b)) + 1;
Klement Sekera75e7d132017-09-20 08:26:30 +0200100}
101
102typedef struct
103{
104 // hash table key
Klement Sekera896c8962019-06-24 11:52:49 +0000105 ip6_full_reass_key_t key;
Klement Sekera75e7d132017-09-20 08:26:30 +0200106 // time when last packet was received
107 f64 last_heard;
108 // internal id of this reassembly
Klement Sekera4c533132018-02-22 11:41:12 +0100109 u64 id;
Klement Sekera75e7d132017-09-20 08:26:30 +0200110 // buffer index of first buffer in this reassembly context
111 u32 first_bi;
112 // last octet of packet, ~0 until fragment without more_fragments arrives
113 u32 last_packet_octet;
114 // length of data collected so far
115 u32 data_len;
116 // trace operation counter
117 u32 trace_op_counter;
Klement Sekerae8498652019-06-17 12:23:15 +0000118 // next index - used by custom apps (~0 if not set)
Klement Sekera21aa8f12019-05-20 12:27:33 +0200119 u32 next_index;
Klement Sekerae8498652019-06-17 12:23:15 +0000120 // error next index - used by custom apps (~0 if not set)
Klement Sekera21aa8f12019-05-20 12:27:33 +0200121 u32 error_next_index;
Klement Sekera4c533132018-02-22 11:41:12 +0100122 // minimum fragment length for this reassembly - used to estimate MTU
123 u16 min_fragment_length;
Klement Sekera3a343d42019-05-16 14:35:46 +0200124 // number of fragments for this reassembly
125 u32 fragments_n;
Klement Sekera630ab582019-07-19 09:14:19 +0000126 // thread owning memory for this context (whose pool contains this ctx)
127 u32 memory_owner_thread_index;
128 // thread which received fragment with offset 0 and which sends out the
129 // completed reassembly
130 u32 sendout_thread_index;
Klement Sekera896c8962019-06-24 11:52:49 +0000131} ip6_full_reass_t;
Klement Sekera75e7d132017-09-20 08:26:30 +0200132
133typedef struct
134{
Klement Sekera896c8962019-06-24 11:52:49 +0000135 ip6_full_reass_t *pool;
Klement Sekera4c533132018-02-22 11:41:12 +0100136 u32 reass_n;
Klement Sekera4c533132018-02-22 11:41:12 +0100137 u32 id_counter;
138 clib_spinlock_t lock;
Klement Sekera896c8962019-06-24 11:52:49 +0000139} ip6_full_reass_per_thread_t;
Klement Sekera4c533132018-02-22 11:41:12 +0100140
141typedef struct
142{
Klement Sekera75e7d132017-09-20 08:26:30 +0200143 // IPv6 config
144 u32 timeout_ms;
145 f64 timeout;
146 u32 expire_walk_interval_ms;
Klement Sekera3a343d42019-05-16 14:35:46 +0200147 // maximum number of fragments in one reassembly
148 u32 max_reass_len;
149 // maximum number of reassemblies
Klement Sekera75e7d132017-09-20 08:26:30 +0200150 u32 max_reass_n;
151
152 // IPv6 runtime
Klement Sekera75e7d132017-09-20 08:26:30 +0200153 clib_bihash_48_8_t hash;
Klement Sekera4c533132018-02-22 11:41:12 +0100154
155 // per-thread data
Klement Sekera896c8962019-06-24 11:52:49 +0000156 ip6_full_reass_per_thread_t *per_thread_data;
Klement Sekera75e7d132017-09-20 08:26:30 +0200157
158 // convenience
159 vlib_main_t *vlib_main;
Klement Sekera75e7d132017-09-20 08:26:30 +0200160
Klement Sekera75e7d132017-09-20 08:26:30 +0200161 u32 ip6_icmp_error_idx;
Klement Sekera896c8962019-06-24 11:52:49 +0000162 u32 ip6_full_reass_expire_node_idx;
Klement Sekera75e7d132017-09-20 08:26:30 +0200163
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -0800164 /** Worker handoff */
165 u32 fq_index;
Klement Sekera01c1fa42021-12-14 18:25:11 +0000166 u32 fq_local_index;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -0800167 u32 fq_feature_index;
168
Klement Sekera7b2e9fb2019-10-01 13:00:22 +0000169 // reference count for enabling/disabling feature - per interface
170 u32 *feature_use_refcount_per_intf;
Klement Sekera01c1fa42021-12-14 18:25:11 +0000171
172 // whether local fragmented packets are reassembled or not
173 int is_local_reass_enabled;
Klement Sekera896c8962019-06-24 11:52:49 +0000174} ip6_full_reass_main_t;
Klement Sekera75e7d132017-09-20 08:26:30 +0200175
Klement Sekera896c8962019-06-24 11:52:49 +0000176extern ip6_full_reass_main_t ip6_full_reass_main;
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700177
178#ifndef CLIB_MARCH_VARIANT
Klement Sekera896c8962019-06-24 11:52:49 +0000179ip6_full_reass_main_t ip6_full_reass_main;
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700180#endif /* CLIB_MARCH_VARIANT */
Klement Sekera75e7d132017-09-20 08:26:30 +0200181
182typedef enum
183{
Klement Sekera896c8962019-06-24 11:52:49 +0000184 IP6_FULL_REASSEMBLY_NEXT_INPUT,
185 IP6_FULL_REASSEMBLY_NEXT_DROP,
186 IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR,
187 IP6_FULL_REASSEMBLY_NEXT_HANDOFF,
188 IP6_FULL_REASSEMBLY_N_NEXT,
189} ip6_full_reass_next_t;
Klement Sekera75e7d132017-09-20 08:26:30 +0200190
191typedef enum
192{
193 RANGE_NEW,
194 RANGE_OVERLAP,
195 ICMP_ERROR_RT_EXCEEDED,
196 ICMP_ERROR_FL_TOO_BIG,
197 ICMP_ERROR_FL_NOT_MULT_8,
198 FINALIZE,
Klement Sekera630ab582019-07-19 09:14:19 +0000199 HANDOFF,
Klement Sekera01c1fa42021-12-14 18:25:11 +0000200 PASSTHROUGH,
Klement Sekera896c8962019-06-24 11:52:49 +0000201} ip6_full_reass_trace_operation_e;
Klement Sekera75e7d132017-09-20 08:26:30 +0200202
203typedef struct
204{
205 u16 range_first;
206 u16 range_last;
207 u32 range_bi;
208 i32 data_offset;
209 u32 data_len;
210 u32 first_bi;
Klement Sekera896c8962019-06-24 11:52:49 +0000211} ip6_full_reass_range_trace_t;
Klement Sekera75e7d132017-09-20 08:26:30 +0200212
213typedef struct
214{
Klement Sekera896c8962019-06-24 11:52:49 +0000215 ip6_full_reass_trace_operation_e action;
Klement Sekera75e7d132017-09-20 08:26:30 +0200216 u32 reass_id;
Klement Sekera896c8962019-06-24 11:52:49 +0000217 ip6_full_reass_range_trace_t trace_range;
Klement Sekera75e7d132017-09-20 08:26:30 +0200218 u32 op_id;
219 u32 fragment_first;
220 u32 fragment_last;
221 u32 total_data_len;
Klement Sekera630ab582019-07-19 09:14:19 +0000222 u32 thread_id;
223 u32 thread_id_to;
Klement Sekera8563cb32019-10-10 17:03:57 +0000224 bool is_after_handoff;
225 ip6_header_t ip6_header;
226 ip6_frag_hdr_t ip6_frag_header;
Klement Sekera896c8962019-06-24 11:52:49 +0000227} ip6_full_reass_trace_t;
Klement Sekera75e7d132017-09-20 08:26:30 +0200228
229static void
Klement Sekera896c8962019-06-24 11:52:49 +0000230ip6_full_reass_trace_details (vlib_main_t * vm, u32 bi,
231 ip6_full_reass_range_trace_t * trace)
Klement Sekera75e7d132017-09-20 08:26:30 +0200232{
233 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
234 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
235 trace->range_first = vnb->ip.reass.range_first;
236 trace->range_last = vnb->ip.reass.range_last;
Klement Sekera896c8962019-06-24 11:52:49 +0000237 trace->data_offset = ip6_full_reass_buffer_get_data_offset (b);
238 trace->data_len = ip6_full_reass_buffer_get_data_len (b);
Klement Sekera75e7d132017-09-20 08:26:30 +0200239 trace->range_bi = bi;
240}
241
Klement Sekera4c533132018-02-22 11:41:12 +0100242static u8 *
Klement Sekera896c8962019-06-24 11:52:49 +0000243format_ip6_full_reass_range_trace (u8 * s, va_list * args)
Klement Sekera75e7d132017-09-20 08:26:30 +0200244{
Klement Sekera896c8962019-06-24 11:52:49 +0000245 ip6_full_reass_range_trace_t *trace =
246 va_arg (*args, ip6_full_reass_range_trace_t *);
247 s =
248 format (s, "range: [%u, %u], off %d, len %u, bi %u", trace->range_first,
249 trace->range_last, trace->data_offset, trace->data_len,
250 trace->range_bi);
Klement Sekera75e7d132017-09-20 08:26:30 +0200251 return s;
252}
253
Klement Sekera4c533132018-02-22 11:41:12 +0100254static u8 *
Klement Sekera896c8962019-06-24 11:52:49 +0000255format_ip6_full_reass_trace (u8 * s, va_list * args)
Klement Sekera75e7d132017-09-20 08:26:30 +0200256{
257 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
258 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Klement Sekera896c8962019-06-24 11:52:49 +0000259 ip6_full_reass_trace_t *t = va_arg (*args, ip6_full_reass_trace_t *);
Klement Sekera630ab582019-07-19 09:14:19 +0000260 u32 indent = 0;
261 if (~0 != t->reass_id)
262 {
Klement Sekera8563cb32019-10-10 17:03:57 +0000263 if (t->is_after_handoff)
264 {
265 s =
266 format (s, "%U\n", format_ip6_header, &t->ip6_header,
267 sizeof (t->ip6_header));
268 s =
269 format (s, " %U\n", format_ip6_frag_hdr, &t->ip6_frag_header,
270 sizeof (t->ip6_frag_header));
271 indent = 2;
272 }
273 s =
274 format (s, "%Ureass id: %u, op id: %u, ", format_white_space, indent,
275 t->reass_id, t->op_id);
Klement Sekera630ab582019-07-19 09:14:19 +0000276 indent = format_get_indent (s);
277 s = format (s, "first bi: %u, data len: %u, ip/fragment[%u, %u]",
278 t->trace_range.first_bi, t->total_data_len,
279 t->fragment_first, t->fragment_last);
280 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200281 switch (t->action)
282 {
283 case RANGE_NEW:
284 s = format (s, "\n%Unew %U", format_white_space, indent,
Klement Sekera896c8962019-06-24 11:52:49 +0000285 format_ip6_full_reass_range_trace, &t->trace_range);
Klement Sekera75e7d132017-09-20 08:26:30 +0200286 break;
287 case RANGE_OVERLAP:
288 s = format (s, "\n%Uoverlap %U", format_white_space, indent,
Klement Sekera896c8962019-06-24 11:52:49 +0000289 format_ip6_full_reass_range_trace, &t->trace_range);
Klement Sekera75e7d132017-09-20 08:26:30 +0200290 break;
291 case ICMP_ERROR_FL_TOO_BIG:
292 s = format (s, "\n%Uicmp-error - frag_len > 65535 %U",
Klement Sekera896c8962019-06-24 11:52:49 +0000293 format_white_space, indent,
294 format_ip6_full_reass_range_trace, &t->trace_range);
Klement Sekera75e7d132017-09-20 08:26:30 +0200295 break;
296 case ICMP_ERROR_FL_NOT_MULT_8:
297 s = format (s, "\n%Uicmp-error - frag_len mod 8 != 0 %U",
Klement Sekera896c8962019-06-24 11:52:49 +0000298 format_white_space, indent,
299 format_ip6_full_reass_range_trace, &t->trace_range);
Klement Sekera75e7d132017-09-20 08:26:30 +0200300 break;
301 case ICMP_ERROR_RT_EXCEEDED:
302 s = format (s, "\n%Uicmp-error - reassembly time exceeded",
303 format_white_space, indent);
304 break;
305 case FINALIZE:
306 s = format (s, "\n%Ufinalize reassembly", format_white_space, indent);
307 break;
Klement Sekera630ab582019-07-19 09:14:19 +0000308 case HANDOFF:
309 s =
310 format (s, "handoff from thread #%u to thread #%u", t->thread_id,
311 t->thread_id_to);
312 break;
Klement Sekera01c1fa42021-12-14 18:25:11 +0000313 case PASSTHROUGH:
314 s = format (s, "passthrough - not a fragment");
315 break;
Klement Sekera75e7d132017-09-20 08:26:30 +0200316 }
317 return s;
318}
319
320static void
Klement Sekera896c8962019-06-24 11:52:49 +0000321ip6_full_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
Klement Sekera896c8962019-06-24 11:52:49 +0000322 ip6_full_reass_t * reass, u32 bi,
Klement Sekera8563cb32019-10-10 17:03:57 +0000323 ip6_frag_hdr_t * ip6_frag_header,
Klement Sekera896c8962019-06-24 11:52:49 +0000324 ip6_full_reass_trace_operation_e action,
325 u32 thread_id_to)
Klement Sekera75e7d132017-09-20 08:26:30 +0200326{
327 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
328 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
Klement Sekera8563cb32019-10-10 17:03:57 +0000329 bool is_after_handoff = false;
Klement Sekera53be16d2020-12-15 21:47:36 +0100330 if (pool_is_free_index
331 (vm->trace_main.trace_buffer_pool, vlib_buffer_get_trace_index (b)))
332 {
333 // this buffer's trace is gone
334 b->flags &= ~VLIB_BUFFER_IS_TRACED;
335 return;
336 }
Klement Sekera8563cb32019-10-10 17:03:57 +0000337 if (vlib_buffer_get_trace_thread (b) != vm->thread_index)
338 {
339 is_after_handoff = true;
340 }
Klement Sekera896c8962019-06-24 11:52:49 +0000341 ip6_full_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
Klement Sekera8563cb32019-10-10 17:03:57 +0000342 t->is_after_handoff = is_after_handoff;
343 if (t->is_after_handoff)
344 {
345 clib_memcpy (&t->ip6_header, vlib_buffer_get_current (b),
346 clib_min (sizeof (t->ip6_header), b->current_length));
347 if (ip6_frag_header)
348 {
349 clib_memcpy (&t->ip6_frag_header, ip6_frag_header,
350 sizeof (t->ip6_frag_header));
351 }
352 else
353 {
354 clib_memset (&t->ip6_frag_header, 0, sizeof (t->ip6_frag_header));
355 }
356 }
Klement Sekera896c8962019-06-24 11:52:49 +0000357 if (reass)
358 {
359 t->reass_id = reass->id;
360 t->op_id = reass->trace_op_counter;
361 t->trace_range.first_bi = reass->first_bi;
362 t->total_data_len = reass->data_len;
363 ++reass->trace_op_counter;
364 }
365 else
366 {
367 t->reass_id = ~0;
368 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200369 t->action = action;
Klement Sekera630ab582019-07-19 09:14:19 +0000370 t->thread_id = vm->thread_index;
371 t->thread_id_to = thread_id_to;
Klement Sekera896c8962019-06-24 11:52:49 +0000372 ip6_full_reass_trace_details (vm, bi, &t->trace_range);
Klement Sekera75e7d132017-09-20 08:26:30 +0200373 t->fragment_first = vnb->ip.reass.fragment_first;
374 t->fragment_last = vnb->ip.reass.fragment_last;
Klement Sekera75e7d132017-09-20 08:26:30 +0200375#if 0
376 static u8 *s = NULL;
Klement Sekera896c8962019-06-24 11:52:49 +0000377 s = format (s, "%U", format_ip6_full_reass_trace, NULL, NULL, t);
Klement Sekera75e7d132017-09-20 08:26:30 +0200378 printf ("%.*s\n", vec_len (s), s);
379 fflush (stdout);
380 vec_reset_length (s);
381#endif
382}
383
Klement Sekera4c533132018-02-22 11:41:12 +0100384always_inline void
Klement Sekera896c8962019-06-24 11:52:49 +0000385ip6_full_reass_free_ctx (ip6_full_reass_per_thread_t * rt,
386 ip6_full_reass_t * reass)
Klement Sekera630ab582019-07-19 09:14:19 +0000387{
388 pool_put (rt->pool, reass);
389 --rt->reass_n;
390}
391
392always_inline void
Klement Sekera896c8962019-06-24 11:52:49 +0000393ip6_full_reass_free (ip6_full_reass_main_t * rm,
394 ip6_full_reass_per_thread_t * rt,
395 ip6_full_reass_t * reass)
Klement Sekera75e7d132017-09-20 08:26:30 +0200396{
397 clib_bihash_kv_48_8_t kv;
398 kv.key[0] = reass->key.as_u64[0];
399 kv.key[1] = reass->key.as_u64[1];
400 kv.key[2] = reass->key.as_u64[2];
401 kv.key[3] = reass->key.as_u64[3];
402 kv.key[4] = reass->key.as_u64[4];
403 kv.key[5] = reass->key.as_u64[5];
404 clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
Klement Sekera896c8962019-06-24 11:52:49 +0000405 ip6_full_reass_free_ctx (rt, reass);
Klement Sekera75e7d132017-09-20 08:26:30 +0200406}
407
Klement Sekera4c533132018-02-22 11:41:12 +0100408always_inline void
Klement Sekera42cec0e2021-08-02 16:14:15 +0200409ip6_full_reass_drop_all (vlib_main_t *vm, vlib_node_runtime_t *node,
Klement Sekerae63a2d42021-05-20 12:23:00 +0200410 ip6_full_reass_t *reass, u32 offending_bi)
Klement Sekera75e7d132017-09-20 08:26:30 +0200411{
412 u32 range_bi = reass->first_bi;
413 vlib_buffer_t *range_b;
414 vnet_buffer_opaque_t *range_vnb;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100415 u32 *to_free = NULL;
Klement Sekera75e7d132017-09-20 08:26:30 +0200416 while (~0 != range_bi)
417 {
418 range_b = vlib_get_buffer (vm, range_bi);
419 range_vnb = vnet_buffer (range_b);
420 u32 bi = range_bi;
421 while (~0 != bi)
422 {
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100423 vec_add1 (to_free, bi);
Klement Sekerae63a2d42021-05-20 12:23:00 +0200424 if (bi == offending_bi)
425 {
426 offending_bi = ~0;
427 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200428 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
429 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
430 {
431 bi = b->next_buffer;
432 b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
433 }
434 else
435 {
436 bi = ~0;
437 }
438 }
439 range_bi = range_vnb->ip.reass.next_range_bi;
440 }
Klement Sekerae63a2d42021-05-20 12:23:00 +0200441 if (~0 != offending_bi)
442 {
443 vec_add1 (to_free, offending_bi);
444 }
Klement Sekera21aa8f12019-05-20 12:27:33 +0200445 /* send to next_error_index */
Klement Sekerae8498652019-06-17 12:23:15 +0000446 if (~0 != reass->error_next_index)
Klement Sekera21aa8f12019-05-20 12:27:33 +0200447 {
448 u32 n_left_to_next, *to_next, next_index;
449
450 next_index = reass->error_next_index;
451 u32 bi = ~0;
452
453 while (vec_len (to_free) > 0)
454 {
455 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
456
457 while (vec_len (to_free) > 0 && n_left_to_next > 0)
458 {
459 bi = vec_pop (to_free);
460
461 if (~0 != bi)
462 {
463 to_next[0] = bi;
464 to_next += 1;
465 n_left_to_next -= 1;
Klement Sekera21aa8f12019-05-20 12:27:33 +0200466 }
467 }
468 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
469 }
470 }
471 else
472 {
473 vlib_buffer_free (vm, to_free, vec_len (to_free));
474 }
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100475 vec_free (to_free);
Klement Sekera75e7d132017-09-20 08:26:30 +0200476}
477
Klement Sekera4c533132018-02-22 11:41:12 +0100478always_inline void
Klement Sekera896c8962019-06-24 11:52:49 +0000479ip6_full_reass_on_timeout (vlib_main_t * vm, vlib_node_runtime_t * node,
Klement Sekera896c8962019-06-24 11:52:49 +0000480 ip6_full_reass_t * reass, u32 * icmp_bi)
Klement Sekera75e7d132017-09-20 08:26:30 +0200481{
482 if (~0 == reass->first_bi)
483 {
484 return;
485 }
Klement Sekerae8498652019-06-17 12:23:15 +0000486 if (~0 == reass->next_index) // custom apps don't want icmp
Klement Sekera75e7d132017-09-20 08:26:30 +0200487 {
Klement Sekera21aa8f12019-05-20 12:27:33 +0200488 vlib_buffer_t *b = vlib_get_buffer (vm, reass->first_bi);
489 if (0 == vnet_buffer (b)->ip.reass.fragment_first)
Klement Sekera75e7d132017-09-20 08:26:30 +0200490 {
Klement Sekera21aa8f12019-05-20 12:27:33 +0200491 *icmp_bi = reass->first_bi;
492 if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
493 {
Klement Sekera42cec0e2021-08-02 16:14:15 +0200494 ip6_full_reass_add_trace (vm, node, reass, reass->first_bi, NULL,
495 ICMP_ERROR_RT_EXCEEDED, ~0);
Klement Sekera21aa8f12019-05-20 12:27:33 +0200496 }
497 // fragment with offset zero received - send icmp message back
498 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
499 {
500 // separate first buffer from chain and steer it towards icmp node
501 b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
502 reass->first_bi = b->next_buffer;
503 }
504 else
505 {
506 reass->first_bi = vnet_buffer (b)->ip.reass.next_range_bi;
507 }
508 icmp6_error_set_vnet_buffer (b, ICMP6_time_exceeded,
509 ICMP6_time_exceeded_fragment_reassembly_time_exceeded,
510 0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200511 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200512 }
Klement Sekerae63a2d42021-05-20 12:23:00 +0200513 ip6_full_reass_drop_all (vm, node, reass, ~0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200514}
515
Klement Sekera896c8962019-06-24 11:52:49 +0000516always_inline ip6_full_reass_t *
Klement Sekera7c3275e2021-12-07 09:49:53 +0000517ip6_full_reass_find_or_create (vlib_main_t *vm, vlib_node_runtime_t *node,
518 ip6_full_reass_main_t *rm,
519 ip6_full_reass_per_thread_t *rt,
520 ip6_full_reass_kv_t *kv, u32 *icmp_bi,
521 u8 *do_handoff, int skip_bihash)
Klement Sekera75e7d132017-09-20 08:26:30 +0200522{
Klement Sekera896c8962019-06-24 11:52:49 +0000523 ip6_full_reass_t *reass;
Klement Sekera630ab582019-07-19 09:14:19 +0000524 f64 now;
525
526again:
527
528 reass = NULL;
529 now = vlib_time_now (vm);
Klement Sekera75e7d132017-09-20 08:26:30 +0200530
Klement Sekera7c3275e2021-12-07 09:49:53 +0000531 if (!skip_bihash && !clib_bihash_search_48_8 (&rm->hash, &kv->kv, &kv->kv))
Klement Sekera75e7d132017-09-20 08:26:30 +0200532 {
Gao Feng9165e032020-04-26 09:57:18 +0800533 if (vm->thread_index != kv->v.memory_owner_thread_index)
534 {
535 *do_handoff = 1;
536 return NULL;
537 }
538
Klement Sekera630ab582019-07-19 09:14:19 +0000539 reass =
540 pool_elt_at_index (rm->per_thread_data
541 [kv->v.memory_owner_thread_index].pool,
542 kv->v.reass_index);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -0800543
Klement Sekera75e7d132017-09-20 08:26:30 +0200544 if (now > reass->last_heard + rm->timeout)
545 {
Klement Sekera42cec0e2021-08-02 16:14:15 +0200546 ip6_full_reass_on_timeout (vm, node, reass, icmp_bi);
Klement Sekera896c8962019-06-24 11:52:49 +0000547 ip6_full_reass_free (rm, rt, reass);
Klement Sekera75e7d132017-09-20 08:26:30 +0200548 reass = NULL;
549 }
550 }
551
552 if (reass)
553 {
554 reass->last_heard = now;
555 return reass;
556 }
557
Klement Sekera4c533132018-02-22 11:41:12 +0100558 if (rt->reass_n >= rm->max_reass_n)
Klement Sekera75e7d132017-09-20 08:26:30 +0200559 {
560 reass = NULL;
561 return reass;
562 }
563 else
564 {
Klement Sekera4c533132018-02-22 11:41:12 +0100565 pool_get (rt->pool, reass);
Dave Barachb7b92992018-10-17 10:38:51 -0400566 clib_memset (reass, 0, sizeof (*reass));
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -0800567 reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
Klement Sekera4c533132018-02-22 11:41:12 +0100568 ++rt->id_counter;
Klement Sekera75e7d132017-09-20 08:26:30 +0200569 reass->first_bi = ~0;
570 reass->last_packet_octet = ~0;
571 reass->data_len = 0;
Klement Sekerae8498652019-06-17 12:23:15 +0000572 reass->next_index = ~0;
573 reass->error_next_index = ~0;
Klement Sekera8d4db8b2022-01-24 22:30:04 +0000574 reass->memory_owner_thread_index = vm->thread_index;
Klement Sekera4c533132018-02-22 11:41:12 +0100575 ++rt->reass_n;
Klement Sekera75e7d132017-09-20 08:26:30 +0200576 }
577
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -0800578 kv->v.reass_index = (reass - rt->pool);
Klement Sekera630ab582019-07-19 09:14:19 +0000579 kv->v.memory_owner_thread_index = vm->thread_index;
Klement Sekera75e7d132017-09-20 08:26:30 +0200580 reass->last_heard = now;
581
Klement Sekera7c3275e2021-12-07 09:49:53 +0000582 if (!skip_bihash)
Klement Sekera75e7d132017-09-20 08:26:30 +0200583 {
Klement Sekera7c3275e2021-12-07 09:49:53 +0000584 reass->key.as_u64[0] = kv->kv.key[0];
585 reass->key.as_u64[1] = kv->kv.key[1];
586 reass->key.as_u64[2] = kv->kv.key[2];
587 reass->key.as_u64[3] = kv->kv.key[3];
588 reass->key.as_u64[4] = kv->kv.key[4];
589 reass->key.as_u64[5] = kv->kv.key[5];
590
591 int rv = clib_bihash_add_del_48_8 (&rm->hash, &kv->kv, 2);
592 if (rv)
593 {
594 ip6_full_reass_free (rm, rt, reass);
595 reass = NULL;
596 // if other worker created a context already work with the other copy
597 if (-2 == rv)
598 goto again;
599 }
600 }
601 else
602 {
603 reass->key.as_u64[0] = ~0;
604 reass->key.as_u64[1] = ~0;
605 reass->key.as_u64[2] = ~0;
606 reass->key.as_u64[3] = ~0;
607 reass->key.as_u64[4] = ~0;
608 reass->key.as_u64[5] = ~0;
Klement Sekera75e7d132017-09-20 08:26:30 +0200609 }
610
611 return reass;
612}
613
Klement Sekera896c8962019-06-24 11:52:49 +0000614always_inline ip6_full_reass_rc_t
615ip6_full_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
616 ip6_full_reass_main_t * rm,
617 ip6_full_reass_per_thread_t * rt,
618 ip6_full_reass_t * reass, u32 * bi0, u32 * next0,
619 u32 * error0, bool is_custom_app)
Klement Sekera75e7d132017-09-20 08:26:30 +0200620{
Klement Sekera75e7d132017-09-20 08:26:30 +0200621 *bi0 = reass->first_bi;
Klement Sekera75e7d132017-09-20 08:26:30 +0200622 *error0 = IP6_ERROR_NONE;
623 ip6_frag_hdr_t *frag_hdr;
624 vlib_buffer_t *last_b = NULL;
625 u32 sub_chain_bi = reass->first_bi;
626 u32 total_length = 0;
627 u32 buf_cnt = 0;
628 u32 dropped_cnt = 0;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100629 u32 *vec_drop_compress = NULL;
Klement Sekera896c8962019-06-24 11:52:49 +0000630 ip6_full_reass_rc_t rv = IP6_FULL_REASS_RC_OK;
Klement Sekera75e7d132017-09-20 08:26:30 +0200631 do
632 {
633 u32 tmp_bi = sub_chain_bi;
634 vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi);
Klement Sekerad0f70a32018-12-14 17:24:13 +0100635 vnet_buffer_opaque_t *vnb = vnet_buffer (tmp);
636 if (!(vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first) &&
637 !(vnb->ip.reass.range_last > vnb->ip.reass.fragment_first))
638 {
Klement Sekera896c8962019-06-24 11:52:49 +0000639 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100640 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100641 }
642
Klement Sekera896c8962019-06-24 11:52:49 +0000643 u32 data_len = ip6_full_reass_buffer_get_data_len (tmp);
Klement Sekera75e7d132017-09-20 08:26:30 +0200644 u32 trim_front = vnet_buffer (tmp)->ip.reass.ip6_frag_hdr_offset +
Klement Sekera896c8962019-06-24 11:52:49 +0000645 sizeof (*frag_hdr) + ip6_full_reass_buffer_get_data_offset (tmp);
Klement Sekera75e7d132017-09-20 08:26:30 +0200646 u32 trim_end =
647 vlib_buffer_length_in_chain (vm, tmp) - trim_front - data_len;
648 if (tmp_bi == reass->first_bi)
649 {
650 /* first buffer - keep ip6 header */
Klement Sekera896c8962019-06-24 11:52:49 +0000651 if (0 != ip6_full_reass_buffer_get_data_offset (tmp))
Klement Sekerad0f70a32018-12-14 17:24:13 +0100652 {
Klement Sekera896c8962019-06-24 11:52:49 +0000653 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100654 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100655 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200656 trim_front = 0;
657 trim_end = vlib_buffer_length_in_chain (vm, tmp) - data_len -
658 (vnet_buffer (tmp)->ip.reass.ip6_frag_hdr_offset +
659 sizeof (*frag_hdr));
Klement Sekerad0f70a32018-12-14 17:24:13 +0100660 if (!(vlib_buffer_length_in_chain (vm, tmp) - trim_end > 0))
661 {
Klement Sekera896c8962019-06-24 11:52:49 +0000662 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100663 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100664 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200665 }
666 u32 keep_data =
667 vlib_buffer_length_in_chain (vm, tmp) - trim_front - trim_end;
668 while (1)
669 {
670 ++buf_cnt;
671 if (trim_front)
672 {
673 if (trim_front > tmp->current_length)
674 {
675 /* drop whole buffer */
Klement Sekerad0f70a32018-12-14 17:24:13 +0100676 if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT))
677 {
Klement Sekera896c8962019-06-24 11:52:49 +0000678 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100679 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100680 }
Klement Sekerae63a2d42021-05-20 12:23:00 +0200681 trim_front -= tmp->current_length;
682 vec_add1 (vec_drop_compress, tmp_bi);
Klement Sekera75e7d132017-09-20 08:26:30 +0200683 tmp->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
684 tmp_bi = tmp->next_buffer;
685 tmp = vlib_get_buffer (vm, tmp_bi);
686 continue;
687 }
688 else
689 {
690 vlib_buffer_advance (tmp, trim_front);
691 trim_front = 0;
692 }
693 }
694 if (keep_data)
695 {
696 if (last_b)
697 {
698 last_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
699 last_b->next_buffer = tmp_bi;
700 }
701 last_b = tmp;
702 if (keep_data <= tmp->current_length)
703 {
704 tmp->current_length = keep_data;
705 keep_data = 0;
706 }
707 else
708 {
709 keep_data -= tmp->current_length;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100710 if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT))
711 {
Klement Sekera896c8962019-06-24 11:52:49 +0000712 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100713 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100714 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200715 }
716 total_length += tmp->current_length;
717 }
718 else
719 {
Klement Sekerad0f70a32018-12-14 17:24:13 +0100720 if (reass->first_bi == tmp_bi)
721 {
Klement Sekera896c8962019-06-24 11:52:49 +0000722 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100723 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100724 }
Klement Sekerae63a2d42021-05-20 12:23:00 +0200725 vec_add1 (vec_drop_compress, tmp_bi);
Klement Sekera75e7d132017-09-20 08:26:30 +0200726 ++dropped_cnt;
727 }
728 if (tmp->flags & VLIB_BUFFER_NEXT_PRESENT)
729 {
730 tmp_bi = tmp->next_buffer;
731 tmp = vlib_get_buffer (vm, tmp->next_buffer);
732 }
733 else
734 {
735 break;
736 }
737 }
738 sub_chain_bi =
739 vnet_buffer (vlib_get_buffer (vm, sub_chain_bi))->ip.
740 reass.next_range_bi;
741 }
742 while (~0 != sub_chain_bi);
Chris Luke30684ac2018-03-29 12:56:58 -0700743
Klement Sekerad0f70a32018-12-14 17:24:13 +0100744 if (!last_b)
745 {
Klement Sekera896c8962019-06-24 11:52:49 +0000746 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100747 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100748 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200749 last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
750 vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi);
Klement Sekerad0f70a32018-12-14 17:24:13 +0100751 if (total_length < first_b->current_length)
752 {
Klement Sekera896c8962019-06-24 11:52:49 +0000753 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100754 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100755 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200756 total_length -= first_b->current_length;
757 first_b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
758 first_b->total_length_not_including_first_buffer = total_length;
759 // drop fragment header
760 vnet_buffer_opaque_t *first_b_vnb = vnet_buffer (first_b);
761 ip6_header_t *ip = vlib_buffer_get_current (first_b);
762 u16 ip6_frag_hdr_offset = first_b_vnb->ip.reass.ip6_frag_hdr_offset;
Ole Troan03092c12021-11-23 15:55:39 +0100763 ip6_ext_hdr_chain_t hdr_chain;
764 ip6_ext_header_t *prev_hdr = 0;
765 int res = ip6_ext_header_walk (first_b, ip, IP_PROTOCOL_IPV6_FRAGMENTATION,
766 &hdr_chain);
767 if (res < 0 ||
768 (hdr_chain.eh[res].protocol != IP_PROTOCOL_IPV6_FRAGMENTATION))
Klement Sekera75e7d132017-09-20 08:26:30 +0200769 {
Ole Troan03092c12021-11-23 15:55:39 +0100770 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
771 goto free_buffers_and_return;
772 }
773 frag_hdr = ip6_ext_next_header_offset (ip, hdr_chain.eh[res].offset);
774 if (res > 0)
775 {
776 prev_hdr = ip6_ext_next_header_offset (ip, hdr_chain.eh[res - 1].offset);
Klement Sekera75e7d132017-09-20 08:26:30 +0200777 prev_hdr->next_hdr = frag_hdr->next_hdr;
778 }
779 else
780 {
781 ip->protocol = frag_hdr->next_hdr;
782 }
Ole Troan03092c12021-11-23 15:55:39 +0100783 if (hdr_chain.eh[res].offset != ip6_frag_hdr_offset)
Klement Sekerad0f70a32018-12-14 17:24:13 +0100784 {
Klement Sekera896c8962019-06-24 11:52:49 +0000785 rv = IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100786 goto free_buffers_and_return;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100787 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200788 memmove (frag_hdr, (u8 *) frag_hdr + sizeof (*frag_hdr),
789 first_b->current_length - ip6_frag_hdr_offset -
790 sizeof (ip6_frag_hdr_t));
791 first_b->current_length -= sizeof (*frag_hdr);
792 ip->payload_length =
793 clib_host_to_net_u16 (total_length + first_b->current_length -
794 sizeof (*ip));
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100795 if (!vlib_buffer_chain_linearize (vm, first_b))
796 {
Klement Sekera896c8962019-06-24 11:52:49 +0000797 rv = IP6_FULL_REASS_RC_NO_BUF;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100798 goto free_buffers_and_return;
799 }
Vijayabhaskar Katamreddy90556d62019-05-23 13:02:28 -0700800 first_b->flags &= ~VLIB_BUFFER_EXT_HDR_VALID;
Klement Sekera75e7d132017-09-20 08:26:30 +0200801 if (PREDICT_FALSE (first_b->flags & VLIB_BUFFER_IS_TRACED))
802 {
Klement Sekera42cec0e2021-08-02 16:14:15 +0200803 ip6_full_reass_add_trace (vm, node, reass, reass->first_bi, NULL,
Klement Sekera896c8962019-06-24 11:52:49 +0000804 FINALIZE, ~0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200805#if 0
806 // following code does a hexdump of packet fragments to stdout ...
807 do
808 {
809 u32 bi = reass->first_bi;
810 u8 *s = NULL;
811 while (~0 != bi)
812 {
813 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
814 s = format (s, "%u: %U\n", bi, format_hexdump,
815 vlib_buffer_get_current (b), b->current_length);
816 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
817 {
818 bi = b->next_buffer;
819 }
820 else
821 {
822 break;
823 }
824 }
825 printf ("%.*s\n", vec_len (s), s);
826 fflush (stdout);
827 vec_free (s);
828 }
829 while (0);
830#endif
831 }
Klement Sekerae8498652019-06-17 12:23:15 +0000832 if (!is_custom_app)
Klement Sekera4c533132018-02-22 11:41:12 +0100833 {
Klement Sekera896c8962019-06-24 11:52:49 +0000834 *next0 = IP6_FULL_REASSEMBLY_NEXT_INPUT;
Klement Sekera4c533132018-02-22 11:41:12 +0100835 }
836 else
837 {
838 *next0 = reass->next_index;
839 }
840 vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length;
Klement Sekera896c8962019-06-24 11:52:49 +0000841 ip6_full_reass_free (rm, rt, reass);
Klement Sekera75e7d132017-09-20 08:26:30 +0200842 reass = NULL;
Klement Sekeraf883f6a2019-02-13 11:01:32 +0100843free_buffers_and_return:
844 vlib_buffer_free (vm, vec_drop_compress, vec_len (vec_drop_compress));
845 vec_free (vec_drop_compress);
846 return rv;
Klement Sekera75e7d132017-09-20 08:26:30 +0200847}
848
Klement Sekera4c533132018-02-22 11:41:12 +0100849always_inline void
Klement Sekera896c8962019-06-24 11:52:49 +0000850ip6_full_reass_insert_range_in_chain (vlib_main_t * vm,
Klement Sekera896c8962019-06-24 11:52:49 +0000851 ip6_full_reass_t * reass,
852 u32 prev_range_bi, u32 new_next_bi)
Klement Sekera75e7d132017-09-20 08:26:30 +0200853{
854
855 vlib_buffer_t *new_next_b = vlib_get_buffer (vm, new_next_bi);
856 vnet_buffer_opaque_t *new_next_vnb = vnet_buffer (new_next_b);
857 if (~0 != prev_range_bi)
858 {
859 vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi);
860 vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b);
861 new_next_vnb->ip.reass.next_range_bi = prev_vnb->ip.reass.next_range_bi;
862 prev_vnb->ip.reass.next_range_bi = new_next_bi;
863 }
864 else
865 {
866 if (~0 != reass->first_bi)
867 {
868 new_next_vnb->ip.reass.next_range_bi = reass->first_bi;
869 }
870 reass->first_bi = new_next_bi;
871 }
Klement Sekera896c8962019-06-24 11:52:49 +0000872 reass->data_len += ip6_full_reass_buffer_get_data_len (new_next_b);
Klement Sekera75e7d132017-09-20 08:26:30 +0200873}
874
Klement Sekera896c8962019-06-24 11:52:49 +0000875always_inline ip6_full_reass_rc_t
Klement Sekera7c3275e2021-12-07 09:49:53 +0000876ip6_full_reass_update (vlib_main_t *vm, vlib_node_runtime_t *node,
877 ip6_full_reass_main_t *rm,
878 ip6_full_reass_per_thread_t *rt,
879 ip6_full_reass_t *reass, u32 *bi0, u32 *next0,
880 u32 *error0, ip6_frag_hdr_t *frag_hdr,
881 bool is_custom_app, u32 *handoff_thread_idx,
882 int skip_bihash)
Klement Sekera75e7d132017-09-20 08:26:30 +0200883{
884 int consumed = 0;
885 vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0);
886 vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
Klement Sekerae8498652019-06-17 12:23:15 +0000887 if (is_custom_app)
888 {
889 reass->next_index = fvnb->ip.reass.next_index; // store next_index before it's overwritten
890 reass->error_next_index = fvnb->ip.reass.error_next_index; // store error_next_index before it is overwritten
891 }
Klement Sekera21aa8f12019-05-20 12:27:33 +0200892
Klement Sekera75e7d132017-09-20 08:26:30 +0200893 fvnb->ip.reass.ip6_frag_hdr_offset =
894 (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
895 ip6_header_t *fip = vlib_buffer_get_current (fb);
Klement Sekerad0f70a32018-12-14 17:24:13 +0100896 if (fb->current_length < sizeof (*fip) ||
897 fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
898 fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
899 {
Klement Sekera896c8962019-06-24 11:52:49 +0000900 return IP6_FULL_REASS_RC_INTERNAL_ERROR;
Klement Sekerad0f70a32018-12-14 17:24:13 +0100901 }
902
Klement Sekera75e7d132017-09-20 08:26:30 +0200903 u32 fragment_first = fvnb->ip.reass.fragment_first =
904 ip6_frag_hdr_offset_bytes (frag_hdr);
905 u32 fragment_length =
906 vlib_buffer_length_in_chain (vm, fb) -
907 (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
Klement Sekera755042d2021-12-01 10:14:38 +0000908 if (0 == fragment_length)
909 {
910 return IP6_FULL_REASS_RC_INVALID_FRAG_LEN;
911 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200912 u32 fragment_last = fvnb->ip.reass.fragment_last =
913 fragment_first + fragment_length - 1;
914 int more_fragments = ip6_frag_hdr_more (frag_hdr);
915 u32 candidate_range_bi = reass->first_bi;
916 u32 prev_range_bi = ~0;
917 fvnb->ip.reass.range_first = fragment_first;
918 fvnb->ip.reass.range_last = fragment_last;
919 fvnb->ip.reass.next_range_bi = ~0;
Klement Sekera75e7d132017-09-20 08:26:30 +0200920 if (!more_fragments)
921 {
922 reass->last_packet_octet = fragment_last;
923 }
924 if (~0 == reass->first_bi)
925 {
926 // starting a new reassembly
Klement Sekera42cec0e2021-08-02 16:14:15 +0200927 ip6_full_reass_insert_range_in_chain (vm, reass, prev_range_bi, *bi0);
Klement Sekera4c533132018-02-22 11:41:12 +0100928 reass->min_fragment_length = clib_net_to_host_u16 (fip->payload_length);
Klement Sekeraf1b4e522019-02-19 14:47:25 +0100929 consumed = 1;
Klement Sekera3a343d42019-05-16 14:35:46 +0200930 reass->fragments_n = 1;
Klement Sekeraf1b4e522019-02-19 14:47:25 +0100931 goto check_if_done_maybe;
Klement Sekera75e7d132017-09-20 08:26:30 +0200932 }
Klement Sekera4c533132018-02-22 11:41:12 +0100933 reass->min_fragment_length =
Klement Sekera75e7d132017-09-20 08:26:30 +0200934 clib_min (clib_net_to_host_u16 (fip->payload_length),
935 fvnb->ip.reass.estimated_mtu);
936 while (~0 != candidate_range_bi)
937 {
938 vlib_buffer_t *candidate_b = vlib_get_buffer (vm, candidate_range_bi);
939 vnet_buffer_opaque_t *candidate_vnb = vnet_buffer (candidate_b);
940 if (fragment_first > candidate_vnb->ip.reass.range_last)
941 {
942 // this fragments starts after candidate range
943 prev_range_bi = candidate_range_bi;
944 candidate_range_bi = candidate_vnb->ip.reass.next_range_bi;
945 if (candidate_vnb->ip.reass.range_last < fragment_last &&
946 ~0 == candidate_range_bi)
947 {
948 // special case - this fragment falls beyond all known ranges
Klement Sekera42cec0e2021-08-02 16:14:15 +0200949 ip6_full_reass_insert_range_in_chain (vm, reass, prev_range_bi,
950 *bi0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200951 consumed = 1;
952 break;
953 }
954 continue;
955 }
956 if (fragment_last < candidate_vnb->ip.reass.range_first)
957 {
958 // this fragment ends before candidate range without any overlap
Klement Sekera42cec0e2021-08-02 16:14:15 +0200959 ip6_full_reass_insert_range_in_chain (vm, reass, prev_range_bi,
960 *bi0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200961 consumed = 1;
962 }
963 else if (fragment_first == candidate_vnb->ip.reass.range_first &&
964 fragment_last == candidate_vnb->ip.reass.range_last)
965 {
966 // duplicate fragment - ignore
967 }
968 else
969 {
970 // overlapping fragment - not allowed by RFC 8200
Klement Sekera75e7d132017-09-20 08:26:30 +0200971 if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
972 {
Klement Sekera42cec0e2021-08-02 16:14:15 +0200973 ip6_full_reass_add_trace (vm, node, reass, *bi0, frag_hdr,
Klement Sekera896c8962019-06-24 11:52:49 +0000974 RANGE_OVERLAP, ~0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200975 }
Klement Sekerae63a2d42021-05-20 12:23:00 +0200976 return IP6_FULL_REASS_RC_OVERLAP;
Klement Sekera75e7d132017-09-20 08:26:30 +0200977 }
978 break;
979 }
Klement Sekera3a343d42019-05-16 14:35:46 +0200980 ++reass->fragments_n;
Klement Sekeraf1b4e522019-02-19 14:47:25 +0100981check_if_done_maybe:
Klement Sekera75e7d132017-09-20 08:26:30 +0200982 if (consumed)
983 {
984 if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
985 {
Klement Sekera42cec0e2021-08-02 16:14:15 +0200986 ip6_full_reass_add_trace (vm, node, reass, *bi0, frag_hdr, RANGE_NEW,
987 ~0);
Klement Sekera75e7d132017-09-20 08:26:30 +0200988 }
989 }
Klement Sekera7c3275e2021-12-07 09:49:53 +0000990 else if (skip_bihash)
991 {
992 // if this reassembly is not in bihash, then the packet must have been
993 // consumed
994 return IP6_FULL_REASS_RC_INTERNAL_ERROR;
995 }
Klement Sekera75e7d132017-09-20 08:26:30 +0200996 if (~0 != reass->last_packet_octet &&
997 reass->data_len == reass->last_packet_octet + 1)
998 {
Klement Sekera630ab582019-07-19 09:14:19 +0000999 *handoff_thread_idx = reass->sendout_thread_index;
Benoît Ganne2d0ebd72019-07-19 13:42:12 +02001000 int handoff =
1001 reass->memory_owner_thread_index != reass->sendout_thread_index;
Klement Sekera896c8962019-06-24 11:52:49 +00001002 ip6_full_reass_rc_t rc =
1003 ip6_full_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0,
1004 is_custom_app);
Benoît Ganne2d0ebd72019-07-19 13:42:12 +02001005 if (IP6_FULL_REASS_RC_OK == rc && handoff)
Klement Sekera630ab582019-07-19 09:14:19 +00001006 {
Klement Sekera896c8962019-06-24 11:52:49 +00001007 return IP6_FULL_REASS_RC_HANDOFF;
Klement Sekera630ab582019-07-19 09:14:19 +00001008 }
1009 return rc;
Klement Sekera75e7d132017-09-20 08:26:30 +02001010 }
1011 else
1012 {
Klement Sekera7c3275e2021-12-07 09:49:53 +00001013 if (skip_bihash)
1014 {
1015 // if this reassembly is not in bihash, it should've been an atomic
1016 // fragment and thus finalized
1017 return IP6_FULL_REASS_RC_INTERNAL_ERROR;
1018 }
Klement Sekera75e7d132017-09-20 08:26:30 +02001019 if (consumed)
1020 {
1021 *bi0 = ~0;
Klement Sekera3a343d42019-05-16 14:35:46 +02001022 if (reass->fragments_n > rm->max_reass_len)
1023 {
Klement Sekera896c8962019-06-24 11:52:49 +00001024 return IP6_FULL_REASS_RC_TOO_MANY_FRAGMENTS;
Klement Sekera3a343d42019-05-16 14:35:46 +02001025 }
Klement Sekera75e7d132017-09-20 08:26:30 +02001026 }
1027 else
1028 {
Klement Sekera896c8962019-06-24 11:52:49 +00001029 *next0 = IP6_FULL_REASSEMBLY_NEXT_DROP;
Klement Sekera75e7d132017-09-20 08:26:30 +02001030 *error0 = IP6_ERROR_REASS_DUPLICATE_FRAGMENT;
1031 }
1032 }
Klement Sekera896c8962019-06-24 11:52:49 +00001033 return IP6_FULL_REASS_RC_OK;
Klement Sekera75e7d132017-09-20 08:26:30 +02001034}
1035
Klement Sekera4c533132018-02-22 11:41:12 +01001036always_inline bool
Ole Troan03092c12021-11-23 15:55:39 +01001037ip6_full_reass_verify_upper_layer_present (vlib_node_runtime_t *node,
1038 vlib_buffer_t *b,
1039 ip6_ext_hdr_chain_t *hc)
Klement Sekera4c533132018-02-22 11:41:12 +01001040{
Ole Troan03092c12021-11-23 15:55:39 +01001041 int nh = hc->eh[hc->length - 1].protocol;
1042 /* Checking to see if it's a terminating header */
1043 if (ip6_ext_hdr (nh))
Klement Sekera4c533132018-02-22 11:41:12 +01001044 {
Ole Troan03092c12021-11-23 15:55:39 +01001045 icmp6_error_set_vnet_buffer (
1046 b, ICMP6_parameter_problem,
1047 ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain, 0);
Klement Sekera4c533132018-02-22 11:41:12 +01001048 b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
Klement Sekera4c533132018-02-22 11:41:12 +01001049 return false;
1050 }
1051 return true;
1052}
1053
1054always_inline bool
Klement Sekera896c8962019-06-24 11:52:49 +00001055ip6_full_reass_verify_fragment_multiple_8 (vlib_main_t * vm,
Klement Sekera896c8962019-06-24 11:52:49 +00001056 vlib_buffer_t * b,
1057 ip6_frag_hdr_t * frag_hdr)
Klement Sekera4c533132018-02-22 11:41:12 +01001058{
1059 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
1060 ip6_header_t *ip = vlib_buffer_get_current (b);
1061 int more_fragments = ip6_frag_hdr_more (frag_hdr);
1062 u32 fragment_length =
1063 vlib_buffer_length_in_chain (vm, b) -
1064 (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
1065 if (more_fragments && 0 != fragment_length % 8)
1066 {
1067 icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
1068 ICMP6_parameter_problem_erroneous_header_field,
1069 (u8 *) & ip->payload_length - (u8 *) ip);
1070 return false;
1071 }
1072 return true;
1073}
1074
1075always_inline bool
Klement Sekera896c8962019-06-24 11:52:49 +00001076ip6_full_reass_verify_packet_size_lt_64k (vlib_main_t * vm,
Klement Sekera896c8962019-06-24 11:52:49 +00001077 vlib_buffer_t * b,
1078 ip6_frag_hdr_t * frag_hdr)
Klement Sekera4c533132018-02-22 11:41:12 +01001079{
1080 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
1081 u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
1082 u32 fragment_length =
1083 vlib_buffer_length_in_chain (vm, b) -
1084 (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
1085 if (fragment_first + fragment_length > 65535)
1086 {
1087 ip6_header_t *ip0 = vlib_buffer_get_current (b);
1088 icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
1089 ICMP6_parameter_problem_erroneous_header_field,
1090 (u8 *) & frag_hdr->fragment_offset_and_more
1091 - (u8 *) ip0);
1092 return false;
1093 }
1094 return true;
1095}
1096
Klement Sekera75e7d132017-09-20 08:26:30 +02001097always_inline uword
Klement Sekera01c1fa42021-12-14 18:25:11 +00001098ip6_full_reassembly_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
1099 vlib_frame_t *frame, bool is_feature,
1100 bool is_custom_app, bool is_local)
Klement Sekera75e7d132017-09-20 08:26:30 +02001101{
1102 u32 *from = vlib_frame_vector_args (frame);
1103 u32 n_left_from, n_left_to_next, *to_next, next_index;
Klement Sekera896c8962019-06-24 11:52:49 +00001104 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
1105 ip6_full_reass_per_thread_t *rt = &rm->per_thread_data[vm->thread_index];
Klement Sekera4c533132018-02-22 11:41:12 +01001106 clib_spinlock_lock (&rt->lock);
Klement Sekera75e7d132017-09-20 08:26:30 +02001107
1108 n_left_from = frame->n_vectors;
1109 next_index = node->cached_next_index;
Klement Sekeraf883f6a2019-02-13 11:01:32 +01001110 while (n_left_from > 0)
Klement Sekera75e7d132017-09-20 08:26:30 +02001111 {
1112 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1113
Klement Sekera75e7d132017-09-20 08:26:30 +02001114 while (n_left_from > 0 && n_left_to_next > 0)
1115 {
1116 u32 bi0;
1117 vlib_buffer_t *b0;
Klement Sekera896c8962019-06-24 11:52:49 +00001118 u32 next0 = IP6_FULL_REASSEMBLY_NEXT_DROP;
Klement Sekera4c533132018-02-22 11:41:12 +01001119 u32 error0 = IP6_ERROR_NONE;
1120 u32 icmp_bi = ~0;
Klement Sekera75e7d132017-09-20 08:26:30 +02001121
1122 bi0 = from[0];
1123 b0 = vlib_get_buffer (vm, bi0);
1124
1125 ip6_header_t *ip0 = vlib_buffer_get_current (b0);
Ole Troan03092c12021-11-23 15:55:39 +01001126 ip6_frag_hdr_t *frag_hdr;
1127 ip6_ext_hdr_chain_t hdr_chain;
1128 int res = ip6_ext_header_walk (
1129 b0, ip0, IP_PROTOCOL_IPV6_FRAGMENTATION, &hdr_chain);
1130 if (res < 0 ||
1131 hdr_chain.eh[res].protocol != IP_PROTOCOL_IPV6_FRAGMENTATION)
Klement Sekera3ecc2212018-03-27 10:34:43 +02001132 {
Ole Troan03092c12021-11-23 15:55:39 +01001133 // this is a mangled packet - no fragmentation
1134 next0 = IP6_FULL_REASSEMBLY_NEXT_DROP;
Klement Sekera01c1fa42021-12-14 18:25:11 +00001135 ip6_full_reass_add_trace (vm, node, NULL, bi0, NULL, PASSTHROUGH,
1136 ~0);
1137 goto skip_reass;
1138 }
1139 if (is_local && !rm->is_local_reass_enabled)
1140 {
1141 next0 = IP6_FULL_REASSEMBLY_NEXT_DROP;
Klement Sekera4c533132018-02-22 11:41:12 +01001142 goto skip_reass;
1143 }
Ole Troan03092c12021-11-23 15:55:39 +01001144 frag_hdr =
1145 ip6_ext_next_header_offset (ip0, hdr_chain.eh[res].offset);
Klement Sekera38f7ccb2019-10-28 11:26:28 +00001146 vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
Ole Troan03092c12021-11-23 15:55:39 +01001147 hdr_chain.eh[res].offset;
Klement Sekera38f7ccb2019-10-28 11:26:28 +00001148
Klement Sekera75e7d132017-09-20 08:26:30 +02001149 if (0 == ip6_frag_hdr_offset (frag_hdr))
1150 {
1151 // first fragment - verify upper-layer is present
Ole Troan03092c12021-11-23 15:55:39 +01001152 if (!ip6_full_reass_verify_upper_layer_present (node, b0,
1153 &hdr_chain))
Klement Sekera75e7d132017-09-20 08:26:30 +02001154 {
Klement Sekera896c8962019-06-24 11:52:49 +00001155 next0 = IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR;
Klement Sekera4c533132018-02-22 11:41:12 +01001156 goto skip_reass;
Klement Sekera75e7d132017-09-20 08:26:30 +02001157 }
Klement Sekera4c533132018-02-22 11:41:12 +01001158 }
Klement Sekera42cec0e2021-08-02 16:14:15 +02001159 if (!ip6_full_reass_verify_fragment_multiple_8 (vm, b0, frag_hdr) ||
1160 !ip6_full_reass_verify_packet_size_lt_64k (vm, b0, frag_hdr))
Klement Sekera4c533132018-02-22 11:41:12 +01001161 {
Klement Sekera896c8962019-06-24 11:52:49 +00001162 next0 = IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR;
Klement Sekera4c533132018-02-22 11:41:12 +01001163 goto skip_reass;
Klement Sekera75e7d132017-09-20 08:26:30 +02001164 }
Klement Sekera7c3275e2021-12-07 09:49:53 +00001165
1166 int skip_bihash = 0;
Klement Sekera896c8962019-06-24 11:52:49 +00001167 ip6_full_reass_kv_t kv;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001168 u8 do_handoff = 0;
Klement Sekera75e7d132017-09-20 08:26:30 +02001169
Klement Sekera7c3275e2021-12-07 09:49:53 +00001170 if (0 == ip6_frag_hdr_offset (frag_hdr) &&
1171 !ip6_frag_hdr_more (frag_hdr))
1172 {
1173 // this is atomic fragment and needs to be processed separately
1174 skip_bihash = 1;
1175 }
1176 else
1177 {
1178 kv.k.as_u64[0] = ip0->src_address.as_u64[0];
1179 kv.k.as_u64[1] = ip0->src_address.as_u64[1];
1180 kv.k.as_u64[2] = ip0->dst_address.as_u64[0];
1181 kv.k.as_u64[3] = ip0->dst_address.as_u64[1];
1182 kv.k.as_u64[4] =
1183 ((u64) vec_elt (ip6_main.fib_index_by_sw_if_index,
1184 vnet_buffer (b0)->sw_if_index[VLIB_RX]))
1185 << 32 |
1186 (u64) frag_hdr->identification;
1187 kv.k.as_u64[5] = ip0->protocol;
1188 }
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001189
Klement Sekera7c3275e2021-12-07 09:49:53 +00001190 ip6_full_reass_t *reass = ip6_full_reass_find_or_create (
1191 vm, node, rm, rt, &kv, &icmp_bi, &do_handoff, skip_bihash);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001192
Klement Sekera630ab582019-07-19 09:14:19 +00001193 if (reass)
1194 {
1195 const u32 fragment_first = ip6_frag_hdr_offset (frag_hdr);
1196 if (0 == fragment_first)
1197 {
1198 reass->sendout_thread_index = vm->thread_index;
1199 }
1200 }
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001201 if (PREDICT_FALSE (do_handoff))
1202 {
Klement Sekera896c8962019-06-24 11:52:49 +00001203 next0 = IP6_FULL_REASSEMBLY_NEXT_HANDOFF;
Klement Sekerade34c352019-06-25 11:19:22 +00001204 vnet_buffer (b0)->ip.reass.owner_thread_index =
1205 kv.v.memory_owner_thread_index;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001206 }
1207 else if (reass)
Klement Sekera75e7d132017-09-20 08:26:30 +02001208 {
Klement Sekera630ab582019-07-19 09:14:19 +00001209 u32 handoff_thread_idx;
Klement Sekerad4ba0d12021-11-02 15:33:55 +01001210 u32 counter = ~0;
Klement Sekera7c3275e2021-12-07 09:49:53 +00001211 switch (ip6_full_reass_update (
1212 vm, node, rm, rt, reass, &bi0, &next0, &error0, frag_hdr,
1213 is_custom_app, &handoff_thread_idx, skip_bihash))
Klement Sekerad0f70a32018-12-14 17:24:13 +01001214 {
Klement Sekera896c8962019-06-24 11:52:49 +00001215 case IP6_FULL_REASS_RC_OK:
Klement Sekerad0f70a32018-12-14 17:24:13 +01001216 /* nothing to do here */
1217 break;
Klement Sekera896c8962019-06-24 11:52:49 +00001218 case IP6_FULL_REASS_RC_HANDOFF:
1219 next0 = IP6_FULL_REASSEMBLY_NEXT_HANDOFF;
Klement Sekera630ab582019-07-19 09:14:19 +00001220 b0 = vlib_get_buffer (vm, bi0);
Klement Sekerade34c352019-06-25 11:19:22 +00001221 vnet_buffer (b0)->ip.reass.owner_thread_index =
1222 handoff_thread_idx;
Klement Sekera630ab582019-07-19 09:14:19 +00001223 break;
Klement Sekera896c8962019-06-24 11:52:49 +00001224 case IP6_FULL_REASS_RC_TOO_MANY_FRAGMENTS:
Klement Sekerad4ba0d12021-11-02 15:33:55 +01001225 counter = IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG;
Klement Sekera3a343d42019-05-16 14:35:46 +02001226 break;
Klement Sekera896c8962019-06-24 11:52:49 +00001227 case IP6_FULL_REASS_RC_NO_BUF:
Klement Sekerad4ba0d12021-11-02 15:33:55 +01001228 counter = IP6_ERROR_REASS_NO_BUF;
Klement Sekera3a343d42019-05-16 14:35:46 +02001229 break;
Klement Sekera896c8962019-06-24 11:52:49 +00001230 case IP6_FULL_REASS_RC_INTERNAL_ERROR:
Klement Sekerad4ba0d12021-11-02 15:33:55 +01001231 counter = IP6_ERROR_REASS_INTERNAL_ERROR;
1232 break;
Klement Sekera755042d2021-12-01 10:14:38 +00001233 case IP6_FULL_REASS_RC_INVALID_FRAG_LEN:
1234 counter = IP6_ERROR_REASS_INVALID_FRAG_LEN;
1235 break;
Klement Sekerae63a2d42021-05-20 12:23:00 +02001236 case IP6_FULL_REASS_RC_OVERLAP:
1237 counter = IP6_ERROR_REASS_OVERLAPPING_FRAGMENT;
1238 break;
Klement Sekerad4ba0d12021-11-02 15:33:55 +01001239 }
1240 if (~0 != counter)
1241 {
1242 vlib_node_increment_counter (vm, node->node_index, counter,
Klement Sekera3a343d42019-05-16 14:35:46 +02001243 1);
Klement Sekerae63a2d42021-05-20 12:23:00 +02001244 ip6_full_reass_drop_all (vm, node, reass, bi0);
Klement Sekera896c8962019-06-24 11:52:49 +00001245 ip6_full_reass_free (rm, rt, reass);
Klement Sekerad0f70a32018-12-14 17:24:13 +01001246 goto next_packet;
Klement Sekerae63a2d42021-05-20 12:23:00 +02001247 break;
Klement Sekerad0f70a32018-12-14 17:24:13 +01001248 }
Klement Sekera75e7d132017-09-20 08:26:30 +02001249 }
1250 else
1251 {
Klement Sekera21aa8f12019-05-20 12:27:33 +02001252 if (is_feature)
1253 {
Klement Sekera896c8962019-06-24 11:52:49 +00001254 next0 = IP6_FULL_REASSEMBLY_NEXT_DROP;
Klement Sekera21aa8f12019-05-20 12:27:33 +02001255 }
1256 else
1257 {
1258 vnet_buffer_opaque_t *fvnb = vnet_buffer (b0);
1259 next0 = fvnb->ip.reass.error_next_index;
1260 }
Klement Sekera75e7d132017-09-20 08:26:30 +02001261 error0 = IP6_ERROR_REASS_LIMIT_REACHED;
1262 }
1263
Klement Sekera75e7d132017-09-20 08:26:30 +02001264 if (~0 != bi0)
1265 {
Klement Sekera4c533132018-02-22 11:41:12 +01001266 skip_reass:
Klement Sekera75e7d132017-09-20 08:26:30 +02001267 to_next[0] = bi0;
1268 to_next += 1;
1269 n_left_to_next -= 1;
Benoît Gannecf7803d2019-10-23 13:53:49 +02001270
1271 /* bi0 might have been updated by reass_finalize, reload */
1272 b0 = vlib_get_buffer (vm, bi0);
Klement Sekera1766ddc2020-03-30 16:59:38 +02001273 if (IP6_ERROR_NONE != error0)
1274 {
1275 b0->error = node->errors[error0];
1276 }
Benoît Gannecf7803d2019-10-23 13:53:49 +02001277
Klement Sekera896c8962019-06-24 11:52:49 +00001278 if (next0 == IP6_FULL_REASSEMBLY_NEXT_HANDOFF)
Klement Sekera630ab582019-07-19 09:14:19 +00001279 {
1280 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1281 {
Klement Sekera42cec0e2021-08-02 16:14:15 +02001282 ip6_full_reass_add_trace (
1283 vm, node, NULL, bi0, frag_hdr, HANDOFF,
1284 vnet_buffer (b0)->ip.reass.owner_thread_index);
Klement Sekera630ab582019-07-19 09:14:19 +00001285 }
1286 }
1287 else if (is_feature && IP6_ERROR_NONE == error0)
Klement Sekera4c533132018-02-22 11:41:12 +01001288 {
Damjan Marion7d98a122018-07-19 20:42:08 +02001289 vnet_feature_next (&next0, b0);
Klement Sekera4c533132018-02-22 11:41:12 +01001290 }
Klement Sekera75e7d132017-09-20 08:26:30 +02001291 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1292 n_left_to_next, bi0, next0);
1293 }
1294
1295 if (~0 != icmp_bi)
1296 {
Klement Sekera896c8962019-06-24 11:52:49 +00001297 next0 = IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR;
Klement Sekera75e7d132017-09-20 08:26:30 +02001298 to_next[0] = icmp_bi;
1299 to_next += 1;
1300 n_left_to_next -= 1;
1301 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1302 n_left_to_next, icmp_bi,
1303 next0);
1304 }
Klement Sekerad0f70a32018-12-14 17:24:13 +01001305 next_packet:
Klement Sekera75e7d132017-09-20 08:26:30 +02001306 from += 1;
1307 n_left_from -= 1;
1308 }
1309
1310 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1311 }
1312
Klement Sekera4c533132018-02-22 11:41:12 +01001313 clib_spinlock_unlock (&rt->lock);
Klement Sekera75e7d132017-09-20 08:26:30 +02001314 return frame->n_vectors;
1315}
1316
Klement Sekera896c8962019-06-24 11:52:49 +00001317static char *ip6_full_reassembly_error_strings[] = {
Klement Sekera75e7d132017-09-20 08:26:30 +02001318#define _(sym, string) string,
1319 foreach_ip6_error
1320#undef _
1321};
1322
Klement Sekera896c8962019-06-24 11:52:49 +00001323VLIB_NODE_FN (ip6_full_reass_node) (vlib_main_t * vm,
1324 vlib_node_runtime_t * node,
1325 vlib_frame_t * frame)
Klement Sekera4c533132018-02-22 11:41:12 +01001326{
Klement Sekera01c1fa42021-12-14 18:25:11 +00001327 return ip6_full_reassembly_inline (vm, node, frame, false /* is_feature */,
1328 false /* is_custom_app */,
1329 false /* is_local */);
Klement Sekera4c533132018-02-22 11:41:12 +01001330}
1331
Klement Sekera896c8962019-06-24 11:52:49 +00001332VLIB_REGISTER_NODE (ip6_full_reass_node) = {
1333 .name = "ip6-full-reassembly",
Klement Sekera75e7d132017-09-20 08:26:30 +02001334 .vector_size = sizeof (u32),
Klement Sekera896c8962019-06-24 11:52:49 +00001335 .format_trace = format_ip6_full_reass_trace,
1336 .n_errors = ARRAY_LEN (ip6_full_reassembly_error_strings),
1337 .error_strings = ip6_full_reassembly_error_strings,
1338 .n_next_nodes = IP6_FULL_REASSEMBLY_N_NEXT,
Klement Sekera75e7d132017-09-20 08:26:30 +02001339 .next_nodes =
1340 {
Klement Sekera896c8962019-06-24 11:52:49 +00001341 [IP6_FULL_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1342 [IP6_FULL_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1343 [IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1344 [IP6_FULL_REASSEMBLY_NEXT_HANDOFF] = "ip6-full-reassembly-handoff",
Klement Sekera75e7d132017-09-20 08:26:30 +02001345 },
1346};
Klement Sekera75e7d132017-09-20 08:26:30 +02001347
Klement Sekera01c1fa42021-12-14 18:25:11 +00001348VLIB_NODE_FN (ip6_local_full_reass_node)
1349(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
1350{
1351 return ip6_full_reassembly_inline (vm, node, frame, false /* is_feature */,
1352 false /* is_custom_app */,
1353 true /* is_local */);
1354}
1355
1356VLIB_REGISTER_NODE (ip6_local_full_reass_node) = {
1357 .name = "ip6-local-full-reassembly",
1358 .vector_size = sizeof (u32),
1359 .format_trace = format_ip6_full_reass_trace,
1360 .n_errors = ARRAY_LEN (ip6_full_reassembly_error_strings),
1361 .error_strings = ip6_full_reassembly_error_strings,
1362 .n_next_nodes = IP6_FULL_REASSEMBLY_N_NEXT,
1363 .next_nodes =
1364 {
1365 [IP6_FULL_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1366 [IP6_FULL_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1367 [IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1368 [IP6_FULL_REASSEMBLY_NEXT_HANDOFF] = "ip6-local-full-reassembly-handoff",
1369 },
1370};
1371
Klement Sekera896c8962019-06-24 11:52:49 +00001372VLIB_NODE_FN (ip6_full_reass_node_feature) (vlib_main_t * vm,
1373 vlib_node_runtime_t * node,
1374 vlib_frame_t * frame)
Klement Sekera4c533132018-02-22 11:41:12 +01001375{
Klement Sekera01c1fa42021-12-14 18:25:11 +00001376 return ip6_full_reassembly_inline (vm, node, frame, true /* is_feature */,
1377 false /* is_custom_app */,
1378 false /* is_local */);
Klement Sekera4c533132018-02-22 11:41:12 +01001379}
1380
Klement Sekera896c8962019-06-24 11:52:49 +00001381VLIB_REGISTER_NODE (ip6_full_reass_node_feature) = {
1382 .name = "ip6-full-reassembly-feature",
Klement Sekera4c533132018-02-22 11:41:12 +01001383 .vector_size = sizeof (u32),
Klement Sekera896c8962019-06-24 11:52:49 +00001384 .format_trace = format_ip6_full_reass_trace,
1385 .n_errors = ARRAY_LEN (ip6_full_reassembly_error_strings),
1386 .error_strings = ip6_full_reassembly_error_strings,
1387 .n_next_nodes = IP6_FULL_REASSEMBLY_N_NEXT,
Klement Sekera4c533132018-02-22 11:41:12 +01001388 .next_nodes =
1389 {
Klement Sekera896c8962019-06-24 11:52:49 +00001390 [IP6_FULL_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1391 [IP6_FULL_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1392 [IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1393 [IP6_FULL_REASSEMBLY_NEXT_HANDOFF] = "ip6-full-reass-feature-hoff",
Klement Sekera4c533132018-02-22 11:41:12 +01001394 },
1395};
Klement Sekera4c533132018-02-22 11:41:12 +01001396
Klement Sekera896c8962019-06-24 11:52:49 +00001397VNET_FEATURE_INIT (ip6_full_reassembly_feature, static) = {
Klement Sekera4c533132018-02-22 11:41:12 +01001398 .arc_name = "ip6-unicast",
Klement Sekera896c8962019-06-24 11:52:49 +00001399 .node_name = "ip6-full-reassembly-feature",
Neale Ranns14046982019-07-29 14:49:52 +00001400 .runs_before = VNET_FEATURES ("ip6-lookup",
Neale Ranns2be3eb62019-08-02 01:17:13 -07001401 "ipsec6-input-feature"),
Klement Sekera4c533132018-02-22 11:41:12 +01001402 .runs_after = 0,
1403};
Klement Sekera4c533132018-02-22 11:41:12 +01001404
Filip Tehlar26ea14e2019-03-11 05:30:21 -07001405#ifndef CLIB_MARCH_VARIANT
Klement Sekera4c533132018-02-22 11:41:12 +01001406static u32
Klement Sekera896c8962019-06-24 11:52:49 +00001407ip6_full_reass_get_nbuckets ()
Klement Sekera75e7d132017-09-20 08:26:30 +02001408{
Klement Sekera896c8962019-06-24 11:52:49 +00001409 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
Klement Sekera75e7d132017-09-20 08:26:30 +02001410 u32 nbuckets;
1411 u8 i;
1412
Vijayabhaskar Katamreddy3fda2002022-05-16 22:18:37 +00001413 /* need more mem with more workers */
1414 nbuckets = (u32) (rm->max_reass_n * (vlib_num_workers () + 1) /
1415 IP6_FULL_REASS_HT_LOAD_FACTOR);
Klement Sekera75e7d132017-09-20 08:26:30 +02001416
1417 for (i = 0; i < 31; i++)
1418 if ((1 << i) >= nbuckets)
1419 break;
1420 nbuckets = 1 << i;
1421
1422 return nbuckets;
1423}
Filip Tehlar26ea14e2019-03-11 05:30:21 -07001424#endif /* CLIB_MARCH_VARIANT */
Klement Sekera75e7d132017-09-20 08:26:30 +02001425
1426typedef enum
1427{
1428 IP6_EVENT_CONFIG_CHANGED = 1,
Klement Sekera896c8962019-06-24 11:52:49 +00001429} ip6_full_reass_event_t;
Klement Sekera75e7d132017-09-20 08:26:30 +02001430
Filip Tehlar26ea14e2019-03-11 05:30:21 -07001431#ifndef CLIB_MARCH_VARIANT
Klement Sekera75e7d132017-09-20 08:26:30 +02001432typedef struct
1433{
1434 int failure;
1435 clib_bihash_48_8_t *new_hash;
1436} ip6_rehash_cb_ctx;
1437
Neale Rannsf50bac12019-12-06 05:53:17 +00001438static int
Klement Sekera75e7d132017-09-20 08:26:30 +02001439ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
1440{
1441 ip6_rehash_cb_ctx *ctx = _ctx;
1442 if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
1443 {
1444 ctx->failure = 1;
1445 }
Neale Rannsf50bac12019-12-06 05:53:17 +00001446 return (BIHASH_WALK_CONTINUE);
Klement Sekera75e7d132017-09-20 08:26:30 +02001447}
1448
Klement Sekera4c533132018-02-22 11:41:12 +01001449static void
Klement Sekera896c8962019-06-24 11:52:49 +00001450ip6_full_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
1451 u32 max_reassembly_length,
1452 u32 expire_walk_interval_ms)
Klement Sekera4c533132018-02-22 11:41:12 +01001453{
Klement Sekera896c8962019-06-24 11:52:49 +00001454 ip6_full_reass_main.timeout_ms = timeout_ms;
1455 ip6_full_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
1456 ip6_full_reass_main.max_reass_n = max_reassemblies;
1457 ip6_full_reass_main.max_reass_len = max_reassembly_length;
1458 ip6_full_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
Klement Sekera4c533132018-02-22 11:41:12 +01001459}
1460
Klement Sekera75e7d132017-09-20 08:26:30 +02001461vnet_api_error_t
Klement Sekera896c8962019-06-24 11:52:49 +00001462ip6_full_reass_set (u32 timeout_ms, u32 max_reassemblies,
1463 u32 max_reassembly_length, u32 expire_walk_interval_ms)
Klement Sekera75e7d132017-09-20 08:26:30 +02001464{
Klement Sekera896c8962019-06-24 11:52:49 +00001465 u32 old_nbuckets = ip6_full_reass_get_nbuckets ();
1466 ip6_full_reass_set_params (timeout_ms, max_reassemblies,
1467 max_reassembly_length, expire_walk_interval_ms);
1468 vlib_process_signal_event (ip6_full_reass_main.vlib_main,
1469 ip6_full_reass_main.ip6_full_reass_expire_node_idx,
Klement Sekera75e7d132017-09-20 08:26:30 +02001470 IP6_EVENT_CONFIG_CHANGED, 0);
Klement Sekera896c8962019-06-24 11:52:49 +00001471 u32 new_nbuckets = ip6_full_reass_get_nbuckets ();
1472 if (ip6_full_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
Klement Sekera75e7d132017-09-20 08:26:30 +02001473 {
1474 clib_bihash_48_8_t new_hash;
Dave Barachb7b92992018-10-17 10:38:51 -04001475 clib_memset (&new_hash, 0, sizeof (new_hash));
Klement Sekera75e7d132017-09-20 08:26:30 +02001476 ip6_rehash_cb_ctx ctx;
1477 ctx.failure = 0;
1478 ctx.new_hash = &new_hash;
Klement Sekera896c8962019-06-24 11:52:49 +00001479 clib_bihash_init_48_8 (&new_hash, "ip6-full-reass", new_nbuckets,
Klement Sekera75e7d132017-09-20 08:26:30 +02001480 new_nbuckets * 1024);
Klement Sekera896c8962019-06-24 11:52:49 +00001481 clib_bihash_foreach_key_value_pair_48_8 (&ip6_full_reass_main.hash,
Klement Sekera75e7d132017-09-20 08:26:30 +02001482 ip6_rehash_cb, &ctx);
1483 if (ctx.failure)
1484 {
1485 clib_bihash_free_48_8 (&new_hash);
1486 return -1;
1487 }
1488 else
1489 {
Klement Sekera896c8962019-06-24 11:52:49 +00001490 clib_bihash_free_48_8 (&ip6_full_reass_main.hash);
1491 clib_memcpy_fast (&ip6_full_reass_main.hash, &new_hash,
1492 sizeof (ip6_full_reass_main.hash));
1493 clib_bihash_copied (&ip6_full_reass_main.hash, &new_hash);
Klement Sekera75e7d132017-09-20 08:26:30 +02001494 }
1495 }
1496 return 0;
1497}
1498
1499vnet_api_error_t
Klement Sekera896c8962019-06-24 11:52:49 +00001500ip6_full_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
1501 u32 * max_reassembly_length,
1502 u32 * expire_walk_interval_ms)
Klement Sekera75e7d132017-09-20 08:26:30 +02001503{
Klement Sekera896c8962019-06-24 11:52:49 +00001504 *timeout_ms = ip6_full_reass_main.timeout_ms;
1505 *max_reassemblies = ip6_full_reass_main.max_reass_n;
1506 *max_reassembly_length = ip6_full_reass_main.max_reass_len;
1507 *expire_walk_interval_ms = ip6_full_reass_main.expire_walk_interval_ms;
Klement Sekera75e7d132017-09-20 08:26:30 +02001508 return 0;
1509}
1510
Klement Sekera4c533132018-02-22 11:41:12 +01001511static clib_error_t *
Klement Sekera896c8962019-06-24 11:52:49 +00001512ip6_full_reass_init_function (vlib_main_t * vm)
Klement Sekera75e7d132017-09-20 08:26:30 +02001513{
Klement Sekera896c8962019-06-24 11:52:49 +00001514 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
Klement Sekera75e7d132017-09-20 08:26:30 +02001515 clib_error_t *error = 0;
1516 u32 nbuckets;
Dave Barach1403fcd2018-02-05 09:45:43 -05001517 vlib_node_t *node;
Klement Sekera75e7d132017-09-20 08:26:30 +02001518
1519 rm->vlib_main = vm;
Klement Sekera75e7d132017-09-20 08:26:30 +02001520
Juraj Slobodacd806922018-10-10 10:15:54 +02001521 vec_validate (rm->per_thread_data, vlib_num_workers ());
Klement Sekera896c8962019-06-24 11:52:49 +00001522 ip6_full_reass_per_thread_t *rt;
Klement Sekera4c533132018-02-22 11:41:12 +01001523 vec_foreach (rt, rm->per_thread_data)
1524 {
1525 clib_spinlock_init (&rt->lock);
1526 pool_alloc (rt->pool, rm->max_reass_n);
1527 }
Dave Barach1403fcd2018-02-05 09:45:43 -05001528
Klement Sekera896c8962019-06-24 11:52:49 +00001529 node = vlib_get_node_by_name (vm, (u8 *) "ip6-full-reassembly-expire-walk");
Dave Barach1403fcd2018-02-05 09:45:43 -05001530 ASSERT (node);
Klement Sekera896c8962019-06-24 11:52:49 +00001531 rm->ip6_full_reass_expire_node_idx = node->index;
Dave Barach1403fcd2018-02-05 09:45:43 -05001532
Klement Sekera896c8962019-06-24 11:52:49 +00001533 ip6_full_reass_set_params (IP6_FULL_REASS_TIMEOUT_DEFAULT_MS,
1534 IP6_FULL_REASS_MAX_REASSEMBLIES_DEFAULT,
1535 IP6_FULL_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT,
1536 IP6_FULL_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
Klement Sekera3ecc2212018-03-27 10:34:43 +02001537
Klement Sekera896c8962019-06-24 11:52:49 +00001538 nbuckets = ip6_full_reass_get_nbuckets ();
1539 clib_bihash_init_48_8 (&rm->hash, "ip6-full-reass", nbuckets,
1540 nbuckets * 1024);
Klement Sekera75e7d132017-09-20 08:26:30 +02001541
Klement Sekera75e7d132017-09-20 08:26:30 +02001542 node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
1543 ASSERT (node);
1544 rm->ip6_icmp_error_idx = node->index;
1545
1546 if ((error = vlib_call_init_function (vm, ip_main_init)))
1547 return error;
1548 ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
Klement Sekera01c1fa42021-12-14 18:25:11 +00001549 ip6_local_full_reass_node.index);
1550 rm->is_local_reass_enabled = 1;
Klement Sekera4c533132018-02-22 11:41:12 +01001551
Klement Sekera896c8962019-06-24 11:52:49 +00001552 rm->fq_index = vlib_frame_queue_main_init (ip6_full_reass_node.index, 0);
Klement Sekera01c1fa42021-12-14 18:25:11 +00001553 rm->fq_local_index =
1554 vlib_frame_queue_main_init (ip6_local_full_reass_node.index, 0);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001555 rm->fq_feature_index =
Klement Sekera896c8962019-06-24 11:52:49 +00001556 vlib_frame_queue_main_init (ip6_full_reass_node_feature.index, 0);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001557
Klement Sekera7b2e9fb2019-10-01 13:00:22 +00001558 rm->feature_use_refcount_per_intf = NULL;
Klement Sekera75e7d132017-09-20 08:26:30 +02001559 return error;
1560}
1561
Klement Sekera896c8962019-06-24 11:52:49 +00001562VLIB_INIT_FUNCTION (ip6_full_reass_init_function);
Filip Tehlar26ea14e2019-03-11 05:30:21 -07001563#endif /* CLIB_MARCH_VARIANT */
Klement Sekera75e7d132017-09-20 08:26:30 +02001564
1565static uword
Klement Sekera42cec0e2021-08-02 16:14:15 +02001566ip6_full_reass_walk_expired (vlib_main_t *vm, vlib_node_runtime_t *node,
1567 CLIB_UNUSED (vlib_frame_t *f))
Klement Sekera75e7d132017-09-20 08:26:30 +02001568{
Klement Sekera896c8962019-06-24 11:52:49 +00001569 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
Klement Sekera75e7d132017-09-20 08:26:30 +02001570 uword event_type, *event_data = 0;
1571
1572 while (true)
1573 {
1574 vlib_process_wait_for_event_or_clock (vm,
1575 (f64) rm->expire_walk_interval_ms
1576 / (f64) MSEC_PER_SEC);
1577 event_type = vlib_process_get_events (vm, &event_data);
1578
1579 switch (event_type)
1580 {
Klement Sekera42cec0e2021-08-02 16:14:15 +02001581 case ~0:
1582 /* no events => timeout */
1583 /* fallthrough */
Klement Sekera75e7d132017-09-20 08:26:30 +02001584 case IP6_EVENT_CONFIG_CHANGED:
Klement Sekera42cec0e2021-08-02 16:14:15 +02001585 /* nothing to do here */
Klement Sekera75e7d132017-09-20 08:26:30 +02001586 break;
1587 default:
1588 clib_warning ("BUG: event type 0x%wx", event_type);
1589 break;
1590 }
1591 f64 now = vlib_time_now (vm);
1592
Klement Sekera896c8962019-06-24 11:52:49 +00001593 ip6_full_reass_t *reass;
Klement Sekera75e7d132017-09-20 08:26:30 +02001594 int *pool_indexes_to_free = NULL;
1595
Klement Sekera4c533132018-02-22 11:41:12 +01001596 uword thread_index = 0;
Klement Sekera75e7d132017-09-20 08:26:30 +02001597 int index;
Juraj Slobodacd806922018-10-10 10:15:54 +02001598 const uword nthreads = vlib_num_workers () + 1;
Klement Sekera75e7d132017-09-20 08:26:30 +02001599 u32 *vec_icmp_bi = NULL;
Klement Sekera4c533132018-02-22 11:41:12 +01001600 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1601 {
Klement Sekera896c8962019-06-24 11:52:49 +00001602 ip6_full_reass_per_thread_t *rt =
1603 &rm->per_thread_data[thread_index];
Klement Sekera4c533132018-02-22 11:41:12 +01001604 clib_spinlock_lock (&rt->lock);
1605
1606 vec_reset_length (pool_indexes_to_free);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001607 pool_foreach_index (index, rt->pool) {
Klement Sekera4c533132018-02-22 11:41:12 +01001608 reass = pool_elt_at_index (rt->pool, index);
1609 if (now > reass->last_heard + rm->timeout)
1610 {
1611 vec_add1 (pool_indexes_to_free, index);
1612 }
Damjan Marionb2c31b62020-12-13 21:47:40 +01001613 }
Klement Sekera4c533132018-02-22 11:41:12 +01001614 int *i;
Klement Sekera4c533132018-02-22 11:41:12 +01001615 vec_foreach (i, pool_indexes_to_free)
Klement Sekera75e7d132017-09-20 08:26:30 +02001616 {
Klement Sekera896c8962019-06-24 11:52:49 +00001617 ip6_full_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
Klement Sekera4c533132018-02-22 11:41:12 +01001618 u32 icmp_bi = ~0;
Klement Sekera42cec0e2021-08-02 16:14:15 +02001619 ip6_full_reass_on_timeout (vm, node, reass, &icmp_bi);
1620 if (~0 != icmp_bi)
1621 vec_add1 (vec_icmp_bi, icmp_bi);
Dave Baracha638c182019-06-21 18:24:07 -04001622
Klement Sekera42cec0e2021-08-02 16:14:15 +02001623 ip6_full_reass_free (rm, rt, reass);
1624 }
Klement Sekera4c533132018-02-22 11:41:12 +01001625
1626 clib_spinlock_unlock (&rt->lock);
1627 }
Klement Sekera75e7d132017-09-20 08:26:30 +02001628
Klement Sekera75e7d132017-09-20 08:26:30 +02001629 while (vec_len (vec_icmp_bi) > 0)
1630 {
1631 vlib_frame_t *f =
1632 vlib_get_frame_to_node (vm, rm->ip6_icmp_error_idx);
1633 u32 *to_next = vlib_frame_vector_args (f);
1634 u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
Klement Sekera4c533132018-02-22 11:41:12 +01001635 int trace_frame = 0;
Klement Sekera75e7d132017-09-20 08:26:30 +02001636 while (vec_len (vec_icmp_bi) > 0 && n_left_to_next > 0)
1637 {
1638 u32 bi = vec_pop (vec_icmp_bi);
1639 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1640 if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
Dave Baracha638c182019-06-21 18:24:07 -04001641 trace_frame = 1;
Klement Sekera75e7d132017-09-20 08:26:30 +02001642 b->error = node->errors[IP6_ERROR_REASS_TIMEOUT];
1643 to_next[0] = bi;
1644 ++f->n_vectors;
1645 to_next += 1;
1646 n_left_to_next -= 1;
Klement Sekera75e7d132017-09-20 08:26:30 +02001647 }
Damjan Marion633b6fd2018-09-14 14:38:53 +02001648 f->frame_flags |= (trace_frame * VLIB_FRAME_TRACE);
Klement Sekera75e7d132017-09-20 08:26:30 +02001649 vlib_put_frame_to_node (vm, rm->ip6_icmp_error_idx, f);
1650 }
1651
1652 vec_free (pool_indexes_to_free);
Klement Sekera75e7d132017-09-20 08:26:30 +02001653 vec_free (vec_icmp_bi);
1654 if (event_data)
1655 {
Damjan Marion8bea5892022-04-04 22:40:45 +02001656 vec_set_len (event_data, 0);
Klement Sekera75e7d132017-09-20 08:26:30 +02001657 }
1658 }
1659
1660 return 0;
1661}
1662
Klement Sekera896c8962019-06-24 11:52:49 +00001663VLIB_REGISTER_NODE (ip6_full_reass_expire_node) = {
1664 .function = ip6_full_reass_walk_expired,
1665 .format_trace = format_ip6_full_reass_trace,
Klement Sekera75e7d132017-09-20 08:26:30 +02001666 .type = VLIB_NODE_TYPE_PROCESS,
Klement Sekera896c8962019-06-24 11:52:49 +00001667 .name = "ip6-full-reassembly-expire-walk",
Klement Sekera75e7d132017-09-20 08:26:30 +02001668
Klement Sekera896c8962019-06-24 11:52:49 +00001669 .n_errors = ARRAY_LEN (ip6_full_reassembly_error_strings),
1670 .error_strings = ip6_full_reassembly_error_strings,
Klement Sekera75e7d132017-09-20 08:26:30 +02001671
1672};
Klement Sekera75e7d132017-09-20 08:26:30 +02001673
1674static u8 *
Klement Sekera896c8962019-06-24 11:52:49 +00001675format_ip6_full_reass_key (u8 * s, va_list * args)
Klement Sekera75e7d132017-09-20 08:26:30 +02001676{
Klement Sekera896c8962019-06-24 11:52:49 +00001677 ip6_full_reass_key_t *key = va_arg (*args, ip6_full_reass_key_t *);
Klement Sekera75e7d132017-09-20 08:26:30 +02001678 s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1679 key->xx_id, format_ip6_address, &key->src, format_ip6_address,
1680 &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1681 return s;
1682}
1683
1684static u8 *
Klement Sekera896c8962019-06-24 11:52:49 +00001685format_ip6_full_reass (u8 * s, va_list * args)
Klement Sekera75e7d132017-09-20 08:26:30 +02001686{
1687 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera896c8962019-06-24 11:52:49 +00001688 ip6_full_reass_t *reass = va_arg (*args, ip6_full_reass_t *);
Klement Sekera75e7d132017-09-20 08:26:30 +02001689
Klement Sekera4c533132018-02-22 11:41:12 +01001690 s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, "
Klement Sekera75e7d132017-09-20 08:26:30 +02001691 "last_packet_octet: %u, trace_op_counter: %u\n",
Klement Sekera896c8962019-06-24 11:52:49 +00001692 reass->id, format_ip6_full_reass_key, &reass->key,
1693 reass->first_bi, reass->data_len, reass->last_packet_octet,
Klement Sekera75e7d132017-09-20 08:26:30 +02001694 reass->trace_op_counter);
1695 u32 bi = reass->first_bi;
1696 u32 counter = 0;
1697 while (~0 != bi)
1698 {
1699 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1700 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
1701 s = format (s, " #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, "
1702 "fragment[%u, %u]\n",
1703 counter, vnb->ip.reass.range_first,
1704 vnb->ip.reass.range_last, bi,
Klement Sekera896c8962019-06-24 11:52:49 +00001705 ip6_full_reass_buffer_get_data_offset (b),
1706 ip6_full_reass_buffer_get_data_len (b),
Klement Sekera75e7d132017-09-20 08:26:30 +02001707 vnb->ip.reass.fragment_first, vnb->ip.reass.fragment_last);
1708 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
1709 {
1710 bi = b->next_buffer;
1711 }
1712 else
1713 {
1714 bi = ~0;
1715 }
1716 }
1717 return s;
1718}
1719
1720static clib_error_t *
Klement Sekera896c8962019-06-24 11:52:49 +00001721show_ip6_full_reass (vlib_main_t * vm, unformat_input_t * input,
1722 CLIB_UNUSED (vlib_cli_command_t * lmd))
Klement Sekera75e7d132017-09-20 08:26:30 +02001723{
Klement Sekera896c8962019-06-24 11:52:49 +00001724 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
Klement Sekera75e7d132017-09-20 08:26:30 +02001725
1726 vlib_cli_output (vm, "---------------------");
1727 vlib_cli_output (vm, "IP6 reassembly status");
1728 vlib_cli_output (vm, "---------------------");
Klement Sekera4c533132018-02-22 11:41:12 +01001729 bool details = false;
Klement Sekera75e7d132017-09-20 08:26:30 +02001730 if (unformat (input, "details"))
1731 {
Klement Sekera4c533132018-02-22 11:41:12 +01001732 details = true;
1733 }
1734
1735 u32 sum_reass_n = 0;
1736 u64 sum_buffers_n = 0;
Klement Sekera896c8962019-06-24 11:52:49 +00001737 ip6_full_reass_t *reass;
Klement Sekera4c533132018-02-22 11:41:12 +01001738 uword thread_index;
Juraj Slobodacd806922018-10-10 10:15:54 +02001739 const uword nthreads = vlib_num_workers () + 1;
Klement Sekera4c533132018-02-22 11:41:12 +01001740 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1741 {
Klement Sekera896c8962019-06-24 11:52:49 +00001742 ip6_full_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
Klement Sekera4c533132018-02-22 11:41:12 +01001743 clib_spinlock_lock (&rt->lock);
1744 if (details)
1745 {
Damjan Marionb2c31b62020-12-13 21:47:40 +01001746 pool_foreach (reass, rt->pool) {
Klement Sekera896c8962019-06-24 11:52:49 +00001747 vlib_cli_output (vm, "%U", format_ip6_full_reass, vm, reass);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001748 }
Klement Sekera4c533132018-02-22 11:41:12 +01001749 }
1750 sum_reass_n += rt->reass_n;
Klement Sekera4c533132018-02-22 11:41:12 +01001751 clib_spinlock_unlock (&rt->lock);
Klement Sekera75e7d132017-09-20 08:26:30 +02001752 }
1753 vlib_cli_output (vm, "---------------------");
Klement Sekera4c533132018-02-22 11:41:12 +01001754 vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1755 (long unsigned) sum_reass_n);
Vladimir Ratnikova877cf92019-12-21 06:27:52 -05001756 vlib_cli_output (vm,
1757 "Maximum configured concurrent full IP6 reassemblies per worker-thread: %lu\n",
1758 (long unsigned) rm->max_reass_n);
1759 vlib_cli_output (vm,
Anton Nikolaev74a4a702021-02-17 14:45:40 +05001760 "Maximum configured amount of fragments "
1761 "per full IP6 reassembly: %lu\n",
1762 (long unsigned) rm->max_reass_len);
1763 vlib_cli_output (vm,
Vladimir Ratnikova877cf92019-12-21 06:27:52 -05001764 "Maximum configured full IP6 reassembly timeout: %lums\n",
1765 (long unsigned) rm->timeout_ms);
1766 vlib_cli_output (vm,
1767 "Maximum configured full IP6 reassembly expire walk interval: %lums\n",
1768 (long unsigned) rm->expire_walk_interval_ms);
Klement Sekera75e7d132017-09-20 08:26:30 +02001769 vlib_cli_output (vm, "Buffers in use: %lu\n",
Klement Sekera4c533132018-02-22 11:41:12 +01001770 (long unsigned) sum_buffers_n);
Klement Sekera75e7d132017-09-20 08:26:30 +02001771 return 0;
1772}
1773
Klement Sekera896c8962019-06-24 11:52:49 +00001774VLIB_CLI_COMMAND (show_ip6_full_reassembly_cmd, static) = {
1775 .path = "show ip6-full-reassembly",
1776 .short_help = "show ip6-full-reassembly [details]",
1777 .function = show_ip6_full_reass,
Klement Sekera75e7d132017-09-20 08:26:30 +02001778};
Klement Sekera75e7d132017-09-20 08:26:30 +02001779
Filip Tehlar26ea14e2019-03-11 05:30:21 -07001780#ifndef CLIB_MARCH_VARIANT
Klement Sekera4c533132018-02-22 11:41:12 +01001781vnet_api_error_t
Klement Sekera896c8962019-06-24 11:52:49 +00001782ip6_full_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
Klement Sekera4c533132018-02-22 11:41:12 +01001783{
Klement Sekera896c8962019-06-24 11:52:49 +00001784 return vnet_feature_enable_disable ("ip6-unicast",
1785 "ip6-full-reassembly-feature",
Klement Sekera4c533132018-02-22 11:41:12 +01001786 sw_if_index, enable_disable, 0, 0);
1787}
Filip Tehlar26ea14e2019-03-11 05:30:21 -07001788#endif /* CLIB_MARCH_VARIANT */
Klement Sekera4c533132018-02-22 11:41:12 +01001789
Klement Sekera896c8962019-06-24 11:52:49 +00001790#define foreach_ip6_full_reassembly_handoff_error \
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001791_(CONGESTION_DROP, "congestion drop")
1792
1793
1794typedef enum
1795{
Klement Sekera896c8962019-06-24 11:52:49 +00001796#define _(sym,str) IP6_FULL_REASSEMBLY_HANDOFF_ERROR_##sym,
1797 foreach_ip6_full_reassembly_handoff_error
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001798#undef _
Klement Sekera896c8962019-06-24 11:52:49 +00001799 IP6_FULL_REASSEMBLY_HANDOFF_N_ERROR,
1800} ip6_full_reassembly_handoff_error_t;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001801
Klement Sekera896c8962019-06-24 11:52:49 +00001802static char *ip6_full_reassembly_handoff_error_strings[] = {
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001803#define _(sym,string) string,
Klement Sekera896c8962019-06-24 11:52:49 +00001804 foreach_ip6_full_reassembly_handoff_error
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001805#undef _
1806};
1807
1808typedef struct
1809{
1810 u32 next_worker_index;
Klement Sekera896c8962019-06-24 11:52:49 +00001811} ip6_full_reassembly_handoff_trace_t;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001812
1813static u8 *
Klement Sekera896c8962019-06-24 11:52:49 +00001814format_ip6_full_reassembly_handoff_trace (u8 * s, va_list * args)
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001815{
1816 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1817 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Klement Sekera896c8962019-06-24 11:52:49 +00001818 ip6_full_reassembly_handoff_trace_t *t =
1819 va_arg (*args, ip6_full_reassembly_handoff_trace_t *);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001820
1821 s =
Klement Sekera896c8962019-06-24 11:52:49 +00001822 format (s, "ip6-full-reassembly-handoff: next-worker %d",
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001823 t->next_worker_index);
1824
1825 return s;
1826}
1827
1828always_inline uword
Klement Sekera01c1fa42021-12-14 18:25:11 +00001829ip6_full_reassembly_handoff_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
1830 vlib_frame_t *frame, bool is_feature,
1831 bool is_local)
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001832{
Klement Sekera896c8962019-06-24 11:52:49 +00001833 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001834
1835 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1836 u32 n_enq, n_left_from, *from;
1837 u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1838 u32 fq_index;
1839
1840 from = vlib_frame_vector_args (frame);
1841 n_left_from = frame->n_vectors;
1842 vlib_get_buffers (vm, from, bufs, n_left_from);
1843
1844 b = bufs;
1845 ti = thread_indices;
1846
Klement Sekera01c1fa42021-12-14 18:25:11 +00001847 if (is_feature)
1848 {
1849 fq_index = rm->fq_feature_index;
1850 }
1851 else
1852 {
1853 if (is_local)
1854 {
1855 fq_index = rm->fq_local_index;
1856 }
1857 else
1858 {
1859 fq_index = rm->fq_index;
1860 }
1861 }
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001862
1863 while (n_left_from > 0)
1864 {
Klement Sekerade34c352019-06-25 11:19:22 +00001865 ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001866
1867 if (PREDICT_FALSE
1868 ((node->flags & VLIB_NODE_FLAG_TRACE)
1869 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1870 {
Klement Sekera896c8962019-06-24 11:52:49 +00001871 ip6_full_reassembly_handoff_trace_t *t =
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001872 vlib_add_trace (vm, node, b[0], sizeof (*t));
1873 t->next_worker_index = ti[0];
1874 }
1875
1876 n_left_from -= 1;
1877 ti += 1;
1878 b += 1;
1879 }
Damjan Marion9e7a0b42021-05-14 14:50:01 +02001880 n_enq = vlib_buffer_enqueue_to_thread (vm, node, fq_index, from,
1881 thread_indices, frame->n_vectors, 1);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001882
1883 if (n_enq < frame->n_vectors)
1884 vlib_node_increment_counter (vm, node->node_index,
Klement Sekera896c8962019-06-24 11:52:49 +00001885 IP6_FULL_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001886 frame->n_vectors - n_enq);
1887 return frame->n_vectors;
1888}
1889
Klement Sekera896c8962019-06-24 11:52:49 +00001890VLIB_NODE_FN (ip6_full_reassembly_handoff_node) (vlib_main_t * vm,
1891 vlib_node_runtime_t * node,
1892 vlib_frame_t * frame)
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001893{
Klement Sekera01c1fa42021-12-14 18:25:11 +00001894 return ip6_full_reassembly_handoff_inline (
1895 vm, node, frame, false /* is_feature */, false /* is_local */);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001896}
1897
Klement Sekera896c8962019-06-24 11:52:49 +00001898VLIB_REGISTER_NODE (ip6_full_reassembly_handoff_node) = {
1899 .name = "ip6-full-reassembly-handoff",
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001900 .vector_size = sizeof (u32),
Klement Sekera896c8962019-06-24 11:52:49 +00001901 .n_errors = ARRAY_LEN(ip6_full_reassembly_handoff_error_strings),
1902 .error_strings = ip6_full_reassembly_handoff_error_strings,
1903 .format_trace = format_ip6_full_reassembly_handoff_trace,
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001904
1905 .n_next_nodes = 1,
1906
1907 .next_nodes = {
1908 [0] = "error-drop",
1909 },
1910};
1911
Klement Sekera01c1fa42021-12-14 18:25:11 +00001912VLIB_NODE_FN (ip6_local_full_reassembly_handoff_node)
1913(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
1914{
1915 return ip6_full_reassembly_handoff_inline (
1916 vm, node, frame, false /* is_feature */, true /* is_feature */);
1917}
1918
1919VLIB_REGISTER_NODE (ip6_local_full_reassembly_handoff_node) = {
1920 .name = "ip6-local-full-reassembly-handoff",
1921 .vector_size = sizeof (u32),
1922 .n_errors = ARRAY_LEN(ip6_full_reassembly_handoff_error_strings),
1923 .error_strings = ip6_full_reassembly_handoff_error_strings,
1924 .format_trace = format_ip6_full_reassembly_handoff_trace,
1925
1926 .n_next_nodes = 1,
1927
1928 .next_nodes = {
1929 [0] = "error-drop",
1930 },
1931};
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001932
Klement Sekera896c8962019-06-24 11:52:49 +00001933VLIB_NODE_FN (ip6_full_reassembly_feature_handoff_node) (vlib_main_t * vm,
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001934 vlib_node_runtime_t * node, vlib_frame_t * frame)
1935{
Klement Sekera01c1fa42021-12-14 18:25:11 +00001936 return ip6_full_reassembly_handoff_inline (
1937 vm, node, frame, true /* is_feature */, false /* is_local */);
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001938}
1939
Klement Sekera896c8962019-06-24 11:52:49 +00001940VLIB_REGISTER_NODE (ip6_full_reassembly_feature_handoff_node) = {
1941 .name = "ip6-full-reass-feature-hoff",
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001942 .vector_size = sizeof (u32),
Klement Sekera896c8962019-06-24 11:52:49 +00001943 .n_errors = ARRAY_LEN(ip6_full_reassembly_handoff_error_strings),
1944 .error_strings = ip6_full_reassembly_handoff_error_strings,
1945 .format_trace = format_ip6_full_reassembly_handoff_trace,
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001946
1947 .n_next_nodes = 1,
1948
1949 .next_nodes = {
1950 [0] = "error-drop",
1951 },
1952};
Vijayabhaskar Katamreddy470a3702019-03-01 19:57:06 -08001953
Klement Sekera7b2e9fb2019-10-01 13:00:22 +00001954#ifndef CLIB_MARCH_VARIANT
1955int
1956ip6_full_reass_enable_disable_with_refcnt (u32 sw_if_index, int is_enable)
1957{
1958 ip6_full_reass_main_t *rm = &ip6_full_reass_main;
1959 vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1960 if (is_enable)
1961 {
1962 if (!rm->feature_use_refcount_per_intf[sw_if_index])
1963 {
1964 ++rm->feature_use_refcount_per_intf[sw_if_index];
1965 return vnet_feature_enable_disable ("ip6-unicast",
1966 "ip6-full-reassembly-feature",
1967 sw_if_index, 1, 0, 0);
1968 }
1969 ++rm->feature_use_refcount_per_intf[sw_if_index];
1970 }
1971 else
1972 {
1973 --rm->feature_use_refcount_per_intf[sw_if_index];
1974 if (!rm->feature_use_refcount_per_intf[sw_if_index])
1975 return vnet_feature_enable_disable ("ip6-unicast",
1976 "ip6-full-reassembly-feature",
1977 sw_if_index, 0, 0, 0);
1978 }
1979 return -1;
1980}
Klement Sekera01c1fa42021-12-14 18:25:11 +00001981
1982void
1983ip6_local_full_reass_enable_disable (int enable)
1984{
1985 if (enable)
1986 {
1987 if (!ip6_full_reass_main.is_local_reass_enabled)
1988 {
1989 ip6_full_reass_main.is_local_reass_enabled = 1;
1990 ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
1991 ip6_local_full_reass_node.index);
1992 }
1993 }
1994 else
1995 {
1996 if (ip6_full_reass_main.is_local_reass_enabled)
1997 {
1998 ip6_full_reass_main.is_local_reass_enabled = 0;
1999 ip6_unregister_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION);
2000 }
2001 }
2002}
2003
2004int
2005ip6_local_full_reass_enabled ()
2006{
2007 return ip6_full_reass_main.is_local_reass_enabled;
2008}
2009
Klement Sekera7b2e9fb2019-10-01 13:00:22 +00002010#endif
2011
Klement Sekera75e7d132017-09-20 08:26:30 +02002012/*
2013 * fd.io coding-style-patch-verification: ON
2014 *
2015 * Local Variables:
2016 * eval: (c-set-style "gnu")
2017 * End:
2018 */