mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 23:56:57 +02:00
MINOR: protocol: retrieve the family-specific fields from the family
We now take care of retrieving sock_family, l3_addrlen, bind(), addrcmp(), get_src() and get_dst() from the protocol family and not just the protocol itself. There are very few places, this was only seldom used. Interestingly in sock_inet.c used to rely on ->sock_family instead of ->sock_domain, and sock_unix.c used to hard-code PF_UNIX instead of using ->sock_domain. Also it appears obvious we have something wrong it the protocol selection algorithm because sock_domain is the one set to the custom protocols while it ought to be sock_family instead, which would avoid having to hard-code some conversions for UDP namely.
This commit is contained in:
parent
b0254cb361
commit
f1f660978c
@ -534,13 +534,13 @@ static inline int conn_get_src(struct connection *conn)
|
|||||||
if (conn->flags & CO_FL_ADDR_FROM_SET)
|
if (conn->flags & CO_FL_ADDR_FROM_SET)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!conn_ctrl_ready(conn) || !conn->ctrl->get_src)
|
if (!conn_ctrl_ready(conn) || !conn->ctrl->fam->get_src)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!sockaddr_alloc(&conn->src))
|
if (!sockaddr_alloc(&conn->src))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (conn->ctrl->get_src(conn->handle.fd, (struct sockaddr *)conn->src,
|
if (conn->ctrl->fam->get_src(conn->handle.fd, (struct sockaddr *)conn->src,
|
||||||
sizeof(*conn->src),
|
sizeof(*conn->src),
|
||||||
obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
|
obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
@ -557,13 +557,13 @@ static inline int conn_get_dst(struct connection *conn)
|
|||||||
if (conn->flags & CO_FL_ADDR_TO_SET)
|
if (conn->flags & CO_FL_ADDR_TO_SET)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!conn_ctrl_ready(conn) || !conn->ctrl->get_dst)
|
if (!conn_ctrl_ready(conn) || !conn->ctrl->fam->get_dst)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!sockaddr_alloc(&conn->dst))
|
if (!sockaddr_alloc(&conn->dst))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (conn->ctrl->get_dst(conn->handle.fd, (struct sockaddr *)conn->dst,
|
if (conn->ctrl->fam->get_dst(conn->handle.fd, (struct sockaddr *)conn->dst,
|
||||||
sizeof(*conn->dst),
|
sizeof(*conn->dst),
|
||||||
obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
|
obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -82,7 +82,7 @@ int protocol_bind_all(int verbose)
|
|||||||
handler = syslog_fd_handler;
|
handler = syslog_fd_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
lerr = proto->bind(receiver, handler, &errmsg);
|
lerr = proto->fam->bind(receiver, handler, &errmsg);
|
||||||
err |= lerr;
|
err |= lerr;
|
||||||
|
|
||||||
/* errors are reported if <verbose> is set or if they are fatal */
|
/* errors are reported if <verbose> is set or if they are fatal */
|
||||||
|
@ -363,7 +363,7 @@ int sock_find_compatible_fd(const struct receiver *rx)
|
|||||||
int ns_namelen = 0;
|
int ns_namelen = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!rx->proto->addrcmp)
|
if (!rx->proto->fam->addrcmp)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (rx->proto->sock_type == SOCK_DGRAM)
|
if (rx->proto->sock_type == SOCK_DGRAM)
|
||||||
@ -397,7 +397,7 @@ int sock_find_compatible_fd(const struct receiver *rx)
|
|||||||
#ifdef USE_NS
|
#ifdef USE_NS
|
||||||
(!ns_namelen || strcmp(rx->settings->netns->node.key, xfer_sock->namespace) == 0) &&
|
(!ns_namelen || strcmp(rx->settings->netns->node.key, xfer_sock->namespace) == 0) &&
|
||||||
#endif
|
#endif
|
||||||
rx->proto->addrcmp(&xfer_sock->addr, &rx->addr) == 0)
|
rx->proto->fam->addrcmp(&xfer_sock->addr, &rx->addr) == 0)
|
||||||
break;
|
break;
|
||||||
xfer_sock = xfer_sock->next;
|
xfer_sock = xfer_sock->next;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ int sock_inet_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
|
|||||||
struct sockaddr_storage addr_inet = rx->addr;
|
struct sockaddr_storage addr_inet = rx->addr;
|
||||||
|
|
||||||
/* force to classic sock family, not AF_CUST_* */
|
/* force to classic sock family, not AF_CUST_* */
|
||||||
addr_inet.ss_family = rx->proto->sock_family;
|
addr_inet.ss_family = rx->proto->fam->sock_family;
|
||||||
|
|
||||||
/* ensure we never return garbage */
|
/* ensure we never return garbage */
|
||||||
if (errmsg)
|
if (errmsg)
|
||||||
@ -289,7 +289,7 @@ int sock_inet_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
|
|||||||
ext = (fd >= 0);
|
ext = (fd >= 0);
|
||||||
|
|
||||||
if (!ext) {
|
if (!ext) {
|
||||||
fd = my_socketat(rx->settings->netns, rx->proto->sock_family,
|
fd = my_socketat(rx->settings->netns, rx->proto->fam->sock_domain,
|
||||||
rx->proto->sock_type, rx->proto->sock_prot);
|
rx->proto->sock_type, rx->proto->sock_prot);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
err |= ERR_RETRYABLE | ERR_ALERT;
|
err |= ERR_RETRYABLE | ERR_ALERT;
|
||||||
@ -367,7 +367,7 @@ int sock_inet_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!ext && bind(fd, (struct sockaddr *)&addr_inet, rx->proto->sock_addrlen) == -1) {
|
if (!ext && bind(fd, (struct sockaddr *)&addr_inet, rx->proto->fam->sock_addrlen) == -1) {
|
||||||
err |= ERR_RETRYABLE | ERR_ALERT;
|
err |= ERR_RETRYABLE | ERR_ALERT;
|
||||||
memprintf(errmsg, "cannot bind socket");
|
memprintf(errmsg, "cannot bind socket");
|
||||||
goto bind_close_return;
|
goto bind_close_return;
|
||||||
|
@ -218,7 +218,7 @@ int sock_unix_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
|
|||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
/* WT: shouldn't we use my_socketat(rx->netns) here instead ? */
|
/* WT: shouldn't we use my_socketat(rx->netns) here instead ? */
|
||||||
fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
fd = socket(rx->proto->fam->sock_domain, rx->proto->sock_type, rx->proto->sock_prot);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
err |= ERR_FATAL | ERR_ALERT;
|
err |= ERR_FATAL | ERR_ALERT;
|
||||||
memprintf(errmsg, "cannot create receiving socket");
|
memprintf(errmsg, "cannot create receiving socket");
|
||||||
|
Loading…
Reference in New Issue
Block a user