summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenda Xu <heroxbd@gentoo.org>2018-12-28 00:00:00 +0000
committerBarak A. Pearlmutter <bap@debian.org>2019-02-12 16:18:44 +0100
commitf770e262f81b702451b6ed0aebbdd9206067d849 (patch)
tree096d3af982455468221f98e703d2a1149b3e3eac
parenteb356eaec969eca5e81a27178600ff408efea71b (diff)
static EAM
Support SIIT-DC styled EAM static maps Introduce Explicit Address Mapping as defined in RFC7757. This extends the `map <ipv4> <ipv6>` into `map <ipv4 subnet> <ipv6 subnet>`. Forwarded: Nathan Lutchansky <lutchann@litech.org> Gbp-Pq: Name 07-static-EAM.patch
-rw-r--r--addrmap.c18
-rw-r--r--conffile.c40
2 files changed, 54 insertions, 4 deletions
diff --git a/addrmap.c b/addrmap.c
index 7a4bf8b..895c3fc 100644
--- a/addrmap.c
+++ b/addrmap.c
@@ -422,6 +422,9 @@ int map_ip4_to_ip6(struct in6_addr *addr6, const struct in_addr *addr4,
case MAP_TYPE_STATIC:
s = container_of(map4, struct map_static, map4);
*addr6 = s->map6.addr;
+ if (map4->prefix_len < 32) {
+ addr6->s6_addr32[3] = s->map6.addr.s6_addr32[3] | (addr4->s_addr & ~map4->mask.s_addr);
+ }
break;
case MAP_TYPE_RFC6052:
s = container_of(map4, struct map_static, map4);
@@ -564,7 +567,13 @@ int map_ip6_to_ip4(struct in_addr *addr4, const struct in6_addr *addr6,
switch (map6->type) {
case MAP_TYPE_STATIC:
s = container_of(map6, struct map_static, map6);
- *addr4 = s->map4.addr;
+
+ if (map6->prefix_len < 128) {
+ addr4->s_addr = s->map4.addr.s_addr | (addr6->s6_addr32[3] & ~map6->mask.s6_addr32[3]);
+ } else {
+ *addr4 = s->map4.addr;
+ }
+
break;
case MAP_TYPE_RFC6052:
if (extract_from_prefix(addr4, addr6, map6->prefix_len) < 0)
@@ -629,3 +638,10 @@ void addrmap_maint(void)
}
}
}
+
+/*
+Local Variables:
+c-basic-offset: 8
+indent-tabs-mode: t
+End:
+*/
diff --git a/conffile.c b/conffile.c
index ec6433c..1c77371 100644
--- a/conffile.c
+++ b/conffile.c
@@ -217,16 +217,43 @@ static void config_map(int ln, int arg_count, char **args)
m = alloc_map_static(ln);
+ char *slash;
+ slash = strchr(args[0], '/');
+ unsigned int prefix4 = 32;
+ if (slash) {
+ prefix4 = atoi(slash+1);
+ slash[0] = NULL;
+ }
+
if (!inet_pton(AF_INET, args[0], &m->map4.addr)) {
- slog(LOG_CRIT, "Expected an IPv4 address but found \"%s\" on "
- "line %d\n", args[0], ln);
+ slog(LOG_CRIT, "Expected an IPv4 subnet but found \"%s\" on "
+ "line %d\n", args[0], ln);
exit(1);
}
+ m->map4.prefix_len = prefix4;
+ calc_ip4_mask(&m->map4.mask, NULL, prefix4);
+
+ unsigned int prefix6 = 128;
+ slash = strchr(args[1], '/');
+ if (slash) {
+ prefix6 = atoi(slash+1);
+ slash[0] = NULL;
+ }
+
+ if ((32 - prefix4) != (128 - prefix6)) {
+ slog(LOG_CRIT, "IPv4 and IPv6 subnet must be of the same size, but found"
+ " %s and %s line %d\n", args[0], args[1], ln);
+ exit(1);
+ }
+
if (!inet_pton(AF_INET6, args[1], &m->map6.addr)) {
- slog(LOG_CRIT, "Expected an IPv6 address but found \"%s\" on "
+ slog(LOG_CRIT, "Expected an IPv6 subnet but found \"%s\" on "
"line %d\n", args[1], ln);
exit(1);
}
+ m->map6.prefix_len = prefix6;
+ calc_ip6_mask(&m->map6.mask, NULL, prefix6);
+
if (validate_ip4_addr(&m->map4.addr) < 0) {
slog(LOG_CRIT, "Cannot use reserved address %s in map "
"directive, aborting...\n", args[0]);
@@ -490,3 +517,10 @@ malloc_fail:
slog(LOG_CRIT, "Unable to allocate config memory\n");
exit(1);
}
+
+/*
+Local Variables:
+c-basic-offset: 8
+indent-tabs-mode: t
+End:
+*/