MINOR: listener: now use a generic add_listener() function
With the removal of the family-specific port setting, all protocol had
exactly the same implementation of ->add(). A generic one was created
with the name "default_add_listener" so that all other ones can now be
removed. The API was slightly adjusted so that the protocol and the
listener are passed instead of the listener and the port.
Note that all protocols continue to provide this ->add() method instead
of routinely calling default_add_listener() from create_listeners(). This
makes sure that any non-standard protocol will still be able to intercept
the listener addition if needed.
This could be backported to 2.3 along with the few previous patches on
listners as a pure code cleanup.
(cherry picked from commit d1f250f87b8850f24456e62140509e612f8b3415)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/proto_udp.c b/src/proto_udp.c
index 436f2a0..5ac7b15 100644
--- a/src/proto_udp.c
+++ b/src/proto_udp.c
@@ -45,8 +45,6 @@
static int udp_resume_receiver(struct receiver *rx);
static void udp_enable_listener(struct listener *listener);
static void udp_disable_listener(struct listener *listener);
-static void udp4_add_listener(struct listener *listener, int port);
-static void udp6_add_listener(struct listener *listener, int port);
/* Note: must not be declared <const> as its list will be overwritten */
static struct protocol proto_udp4 = {
@@ -56,7 +54,7 @@
.sock_domain = AF_INET,
.sock_type = SOCK_DGRAM,
.sock_prot = IPPROTO_UDP,
- .add = udp4_add_listener,
+ .add = default_add_listener,
.listen = udp_bind_listener,
.enable = udp_enable_listener,
.disable = udp_disable_listener,
@@ -82,7 +80,7 @@
.sock_domain = AF_INET6,
.sock_type = SOCK_DGRAM,
.sock_prot = IPPROTO_UDP,
- .add = udp6_add_listener,
+ .add = default_add_listener,
.listen = udp_bind_listener,
.enable = udp_enable_listener,
.disable = udp_disable_listener,
@@ -142,34 +140,6 @@
return err;
}
-/* Add <listener> to the list of udp4 listeners, on port <port>. The
- * listener's state is automatically updated from LI_INIT to LI_ASSIGNED.
- * The number of listeners for the protocol is updated.
- */
-static void udp4_add_listener(struct listener *listener, int port)
-{
- if (listener->state != LI_INIT)
- return;
- listener_set_state(listener, LI_ASSIGNED);
- listener->rx.proto = &proto_udp4;
- LIST_ADDQ(&proto_udp4.receivers, &listener->rx.proto_list);
- proto_udp4.nb_receivers++;
-}
-
-/* Add <listener> to the list of udp6 listeners, on port <port>. The
- * listener's state is automatically updated from LI_INIT to LI_ASSIGNED.
- * The number of listeners for the protocol is updated.
- */
-static void udp6_add_listener(struct listener *listener, int port)
-{
- if (listener->state != LI_INIT)
- return;
- listener_set_state(listener, LI_ASSIGNED);
- listener->rx.proto = &proto_udp6;
- LIST_ADDQ(&proto_udp6.receivers, &listener->rx.proto_list);
- proto_udp6.nb_receivers++;
-}
-
/* Enable receipt of incoming connections for listener <l>. The receiver must
* still be valid.
*/