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!
This commit is contained in:
Willy Tarreau 2020-09-02 18:40:02 +02:00
parent fc974887ce
commit ad33acf838
4 changed files with 16 additions and 30 deletions

View File

@ -162,12 +162,11 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e
if (listener->state != LI_ASSIGNED) if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */ return ERR_NONE; /* already bound */
err = sockpair_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg); if (!(listener->rx.flags & RX_F_BOUND)) {
if (err != ERR_NONE) { msg = "receiving socket not bound";
snprintf(errmsg, errlen, "%s", msg); goto err_return;
free(msg); msg = NULL;
return err;
} }
listener->state = LI_LISTEN; listener->state = LI_LISTEN;
return err; return err;

View File

@ -561,6 +561,8 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
socklen_t ready_len; socklen_t ready_len;
char *msg = NULL; char *msg = NULL;
err = ERR_NONE;
/* ensure we never return garbage */ /* ensure we never return garbage */
if (errlen) if (errlen)
*errmsg = 0; *errmsg = 0;
@ -568,11 +570,9 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
if (listener->state != LI_ASSIGNED) if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */ return ERR_NONE; /* already bound */
err = sock_inet_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg); if (!(listener->rx.flags & RX_F_BOUND)) {
if (err != ERR_NONE) { msg = "receiving socket not bound";
snprintf(errmsg, errlen, "%s", msg); goto tcp_return;
free(msg); msg = NULL;
return err;
} }
fd = listener->rx.fd; fd = listener->rx.fd;
@ -691,6 +691,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
tcp_close_return: tcp_close_return:
close(fd); close(fd);
tcp_return:
if (msg && errlen) { if (msg && errlen) {
char pn[INET6_ADDRSTRLEN]; char pn[INET6_ADDRSTRLEN];

View File

@ -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 udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
{ {
int err = ERR_NONE; int err = ERR_NONE;
void *handler = NULL;
char *msg = NULL; char *msg = NULL;
/* ensure we never return garbage */ /* 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) if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */ return ERR_NONE; /* already bound */
switch (listener->bind_conf->frontend->mode) { if (!(listener->rx.flags & RX_F_BOUND)) {
case PR_MODE_SYSLOG: msg = "receiving socket not bound";
handler = syslog_fd_handler;
break;
default:
err |= ERR_FATAL | ERR_ALERT;
msg = "UDP is not yet supported on this proxy mode";
goto udp_return; 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; listener->state = LI_LISTEN;
udp_return: udp_return:

View File

@ -103,11 +103,9 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
if (listener->state != LI_ASSIGNED) if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */ return ERR_NONE; /* already bound */
err = sock_unix_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg); if (!(listener->rx.flags & RX_F_BOUND)) {
if (err != ERR_NONE) { msg = "receiving socket not bound";
snprintf(errmsg, errlen, "%s", msg); goto uxst_return;
free(msg); msg = NULL;
return err;
} }
fd = listener->rx.fd; fd = listener->rx.fd;
@ -130,6 +128,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
uxst_close_return: uxst_close_return:
close(fd); close(fd);
uxst_return:
if (msg && errlen) { if (msg && errlen) {
const char *path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path; const char *path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path;
snprintf(errmsg, errlen, "%s [%s]", msg, path); snprintf(errmsg, errlen, "%s [%s]", msg, path);