]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Start removing stupid inst->name boilerplate from all the modules
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 2 Sep 2019 03:59:55 +0000 (23:59 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 2 Sep 2019 03:59:55 +0000 (23:59 -0400)
src/lib/server/dl_module.c
src/lib/server/dl_module.h
src/modules/rlm_always/rlm_always.c

index 8e75c6fcf39e6c90d4a0912ea8dd0c914ee5247d..42bfe66129ccd678b497157bed2aeb4c9d88817c 100644 (file)
@@ -52,6 +52,16 @@ struct dl_module_loader_s {
 
 static dl_module_loader_t      *dl_module_loader;
 
+/** Make data to instance name resolution more efficient
+ *
+ */
+typedef struct {
+       void                    *data;          //!< Module's data.
+       dl_module_inst_t        *inst;          //!< Instance wrapper struct.
+} dl_module_inst_cache_t;
+
+static _Thread_local dl_module_inst_cache_t    dl_inst_cache;
+
 /** Modules which need RTLD_GLOBAL set
  *
  */
@@ -190,9 +200,24 @@ dl_module_inst_t const *dl_module_instance_by_data(void const *data)
 
        memcpy(&mutable, &data, sizeof(mutable));
 
+       if (dl_inst_cache.data == data) return dl_inst_cache.inst;
+
        return rbtree_finddata(dl_module_loader->inst_data_tree, &(dl_module_inst_t){ .data = mutable });
 }
 
+/** Lookup instance name via instance data
+ *
+ */
+char const *dl_module_instance_name_by_data(void const *data)
+{
+       dl_module_inst_t const *inst;
+
+       inst = dl_module_instance_by_data(data);
+       if (!inst) return NULL;
+
+       return inst->name;
+}
+
 /** A convenience function for returning a parent's private data
  *
  * @param[in] data     Private instance data for child.
@@ -319,7 +344,8 @@ dl_module_t const *dl_module(CONF_SECTION *conf, dl_module_t const *parent, char
 
        if (parent) {
                module_name = talloc_typed_asprintf(NULL, "%s_%s_%s",
-                                                   fr_table_str_by_value(dl_module_type_prefix, parent->type, "<INVALID>"),
+                                                   fr_table_str_by_value(dl_module_type_prefix,
+                                                                         parent->type, "<INVALID>"),
                                                    parent->common->name, name);
        } else {
                module_name = talloc_typed_asprintf(NULL, "%s_%s",
index e9438fecac99a59de0683608c4b5d43a81d0ffdb..ceb93322f167725a01b96ea048aa0ef789acf0df 100644 (file)
@@ -162,6 +162,8 @@ dl_module_t const   *dl_module(CONF_SECTION *conf, dl_module_t const *parent,
 
 dl_module_inst_t const *dl_module_instance_by_data(void const *data);
 
+char const             *dl_module_instance_name_by_data(void const *data);
+
 void                   *dl_module_parent_data_by_child_data(void const *data);
 
 void                   *dl_module_instance_symbol(dl_module_inst_t const *instance, char const *sym_name);
index 13d903216da9c280635b719f7152e839356b0874..57bdfb20c55877822fa0e4898a7ca911bd1a1077 100644 (file)
@@ -25,7 +25,7 @@
 RCSID("$Id$")
 
 #define LOG_PREFIX "rlm_always (%s) - "
-#define LOG_PREFIX_ARGS inst->name
+#define LOG_PREFIX_ARGS dl_module_instance_name_by_data(inst)
 
 #include <freeradius-devel/server/base.h>
 #include <freeradius-devel/server/module.h>
@@ -35,7 +35,6 @@ RCSID("$Id$")
  *     going to return.
  */
 typedef struct {
-       char const      *name;          //!< Name of this instance of the always module.
        char const      *rcode_str;     //!< The base value.
 
        rlm_rcode_t     rcode;          //!< The integer constant representing rcode_str.
@@ -57,8 +56,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
 {
        rlm_always_t *inst = instance;
 
-       inst->name = cf_section_name1(conf);
-       if (!inst->name) inst->name = cf_section_name2(conf);
        /*
         *      Convert the rcode string to an int
         */