Initialize host side MAC when in IPv6 only mode

When sending packets to the guest we need a source MAC address, which we
currently take from the host side interface we're using (though it's
basically arbitrary).  However if not given on the command line this MAC
is initialized in an IPv4 specific path, and will end up as
00:00:00:00:00:00 when running "passt 6".  The MAC address is also used
for IPv6 packets, though.

Interestingly, we largely seem to get away with using an all-zero MAC, but
it's probably not a good idea.  Make the IPv6 path pick the MAC address
from its interface if the IPv4 path hasn't already done so.

While we're there, use the existing MAC_IS_ZERO macro to make the code a
little clearer.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2022-07-22 15:31:14 +10:00 committed by Stefano Brivio
parent 06abfcf6d9
commit 3f19072640

17
conf.c
View file

@ -672,7 +672,7 @@ static void conf_ip(struct ctx *c)
memcpy(&c->addr4_seen, &c->addr4, sizeof(c->addr4_seen)); memcpy(&c->addr4_seen, &c->addr4, sizeof(c->addr4_seen));
if (!memcmp(c->mac, MAC_ZERO, ETH_ALEN)) if (MAC_IS_ZERO(c->mac))
nl_link(0, c->ifi4, c->mac, 0, 0); nl_link(0, c->ifi4, c->mac, 0, 0);
} }
@ -691,17 +691,20 @@ static void conf_ip(struct ctx *c)
memcpy(&c->addr6_seen, &c->addr6, sizeof(c->addr6)); memcpy(&c->addr6_seen, &c->addr6, sizeof(c->addr6));
memcpy(&c->addr6_ll_seen, &c->addr6_ll, sizeof(c->addr6_ll)); memcpy(&c->addr6_ll_seen, &c->addr6_ll, sizeof(c->addr6_ll));
if (MAC_IS_ZERO(c->mac))
nl_link(0, c->ifi6, c->mac, 0, 0);
} }
if (!c->gw4 || !c->addr4 || if (!c->gw4 || !c->addr4 || MAC_IS_ZERO(c->mac))
!memcmp(c->mac, ((uint8_t [ETH_ALEN]){ 0 }), ETH_ALEN))
v4 = IP_VERSION_DISABLED; v4 = IP_VERSION_DISABLED;
else else
v4 = IP_VERSION_ENABLED; v4 = IP_VERSION_ENABLED;
if (IN6_IS_ADDR_UNSPECIFIED(&c->gw6) || if (IN6_IS_ADDR_UNSPECIFIED(&c->gw6) ||
IN6_IS_ADDR_UNSPECIFIED(&c->addr6) || IN6_IS_ADDR_UNSPECIFIED(&c->addr6) ||
IN6_IS_ADDR_UNSPECIFIED(&c->addr6_ll)) IN6_IS_ADDR_UNSPECIFIED(&c->addr6_ll) ||
MAC_IS_ZERO(c->mac))
v6 = IP_VERSION_DISABLED; v6 = IP_VERSION_DISABLED;
else else
v6 = IP_VERSION_ENABLED; v6 = IP_VERSION_ENABLED;
@ -905,12 +908,12 @@ static void conf_print(const struct ctx *c)
if (c->mode == MODE_PASTA) if (c->mode == MODE_PASTA)
info("Namespace interface: %s", c->pasta_ifn); info("Namespace interface: %s", c->pasta_ifn);
if (c->v4) { info("MAC:");
info("ARP:"); info(" host: %02x:%02x:%02x:%02x:%02x:%02x",
info(" address: %02x:%02x:%02x:%02x:%02x:%02x",
c->mac[0], c->mac[1], c->mac[2], c->mac[0], c->mac[1], c->mac[2],
c->mac[3], c->mac[4], c->mac[5]); c->mac[3], c->mac[4], c->mac[5]);
if (c->v4) {
if (!c->no_dhcp) { if (!c->no_dhcp) {
info("DHCP:"); info("DHCP:");
info(" assign: %s", info(" assign: %s",