summaryrefslogtreecommitdiffstats
path: root/src/plugins/map/ip6_map_t.c
diff options
context:
space:
mode:
authorJon Loeliger <jdl@netgate.com>2020-01-28 07:30:28 -0600
committerOle Trøan <otroan@employees.org>2020-01-30 11:05:35 +0000
commit65866f03d96bd41b99b1c823ea6f38cd77fac58c (patch)
treea1c63ac21b3549ba0160e313ecee6bc275ec71c0 /src/plugins/map/ip6_map_t.c
parent56817e2c486a26167783676774b0dea9c103b200 (diff)
map: Prevent IPv4 prefix spoofing during IPv6 -> IPv4
Prevent malicious packets with spoofed embedded IPv4 addresses by limiting the IPv6 ingress packets to known MAP-T domains. Drop spoofed packets. Add several tests that ensure spoofing isn't allowed. Type: fix Fixes: fc7344f9be Change-Id: I80a5dd10d5fe7492e3a1b04de389d649a78065e2 Signed-off-by: Jon Loeliger <jdl@netgate.com>
Diffstat (limited to 'src/plugins/map/ip6_map_t.c')
-rw-r--r--src/plugins/map/ip6_map_t.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/map/ip6_map_t.c b/src/plugins/map/ip6_map_t.c
index 95104dc78f4..e205c60e29a 100644
--- a/src/plugins/map/ip6_map_t.c
+++ b/src/plugins/map/ip6_map_t.c
@@ -66,7 +66,7 @@ ip6_to_ip4_set_icmp_cb (ip6_header_t * ip6, ip4_header_t * ip4, void *arg)
// Security check
// Note that this prevents an intermediate IPv6 router from answering
// the request.
- ip4_sadr = map_get_ip4 (&ip6->src_address, ctx->d->flags);
+ ip4_sadr = map_get_ip4 (&ip6->src_address, ctx->d->ip6_src_len);
if (ip6->src_address.as_u64[0] !=
map_get_pfx_net (ctx->d, ip4_sadr, ctx->sender_port)
|| ip6->src_address.as_u64[1] != map_get_sfx_net (ctx->d, ip4_sadr,
@@ -88,7 +88,7 @@ ip6_to_ip4_set_inner_icmp_cb (ip6_header_t * ip6, ip4_header_t * ip4,
u32 inner_ip4_dadr;
//Security check of inner packet
- inner_ip4_dadr = map_get_ip4 (&ip6->dst_address, ctx->d->flags);
+ inner_ip4_dadr = map_get_ip4 (&ip6->dst_address, ctx->d->ip6_src_len);
if (ip6->dst_address.as_u64[0] !=
map_get_pfx_net (ctx->d, inner_ip4_dadr, ctx->sender_port)
|| ip6->dst_address.as_u64[1] != map_get_sfx_net (ctx->d,
@@ -305,6 +305,8 @@ ip6_map_t_fragmented (vlib_main_t * vm,
/*
* Translate IPv6 UDP/TCP packet to IPv4.
+ * Returns 0 on success.
+ * Returns a non-zero error code on error.
*/
always_inline int
map_ip6_to_ip4_tcp_udp (vlib_main_t * vm, vlib_buffer_t * p,
@@ -370,6 +372,16 @@ map_ip6_to_ip4_tcp_udp (vlib_main_t * vm, vlib_buffer_t * p,
ip4->dst_address.as_u32 = vnet_buffer (p)->map_t.v6.daddr;
ip4->src_address.as_u32 = vnet_buffer (p)->map_t.v6.saddr;
+ /*
+ * Drop spoofed packets that from a known domain source.
+ */
+ u32 map_domain_index = -1;
+ u8 error = 0;
+
+ ip4_map_get_domain (&ip4->src_address, &map_domain_index, &error);
+ if (error)
+ return error;
+
ip4->ip_version_and_header_length =
IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
ip4->tos = ip6_translate_tos (ip6->ip_version_traffic_class_and_flow_label);