CLEANUP: protocol: remove family-specific fields from struct protocol

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.
This commit is contained in:
Willy Tarreau 2020-09-04 08:23:14 +02:00
parent f1f660978c
commit 1e984b73f0
6 changed files with 0 additions and 122 deletions

View File

@ -26,10 +26,6 @@
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 */

View 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) */

View 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),

View 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,
};

View 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.

View 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,
};