From bb2ae64b82d0f06c64d687c75f05753a6d49cf66 Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Wed, 14 Jan 2015 11:31:49 +0100 Subject: [PATCH] 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. --- include/types/checks.h | 1 - include/types/server.h | 1 - src/backend.c | 2 +- src/checks.c | 22 ++++++++++------------ src/server.c | 4 +--- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/types/checks.h b/include/types/checks.h index 4b35d303b..3abebe106 100644 --- a/include/types/checks.h +++ b/include/types/checks.h @@ -180,7 +180,6 @@ struct check { 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 23bb2b7fc..f987e25b5 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -196,7 +196,6 @@ struct server { 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 721c12ad8..dbc6d068e 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1059,7 +1059,7 @@ int connect_server(struct session *s) /* 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 62a07219a..8a9eab5d1 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1440,29 +1440,29 @@ static int connect_conn_chk(struct task *t) /* 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 @@ static void tcpcheck_main(struct connection *conn) 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 @@ static int init_email_alert_checks(struct server *s) 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 118a1ed99..edd76708b 100644 --- a/src/server.c +++ b/src/server.c @@ -904,10 +904,9 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr } 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 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr } 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")) {