From 4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 13 Apr 2021 21:59:47 +0200 Subject: passt: Introduce a DHCPv6 server This implementation, similarly to the IPv4 DHCP one, hands out a single address, which is the same as the upstream address for the host. This avoids the need for address translation as long as the client runs a DHCPv6 client. The NDP "Managed" flag is now set in Router Advertisements. Signed-off-by: Stefano Brivio --- passt.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index 8bc7098..ed8b251 100644 --- a/passt.c +++ b/passt.c @@ -47,6 +47,7 @@ #include "arp.h" #include "dhcp.h" #include "ndp.h" +#include "dhcpv6.h" #include "util.h" #include "icmp.h" #include "tcp.h" @@ -308,6 +309,9 @@ static void tap4_handler(struct ctx *c, char *in, size_t len) char buf_d[BUFSIZ] __attribute((__unused__)); char *l4h; + if (!c->v4) + return; + if (arp(c, eh, len) || dhcp(c, eh, len)) return; @@ -358,17 +362,17 @@ static void tap6_handler(struct ctx *c, char *in, size_t len) uint8_t proto; char *l4h; + if (!c->v6) + return; + if (len < sizeof(*eh) + sizeof(*ip6h)) return; - if (ndp(c, eh, len)) + if (ndp(c, eh, len) || dhcpv6(c, eh, len)) return; l4h = ipv6_l4hdr(ip6h, &proto); - /* TODO: Assign MAC address to guest so that, together with prefix - * assigned via NDP, address matches the one from the host. - */ c->addr6_guest = ip6h->saddr; ip6h->saddr = c->addr6; @@ -559,6 +563,9 @@ int main(int argc, char **argv) if (icmp_sock_init(&c) || tcp_sock_init(&c) || udp_sock_init(&c)) exit(EXIT_FAILURE); + if (c.v6) + dhcpv6_init(&c); + if (c.v4) { info("ARP:"); info(" address: %02x:%02x:%02x:%02x:%02x:%02x from %s", @@ -575,7 +582,7 @@ int main(int argc, char **argv) inet_ntop(AF_INET, &c.dns4, buf4[3], sizeof(buf4[3]))); } if (c.v6) { - info("NDP:"); + info("NDP/DHCPv6:"); info(" assign: %s", inet_ntop(AF_INET6, &c.addr6, buf6[0], sizeof(buf6[0]))); info(" router: %s", -- cgit v1.2.3