]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listeners: Add support for a label on bind line
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 26 May 2025 05:38:11 +0000 (07:38 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 26 May 2025 17:00:00 +0000 (19:00 +0200)
It is now possile to set a label on a bind line. All sockets attached to
this bind line inherits from this label. The idea is to be able to groud of
sockets. For now, there is no mechanism to create these groups, this must be
done by hand.

doc/configuration.txt
include/haproxy/listener-t.h
src/listener.c
src/proxy.c

index cb94e2ff604317bc1fe67592dd0e0bb79f2412e5..832948ad4733948821a863e914bcc7a4fa472780 100644 (file)
@@ -16698,6 +16698,10 @@ interface <interface>
   client IP addresses need to be able to reach frontends hosted on different
   interfaces.
 
+label <label>
+  Sets an optional label for these sockets. It could be used group sockets by
+  label, independently of where the bind lines were declared.
+
 level <level>
   This setting is used with the stats sockets only to restrict the nature of
   the commands that can be issued on the socket. It is ignored by other
index b054b75a6bf7e9a4043f6e4aca75c594ee6780f3..70f6c4ed19f93f14768657571f435b2630ee841d 100644 (file)
@@ -244,7 +244,7 @@ struct listener {
        struct fe_counters *counters;   /* statistics counters */
        struct mt_list wait_queue;      /* link element to make the listener wait for something (LI_LIMITED)  */
        char *name;                     /* listener's name */
-
+       char *label;                    /* listener's label */
        unsigned int thr_conn[MAX_THREADS_PER_GROUP]; /* number of connections per thread for the group */
 
        struct list by_fe;              /* chaining in frontend's list of listeners */
index 73954a1982aca0ad0cf8d81e33208c96143e4b0a..a72251013323b5fd804fe86f5d350e51888b6a93 100644 (file)
@@ -932,6 +932,11 @@ struct listener *clone_listener(struct listener *src)
                if (!l->name)
                        goto oom2;
        }
+       if (l->label) {
+               l->label = strdup(l->label);
+               if (!l->label)
+                       goto oom3;
+       }
 
        l->rx.owner = l;
        l->rx.shard_info = NULL;
@@ -952,6 +957,8 @@ struct listener *clone_listener(struct listener *src)
        global.maxsock++;
        return l;
 
+ oom3:
+       free(l->name);
  oom2:
        free(l);
  oom1:
@@ -2422,6 +2429,28 @@ static int bind_parse_name(char **args, int cur_arg, struct proxy *px, struct bi
        return 0;
 }
 
+/* parse the "label" bind keyword */
+static int bind_parse_label(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
+{
+       struct listener *l;
+
+       if (!*args[cur_arg + 1]) {
+               memprintf(err, "'%s' : missing label", args[cur_arg]);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+       list_for_each_entry(l, &conf->listeners, by_bind) {
+               free(l->label);
+               l->label = strdup(args[cur_arg + 1]);
+               if (!l->label) {
+                       memprintf(err, "'%s %s' : out of memory", args[cur_arg], args[cur_arg + 1]);
+                       return ERR_ALERT | ERR_FATAL;
+               }
+       }
+
+       return 0;
+}
+
 /* parse the "nbconn" bind keyword */
 static int bind_parse_nbconn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
 {
@@ -2628,6 +2657,7 @@ static struct bind_kw_list bind_kws = { "ALL", { }, {
        { "guid-prefix",  bind_parse_guid_prefix,  1, 1 }, /* set guid of listening socket */
        { "id",           bind_parse_id,           1, 1 }, /* set id of listening socket */
        { "idle-ping",    bind_parse_idle_ping,    1, 1 }, /* activate idle ping if mux support it */
+       { "label",        bind_parse_label,        1, 1 }, /* set label of listening socket */
        { "maxconn",      bind_parse_maxconn,      1, 0 }, /* set maxconn of listening socket */
        { "name",         bind_parse_name,         1, 1 }, /* set name of listening socket */
        { "nbconn",       bind_parse_nbconn,       1, 1 }, /* set number of connection on active preconnect */
index 326ff3eb67df150b54f679b2261597f0b0c5c58b..5ce28274780b9f120dbe3a950df070fe07354cfd 100644 (file)
@@ -391,6 +391,7 @@ void deinit_proxy(struct proxy *p)
                LIST_DELETE(&l->by_fe);
                LIST_DELETE(&l->by_bind);
                free(l->name);
+               free(l->label);
                free(l->per_thr);
                free(l->counters);
                task_destroy(l->rx.rhttp.task);