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,
252 printf (
"%.*s\n",
vec_len (s), s);
266 clib_bihash_add_del_16_8 (&rm->
hash, &kv, 0);
310 if (!clib_bihash_search_16_8 (&rm->
hash, &kv->
kv, &kv->
kv))
364 if (clib_bihash_add_del_16_8 (&rm->
hash, &kv->
kv, 1))
381 if (0 == fragment_first)
388 if (IP_PROTOCOL_TCP == reass->
ip_proto)
394 else if (IP_PROTOCOL_ICMP == reass->
ip_proto)
397 ((icmp46_header_t *) (ip0 + 1))->
type;
427 bool is_output_feature,
bool is_custom)
430 u32 n_left_from, n_left_to_next, *to_next, next_index;
444 while (n_left_from >= 2)
470 (is_output_feature ? 1 : 0) *
472 ip.save_rewrite_length);
475 (is_output_feature ? 1 : 0) *
477 ip.save_rewrite_length);
497 next0 = is_custom ?
vnet_buffer (b0)->ip.reass.next_index :
500 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
502 if (IP_PROTOCOL_TCP == ip0->
protocol)
504 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
511 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
513 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
514 ((icmp46_header_t *) (ip0 + 1))->
type;
532 next1 = is_custom ?
vnet_buffer (b1)->ip.reass.next_index :
535 vnet_buffer (b1)->ip.reass.is_non_first_fragment = 0;
537 if (IP_PROTOCOL_TCP == ip1->
protocol)
539 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
546 else if (IP_PROTOCOL_ICMP == ip1->
protocol)
548 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
549 ((icmp46_header_t *) (ip1 + 1))->
type;
568 while (n_left_from > 0)
577 (is_output_feature ? 1 : 0) *
579 ip.save_rewrite_length);
602 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
604 if (IP_PROTOCOL_TCP == ip0->
protocol)
606 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
613 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
615 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
616 ((icmp46_header_t *) (ip0 + 1))->
type;
643 while (n_left_from > 0)
647 while (n_left_from > 0 && n_left_to_next > 0)
652 u32 error0 = IP4_ERROR_NONE;
659 (is_output_feature ? 1 : 0) *
661 ip.save_rewrite_length);
673 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
675 if (IP_PROTOCOL_TCP == ip0->
protocol)
677 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
684 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
686 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
687 ((icmp46_header_t *) (ip0 + 1))->
type;
704 const u32 fragment_length =
706 const u32 fragment_last = fragment_first + fragment_length - 1;
707 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 &&
ip4_get_fragment_more (ip0)))
710 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
739 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
744 if (reass->is_complete)
756 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
757 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
758 reass->icmp_type_or_tcp_flags;
760 reass->tcp_ack_number;
762 reass->tcp_seq_number;
763 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
764 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
776 ip4_sv_reass_rc_t rc =
785 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
792 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
798 if (reass->is_complete)
803 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
807 (is_output_feature ? 1 : 0) *
809 ip.save_rewrite_length);
819 if (0 == n_left_to_next)
831 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
832 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
833 reass->icmp_type_or_tcp_flags;
835 reass->tcp_ack_number;
837 reass->tcp_seq_number;
838 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
839 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
849 to_next, n_left_to_next, bi0,
852 _vec_len (reass->cached_buffers) = 0;
860 if (is_feature && IP4_ERROR_NONE == error0)
866 to_next, n_left_to_next,
883 #define _(sym, string) string, 899 .name =
"ip4-sv-reassembly",
900 .vector_size =
sizeof (
u32),
902 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
926 .name =
"ip4-sv-reassembly-feature",
927 .vector_size =
sizeof (
u32),
929 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
943 .arc_name =
"ip4-unicast",
944 .node_name =
"ip4-sv-reassembly-feature",
962 .name =
"ip4-sv-reassembly-output-feature",
963 .vector_size =
sizeof (
u32),
965 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
979 .arc_name =
"ip4-output",
980 .node_name =
"ip4-sv-reassembly-output-feature",
988 .name =
"ip4-sv-reassembly-custom-next",
989 .vector_size =
sizeof (
u32),
991 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
1013 #ifndef CLIB_MARCH_VARIANT 1023 for (i = 0; i < 31; i++)
1024 if ((1 << i) >= nbuckets)
1040 clib_bihash_16_8_t *new_hash;
1043 #ifndef CLIB_MARCH_VARIANT 1048 if (clib_bihash_add_del_16_8 (ctx->
new_hash, kv, 1))
1052 return (BIHASH_WALK_CONTINUE);
1057 u32 max_reassembly_length,
1058 u32 expire_walk_interval_ms)
1069 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
1073 max_reassembly_length, expire_walk_interval_ms);
1078 if (ip4_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
1080 clib_bihash_16_8_t new_hash;
1085 clib_bihash_init_16_8 (&new_hash,
"ip4-dr", new_nbuckets,
1086 new_nbuckets * 1024);
1087 clib_bihash_foreach_key_value_pair_16_8 (&ip4_sv_reass_main.
hash,
1091 clib_bihash_free_16_8 (&new_hash);
1096 clib_bihash_free_16_8 (&ip4_sv_reass_main.
hash);
1098 sizeof (ip4_sv_reass_main.
hash));
1107 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
1110 *max_reassemblies = ip4_sv_reass_main.
max_reass_n;
1146 clib_bihash_init_16_8 (&rm->
hash,
"ip4-dr", nbuckets, nbuckets * 1024);
1170 uword event_type, *event_data = 0;
1194 int *pool_indexes_to_free = NULL;
1196 uword thread_index = 0;
1199 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1207 reass = pool_elt_at_index (rt->pool, index);
1208 if (now > reass->last_heard + rm->timeout)
1210 vec_add1 (pool_indexes_to_free, index);
1229 _vec_len (event_data) = 0;
1240 .name =
"ip4-sv-reassembly-expire-walk",
1254 "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1266 s =
format (s,
"ID: %lu, key: %U trace_op_counter: %u\n",
1279 s =
format (s,
" #%03u: bi: %u, ", counter, bi);
1283 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1298 bool details =
false;
1304 u32 sum_reass_n = 0;
1308 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1316 vlib_cli_output (vm,
"%U", format_ip4_sv_reass, vm, reass);
1325 (
long unsigned) sum_reass_n);
1327 "Maximum configured concurrent shallow virtual IP4 reassemblies per worker-thread: %lu\n",
1330 "Maximum configured shallow virtual IP4 reassembly timeout: %lums\n",
1333 "Maximum configured shallow virtual IP4 reassembly expire walk interval: %lums\n",
1340 .path =
"show ip4-sv-reassembly",
1341 .short_help =
"show ip4-sv-reassembly [details]",
1346 #ifndef CLIB_MARCH_VARIANT 1356 #define foreach_ip4_sv_reass_handoff_error \ 1357 _(CONGESTION_DROP, "congestion drop") 1362 #define _(sym,str) IP4_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1369 #define _(sym,string) string, 1388 format (s,
"ip4-sv-reassembly-handoff: next-worker %d",
1402 u32 n_enq, n_left_from, *from;
1411 ti = thread_indices;
1415 while (n_left_from > 0)
1417 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1421 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1436 if (n_enq < frame->n_vectors)
1438 IP4_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1454 .name =
"ip4-sv-reassembly-handoff",
1455 .vector_size =
sizeof (
u32),
1456 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1483 .name =
"ip4-sv-reass-feature-hoff",
1484 .vector_size =
sizeof (
u32),
1485 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1497 #ifndef CLIB_MARCH_VARIANT 1509 "ip4-sv-reassembly-feature",
1510 sw_if_index, 1, 0, 0);
1520 "ip4-sv-reassembly-feature",
1521 sw_if_index, 0, 0, 0);
1545 "ip4-sv-reassembly-output-feature",
1546 sw_if_index, 1, 0, 0);
1556 "ip4-sv-reassembly-output-feature",
1557 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)
static vlib_cli_command_t show_ip4_sv_reass_cmd
(constructor) VLIB_CLI_COMMAND (show_ip4_sv_reass_cmd)
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 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_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
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)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
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)
vlib_node_registration_t ip4_sv_reass_feature_handoff_node
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_feature_handoff_node)
#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...)
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_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,...)
#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.
void clib_bihash_copied(void *dst, void *src)
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.
vlib_node_registration_t ip4_sv_reass_handoff_node
(constructor) VLIB_REGISTER_NODE (ip4_sv_reass_handoff_node)
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)
#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
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".