1
0
mirror of https://passt.top/passt synced 2024-10-02 03:55:48 +00:00

ndp: Always answer neighbour solicitations with the requested target address

The guest might try to resolve hosts other than the main host
namespace (i.e. the gateway) -- just recycle the target address from
the request and resolve it to the MAC address of the gateway.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-05-21 11:14:52 +02:00
parent ad4a85c860
commit 5fd6db7751

13
ndp.c
View File

@ -48,6 +48,9 @@ int ndp(struct ctx *c, struct ethhdr *eh, size_t len)
char buf[BUFSIZ] = { 0 }; char buf[BUFSIZ] = { 0 };
uint8_t proto, *p; uint8_t proto, *p;
if (len < sizeof(*ehr) + sizeof(*ip6h) + sizeof(ih))
return 0;
ih = (struct icmp6hdr *)ipv6_l4hdr(ip6h, &proto); ih = (struct icmp6hdr *)ipv6_l4hdr(ip6h, &proto);
if (!ih) if (!ih)
return -1; return -1;
@ -61,6 +64,10 @@ int ndp(struct ctx *c, struct ethhdr *eh, size_t len)
ihr = (struct icmp6hdr *)(ip6hr + 1); ihr = (struct icmp6hdr *)(ip6hr + 1);
if (ih->icmp6_type == NS) { if (ih->icmp6_type == NS) {
if (len < sizeof(*ehr) + sizeof(*ip6h) + sizeof(ih) +
sizeof(struct in6_addr))
return -1;
info("NDP: received NS, sending NA"); info("NDP: received NS, sending NA");
ihr->icmp6_type = NA; ihr->icmp6_type = NA;
ihr->icmp6_code = 0; ihr->icmp6_code = 0;
@ -69,10 +76,10 @@ int ndp(struct ctx *c, struct ethhdr *eh, size_t len)
ihr->icmp6_override = 1; ihr->icmp6_override = 1;
p = (unsigned char *)(ihr + 1); p = (unsigned char *)(ihr + 1);
memcpy(p, &c->gw6, sizeof(c->gw6)); /* target address */ memcpy(p, ih + 1, sizeof(struct in6_addr)); /* target address */
p += 16; p += 16;
*p++ = 2; /* target ll */ *p++ = 2; /* target ll */
*p++ = 1; /* length */ *p++ = 1; /* length */
memcpy(p, c->mac, ETH_ALEN); memcpy(p, c->mac, ETH_ALEN);
p += 6; p += 6;
} else if (ih->icmp6_type == RS) { } else if (ih->icmp6_type == RS) {