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;
438 while (n_left_from > 0)
442 while (n_left_from > 0 && n_left_to_next > 0)
447 u32 error0 = IP4_ERROR_NONE;
456 ip.save_rewrite_length);
468 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
470 if (IP_PROTOCOL_TCP == ip0->
protocol)
472 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
479 else if (IP_PROTOCOL_ICMP == ip0->
protocol)
481 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
482 ((icmp46_header_t *) (ip0 + 1))->
type;
499 const u32 fragment_length =
501 const u32 fragment_last = fragment_first + fragment_length - 1;
502 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 &&
ip4_get_fragment_more (ip0)))
505 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
534 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
539 if (reass->is_complete)
551 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
552 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
553 reass->icmp_type_or_tcp_flags;
555 reass->tcp_ack_number;
557 reass->tcp_seq_number;
558 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
559 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
571 ip4_sv_reass_rc_t rc =
580 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
587 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
593 if (reass->is_complete)
598 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
609 if (0 == n_left_to_next)
621 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
622 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
623 reass->icmp_type_or_tcp_flags;
625 reass->tcp_ack_number;
627 reass->tcp_seq_number;
628 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
629 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
639 to_next, n_left_to_next, bi0,
642 _vec_len (reass->cached_buffers) = 0;
650 if (is_feature && IP4_ERROR_NONE == error0)
656 to_next, n_left_to_next,
672 #define _(sym, string) string, 688 .name =
"ip4-sv-reassembly",
689 .vector_size =
sizeof (
u32),
691 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
715 .name =
"ip4-sv-reassembly-feature",
716 .vector_size =
sizeof (
u32),
718 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
732 .arc_name =
"ip4-unicast",
733 .node_name =
"ip4-sv-reassembly-feature",
751 .name =
"ip4-sv-reassembly-output-feature",
752 .vector_size =
sizeof (
u32),
754 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
768 .arc_name =
"ip4-output",
769 .node_name =
"ip4-sv-reassembly-output-feature",
777 .name =
"ip4-sv-reassembly-custom-next",
778 .vector_size =
sizeof (
u32),
780 .n_errors =
ARRAY_LEN (ip4_sv_reass_error_strings),
802 #ifndef CLIB_MARCH_VARIANT 812 for (i = 0; i < 31; i++)
813 if ((1 << i) >= nbuckets)
829 clib_bihash_16_8_t *new_hash;
832 #ifndef CLIB_MARCH_VARIANT 837 if (clib_bihash_add_del_16_8 (ctx->
new_hash, kv, 1))
841 return (BIHASH_WALK_CONTINUE);
846 u32 max_reassembly_length,
847 u32 expire_walk_interval_ms)
858 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
862 max_reassembly_length, expire_walk_interval_ms);
867 if (ip4_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
869 clib_bihash_16_8_t new_hash;
874 clib_bihash_init_16_8 (&new_hash,
"ip4-dr", new_nbuckets,
875 new_nbuckets * 1024);
876 clib_bihash_foreach_key_value_pair_16_8 (&ip4_sv_reass_main.
hash,
880 clib_bihash_free_16_8 (&new_hash);
885 clib_bihash_free_16_8 (&ip4_sv_reass_main.
hash);
887 sizeof (ip4_sv_reass_main.
hash));
896 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
935 clib_bihash_init_16_8 (&rm->
hash,
"ip4-dr", nbuckets, nbuckets * 1024);
959 uword event_type, *event_data = 0;
983 int *pool_indexes_to_free = NULL;
985 uword thread_index = 0;
988 for (thread_index = 0; thread_index < nthreads; ++thread_index)
996 reass = pool_elt_at_index (rt->pool, index);
997 if (now > reass->last_heard + rm->timeout)
999 vec_add1 (pool_indexes_to_free, index);
1018 _vec_len (event_data) = 0;
1029 .name =
"ip4-sv-reassembly-expire-walk",
1043 "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1055 s =
format (s,
"ID: %lu, key: %U trace_op_counter: %u\n",
1068 s =
format (s,
" #%03u: bi: %u, ", counter, bi);
1072 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1087 bool details =
false;
1093 u32 sum_reass_n = 0;
1097 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1105 vlib_cli_output (vm,
"%U", format_ip4_sv_reass, vm, reass);
1114 (
long unsigned) sum_reass_n);
1116 "Maximum configured concurrent shallow virtual IP4 reassemblies per worker-thread: %lu\n",
1119 "Maximum configured shallow virtual IP4 reassembly timeout: %lums\n",
1122 "Maximum configured shallow virtual IP4 reassembly expire walk interval: %lums\n",
1129 .path =
"show ip4-sv-reassembly",
1130 .short_help =
"show ip4-sv-reassembly [details]",
1135 #ifndef CLIB_MARCH_VARIANT 1145 #define foreach_ip4_sv_reass_handoff_error \ 1146 _(CONGESTION_DROP, "congestion drop") 1151 #define _(sym,str) IP4_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1158 #define _(sym,string) string, 1177 format (s,
"ip4-sv-reassembly-handoff: next-worker %d",
1191 u32 n_enq, n_left_from, *from;
1200 ti = thread_indices;
1204 while (n_left_from > 0)
1206 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1210 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1225 if (n_enq < frame->n_vectors)
1227 IP4_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1243 .name =
"ip4-sv-reassembly-handoff",
1244 .vector_size =
sizeof (
u32),
1245 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1272 .name =
"ip4-sv-reass-feature-hoff",
1273 .vector_size =
sizeof (
u32),
1274 .n_errors =
ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1286 #ifndef CLIB_MARCH_VARIANT 1298 "ip4-sv-reassembly-feature",
1299 sw_if_index, 1, 0, 0);
1309 "ip4-sv-reassembly-feature",
1310 sw_if_index, 0, 0, 0);
1334 "ip4-sv-reassembly-output-feature",
1335 sw_if_index, 1, 0, 0);
1345 "ip4-sv-reassembly-output-feature",
1346 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.
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,...)
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
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
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 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)
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".