diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2023-03-08 12:38:39 +0100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-03-09 03:44:21 +0100 |
commit | 5aea2f88ab5f63f01885109a4afb1271607fc06b (patch) | |
tree | 6ed6fbda7504a00da18fcc977492ee4172680777 /tcp.c | |
parent | 73992c42cea0df56f6ba0a3bef0f4a939f26ebad (diff) | |
download | passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.tar passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.tar.gz passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.tar.bz2 passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.tar.lz passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.tar.xz passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.tar.zst passt-5aea2f88ab5f63f01885109a4afb1271607fc06b.zip |
tcp, udp: Fix partial success return codes in {tcp,udp}_sock_init()
The comments say we should return 0 on partial success, and an error
code on complete failure. Rationale: if the user configures a port
forwarding, and we succeed to bind that port for IPv4 or IPv6 only,
that might actually be what the user intended.
Adjust the two functions to reflect the comments.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tcp.c')
-rw-r--r-- | tcp.c | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -2993,7 +2993,7 @@ static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, const char *ifname, in_port_t port) { - int ret = 0, af_ret; + int r4 = SOCKET_MAX + 1, r6 = SOCKET_MAX + 1; if (af == AF_UNSPEC && c->ifi4 && c->ifi6) /* Attempt to get a dual stack socket */ @@ -3001,19 +3001,16 @@ int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, return 0; /* Otherwise create a socket per IP version */ - if ((af == AF_INET || af == AF_UNSPEC) && c->ifi4) { - af_ret = tcp_sock_init_af(c, AF_INET, port, addr, ifname); - if (af_ret < 0) - ret = af_ret; - } + if ((af == AF_INET || af == AF_UNSPEC) && c->ifi4) + r4 = tcp_sock_init_af(c, AF_INET, port, addr, ifname); - if ((af == AF_INET6 || af == AF_UNSPEC) && c->ifi6) { - af_ret = tcp_sock_init_af(c, AF_INET6, port, addr, ifname); - if (af_ret < 0) - ret = af_ret; - } + if ((af == AF_INET6 || af == AF_UNSPEC) && c->ifi6) + r6 = tcp_sock_init_af(c, AF_INET6, port, addr, ifname); - return ret; + if (IN_INTERVAL(0, SOCKET_MAX, r4) || IN_INTERVAL(0, SOCKET_MAX, r6)) + return 0; + + return r4 < 0 ? r4 : r6; } /** |