]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Check uniqness of SPOE engine names during config parsing
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 19 Sep 2017 09:08:28 +0000 (11:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 10:36:12 +0000 (11:36 +0100)
The engine name is now kept in "spoe_config" struture. Because a SPOE filter can
be declared without engine name, we use the SPOE agent name by default. Then,
its uniqness is checked against all others SPOE engines configured for the same
proxy.

  * TODO: Add documentation

doc/SPOE.txt
include/types/spoe.h
src/flt_spoe.c

index 611b22878698bb0516e17e8cce873751564a144b..48cfa021f7e18c4685bfa9e2703c01032daee378 100644 (file)
@@ -140,6 +140,9 @@ If no engine name is provided on the SPOE filter line, no SPOE scope must be
 found in the SPOE configuration file. All the file is considered to be in the
 same anonymous and implicit scope.
 
+The engine name must be uniq for a proxy. If no engine name is provided on the
+SPOE filter line, the SPOE agent name is unsed by default.
+
 2.2. "spoe-agent" section
 --------------------------
 
index 193c2f64b8a690d2426b80247669aab380ce4575..2d94e36ecc4a8fc6ec99bd08976f65b625f389e1 100644 (file)
@@ -237,6 +237,8 @@ struct spoe_agent {
 
 /* SPOE filter configuration */
 struct spoe_config {
+       char              *id;          /* The SPOE engine name. If undefined in HAProxy config,
+                                        * it will be set with the SPOE agent name */
        struct proxy      *proxy;       /* Proxy owning the filter */
        struct spoe_agent *agent;       /* Agent used by this filter */
        struct proxy       agent_fe;    /* Agent frontend */
index dbc9d30755bf79eb998d0755306c42a0071db062..44e67243c5027af73a8825fa44402270d01d950c 100644 (file)
@@ -2745,6 +2745,7 @@ spoe_deinit(struct proxy *px, struct flt_conf *fconf)
                struct spoe_agent *agent = conf->agent;
 
                spoe_release_agent(agent);
+               free(conf->id);
                free(conf);
        }
        fconf->conf = NULL;
@@ -2755,9 +2756,30 @@ spoe_deinit(struct proxy *px, struct flt_conf *fconf)
 static int
 spoe_check(struct proxy *px, struct flt_conf *fconf)
 {
+       struct flt_conf    *f;
        struct spoe_config *conf = fconf->conf;
        struct proxy       *target;
 
+       /* Check all SPOE filters for proxy <px> to be sure all SPOE agent names
+        * are uniq */
+       list_for_each_entry(f, &px->filter_configs, list) {
+               struct spoe_config *c = f->conf;
+
+               /* This is not an SPOE filter */
+               if (f->id != spoe_filter_id)
+                       continue;
+               /* This is the current SPOE filter */
+               if (f == fconf)
+                       continue;
+
+               /* Check engine Id. It should be uniq */
+               if (!strcmp(conf->id, c->id)) {
+                       Alert("Proxy %s : duplicated name for SPOE engine '%s'.\n",
+                             px->id, conf->id);
+                       return 1;
+               }
+       }
+
        target = proxy_be_by_name(conf->agent->b.name);
        if (target == NULL) {
                Alert("Proxy %s : unknown backend '%s' used by SPOE agent '%s'"
@@ -3707,6 +3729,7 @@ parse_spoe_flt(char **args, int *cur_arg, struct proxy *px,
        }
 
  finish:
+       conf->id    = strdup(engine ? engine : curagent->id);
        conf->agent = curagent;
        list_for_each_entry_safe(mp, mpback, &curmps, list) {
                LIST_DEL(&mp->list);