From: Nick Porter Date: Tue, 25 Aug 2020 09:56:32 +0000 (+0100) Subject: Rename mod_bulkrelease to mod_bulk_release plus query names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5dcf4e19f863aef8d90899e135605dfbeac03b81;p=thirdparty%2Ffreeradius-server.git Rename mod_bulkrelease to mod_bulk_release plus query names --- diff --git a/raddb/mods-config/sql/ippool/mssql/queries.conf b/raddb/mods-config/sql/ippool/mssql/queries.conf index 52bcce24863..9b560260b82 100644 --- a/raddb/mods-config/sql/ippool/mssql/queries.conf +++ b/raddb/mods-config/sql/ippool/mssql/queries.conf @@ -146,7 +146,7 @@ release_clear = "\ # # Frees all IPs allocated to a NAS when an accounting ON / OFF record arrives # -bulkrelease_clear = "\ +bulk_release_clear = "\ UPDATE ${ippool_table} \ SET \ NASIPAddress = '', \ diff --git a/raddb/mods-config/sql/ippool/mysql/queries.conf b/raddb/mods-config/sql/ippool/mysql/queries.conf index e3c5c559085..1a4fb090df3 100644 --- a/raddb/mods-config/sql/ippool/mysql/queries.conf +++ b/raddb/mods-config/sql/ippool/mysql/queries.conf @@ -187,7 +187,7 @@ release_clear = "\ # Comment out if you want users to be able to obtain their # same address after an outage. # -bulkrelease_clear = "\ +bulk_release_clear = "\ UPDATE ${ippool_table} \ SET \ nasipaddress = '', \ diff --git a/raddb/mods-config/sql/ippool/oracle/queries.conf b/raddb/mods-config/sql/ippool/oracle/queries.conf index c91baadbd7d..e13d3bfa3ee 100644 --- a/raddb/mods-config/sql/ippool/oracle/queries.conf +++ b/raddb/mods-config/sql/ippool/oracle/queries.conf @@ -164,8 +164,8 @@ release_commit = "commit" # This query frees all IP addresses allocated to a NAS when an # accounting ON / OFF record arrives from that NAS # -bulkrelease_begin = "commit" -bulkrelease_clear = "\ +bulk_release_begin = "commit" +bulk_release_clear = "\ UPDATE ${ippool_table} \ SET \ nasipaddress = '0', \ @@ -173,4 +173,4 @@ bulkrelease_clear = "\ callingstationid = '0', \ expiry_time = current_timestamp - INTERVAL '1' second(1) \ WHERE nasipaddress = '%{Nas-IP-Address}'" -bulkrelease_commit = "commit" +bulk_release_commit = "commit" diff --git a/raddb/mods-config/sql/ippool/postgresql/queries.conf b/raddb/mods-config/sql/ippool/postgresql/queries.conf index a9321eda8bc..01d474018af 100644 --- a/raddb/mods-config/sql/ippool/postgresql/queries.conf +++ b/raddb/mods-config/sql/ippool/postgresql/queries.conf @@ -169,7 +169,7 @@ release_clear = "\ # This query frees all IP addresses allocated to a NAS when an # accounting ON / OFF record arrives from that NAS # -bulkrelease_clear = "\ +bulk_release_clear = "\ UPDATE ${ippool_table} \ SET \ nasipaddress = '', \ diff --git a/raddb/mods-config/sql/ippool/sqlite/queries.conf b/raddb/mods-config/sql/ippool/sqlite/queries.conf index 7681f8a7e56..4628cf993df 100644 --- a/raddb/mods-config/sql/ippool/sqlite/queries.conf +++ b/raddb/mods-config/sql/ippool/sqlite/queries.conf @@ -117,7 +117,7 @@ release_clear = "\ # # Frees all IPs allocated to a NAS when an accounting ON / OFF record arrives # -bulkrelease_clear = "\ +bulk_release_clear = "\ UPDATE ${ippool_table} \ SET \ nasipaddress = '', \ diff --git a/src/modules/rlm_sqlippool/rlm_sqlippool.c b/src/modules/rlm_sqlippool/rlm_sqlippool.c index 6ab5b333ca1..0707d5477c9 100644 --- a/src/modules/rlm_sqlippool/rlm_sqlippool.c +++ b/src/modules/rlm_sqlippool/rlm_sqlippool.c @@ -70,9 +70,9 @@ typedef struct { char const *release_commit; //!< SQL query to commit. /* Bulk release sequence */ - char const *bulkrelease_begin; //!< SQL query to begin. - char const *bulkrelease_clear; //!< SQL query to bulk clear several IPs. - char const *bulkrelease_commit; //!< SQL query to commit. + char const *bulk_release_begin; //!< SQL query to begin. + char const *bulk_release_clear; //!< SQL query to bulk clear several IPs. + char const *bulk_release_commit; //!< SQL query to commit. /* Mark sequence */ char const *mark_begin; //!< SQL query to begin. @@ -140,11 +140,11 @@ static CONF_PARSER module_config[] = { { FR_CONF_OFFSET("release_commit", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_sqlippool_t, release_commit) }, - { FR_CONF_OFFSET("bulkrelease_begin", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_sqlippool_t, bulkrelease_begin) }, + { FR_CONF_OFFSET("bulk_release_begin", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_sqlippool_t, bulk_release_begin) }, - { FR_CONF_OFFSET("bulkrelease_clear", FR_TYPE_STRING | FR_TYPE_XLAT , rlm_sqlippool_t, bulkrelease_clear) }, + { FR_CONF_OFFSET("bulk_release_clear", FR_TYPE_STRING | FR_TYPE_XLAT , rlm_sqlippool_t, bulk_release_clear) }, - { FR_CONF_OFFSET("bulkrelease_commit", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_sqlippool_t, bulkrelease_commit) }, + { FR_CONF_OFFSET("bulk_release_commit", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_sqlippool_t, bulk_release_commit) }, { FR_CONF_OFFSET("mark_begin", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_sqlippool_t, mark_begin) }, @@ -696,10 +696,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_release(module_ctx_t const *mctx, REQUES } /* - * Mark a lease. Typically for DHCP Decline where IPs need to be marked - * as invalid + * Release a collection of leases. */ -static rlm_rcode_t CC_HINT(nonnull) mod_mark(module_ctx_t const *mctx, REQUEST *request) +static rlm_rcode_t CC_HINT(nonnull) mod_bulk_release(module_ctx_t const *mctx, REQUEST *request) { rlm_sqlippool_t *inst = talloc_get_type_abort(mctx->instance, rlm_sqlippool_t); rlm_sql_handle_t *handle; @@ -714,9 +713,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_mark(module_ctx_t const *mctx, REQUEST * return RLM_MODULE_FAIL; } - DO_PART(mark_begin); - DO_PART(mark_update); - DO_PART(mark_commit); + DO_PART(bulk_release_begin); + DO_PART(bulk_release_clear); + DO_PART(bulk_release_commit); if (handle) fr_pool_connection_release(inst->sql_inst->pool, request, handle); return RLM_MODULE_OK; @@ -726,24 +725,35 @@ static rlm_rcode_t CC_HINT(nonnull) mod_mark(module_ctx_t const *mctx, REQUEST * return RLM_MODULE_FAIL; } -static int mod_accounting_on(rlm_sql_handle_t **handle, - rlm_sqlippool_t const *inst, REQUEST *request) +/* + * Mark a lease. Typically for DHCP Decline where IPs need to be marked + * as invalid + */ +static rlm_rcode_t CC_HINT(nonnull) mod_mark(module_ctx_t const *mctx, REQUEST *request) { - DO(bulkrelease_begin); - DO(bulkrelease_clear); - DO(bulkrelease_commit); + rlm_sqlippool_t *inst = talloc_get_type_abort(mctx->instance, rlm_sqlippool_t); + rlm_sql_handle_t *handle; - return RLM_MODULE_OK; -} + handle = fr_pool_connection_get(inst->sql_inst->pool, request); + if (!handle) { + REDEBUG("Failed reserving SQL connection"); + return RLM_MODULE_FAIL; + } -static int mod_accounting_off(rlm_sql_handle_t **handle, - rlm_sqlippool_t const *inst, REQUEST *request) -{ - DO(bulkrelease_begin); - DO(bulkrelease_clear); - DO(bulkrelease_commit); + if (inst->sql_inst->sql_set_user(inst->sql_inst, request, NULL) < 0) { + return RLM_MODULE_FAIL; + } + + DO_PART(mark_begin); + DO_PART(mark_update); + DO_PART(mark_commit); + if (handle) fr_pool_connection_release(inst->sql_inst->pool, request, handle); return RLM_MODULE_OK; + + error: + if (handle) fr_pool_connection_release(inst->sql_inst->pool, request, handle); + return RLM_MODULE_FAIL; } /* @@ -752,12 +762,10 @@ static int mod_accounting_off(rlm_sql_handle_t **handle, */ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(module_ctx_t const *mctx, REQUEST *request) { - rlm_sqlippool_t const *inst = talloc_get_type_abort_const(mctx->instance, rlm_sqlippool_t); int rcode = RLM_MODULE_NOOP; VALUE_PAIR *vp; int acct_status_type; - rlm_sql_handle_t *handle; vp = fr_pair_find_by_da(request->packet->vps, attr_acct_status_type, TAG_ANY); if (!vp) { @@ -766,26 +774,6 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(module_ctx_t const *mctx, REQ } acct_status_type = vp->vp_uint32; - switch (acct_status_type) { - case FR_STATUS_START: - case FR_STATUS_ALIVE: - case FR_STATUS_STOP: - case FR_STATUS_ACCOUNTING_ON: - case FR_STATUS_ACCOUNTING_OFF: - break; /* continue through to the next section */ - - default: - /* We don't care about any other accounting packet */ - return RLM_MODULE_NOOP; - } - - handle = fr_pool_connection_get(inst->sql_inst->pool, request); - if (!handle) { - RDEBUG2("Failed reserving SQL connection"); - return RLM_MODULE_FAIL; - } - - if (inst->sql_inst->sql_set_user(inst->sql_inst, request, NULL) < 0) return RLM_MODULE_FAIL; switch (acct_status_type) { case FR_STATUS_START: @@ -798,14 +786,14 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(module_ctx_t const *mctx, REQ break; case FR_STATUS_ACCOUNTING_ON: - rcode = mod_accounting_on(&handle, inst, request); - break; - case FR_STATUS_ACCOUNTING_OFF: - rcode = mod_accounting_off(&handle, inst, request); + rcode = mod_bulk_release(mctx, request); break; + + default: + /* We don't care about any other accounting packet */ + return RLM_MODULE_NOOP; } - fr_pool_connection_release(inst->sql_inst->pool, request, handle); return rcode; }