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.
diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h
index 05e85e1..876f557 100644
--- a/include/haproxy/connection.h
+++ b/include/haproxy/connection.h
@@ -534,13 +534,13 @@
if (conn->flags & CO_FL_ADDR_FROM_SET)
return 1;
- if (!conn_ctrl_ready(conn) || !conn->ctrl->get_src)
+ if (!conn_ctrl_ready(conn) || !conn->ctrl->fam->get_src)
return 0;
if (!sockaddr_alloc(&conn->src))
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),
obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
return 0;
@@ -557,13 +557,13 @@
if (conn->flags & CO_FL_ADDR_TO_SET)
return 1;
- if (!conn_ctrl_ready(conn) || !conn->ctrl->get_dst)
+ if (!conn_ctrl_ready(conn) || !conn->ctrl->fam->get_dst)
return 0;
if (!sockaddr_alloc(&conn->dst))
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),
obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
return 0;
diff --git a/src/protocol.c b/src/protocol.c
index a4e93e2..7485870 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -82,7 +82,7 @@
handler = syslog_fd_handler;
}
- lerr = proto->bind(receiver, handler, &errmsg);
+ lerr = proto->fam->bind(receiver, handler, &errmsg);
err |= lerr;
/* errors are reported if <verbose> is set or if they are fatal */
diff --git a/src/sock.c b/src/sock.c
index 9431e75..3e414a8 100644
--- a/src/sock.c
+++ b/src/sock.c
@@ -363,7 +363,7 @@
int ns_namelen = 0;
int ret = -1;
- if (!rx->proto->addrcmp)
+ if (!rx->proto->fam->addrcmp)
return -1;
if (rx->proto->sock_type == SOCK_DGRAM)
@@ -397,7 +397,7 @@
#ifdef USE_NS
(!ns_namelen || strcmp(rx->settings->netns->node.key, xfer_sock->namespace) == 0) &&
#endif
- rx->proto->addrcmp(&xfer_sock->addr, &rx->addr) == 0)
+ rx->proto->fam->addrcmp(&xfer_sock->addr, &rx->addr) == 0)
break;
xfer_sock = xfer_sock->next;
}
diff --git a/src/sock_inet.c b/src/sock_inet.c
index 09ff71e..7c814d0 100644
--- a/src/sock_inet.c
+++ b/src/sock_inet.c
@@ -263,7 +263,7 @@
struct sockaddr_storage addr_inet = rx->addr;
/* 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 */
if (errmsg)
@@ -289,7 +289,7 @@
ext = (fd >= 0);
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);
if (fd == -1) {
err |= ERR_RETRYABLE | ERR_ALERT;
@@ -367,7 +367,7 @@
}
#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;
memprintf(errmsg, "cannot bind socket");
goto bind_close_return;
diff --git a/src/sock_unix.c b/src/sock_unix.c
index 4620b74..8bdfed9 100644
--- a/src/sock_unix.c
+++ b/src/sock_unix.c
@@ -218,7 +218,7 @@
addr.sun_family = AF_UNIX;
/* 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) {
err |= ERR_FATAL | ERR_ALERT;
memprintf(errmsg, "cannot create receiving socket");