]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: protocol: remove family-specific fields from struct protocol
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Sep 2020 06:23:14 +0000 (08:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 20:08:07 +0000 (22:08 +0200)
This removes the following fields from struct protocol that are now
retrieved from the protocol family instead: .sock_family, .sock_addrlen,
.l3_addrlen, .addrcmp, .bind, .get_src, .get_dst.

This also removes the UDP-specific udp{,6}_get_{src,dst}() functions
which were referenced but not used yet. Their goal was only to remap
the original AF_INET* addresses to AF_CUST_UDP*.

Note that .sock_domain is still there as it's used as a selector for
the protocol struct to be used.

include/haproxy/proto_udp.h
include/haproxy/protocol-t.h
src/proto_sockpair.c
src/proto_tcp.c
src/proto_udp.c
src/proto_uxst.c

index 6b91cea7c38715e09ee28dcdf36cd10ec30b5c39..f9069d16e3531a73f2f5ee43628fabe64ce61518 100644 (file)
 
 int udp_bind_socket(int fd, int flags, struct sockaddr_storage *local, struct sockaddr_storage *remote);
 int udp_pause_listener(struct listener *l);
-int udp_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
-int udp6_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
-int udp_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
-int udp6_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
 
 #endif /* _PROTO_PROTO_UDP_H */
 
index fe0c9812ad389aeadd6bfb42cdf2ad8d1f871f58..4f5aac221e0d545911996b539bf43c6260742378 100644 (file)
@@ -84,21 +84,14 @@ struct protocol {
        int sock_domain;                                /* socket domain, as passed to socket()   */
        int sock_type;                                  /* socket type, as passed to socket()     */
        int sock_prot;                                  /* socket protocol, as passed to socket() */
-       sa_family_t sock_family;                        /* socket family, for sockaddr */
-       socklen_t sock_addrlen;                         /* socket address length, used by bind() */
-       int l3_addrlen;                                 /* layer3 address length, used by hashes */
        void (*accept)(int fd);                         /* generic accept function */
-       int (*bind)(struct receiver *rx, void (*handler)(int fd), char **errmsg); /* bind a receiver */
        int (*listen)(struct listener *l, char *errmsg, int errlen); /* start a listener */
        int (*enable_all)(struct protocol *proto);      /* enable all bound listeners */
        int (*disable_all)(struct protocol *proto);     /* disable all bound listeners */
        int (*connect)(struct connection *, int flags); /* connect function if any, see below for flags values */
-       int (*get_src)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve src addr */
-       int (*get_dst)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve dst addr */
        int (*drain)(int fd);                           /* indicates whether we can safely close the fd */
        int (*pause)(struct listener *l);               /* temporarily pause this listener for a soft restart */
        void (*add)(struct listener *l, int port);      /* add a listener for this protocol and port */
-       int (*addrcmp)(const struct sockaddr_storage *, const struct sockaddr_storage *); /* compare addresses (like memcmp) */
 
        struct list listeners;                          /* list of listeners using this protocol (under proto_lock) */
        int nb_listeners;                               /* number of listeners (under proto_lock) */
index a2a9607a822e9f34b3b838cd6e55fddb6dcb3a0c..6b1d69c7f9a7d67ba422b13e759bad4e35446d71 100644 (file)
@@ -64,17 +64,11 @@ static struct protocol proto_sockpair = {
        .sock_domain = AF_CUST_SOCKPAIR,
        .sock_type = SOCK_STREAM,
        .sock_prot = 0,
-       .sock_family = AF_UNIX,
-       .sock_addrlen = sizeof(struct sockaddr_un),
-       .l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path),/* path len */
        .accept = &listener_accept,
        .connect = &sockpair_connect_server,
-       .bind = sockpair_bind_receiver,
        .listen = sockpair_bind_listener,
        .enable_all = enable_all_listeners,
        .disable_all = disable_all_listeners,
-       .get_src = NULL,
-       .get_dst = NULL,
        .pause = NULL,
        .add = sockpair_add_listener,
        .listeners = LIST_HEAD_INIT(proto_sockpair.listeners),
index cb4dc32020bcf90011ee292d00c6ecbf16124dbc..33d39b3d58d9544bf96b668dcf253b157eaefcd4 100644 (file)
@@ -55,19 +55,12 @@ static struct protocol proto_tcpv4 = {
        .sock_domain = AF_INET,
        .sock_type = SOCK_STREAM,
        .sock_prot = IPPROTO_TCP,
-       .sock_family = AF_INET,
-       .sock_addrlen = sizeof(struct sockaddr_in),
-       .l3_addrlen = 32/8,
        .accept = &listener_accept,
        .connect = tcp_connect_server,
-       .bind = sock_inet_bind_receiver,
        .listen = tcp_bind_listener,
        .enable_all = enable_all_listeners,
-       .get_src = sock_get_src,
-       .get_dst = sock_inet_get_dst,
        .pause = tcp_pause_listener,
        .add = tcpv4_add_listener,
-       .addrcmp = sock_inet4_addrcmp,
        .listeners = LIST_HEAD_INIT(proto_tcpv4.listeners),
        .nb_listeners = 0,
 };
@@ -81,19 +74,12 @@ static struct protocol proto_tcpv6 = {
        .sock_domain = AF_INET6,
        .sock_type = SOCK_STREAM,
        .sock_prot = IPPROTO_TCP,
-       .sock_family = AF_INET6,
-       .sock_addrlen = sizeof(struct sockaddr_in6),
-       .l3_addrlen = 128/8,
        .accept = &listener_accept,
        .connect = tcp_connect_server,
-       .bind = sock_inet_bind_receiver,
        .listen = tcp_bind_listener,
        .enable_all = enable_all_listeners,
-       .get_src = sock_get_src,
-       .get_dst = sock_get_dst,
        .pause = tcp_pause_listener,
        .add = tcpv6_add_listener,
-       .addrcmp = sock_inet6_addrcmp,
        .listeners = LIST_HEAD_INIT(proto_tcpv6.listeners),
        .nb_listeners = 0,
 };
index d4d6b2afa5e0344c8bb4e1c7dbeb5e10679d5bcf..d408d7c26e1ef881dfcdc299ffb65110935e7686 100644 (file)
@@ -51,19 +51,12 @@ static struct protocol proto_udp4 = {
        .sock_domain = AF_CUST_UDP4,
        .sock_type = SOCK_DGRAM,
        .sock_prot = IPPROTO_UDP,
-       .sock_family = AF_INET,
-       .sock_addrlen = sizeof(struct sockaddr_in),
-       .l3_addrlen = 32/8,
        .accept = NULL,
        .connect = NULL,
-       .bind = sock_inet_bind_receiver,
        .listen = udp_bind_listener,
        .enable_all = enable_all_listeners,
-       .get_src = udp_get_src,
-       .get_dst = udp_get_dst,
        .pause = udp_pause_listener,
        .add = udp4_add_listener,
-       .addrcmp = sock_inet4_addrcmp,
        .listeners = LIST_HEAD_INIT(proto_udp4.listeners),
        .nb_listeners = 0,
 };
@@ -77,95 +70,18 @@ static struct protocol proto_udp6 = {
        .sock_domain = AF_CUST_UDP6,
        .sock_type = SOCK_DGRAM,
        .sock_prot = IPPROTO_UDP,
-       .sock_family = AF_INET6,
-       .sock_addrlen = sizeof(struct sockaddr_in6),
-       .l3_addrlen = 128/8,
        .accept = NULL,
        .connect = NULL,
-       .bind = sock_inet_bind_receiver,
        .listen = udp_bind_listener,
        .enable_all = enable_all_listeners,
-       .get_src = udp6_get_src,
-       .get_dst = udp6_get_dst,
        .pause = udp_pause_listener,
        .add = udp6_add_listener,
-       .addrcmp = sock_inet6_addrcmp,
        .listeners = LIST_HEAD_INIT(proto_udp6.listeners),
        .nb_listeners = 0,
 };
 
 INITCALL1(STG_REGISTER, protocol_register, &proto_udp6);
 
-/*
- * Retrieves the source address for the socket <fd>, with <dir> indicating
- * if we're a listener (=0) or an initiator (!=0). It returns 0 in case of
- * success, -1 in case of error. The socket's source address is stored in
- * <sa> for <salen> bytes.
- */
-int udp_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir)
-{
-       int ret;
-
-       ret = sock_get_src(fd, sa, salen, dir);
-       if (!ret)
-               sa->sa_family = AF_CUST_UDP4;
-
-       return ret;
-}
-
-/*
- * Retrieves the source address for the socket <fd>, with <dir> indicating
- * if we're a listener (=0) or an initiator (!=0). It returns 0 in case of
- * success, -1 in case of error. The socket's source address is stored in
- * <sa> for <salen> bytes.
- */
-int udp6_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir)
-{
-       int ret;
-
-       ret = sock_get_src(fd, sa, salen, dir);
-       if (!ret)
-               sa->sa_family = AF_CUST_UDP6;
-
-       return ret;
-}
-
-/*
- * Retrieves the original destination address for the socket <fd>, with <dir>
- * indicating if we're a listener (=0) or an initiator (!=0). In the case of a
- * listener, if the original destination address was translated, the original
- * address is retrieved. It returns 0 in case of success, -1 in case of error.
- * The socket's source address is stored in <sa> for <salen> bytes.
- */
-int udp_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir)
-{
-       int ret;
-
-       ret = sock_inet_get_dst(fd, sa, salen, dir);
-       if (!ret)
-               sa->sa_family = AF_CUST_UDP4;
-
-       return ret;
-}
-
-/*
- * Retrieves the original destination address for the socket <fd>, with <dir>
- * indicating if we're a listener (=0) or an initiator (!=0). In the case of a
- * listener, if the original destination address was translated, the original
- * address is retrieved. It returns 0 in case of success, -1 in case of error.
- * The socket's source address is stored in <sa> for <salen> bytes.
- */
-int udp6_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir)
-{
-       int ret;
-
-       ret = sock_get_dst(fd, sa, salen, dir);
-       if (!ret)
-               sa->sa_family = AF_CUST_UDP6;
-
-       return ret;
-}
-
 /* This function tries to bind a UDPv4/v6 listener. It may return a warning or
  * an error message in <errmsg> if the message is at most <errlen> bytes long
  * (including '\0'). Note that <errmsg> may be NULL if <errlen> is also zero.
index 0b8e1767d933a9d6306a0150c8b784219c05caf9..0dd03f85b6c9cd512b236be10b8e29240dbd537b 100644 (file)
@@ -52,20 +52,13 @@ static struct protocol proto_unix = {
        .sock_domain = PF_UNIX,
        .sock_type = SOCK_STREAM,
        .sock_prot = 0,
-       .sock_family = AF_UNIX,
-       .sock_addrlen = sizeof(struct sockaddr_un),
-       .l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path),/* path len */
        .accept = &listener_accept,
        .connect = &uxst_connect_server,
-       .bind = sock_unix_bind_receiver,
        .listen = uxst_bind_listener,
        .enable_all = enable_all_listeners,
        .disable_all = disable_all_listeners,
-       .get_src = sock_get_src,
-       .get_dst = sock_get_dst,
        .pause = uxst_pause_listener,
        .add = uxst_add_listener,
-       .addrcmp = sock_unix_addrcmp,
        .listeners = LIST_HEAD_INIT(proto_unix.listeners),
        .nb_listeners = 0,
 };