17 #include "../ip/ip_frag.h" 24 #ifdef MAP_SKIP_IP6_LOOKUP 77 return format (s,
"MAP domain index: %d L4 port: %u Status: %s",
79 t->
cached ?
"cached" :
"forwarded");
96 return format (s,
"Offset: %d Fragment length: %d Status: %s", t->
offset,
107 u16 sp4 = clib_net_to_host_u16 (port);
136 ip6) ? MAP_ERROR_NONE :
137 MAP_ERROR_DECAP_SEC_CHECK;
141 *error = MAP_ERROR_BAD_PROTOCOL;
155 #ifdef MAP_SKIP_IP6_LOOKUP 172 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
182 while (n_left_from > 0)
187 while (n_left_from >= 4 && n_left_to_next >= 2)
191 u8 error0 = MAP_ERROR_NONE;
192 u8 error1 = MAP_ERROR_NONE;
196 u16 port0 = 0, port1 = 0;
197 u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
216 pi0 = to_next[0] = from[0];
217 pi1 = to_next[1] = from[1];
243 (ip60->
protocol == IP_PROTOCOL_IP_IN_IP
249 src_address.as_u32, &map_domain_index0,
252 else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
254 sizeof (icmp46_header_t))
256 icmp46_header_t *icmp = (
void *) (ip60 + 1);
257 next0 = (icmp->type == ICMP6_echo_request
262 else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
268 error0 = MAP_ERROR_BAD_PROTOCOL;
271 (ip61->
protocol == IP_PROTOCOL_IP_IN_IP
277 src_address.as_u32, &map_domain_index1,
280 else if (ip61->
protocol == IP_PROTOCOL_ICMP6 &&
282 sizeof (icmp46_header_t))
284 icmp46_header_t *icmp = (
void *) (ip61 + 1);
285 next1 = (icmp->type == ICMP6_echo_request
290 else if (ip61->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
296 error1 = MAP_ERROR_BAD_PROTOCOL;
309 && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)))
327 map_domain_index0, 1,
342 && (clib_host_to_net_u16 (ip41->
length) > d1->mtu)))
360 map_domain_index1, 1,
380 if (error0 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled)
385 ICMP6_destination_unreachable_source_address_failed_policy,
394 if (error1 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled)
399 ICMP6_destination_unreachable_source_address_failed_policy,
417 n_left_to_next, pi0, pi1, next0,
422 while (n_left_from > 0 && n_left_to_next > 0)
426 u8 error0 = MAP_ERROR_NONE;
431 u32 map_domain_index0 = ~0;
434 pi0 = to_next[0] = from[0];
456 (ip60->
protocol == IP_PROTOCOL_IP_IN_IP
462 src_address.as_u32, &map_domain_index0,
465 else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
467 sizeof (icmp46_header_t))
469 icmp46_header_t *icmp = (
void *) (ip60 + 1);
470 next0 = (icmp->type == ICMP6_echo_request
475 else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION &&
476 (((ip6_frag_hdr_t *) (ip60 + 1))->next_hdr ==
477 IP_PROTOCOL_IP_IN_IP))
483 error0 = MAP_ERROR_BAD_PROTOCOL;
496 && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)))
514 map_domain_index0, 1,
528 (error0 == MAP_ERROR_DECAP_SEC_CHECK
529 || error0 == MAP_ERROR_NO_DOMAIN))
534 ICMP6_destination_unreachable_source_address_failed_policy,
549 n_left_to_next, pi0, next0);
561 u32 ** fragments_to_drop)
565 ip6_frag_hdr_t *frag0;
583 frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
592 #ifdef MAP_IP6_REASS_COUNT_BYTES 633 tr->
frag_len = clib_net_to_host_u16 (ip40->
length) -
sizeof (*ip40);
646 u8 protocol = frag0->next_hdr;
647 memmove (
u8_ptr_add (ip40, -
sizeof (*ip60)), ip60,
sizeof (*ip60));
683 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
692 while (n_left_from > 0)
697 while (n_left_from > 0 && n_left_to_next > 0)
701 u8 error0 = MAP_ERROR_NONE;
703 ip6_frag_hdr_t *frag0;
708 pi0 = to_next[0] = from[0];
716 frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
718 clib_host_to_net_u16 (frag0->fragment_offset_and_more) & (~7);
738 frag0->identification, frag0->next_hdr,
744 error0 = MAP_ERROR_FRAGMENT_MEMORY;
751 error0 = MAP_ERROR_FRAGMENT_MALFORMED;
755 (r, pi0, offset, next_offset, (
u8 *) (frag0 + 1), frag_len))
758 error0 = MAP_ERROR_FRAGMENT_MEMORY;
762 #ifdef MAP_IP6_REASS_COUNT_BYTES 768 #ifdef MAP_IP6_REASS_COUNT_BYTES 775 if (error0 == MAP_ERROR_NONE)
788 to_next, n_left_to_next,
805 &error_node->
errors[MAP_ERROR_NONE],
808 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
823 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
830 u32 *fragments_to_loopback =
NULL;
835 while (n_left_from > 0)
840 while (n_left_from > 0 && n_left_to_next > 0)
844 u8 error0 = MAP_ERROR_NONE;
849 u32 map_domain_index0 = ~0;
853 pi0 = to_next[0] = from[0];
866 &map_domain_index0, &error0);
878 error0 = MAP_ERROR_FRAGMENT_MEMORY;
891 error0 = MAP_ERROR_FRAGMENT_MEMORY;
902 error0 = MAP_ERROR_BAD_PROTOCOL;
913 #ifdef MAP_IP4_REASS_COUNT_BYTES 920 clib_host_to_net_u16 (ip40->
length) - 20;
931 ip60) ? MAP_ERROR_NONE :
932 MAP_ERROR_DECAP_SEC_CHECK;
935 (d0->
mtu && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)
936 && error0 == MAP_ERROR_NONE && !cached))
962 if (error0 == MAP_ERROR_NONE)
965 map_domain_index0, 1,
973 n_left_to_next, pi0, next0);
977 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
991 fragments_to_loopback + (len -
1002 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
1017 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
1022 u16 *fragment_ids, *fid;
1029 fid = fragment_ids =
1031 n_left_from * sizeof (fragment_ids[0]));
1033 while (n_left_from > 0)
1038 while (n_left_from > 0 && n_left_to_next > 0)
1042 u8 error0 = MAP_ERROR_NONE;
1047 pi0 = to_next[0] = from[0];
1051 n_left_to_next -= 1;
1072 error0 = MAP_ERROR_ICMP_RELAY;
1076 icmp46_header_t *icmp60 = (icmp46_header_t *) (ip60 + 1);
1079 if (inner_ip60->
protocol != IP_PROTOCOL_IP_IN_IP)
1081 error0 = MAP_ERROR_ICMP_RELAY;
1088 icmp46_header_t *new_icmp40 = (icmp46_header_t *) (new_ip40 + 1);
1093 switch (icmp60->type)
1095 case ICMP6_destination_unreachable:
1096 case ICMP6_time_exceeded:
1097 case ICMP6_parameter_problem:
1099 new_icmp40->type = ICMP4_destination_unreachable;
1101 ICMP4_destination_unreachable_destination_unreachable_host;
1104 case ICMP6_packet_too_big:
1107 mtu = clib_net_to_host_u32 (*((
u32 *) (icmp60 + 1)));
1114 error0 = MAP_ERROR_ICMP_RELAY;
1118 new_icmp40->type = ICMP4_destination_unreachable;
1120 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set;
1121 *((
u32 *) (new_icmp40 + 1)) =
1122 clib_host_to_net_u32 (mtu < 1280 ? 1280 : mtu);
1126 error0 = MAP_ERROR_ICMP_RELAY;
1135 u16 nlen = (tlen - 20) > 576 ? 576 : tlen - 20;
1136 new_ip40->
length = clib_host_to_net_u16 (nlen);
1140 new_ip40->
protocol = IP_PROTOCOL_ICMP;
1145 new_icmp40->checksum = 0;
1164 n_left_to_next, pi0, next0);
1174 #define _(sym,string) string, 1183 .vector_size =
sizeof(
u32),
1193 #ifdef MAP_SKIP_IP6_LOOKUP 1210 .name =
"ip6-map-ip6-reass",
1211 .vector_size =
sizeof(
u32),
1227 .name =
"ip6-map-ip4-reass",
1228 .vector_size =
sizeof(
u32),
1245 .name =
"ip6-map-icmp-relay",
1246 .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 void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
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 void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
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)
IPv4 to IPv6 translation.
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 u16 ip4_get_port(ip4_header_t *ip, u8 sender)
Get TCP/UDP port number or ICMP id from IPv4 packet.
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)
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)
#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)
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 uword vlib_get_thread_index(void)
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_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)
IPv6 to IPv4 translation.
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 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)