30 #define MSEC_PER_SEC 1000 31 #define IP6_SV_REASS_TIMEOUT_DEFAULT_MS 100 32 #define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default 33 #define IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT 1024 34 #define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3 35 #define IP6_SV_REASS_HT_LOAD_FACTOR (0.75) 158 #ifndef CLIB_MARCH_VARIANT 202 s =
format (s,
"[cached]");
206 format (s,
"[finish, ip proto=%u, src_port=%u, dst_port=%u]",
212 format (s,
"[forward, ip proto=%u, src_port=%u, dst_port=%u]",
217 s =
format (s,
"[not-fragmented]");
227 ip6_sv_reass_trace_operation_e
action,
235 b->
flags &= ~VLIB_BUFFER_IS_TRACED;
252 printf (
"%.*s\n",
vec_len (s), s);
269 clib_bihash_add_del_48_8 (&rm->
hash, &kv, 0);
315 if (!clib_bihash_search_48_8 (&rm->
hash, &kv->
kv, &kv->
kv))
374 if (clib_bihash_add_del_48_8 (&rm->
hash, &kv->
kv, 1))
387 ip6_frag_hdr_t * frag_hdr)
391 fvnb->
ip.reass.ip6_frag_hdr_offset =
395 fvnb->
ip.reass.ip6_frag_hdr_offset == 0 ||
401 u32 fragment_first = fvnb->
ip.reass.fragment_first =
403 u32 fragment_length =
405 (fvnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
406 u32 fragment_last = fvnb->
ip.reass.fragment_last =
407 fragment_first + fragment_length - 1;
408 fvnb->
ip.reass.range_first = fragment_first;
409 fvnb->
ip.reass.range_last = fragment_last;
410 fvnb->
ip.reass.next_range_bi = ~0;
411 if (0 == fragment_first)
449 ip6_frag_hdr_t * frag_hdr)
451 ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
456 if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
459 ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
461 b->
error = node->
errors[IP6_ERROR_REASS_MISSING_UPPER];
472 ip6_frag_hdr_t * frag_hdr)
477 u32 fragment_length =
479 (vnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
480 if (more_fragments && 0 != fragment_length % 8)
483 ICMP6_parameter_problem_erroneous_header_field,
494 ip6_frag_hdr_t * frag_hdr)
498 u32 fragment_length =
500 (vnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
501 if (fragment_first + fragment_length > 65535)
505 ICMP6_parameter_problem_erroneous_header_field,
506 (
u8 *) & frag_hdr->fragment_offset_and_more
519 u32 n_left_from, n_left_to_next, *to_next, next_index;
527 while (n_left_from > 0)
531 while (n_left_from > 0 && n_left_to_next > 0)
536 u32 error0 = IP6_ERROR_NONE;
543 ip6_frag_hdr_t *frag_hdr = NULL;
544 ip6_ext_header_t *prev_hdr;
549 IP_PROTOCOL_IPV6_FRAGMENTATION,
564 error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO;
569 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
584 (
u8 *) frag_hdr - (
u8 *) ip0;
589 (node, b0, frag_hdr))
596 (vm, node, b0, frag_hdr)
614 (
u64) frag_hdr->identification;
632 error0 = IP6_ERROR_REASS_LIMIT_REACHED;
637 if (reass->is_complete)
641 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
642 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
643 reass->icmp_type_or_tcp_flags;
645 reass->tcp_ack_number;
647 reass->tcp_seq_number;
648 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
649 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
663 (vm, node, rm, rt, reass, bi0, frag_hdr))
670 IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
677 IP6_ERROR_REASS_UNSUPP_IP_PROTO,
684 IP6_ERROR_REASS_INTERNAL_ERROR, 1);
690 if (reass->is_complete)
695 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
696 if (0 == n_left_to_next)
716 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
717 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
718 reass->icmp_type_or_tcp_flags;
720 reass->tcp_ack_number;
722 reass->tcp_seq_number;
723 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
724 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
734 to_next, n_left_to_next, bi0,
737 _vec_len (reass->cached_buffers) = 0;
745 if (is_feature && IP6_ERROR_NONE == error0)
751 n_left_to_next, bi0, next0);
756 to_next[0] = icmp_bi;
760 n_left_to_next, icmp_bi,
777 #define _(sym, string) string, 791 .name =
"ip6-sv-reassembly",
792 .vector_size =
sizeof (
u32),
794 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
816 .name =
"ip6-sv-reassembly-feature",
817 .vector_size =
sizeof (
u32),
819 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
834 .arc_name =
"ip6-unicast",
835 .node_name =
"ip6-sv-reassembly-feature",
841 #ifndef CLIB_MARCH_VARIANT 851 for (i = 0; i < 31; i++)
852 if ((1 << i) >= nbuckets)
865 #ifndef CLIB_MARCH_VARIANT 869 clib_bihash_48_8_t *new_hash;
876 if (clib_bihash_add_del_48_8 (ctx->
new_hash, kv, 1))
880 return (BIHASH_WALK_CONTINUE);
885 u32 max_reassembly_length,
886 u32 expire_walk_interval_ms)
897 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
901 max_reassembly_length, expire_walk_interval_ms);
906 if (ip6_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
908 clib_bihash_48_8_t new_hash;
913 clib_bihash_init_48_8 (&new_hash,
"ip6-sv-reass", new_nbuckets,
914 new_nbuckets * 1024);
915 clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.
hash,
919 clib_bihash_free_48_8 (&new_hash);
924 clib_bihash_free_48_8 (&ip6_sv_reass_main.
hash);
926 sizeof (ip6_sv_reass_main.
hash));
935 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
974 clib_bihash_init_48_8 (&rm->
hash,
"ip6-sv-reass", nbuckets,
1006 uword event_type, *event_data = 0;
1029 int *pool_indexes_to_free = NULL;
1031 uword thread_index = 0;
1034 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1045 vec_add1 (pool_indexes_to_free, index);
1064 _vec_len (event_data) = 0;
1076 .name =
"ip6-sv-reassembly-expire-walk",
1078 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
1088 s =
format (s,
"xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1100 s =
format (s,
"ID: %lu, key: %U, trace_op_counter: %u\n",
1112 s =
format (s,
" #%03u: bi: %u\n", counter, bi);
1116 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1130 bool details =
false;
1136 u32 sum_reass_n = 0;
1137 u64 sum_buffers_n = 0;
1141 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1158 (
long unsigned) sum_reass_n);
1160 "Maximum configured concurrent shallow virtual IP6 reassemblies per worker-thread: %lu\n",
1163 "Maximum configured shallow virtual IP6 reassembly timeout: %lums\n",
1166 "Maximum configured shallow virtual IP6 reassembly expire walk interval: %lums\n",
1169 (
long unsigned) sum_buffers_n);
1175 .path =
"show ip6-sv-reassembly",
1176 .short_help =
"show ip6-sv-reassembly [details]",
1181 #ifndef CLIB_MARCH_VARIANT 1190 #define foreach_ip6_sv_reassembly_handoff_error \ 1191 _(CONGESTION_DROP, "congestion drop") 1196 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1202 static char *ip6_sv_reassembly_handoff_error_strings[] = {
1203 #define _(sym,string) string, 1222 format (s,
"ip6-sv-reassembly-handoff: next-worker %d",
1236 u32 n_enq, n_left_from, *from;
1245 ti = thread_indices;
1249 while (n_left_from > 0)
1251 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1255 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1270 if (n_enq < frame->n_vectors)
1272 IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1287 .name =
"ip6-sv-reassembly-handoff",
1288 .vector_size =
sizeof (
u32),
1289 .n_errors =
ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1310 .name =
"ip6-sv-reass-feature-hoff",
1311 .vector_size =
sizeof (
u32),
1312 .n_errors =
ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1324 #ifndef CLIB_MARCH_VARIANT 1336 "ip6-sv-reassembly-feature",
1337 sw_if_index, 1, 0, 0);
1346 "ip6-sv-reassembly-feature",
1347 sw_if_index, 0, 0, 0);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
VNET_FEATURE_INIT(ip6_sv_reassembly_feature)
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 vec_foreach_index(var, v)
Iterate over vector indices.
static bool ip6_sv_reass_verify_packet_size_lt_64k(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
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 * ip6_sv_reassembly_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...
void ip6_register_protocol(u32 protocol, u32 node_index)
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.
vnet_main_t * vnet_get_main(void)
struct vnet_buffer_opaque_t::@174::@176 ip
#define pool_foreach(VAR, POOL)
Iterate through pool.
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
static uword ip6_sv_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
#define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT
#define clib_memcpy_fast(a, b, c)
clib_bihash_48_8_t * new_hash
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
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 ip6_sv_reass_rc_t ip6_sv_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_sv_reass_main_t *rm, ip6_sv_reass_per_thread_t *rt, ip6_sv_reass_t *reass, u32 bi0, ip6_frag_hdr_t *frag_hdr)
#define IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT
static void ip6_sv_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
u32 * feature_use_refcount_per_intf
#define VLIB_NODE_FN(node)
static u16 ip6_get_port(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6, u16 buffer_len, u8 *ip_protocol, u16 *src_port, u16 *dst_port, u8 *icmp_type_or_tcp_flags, u32 *tcp_ack_number, u32 *tcp_seq_number)
Get L4 information like port number or ICMP id from IPv6 packet.
vlib_error_t * errors
Vector of errors for this node.
static clib_error_t * ip6_sv_reass_init_function(vlib_main_t *vm)
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).
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static void ip6_sv_reass_free(vlib_main_t *vm, ip6_sv_reass_main_t *rm, ip6_sv_reass_per_thread_t *rt, ip6_sv_reass_t *reass)
vlib_trace_header_t ** trace_buffer_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...
ip6_sv_reass_trace_operation_e action
description fragment has unexpected format
static u8 * format_ip6_sv_reass(u8 *s, va_list *args)
ip6_sv_reass_per_thread_t * per_thread_data
static int ip6_rehash_cb(clib_bihash_kv_48_8_t *kv, void *_ctx)
vlib_node_registration_t ip6_sv_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_expire_node)
static uword ip6_sv_reassembly_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
static bool ip6_sv_reass_verify_fragment_multiple_8(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
#define vlib_call_init_function(vm, x)
static void * ip6_ext_header_find(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_header, u8 header_type, ip6_ext_header_t **prev_ext_header)
#define foreach_ip6_sv_reassembly_handoff_error
void icmp6_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
static void clib_spinlock_init(clib_spinlock_t *p)
#define ip6_frag_hdr_more(hdr)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
#define IP6_SV_REASS_HT_LOAD_FACTOR
#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)
IPv6 shallow virtual reassembly.
vnet_api_error_t ip6_sv_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
u8 icmp_type_or_tcp_flags
ip6_sv_reassembly_handoff_error_t
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.
ip6_sv_reass_trace_operation_e
static clib_error_t * show_ip6_sv_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
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 VLIB_REGISTER_NODE(x,...)
clib_error_t * ip_main_init(vlib_main_t *vm)
u32 fq_index
Worker handoff.
sll srl srl sll sra u16x4 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 u32 ip6_sv_reass_get_nbuckets()
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
vnet_api_error_t ip6_sv_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
set ip6 reassembly configuration
#define ip6_frag_hdr_offset_bytes(hdr)
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.
static char * ip6_sv_reassembly_error_strings[]
u32 expire_walk_interval_ms
static u8 ip6_ext_hdr(u8 nexthdr)
vlib_main_t vlib_node_runtime_t * node
#define VLIB_CLI_COMMAND(x,...)
#define ip6_frag_hdr_offset(hdr)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
#define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
vnet_api_error_t ip6_sv_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *max_reassembly_length, u32 *expire_walk_interval_ms)
get ip6 reassembly configuration
static bool ip6_sv_reass_verify_upper_layer_present(vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
vlib_trace_main_t trace_main
IPv6 to IPv4 translation.
int ip6_sv_reass_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
#define VNET_FEATURES(...)
static void ip6_sv_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_sv_reass_main_t *rm, ip6_sv_reass_t *reass, u32 bi, ip6_sv_reass_trace_operation_e action, u32 ip_proto, u16 l4_src_port, u16 l4_dst_port)
#define vec_elt(v, i)
Get vector value at index i.
static void ip6_sv_reass_init(ip6_sv_reass_t *reass)
static uword ip6_sv_reassembly_handoff_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
vl_api_mac_event_action_t action
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_registration_t ip6_sv_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_node)
u32 next_buffer
Next buffer for this linked-list of buffers.
static u8 * format_ip6_sv_reass_key(u8 *s, va_list *args)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
VLIB buffer representation.
ip6_sv_reass_main_t ip6_sv_reass_main
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static ip6_sv_reass_t * ip6_sv_reass_find_or_create(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_sv_reass_main_t *rm, ip6_sv_reass_per_thread_t *rt, ip6_sv_reass_kv_t *kv, u32 *icmp_bi, u8 *do_handoff)
#define foreach_ip6_error
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)
u32 ip6_sv_reass_expire_node_idx
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_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
static u8 * format_ip6_sv_reassembly_handoff_trace(u8 *s, va_list *args)
u32 * fib_index_by_sw_if_index
vlib_node_registration_t ip6_sv_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_node_feature)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u8 * format_ip6_sv_reass_trace(u8 *s, va_list *args)
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".
#define IP6_SV_REASS_TIMEOUT_DEFAULT_MS