Skip to content

Commit

Permalink
conf: Allow binding to ports on an interface without a specific address
Browse files Browse the repository at this point in the history
Somebody might want to bind listening sockets to a specific
interface, but not a specific address, and there isn't really a
reason to prevent that. For example:

  -t %eth0/2022

Alternatively, we support options such as -t 0.0.0.0%eth0/2022 and
-t ::%eth0/2022, but not together, for the same port.

Enable this kind of syntax and add examples to the man page.

Reported-by: Paul Holzinger <[email protected]>
Link: containers/podman#14425 (comment)
Signed-off-by: Stefano Brivio <[email protected]>
  • Loading branch information
sbrivio-rh committed Mar 29, 2023
1 parent 33d88f7 commit 98a9a7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg,
ifname++;
}

if (inet_pton(AF_INET, buf, addr))
if (ifname == buf + 1) /* Interface without address */
addr = NULL;
else if (inet_pton(AF_INET, buf, addr))
af = AF_INET;
else if (inet_pton(AF_INET6, buf, addr))
af = AF_INET6;
Expand Down
6 changes: 6 additions & 0 deletions passt.1
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ Forward local port 22, bound to 192.0.2.1, to port 22 on the guest
-t 192.0.2.1%eth0/22
Forward local port 22, bound to 192.0.2.1 and interface eth0, to port 22
.TP
-t %eth0/22
Forward local port 22, bound to any address on interface eth0, to port 22
.TP
-t 2000-5000,~3000-3010
Forward local ports between 2000 and 5000, except for those between 3000 and
3010
Expand Down Expand Up @@ -467,6 +470,9 @@ Forward local port 22, bound to 192.0.2.1, to port 22 in the target namespace
-t 192.0.2.1%eth0/22
Forward local port 22, bound to 192.0.2.1 and interface eth0, to port 22
.TP
-t %eth0/22
Forward local port 22, bound to any address on interface eth0, to port 22
.TP
-t 2000-5000,~3000-3010
Forward local ports between 2000 and 5000, except for those between 3000 and
3010
Expand Down

0 comments on commit 98a9a7d

Please sign in to comment.