Remove redundant connection pool indirection in rlm_sql
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 14 Nov 2014 21:46:04 +0000 (16:46 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 14 Nov 2014 21:46:04 +0000 (16:46 -0500)
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/rlm_sql.h
src/modules/rlm_sql/sql.c
src/modules/rlm_sqlhpwippool/rlm_sqlhpwippool.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index f49dc76..7471ce6 100644 (file)
@@ -165,7 +165,7 @@ static ssize_t sql_xlat(void *instance, REQUEST *request, char const *query, cha
         */
        sql_set_user(inst, request, NULL);
 
-       handle = sql_get_socket(inst);
+       handle = fr_connection_get(inst->pool);
        if (!handle) {
                return 0;
        }
@@ -274,7 +274,7 @@ static ssize_t sql_xlat(void *instance, REQUEST *request, char const *query, cha
        (inst->module->sql_finish_select_query)(handle, inst->config);
 
 finish:
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
 
        return ret;
 }
@@ -292,7 +292,7 @@ static int generate_sql_clients(rlm_sql_t *inst)
        DEBUG("rlm_sql (%s) in generate_sql_clients: query is %s",
              inst->config->xlat_name, inst->config->client_query);
 
-       handle = sql_get_socket(inst);
+       handle = fr_connection_get(inst->pool);
        if (!handle) {
                return -1;
        }
@@ -364,7 +364,7 @@ static int generate_sql_clients(rlm_sql_t *inst)
        }
 
        (inst->module->sql_finish_select_query)(handle, inst->config);
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
 
        return 0;
 }
@@ -577,7 +577,7 @@ static int CC_HINT(nonnull (1, 2, 4)) sql_groupcmp(void *instance, REQUEST *requ
        /*
         *      Get a socket for this lookup
         */
-       handle = sql_get_socket(inst);
+       handle = fr_connection_get(inst->pool);
        if (!handle) {
                return 1;
        }
@@ -587,7 +587,7 @@ static int CC_HINT(nonnull (1, 2, 4)) sql_groupcmp(void *instance, REQUEST *requ
         */
        if (sql_get_grouplist(inst, &handle, request, &head) < 0) {
                REDEBUG("Error getting group membership");
-               sql_release_socket(inst, handle);
+               fr_connection_release(inst->pool, handle);
                return 1;
        }
 
@@ -596,14 +596,14 @@ static int CC_HINT(nonnull (1, 2, 4)) sql_groupcmp(void *instance, REQUEST *requ
                        RDEBUG("sql_groupcmp finished: User is a member of group %s",
                               check->vp_strvalue);
                        talloc_free(head);
-                       sql_release_socket(inst, handle);
+                       fr_connection_release(inst->pool, handle);
                        return 0;
                }
        }
 
        /* Free the grouplist */
        talloc_free(head);
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
 
        RDEBUG("sql_groupcmp finished: User is NOT a member of group %s", check->vp_strvalue);
 
@@ -748,9 +748,7 @@ static int mod_detach(void *instance)
 {
        rlm_sql_t *inst = instance;
 
-       if (inst->config) {
-               if (inst->pool) sql_poolfree(inst);
-       }
+       if (inst->config) if (inst->pool) fr_connection_pool_delete(inst->pool);
 
        if (inst->handle) {
 #if 0
@@ -841,8 +839,6 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
         *      Export these methods, too.  This avoids RTDL_GLOBAL.
         */
        inst->sql_set_user              = sql_set_user;
-       inst->sql_get_socket            = sql_get_socket;
-       inst->sql_release_socket        = sql_release_socket;
        inst->sql_escape_func           = sql_escape_func;
        inst->sql_query                 = rlm_sql_query;
        inst->sql_select_query          = rlm_sql_select_query;
@@ -919,7 +915,8 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
         */
        INFO("rlm_sql (%s): Attempting to connect to database \"%s\"", inst->config->xlat_name, inst->config->sql_db);
 
-       if (sql_socket_pool_init(inst) < 0) return -1;
+       inst->pool = fr_connection_pool_module_init(inst->cs, inst, mod_conn_create, NULL, NULL);
+       if (!inst->pool) return -1;
 
        if (inst->config->groupmemb_query &&
            inst->config->groupmemb_query[0]) {
@@ -980,7 +977,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, REQUEST *reque
         *      After this point use goto error or goto release to cleanup socket temporary pairlists and
         *      temporary attributes.
         */
-       handle = sql_get_socket(inst);
+       handle = fr_connection_get(inst->pool);
        if (!handle) {
                rcode = RLM_MODULE_FAIL;
                goto error;
@@ -1167,7 +1164,7 @@ release:
                rcode = RLM_MODULE_NOTFOUND;
        }
 
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
        sql_unset_user(inst, request);
 
        return rcode;
@@ -1177,7 +1174,7 @@ error:
        pairfree(&reply_tmp);
        sql_unset_user(inst, request);
 
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
 
        return rcode;
 }
@@ -1240,7 +1237,7 @@ static int acct_redundant(rlm_sql_t *inst, REQUEST *request, sql_acct_section_t
 
        RDEBUG2("Using query template '%s'", attr);
 
-       handle = sql_get_socket(inst);
+       handle = fr_connection_get(inst->pool);
        if (!handle) {
                rcode = RLM_MODULE_FAIL;
 
@@ -1281,7 +1278,7 @@ static int acct_redundant(rlm_sql_t *inst, REQUEST *request, sql_acct_section_t
                 *
                 *  If we get RLM_SQL_RECONNECT it means all connections in the pool
                 *  were exhausted, and we couldn't create a new connection,
-                *  so we do not need to call sql_release_socket.
+                *  so we do not need to call fr_connection_release.
                 */
                sql_ret = rlm_sql_query(&handle, inst, expanded);
                TALLOC_FREE(expanded);
@@ -1329,7 +1326,7 @@ static int acct_redundant(rlm_sql_t *inst, REQUEST *request, sql_acct_section_t
 
 finish:
        talloc_free(expanded);
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
        sql_unset_user(inst, request);
 
        return rcode;
@@ -1399,7 +1396,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_checksimul(void *instance, REQUEST * req
        }
 
        /* initialize the sql socket */
-       handle = sql_get_socket(inst);
+       handle = fr_connection_get(inst->pool);
        if (!handle) {
                talloc_free(expanded);
                sql_unset_user(inst, request);
@@ -1548,7 +1545,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_checksimul(void *instance, REQUEST * req
        finish:
 
        (inst->module->sql_finish_select_query)(handle, inst->config);
-       sql_release_socket(inst, handle);
+       fr_connection_release(inst->pool, handle);
        talloc_free(expanded);
        sql_unset_user(inst, request);
 
index 31dd107..ba9b969 100644 (file)
@@ -139,8 +139,6 @@ struct sql_inst {
        rlm_sql_module_t *module;
 
        int (*sql_set_user)(rlm_sql_t *inst, REQUEST *request, char const *username);
-       rlm_sql_handle_t *(*sql_get_socket)(rlm_sql_t *inst);
-       int (*sql_release_socket)(rlm_sql_t *inst, rlm_sql_handle_t *handle);
        size_t (*sql_escape_func)(REQUEST *, char *out, size_t outlen, char const *in, void *arg);
        sql_rcode_t (*sql_query)(rlm_sql_handle_t **handle, rlm_sql_t *inst, char const *query);
        sql_rcode_t (*sql_select_query)(rlm_sql_handle_t **handle, rlm_sql_t *inst, char const *query);
@@ -152,11 +150,7 @@ typedef struct sql_grouplist {
        struct sql_grouplist    *next;
 } rlm_sql_grouplist_t;
 
-int            sql_socket_pool_init(rlm_sql_t *inst);
-void           sql_poolfree(rlm_sql_t *inst);
-int            sql_close_socket(rlm_sql_t *inst, rlm_sql_handle_t *handle);
-rlm_sql_handle_t *sql_get_socket(rlm_sql_t *inst);
-int            sql_release_socket(rlm_sql_t *inst, rlm_sql_handle_t *handle);
+void           *mod_conn_create(TALLOC_CTX *ctx, void *instance);
 int            sql_userparse(TALLOC_CTX *ctx, VALUE_PAIR **first_pair, rlm_sql_row_t row);
 int            sql_read_realms(rlm_sql_handle_t *handle);
 int            sql_getvpdata(TALLOC_CTX *ctx, rlm_sql_t *inst, rlm_sql_handle_t **handle, VALUE_PAIR **pair, char const *query);
index 53d10e1..126dc4f 100644 (file)
@@ -39,7 +39,7 @@ RCSID("$Id$")
 #ifdef HAVE_PTHREAD_H
 #endif
 
-static int _sql_conn_free(rlm_sql_handle_t *conn)
+static int _mod_conn_free(rlm_sql_handle_t *conn)
 {
        rlm_sql_t *inst = conn->inst;
 
@@ -50,7 +50,7 @@ static int _sql_conn_free(rlm_sql_handle_t *conn)
        return 0;
 }
 
-static void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
 {
        int rcode;
        rlm_sql_t *inst = instance;
@@ -75,7 +75,7 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
         *      Then we call our destructor to trigger an modules.sql.close
         *      event, then all the memory is freed.
         */
-       talloc_set_destructor(handle, _sql_conn_free);
+       talloc_set_destructor(handle, _mod_conn_free);
 
        rcode = (inst->module->sql_socket_init)(handle, inst->config);
        if (rcode != 0) {
@@ -102,60 +102,6 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance)
 
 /*************************************************************************
  *
- *     Function: sql_socket_pool_init
- *
- *     Purpose: Connect to the sql server, if possible
- *
- *************************************************************************/
-int sql_socket_pool_init(rlm_sql_t * inst)
-{
-       inst->pool = fr_connection_pool_module_init(inst->cs, inst, mod_conn_create, NULL, NULL);
-       if (!inst->pool) return -1;
-
-       return 1;
-}
-
-/*************************************************************************
- *
- *     Function: sql_poolfree
- *
- *     Purpose: Clean up and free sql pool
- *
- *************************************************************************/
-void sql_poolfree(rlm_sql_t * inst)
-{
-       fr_connection_pool_delete(inst->pool);
-}
-
-
-/*************************************************************************
- *
- *     Function: sql_get_socket
- *
- *     Purpose: Return a SQL handle from the connection pool
- *
- *************************************************************************/
-rlm_sql_handle_t * sql_get_socket(rlm_sql_t * inst)
-{
-       return fr_connection_get(inst->pool);
-}
-
-/*************************************************************************
- *
- *     Function: sql_release_socket
- *
- *     Purpose: Frees a SQL handle back to the connection pool
- *
- *************************************************************************/
-int sql_release_socket(rlm_sql_t * inst, rlm_sql_handle_t * handle)
-{
-       fr_connection_release(inst->pool, handle);
-       return 0;
-}
-
-
-/*************************************************************************
- *
  *     Function: sql_userparse
  *
  *     Purpose: Read entries from the database and fill VALUE_PAIR structures
index 2063591..738ee45 100644 (file)
@@ -53,7 +53,7 @@ RCSID("$Id$");
 
 typedef struct rlm_sqlhpwippool_t {
        char const *myname;                     //!< Name of this instance
-       rlm_sql_t *sqlinst;
+       rlm_sql_t *sql_inst;
        rlm_sql_module_t *db;
 #ifdef HAVE_PTHREAD_D
        pthread_mutex_t mutex;                  //!< Used "with" sync_after
@@ -106,9 +106,9 @@ static int nvp_vquery(unsigned int line, rlm_sqlhpwippool_t *data,
 {
        char query[MAX_QUERY_LEN];
        vsnprintf(query, MAX_QUERY_LEN, fmt, ap);
-       if (rlm_sql_query(&sqlsock, data->sqlinst, query)) {
+       if (rlm_sql_query(&sqlsock, data->sql_inst, query)) {
                nvp_log(__LINE__, data, L_ERR, "nvp_vquery(): query from line %u: %s",
-                       line, (char const *)(data->db->sql_error)(sqlsock, data->sqlinst->config));
+                       line, (char const *)(data->db->sql_error)(sqlsock, data->sql_inst->config));
                return 0;
        }
 
@@ -133,7 +133,7 @@ static int nvp_query(unsigned int line, rlm_sqlhpwippool_t *data,
 /* handy wrapper around data->db->sql_finish_query() */
 static int nvp_finish(rlm_sqlhpwippool_t *data, rlm_sql_handle_t *sqlsock)
 {
-       return (data->db->sql_finish_query)(sqlsock, data->sqlinst->config);
+       return (data->db->sql_finish_query)(sqlsock, data->sql_inst->config);
 }
 
 /* executes query and fetches first row
@@ -152,20 +152,20 @@ static int nvp_select(unsigned int line, rlm_sqlhpwippool_t *data,
        }
        va_end(ap);
 
-       if ((data->db->sql_store_result)(sqlsock, data->sqlinst->config)) {
+       if ((data->db->sql_store_result)(sqlsock, data->sql_inst->config)) {
                nvp_log(__LINE__, data, L_ERR,
                        "nvp_select(): error while saving results of query from line %u",
                        line);
                return 0;
        }
 
-       if ((data->db->sql_num_rows)(sqlsock, data->sqlinst->config) < 1) {
+       if ((data->db->sql_num_rows)(sqlsock, data->sql_inst->config) < 1) {
                nvp_log(__LINE__, data, L_DBG,
                        "nvp_select(): no results in query from line %u", line);
                return -1;
        }
 
-       if ((data->db->sql_fetch_row)(sqlsock, data->sqlinst->config)) {
+       if ((data->db->sql_fetch_row)(sqlsock, data->sql_inst->config)) {
                nvp_log(__LINE__, data, L_ERR, "nvp_select(): couldn't fetch row "
                                               "from results of query from line %u",
                        line);
@@ -177,7 +177,7 @@ static int nvp_select(unsigned int line, rlm_sqlhpwippool_t *data,
 
 static int nvp_select_finish(rlm_sqlhpwippool_t *data, rlm_sql_handle_t *sqlsock)
 {
-       return ((data->db->sql_free_result)(sqlsock, data->sqlinst->config) ||
+       return ((data->db->sql_free_result)(sqlsock, data->sql_inst->config) ||
                nvp_finish(data, sqlsock));
 }
 
@@ -232,7 +232,7 @@ static int nvp_cleanup(rlm_sqlhpwippool_t *data)
        rlm_sql_handle_t *sqlsock;
 
        /* initialize the SQL socket */
-       sqlsock = sql_get_socket(data->sqlinst);
+       sqlsock = fr_connection_get(data->sql_inst->pool);
        if (!sqlsock) {
                nvp_log(__LINE__, data, L_ERR, "nvp_cleanup(): error while "
                                               "requesting new SQL connection");
@@ -241,7 +241,7 @@ static int nvp_cleanup(rlm_sqlhpwippool_t *data)
 
        /* free IPs of closed sessions */
        if (!nvp_freeclosed(data, sqlsock)) {
-               sql_release_socket(data->sqlinst, sqlsock);
+               fr_connection_release(data->sql_inst->pool, sqlsock);
                return 0;
        }
 
@@ -262,7 +262,7 @@ static int nvp_cleanup(rlm_sqlhpwippool_t *data)
                                "`ips`.`rsv_until` != 0"   /* no acct pkt received yet */
                        ")",
            data->db_name)) {
-               sql_release_socket(data->sqlinst, sqlsock);
+               fr_connection_release(data->sql_inst->pool, sqlsock);
                return 0;
        }
        else {
@@ -271,11 +271,11 @@ static int nvp_cleanup(rlm_sqlhpwippool_t *data)
 
        /* count number of free IP addresses in IP pools */
        if (!nvp_syncfree(data, sqlsock)) {
-               sql_release_socket(data->sqlinst, sqlsock);
+               fr_connection_release(data->sql_inst->pool, sqlsock);
                return 0;
        }
 
-       sql_release_socket(data->sqlinst, sqlsock);
+       fr_connection_release(data->sql_inst->pool, sqlsock);
        return 1;
 }
 
@@ -283,7 +283,7 @@ static int nvp_cleanup(rlm_sqlhpwippool_t *data)
 static int mod_instantiate(CONF_SECTION *conf, void *instance)
 {
        rlm_sqlhpwippool_t *inst = instance;
-       module_instance_t *sqlinst;
+       module_instance_t *sql_inst;
 
        /* save my name */
        inst->myname = cf_section_name2(conf);
@@ -293,8 +293,8 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
 
        inst->sincesync = 0;
 
-       sqlinst = find_module_instance(cf_section_find("modules"), (inst->sql_module_instance), true);
-       if (!sqlinst) {
+       sql_inst = find_module_instance(cf_section_find("modules"), (inst->sql_module_instance), true);
+       if (!sql_inst) {
                nvp_log(__LINE__, inst, L_ERR,
                        "mod_instantiate(): cannot find module instance "
                        "named \"%s\"",
@@ -303,7 +303,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        }
 
        /* check if the given instance is really a rlm_sql instance */
-       if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) {
+       if (strcmp(sql_inst->entry->name, "rlm_sql") != 0) {
                nvp_log(__LINE__, inst, L_ERR,
                        "mod_instantiate(): given instance (%s) is not "
                        "an instance of the rlm_sql module",
@@ -312,8 +312,8 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        }
 
        /* save pointers to useful "objects" */
-       inst->sqlinst = (rlm_sql_t *) sqlinst->insthandle;
-       inst->db = (rlm_sql_module_t *) inst->sqlinst->module;
+       inst->sql_inst = (rlm_sql_t *) sql_inst->insthandle;
+       inst->db = (rlm_sql_module_t *) inst->sql_inst->module;
 
        return ((nvp_cleanup(inst)) ? 0 : -1);
 }
@@ -372,7 +372,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
        }
 
        /* get our database connection */
-       sqlsock = sql_get_socket(inst->sqlinst);
+       sqlsock = fr_connection_get(inst->sql_inst->pool);
        if (!sqlsock) {
                nvp_log(__LINE__, inst, L_ERR,
                        "mod_post_auth(): error while requesting an SQL socket");
@@ -383,7 +383,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
        if (nvp_select(__LINE__, inst, sqlsock, "SELECT CONNECTION_ID()") < 1) {
                nvp_log(__LINE__, inst, L_ERR, "mod_post_auth(): WTF ;-)!");
                nvp_select_finish(inst, sqlsock);
-               sql_release_socket(inst->sqlinst, sqlsock);
+               fr_connection_release(inst->sql_inst->pool, sqlsock);
                return RLM_MODULE_FAIL;
        }
 
@@ -412,7 +412,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                if (!r) {
                        nvp_log(__LINE__, inst, L_ERR,
                                "mod_post_auth(): synchronization failed");
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
        }
@@ -444,7 +444,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                        goto end_gid;             /* exit the main loop */
 
                case 0:
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
 
@@ -487,7 +487,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                                goto end_prio;         /* select next gid */
 
                        case 0:
-                               sql_release_socket(inst->sqlinst, sqlsock);
+                               fr_connection_release(inst->sql_inst->pool, sqlsock);
                                return RLM_MODULE_FAIL;
                        }
 
@@ -534,7 +534,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                                        goto end_pid;         /* select next prio */
 
                                case 0:
-                                       sql_release_socket(inst->sqlinst, sqlsock);
+                                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                                        return RLM_MODULE_FAIL;
                                }
 
@@ -561,7 +561,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                                        "ORDER BY RAND() "
                                        "LIMIT 1",
                                    inst->db_name, pid, connid, inst->free_after, ip_start, ip_stop)) {
-                                       sql_release_socket(inst->sqlinst, sqlsock);
+                                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                                        return RLM_MODULE_FAIL;
                                }
                                else {
@@ -584,7 +584,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                                        continue;                           /* select next pid */
 
                                case 0:
-                                       sql_release_socket(inst->sqlinst, sqlsock);
+                                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                                        return RLM_MODULE_FAIL;
                                }
 
@@ -597,7 +597,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                                                "`pid` = %lu "
                                "LIMIT 1",
                                    inst->db_name, pid)) {
-                                       sql_release_socket(inst->sqlinst, sqlsock);
+                                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                                        return RLM_MODULE_FAIL;
                                }
                                else {
@@ -615,7 +615,7 @@ end_prio: continue;   /* stupid */
 end_gid:
 
        /* release SQL socket */
-       sql_release_socket(inst->sqlinst, sqlsock);
+       fr_connection_release(inst->sql_inst->pool, sqlsock);
 
        /* no free IP address found */
        if (!ip.s_addr) {
@@ -684,7 +684,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
        }
 
        /* connect to database */
-       sqlsock = sql_get_socket(inst->sqlinst);
+       sqlsock = fr_connection_get(inst->sql_inst->pool);
        if (!sqlsock) {
                nvp_log(__LINE__, inst, L_ERR,
                        "mod_accounting(): couldn't connect to database");
@@ -698,7 +698,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS, 0, TAG_ANY);
                if (!vp) {
                        nvp_log(__LINE__, inst, L_ERR, "mod_accounting(): no framed IP");
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
 
@@ -711,7 +711,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                                "`rsv_by` = '%s' "
                        "WHERE `ip` = %lu",
                    inst->db_name, sessid, framedip)) {
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
                nvp_finish(inst, sqlsock);
@@ -727,7 +727,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                                "`ips`.`rsv_by` = '%s' AND "
                                "`ips`.`ip` BETWEEN `ip_pools`.`ip_start` AND `ip_pools`.`ip_stop`",
                    inst->db_name, inst->free_after, sessid)) {
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
                nvp_finish(inst, sqlsock);
@@ -738,7 +738,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                vp = pairfind(request->packet->vps, PW_NAS_IP_ADDRESS, 0, TAG_ANY);
                if (!vp) {
                        nvp_log(__LINE__, inst, L_ERR, "mod_accounting(): no NAS IP");
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
 
@@ -752,7 +752,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                                "`radacct`.`nasipaddress` = '%s' AND "
                                "`ips`.`rsv_by` = `radacct`.`acctuniqueid`",
                    inst->db_name, inst->free_after, nasipstr)) {
-                       sql_release_socket(inst->sqlinst, sqlsock);
+                       fr_connection_release(inst->sql_inst->pool, sqlsock);
                        return RLM_MODULE_FAIL;
                }
                nvp_finish(inst, sqlsock);
@@ -760,7 +760,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                break;
        }
 
-       sql_release_socket(inst->sqlinst, sqlsock);
+       fr_connection_release(inst->sql_inst->pool, sqlsock);
        return RLM_MODULE_OK;
 }
 
index 54cc499..3794a61 100644 (file)
@@ -403,7 +403,7 @@ finish:
  */
 static int mod_instantiate(CONF_SECTION *conf, void *instance)
 {
-       module_instance_t *sqlinst;
+       module_instance_t *sql_inst;
        rlm_sqlippool_t *inst = instance;
        char const *pool_name = NULL;
 
@@ -413,9 +413,9 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        } else {
                inst->pool_name = talloc_typed_strdup(inst, "ippool");
        }
-       sqlinst = find_module_instance(cf_section_find("modules"),
+       sql_inst = find_module_instance(cf_section_find("modules"),
                                       inst->sql_instance_name, true);
-       if (!sqlinst) {
+       if (!sql_inst) {
                cf_log_err_cs(conf, "failed to find sql instance named %s",
                           inst->sql_instance_name);
                return -1;
@@ -427,14 +427,14 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                inst->framed_ip_address = PW_FRAMED_IPV6_PREFIX;
        }
 
-       if (strcmp(sqlinst->entry->name, "rlm_sql") != 0) {
+       if (strcmp(sql_inst->entry->name, "rlm_sql") != 0) {
                cf_log_err_cs(conf, "Module \"%s\""
                       " is not an instance of the rlm_sql module",
                       inst->sql_instance_name);
                return -1;
        }
 
-       inst->sql_inst = (rlm_sql_t *) sqlinst->insthandle;
+       inst->sql_inst = (rlm_sql_t *) sql_inst->insthandle;
        return 0;
 }
 
@@ -488,7 +488,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                return do_logging(request, inst->log_nopool, RLM_MODULE_NOOP);
        }
 
-       handle = inst->sql_inst->sql_get_socket(inst->sql_inst);
+       handle = fr_connection_get(inst->sql_inst->pool);
        if (!handle) {
                REDEBUG("cannot get sql connection");
                return RLM_MODULE_FAIL;
@@ -539,7 +539,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                                                          inst->pool_check, handle, inst, request,
                                                          (char *) NULL, 0);
 
-                       inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+                       fr_connection_release(inst->sql_inst->pool, handle);
 
                        if (allocation_len) {
 
@@ -567,7 +567,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
 
                }
 
-               inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+               fr_connection_release(inst->sql_inst->pool, handle);
 
                RDEBUG("IP address could not be allocated");
                return do_logging(request, inst->log_failed, RLM_MODULE_NOOP);
@@ -582,7 +582,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
                DO(allocate_commit);
 
                RDEBUG("Invalid IP number [%s] returned from instbase query.", allocation);
-               inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+               fr_connection_release(inst->sql_inst->pool, handle);
                return do_logging(request, inst->log_failed, RLM_MODULE_NOOP);
        }
 
@@ -597,7 +597,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
 
        DO(allocate_commit);
 
-       inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+       fr_connection_release(inst->sql_inst->pool, handle);
 
        return do_logging(request, inst->log_success, RLM_MODULE_OK);
 }
@@ -684,7 +684,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                return RLM_MODULE_NOOP;
        }
 
-       handle = inst->sql_inst->sql_get_socket(inst->sql_inst);
+       handle = fr_connection_get(inst->sql_inst->pool);
        if (!handle) {
                RDEBUG("Cannot allocate sql connection");
                return RLM_MODULE_FAIL;
@@ -716,7 +716,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                break;
        }
 
-       inst->sql_inst->sql_release_socket(inst->sql_inst, handle);
+       fr_connection_release(inst->sql_inst->pool, handle);
 
        return rcode;
 }