public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top
Subject: [PATCH 4/7] Move passt mac_guest init to be more symmetric with pasta
Date: Fri, 22 Jul 2022 15:31:15 +1000	[thread overview]
Message-ID: <20220722053118.1067459-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20220722053118.1067459-1-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]

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(a)gibson.dropbear.id.au>
---
 conf.c | 3 ---
 tap.c  | 6 ++++++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/conf.c b/conf.c
index bc8851f..f5b761f 100644
--- a/conf.c
+++ b/conf.c
@@ -676,9 +676,6 @@ static void conf_ip(struct ctx *c)
 			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) {
 		int prefix_len = 0;
 
diff --git a/tap.c b/tap.c
index a3c711c..43a7372 100644
--- a/tap.c
+++ b/tap.c
@@ -794,6 +794,12 @@ static void tap_sock_unix_init(struct ctx *c)
 		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++) {
 		char *path = addr.sun_path;
 
-- 
@@ -794,6 +794,12 @@ static void tap_sock_unix_init(struct ctx *c)
 		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++) {
 		char *path = addr.sun_path;
 
-- 
2.37.1


  parent reply	other threads:[~2022-07-22  5:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22  5:31 [PATCH 0/7] Improved selection of external interface and IP configuration David Gibson
2022-07-22  5:31 ` [PATCH 1/7] Allow different external interfaces for IPv4 and IPv6 connectivity David Gibson
2022-07-22  5:31 ` [PATCH 2/7] Separately locate external interfaces for IPv4 and IPv6 David Gibson
2022-08-01 10:23   ` Stefano Brivio
2022-07-22  5:31 ` [PATCH 3/7] Initialize host side MAC when in IPv6 only mode David Gibson
2022-07-22  5:31 ` David Gibson [this message]
2022-07-22  5:31 ` [PATCH 5/7] Clarify semantics of c->v4 and c->v6 variables David Gibson
2022-08-01 10:24   ` Stefano Brivio
2022-07-22  5:31 ` [PATCH 6/7] Separate IPv4 and IPv6 configuration David Gibson
2022-08-01 10:24   ` Stefano Brivio
2022-07-22  5:31 ` [PATCH 7/7] Make substructures for IPv4 and IPv6 specific context information David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722053118.1067459-5-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).