MEDIUM: protocol: automatically pick the proto associated to the connection.
When the destination IP is dynamically set, we can't use the "target"
to define the proto. This patch ensures that we always use the protocol
associated with the address family. The proto field was removed from
the server and check structs.
diff --git a/include/types/checks.h b/include/types/checks.h
index 4b35d30..3abebe1 100644
--- a/include/types/checks.h
+++ b/include/types/checks.h
@@ -180,7 +180,6 @@
char **argv; /* the arguments to use if running a process-based check */
char **envp; /* the environment to use if running a process-based check */
struct pid_list *curpid; /* entry in pid_list used for current process-based test, or -1 if not in test */
- struct protocol *proto; /* server address protocol for health checks */
struct sockaddr_storage addr; /* the address to check */
};
diff --git a/include/types/server.h b/include/types/server.h
index 23bb2b7..f987e25 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -196,7 +196,6 @@
const struct netns_entry *netns; /* contains network namespace name or NULL. Network namespace comes from configuration */
/* warning, these structs are huge, keep them at the bottom */
struct sockaddr_storage addr; /* the address to connect to */
- struct protocol *proto; /* server address protocol */
struct xprt_ops *xprt; /* transport-layer operations */
unsigned down_time; /* total time the server was down */
time_t last_change; /* last time, when the state was changed */
diff --git a/src/backend.c b/src/backend.c
index 721c12a..dbc6d06 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1059,7 +1059,7 @@
/* set the correct protocol on the output stream interface */
if (objt_server(s->target)) {
- conn_prepare(srv_conn, objt_server(s->target)->proto, objt_server(s->target)->xprt);
+ conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), objt_server(s->target)->xprt);
}
else if (obj_type(s->target) == OBJ_TYPE_PROXY) {
/* proxies exclusively run on raw_sock right now */
diff --git a/src/checks.c b/src/checks.c
index 62a0721..8a9eab5 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -1440,29 +1440,29 @@
/* prepare a new connection */
conn_init(conn);
- conn_prepare(conn, check->proto, check->xprt);
- conn_attach(conn, check, &check_conn_cb);
- conn->target = &s->obj_type;
-
- /* no client address */
- clear_addr(&conn->addr.from);
if (is_addr(&check->addr)) {
-
/* we'll connect to the check addr specified on the server */
conn->addr.to = check->addr;
- proto = check->proto;
}
else {
/* we'll connect to the addr on the server */
conn->addr.to = s->addr;
- proto = s->proto;
}
if (check->port) {
set_host_port(&conn->addr.to, check->port);
}
+ proto = protocol_by_family(conn->addr.to.ss_family);
+
+ conn_prepare(conn, proto, check->xprt);
+ conn_attach(conn, check, &check_conn_cb);
+ conn->target = &s->obj_type;
+
+ /* no client address */
+ clear_addr(&conn->addr.from);
+
/* only plain tcp-check supports quick ACK */
quickack = check->type == 0 || check->type == PR_O2_TCPCHK_CHK;
@@ -2504,13 +2504,12 @@
if (is_addr(&check->addr)) {
/* we'll connect to the check addr specified on the server */
conn->addr.to = check->addr;
- proto = check->proto;
}
else {
/* we'll connect to the addr on the server */
conn->addr.to = s->addr;
- proto = s->proto;
}
+ proto = protocol_by_family(conn->addr.to.ss_family);
/* port */
if (check->current_step->port)
@@ -2908,7 +2907,6 @@
if (!get_host_port(&mailer->addr))
/* Default to submission port */
check->port = 587;
- check->proto = mailer->proto;
check->addr = mailer->addr;
check->server = s;
}
diff --git a/src/server.c b/src/server.c
index 118a1ed..edd7670 100644
--- a/src/server.c
+++ b/src/server.c
@@ -904,10 +904,9 @@
}
newsrv->addr = *sk;
- newsrv->proto = newsrv->check.proto = newsrv->agent.proto = protocol_by_family(newsrv->addr.ss_family);
newsrv->xprt = newsrv->check.xprt = newsrv->agent.xprt = &raw_sock;
- if (!newsrv->proto) {
+ if (!protocol_by_family(newsrv->addr.ss_family)) {
Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n",
file, linenum, newsrv->addr.ss_family, args[2]);
err_code |= ERR_ALERT | ERR_FATAL;
@@ -1114,7 +1113,6 @@
}
newsrv->check.addr = newsrv->agent.addr = *sk;
- newsrv->check.proto = newsrv->agent.proto = protocol_by_family(sk->ss_family);
cur_arg += 2;
}
else if (!strcmp(args[cur_arg], "port")) {