Move passt mac_guest init to be more symmetric with pasta

In pasta mode, the guest's MAC address is set up in pasta_ns_cobf() called
from tap_sock_tun_init().  If we have a guest MAC configured with
--ns-mac-addr, this will set the given MAC on the kernel tuntap device, or
if we haven't configured one it will update our record of the guest MAC to
the kernel assigned one from the device.

For passt, we don't initially know the guest's MAC until we receive packets
from it, so we have to initially use a broadcast address.  This is - oddly
- set up in an entirely different place, in conf_ip() conditional on the
mode.

Move it to the logically matching place for passt - tap_sock_unix_init().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2022-07-22 15:31:15 +10:00 committed by Stefano Brivio
parent 3f19072640
commit 4bc883aeab
2 changed files with 6 additions and 3 deletions

3
conf.c
View file

@ -676,9 +676,6 @@ static void conf_ip(struct ctx *c)
nl_link(0, c->ifi4, c->mac, 0, 0); nl_link(0, c->ifi4, c->mac, 0, 0);
} }
if (c->mode == MODE_PASST)
memset(&c->mac_guest, 0xff, sizeof(c->mac_guest));
if (v6 != IP_VERSION_DISABLED) { if (v6 != IP_VERSION_DISABLED) {
int prefix_len = 0; int prefix_len = 0;

6
tap.c
View file

@ -794,6 +794,12 @@ static void tap_sock_unix_init(struct ctx *c)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* In passt mode, we don't know the guest's MAC until it sends
* us packets. Use the broadcast address so our first packets
* will reach it.
*/
memset(&c->mac_guest, 0xff, sizeof(c->mac_guest));
for (i = 1; i < UNIX_SOCK_MAX; i++) { for (i = 1; i < UNIX_SOCK_MAX; i++) {
char *path = addr.sun_path; char *path = addr.sun_path;