]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: Make 'default-server' support 'send-proxy' and 'send-proxy-v2 keywords.
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 10 Mar 2017 15:40:00 +0000 (16:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Mar 2017 12:36:12 +0000 (14:36 +0200)
This patch makes 'default-server' directive support 'send-proxy'
(resp. 'send-proxy-v2') setting.
A new keyword 'no-send-proxy' (resp. 'no-send-proxy-v2') has been added
to disable 'send-proxy' (resp. 'send-proxy-v2') setting both in 'server' and
'default-server' directives.

src/server.c

index c5a4d31eec31109be76bad34681be7cb00508afe..ddb2842ee774c60bdf5c4bf8d2cc7f4e226bbfee 100644 (file)
@@ -277,6 +277,27 @@ static int srv_parse_no_check_send_proxy(char **args, int *cur_arg,
        return 0;
 }
 
+/* Disable server PROXY protocol flags. */
+static int inline srv_disable_pp_flags(struct server *srv, unsigned int flags)
+{
+       srv->pp_opts &= ~flags;
+       return 0;
+}
+
+/* Parse the "no-send-proxy" server keyword */
+static int srv_parse_no_send_proxy(char **args, int *cur_arg,
+                                   struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       return srv_disable_pp_flags(newsrv, SRV_PP_V1);
+}
+
+/* Parse the "no-send-proxy-v2" server keyword */
+static int srv_parse_no_send_proxy_v2(char **args, int *cur_arg,
+                                      struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       return srv_disable_pp_flags(newsrv, SRV_PP_V2);
+}
+
 /* Parse the "non-stick" server keyword */
 static int srv_parse_non_stick(char **args, int *cur_arg,
                                struct proxy *curproxy, struct server *newsrv, char **err)
@@ -285,6 +306,27 @@ static int srv_parse_non_stick(char **args, int *cur_arg,
        return 0;
 }
 
+/* Enable server PROXY protocol flags. */
+static int inline srv_enable_pp_flags(struct server *srv, unsigned int flags)
+{
+       srv->pp_opts |= flags;
+       return 0;
+}
+
+/* Parse the "send-proxy" server keyword */
+static int srv_parse_send_proxy(char **args, int *cur_arg,
+                                struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       return srv_enable_pp_flags(newsrv, SRV_PP_V1);
+}
+
+/* Parse the "send-proxy-v2" server keyword */
+static int srv_parse_send_proxy_v2(char **args, int *cur_arg,
+                                   struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       return srv_enable_pp_flags(newsrv, SRV_PP_V2);
+}
+
 /* Parse the "stick" server keyword */
 static int srv_parse_stick(char **args, int *cur_arg,
                            struct proxy *curproxy, struct server *newsrv, char **err)
@@ -907,7 +949,11 @@ static struct srv_kw_list srv_kws = { "ALL", { }, {
        { "id",                  srv_parse_id,                  1,  0 }, /* set id# of server */
        { "no-backup",           srv_parse_no_backup,           0,  1 }, /* Flag as non-backup server */
        { "no-check-send-proxy", srv_parse_no_check_send_proxy, 0,  1 }, /* disable PROXY protol for health checks */
+       { "no-send-proxy",       srv_parse_no_send_proxy,       0,  1 }, /* Disable use of PROXY V1 protocol */
+       { "no-send-proxy-v2",    srv_parse_no_send_proxy_v2,    0,  1 }, /* Disable use of PROXY V2 protocol */
        { "non-stick",           srv_parse_non_stick,           0,  1 }, /* Disable stick-table persistence */
+       { "send-proxy",          srv_parse_send_proxy,          0,  1 }, /* Enforce use of PROXY V1 protocol */
+       { "send-proxy-v2",       srv_parse_send_proxy_v2,       0,  1 }, /* Enforce use of PROXY V2 protocol */
        { "stick",               srv_parse_stick,               0,  1 }, /* Enable stick-table persistence */
        { NULL, NULL, 0 },
 }};
@@ -1196,6 +1242,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                goto out;
                        }
 
+                       newsrv->pp_opts         = curproxy->defsrv.pp_opts;
                        newsrv->use_ssl         = curproxy->defsrv.use_ssl;
                        newsrv->check.use_ssl   = curproxy->defsrv.check.use_ssl;
                        newsrv->check.port      = curproxy->defsrv.check.port;
@@ -1560,14 +1607,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                newsrv->flags |= SRV_F_CHECKPORT;
                                cur_arg += 2;
                        }
-                       else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) {
-                               newsrv->pp_opts |= SRV_PP_V1;
-                               cur_arg ++;
-                       }
-                       else if (!defsrv && !strcmp(args[cur_arg], "send-proxy-v2")) {
-                               newsrv->pp_opts |= SRV_PP_V2;
-                               cur_arg ++;
-                       }
                        else if (!strcmp(args[cur_arg], "weight")) {
                                int w;
                                w = atol(args[cur_arg + 1]);