aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-07-26 14:10:29 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-07-26 14:10:29 +0200
commit86b273150a47c6f5783db865d1385675f5c4e5a6 (patch)
treebc0011bc64f00a519817eb7b74a7d20664f8e3fb /util.c
parentf4aaa471a1d304b0b6c767ef4b2fb88b45c02ef1 (diff)
downloadpasst-86b273150a47c6f5783db865d1385675f5c4e5a6.tar
passt-86b273150a47c6f5783db865d1385675f5c4e5a6.tar.gz
passt-86b273150a47c6f5783db865d1385675f5c4e5a6.tar.bz2
passt-86b273150a47c6f5783db865d1385675f5c4e5a6.tar.lz
passt-86b273150a47c6f5783db865d1385675f5c4e5a6.tar.xz
passt-86b273150a47c6f5783db865d1385675f5c4e5a6.tar.zst
passt-86b273150a47c6f5783db865d1385675f5c4e5a6.zip
tcp, udp: Allow binding ports in init namespace to both tap and loopback
Traffic with loopback source address will be forwarded to the direct loopback connection in the namespace, and the tap interface is used for the rest. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/util.c b/util.c
index 33894f7..fe18cd8 100644
--- a/util.c
+++ b/util.c
@@ -125,13 +125,13 @@ char *ipv6_l4hdr(struct ipv6hdr *ip6h, uint8_t *proto)
* @af: Address family, AF_INET or AF_INET6
* @proto: Protocol number
* @port: Port, host order
- * @lo: Bind to loopback address only, if set
+ * @bind_type: Type of address for binding
* @data: epoll reference portion for protocol handlers
*
* Return: newly created socket, -1 on error
*/
-int sock_l4(struct ctx *c, int af, uint8_t proto, uint16_t port, int lo,
- uint32_t data)
+int sock_l4(struct ctx *c, int af, uint8_t proto, uint16_t port,
+ enum bind_type bind_addr, uint32_t data)
{
union epoll_ref ref = { .proto = proto, .data = data };
struct sockaddr_in addr4 = {
@@ -161,16 +161,20 @@ int sock_l4(struct ctx *c, int af, uint8_t proto, uint16_t port, int lo,
ref.s = fd;
if (af == AF_INET) {
- if (lo)
+ if (bind_addr == BIND_LOOPBACK)
addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ else if (bind_addr == BIND_EXT)
+ addr4.sin_addr.s_addr = c->addr4;
else
addr4.sin_addr.s_addr = htonl(INADDR_ANY);
sa = (const struct sockaddr *)&addr4;
sl = sizeof(addr4);
} else {
- if (lo)
+ if (bind_addr == BIND_LOOPBACK)
addr6.sin6_addr = in6addr_loopback;
+ else if (bind_addr == BIND_EXT)
+ addr6.sin6_addr = c->addr6;
else
addr6.sin6_addr = in6addr_any;