public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Paul Holzinger <pholzing@redhat.com>
Subject: [PATCH] udp: Actually bind detected namespace ports in init namespace
Date: Tue, 21 Mar 2023 16:20:07 +0100	[thread overview]
Message-ID: <20230321152007.615032-1-sbrivio@redhat.com> (raw)

When I reworked udp_init() to move most of the port binding logic
to conf_ports, I accidentally dropped this bit of automatic port
detection (and binding) at start-up.

On -U auto, in pasta mode, udp_sock_init_ns() binds ports in the
namespace that correspond to ports bound in the init namespace,
but on -u auto, nothing actually happens after port detection.

Add udp_sock_init_init() to deal with this, and while at it fix
the comment to udp_sock_init_ns(): the latter takes care of
outbound "connections".

This is currently not covered by tests, and the UDP port needs to
be already bound in the namespace when pasta starts (periodic
detection for UDP is a missing feature at the moment). It can be
checked like this:

  $ unshare -rUn
  # echo $$
  590092
  # socat -u UDP-LISTEN:5555 STDOUT

  $ pasta -q -u auto 590092
  $ echo "test" | socat -u STDIN UDP:localhost:5555

Reported-by: Paul Holzinger <pholzing@redhat.com>
Fixes: 3c6ae625101a ("conf, tcp, udp: Allow address specification for forwarded ports")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 udp.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/udp.c b/udp.c
index b7bc4f3..45c8d40 100644
--- a/udp.c
+++ b/udp.c
@@ -1042,7 +1042,23 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
 }
 
 /**
- * udp_sock_init_ns() - Bind sockets in namespace for inbound connections
+ * udp_sock_init_init() - Bind sockets in init namespace for inbound connections
+ * @c:		Execution context
+ */
+static void udp_sock_init_init(struct ctx *c)
+{
+	unsigned dst;
+
+	for (dst = 0; dst < NUM_PORTS; dst++) {
+		if (!bitmap_isset(c->udp.fwd_in.f.map, dst))
+			continue;
+
+		udp_sock_init(c, 0, AF_UNSPEC, NULL, NULL, dst);
+	}
+}
+
+/**
+ * udp_sock_init_ns() - Bind sockets in namespace for outbound connections
  * @arg:	Execution context
  *
  * Return: 0
@@ -1110,6 +1126,7 @@ int udp_init(struct ctx *c)
 
 	if (c->mode == MODE_PASTA) {
 		udp_splice_iov_init();
+		udp_sock_init_init(c);
 		NS_CALL(udp_sock_init_ns, c);
 	}
 
-- 
@@ -1042,7 +1042,23 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
 }
 
 /**
- * udp_sock_init_ns() - Bind sockets in namespace for inbound connections
+ * udp_sock_init_init() - Bind sockets in init namespace for inbound connections
+ * @c:		Execution context
+ */
+static void udp_sock_init_init(struct ctx *c)
+{
+	unsigned dst;
+
+	for (dst = 0; dst < NUM_PORTS; dst++) {
+		if (!bitmap_isset(c->udp.fwd_in.f.map, dst))
+			continue;
+
+		udp_sock_init(c, 0, AF_UNSPEC, NULL, NULL, dst);
+	}
+}
+
+/**
+ * udp_sock_init_ns() - Bind sockets in namespace for outbound connections
  * @arg:	Execution context
  *
  * Return: 0
@@ -1110,6 +1126,7 @@ int udp_init(struct ctx *c)
 
 	if (c->mode == MODE_PASTA) {
 		udp_splice_iov_init();
+		udp_sock_init_init(c);
 		NS_CALL(udp_sock_init_ns, c);
 	}
 
-- 
2.39.2


                 reply	other threads:[~2023-03-21 15:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230321152007.615032-1-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=pholzing@redhat.com \
    /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).