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(...) 105 return vnb->
ip.reass.range_first - vnb->
ip.reass.fragment_first;
112 return clib_min (vnb->
ip.reass.range_last, vnb->
ip.reass.fragment_last) -
176 #ifndef CLIB_MARCH_VARIANT 253 s =
format (s,
"first bi: %u, data len: %u, ip/fragment[%u, %u]",
285 ip4_reass_trace_operation_e action,
u32 size_diff)
292 b->
flags &= ~VLIB_BUFFER_IS_TRACED;
309 printf (
"%.*s\n",
vec_len (s), s);
323 clib_bihash_add_del_16_8 (&rm->
hash, &kv, 0);
336 while (~0 != range_bi)
345 if (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
348 b->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
355 range_bi = range_vnb->
ip.reass.next_range_bi;
369 if (!clib_bihash_search_16_8
412 kv->v.reass_index = (reass - rt->
pool);
434 u32 total_length = 0;
438 u32 tmp_bi = sub_chain_bi;
442 if (!(vnb->
ip.reass.range_first >= vnb->
ip.reass.fragment_first) &&
443 !(vnb->
ip.reass.range_last > vnb->
ip.reass.fragment_first))
480 if (!(tmp->
flags & VLIB_BUFFER_NEXT_PRESENT))
484 tmp->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
499 last_b->
flags |= VLIB_BUFFER_NEXT_PRESENT;
503 if (keep_data <= tmp->current_length)
511 if (!(tmp->
flags & VLIB_BUFFER_NEXT_PRESENT))
526 if (tmp->
flags & VLIB_BUFFER_NEXT_PRESENT)
540 while (~0 != sub_chain_bi);
546 last_b->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
547 if (total_length < first_b->current_length)
552 first_b->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
577 if (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
586 printf (
"%.*s\n",
vec_len (s), s);
603 *error0 = IP4_ERROR_NONE;
614 u32 prev_range_bi,
u32 new_next_bi)
618 if (~0 != prev_range_bi)
622 new_next_vnb->
ip.reass.next_range_bi = prev_vnb->
ip.reass.next_range_bi;
623 prev_vnb->
ip.reass.next_range_bi = new_next_bi;
629 new_next_vnb->
ip.reass.next_range_bi = reass->
first_bi;
634 if (!(vnb->
ip.reass.range_first >= vnb->
ip.reass.fragment_first) &&
635 !(vnb->
ip.reass.range_last > vnb->
ip.reass.fragment_first))
652 if (~0 != prev_range_bi)
656 if (!(prev_vnb->
ip.reass.next_range_bi == discard_bi))
660 prev_vnb->
ip.reass.next_range_bi = discard_vnb->
ip.reass.next_range_bi;
664 reass->
first_bi = discard_vnb->
ip.reass.next_range_bi;
667 if (!(vnb->
ip.reass.range_first >= vnb->
ip.reass.fragment_first) &&
668 !(vnb->
ip.reass.range_last > vnb->
ip.reass.fragment_first))
681 if (discard_b->
flags & VLIB_BUFFER_NEXT_PRESENT)
683 discard_b->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
708 const u32 fragment_length =
710 const u32 fragment_last = fragment_first + fragment_length - 1;
711 fvnb->
ip.reass.fragment_first = fragment_first;
712 fvnb->
ip.reass.fragment_last = fragment_last;
715 u32 prev_range_bi = ~0;
716 fvnb->
ip.reass.range_first = fragment_first;
717 fvnb->
ip.reass.range_last = fragment_last;
718 fvnb->
ip.reass.next_range_bi = ~0;
742 fvnb->
ip.reass.estimated_mtu);
743 while (~0 != candidate_range_bi)
747 if (fragment_first > candidate_vnb->
ip.reass.range_last)
750 prev_range_bi = candidate_range_bi;
751 candidate_range_bi = candidate_vnb->
ip.reass.next_range_bi;
752 if (candidate_vnb->
ip.reass.range_last < fragment_last &&
753 ~0 == candidate_range_bi)
758 prev_range_bi, *bi0);
768 if (fragment_last < candidate_vnb->ip.reass.range_first)
782 if (fragment_first >= candidate_vnb->
ip.reass.range_first &&
783 fragment_last <= candidate_vnb->ip.reass.range_last)
793 int discard_candidate = 0;
794 if (fragment_first < candidate_vnb->ip.reass.range_first)
797 fragment_last - candidate_vnb->
ip.reass.range_first + 1;
800 candidate_vnb->
ip.reass.range_first += overlap;
814 prev_range_bi, *bi0);
823 discard_candidate = 1;
826 else if (fragment_last > candidate_vnb->
ip.reass.range_last)
829 candidate_vnb->
ip.reass.range_last - fragment_first + 1;
832 fvnb->
ip.reass.range_first += overlap;
833 if (~0 != candidate_vnb->
ip.reass.next_range_bi)
835 prev_range_bi = candidate_range_bi;
837 candidate_vnb->
ip.reass.next_range_bi;
856 discard_candidate = 1;
861 discard_candidate = 1;
863 if (discard_candidate)
865 u32 next_range_bi = candidate_vnb->
ip.reass.next_range_bi;
875 if (~0 != next_range_bi)
877 candidate_range_bi = next_range_bi;
885 prev_range_bi, *bi0);
918 *error0 = IP4_ERROR_REASS_DUPLICATE_FRAGMENT;
930 u32 n_left_from, n_left_to_next, *to_next, next_index;
937 while (n_left_from > 0)
941 while (n_left_from > 0 && n_left_to_next > 0)
946 u32 error0 = IP4_ERROR_NONE;
967 const u32 fragment_length =
969 const u32 fragment_last = fragment_first + fragment_length - 1;
970 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 &&
ip4_get_fragment_more (ip0)))
973 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
996 reass.owner_feature_thread_index =
1005 (vm, node, rm, rt, reass, &bi0, &next0,
1006 &error0, is_feature))
1024 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
1035 n_left_to_next -= 1;
1036 if (is_feature && IP4_ERROR_NONE == error0)
1042 to_next, n_left_to_next,
1060 #define _(sym, string) string, 1073 .name =
"ip4-reassembly",
1074 .vector_size =
sizeof (
u32),
1076 .n_errors =
ARRAY_LEN (ip4_reassembly_error_strings),
1098 .name =
"ip4-reassembly-feature",
1099 .vector_size =
sizeof (
u32),
1101 .n_errors =
ARRAY_LEN (ip4_reassembly_error_strings),
1115 .arc_name =
"ip4-unicast",
1116 .node_name =
"ip4-reassembly-feature",
1122 #ifndef CLIB_MARCH_VARIANT 1132 for (i = 0; i < 31; i++)
1133 if ((1 << i) >= nbuckets)
1152 #ifndef CLIB_MARCH_VARIANT 1157 if (clib_bihash_add_del_16_8 (ctx->
new_hash, kv, 1))
1165 u32 expire_walk_interval_ms)
1175 u32 expire_walk_interval_ms)
1179 expire_walk_interval_ms);
1184 if (ip4_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
1186 clib_bihash_16_8_t new_hash;
1191 clib_bihash_init_16_8 (&new_hash,
"ip4-reass", new_nbuckets,
1192 new_nbuckets * 1024);
1193 clib_bihash_foreach_key_value_pair_16_8 (&ip4_reass_main.
hash,
1197 clib_bihash_free_16_8 (&new_hash);
1202 clib_bihash_free_16_8 (&ip4_reass_main.
hash);
1204 sizeof (ip4_reass_main.
hash));
1212 u32 * expire_walk_interval_ms)
1248 clib_bihash_init_16_8 (&rm->
hash,
"ip4-reass", nbuckets, nbuckets * 1024);
1270 uword event_type, *event_data = 0;
1294 int *pool_indexes_to_free =
NULL;
1296 uword thread_index = 0;
1299 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1307 reass = pool_elt_at_index (rt->pool, index);
1308 if (now > reass->last_heard + rm->timeout)
1310 vec_add1 (pool_indexes_to_free, index);
1330 _vec_len (event_data) = 0;
1341 .name =
"ip4-reassembly-expire-walk",
1353 s =
format (s,
"xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1365 s =
format (s,
"ID: %lu, key: %U\n first_bi: %u, data_len: %u, " 1366 "last_packet_octet: %u, trace_op_counter: %u\n",
1376 s =
format (s,
" #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, " 1377 "fragment[%u, %u]\n",
1378 counter, vnb->
ip.reass.range_first,
1379 vnb->
ip.reass.range_last, bi,
1382 vnb->
ip.reass.fragment_first, vnb->
ip.reass.fragment_last);
1383 if (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
1405 bool details =
false;
1411 u32 sum_reass_n = 0;
1415 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1423 vlib_cli_output (vm,
"%U", format_ip4_reass, vm, reass);
1432 (
long unsigned) sum_reass_n);
1434 "Maximum configured concurrent IP4 reassemblies per worker-thread: %lu\n",
1441 .path =
"show ip4-reassembly",
1442 .short_help =
"show ip4-reassembly [details]",
1447 #ifndef CLIB_MARCH_VARIANT 1452 "ip4-reassembly-feature", sw_if_index,
1453 enable_disable, 0, 0);
1458 #define foreach_ip4_reassembly_handoff_error \ 1459 _(CONGESTION_DROP, "congestion drop") 1464 #define _(sym,str) IP4_REASSEMBLY_HANDOFF_ERROR_##sym, 1471 #define _(sym,string) string, 1490 format (s,
"ip4-reassembly-handoff: next-worker %d",
1504 u32 n_enq, n_left_from, *from;
1513 ti = thread_indices;
1517 while (n_left_from > 0)
1521 reass.owner_feature_thread_index :
vnet_buffer (b[0])->ip.
1522 reass.owner_thread_index;
1526 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1541 if (n_enq < frame->n_vectors)
1543 IP4_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1559 .name =
"ip4-reassembly-handoff",
1560 .vector_size =
sizeof (
u32),
1561 .n_errors =
ARRAY_LEN(ip4_reassembly_handoff_error_strings),
1588 .name =
"ip4-reass-feature-hoff",
1589 .vector_size =
sizeof (
u32),
1590 .n_errors =
ARRAY_LEN(ip4_reassembly_handoff_error_strings),
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
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_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
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 void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static 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_kv_t *kv, u8 *do_handoff)
vnet_main_t * vnet_get_main(void)
u32 ip4_reass_expire_node_idx
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
static u8 * format_ip4_reass_trace(u8 *s, va_list *args)
#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)
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
u16 current_length
Nbytes between current data and the end of this buffer.
#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)
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
#define foreach_ip4_reassembly_handoff_error
#define VLIB_NODE_FN(node)
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_node_registration_t ip4_reassembly_handoff_node
(constructor) VLIB_REGISTER_NODE (ip4_reassembly_handoff_node)
vlib_trace_header_t ** trace_buffer_pool
ip4_reassembly_handoff_error_t
#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)
static void clib_spinlock_init(clib_spinlock_t *p)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
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
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
#define IP4_REASS_DEBUG_BUFFER(...)
vlib_node_registration_t ip4_reassembly_feature_handoff_node
(constructor) VLIB_REGISTER_NODE (ip4_reassembly_feature_handoff_node)
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
u32 node_index
Node index.
#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)
vlib_node_registration_t ip4_reass_node
(constructor) VLIB_REGISTER_NODE (ip4_reass_node)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
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,...)
static u8 * format_ip4_reassembly_handoff_trace(u8 *s, va_list *args)
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
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
#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)
static uword ip4_reassembly_handoff_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, 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)
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)
#define vec_elt(v, i)
Get vector value at index i.
struct _vlib_node_registration vlib_node_registration_t
static char * ip4_reassembly_handoff_error_strings[]
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 next_buffer
Next buffer for this linked-list of buffers.
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
ip4_reass_trace_operation_e action
static vlib_node_registration_t ip4_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip4_reass_expire_node)
static_always_inline u32 vlib_buffer_enqueue_to_thread(vlib_main_t *vm, u32 frame_queue_index, u32 *buffer_indices, u16 *thread_indices, u32 n_packets, int drop_on_congestion)
static u8 * format_ip4_reass(u8 *s, va_list *args)
ip4_main_t ip4_main
Global ip4 main structure.
static u32 vlib_num_workers()
#define vec_foreach(var, vec)
Vector iterator.
u16 flags
Copy of main node flags.
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)
struct vnet_buffer_opaque_t::@58::@60 ip
#define pool_foreach_index(i, v, body)
Iterate pool by index.
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#define VLIB_NODE_FLAG_TRACE
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
u32 fq_index
Worker handoff.
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.
static u16 ip4_header_checksum(ip4_header_t *i)
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".