diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2023-03-08 12:14:29 +0100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-03-09 03:44:21 +0100 |
commit | 73992c42cea0df56f6ba0a3bef0f4a939f26ebad (patch) | |
tree | 0ea4292ab62f4c23fd6399e174147b2687b1890d /tcp.c | |
parent | 50687616e4a99eabb2f22de8651817746c0abda1 (diff) | |
download | passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.tar passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.tar.gz passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.tar.bz2 passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.tar.lz passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.tar.xz passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.tar.zst passt-73992c42cea0df56f6ba0a3bef0f4a939f26ebad.zip |
tcp, udp, util: Pass socket creation errors all the way up
...starting from sock_l4(), pass negative error (errno) codes instead
of -1. They will only be used in two commits from now, no functional
changes intended here.
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 | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -2955,7 +2955,7 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events, * @addr: Pointer to address for binding, NULL if not configured * @ifname: Name of interface to bind to, NULL if not configured * - * Return: fd for the new listening socket, or -1 on failure + * Return: fd for the new listening socket, negative error code on failure */ static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, const struct in_addr *addr, const char *ifname) @@ -2968,13 +2968,13 @@ static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, if (c->tcp.fwd_in.mode == FWD_AUTO) { if (af == AF_INET || af == AF_UNSPEC) - tcp_sock_init_ext[port][V4] = s; + tcp_sock_init_ext[port][V4] = s < 0 ? -1 : s; if (af == AF_INET6 || af == AF_UNSPEC) - tcp_sock_init_ext[port][V6] = s; + tcp_sock_init_ext[port][V6] = s < 0 ? -1 : s; } if (s < 0) - return -1; + return s; tcp_sock_set_bufsize(c, s); return s; @@ -2988,12 +2988,12 @@ static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, * @ifname: Name of interface to bind to, NULL if not configured * @port: Port, host order * - * Return: 0 on (partial) success, -1 on (complete) failure + * Return: 0 on (partial) success, negative error code on (complete) failure */ 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; + int ret = 0, af_ret; if (af == AF_UNSPEC && c->ifi4 && c->ifi6) /* Attempt to get a dual stack socket */ @@ -3002,13 +3002,15 @@ int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, /* Otherwise create a socket per IP version */ if ((af == AF_INET || af == AF_UNSPEC) && c->ifi4) { - if (tcp_sock_init_af(c, AF_INET, port, addr, ifname) < 0) - ret = -1; + af_ret = tcp_sock_init_af(c, AF_INET, port, addr, ifname); + if (af_ret < 0) + ret = af_ret; } if ((af == AF_INET6 || af == AF_UNSPEC) && c->ifi6) { - if (tcp_sock_init_af(c, AF_INET6, port, addr, ifname) < 0) - ret = -1; + af_ret = tcp_sock_init_af(c, AF_INET6, port, addr, ifname); + if (af_ret < 0) + ret = af_ret; } return ret; |