29 #define MSEC_PER_SEC 1000 30 #define IP4_REASS_TIMEOUT_DEFAULT_MS 100 31 #define IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default 32 #define IP4_REASS_MAX_REASSEMBLIES_DEFAULT 1024 33 #define IP4_REASS_HT_LOAD_FACTOR (0.75) 35 #define IP4_REASS_DEBUG_BUFFERS 0 36 #if IP4_REASS_DEBUG_BUFFERS 37 #define IP4_REASS_DEBUG_BUFFER(bi, what) \ 41 printf (#what "buffer %u", _bi); \ 42 vlib_buffer_t *_b = vlib_get_buffer (vm, _bi); \ 43 while (_b->flags & VLIB_BUFFER_NEXT_PRESENT) \ 45 _bi = _b->next_buffer; \ 46 printf ("[%u]", _bi); \ 47 _b = vlib_get_buffer (vm, _bi); \ 54 #define IP4_REASS_DEBUG_BUFFER(...) 85 return vnb->
ip.reass.range_first - vnb->
ip.reass.fragment_first;
92 return clib_min (vnb->
ip.reass.range_last, vnb->
ip.reass.fragment_last) -
219 s =
format (s,
"first bi: %u, data len: %u, ip/fragment[%u, %u]",
251 ip4_reass_trace_operation_e action,
u32 size_diff)
258 b->
flags &= ~VLIB_BUFFER_IS_TRACED;
275 printf (
"%.*s\n",
vec_len (s), s);
288 clib_bihash_add_del_16_8 (&rm->
hash, &kv, 0);
301 while (~0 != range_bi)
310 if (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
313 b->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
320 range_bi = range_vnb->
ip.reass.next_range_bi;
336 if (!clib_bihash_search_16_8 (&rm->
hash, &kv, &value))
376 if (clib_bihash_add_del_16_8 (&rm->
hash, &kv, 1))
394 u32 total_length = 0;
398 u32 tmp_bi = sub_chain_bi;
402 if (!(vnb->
ip.reass.range_first >= vnb->
ip.reass.fragment_first) &&
403 !(vnb->
ip.reass.range_last > vnb->
ip.reass.fragment_first))
440 if (!(tmp->
flags & VLIB_BUFFER_NEXT_PRESENT))
444 tmp->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
459 last_b->
flags |= VLIB_BUFFER_NEXT_PRESENT;
463 if (keep_data <= tmp->current_length)
471 if (!(tmp->
flags & VLIB_BUFFER_NEXT_PRESENT))
486 if (tmp->
flags & VLIB_BUFFER_NEXT_PRESENT)
500 while (~0 != sub_chain_bi);
506 last_b->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
507 if (total_length < first_b->current_length)
512 first_b->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
537 if (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
546 printf (
"%.*s\n",
vec_len (s), s);
563 *error0 = IP4_ERROR_NONE;
574 u32 prev_range_bi,
u32 new_next_bi)
578 if (~0 != prev_range_bi)
582 new_next_vnb->
ip.reass.next_range_bi = prev_vnb->
ip.reass.next_range_bi;
583 prev_vnb->
ip.reass.next_range_bi = new_next_bi;
589 new_next_vnb->
ip.reass.next_range_bi = reass->
first_bi;
594 if (!(vnb->
ip.reass.range_first >= vnb->
ip.reass.fragment_first) &&
595 !(vnb->
ip.reass.range_last > vnb->
ip.reass.fragment_first))
612 if (~0 != prev_range_bi)
616 if (!(prev_vnb->
ip.reass.next_range_bi == discard_bi))
620 prev_vnb->
ip.reass.next_range_bi = discard_vnb->
ip.reass.next_range_bi;
624 reass->
first_bi = discard_vnb->
ip.reass.next_range_bi;
627 if (!(vnb->
ip.reass.range_first >= vnb->
ip.reass.fragment_first) &&
628 !(vnb->
ip.reass.range_last > vnb->
ip.reass.fragment_first))
641 if (discard_b->
flags & VLIB_BUFFER_NEXT_PRESENT)
643 discard_b->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
668 const u32 fragment_length =
670 const u32 fragment_last = fragment_first + fragment_length - 1;
671 fvnb->
ip.reass.fragment_first = fragment_first;
672 fvnb->
ip.reass.fragment_last = fragment_last;
675 u32 prev_range_bi = ~0;
676 fvnb->
ip.reass.range_first = fragment_first;
677 fvnb->
ip.reass.range_last = fragment_last;
678 fvnb->
ip.reass.next_range_bi = ~0;
702 fvnb->
ip.reass.estimated_mtu);
703 while (~0 != candidate_range_bi)
707 if (fragment_first > candidate_vnb->
ip.reass.range_last)
710 prev_range_bi = candidate_range_bi;
711 candidate_range_bi = candidate_vnb->
ip.reass.next_range_bi;
712 if (candidate_vnb->
ip.reass.range_last < fragment_last &&
713 ~0 == candidate_range_bi)
718 prev_range_bi, *bi0);
728 if (fragment_last < candidate_vnb->ip.reass.range_first)
742 if (fragment_first >= candidate_vnb->
ip.reass.range_first &&
743 fragment_last <= candidate_vnb->ip.reass.range_last)
753 int discard_candidate = 0;
754 if (fragment_first < candidate_vnb->ip.reass.range_first)
757 fragment_last - candidate_vnb->
ip.reass.range_first + 1;
760 candidate_vnb->
ip.reass.range_first += overlap;
774 prev_range_bi, *bi0);
783 discard_candidate = 1;
786 else if (fragment_last > candidate_vnb->
ip.reass.range_last)
789 candidate_vnb->
ip.reass.range_last - fragment_first + 1;
792 fvnb->
ip.reass.range_first += overlap;
793 if (~0 != candidate_vnb->
ip.reass.next_range_bi)
795 prev_range_bi = candidate_range_bi;
797 candidate_vnb->
ip.reass.next_range_bi;
816 discard_candidate = 1;
821 discard_candidate = 1;
823 if (discard_candidate)
825 u32 next_range_bi = candidate_vnb->
ip.reass.next_range_bi;
835 if (~0 != next_range_bi)
837 candidate_range_bi = next_range_bi;
845 prev_range_bi, *bi0);
878 *error0 = IP4_ERROR_REASS_DUPLICATE_FRAGMENT;
890 u32 n_left_from, n_left_to_next, *to_next, next_index;
897 while (n_left_from > 0)
901 while (n_left_from > 0 && n_left_to_next > 0)
906 u32 error0 = IP4_ERROR_NONE;
927 const u32 fragment_length =
929 const u32 fragment_last = fragment_first + fragment_length - 1;
930 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 &&
ip4_get_fragment_more (ip0)))
933 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
951 (vm, node, rm, rt, reass, &bi0, &next0, &error0,
970 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
982 if (is_feature && IP4_ERROR_NONE == error0)
988 n_left_to_next, bi0, next0);
1005 #define _(sym, string) string, 1020 .name =
"ip4-reassembly",
1021 .vector_size =
sizeof (
u32),
1023 .n_errors =
ARRAY_LEN (ip4_reassembly_error_strings),
1046 .name =
"ip4-reassembly-feature",
1047 .vector_size =
sizeof (
u32),
1049 .n_errors =
ARRAY_LEN (ip4_reassembly_error_strings),
1064 .arc_name =
"ip4-unicast",
1065 .node_name =
"ip4-reassembly-feature",
1080 for (i = 0; i < 31; i++)
1081 if ((1 << i) >= nbuckets)
1103 if (clib_bihash_add_del_16_8 (ctx->
new_hash, kv, 1))
1111 u32 expire_walk_interval_ms)
1121 u32 expire_walk_interval_ms)
1125 expire_walk_interval_ms);
1130 if (ip4_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
1132 clib_bihash_16_8_t new_hash;
1137 clib_bihash_init_16_8 (&new_hash,
"ip4-reass", new_nbuckets,
1138 new_nbuckets * 1024);
1139 clib_bihash_foreach_key_value_pair_16_8 (&ip4_reass_main.
hash,
1143 clib_bihash_free_16_8 (&new_hash);
1148 clib_bihash_free_16_8 (&ip4_reass_main.
hash);
1150 sizeof (ip4_reass_main.
hash));
1158 u32 * expire_walk_interval_ms)
1194 clib_bihash_init_16_8 (&rm->
hash,
"ip4-reass", nbuckets, nbuckets * 1024);
1210 uword event_type, *event_data = 0;
1233 int *pool_indexes_to_free =
NULL;
1235 uword thread_index = 0;
1238 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1246 reass = pool_elt_at_index (rt->pool, index);
1247 if (now > reass->last_heard + rm->timeout)
1249 vec_add1 (pool_indexes_to_free, index);
1269 _vec_len (event_data) = 0;
1280 .name =
"ip4-reassembly-expire-walk",
1292 s =
format (s,
"xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1304 s =
format (s,
"ID: %lu, key: %U\n first_bi: %u, data_len: %u, " 1305 "last_packet_octet: %u, trace_op_counter: %u\n",
1315 s =
format (s,
" #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, " 1316 "fragment[%u, %u]\n",
1317 counter, vnb->
ip.reass.range_first,
1318 vnb->
ip.reass.range_last, bi,
1321 vnb->
ip.reass.fragment_first, vnb->
ip.reass.fragment_last);
1322 if (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
1343 bool details =
false;
1349 u32 sum_reass_n = 0;
1353 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1361 vlib_cli_output (vm,
"%U", format_ip4_reass, vm, reass);
1370 (
long unsigned) sum_reass_n);
1372 "Maximum configured concurrent IP4 reassemblies per worker-thread: %lu\n",
1379 .path =
"show ip4-reassembly",
1380 .short_help =
"show ip4-reassembly [details]",
1389 sw_if_index, enable_disable, 0, 0);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static uword ip4_reassembly_feature(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
VLIB_NODE_FUNCTION_MULTIARCH(ip4_reass_node, ip4_reassembly)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
static uword ip4_reassembly(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
vnet_main_t * vnet_get_main(void)
u32 ip4_reass_expire_node_idx
u8 * format_ip4_reass_trace(u8 *s, va_list *args)
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
#define clib_memcpy_fast(a, b, c)
#define IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static char * ip4_reassembly_error_strings[]
static f64 vlib_time_now(vlib_main_t *vm)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static ip4_reass_rc_t ip4_reass_insert_range_in_chain(vlib_main_t *vm, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass, u32 prev_range_bi, u32 new_next_bi)
vlib_error_t * errors
Vector of errors for this node.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
ip4_reass_per_thread_t * per_thread_data
static ip4_reass_rc_t ip4_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, bool is_feature)
static void ip4_reass_trace_details(vlib_main_t *vm, u32 bi, ip4_reass_range_trace_t *trace)
static int ip4_get_fragment_offset_bytes(const ip4_header_t *i)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vlib_trace_header_t ** trace_buffer_pool
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
static void ip4_rehash_cb(clib_bihash_kv_16_8_t *kv, void *_ctx)
static void ip4_reass_free(ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass)
static u16 ip4_reass_buffer_get_data_len(vlib_buffer_t *b)
u32 expire_walk_interval_ms
static void ip4_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 expire_walk_interval_ms)
static uword ip4_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
ip4_reass_t * ip4_reass_find_or_create(vlib_main_t *vm, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_key_t *k)
static void clib_spinlock_init(clib_spinlock_t *p)
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
static uword ip4_reassembly_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
static u8 * format_ip4_reass_key(u8 *s, va_list *args)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vnet_api_error_t ip4_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 expire_walk_interval_ms)
set ip4 reassembly configuration
u16 current_length
Nbytes between current data and the end of this buffer.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
#define IP4_REASS_DEBUG_BUFFER(...)
static int ip4_get_fragment_offset(const ip4_header_t *i)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
vnet_api_error_t ip4_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *expire_walk_interval_ms)
get ip4 reassembly configuration
#define pool_put(P, E)
Free an object E in pool P.
static vlib_cli_command_t show_ip4_reassembly_cmd
(constructor) VLIB_CLI_COMMAND (show_ip4_reassembly_cmd)
ip4_reass_main_t ip4_reass_main
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static u8 * format_ip4_reass_range_trace(u8 *s, va_list *args)
static vlib_node_registration_t ip4_reass_node
(constructor) VLIB_REGISTER_NODE (ip4_reass_node)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
ip4_reass_trace_operation_e
#define foreach_ip4_error
static clib_error_t * ip4_reass_init_function(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
clib_bihash_16_8_t * new_hash
#define vec_free(V)
Free vector's memory (no header).
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
ip4_reass_range_trace_t trace_range
#define clib_warning(format, args...)
VNET_FEATURE_INIT(ip4_reassembly_feature, static)
static void ip4_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_t *reass, u32 bi, ip4_reass_trace_operation_e action, u32 size_diff)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static clib_error_t * show_ip4_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static ip4_reass_rc_t ip4_reass_finalize(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, bool is_feature)
#define IP4_REASS_MAX_REASSEMBLIES_DEFAULT
static int ip4_get_fragment_more(const ip4_header_t *i)
static ip4_reass_rc_t ip4_reass_remove_range_from_chain(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_t *reass, u32 prev_range_bi, u32 discard_bi)
#define IP4_REASS_HT_LOAD_FACTOR
vnet_api_error_t ip4_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
#define VLIB_CLI_COMMAND(x,...)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
static u32 ip4_reass_get_nbuckets()
static u32 ip4_reass_buffer_get_data_offset(vlib_buffer_t *b)
u32 next_buffer
Next buffer for this linked-list of buffers.
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
vlib_trace_main_t trace_main
#define IP4_REASS_TIMEOUT_DEFAULT_MS
#define VNET_FEATURES(...)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
ip4_reass_trace_operation_e action
static_always_inline uword os_get_thread_index(void)
static vlib_node_registration_t ip4_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip4_reass_expire_node)
static u8 * format_ip4_reass(u8 *s, va_list *args)
static u32 vlib_num_workers()
#define vec_foreach(var, vec)
Vector iterator.
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
static int ip4_header_bytes(const ip4_header_t *i)
static void ip4_reass_on_timeout(vlib_main_t *vm, ip4_reass_main_t *rm, ip4_reass_t *reass)
#define pool_foreach_index(i, v, body)
Iterate pool by index.
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_node_registration_t ip4_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip4_reass_node_feature)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
static u16 ip4_header_checksum(ip4_header_t *i)
struct vnet_buffer_opaque_t::@56::@58 ip
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".