aboutgitcodebugslistschat
path: root/util.h
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2022-10-12 16:48:52 +0200
committerStefano Brivio <sbrivio@redhat.com>2022-10-15 02:10:36 +0200
commit6f3e38cac5c23dcd2dd6649132f0c55bac331f2e (patch)
tree0fdb140627201155084a306775a885321284bef7 /util.h
parentd0dd0242a69f4ae5be4f46030bf321eb6867b2f8 (diff)
downloadpasst-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.tar
passt-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.tar.gz
passt-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.tar.bz2
passt-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.tar.lz
passt-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.tar.xz
passt-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.tar.zst
passt-6f3e38cac5c23dcd2dd6649132f0c55bac331f2e.zip
Don't create 'tap' socket for ports that are bound to loopback only
If the user specifies an explicit loopback address for a port binding, we're going to use that address for the 'tap' socket, and the same exact address for the 'spliced' socket (because those are, by definition, only bound to loopback addresses). This means that the second binding will fail, and, unexpectedly, the port is forwarded, but via tap device, which means the source address in the namespace won't be a loopback address. Make it explicit under which conditions we're creating which kind of socket, by refactoring tcp_sock_init() into two separate functions for IPv4 and IPv6 and gathering those conditions at the beginning. Also, don't create spliced sockets if the user specifies explicitly a non-loopback address, those are harmless but not desired either. Fixes: 3c6ae625101a ("conf, tcp, udp: Allow address specification for forwarded ports") Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.h')
-rw-r--r--util.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/util.h b/util.h
index 7dc3d18..b1eadfd 100644
--- a/util.h
+++ b/util.h
@@ -81,6 +81,9 @@
#define MAC_ZERO ((uint8_t [ETH_ALEN]){ 0 })
#define MAC_IS_ZERO(addr) (!memcmp((addr), MAC_ZERO, ETH_ALEN))
+#define IPV4_IS_LOOPBACK(addr) \
+ ((addr) >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET)
+
#define NS_FN_STACK_SIZE (RLIMIT_STACK_VAL * 1024 / 4)
#define NS_CALL(fn, arg) \
do { \