]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: protocol: automatically pick the proto associated to the connection.
authorThierry FOURNIER <tfournier@haproxy.com>
Wed, 14 Jan 2015 10:31:49 +0000 (11:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Feb 2015 22:12:31 +0000 (23:12 +0100)
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
include/types/server.h
src/backend.c
src/checks.c
src/server.c

index 4b35d303bdae370e1fa57ce6b22fb9e6b75a8de8..3abebe106ca44f99c51f226484ef13a5fdab9ac8 100644 (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 */
 };
 
index 23bb2b7fcd3b597edd76f14aeb61db1bd3c969bf..f987e25b5e9452eb9a7051199ee4437c38a38d3a 100644 (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 */
index 721c12ad8332d9c12d6e88fc181a6ca73ebdf953..dbc6d068e924adab2e01f3159d7633c927dc3740 100644 (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 */
index 62a07219ac3cae9d46205335d587a25fa032d239..8a9eab5d1a8ba93aa08bee8eff5a551831941374 100644 (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;
        }
index 118a1ed995bbbfe49ce96c8023f1ff17651bef38..edd76708b5b15f3a8869afaa366beedf61629f9f 100644 (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")) {