17 #include "../ip/ip_frag.h" 20 #define IP4_MAP_T_DUAL_LOOP 1 64 }) ip4_mapt_pseudo_header_t;
77 IP_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP6 : ip4->
protocol,
95 IP_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP6 : ip4->
protocol,
143 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
152 while (n_left_from > 0)
156 while (n_left_from > 0 && n_left_to_next > 0)
160 ip4_mapt_icmp_next_t next0;
168 pi0 = to_next[0] = from[0];
173 error0 = MAP_ERROR_NONE;
192 error0 = MAP_ERROR_ICMP;
201 error0 = MAP_ERROR_ICMP;
218 map_t.map_domain_index, 1,
227 to_next, n_left_to_next, pi0,
238 ip4_mapt_pseudo_header_t *pheader =
ctx;
252 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
259 while (n_left_from > 0)
263 while (n_left_from > 0 && n_left_to_next > 0)
267 ip4_mapt_pseudo_header_t *pheader0;
268 ip4_mapt_fragmented_next_t next0;
271 pi0 = to_next[0] = from[0];
285 p0->
error = error_node->
errors[MAP_ERROR_FRAGMENT_DROPPED];
301 to_next, n_left_to_next, pi0,
313 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
321 while (n_left_from > 0)
325 #ifdef IP4_MAP_T_DUAL_LOOP 326 while (n_left_from >= 4 && n_left_to_next >= 2)
330 ip4_mapt_pseudo_header_t *pheader0, *pheader1;
331 ip4_mapt_tcp_udp_next_t next0, next1;
333 pi0 = to_next[0] = from[0];
334 pi1 = to_next[1] = from[1];
388 to_next, n_left_to_next, pi0, pi1,
393 while (n_left_from > 0 && n_left_to_next > 0)
397 ip4_mapt_pseudo_header_t *pheader0;
398 ip4_mapt_tcp_udp_next_t next0;
400 pi0 = to_next[0] = from[0];
431 to_next, n_left_to_next, pi0,
443 u8 * error0, ip4_mapt_next_t * next0)
455 *error0 = (*dst_port0 == -1) ? MAP_ERROR_FRAGMENT_MEMORY : *error0;
462 *error0 = ip4_len0 < 40 ? MAP_ERROR_MALFORMED : *error0;
469 *error0 = ip4_len0 < 28 ? MAP_ERROR_MALFORMED : *error0;
472 else if (ip40->
protocol == IP_PROTOCOL_ICMP)
477 else if (((icmp46_header_t *)
u8_ptr_add (ip40,
sizeof (*ip40)))->code
479 || ((icmp46_header_t *)
481 sizeof (*ip40)))->code == ICMP4_echo_request)
486 *error0 = MAP_ERROR_BAD_PROTOCOL;
493 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
502 while (n_left_from > 0)
506 #ifdef IP4_MAP_T_DUAL_LOOP 507 while (n_left_from >= 4 && n_left_to_next >= 2)
513 ip4_mapt_next_t next0 = 0, next1 = 0;
514 u16 ip4_len0, ip4_len1;
516 i32 dst_port0, dst_port1;
517 ip4_mapt_pseudo_header_t *pheader0, *pheader1;
519 pi0 = to_next[0] = from[0];
520 pi1 = to_next[1] = from[1];
525 error0 = MAP_ERROR_NONE;
526 error1 = MAP_ERROR_NONE;
532 ip4_len0 = clib_host_to_net_u16 (ip40->
length);
533 ip4_len1 = clib_host_to_net_u16 (ip41->
length);
538 error0 = MAP_ERROR_UNKNOWN;
545 error1 = MAP_ERROR_UNKNOWN;
578 pheader0->daddr.as_u64[0] =
580 pheader0->daddr.as_u64[1] =
582 pheader1->daddr.as_u64[0] =
584 pheader1->daddr.as_u64[1] =
590 && ip4_map_fragment_cache (ip40, dst_port0)))
592 error0 = MAP_ERROR_FRAGMENT_MEMORY;
598 && ip4_map_fragment_cache (ip41, dst_port1)))
600 error1 = MAP_ERROR_FRAGMENT_MEMORY;
609 map_t.map_domain_index, 1,
620 map_t.map_domain_index, 1,
630 n_left_to_next, pi0, pi1, next0,
635 while (n_left_from > 0 && n_left_to_next > 0)
641 ip4_mapt_next_t next0;
645 ip4_mapt_pseudo_header_t *pheader0;
647 pi0 = to_next[0] = from[0];
652 error0 = MAP_ERROR_NONE;
656 ip4_len0 = clib_host_to_net_u16 (ip40->
length);
660 error0 = MAP_ERROR_UNKNOWN;
681 pheader0->daddr.as_u64[0] =
683 pheader0->daddr.as_u64[1] =
692 && ip4_map_fragment_cache (ip40, dst_port0)))
694 error0 = MAP_ERROR_UNKNOWN;
703 map_t.map_domain_index, 1,
711 to_next, n_left_to_next, pi0,
719 static char *map_t_error_strings[] = {
720 #define _(sym,string) string, 728 .name =
"ip4-map-t-fragmented",
729 .vector_size =
sizeof(
u32),
734 .error_strings = map_t_error_strings,
748 .name =
"ip4-map-t-icmp",
749 .vector_size =
sizeof(
u32),
754 .error_strings = map_t_error_strings,
768 .name =
"ip4-map-t-tcp-udp",
769 .vector_size =
sizeof(
u32),
774 .error_strings = map_t_error_strings,
789 .vector_size =
sizeof(
u32),
794 .error_strings = map_t_error_strings,
#define map_ip4_reass_lock()
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.
#define IP6_FRAG_NODE_NAME
static_always_inline void ip4_map_t_classify(vlib_buffer_t *p0, map_domain_t *d0, ip4_header_t *ip40, u16 ip4_len0, i32 *dst_port0, u8 *error0, ip4_mapt_next_t *next0)
static_always_inline i32 ip4_map_fragment_get_port(ip4_header_t *ip4)
vlib_error_t * errors
Vector of errors for this node.
IPv4 to IPv6 translation.
static uword ip4_map_t_icmp(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static int ip4_to_ip6_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *ctx)
static uword ip4_map_t(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline void ip4_map_t_embedded_address(map_domain_t *d, ip6_address_t *ip6, const ip4_address_t *ip4)
#define static_always_inline
vlib_combined_counter_main_t * domain_counters
ip4_mapt_fragmented_next_t
static int ip4_get_fragment_offset(ip4_header_t *i)
static u16 ip4_get_port(ip4_header_t *ip, u8 sender)
Get TCP/UDP port number or ICMP id from IPv4 packet.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
static_always_inline u64 map_get_pfx_net(map_domain_t *d, u32 addr, u16 port)
static_always_inline u64 map_get_sfx_net(map_domain_t *d, u32 addr, u16 port)
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)
static_always_inline map_domain_t * ip4_map_get_domain(u32 mdi)
#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.
static_always_inline uword vlib_get_thread_index(void)
static int ip4_to_ip6_tcp_udp(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx)
Translate IPv4 UDP/TCP packet to IPv6.
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
static int ip4_is_first_fragment(ip4_header_t *i)
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 foreach_map_error
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 int ip4_to_ip6_set_inner_icmp_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
static int icmp_to_icmp6(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx, ip4_to_ip6_set_fn_t inner_fn, void *inner_ctx)
Translate ICMP4 packet to ICMP6.
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()
u8 * format_map_trace(u8 *s, va_list *args)
static int ip4_to_ip6_set_icmp_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
static uword ip4_map_t_tcp_udp(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static uword ip4_map_t_fragmented(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static int ip4_to_ip6_fragmented(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx)
Translate IPv4 fragmented packet to IPv6.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
A collection of combined counters.
#define VLIB_REGISTER_NODE(x,...)
typedef CLIB_PACKED(struct{ip6_address_t daddr;ip6_address_t saddr;u8 unused[28];})
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.