aboutgitcodebugslistschat
path: root/passt.1
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2023-03-08 03:29:51 +0100
committerStefano Brivio <sbrivio@redhat.com>2023-03-09 03:43:59 +0100
commita9c59dd91baa6315259328fc0e36ac63a61ab24b (patch)
tree7521d3ff5f142ed9acf20e7b1cafc537a818031a /passt.1
parent70148ce5be9844ba0e3c8112fb0117689c1bfca0 (diff)
downloadpasst-a9c59dd91baa6315259328fc0e36ac63a61ab24b.tar
passt-a9c59dd91baa6315259328fc0e36ac63a61ab24b.tar.gz
passt-a9c59dd91baa6315259328fc0e36ac63a61ab24b.tar.bz2
passt-a9c59dd91baa6315259328fc0e36ac63a61ab24b.tar.lz
passt-a9c59dd91baa6315259328fc0e36ac63a61ab24b.tar.xz
passt-a9c59dd91baa6315259328fc0e36ac63a61ab24b.tar.zst
passt-a9c59dd91baa6315259328fc0e36ac63a61ab24b.zip
conf, icmp, tcp, udp: Add options to bind to outbound address and interface
I didn't notice earlier: libslirp (and slirp4netns) supports binding outbound sockets to specific IPv4 and IPv6 addresses, to force the source addresse selection. If we want to claim feature parity, we should implement that as well. Further, Podman supports specifying outbound interfaces as well, but this is simply done by resolving the primary address for an interface when the network back-end is started. However, since kernel version 5.7, commit c427bfec18f2 ("net: core: enable SO_BINDTODEVICE for non-root users"), we can actually bind to a specific interface name, which doesn't need to be validated in advance. Implement -o / --outbound ADDR to bind to IPv4 and IPv6 addresses, and --outbound-if4 and --outbound-if6 to bind IPv4 and IPv6 sockets to given interfaces. Given that it probably makes little sense to select addresses and routes from interfaces different than the ones given for outbound sockets, also assign those as "template" interfaces, by default, unless explicitly overridden by '-i'. For ICMP and UDP, we call sock_l4() to open outbound sockets, as we already needed to bind to given ports or echo identifiers, and we can bind() a socket only once: there, pass address (if any) and interface (if any) for the existing bind() and setsockopt() calls. For TCP, in general, we wouldn't otherwise bind sockets. Add a specific helper to do that. For UDP outbound sockets, we need to know if the final destination of the socket is a loopback address, before we decide whether it makes sense to bind the socket at all: move the block mangling the address destination before the creation of the socket in the IPv4 path. This was already the case for the IPv6 path. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'passt.1')
-rw-r--r--passt.129
1 files changed, 27 insertions, 2 deletions
diff --git a/passt.1 b/passt.1
index f317c33..6136fa5 100644
--- a/passt.1
+++ b/passt.1
@@ -180,8 +180,33 @@ to allow mapping of local traffic to guest and target namespace. See the
.TP
.BR \-i ", " \-\-interface " " \fIname
Use host interface \fIname\fR to derive addresses and routes.
-Default is to use the interfaces with the first default routes for each IP
-version.
+Default is to use the interfaces specified by \fB--outbound-if4\fR and
+\fB--outbound-if6\fR, for IPv4 and IPv6 addresses and routes, respectively. If
+no interfaces are given, the interface with the first default routes for each IP
+version is selected.
+
+.TP
+.BR \-o ", " \-\-outbound " " \fIaddr
+Use an IPv4 \fIaddr\fR as source address for IPv4 outbound TCP connections, UDP
+flows, ICMP requests, or an IPv6 \fIaddr\fR for IPv6 ones, by binding outbound
+sockets to it.
+This option can be specified zero (for defaults) to two times (once for IPv4,
+once for IPv6).
+By default, the source address is selected by the routing tables.
+
+.TP
+.BR \-\-outbound-if4 " " \fIname
+Bind IPv4 outbound sockets to host interface \fIname\fR, and, unless another
+interface is specified via \fB-i\fR, \fB--interface\fR, use this interface to
+derive IPv4 addresses and routes.
+By default, the interface given by the default route is selected.
+
+.TP
+.BR \-\-outbound-if6 " " \fIname
+Bind IPv6 outbound sockets to host interface \fIname\fR, and, unless another
+interface is specified via \fB-i\fR, \fB--interface\fR, use this interface to
+derive IPv6 addresses and routes.
+By default, the interface given by the default route is selected.
.TP
.BR \-D ", " \-\-dns " " \fIaddr