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.
This commit is contained in:
Thierry FOURNIER 2015-01-14 11:31:49 +01:00 committed by Willy Tarreau
parent b550d009ca
commit bb2ae64b82
5 changed files with 12 additions and 18 deletions

View File

@ -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 */
};

View File

@ -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 */

View File

@ -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 */

View File

@ -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;
}

View File

@ -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")) {