17 #include "../ip/ip_frag.h" 22 #ifdef MAP_SKIP_IP6_LOOKUP 75 return format (s,
"MAP domain index: %d L4 port: %u Status: %s",
77 t->
cached ?
"cached" :
"forwarded");
94 return format (s,
"Offset: %d Fragment length: %d Status: %s", t->
offset,
105 u16 sp4 = clib_net_to_host_u16 (port);
134 ip6) ? MAP_ERROR_NONE :
135 MAP_ERROR_DECAP_SEC_CHECK;
139 *error = MAP_ERROR_BAD_PROTOCOL;
153 #ifdef MAP_SKIP_IP6_LOOKUP 170 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
180 while (n_left_from > 0)
185 while (n_left_from >= 4 && n_left_to_next >= 2)
189 u8 error0 = MAP_ERROR_NONE;
190 u8 error1 = MAP_ERROR_NONE;
194 u16 port0 = 0, port1 = 0;
195 u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
214 pi0 = to_next[0] = from[0];
215 pi1 = to_next[1] = from[1];
241 (ip60->
protocol == IP_PROTOCOL_IP_IN_IP
247 as_u32, &map_domain_index0, &error0);
249 else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
251 sizeof (icmp46_header_t))
253 icmp46_header_t *icmp = (
void *) (ip60 + 1);
254 next0 = (icmp->type == ICMP6_echo_request
259 else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
265 error0 = MAP_ERROR_BAD_PROTOCOL;
268 (ip61->
protocol == IP_PROTOCOL_IP_IN_IP
274 as_u32, &map_domain_index1, &error1);
276 else if (ip61->
protocol == IP_PROTOCOL_ICMP6 &&
278 sizeof (icmp46_header_t))
280 icmp46_header_t *icmp = (
void *) (ip61 + 1);
281 next1 = (icmp->type == ICMP6_echo_request
286 else if (ip61->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
292 error1 = MAP_ERROR_BAD_PROTOCOL;
305 && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)))
323 map_domain_index0, 1,
338 && (clib_host_to_net_u16 (ip41->
length) > d1->mtu)))
356 map_domain_index1, 1,
376 if (error0 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled)
381 ICMP6_destination_unreachable_source_address_failed_policy,
390 if (error1 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled)
395 ICMP6_destination_unreachable_source_address_failed_policy,
413 n_left_to_next, pi0, pi1, next0,
418 while (n_left_from > 0 && n_left_to_next > 0)
422 u8 error0 = MAP_ERROR_NONE;
427 u32 map_domain_index0 = ~0;
430 pi0 = to_next[0] = from[0];
452 (ip60->
protocol == IP_PROTOCOL_IP_IN_IP
458 as_u32, &map_domain_index0, &error0);
460 else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
462 sizeof (icmp46_header_t))
464 icmp46_header_t *icmp = (
void *) (ip60 + 1);
465 next0 = (icmp->type == ICMP6_echo_request
470 else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION &&
471 (((ip6_frag_hdr_t *) (ip60 + 1))->next_hdr ==
472 IP_PROTOCOL_IP_IN_IP))
478 error0 = MAP_ERROR_BAD_PROTOCOL;
491 && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)))
509 map_domain_index0, 1,
523 (error0 == MAP_ERROR_DECAP_SEC_CHECK
524 || error0 == MAP_ERROR_NO_DOMAIN))
529 ICMP6_destination_unreachable_source_address_failed_policy,
544 n_left_to_next, pi0, next0);
556 u32 ** fragments_to_drop)
560 ip6_frag_hdr_t *frag0;
578 frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
587 #ifdef MAP_IP6_REASS_COUNT_BYTES 628 tr->
frag_len = clib_net_to_host_u16 (ip40->
length) -
sizeof (*ip40);
641 u8 protocol = frag0->next_hdr;
642 memmove (
u8_ptr_add (ip40, -
sizeof (*ip60)), ip60,
sizeof (*ip60));
678 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
687 while (n_left_from > 0)
692 while (n_left_from > 0 && n_left_to_next > 0)
696 u8 error0 = MAP_ERROR_NONE;
698 ip6_frag_hdr_t *frag0;
703 pi0 = to_next[0] = from[0];
711 frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
713 clib_host_to_net_u16 (frag0->fragment_offset_and_more) & (~7);
733 frag0->identification, frag0->next_hdr,
739 error0 = MAP_ERROR_FRAGMENT_MEMORY;
746 error0 = MAP_ERROR_FRAGMENT_MALFORMED;
750 (r, pi0, offset, next_offset, (
u8 *) (frag0 + 1), frag_len))
753 error0 = MAP_ERROR_FRAGMENT_MEMORY;
757 #ifdef MAP_IP6_REASS_COUNT_BYTES 763 #ifdef MAP_IP6_REASS_COUNT_BYTES 770 if (error0 == MAP_ERROR_NONE)
783 to_next, n_left_to_next,
800 &error_node->
errors[MAP_ERROR_NONE],
803 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
818 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
825 u32 *fragments_to_loopback =
NULL;
830 while (n_left_from > 0)
835 while (n_left_from > 0 && n_left_to_next > 0)
839 u8 error0 = MAP_ERROR_NONE;
844 u32 map_domain_index0 = ~0;
848 pi0 = to_next[0] = from[0];
861 &map_domain_index0, &error0);
873 error0 = MAP_ERROR_FRAGMENT_MEMORY;
886 error0 = MAP_ERROR_FRAGMENT_MEMORY;
899 error0 = MAP_ERROR_BAD_PROTOCOL;
910 #ifdef MAP_IP4_REASS_COUNT_BYTES 917 clib_host_to_net_u16 (ip40->
length) - 20;
928 ip60) ? MAP_ERROR_NONE :
929 MAP_ERROR_DECAP_SEC_CHECK;
932 (d0->
mtu && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)
933 && error0 == MAP_ERROR_NONE && !cached))
959 if (error0 == MAP_ERROR_NONE)
961 cpu_index, map_domain_index0,
970 n_left_to_next, pi0, next0);
974 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
988 fragments_to_loopback + (len -
999 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
1014 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
1019 u16 *fragment_ids, *fid;
1026 fid = fragment_ids =
1028 n_left_from * sizeof (fragment_ids[0]));
1030 while (n_left_from > 0)
1035 while (n_left_from > 0 && n_left_to_next > 0)
1039 u8 error0 = MAP_ERROR_NONE;
1044 pi0 = to_next[0] = from[0];
1048 n_left_to_next -= 1;
1069 error0 = MAP_ERROR_ICMP_RELAY;
1073 icmp46_header_t *icmp60 = (icmp46_header_t *) (ip60 + 1);
1076 if (inner_ip60->
protocol != IP_PROTOCOL_IP_IN_IP)
1078 error0 = MAP_ERROR_ICMP_RELAY;
1085 icmp46_header_t *new_icmp40 = (icmp46_header_t *) (new_ip40 + 1);
1090 switch (icmp60->type)
1092 case ICMP6_destination_unreachable:
1093 case ICMP6_time_exceeded:
1094 case ICMP6_parameter_problem:
1096 new_icmp40->type = ICMP4_destination_unreachable;
1098 ICMP4_destination_unreachable_destination_unreachable_host;
1101 case ICMP6_packet_too_big:
1104 mtu = clib_net_to_host_u32 (*((
u32 *) (icmp60 + 1)));
1111 error0 = MAP_ERROR_ICMP_RELAY;
1115 new_icmp40->type = ICMP4_destination_unreachable;
1117 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set;
1118 *((
u32 *) (new_icmp40 + 1)) =
1119 clib_host_to_net_u32 (mtu < 1280 ? 1280 : mtu);
1123 error0 = MAP_ERROR_ICMP_RELAY;
1132 u16 nlen = (tlen - 20) > 576 ? 576 : tlen - 20;
1133 new_ip40->
length = clib_host_to_net_u16 (nlen);
1137 new_ip40->
protocol = IP_PROTOCOL_ICMP;
1142 new_icmp40->checksum = 0;
1160 n_left_to_next, pi0, next0);
1170 #define _(sym,string) string, 1179 .vector_size =
sizeof(
u32),
1189 #ifdef MAP_SKIP_IP6_LOOKUP 1206 .name =
"ip6-map-ip6-reass",
1207 .vector_size =
sizeof(
u32),
1223 .name =
"ip6-map-ip4-reass",
1224 .vector_size =
sizeof(
u32),
1241 .name =
"ip6-map-icmp-relay",
1242 .vector_size =
sizeof(
u32),
#define map_ip4_reass_lock()
sll srl srl sll sra u16x4 i
static_always_inline bool ip6_map_sec_check(map_domain_t *d, u16 port, ip4_header_t *ip4, ip6_header_t *ip6)
static_always_inline u64 map_get_pfx(map_domain_t *d, u32 addr, u16 port)
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
dpo_id_t dpo
The Load-balance object index to use to forward.
static void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
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.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct _vlib_node_registration vlib_node_registration_t
static char * map_error_strings[]
vlib_error_t * errors
Vector of errors for this node.
vlib_node_registration_t ip6_map_ip4_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_map_ip4_reass_node)
#define u16_net_add(u, val)
static_always_inline void ip6_map_ip6_reass_prepare(vlib_main_t *vm, vlib_node_runtime_t *node, map_ip6_reass_t *r, u32 **fragments_ready, u32 **fragments_to_drop)
vlib_node_registration_t ip6_map_node
(constructor) VLIB_REGISTER_NODE (ip6_map_node)
map_ip6_fragment_t fragments[MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY]
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define map_ip6_reass_unlock()
#define static_always_inline
static_always_inline void ip6_map_security_check(map_domain_t *d, ip4_header_t *ip4, ip6_header_t *ip6, u32 *next, u8 *error)
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
vlib_combined_counter_main_t * domain_counters
static int ip4_get_fragment_offset(ip4_header_t *i)
ip4_address_t icmp4_src_address
vlib_node_registration_t ip6_map_ip6_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_map_ip6_reass_node)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static_always_inline void map_send_all_to_node(vlib_main_t *vm, u32 *pi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
vlib_simple_counter_main_t icmp_relayed
int map_ip4_reass_add_fragment(map_ip4_reass_t *r, u32 pi)
u8 * format_ip6_map_ip4_reass_trace(u8 *s, va_list *args)
void icmp6_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
static int ip4_is_fragment(ip4_header_t *i)
#define ip6_frag_hdr_more(hdr)
u16 current_length
Nbytes between current data and the end of this buffer.
static_always_inline map_domain_t * ip6_map_get_domain(u32 mdi, ip4_address_t *addr, u32 *map_domain_index, u8 *error)
uword os_get_cpu_number(void)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
map_ip4_reass_t * map_ip4_reass_get(u32 src, u32 dst, u16 fragment_id, u8 protocol, u32 **pi_to_drop)
i32 ip4_get_port(ip4_header_t *ip, map_dir_e dir, u16 buffer_len)
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
#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).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
void map_ip4_drop_pi(u32 pi)
u16 ip4_map_get_port(ip4_header_t *ip, map_dir_e dir)
map_main_pre_resolved_t pre_resolved[FIB_PROTOCOL_MAX]
Pre-resolvd per-protocol global next-hops.
void map_ip4_reass_free(map_ip4_reass_t *r, u32 **pi_to_drop)
#define IP4_HEADER_FLAG_MORE_FRAGMENTS
static_always_inline void map_ip4_reass_get_fragments(map_ip4_reass_t *r, u32 **pi)
#define CLIB_PREFETCH(addr, size, type)
map_ip6_reass_t * map_ip6_reass_get(ip6_address_t *src, ip6_address_t *dst, u32 fragment_id, u8 protocol, u32 **pi_to_drop)
#define vec_free(V)
Free vector's memory (no header).
#define VLIB_BUFFER_IS_TRACED
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
static uword ip6_map_icmp_relay(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define clib_memcpy(a, b, c)
static uword ip6_map_ip4_reass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define foreach_map_error
static uword ip6_map(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#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 u8_ptr_add(ptr, index)
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
static_always_inline bool ip6_map_ip4_lookup_bypass(vlib_buffer_t *p0, ip4_header_t *ip)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
#define map_ip4_reass_unlock()
static vlib_node_registration_t ip6_map_icmp_relay_node
(constructor) VLIB_REGISTER_NODE (ip6_map_icmp_relay_node)
u8 * format_map_trace(u8 *s, va_list *args)
static int ip4_get_fragment_more(ip4_header_t *i)
u8 * format_ip6_map_ip6_reass_trace(u8 *s, va_list *args)
static vlib_main_t * vlib_get_main(void)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static uword ip6_map_ip6_reass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
index_t dpoi_index
the index of objects of that type
#define FIB_NODE_INDEX_INVALID
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define map_ip6_reass_lock()
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
A collection of combined counters.
struct clib_bihash_value offset
template key/value backing page structure
void map_ip6_reass_free(map_ip6_reass_t *r, u32 **pi_to_drop)
#define VLIB_REGISTER_NODE(x,...)
#define MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY
#define IP4_HEADER_FLAG_DONT_FRAGMENT
static_always_inline u64 map_get_sfx(map_domain_t *d, u32 addr, u16 port)
u32 ip6_reass_buffered_counter
int map_ip6_reass_add_fragment(map_ip6_reass_t *r, u32 pi, u16 data_offset, u16 next_data_offset, u8 *data_start, u16 data_len)
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 cpu_index, u32 index, u64 increment)
Increment a simple counter.
static u16 ip4_header_checksum(ip4_header_t *i)
clib_random_buffer_t random_buffer
static u16 ip_csum_fold(ip_csum_t c)
void map_ip6_drop_pi(u32 pi)