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
361 kv->v.reass_index = (reass - rt->
pool);
382 if (0 == fragment_first)
389 if (IP_PROTOCOL_TCP == reass->
ip_proto)
395 else if (IP_PROTOCOL_ICMP == reass->
ip_proto)
398 ((icmp46_header_t *) (ip0 + 1))->
type;
428 bool is_output_feature,
bool is_custom)
431 u32 n_left_from, n_left_to_next, *to_next, next_index;
439 while (n_left_from > 0)
443 while (n_left_from > 0 && n_left_to_next > 0)
448 u32 error0 = IP4_ERROR_NONE;
457 ip.save_rewrite_length);
471 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
473 if (IP_PROTOCOL_TCP == ip0->
protocol)
475 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
482 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
484 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
485 ((icmp46_header_t *) (ip0 + 1))->
type;
502 const u32 fragment_length =
504 const u32 fragment_last = fragment_first + fragment_length - 1;
505 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 &&
ip4_get_fragment_more (ip0)))
508 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
536 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
540 if (reass->is_complete)
554 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
555 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
556 reass->icmp_type_or_tcp_flags;
558 reass->tcp_ack_number;
560 reass->tcp_seq_number;
561 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
562 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
563 error0 = IP4_ERROR_NONE;
575 ip4_sv_reass_rc_t rc =
584 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
591 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
597 if (reass->is_complete)
602 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
613 if (0 == n_left_to_next)
628 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
629 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
630 reass->icmp_type_or_tcp_flags;
632 reass->tcp_ack_number;
634 reass->tcp_seq_number;
635 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
636 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
646 to_next, n_left_to_next, bi0,
649 _vec_len (reass->cached_buffers) = 0;
659 if (is_feature && IP4_ERROR_NONE == error0)
665 to_next, n_left_to_next,
681 #define _(sym, string) string, 697 .name =
"ip4-sv-reassembly",
698 .vector_size =
sizeof (
u32),
700 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
724 .name =
"ip4-sv-reassembly-feature",
725 .vector_size =
sizeof (
u32),
727 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
741 .arc_name =
"ip4-unicast",
742 .node_name =
"ip4-sv-reassembly-feature",
760 .name =
"ip4-sv-reassembly-output-feature",
761 .vector_size =
sizeof (
u32),
763 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
777 .arc_name =
"ip4-output",
778 .node_name =
"ip4-sv-reassembly-output-feature",
786 .name =
"ip4-sv-reassembly-custom-next",
787 .vector_size =
sizeof (
u32),
789 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
811 #ifndef CLIB_MARCH_VARIANT 821 for (i = 0; i < 31; i++)
822 if ((1 << i) >= nbuckets)
838 clib_bihash_16_8_t *new_hash;
841 #ifndef CLIB_MARCH_VARIANT 846 if (clib_bihash_add_del_16_8 (ctx->
new_hash, kv, 1))
850 return (BIHASH_WALK_CONTINUE);
855 u32 max_reassembly_length,
856 u32 expire_walk_interval_ms)
867 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
871 max_reassembly_length, expire_walk_interval_ms);
876 if (ip4_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
878 clib_bihash_16_8_t new_hash;
883 clib_bihash_init_16_8 (&new_hash,
"ip4-dr", new_nbuckets,
884 new_nbuckets * 1024);
885 clib_bihash_foreach_key_value_pair_16_8 (&ip4_sv_reass_main.
hash,
889 clib_bihash_free_16_8 (&new_hash);
894 clib_bihash_free_16_8 (&ip4_sv_reass_main.
hash);
896 sizeof (ip4_sv_reass_main.
hash));
905 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
944 clib_bihash_init_16_8 (&rm->
hash,
"ip4-dr", nbuckets, nbuckets * 1024);
968 uword event_type, *event_data = 0;
992 int *pool_indexes_to_free =
NULL;
994 uword thread_index = 0;
997 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1005 reass = pool_elt_at_index (rt->pool, index);
1006 if (now > reass->last_heard + rm->timeout)
1008 vec_add1 (pool_indexes_to_free, index);
1027 _vec_len (event_data) = 0;
1038 .name =
"ip4-sv-reassembly-expire-walk",
1052 "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1064 s =
format (s,
"ID: %lu, key: %U trace_op_counter: %u\n",
1077 s =
format (s,
" #%03u: bi: %u, ", counter, bi);
1081 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1096 bool details =
false;
1102 u32 sum_reass_n = 0;
1106 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1114 vlib_cli_output (vm,
"%U", format_ip4_sv_reass, vm, reass);
1123 (
long unsigned) sum_reass_n);
1125 "Maximum configured concurrent IP4 reassemblies per worker-thread: %lu\n",
1132 .path =
"show ip4-sv-reassembly",
1133 .short_help =
"show ip4-sv-reassembly [details]",
1138 #ifndef CLIB_MARCH_VARIANT 1148 #define foreach_ip4_sv_reass_handoff_error \ 1149 _(CONGESTION_DROP, "congestion drop") 1154 #define _(sym,str) IP4_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1161 #define _(sym,string) string, 1180 format (s,
"ip4-sv-reassembly-handoff: next-worker %d",
1194 u32 n_enq, n_left_from, *from;
1203 ti = thread_indices;
1207 while (n_left_from > 0)
1209 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1213 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1228 if (n_enq < frame->n_vectors)
1230 IP4_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1246 .name =
"ip4-sv-reassembly-handoff",
1247 .vector_size =
sizeof (
u32),
1248 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1275 .name =
"ip4-sv-reass-feature-hoff",
1276 .vector_size =
sizeof (
u32),
1277 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1289 #ifndef CLIB_MARCH_VARIANT 1301 "ip4-sv-reassembly-feature",
1302 sw_if_index, 1, 0, 0);
1312 "ip4-sv-reassembly-feature",
1313 sw_if_index, 0, 0, 0);
1337 "ip4-sv-reassembly-output-feature",
1338 sw_if_index, 1, 0, 0);
1348 "ip4-sv-reassembly-output-feature",
1349 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)
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.
vl_api_interface_index_t sw_if_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)
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.
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,...)
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_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
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.
#define VNET_FEATURES(...)
static vlib_main_t * vlib_get_main(void)
u32 ip4_sv_reass_expire_node_idx
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.
void clib_bihash_copied(void *dst, void *src)
struct _vlib_node_registration vlib_node_registration_t
#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.
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.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
u16 flags
Copy of main node flags.
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)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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)
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".