summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2020-09-01 19:13:01 +0200
committerWilly Tarreau <w@1wt.eu>2020-09-01 19:13:01 +0200
commit84afb0388f5da0bbc2fb6eacb5fa9c88fe35b6e8 (patch)
treedc6882321eb298fe5e01dd5a8555fdd023d1318c
parenta88243c78ab28ad815cd89afd60ed2d7bda9a4b4 (diff)
downloadhaproxy-20200901-split-protos-8a.tar.gz
CLEANUP: protocol: replace all ->unbind_all() functions with a central call20200901-split-protos-8a
Just like with the previous patches, we don't need to have protocol specific unbind_all() calls. These ones are always unbind_all_listeners except for uxst where the simplifications that came over the years have resulted in a locally reimplemented version of the same function: the test on (state > LI_ASSIGNED) there is equivalent to the one on (state >= LI_PAUSED) that is used in do_unbind_listener(), and it seems these have been equivalent since at least commit dabf2e264 ("[MAJOR] added a new state to listeners")). Now protocol_unbind_all() will simply call unbind_listener() for each protocol's listener. and we don't need proto->unbind() anymore.
-rw-r--r--include/haproxy/listener.h7
-rw-r--r--src/listener.c16
-rw-r--r--src/proto_sockpair.c1
-rw-r--r--src/proto_tcp.c2
-rw-r--r--src/proto_udp.c2
-rw-r--r--src/proto_uxst.c34
-rw-r--r--src/protocol.c6
7 files changed, 3 insertions, 65 deletions
diff --git a/include/haproxy/listener.h b/include/haproxy/listener.h
index 996f3d8b8..9715f89ae 100644
--- a/include/haproxy/listener.h
+++ b/include/haproxy/listener.h
@@ -83,13 +83,6 @@ void unbind_listener(struct listener *listener);
*/
void unbind_listener_no_close(struct listener *listener);
-/* This function closes all listening sockets bound to the protocol <proto>,
- * and the listeners end in LI_ASSIGNED state if they were higher. It does not
- * detach them from the protocol. It always returns ERR_NONE.
- */
-int unbind_all_listeners(struct protocol *proto);
-
-
/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
* range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
* allocation). The address family is taken from ss->ss_family. The number of
diff --git a/src/listener.c b/src/listener.c
index 39187eaf6..431336a97 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -533,22 +533,6 @@ void unbind_listener_no_close(struct listener *listener)
HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
}
-/* This function closes all listening sockets bound to the protocol <proto>,
- * and the listeners end in LI_ASSIGNED state if they were higher. It does not
- * detach them from the protocol. It always returns ERR_NONE.
- *
- * Must be called with proto_lock held.
- *
- */
-int unbind_all_listeners(struct protocol *proto)
-{
- struct listener *listener;
-
- list_for_each_entry(listener, &proto->listeners, rx.proto_list)
- unbind_listener(listener);
- return ERR_NONE;
-}
-
/* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
* range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
* allocation). The address family is taken from ss->ss_family. The number of
diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c
index edd481fb9..6753748b8 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -56,7 +56,6 @@ static struct protocol proto_sockpair = {
.accept = &listener_accept,
.connect = &sockpair_connect_server,
.bind = sockpair_bind_listener,
- .unbind_all = NULL,
.enable_all = enable_all_listeners,
.disable_all = disable_all_listeners,
.get_src = NULL,
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 959fb2b52..f7ad4cc61 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -60,7 +60,6 @@ static struct protocol proto_tcpv4 = {
.accept = &listener_accept,
.connect = tcp_connect_server,
.bind = tcp_bind_listener,
- .unbind_all = unbind_all_listeners,
.enable_all = enable_all_listeners,
.get_src = sock_get_src,
.get_dst = sock_inet_get_dst,
@@ -85,7 +84,6 @@ static struct protocol proto_tcpv6 = {
.accept = &listener_accept,
.connect = tcp_connect_server,
.bind = tcp_bind_listener,
- .unbind_all = unbind_all_listeners,
.enable_all = enable_all_listeners,
.get_src = sock_get_src,
.get_dst = sock_get_dst,
diff --git a/src/proto_udp.c b/src/proto_udp.c
index 85a358df5..61237e21d 100644
--- a/src/proto_udp.c
+++ b/src/proto_udp.c
@@ -56,7 +56,6 @@ static struct protocol proto_udp4 = {
.accept = NULL,
.connect = NULL,
.bind = udp_bind_listener,
- .unbind_all = unbind_all_listeners,
.enable_all = enable_all_listeners,
.get_src = udp_get_src,
.get_dst = udp_get_dst,
@@ -81,7 +80,6 @@ static struct protocol proto_udp6 = {
.accept = NULL,
.connect = NULL,
.bind = udp_bind_listener,
- .unbind_all = unbind_all_listeners,
.enable_all = enable_all_listeners,
.get_src = udp6_get_src,
.get_dst = udp6_get_dst,
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index 2273fa33c..46c332527 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -58,7 +58,6 @@ static struct protocol proto_unix = {
.accept = &listener_accept,
.connect = &uxst_connect_server,
.bind = uxst_bind_listener,
- .unbind_all = uxst_unbind_listeners,
.enable_all = enable_all_listeners,
.disable_all = disable_all_listeners,
.get_src = sock_get_src,
@@ -298,17 +297,6 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
return err;
}
-/* This function closes the UNIX sockets for the specified listener.
- * The listener enters the LI_ASSIGNED state. It always returns ERR_NONE.
- */
-static int uxst_unbind_listener(struct listener *listener)
-{
- if (listener->state > LI_ASSIGNED) {
- unbind_listener(listener);
- }
- return ERR_NONE;
-}
-
/* Add <listener> to the list of unix stream listeners (port is ignored). The
* listener's state is automatically updated from LI_INIT to LI_ASSIGNED.
* The number of listeners for the protocol is updated.
@@ -523,28 +511,6 @@ static int uxst_connect_server(struct connection *conn, int flags)
return SF_ERR_NONE; /* connection is OK */
}
-
-/********************************
- * 3) protocol-oriented functions
- ********************************/
-
-
-/* This function stops all listening UNIX sockets bound to the protocol
- * <proto>. It does not detaches them from the protocol.
- * It always returns ERR_NONE.
- *
- * Must be called with proto_lock held.
- *
- */
-static int uxst_unbind_listeners(struct protocol *proto)
-{
- struct listener *listener;
-
- list_for_each_entry(listener, &proto->listeners, rx.proto_list)
- uxst_unbind_listener(listener);
- return ERR_NONE;
-}
-
/*
* Local variables:
* c-indent-level: 8
diff --git a/src/protocol.c b/src/protocol.c
index 529f71175..eb646a7f1 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -82,14 +82,14 @@ int protocol_bind_all(char *errmsg, int errlen)
int protocol_unbind_all(void)
{
struct protocol *proto;
+ struct listener *listener;
int err;
err = 0;
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
list_for_each_entry(proto, &protocols, list) {
- if (proto->unbind_all) {
- err |= proto->unbind_all(proto);
- }
+ list_for_each_entry(listener, &proto->listeners, rx.proto_list)
+ unbind_listener(listener);
}
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
return err;