summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2020-09-02 18:40:02 +0200
committerWilly Tarreau <w@1wt.eu>2020-09-02 19:03:43 +0200
commita8cde8a53210d3e3a00f5c9a73684d388e6cb406 (patch)
treedf2262e712720734620b976c28cbd8a0009cce81
parent6f9fa734e3d6a733639078c84a7e80d04cb6ab09 (diff)
downloadhaproxy-a8cde8a53210d3e3a00f5c9a73684d388e6cb406.tar.gz
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!
-rw-r--r--src/proto_sockpair.c12
-rw-r--r--src/proto_tcp.c12
-rw-r--r--src/proto_udp.c19
-rw-r--r--src/proto_uxst.c10
4 files changed, 14 insertions, 39 deletions
diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c
index ea823f627..14f2ab492 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -164,15 +164,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, listener,
- listener->bind_conf->bind_thread, &msg);
-
- if (err != ERR_NONE) {
- snprintf(errmsg, errlen, "%s", msg);
- free(msg); msg = NULL;
- return err;
+ if (!(listener->rx.options & RX_O_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 9e8e5a403..9a36afab0 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,13 +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, listener,
- listener->bind_conf->bind_thread, &msg);
- if (err != ERR_NONE) {
- snprintf(errmsg, errlen, "%s", msg);
- free(msg); msg = NULL;
- return err;
+ if (!(listener->rx.options & RX_O_BOUND)) {
+ msg = "receiving socket not bound";
+ goto tcp_close_return;
}
fd = listener->rx.fd;
diff --git a/src/proto_udp.c b/src/proto_udp.c
index 2367a38bf..116860164 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,25 +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.options & RX_O_BOUND)) {
+ msg = "receiving socket not bound";
goto udp_return;
}
- err = sock_inet_bind_receiver(&listener->rx,
- handler, listener,
- listener->bind_conf->bind_thread, &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 82a1f33d0..20db157a6 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -103,13 +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, listener,
- listener->bind_conf->bind_thread, &msg);
- if (err != ERR_NONE) {
- snprintf(errmsg, errlen, "%s", msg);
- free(msg); msg = NULL;
- return err;
+ if (!(listener->rx.options & RX_O_BOUND)) {
+ msg = "receiving socket not bound";
+ goto uxst_close_return;
}
fd = listener->rx.fd;