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
364 kv->v.reass_index = (reass - rt->
pool);
381 ip6_frag_hdr_t * frag_hdr)
385 fvnb->
ip.reass.ip6_frag_hdr_offset =
389 fvnb->
ip.reass.ip6_frag_hdr_offset == 0 ||
395 u32 fragment_first = fvnb->
ip.reass.fragment_first =
397 u32 fragment_length =
399 (fvnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
400 u32 fragment_last = fvnb->
ip.reass.fragment_last =
401 fragment_first + fragment_length - 1;
402 fvnb->
ip.reass.range_first = fragment_first;
403 fvnb->
ip.reass.range_last = fragment_last;
404 fvnb->
ip.reass.next_range_bi = ~0;
405 if (0 == fragment_first)
443 ip6_frag_hdr_t * frag_hdr)
445 ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
450 if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
453 ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
455 b->
error = node->
errors[IP6_ERROR_REASS_MISSING_UPPER];
466 ip6_frag_hdr_t * frag_hdr)
471 u32 fragment_length =
473 (vnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
474 if (more_fragments && 0 != fragment_length % 8)
477 ICMP6_parameter_problem_erroneous_header_field,
488 ip6_frag_hdr_t * frag_hdr)
492 u32 fragment_length =
494 (vnb->
ip.reass.ip6_frag_hdr_offset +
sizeof (*frag_hdr));
495 if (fragment_first + fragment_length > 65535)
499 ICMP6_parameter_problem_erroneous_header_field,
500 (
u8 *) & frag_hdr->fragment_offset_and_more
513 u32 n_left_from, n_left_to_next, *to_next, next_index;
521 while (n_left_from > 0)
525 while (n_left_from > 0 && n_left_to_next > 0)
530 u32 error0 = IP6_ERROR_NONE;
537 ip6_frag_hdr_t *frag_hdr =
NULL;
538 ip6_ext_header_t *prev_hdr;
543 IP_PROTOCOL_IPV6_FRAGMENTATION,
558 error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO;
565 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
580 (
u8 *) frag_hdr - (
u8 *) ip0;
585 (node, b0, frag_hdr))
592 (vm, node, b0, frag_hdr)
610 (
u64) frag_hdr->identification;
628 error0 = IP6_ERROR_REASS_LIMIT_REACHED;
632 if (reass->is_complete)
639 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
640 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
641 reass->icmp_type_or_tcp_flags;
643 reass->tcp_ack_number;
645 reass->tcp_seq_number;
646 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
647 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
649 error0 = IP6_ERROR_NONE;
662 (vm, node, rm, rt, reass, bi0, frag_hdr))
669 IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
676 IP6_ERROR_REASS_UNSUPP_IP_PROTO,
683 IP6_ERROR_REASS_INTERNAL_ERROR, 1);
691 if (reass->is_complete)
696 u32 bi0 =
vec_elt (reass->cached_buffers, idx);
697 if (0 == n_left_to_next)
720 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
721 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
722 reass->icmp_type_or_tcp_flags;
724 reass->tcp_ack_number;
726 reass->tcp_seq_number;
727 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
728 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
738 to_next, n_left_to_next, bi0,
741 _vec_len (reass->cached_buffers) = 0;
749 if (is_feature && IP6_ERROR_NONE == error0)
755 n_left_to_next, bi0, next0);
760 to_next[0] = icmp_bi;
764 n_left_to_next, icmp_bi,
781 #define _(sym, string) string, 795 .name =
"ip6-sv-reassembly",
796 .vector_size =
sizeof (
u32),
798 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
820 .name =
"ip6-sv-reassembly-feature",
821 .vector_size =
sizeof (
u32),
823 .n_errors =
ARRAY_LEN (ip6_sv_reassembly_error_strings),
838 .arc_name =
"ip6-unicast",
839 .node_name =
"ip6-sv-reassembly-feature",
845 #ifndef CLIB_MARCH_VARIANT 855 for (i = 0; i < 31; i++)
856 if ((1 << i) >= nbuckets)
869 #ifndef CLIB_MARCH_VARIANT 873 clib_bihash_48_8_t *new_hash;
880 if (clib_bihash_add_del_48_8 (ctx->
new_hash, kv, 1))
884 return (BIHASH_WALK_CONTINUE);
889 u32 max_reassembly_length,
890 u32 expire_walk_interval_ms)
901 u32 max_reassembly_length,
u32 expire_walk_interval_ms)
905 max_reassembly_length, expire_walk_interval_ms);
910 if (ip6_sv_reass_main.
max_reass_n > 0 && new_nbuckets > old_nbuckets)
912 clib_bihash_48_8_t new_hash;
917 clib_bihash_init_48_8 (&new_hash,
"ip6-sv-reass", new_nbuckets,
918 new_nbuckets * 1024);
919 clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.
hash,
923 clib_bihash_free_48_8 (&new_hash);
928 clib_bihash_free_48_8 (&ip6_sv_reass_main.
hash);
930 sizeof (ip6_sv_reass_main.
hash));
939 u32 * max_reassembly_length,
u32 * expire_walk_interval_ms)
978 clib_bihash_init_48_8 (&rm->
hash,
"ip6-sv-reass", nbuckets,
1010 uword event_type, *event_data = 0;
1033 int *pool_indexes_to_free =
NULL;
1035 uword thread_index = 0;
1038 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1046 reass = pool_elt_at_index (rt->pool, index);
1047 if (now > reass->last_heard + rm->timeout)
1049 vec_add1 (pool_indexes_to_free, index);
1068 _vec_len (event_data) = 0;
1080 .name =
"ip6-sv-reassembly-expire-walk",
1092 s =
format (s,
"xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1104 s =
format (s,
"ID: %lu, key: %U, trace_op_counter: %u\n",
1116 s =
format (s,
" #%03u: bi: %u\n", counter, bi);
1120 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT);
1134 bool details =
false;
1140 u32 sum_reass_n = 0;
1141 u64 sum_buffers_n = 0;
1145 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1153 vlib_cli_output (vm,
"%U", format_ip6_sv_reass, vm, reass);
1162 (
long unsigned) sum_reass_n);
1163 vlib_cli_output (vm,
"Maximum configured concurrent IP6 reassemblies per " 1164 "worker-thread: %lu\n", (
long unsigned) rm->
max_reass_n);
1166 (
long unsigned) sum_buffers_n);
1172 .path =
"show ip6-sv-reassembly",
1173 .short_help =
"show ip6-sv-reassembly [details]",
1178 #ifndef CLIB_MARCH_VARIANT 1187 #define foreach_ip6_sv_reassembly_handoff_error \ 1188 _(CONGESTION_DROP, "congestion drop") 1193 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym, 1200 #define _(sym,string) string, 1219 format (s,
"ip6-sv-reassembly-handoff: next-worker %d",
1233 u32 n_enq, n_left_from, *from;
1242 ti = thread_indices;
1246 while (n_left_from > 0)
1248 ti[0] =
vnet_buffer (b[0])->ip.reass.owner_thread_index;
1252 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1267 if (n_enq < frame->n_vectors)
1269 IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1284 .name =
"ip6-sv-reassembly-handoff",
1285 .vector_size =
sizeof (
u32),
1286 .n_errors =
ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1307 .name =
"ip6-sv-reass-feature-hoff",
1308 .vector_size =
sizeof (
u32),
1309 .n_errors =
ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1321 #ifndef CLIB_MARCH_VARIANT 1333 "ip6-sv-reassembly-feature",
1334 sw_if_index, 1, 0, 0);
1343 "ip6-sv-reassembly-feature",
1344 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)
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...
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.
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.
#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.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static char * ip6_sv_reassembly_error_strings[]
u32 expire_walk_interval_ms
vlib_main_t vlib_node_runtime_t * node
static u8 ip6_ext_hdr(u8 nexthdr)
#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
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)
struct vnet_buffer_opaque_t::@132::@134 ip
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)
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)
#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 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.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
u16 flags
Copy of main node flags.
#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)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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)
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