aboutgitcodebugslistschat
path: root/passt.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-04-13 21:59:47 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-04-13 22:37:40 +0200
commit4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01 (patch)
tree86557a9f4ec49b64e72379de5beff1248ba2404c /passt.c
parent6b1a9f0d34069c218bdfa666a1f11dfcdf2b85cd (diff)
downloadpasst-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.tar
passt-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.tar.gz
passt-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.tar.bz2
passt-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.tar.lz
passt-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.tar.xz
passt-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.tar.zst
passt-4aa8e54a303dfde9a53c47cd07c5af3c5fad4f01.zip
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 <sbrivio@redhat.com>
Diffstat (limited to 'passt.c')
-rw-r--r--passt.c17
1 files changed, 12 insertions, 5 deletions
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",