From: Willy Tarreau Date: Wed, 2 Sep 2020 16:40:02 +0000 (+0200) Subject: MEDIUM: protocol: do not call proto->bind() anymore from bind_listener() X-Git-Tag: v2.3-dev5~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ad33acf83866cfdf6fb4db330a3c8abc85050cb5;p=thirdparty%2Fhaproxy.git MEDIUM: protocol: do not call proto->bind() anymore from bind_listener() All protocol's listeners now only take care of themselves and not of the receiver anymore since that's already being done in proto_bind_all(). Now it finally becomes obvious that UDP doesn't need a listener, as the only thing it does is to set the listener's state to LI_LISTEN! --- diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index 00fce76cbf..a920f4e61d 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -162,12 +162,11 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e if (listener->state != LI_ASSIGNED) return ERR_NONE; /* already bound */ - err = sockpair_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg); - if (err != ERR_NONE) { - snprintf(errmsg, errlen, "%s", msg); - free(msg); msg = NULL; - return err; + if (!(listener->rx.flags & RX_F_BOUND)) { + msg = "receiving socket not bound"; + goto err_return; } + listener->state = LI_LISTEN; return err; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 57ccfed23b..4af22e557a 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -561,6 +561,8 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) socklen_t ready_len; char *msg = NULL; + err = ERR_NONE; + /* ensure we never return garbage */ if (errlen) *errmsg = 0; @@ -568,11 +570,9 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) if (listener->state != LI_ASSIGNED) return ERR_NONE; /* already bound */ - err = sock_inet_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg); - if (err != ERR_NONE) { - snprintf(errmsg, errlen, "%s", msg); - free(msg); msg = NULL; - return err; + if (!(listener->rx.flags & RX_F_BOUND)) { + msg = "receiving socket not bound"; + goto tcp_return; } fd = listener->rx.fd; @@ -691,6 +691,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) tcp_close_return: close(fd); + tcp_return: if (msg && errlen) { char pn[INET6_ADDRSTRLEN]; diff --git a/src/proto_udp.c b/src/proto_udp.c index 957deb4d91..43eff39c47 100644 --- a/src/proto_udp.c +++ b/src/proto_udp.c @@ -180,7 +180,6 @@ int udp6_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir) int udp_bind_listener(struct listener *listener, char *errmsg, int errlen) { int err = ERR_NONE; - void *handler = NULL; char *msg = NULL; /* ensure we never return garbage */ @@ -190,23 +189,11 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen) if (listener->state != LI_ASSIGNED) return ERR_NONE; /* already bound */ - switch (listener->bind_conf->frontend->mode) { - case PR_MODE_SYSLOG: - handler = syslog_fd_handler; - break; - default: - err |= ERR_FATAL | ERR_ALERT; - msg = "UDP is not yet supported on this proxy mode"; + if (!(listener->rx.flags & RX_F_BOUND)) { + msg = "receiving socket not bound"; goto udp_return; } - err = sock_inet_bind_receiver(&listener->rx, handler, &msg); - - if (err != ERR_NONE) { - snprintf(errmsg, errlen, "%s", msg); - free(msg); msg = NULL; - return err; - } listener->state = LI_LISTEN; udp_return: diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 3e29e871a0..5ceb18f13d 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -103,11 +103,9 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle if (listener->state != LI_ASSIGNED) return ERR_NONE; /* already bound */ - err = sock_unix_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg); - if (err != ERR_NONE) { - snprintf(errmsg, errlen, "%s", msg); - free(msg); msg = NULL; - return err; + if (!(listener->rx.flags & RX_F_BOUND)) { + msg = "receiving socket not bound"; + goto uxst_return; } fd = listener->rx.fd; @@ -130,6 +128,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle uxst_close_return: close(fd); + uxst_return: if (msg && errlen) { const char *path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path; snprintf(errmsg, errlen, "%s [%s]", msg, path);