31 #define MSEC_PER_SEC 1000 32 #define IP4_SV_REASS_TIMEOUT_DEFAULT_MS 100 33 #define IP4_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default 34 #define IP4_SV_REASS_MAX_REASSEMBLIES_DEFAULT 1024 35 #define IP4_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3 36 #define IP4_SV_REASS_HT_LOAD_FACTOR (0.75) 164 #ifndef CLIB_MARCH_VARIANT 210 s =
format (s,
"[cached]");
214 format (s,
"[finish, ip proto=%u, src_port=%u, dst_port=%u]",
220 format (s,
"[forward, ip proto=%u, src_port=%u, dst_port=%u]",
225 s =
format (s,
"[not-fragmented]");
234 u32 bi, ip4_sv_reass_trace_operation_e
action,
242 b->
flags &= ~VLIB_BUFFER_IS_TRACED;
259 printf (
"%.*s\n",
vec_len (s), s);
273 clib_bihash_add_del_16_8 (&rm->
hash, &kv, 0);
317 if (!clib_bihash_search_16_8 (&rm->
hash, &kv->
kv, &kv->
kv))
371 if (clib_bihash_add_del_16_8 (&rm->
hash, &kv->
kv, 1))
388 if (0 == fragment_first)
395 if (IP_PROTOCOL_TCP == reass->
ip_proto)
401 else if (IP_PROTOCOL_ICMP == reass->
ip_proto)
404 ((icmp46_header_t *) (ip0 + 1))->
type;
434 bool is_output_feature,
bool is_custom)
437 u32 n_left_from, n_left_to_next, *to_next, next_index;
451 while (n_left_from >= 2)
477 (is_output_feature ? 1 : 0) *
479 ip.save_rewrite_length);
482 (is_output_feature ? 1 : 0) *
484 ip.save_rewrite_length);
504 next0 = is_custom ?
vnet_buffer (b0)->ip.reass.next_index :
507 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
509 if (IP_PROTOCOL_TCP == ip0->
protocol)
511 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
518 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
520 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
521 ((icmp46_header_t *) (ip0 + 1))->
type;
539 next1 = is_custom ?
vnet_buffer (b1)->ip.reass.next_index :
542 vnet_buffer (b1)->ip.reass.is_non_first_fragment = 0;
544 if (IP_PROTOCOL_TCP == ip1->
protocol)
546 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
553 else if (IP_PROTOCOL_ICMP == ip1->
protocol)
555 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
556 ((icmp46_header_t *) (ip1 + 1))->
type;
575 while (n_left_from > 0)
584 (is_output_feature ? 1 : 0) *
586 ip.save_rewrite_length);
609 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
611 if (IP_PROTOCOL_TCP == ip0->
protocol)
613 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
620 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
622 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
623 ((icmp46_header_t *) (ip0 + 1))->
type;
650 while (n_left_from > 0)
654 while (n_left_from > 0 && n_left_to_next > 0)
659 u32 error0 = IP4_ERROR_NONE;
666 (is_output_feature ? 1 : 0) *
668 ip.save_rewrite_length);
680 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
682 if (IP_PROTOCOL_TCP == ip0->
protocol)
684 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
691 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
693 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
694 ((icmp46_header_t *) (ip0 + 1))->
type;
711 const u32 fragment_length =
713 const u32 fragment_last = fragment_first + fragment_length - 1;
714 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 &&
ip4_get_fragment_more (ip0)))
717 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
746 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
751 if (reass->is_complete)
763 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
764 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
765 reass->icmp_type_or_tcp_flags;
767 reass->tcp_ack_number;
769 reass->tcp_seq_number;
770 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
771 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
783 ip4_sv_reass_rc_t rc =
792 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
799 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
805 if (reass->is_complete)
810 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
814 (is_output_feature ? 1 : 0) *
816 ip.save_rewrite_length);
826 if (0 == n_left_to_next)
838 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
839 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
840 reass->icmp_type_or_tcp_flags;
842 reass->tcp_ack_number;
844 reass->tcp_seq_number;
845 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
846 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
856 to_next, n_left_to_next, bi0,
859 _vec_len (reass->cached_buffers) = 0;
867 if (is_feature && IP4_ERROR_NONE == error0)
873 to_next, n_left_to_next,
890 #define _(sym, string) string, 906 .name =
"ip4-sv-reassembly",
907 .vector_size =
sizeof (
u32),
909 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
933 .name =
"ip4-sv-reassembly-feature",
934 .vector_size =
sizeof (
u32),
936 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
950 .arc_name =
"ip4-unicast",
951 .node_name =
"ip4-sv-reassembly-feature",
969 .name =
"ip4-sv-reassembly-output-feature",
970 .vector_size =
sizeof (
u32),
972 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
986 .arc_name =
"ip4-output",
987 .node_name =
"ip4-sv-reassembly-output-feature",
995 .name =
"ip4-sv-reassembly-custom-next",
996 .vector_size =
sizeof (
u32),
998 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
1020 #ifndef CLIB_MARCH_VARIANT 1030 for (i = 0; i < 31; i++)
1031 if ((1 << i) >= nbuckets)
1047 clib_bihash_16_8_t *new_hash;
1050 #ifndef CLIB_MARCH_VARIANT 1055 if (clib_bihash_add_del_16_8 (ctx->
new_hash, kv, 1))
1059 return (BIHASH_WALK_CONTINUE);
1064 u32 max_reassembly_length,
1065 u32 expire_walk_interval_ms)
1076 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
1080 max_reassembly_length, expire_walk_interval_ms);
1085 if (ip4_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
1087 clib_bihash_16_8_t new_hash;
1092 clib_bihash_init_16_8 (&new_hash,
"ip4-dr", new_nbuckets,
1093 new_nbuckets * 1024);
1094 clib_bihash_foreach_key_value_pair_16_8 (&ip4_sv_reass_main.
hash,
1098 clib_bihash_free_16_8 (&new_hash);
1103 clib_bihash_free_16_8 (&ip4_sv_reass_main.
hash);
1105 sizeof (ip4_sv_reass_main.
hash));
1114 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
1117 *max_reassemblies = ip4_sv_reass_main.
max_reass_n;
1153 clib_bihash_init_16_8 (&rm->
hash,
"ip4-dr", nbuckets, nbuckets * 1024);
1177 uword event_type, *event_data = 0;
1201 int *pool_indexes_to_free = NULL;
1203 uword thread_index = 0;
1206 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1217 vec_add1 (pool_indexes_to_free, index);
1236 _vec_len (event_data) = 0;
1247 .name =
"ip4-sv-reassembly-expire-walk",
1249 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
1261 "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1273 s =
format (s,
"ID: %lu, key: %U trace_op_counter: %u\n",
1286 s =
format (s,
" #%03u: bi: %u, ", counter, bi);
1290 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1305 bool details =
false;
1311 u32 sum_reass_n = 0;
1315 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1332 (
long unsigned) sum_reass_n);
1334 "Maximum configured concurrent shallow virtual IP4 reassemblies per worker-thread: %lu\n",
1337 "Maximum configured shallow virtual IP4 reassembly timeout: %lums\n",
1340 "Maximum configured shallow virtual IP4 reassembly expire walk interval: %lums\n",
1347 .path =
"show ip4-sv-reassembly",
1348 .short_help =
"show ip4-sv-reassembly [details]",
1353 #ifndef CLIB_MARCH_VARIANT 1363 #define foreach_ip4_sv_reass_handoff_error \ 1364 _(CONGESTION_DROP, "congestion drop") 1369 #define _(sym,str) IP4_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1375 static char *ip4_sv_reass_handoff_error_strings[] = {
1376 #define _(sym,string) string, 1395 format (s,
"ip4-sv-reassembly-handoff: next-worker %d",
1409 u32 n_enq, n_left_from, *from;
1418 ti = thread_indices;
1422 while (n_left_from > 0)
1424 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1428 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1443 if (n_enq < frame->n_vectors)
1445 IP4_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1461 .name =
"ip4-sv-reassembly-handoff",
1462 .vector_size =
sizeof (
u32),
1463 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1490 .name =
"ip4-sv-reass-feature-hoff",
1491 .vector_size =
sizeof (
u32),
1492 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1504 #ifndef CLIB_MARCH_VARIANT 1516 "ip4-sv-reassembly-feature",
1517 sw_if_index, 1, 0, 0);
1527 "ip4-sv-reassembly-feature",
1528 sw_if_index, 0, 0, 0);
1552 "ip4-sv-reassembly-output-feature",
1553 sw_if_index, 1, 0, 0);
1563 "ip4-sv-reassembly-output-feature",
1564 sw_if_index, 0, 0, 0);
#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.
#define IP4_SV_REASS_TIMEOUT_DEFAULT_MS
#define vec_foreach_index(var, v)
Iterate over vector indices.
static void ip4_sv_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
#define IP4_SV_REASS_HT_LOAD_FACTOR
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
#define pool_foreach_index(i, v)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
static char * ip4_sv_reass_handoff_error_strings[]
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_sv_reass_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature, bool is_output_feature, bool is_custom)
vl_api_wireguard_peer_flags_t flags
int ip4_sv_reass_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
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 u32 vlib_buffer_get_trace_index(vlib_buffer_t *b)
Extract the trace (pool) index from a trace handle.
static ip4_sv_reass_rc_t ip4_sv_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_sv_reass_main_t *rm, ip4_sv_reass_per_thread_t *rt, ip4_header_t *ip0, ip4_sv_reass_t *reass, u32 bi0)
#define IP4_SV_REASS_MAX_REASSEMBLIES_DEFAULT
vlib_node_registration_t ip4_sv_reass_custom_node
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_custom_node)
vnet_main_t * vnet_get_main(void)
static u8 * format_ip4_sv_reass_key(u8 *s, va_list *args)
#define pool_foreach(VAR, POOL)
Iterate through pool.
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
u32 * feature_use_refcount_per_intf
vnet_api_error_t ip4_sv_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *max_reassembly_length, u32 *expire_walk_interval_ms)
get ip4 reassembly configuration
#define clib_memcpy_fast(a, b, c)
vlib_node_registration_t ip4_sv_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_node_feature)
static void ip4_sv_reass_init(ip4_sv_reass_t *reass)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
static u32 ip4_sv_reass_get_nbuckets()
u32 * output_feature_use_refcount_per_intf
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
int ip4_sv_reass_output_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
static u8 * format_ip4_sv_reass_trace(u8 *s, va_list *args)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define IP4_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
vnet_api_error_t ip4_sv_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
#define VLIB_NODE_FN(node)
vlib_error_t * errors
Vector of errors for this node.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct _tcp_header tcp_header_t
static void ip4_sv_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_sv_reass_main_t *rm, ip4_sv_reass_t *reass, u32 bi, ip4_sv_reass_trace_operation_e action, u32 ip_proto, u16 l4_src_port, u16 l4_dst_port)
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
static int ip4_get_fragment_offset_bytes(const ip4_header_t *i)
IPv4 to IPv6 translation.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u8 icmp_type_or_tcp_flags
ip4_sv_reass_main_t ip4_sv_reass_main
#define u8_ptr_add(ptr, index)
#define foreach_ip4_sv_reass_handoff_error
vlib_trace_header_t ** trace_buffer_pool
static ip4_sv_reass_t * ip4_sv_reass_find_or_create(vlib_main_t *vm, ip4_sv_reass_main_t *rm, ip4_sv_reass_per_thread_t *rt, ip4_sv_reass_kv_t *kv, u8 *do_handoff)
static u32 slow_path(dslite_main_t *dm, dslite_session_key_t *in2out_key, dslite_session_t **sp, u32 next, u8 *error, u32 thread_index)
#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 u16 ip4_get_fragment_more(const ip4_header_t *i)
description fragment has unexpected format
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
u32 expire_walk_interval_ms
clib_bihash_16_8_t * new_hash
ip4_sv_reass_trace_operation_e action
ip4_sv_reass_handoff_error_t
static char * ip4_sv_reass_error_strings[]
static u16 ip4_get_port(ip4_header_t *ip, u8 sender)
Get TCP/UDP port number or ICMP id from IPv4 packet.
static void clib_spinlock_init(clib_spinlock_t *p)
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
vlib_node_registration_t ip4_sv_reass_node
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_node)
vlib_node_registration_t ip4_sv_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_expire_node)
vnet_api_error_t ip4_sv_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
set ip4 reassembly configuration
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
#define IP4_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT
IPv4 shallow virtual reassembly.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define pool_put(P, E)
Free an object E in pool P.
ip4_sv_reass_trace_operation_e
u32 fq_index
Worker handoff.
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 void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define foreach_ip4_error
static uword ip4_sv_reass_handoff_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
sll srl srl sll sra u16x4 i
static u16 ip4_get_fragment_offset(const ip4_header_t *i)
#define vec_free(V)
Free vector's memory (no header).
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
#define clib_warning(format, args...)
__clib_export void clib_bihash_copied(void *dst, void *src)
static clib_error_t * show_ip4_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
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_main_t vlib_node_runtime_t * node
#define VLIB_CLI_COMMAND(x,...)
VNET_FEATURE_INIT(ip4_sv_reass_feature)
static uword ip4_sv_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
vlib_trace_main_t trace_main
#define VNET_FEATURES(...)
static vlib_main_t * vlib_get_main(void)
u32 ip4_sv_reass_expire_node_idx
#define vec_elt(v, i)
Get vector value at index i.
struct _vlib_node_registration vlib_node_registration_t
vl_api_mac_event_action_t action
#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_main_t vlib_node_runtime_t vlib_frame_t * frame
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
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)
ip4_sv_reass_per_thread_t * per_thread_data
static u8 * format_ip4_sv_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.
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static void ip4_sv_reass_free(vlib_main_t *vm, ip4_sv_reass_main_t *rm, ip4_sv_reass_per_thread_t *rt, ip4_sv_reass_t *reass)
static int ip4_rehash_cb(clib_bihash_kv_16_8_t *kv, void *_ctx)
static int ip4_header_bytes(const ip4_header_t *i)
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
vlib_node_registration_t ip4_sv_reass_node_output_feature
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_node_output_feature)
static u8 * format_ip4_sv_reass_handoff_trace(u8 *s, va_list *args)
#define CLIB_CACHE_LINE_BYTES
uword ip4_sv_reass_custom_register_next_node(uword node_index)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static clib_error_t * ip4_sv_reass_init_function(vlib_main_t *vm)
vl_api_interface_index_t sw_if_index
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".