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,
245 printf (
"%.*s\n",
vec_len (s), s);
262 clib_bihash_add_del_48_8 (&rm->
hash, &kv, 0);
308 if (!clib_bihash_search_48_8 (&rm->
hash, &kv->
kv, &kv->
kv))
367 if (clib_bihash_add_del_48_8 (&rm->
hash, &kv->
kv, 1))
380 ip6_frag_hdr_t * frag_hdr)
384 fvnb->
ip.reass.ip6_frag_hdr_offset =
388 fvnb->
ip.reass.ip6_frag_hdr_offset == 0 ||
394 u32 fragment_first = fvnb->
ip.reass.fragment_first =
396 u32 fragment_length =
398 (fvnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
399 u32 fragment_last = fvnb->
ip.reass.fragment_last =
400 fragment_first + fragment_length - 1;
401 fvnb->
ip.reass.range_first = fragment_first;
402 fvnb->
ip.reass.range_last = fragment_last;
403 fvnb->
ip.reass.next_range_bi = ~0;
404 if (0 == fragment_first)
442 ip6_frag_hdr_t * frag_hdr)
444 ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
449 if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
452 ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
454 b->
error = node->
errors[IP6_ERROR_REASS_MISSING_UPPER];
465 ip6_frag_hdr_t * frag_hdr)
470 u32 fragment_length =
472 (vnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
473 if (more_fragments && 0 != fragment_length % 8)
476 ICMP6_parameter_problem_erroneous_header_field,
487 ip6_frag_hdr_t * frag_hdr)
491 u32 fragment_length =
493 (vnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
494 if (fragment_first + fragment_length > 65535)
498 ICMP6_parameter_problem_erroneous_header_field,
499 (
u8 *) & frag_hdr->fragment_offset_and_more
512 u32 n_left_from, n_left_to_next, *to_next, next_index;
520 while (n_left_from > 0)
524 while (n_left_from > 0 && n_left_to_next > 0)
529 u32 error0 = IP6_ERROR_NONE;
536 ip6_frag_hdr_t *frag_hdr = NULL;
537 ip6_ext_header_t *prev_hdr;
542 IP_PROTOCOL_IPV6_FRAGMENTATION,
557 error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO;
562 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
577 (
u8 *) frag_hdr - (
u8 *) ip0;
582 (node, b0, frag_hdr))
589 (vm, node, b0, frag_hdr)
607 (
u64) frag_hdr->identification;
625 error0 = IP6_ERROR_REASS_LIMIT_REACHED;
630 if (reass->is_complete)
634 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
635 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
636 reass->icmp_type_or_tcp_flags;
638 reass->tcp_ack_number;
640 reass->tcp_seq_number;
641 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
642 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
656 (vm, node, rm, rt, reass, bi0, frag_hdr))
663 IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
670 IP6_ERROR_REASS_UNSUPP_IP_PROTO,
677 IP6_ERROR_REASS_INTERNAL_ERROR, 1);
683 if (reass->is_complete)
688 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
689 if (0 == n_left_to_next)
709 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
710 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
711 reass->icmp_type_or_tcp_flags;
713 reass->tcp_ack_number;
715 reass->tcp_seq_number;
716 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
717 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
727 to_next, n_left_to_next, bi0,
730 _vec_len (reass->cached_buffers) = 0;
738 if (is_feature && IP6_ERROR_NONE == error0)
744 n_left_to_next, bi0, next0);
749 to_next[0] = icmp_bi;
753 n_left_to_next, icmp_bi,
770 #define _(sym, string) string, 784 .name =
"ip6-sv-reassembly",
785 .vector_size =
sizeof (
u32),
787 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
809 .name =
"ip6-sv-reassembly-feature",
810 .vector_size =
sizeof (
u32),
812 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
827 .arc_name =
"ip6-unicast",
828 .node_name =
"ip6-sv-reassembly-feature",
834 #ifndef CLIB_MARCH_VARIANT 844 for (i = 0; i < 31; i++)
845 if ((1 << i) >= nbuckets)
858 #ifndef CLIB_MARCH_VARIANT 862 clib_bihash_48_8_t *new_hash;
869 if (clib_bihash_add_del_48_8 (ctx->
new_hash, kv, 1))
873 return (BIHASH_WALK_CONTINUE);
878 u32 max_reassembly_length,
879 u32 expire_walk_interval_ms)
890 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
894 max_reassembly_length, expire_walk_interval_ms);
899 if (ip6_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
901 clib_bihash_48_8_t new_hash;
906 clib_bihash_init_48_8 (&new_hash,
"ip6-sv-reass", new_nbuckets,
907 new_nbuckets * 1024);
908 clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.
hash,
912 clib_bihash_free_48_8 (&new_hash);
917 clib_bihash_free_48_8 (&ip6_sv_reass_main.
hash);
919 sizeof (ip6_sv_reass_main.
hash));
928 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
967 clib_bihash_init_48_8 (&rm->
hash,
"ip6-sv-reass", nbuckets,
999 uword event_type, *event_data = 0;
1022 int *pool_indexes_to_free = NULL;
1024 uword thread_index = 0;
1027 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1035 reass = pool_elt_at_index (rt->pool, index);
1036 if (now > reass->last_heard + rm->timeout)
1038 vec_add1 (pool_indexes_to_free, index);
1057 _vec_len (event_data) = 0;
1069 .name =
"ip6-sv-reassembly-expire-walk",
1081 s =
format (s,
"xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1093 s =
format (s,
"ID: %lu, key: %U, trace_op_counter: %u\n",
1105 s =
format (s,
" #%03u: bi: %u\n", counter, bi);
1109 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1123 bool details =
false;
1129 u32 sum_reass_n = 0;
1130 u64 sum_buffers_n = 0;
1134 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1142 vlib_cli_output (vm,
"%U", format_ip6_sv_reass, vm, reass);
1151 (
long unsigned) sum_reass_n);
1153 "Maximum configured concurrent shallow virtual IP6 reassemblies per worker-thread: %lu\n",
1156 "Maximum configured shallow virtual IP6 reassembly timeout: %lums\n",
1159 "Maximum configured shallow virtual IP6 reassembly expire walk interval: %lums\n",
1162 (
long unsigned) sum_buffers_n);
1168 .path =
"show ip6-sv-reassembly",
1169 .short_help =
"show ip6-sv-reassembly [details]",
1174 #ifndef CLIB_MARCH_VARIANT 1183 #define foreach_ip6_sv_reassembly_handoff_error \ 1184 _(CONGESTION_DROP, "congestion drop") 1189 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1196 #define _(sym,string) string, 1215 format (s,
"ip6-sv-reassembly-handoff: next-worker %d",
1229 u32 n_enq, n_left_from, *from;
1238 ti = thread_indices;
1242 while (n_left_from > 0)
1244 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1248 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1263 if (n_enq < frame->n_vectors)
1265 IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1280 .name =
"ip6-sv-reassembly-handoff",
1281 .vector_size =
sizeof (
u32),
1282 .n_errors =
ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1303 .name =
"ip6-sv-reass-feature-hoff",
1304 .vector_size =
sizeof (
u32),
1305 .n_errors =
ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1317 #ifndef CLIB_MARCH_VARIANT 1329 "ip6-sv-reassembly-feature",
1330 sw_if_index, 1, 0, 0);
1339 "ip6-sv-reassembly-feature",
1340 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)
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.
vnet_main_t * vnet_get_main(void)
#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 vlib_cli_command_t show_ip6_sv_reassembly_cmd
(constructor) VLIB_CLI_COMMAND (show_ip6_sv_reassembly_cmd)
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_node_registration_t ip6_sv_reassembly_feature_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reassembly_feature_handoff_node)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vlib_node_registration_t ip6_sv_reassembly_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node)
#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
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...)
static u32 ip6_sv_reass_get_nbuckets()
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)
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.
void clib_bihash_copied(void *dst, void *src)
struct vnet_buffer_opaque_t::@162::@164 ip
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)
#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
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