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 163 adj_index0 += (hash_c0 & (adj->
n_adj - 1));
178 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
188 while (n_left_from > 0)
193 while (n_left_from >= 4 && n_left_to_next >= 2)
197 u8 error0 = MAP_ERROR_NONE;
198 u8 error1 = MAP_ERROR_NONE;
202 u16 port0 = 0, port1 = 0;
203 u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
222 pi0 = to_next[0] = from[0];
223 pi1 = to_next[1] = from[1];
249 (ip60->
protocol == IP_PROTOCOL_IP_IN_IP
255 as_u32, &map_domain_index0, &error0);
257 else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
259 sizeof (icmp46_header_t))
261 icmp46_header_t *icmp = (
void *) (ip60 + 1);
262 next0 = (icmp->type == ICMP6_echo_request
267 else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
273 error0 = MAP_ERROR_BAD_PROTOCOL;
276 (ip61->
protocol == IP_PROTOCOL_IP_IN_IP
282 as_u32, &map_domain_index1, &error1);
284 else if (ip61->
protocol == IP_PROTOCOL_ICMP6 &&
286 sizeof (icmp46_header_t))
288 icmp46_header_t *icmp = (
void *) (ip61 + 1);
289 next1 = (icmp->type == ICMP6_echo_request
294 else if (ip61->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
300 error1 = MAP_ERROR_BAD_PROTOCOL;
313 && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)))
331 map_domain_index0, 1,
346 && (clib_host_to_net_u16 (ip41->
length) > d1->mtu)))
364 map_domain_index1, 1,
384 if (error0 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled)
389 ICMP6_destination_unreachable_source_address_failed_policy,
398 if (error1 == MAP_ERROR_DECAP_SEC_CHECK && mm->
icmp6_enabled)
403 ICMP6_destination_unreachable_source_address_failed_policy,
421 n_left_to_next, pi0, pi1, next0,
426 while (n_left_from > 0 && n_left_to_next > 0)
430 u8 error0 = MAP_ERROR_NONE;
435 u32 map_domain_index0 = ~0;
438 pi0 = to_next[0] = from[0];
460 (ip60->
protocol == IP_PROTOCOL_IP_IN_IP
466 as_u32, &map_domain_index0, &error0);
468 else if (ip60->
protocol == IP_PROTOCOL_ICMP6 &&
470 sizeof (icmp46_header_t))
472 icmp46_header_t *icmp = (
void *) (ip60 + 1);
473 next0 = (icmp->type == ICMP6_echo_request
478 else if (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION &&
479 (((ip6_frag_hdr_t *) (ip60 + 1))->next_hdr ==
480 IP_PROTOCOL_IP_IN_IP))
486 error0 = MAP_ERROR_BAD_PROTOCOL;
499 && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)))
517 map_domain_index0, 1,
531 (error0 == MAP_ERROR_DECAP_SEC_CHECK
532 || error0 == MAP_ERROR_NO_DOMAIN))
537 ICMP6_destination_unreachable_source_address_failed_policy,
552 n_left_to_next, pi0, next0);
564 u32 ** fragments_to_drop)
568 ip6_frag_hdr_t *frag0;
586 frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
595 #ifdef MAP_IP6_REASS_COUNT_BYTES 636 tr->
frag_len = clib_net_to_host_u16 (ip40->
length) -
sizeof (*ip40);
649 u8 protocol = frag0->next_hdr;
650 memmove (
u8_ptr_add (ip40, -
sizeof (*ip60)), ip60,
sizeof (*ip60));
686 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
695 while (n_left_from > 0)
700 while (n_left_from > 0 && n_left_to_next > 0)
704 u8 error0 = MAP_ERROR_NONE;
706 ip6_frag_hdr_t *frag0;
711 pi0 = to_next[0] = from[0];
719 frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
721 clib_host_to_net_u16 (frag0->fragment_offset_and_more) & (~7);
741 frag0->identification, frag0->next_hdr,
747 error0 = MAP_ERROR_FRAGMENT_MEMORY;
754 error0 = MAP_ERROR_FRAGMENT_MALFORMED;
758 (r, pi0, offset, next_offset, (
u8 *) (frag0 + 1), frag_len))
761 error0 = MAP_ERROR_FRAGMENT_MEMORY;
765 #ifdef MAP_IP6_REASS_COUNT_BYTES 771 #ifdef MAP_IP6_REASS_COUNT_BYTES 778 if (error0 == MAP_ERROR_NONE)
791 to_next, n_left_to_next,
808 &error_node->
errors[MAP_ERROR_NONE],
811 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
826 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
833 u32 *fragments_to_loopback =
NULL;
838 while (n_left_from > 0)
843 while (n_left_from > 0 && n_left_to_next > 0)
847 u8 error0 = MAP_ERROR_NONE;
852 u32 map_domain_index0 = ~0;
856 pi0 = to_next[0] = from[0];
869 &map_domain_index0, &error0);
881 error0 = MAP_ERROR_FRAGMENT_MEMORY;
894 error0 = MAP_ERROR_FRAGMENT_MEMORY;
907 error0 = MAP_ERROR_BAD_PROTOCOL;
918 #ifdef MAP_IP4_REASS_COUNT_BYTES 925 clib_host_to_net_u16 (ip40->
length) - 20;
936 ip60) ? MAP_ERROR_NONE :
937 MAP_ERROR_DECAP_SEC_CHECK;
940 (d0->
mtu && (clib_host_to_net_u16 (ip40->
length) > d0->
mtu)
941 && error0 == MAP_ERROR_NONE && !cached))
967 if (error0 == MAP_ERROR_NONE)
969 cpu_index, map_domain_index0,
978 n_left_to_next, pi0, next0);
982 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
996 fragments_to_loopback + (len -
1007 &error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED],
1022 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
1027 u16 *fragment_ids, *fid;
1034 fid = fragment_ids =
1036 n_left_from * sizeof (fragment_ids[0]));
1038 while (n_left_from > 0)
1043 while (n_left_from > 0 && n_left_to_next > 0)
1047 u8 error0 = MAP_ERROR_NONE;
1052 pi0 = to_next[0] = from[0];
1056 n_left_to_next -= 1;
1077 error0 = MAP_ERROR_ICMP_RELAY;
1081 icmp46_header_t *icmp60 = (icmp46_header_t *) (ip60 + 1);
1084 if (inner_ip60->
protocol != IP_PROTOCOL_IP_IN_IP)
1086 error0 = MAP_ERROR_ICMP_RELAY;
1093 icmp46_header_t *new_icmp40 = (icmp46_header_t *) (new_ip40 + 1);
1098 switch (icmp60->type)
1100 case ICMP6_destination_unreachable:
1101 case ICMP6_time_exceeded:
1102 case ICMP6_parameter_problem:
1104 new_icmp40->type = ICMP4_destination_unreachable;
1106 ICMP4_destination_unreachable_destination_unreachable_host;
1109 case ICMP6_packet_too_big:
1112 mtu = clib_net_to_host_u32 (*((
u32 *) (icmp60 + 1)));
1119 error0 = MAP_ERROR_ICMP_RELAY;
1123 new_icmp40->type = ICMP4_destination_unreachable;
1125 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set;
1126 *((
u32 *) (new_icmp40 + 1)) =
1127 clib_host_to_net_u32 (mtu < 1280 ? 1280 : mtu);
1131 error0 = MAP_ERROR_ICMP_RELAY;
1140 u16 nlen = (tlen - 20) > 576 ? 576 : tlen - 20;
1141 new_ip40->
length = clib_host_to_net_u16 (nlen);
1145 new_ip40->
protocol = IP_PROTOCOL_ICMP;
1150 new_icmp40->checksum = 0;
1168 n_left_to_next, pi0, next0);
1178 #define _(sym,string) string, 1187 .vector_size =
sizeof(
u32),
1197 #ifdef MAP_SKIP_IP6_LOOKUP 1214 .name =
"ip6-map-ip6-reass",
1215 .vector_size =
sizeof(
u32),
1231 .name =
"ip6-map-ip4-reass",
1232 .vector_size =
sizeof(
u32),
1249 .name =
"ip6-map-icmp-relay",
1250 .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)
Release pointer to next frame vector data.
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 cpu_index, u32 index, u32 increment)
Increment a simple counter.
#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 vlib_main_t * vlib_get_main(void)
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
static void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
#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
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)
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)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
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)
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)
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)
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 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 void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
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)
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u32 packet_increment, u32 byte_increment)
Increment a combined counter.
#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()
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)
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple without the "reverse" bit.
static int ip4_get_fragment_more(ip4_header_t *i)
u8 * format_ip6_map_ip6_reass_trace(u8 *s, va_list *args)
#define VLIB_BUFFER_IS_TRACED
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u16 n_adj
Number of adjecencies in block.
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)
#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_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#define VLIB_REGISTER_NODE(x,...)
ip4_main_t ip4_main
Global ip4 main structure.
#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)
static ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)