diff options
author | Matus Fabian <matfabia@cisco.com> | 2017-06-21 06:15:18 -0700 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2017-06-21 16:27:41 +0000 |
commit | 428dc9110bee7eedf8aac6f12a89181e8e5343f5 (patch) | |
tree | a24e6acb6db074054286f18dd11ac96df96c2832 /src/plugins/snat/nat64_out2in.c | |
parent | 793fe2179c2403af330409f7e7d34bb0f7910b99 (diff) |
NAT64: custom prefix
Change-Id: If397b49861468eed29b964fa64b186f80eb0eceb
Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'src/plugins/snat/nat64_out2in.c')
-rw-r--r-- | src/plugins/snat/nat64_out2in.c | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/src/plugins/snat/nat64_out2in.c b/src/plugins/snat/nat64_out2in.c index 0a5fbe5b357..755aa638aa5 100644 --- a/src/plugins/snat/nat64_out2in.c +++ b/src/plugins/snat/nat64_out2in.c @@ -21,15 +21,6 @@ #include <vnet/ip/ip4_to_ip6.h> #include <vnet/fib/ip4_fib.h> -/* *INDENT-OFF* */ -static u8 well_known_prefix[] = { - 0x00, 0x64, 0xff, 0x9b, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 -}; -/* *INDENT-ON* */ - typedef struct { u32 sw_if_index; @@ -112,9 +103,6 @@ nat64_out2in_tcp_udp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, memset (&daddr, 0, sizeof (daddr)); daddr.ip4.as_u32 = ip4->dst_address.as_u32; - memcpy (&ip6_saddr, well_known_prefix, sizeof (ip6_saddr)); - ip6_saddr.as_u32[3] = ip4->src_address.as_u32; - ste = nat64_db_st_entry_find (&nm->db, &daddr, &saddr, dport, sport, proto, fib_index, 0); @@ -132,6 +120,7 @@ nat64_out2in_tcp_udp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, if (!bibe) return -1; + nat64_compose_ip6 (&ip6_saddr, &ip4->src_address, bibe->fib_index); ste = nat64_db_st_entry_create (&nm->db, bibe, &ip6_saddr, &saddr.ip4, sport); @@ -139,8 +128,8 @@ nat64_out2in_tcp_udp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, nat64_session_reset_timeout (ste, ctx->vm); - ip6->src_address.as_u64[0] = ip6_saddr.as_u64[0]; - ip6->src_address.as_u64[1] = ip6_saddr.as_u64[1]; + ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0]; + ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1]; ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0]; ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1]; @@ -179,9 +168,6 @@ nat64_out2in_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, void *arg) memset (&daddr, 0, sizeof (daddr)); daddr.ip4.as_u32 = ip4->dst_address.as_u32; - memcpy (&ip6_saddr, well_known_prefix, sizeof (ip6_saddr)); - ip6_saddr.as_u32[3] = ip4->src_address.as_u32; - if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply) { u16 out_id = ((u16 *) (icmp))[2]; @@ -205,6 +191,7 @@ nat64_out2in_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, void *arg) if (!bibe) return -1; + nat64_compose_ip6 (&ip6_saddr, &ip4->src_address, bibe->fib_index); ste = nat64_db_st_entry_create (&nm->db, bibe, &ip6_saddr, &saddr.ip4, 0); @@ -212,8 +199,8 @@ nat64_out2in_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, void *arg) nat64_session_reset_timeout (ste, ctx->vm); - ip6->src_address.as_u64[0] = ip6_saddr.as_u64[0]; - ip6->src_address.as_u64[1] = ip6_saddr.as_u64[1]; + ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0]; + ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1]; ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0]; ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1]; @@ -225,8 +212,8 @@ nat64_out2in_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, void *arg) { ip6_header_t *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8); - ip6->src_address.as_u64[0] = ip6_saddr.as_u64[0]; - ip6->src_address.as_u64[1] = ip6_saddr.as_u64[1]; + nat64_compose_ip6 (&ip6->src_address, &ip4->src_address, + vnet_buffer (ctx->b)->sw_if_index[VLIB_TX]); ip6->dst_address.as_u64[0] = inner_ip6->src_address.as_u64[0]; ip6->dst_address.as_u64[1] = inner_ip6->src_address.as_u64[1]; } @@ -243,7 +230,6 @@ nat64_out2in_inner_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, nat64_db_bib_entry_t *bibe; nat64_db_st_entry_t *ste; ip46_address_t saddr, daddr; - ip6_address_t ip6_daddr; u32 sw_if_index, fib_index; snat_protocol_t proto = ip_proto_to_snat_proto (ip4->protocol); @@ -256,9 +242,6 @@ nat64_out2in_inner_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, memset (&daddr, 0, sizeof (daddr)); daddr.ip4.as_u32 = ip4->dst_address.as_u32; - memcpy (&ip6_daddr, well_known_prefix, sizeof (ip6_daddr)); - ip6_daddr.as_u32[3] = ip4->dst_address.as_u32; - if (proto == SNAT_PROTOCOL_ICMP) { icmp46_header_t *icmp = ip4_next_header (ip4); @@ -279,8 +262,8 @@ nat64_out2in_inner_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, if (!bibe) return -1; - ip6->dst_address.as_u64[0] = ip6_daddr.as_u64[0]; - ip6->dst_address.as_u64[1] = ip6_daddr.as_u64[1]; + ip6->dst_address.as_u64[0] = ste->in_r_addr.as_u64[0]; + ip6->dst_address.as_u64[1] = ste->in_r_addr.as_u64[1]; ip6->src_address.as_u64[0] = bibe->in_addr.as_u64[0]; ip6->src_address.as_u64[1] = bibe->in_addr.as_u64[1]; ((u16 *) (icmp))[2] = bibe->in_port; @@ -306,8 +289,7 @@ nat64_out2in_inner_icmp_set_cb (ip4_header_t * ip4, ip6_header_t * ip6, if (!bibe) return -1; - ip6->dst_address.as_u64[0] = ip6_daddr.as_u64[0]; - ip6->dst_address.as_u64[1] = ip6_daddr.as_u64[1]; + nat64_compose_ip6 (&ip6->dst_address, &daddr.ip4, bibe->fib_index); ip6->src_address.as_u64[0] = bibe->in_addr.as_u64[0]; ip6->src_address.as_u64[1] = bibe->in_addr.as_u64[1]; udp->src_port = bibe->in_port; |