]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
qualify listener instance names a bit more cleanly
authorAlan T. DeKok <aland@freeradius.org>
Sun, 9 Feb 2025 17:10:22 +0000 (12:10 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 9 Feb 2025 17:14:05 +0000 (12:14 -0500)
which doesn't matter now, but may matter when we need to have
better debug messages about them.

raddb/sites-available/default
src/lib/server/virtual_servers.c

index e92792e6ad4c5eaa59c84f42766abf5508e17d32..5ab8278dacd467d0a877e73b244375d048d56bd5 100644 (file)
@@ -215,7 +215,14 @@ server default {
        #  order to make FreeRADIUS more flexible, and to make the
        #  configuration simpler and more consistent.
        #
-       listen {
+       #  If there are multiple `listen` sections in the same
+       #  virtual server, they need to be given a second name.
+       #
+       #  Listen sections are identified by virtual server name,
+       #  then by the namespace, then by transport, finally by
+       #  a second name.
+       #
+       listen authentication {
                #
                #  type:: The type of packet to accept.
                #
@@ -603,7 +610,7 @@ server default {
                }
        }
 
-       listen tcp_auth {
+       listen authentication {
                type = Access-Request
                type = Status-Server
 
@@ -660,7 +667,7 @@ server default {
        #
        #  ### Listen for Accounting-Request packets
        #
-       listen udp_acct {
+       listen accounting {
                type = Accounting-Request
 
                transport = udp
index 43956c8e38a7467c6ad7f5ec877997ee42803e1d..4cf8d2fc1cb6226b19b9122d8d70c48c3baed8a8 100644 (file)
@@ -378,17 +378,16 @@ static int namespace_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *paren
  *     - 0 on success.
  *     - -1 on failure.
  */
-static int listen_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
+static int listen_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
 {
        fr_virtual_listen_t     *listener = talloc_get_type_abort(out, fr_virtual_listen_t); /* Pre-allocated for us */
        CONF_SECTION            *listener_cs = cf_item_to_section(ci);
        CONF_SECTION            *server_cs = cf_item_to_section(cf_parent(ci));
        CONF_PAIR               *namespace = cf_pair_find(server_cs, "namespace");
 
-       CONF_PAIR               *proto;
-       char const              *mod_name;
-       char const              *inst_name;
-       char                    *qual_inst_name;
+       CONF_PAIR               *cp;
+       char const              *protocol, *transport, *name2;
+       char                    *inst_name;
 
        module_instance_t       *mi;
 
@@ -431,56 +430,52 @@ static int listen_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
         *      to be included in the server.
         *
         */
-       proto = cf_pair_find(listener_cs, "proto");
-       if (proto) {
-               mod_name = cf_pair_value(proto);
+       cp = cf_pair_find(listener_cs, "proto");
+       if (cp) {
+               protocol = cf_pair_value(cp);
+               if (!protocol) {
+                       cf_log_err(cp, "Missing value");
+                       return -1;
+               }
        } else {
-               mod_name = cf_pair_value(namespace);
+               protocol = cf_pair_value(namespace);
        }
 
+       name2 = cf_section_name2(listener_cs);
+
        /*
-        *      Inst name comes from the 'listen' name2
-        *      or from the module name.
-        *
-        *      The inst name is qualified with the name
-        *      of the server the listener appears in.
-        *
-        *      The following results in the instance name of 'foo.radius':
-        *
-        *      server foo {
-        *              namespace = radius
-        *              listen {
-        *
-        *              }
-        *      }
-        *
-        *      The following results in the instance name 'foo.my_network':
-        *
-        *      server foo {
-        *              namespace = radius
-        *              listen my_network {
-        *
-        *              }
-        *      }
+        *      As with almost everything else, the listeners are
+        *      modules.  Create a unique name for them.
+        */
+       cp = cf_pair_find(listener_cs, "transport");
+       if (cp && cf_pair_value(cp)) {
+               transport = cf_pair_value(cp);
+       } else {
+               transport = "generic";
+       }
+
+       /*
+        *      Instance names are default.radius.udp.foo, or default.radius.udp
         */
-       inst_name = cf_section_name2(listener_cs);
-       if (!inst_name) inst_name = mod_name;
+       if (name2) {
+               MEM(inst_name = talloc_asprintf(ctx, "%s.%s.%s.%s", cf_section_name2(server_cs),
+                                               protocol, transport, name2));
+       } else {
+               MEM(inst_name = talloc_asprintf(ctx, "%s.%s.%s", cf_section_name2(server_cs),
+                                               protocol, transport));
+       }
 
        if (module_instance_name_valid(inst_name) < 0) {
        error:
-               cf_log_err(listener_cs, "Failed loading listener");
+               cf_log_err(listener_cs, "Failed loading listen section.");
                return -1;
        }
-
-       MEM(qual_inst_name = talloc_asprintf(NULL, "%s.%s", cf_section_name2(server_cs), inst_name));
-       mi = module_instance_alloc(proto_modules, NULL, DL_MODULE_TYPE_PROTO, mod_name, qual_inst_name, 0);
-       talloc_free(qual_inst_name);
+       mi = module_instance_alloc(proto_modules, NULL, DL_MODULE_TYPE_PROTO, protocol, inst_name, 0);
+       talloc_free(inst_name);
        if (!mi) goto error;
 
        if (unlikely(module_instance_conf_parse(mi, listener_cs) < 0)) goto error;
 
-       if (DEBUG_ENABLED4) cf_log_debug(ci, "Loading %s listener into %p", inst_name, out);
-
        listener->proto_mi = mi;
        listener->proto_module = (fr_app_t const *)listener->proto_mi->module->exported;
        cf_data_add(listener_cs, mi, "proto_module", false);