17 #include "../ip/ip_frag.h" 21 #ifdef MAP_SKIP_IP6_LOOKUP 94 u16 sp4 = clib_net_to_host_u16(port);
115 *error =
ip6_map_sec_check(d, port, ip4, ip6) ? MAP_ERROR_NONE : MAP_ERROR_DECAP_SEC_CHECK;
117 *error = MAP_ERROR_BAD_PROTOCOL;
129 #ifdef MAP_SKIP_IP6_LOOKUP 132 if (adj_index0 > 0) {
135 if (adj->
n_adj > 1) {
137 adj_index0 += (hash_c0 & (adj->
n_adj - 1));
154 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
163 while (n_left_from > 0) {
167 while (n_left_from >= 4 && n_left_to_next >= 2) {
170 u8 error0 = MAP_ERROR_NONE;
171 u8 error1 = MAP_ERROR_NONE;
175 u16 port0 = 0, port1 = 0;
176 u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
195 pi0 = to_next[0] = from[0];
196 pi1 = to_next[1] = from[1];
223 &map_domain_index0, &error0);
224 }
else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
225 clib_net_to_host_u16(ip60->
payload_length) >
sizeof(icmp46_header_t)) {
226 icmp46_header_t *icmp = (
void *)(ip60 + 1);
227 next0 = (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply) ?
229 }
else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION) {
232 error0 = MAP_ERROR_BAD_PROTOCOL;
236 &map_domain_index1, &error1);
237 }
else if (ip61->
protocol == IP_PROTOCOL_ICMP6 &&
238 clib_net_to_host_u16(ip61->
payload_length) >
sizeof(icmp46_header_t)) {
239 icmp46_header_t *icmp = (
void *)(ip61 + 1);
240 next1 = (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply) ?
242 }
else if (ip61->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION) {
245 error1 = MAP_ERROR_BAD_PROTOCOL;
264 clib_net_to_host_u16(ip40->
length));
283 clib_net_to_host_u16(ip41->
length));
299 if (error0 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled) {
303 ICMP6_destination_unreachable_source_address_failed_policy, 0);
309 if (error1 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled) {
313 ICMP6_destination_unreachable_source_address_failed_policy, 0);
331 while (n_left_from > 0 && n_left_to_next > 0) {
334 u8 error0 = MAP_ERROR_NONE;
339 u32 map_domain_index0 = ~0;
342 pi0 = to_next[0] = from[0];
365 &map_domain_index0, &error0);
366 }
else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
367 clib_net_to_host_u16(ip60->
payload_length) >
sizeof(icmp46_header_t)) {
368 icmp46_header_t *icmp = (
void *)(ip60 + 1);
369 next0 = (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply) ?
371 }
else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION &&
372 (((ip6_frag_hdr_t *)(ip60+1))->next_hdr == IP_PROTOCOL_IP_IN_IP)) {
375 error0 = MAP_ERROR_BAD_PROTOCOL;
394 clib_net_to_host_u16(ip40->
length));
405 (error0 == MAP_ERROR_DECAP_SEC_CHECK || error0 == MAP_ERROR_NO_DOMAIN)) {
409 ICMP6_destination_unreachable_source_address_failed_policy, 0);
431 u32 **fragments_ready,
u32 **fragments_to_drop)
435 ip6_frag_hdr_t *frag0;
451 frag0 = (ip6_frag_hdr_t *)(ip60 + 1);
459 #ifdef MAP_IP6_REASS_COUNT_BYTES 486 tr->
frag_len = clib_net_to_host_u16(ip40->
length) -
sizeof(*ip40);
499 u8 protocol = frag0->next_hdr;
500 memmove(
u8_ptr_add(ip40, -
sizeof(*ip60)), ip60,
sizeof(*ip60));
534 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
542 while (n_left_from > 0) {
546 while (n_left_from > 0 && n_left_to_next > 0) {
549 u8 error0 = MAP_ERROR_NONE;
551 ip6_frag_hdr_t *frag0;
556 pi0 = to_next[0] = from[0];
564 frag0 = (ip6_frag_hdr_t *)(ip60 + 1);
565 offset = clib_host_to_net_u16(frag0->fragment_offset_and_more) & (~7);
566 frag_len = clib_net_to_host_u16(ip60->
payload_length) -
sizeof(*frag0);
580 frag0->identification, frag0->next_hdr, &fragments_to_drop);
584 error0 = MAP_ERROR_FRAGMENT_MEMORY;
589 error0 = MAP_ERROR_FRAGMENT_MALFORMED;
592 error0 = MAP_ERROR_FRAGMENT_MEMORY;
594 #ifdef MAP_IP6_REASS_COUNT_BYTES 599 #ifdef MAP_IP6_REASS_COUNT_BYTES 606 if (error0 == MAP_ERROR_NONE) {
625 &error_node->
errors[MAP_ERROR_NONE],
628 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
644 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
650 u32 *fragments_to_loopback =
NULL;
655 while (n_left_from > 0) {
659 while (n_left_from > 0 && n_left_to_next > 0) {
662 u8 error0 = MAP_ERROR_NONE;
667 u32 map_domain_index0 = ~0;
671 pi0 = to_next[0] = from[0];
682 &map_domain_index0, &error0);
690 error0 = MAP_ERROR_FRAGMENT_MEMORY;
698 error0 = MAP_ERROR_FRAGMENT_MEMORY;
705 error0 = MAP_ERROR_BAD_PROTOCOL;
714 #ifdef MAP_IP4_REASS_COUNT_BYTES 727 error0 =
ip6_map_sec_check(d0, port0, ip40, ip60) ? MAP_ERROR_NONE : MAP_ERROR_DECAP_SEC_CHECK;
730 error0 == MAP_ERROR_NONE && !cached)) {
750 if (error0 == MAP_ERROR_NONE)
752 clib_net_to_host_u16(ip40->
length));
759 if(n_left_from == 0 &&
vec_len(fragments_to_loopback)) {
776 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
792 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
796 u16 *fragment_ids, *fid;
805 while (n_left_from > 0) {
809 while (n_left_from > 0 && n_left_to_next > 0) {
812 u8 error0 = MAP_ERROR_NONE;
817 pi0 = to_next[0] = from[0];
841 error0 = MAP_ERROR_ICMP_RELAY;
845 icmp46_header_t *icmp60 = (icmp46_header_t *)(ip60 + 1);
848 if (inner_ip60->
protocol != IP_PROTOCOL_IP_IN_IP) {
849 error0 = MAP_ERROR_ICMP_RELAY;
856 icmp46_header_t *new_icmp40 = (icmp46_header_t *)(new_ip40 + 1);
861 switch (icmp60->type) {
862 case ICMP6_destination_unreachable:
863 case ICMP6_time_exceeded:
864 case ICMP6_parameter_problem:
866 new_icmp40->type = ICMP4_destination_unreachable;
867 new_icmp40->code = ICMP4_destination_unreachable_destination_unreachable_host;
870 case ICMP6_packet_too_big:
873 mtu = clib_net_to_host_u32(*((
u32 *)(icmp60 + 1)));
877 error0 = MAP_ERROR_ICMP_RELAY;
881 new_icmp40->type = ICMP4_destination_unreachable;
882 new_icmp40->code = ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set;
883 *((
u32 *)(new_icmp40 + 1)) = clib_host_to_net_u32(mtu < 1280 ? 1280 : mtu);
887 error0 = MAP_ERROR_ICMP_RELAY;
896 u16 nlen = (tlen - 20) > 576 ? 576 : tlen - 20;
897 new_ip40->
length = clib_host_to_net_u16(nlen);
900 new_ip40->
protocol = IP_PROTOCOL_ICMP;
905 new_icmp40->checksum = 0;
930 #define _(sym,string) string, 938 .vector_size =
sizeof(
u32),
948 #ifdef MAP_SKIP_IP6_LOOKUP 963 .name =
"ip6-map-ip6-reass",
964 .vector_size =
sizeof(
u32),
978 .name =
"ip6-map-ip4-reass",
979 .vector_size =
sizeof(
u32),
994 .name =
"ip6-map-icmp-relay",
995 .vector_size =
sizeof(
u32),
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
#define map_ip4_reass_lock()
always_inline void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
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)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
always_inline int ip4_get_fragment_offset(ip4_header_t *i)
static vlib_node_registration_t ip6_map_icmp_relay_node
(constructor) VLIB_REGISTER_NODE (ip6_map_icmp_relay_node)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct _vlib_node_registration vlib_node_registration_t
ip_lookup_main_t lookup_main
always_inline int ip4_is_fragment(ip4_header_t *i)
static char * map_error_strings[]
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)
always_inline void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
always_inline vlib_main_t * vlib_get_main(void)
vlib_node_registration_t ip6_map_node
(constructor) VLIB_REGISTER_NODE (ip6_map_node)
always_inline int ip4_get_fragment_more(ip4_header_t *i)
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
always_inline void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u32 packet_increment, u32 byte_increment)
ip4_address_t icmp4_src_address
vlib_node_registration_t ip6_map_ip6_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_map_ip6_reass_node)
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)
always_inline void * vlib_frame_vector_args(vlib_frame_t *f)
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)
#define ip6_frag_hdr_more(hdr)
always_inline u16 ip_csum_fold(ip_csum_t c)
u16 current_length
Nbytes between current data and the end of this buffer.
always_inline void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 cpu_index, u32 index, u32 increment)
uword os_get_cpu_number(void)
static_always_inline map_domain_t * ip6_map_get_domain(u32 adj_index, ip4_address_t *addr, u32 *map_domain_index, u8 *error)
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)
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
always_inline u16 ip4_header_checksum(ip4_header_t *i)
void map_ip4_drop_pi(u32 pi)
u16 ip4_map_get_port(ip4_header_t *ip, map_dir_e dir)
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).
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)
#define u8_ptr_add(ptr, index)
static_always_inline bool ip6_map_ip4_lookup_bypass(vlib_buffer_t *p0, ip4_header_t *ip)
#define map_ip4_reass_unlock()
u8 * format_map_trace(u8 *s, va_list *args)
#define IP_FLOW_HASH_DEFAULT
u8 * format_ip6_map_ip6_reass_trace(u8 *s, va_list *args)
#define VLIB_BUFFER_IS_TRACED
always_inline ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
static uword ip6_map_ip6_reass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
always_inline void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
#define map_ip6_reass_lock()
always_inline u32 ip4_compute_flow_hash(ip4_header_t *ip, u32 flow_hash_config)
always_inline void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
always_inline void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
void map_ip6_reass_free(map_ip6_reass_t *r, u32 **pi_to_drop)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#define VLIB_REGISTER_NODE(x,...)
always_inline vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
#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.
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
clib_random_buffer_t random_buffer
void map_ip6_drop_pi(u32 pi)