2 * rlm_sqlippool.c rlm_sqlippool - FreeRADIUS SQL IP Pool Module
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Copyright 2002 Globe.Net Communications Limited
21 * Copyright 2006 The FreeRADIUS server project
22 * Copyright 2006 Suntel Communications
25 #include <freeradius-devel/autoconf.h>
26 #include <freeradius-devel/libradius.h>
32 #include <netinet/in.h>
34 #include <freeradius-devel/radiusd.h>
35 #include <freeradius-devel/modules.h>
36 #include <freeradius-devel/conffile.h>
37 #include <freeradius-devel/modpriv.h>
41 static const char rcsid[] = "$Id$";
44 * Define a structure for our module configuration.
46 typedef struct rlm_sqlippool_t {
47 char *sql_instance_name;
55 /* We ended up removing the init
56 queries so that its up to user
57 to create the db structure and put the required
60 /* Allocation sequence */
61 char *allocate_begin; /* SQL query to begin */
62 char *allocate_clear; /* SQL query to clear an IP */
63 char *allocate_find; /* SQL query to find an unused IP */
64 char *allocate_update; /* SQL query to mark an IP as used */
65 char *allocate_commit; /* SQL query to commit */
66 char *allocate_rollback; /* SQL query to rollback */
69 char *start_begin; /* SQL query to begin */
70 char *start_update; /* SQL query to update an IP entry */
71 char *start_commit; /* SQL query to commit */
72 char *start_rollback; /* SQL query to rollback */
75 char *alive_begin; /* SQL query to begin */
76 char *alive_update; /* SQL query to update an IP entry */
77 char *alive_commit; /* SQL query to commit */
78 char *alive_rollback; /* SQL query to rollback */
81 char *stop_begin; /* SQL query to begin */
82 char *stop_clear; /* SQL query to clear an IP */
83 char *stop_commit; /* SQL query to commit */
84 char *stop_rollback; /* SQL query to rollback */
87 char *on_begin; /* SQL query to begin */
88 char *on_clear; /* SQL query to clear an entire NAS */
89 char *on_commit; /* SQL query to commit */
90 char *on_rollback; /* SQL query to rollback */
93 char *off_begin; /* SQL query to begin */
94 char *off_clear; /* SQL query to clear an entire NAS */
95 char *off_commit; /* SQL query to commit */
96 char *off_rollback; /* SQL query to rollback */
100 char *log_exists; /* There Was an ip address already asigned */
101 char *log_success; /* We successfully allocated ip address from pool */
102 char *log_failed; /* Failed to allocate ip from the pool */
103 char *log_nopool; /* There was no Framed-IP-Address but also no Pool-Name */
105 /* Reserved to handle 255.255.255.254 Requests */
106 char *defaultpool; /* Default Pool-Name if there is non in the check items */
111 * A mapping of configuration file names to internal variables.
113 * Note that the string is dynamically allocated, so it MUST
114 * be freed. When the configuration file parse re-reads the string,
115 * it free's the old one, and strdup's the new one, placing the pointer
116 * to the strdup'd string into 'config.string'. This gets around
119 static CONF_PARSER module_config[] = {
120 {"sql-instance-name",PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,sql_instance_name), NULL, "sql"},
122 { "lease-duration", PW_TYPE_INTEGER, offsetof(rlm_sqlippool_t,lease_duration), NULL, "86400"},
124 { "pool-name" , PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t, pool_name), NULL, ""},
126 { "allocate-begin", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,allocate_begin), NULL, "BEGIN" },
127 { "allocate-clear", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,allocate_clear), NULL, "" },
128 { "allocate-find", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,allocate_find), NULL, "" },
129 { "allocate-update", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,allocate_update), NULL, "" },
130 { "allocate-commit", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,allocate_commit), NULL, "COMMIT" },
131 { "allocate-rollback", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,allocate_rollback), NULL, "ROLLBACK" },
133 { "start-begin", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,start_begin), NULL, "BEGIN" },
134 { "start-update", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,start_update), NULL, "" },
135 { "start-commit", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,start_commit), NULL, "COMMIT" },
136 { "start-rollback", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,start_rollback), NULL, "ROLLBACK" },
138 { "alive-begin", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,alive_begin), NULL, "BEGIN" },
139 { "alive-update", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,alive_update), NULL, "" },
140 { "alive-commit", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,alive_commit), NULL, "COMMIT" },
141 { "alive-rollback", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,alive_rollback), NULL, "ROLLBACK" },
143 { "stop-begin", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,stop_begin), NULL, "BEGIN" },
144 { "stop-clear", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,stop_clear), NULL, "" },
145 { "stop-commit", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,stop_commit), NULL, "COMMIT" },
146 { "stop-rollback", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,stop_rollback), NULL, "ROLLBACK" },
148 { "on-begin", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,on_begin), NULL, "BEGIN" },
149 { "on-clear", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,on_clear), NULL, "" },
150 { "on-commit", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,on_commit), NULL, "COMMIT" },
151 { "on-rollback", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,on_rollback), NULL, "ROLLBACK" },
153 { "off-begin", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,off_begin), NULL, "BEGIN" },
154 { "off-clear", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,off_clear), NULL, "" },
155 { "off-commit", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,off_commit), NULL, "COMMIT" },
156 { "off-rollback", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t,off_rollback), NULL, "ROLLBACK" },
158 { "sqlippool_log_exists", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t, log_exists), NULL, "" },
159 { "sqlippool_log_success", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t, log_success), NULL, "" },
160 { "sqlippool_log_failed", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t, log_failed), NULL, "" },
161 { "sqlippool_log_nopool", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t, log_nopool), NULL, "" },
163 { "defaultpool", PW_TYPE_STRING_PTR, offsetof(rlm_sqlippool_t, defaultpool), NULL, "main_pool" },
167 { NULL, -1, 0, NULL, NULL }
171 * Replace %<whatever> in a string.
178 static int sqlippool_expand(char * out, int outlen, const char * fmt, void * instance, char * param, int param_len)
180 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
183 char tmp[40]; /* For temporary storing of integers */
188 for (p = fmt; *p ; p++) {
192 /* Calculate freespace in output */
193 freespace = outlen - (q - out);
198 if (c != '%' && c != '$' && c != '\\') {
200 * We check if we're inside an open brace. If we are
201 * then we assume this brace is NOT literal, but is
202 * a closing brace and apply it
204 if((c == '}') && openbraces) {
237 case 'P': /* pool name */
238 strNcpy(q, data->pool_name, freespace);
241 case 'I': /* IP address */
242 if (param && param_len > 0) {
243 if (param_len > freespace) {
244 strNcpy(q, param, freespace);
248 memcpy(q, param, param_len);
253 case 'J': /* lease duration */
254 sprintf(tmp, "%d", data->lease_duration);
255 strNcpy(q, tmp, freespace);
268 DEBUG2("sqlippool_expand: '%s'", out);
275 * Query the database executing a command with no result rows
277 static int sqlippool_command(const char * fmt, SQLSOCK * sqlsocket, void * instance, REQUEST * request, char * param, int param_len)
279 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
280 char expansion[MAX_STRING_LEN * 4];
281 char query[MAX_STRING_LEN * 4];
283 sqlippool_expand(expansion, sizeof(expansion), fmt, instance, param, param_len);
286 * Do an xlat on the provided string
289 if (!radius_xlat(query, sizeof(query), expansion, request, NULL)) {
290 radlog(L_ERR, "sqlippool_command: xlat failed.");
295 strcpy(query, expansion);
299 DEBUG2("sqlippool_command: '%s'", query);
301 if (rlm_sql_query(sqlsocket, data->sql_inst, query)){
302 radlog(L_ERR, "sqlippool_command: database query error");
306 (data->sql_inst->module->sql_finish_query)(sqlsocket, data->sql_inst->config);
311 * Query the database expecting a single result row
313 static int sqlippool_query1(char * out, int outlen, const char * fmt, SQLSOCK * sqlsocket, void * instance, REQUEST * request, char * param, int param_len)
315 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
316 char expansion[MAX_STRING_LEN * 4];
317 char query[MAX_STRING_LEN * 4];
321 sqlippool_expand(expansion, sizeof(expansion), fmt, instance, param, param_len);
324 * Do an xlat on the provided string
327 if (!radius_xlat(query, sizeof(query), expansion, request, NULL)) {
328 radlog(L_ERR, "sqlippool_command: xlat failed.");
334 strcpy(query, expansion);
338 DEBUG2("sqlippool_query1: '%s'", query);
340 if (rlm_sql_select_query(sqlsocket, data->sql_inst, query)){
341 radlog(L_ERR, "sqlippool_query1: database query error");
346 r = rlm_sql_fetch_row(sqlsocket, data->sql_inst);
347 (data->sql_inst->module->sql_finish_select_query)(sqlsocket, data->sql_inst->config);
350 DEBUG("sqlippool_query1: SQL query did not succeed");
355 row = sqlsocket->row;
357 DEBUG("sqlippool_query1: SQL query did not return any results");
363 DEBUG("sqlippool_query1: row[0] returned NULL");
370 DEBUG("sqlippool_query1: insufficient string space");
375 strncpy(out, row[0], r);
381 static int sqlippool_initialize_sql(void * instance)
384 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
388 sqlsocket = sql_get_socket(data->sql_inst);
389 if (sqlsocket == NULL) {
390 DEBUG("rlm_sqlippool: cannot allocate sql connection for initialization sequence");
398 * Do any per-module initialization that is separate to each
399 * configured instance of the module. e.g. set up connections
400 * to external databases, read configuration files, set up
401 * dictionary entries, etc.
403 * If configuration information is given in the config section
404 * that must be referenced in later calls, store a handle to it
405 * in *instance otherwise put a null pointer there.
407 static int sqlippool_instantiate(CONF_SECTION * conf, void ** instance)
409 rlm_sqlippool_t * data;
410 char * pool_name = NULL;
413 * Set up a storage area for instance data
415 data = rad_malloc(sizeof(*data));
416 memset(data, 0, sizeof(*data));
419 * If the configuration parameters can't be parsed, then
422 if (cf_section_parse(conf, data, module_config) < 0) {
427 if (data->sql_instance_name == NULL || strlen(data->sql_instance_name) == 0) {
428 radlog(L_ERR, "rlm_sqlippool: the 'sql-instance-name' variable must be set.");
434 * Check that all the queries are in place
437 if (data->allocate_clear == NULL || strlen(data->allocate_clear) == 0) {
438 radlog(L_ERR, "rlm_sqlippool: the 'allocate-clear' statement must be set.");
443 if (data->allocate_find == NULL || strlen(data->allocate_find) == 0) {
444 radlog(L_ERR, "rlm_sqlippool: the 'allocate_find' statement must be set.");
449 if (data->allocate_update == NULL || strlen(data->allocate_update) == 0) {
450 radlog(L_ERR, "rlm_sqlippool: the 'allocate_update' statement must be set.");
455 if (data->start_update == NULL || strlen(data->start_update) == 0) {
456 radlog(L_ERR, "rlm_sqlippool: the 'start-update' statement must be set.");
461 if (data->alive_update == NULL || strlen(data->alive_update) == 0) {
462 radlog(L_ERR, "rlm_sqlippool: the 'alive-update' statement must be set.");
467 if (data->stop_clear == NULL || strlen(data->stop_clear) == 0) {
468 radlog(L_ERR, "rlm_sqlippool: the 'stop-clear' statement must be set.");
473 if (data->on_clear == NULL || strlen(data->on_clear) == 0) {
474 radlog(L_ERR, "rlm_sqlippool: the 'on-clear' statement must be set.");
479 if (data->off_clear == NULL || strlen(data->off_clear) == 0) {
480 radlog(L_ERR, "rlm_sqlippool: the 'off-clear' statement must be set.");
485 pool_name = cf_section_name2(conf);
486 if (pool_name != NULL)
487 data->pool_name = strdup(pool_name);
489 data->pool_name = strdup("ippool");
491 if ( !(data->sql_inst = (SQL_INST *) (find_module_instance(cf_section_find("modules"), data->sql_instance_name))->insthandle) )
493 radlog(L_ERR, "sqlippool_instantiate: failed to find sql instance named %s", data->sql_instance_name);
498 sqlippool_initialize_sql(data);
505 * if we have something to log, then we log it
506 * otherwise we return the retcode as soon as possible
509 static int do_logging(char *str, int retcode)
512 radlog(L_INFO,"%s", str);
518 * Allocate an IP number from the pool.
520 static int sqlippool_postauth(void *instance, REQUEST * request)
522 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
523 char allocation[MAX_STRING_LEN];
525 uint32_t ip_allocation;
528 lrad_ipaddr_t ipaddr;
530 VALUE_PAIR *callingsid;
533 int do_callingsid = 0;
534 int do_calledsid = 0;
536 char logstr[MAX_STRING_LEN];
539 * If there is a Framed-IP-Address attribute in the reply do nothing
541 if (pairfind(request->reply->vps, PW_FRAMED_IP_ADDRESS) != NULL) {
542 /* We already have a Framed-IP-Address */
543 radius_xlat(logstr, sizeof(logstr), data->log_exists, request, NULL);
544 DEBUG("rlm_sqlippool: Framed-IP-Address already exists");
546 return do_logging(logstr, RLM_MODULE_NOOP);
549 if (pairfind(request->config_items, PW_POOL_NAME) == NULL) {
550 DEBUG("rlm_sqlippool: We Dont have Pool-Name in check items.. Lets do nothing..");
551 radius_xlat(logstr, sizeof(logstr), data->log_nopool, request, NULL);
553 return do_logging(logstr, RLM_MODULE_NOOP);
556 if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
557 DEBUG("rlm_sqlippool: unknown NAS-IP-Address");
558 return RLM_MODULE_NOOP;
561 if (pairfind(request->packet->vps, PW_NAS_PORT) == NULL) {
562 DEBUG("rlm_sqlippool: unknown NAS-Port");
563 return RLM_MODULE_NOOP;
566 sqlsocket = sql_get_socket(data->sql_inst);
567 if (sqlsocket == NULL) {
568 DEBUG("rlm_sqlippool: cannot allocate sql connection");
569 return RLM_MODULE_NOOP;
575 sqlippool_command(data->allocate_begin, sqlsocket, instance, request,
581 sqlippool_command(data->allocate_clear, sqlsocket, instance, request,
587 allocation_len = sqlippool_query1(allocation, sizeof(allocation),
588 data->allocate_find, sqlsocket, instance, request,
591 if (allocation_len == 0)
596 sqlippool_command(data->allocate_commit, sqlsocket, instance, request,
599 DEBUG("rlm_sqlippool: IP number could not be allocated.");
600 sql_release_socket(data->sql_inst, sqlsocket);
601 radius_xlat(logstr, sizeof(logstr), data->log_failed, request, NULL);
603 return do_logging(logstr, RLM_MODULE_NOOP);
607 /* Reminder to self </tuyan>
608 * please make it work with the ipv6 address'
609 * before the freeradius v2 release
611 if ((ip_hton(allocation, AF_INET, &ipaddr) < 0) ||
612 ((ip_allocation = ipaddr.ipaddr.ip4addr.s_addr) == INADDR_NONE))
617 sqlippool_command(data->allocate_commit, sqlsocket, instance, request,
620 DEBUG("rlm_sqlippool: Invalid IP number [%s] returned from database query.", allocation);
621 sql_release_socket(data->sql_inst, sqlsocket);
622 radius_xlat(logstr, sizeof(logstr), data->log_failed, request, NULL);
624 return do_logging(logstr, RLM_MODULE_NOOP);
630 sqlippool_command(data->allocate_update, sqlsocket, instance, request,
631 allocation, allocation_len);
633 DEBUG("rlm_sqlippool: Allocated IP %s [%08x]", allocation, ip_allocation);
635 if ((vp = paircreate(PW_FRAMED_IP_ADDRESS, PW_TYPE_IPADDR)) == NULL) {
636 radlog(L_ERR|L_CONS, "no memory");
637 sql_release_socket(data->sql_inst, sqlsocket);
638 return RLM_MODULE_NOOP;
640 vp->lvalue = ip_allocation;
641 pairadd(&request->reply->vps, vp);
646 sqlippool_command(data->allocate_commit, sqlsocket, instance, request,
649 sql_release_socket(data->sql_inst, sqlsocket);
650 radius_xlat(logstr, sizeof(logstr), data->log_success, request, NULL);
652 return do_logging(logstr, RLM_MODULE_OK);
655 static int sqlippool_accounting_start(void * instance, REQUEST * request)
657 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
660 if (pairfind(request->packet->vps, PW_NAS_PORT) == NULL) {
661 DEBUG("rlm_ippool: Could not find port number in packet.");
662 return RLM_MODULE_NOOP;
665 if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
666 DEBUG("rlm_ippool: Could not find nas information in packet.");
667 return RLM_MODULE_NOOP;
670 sqlsocket = sql_get_socket(data->sql_inst);
671 if (sqlsocket == NULL) {
672 DEBUG("rlm_sqlippool: cannot allocate sql connection");
673 return RLM_MODULE_NOOP;
679 sqlippool_command(data->start_begin, sqlsocket, instance, request,
685 sqlippool_command(data->start_update, sqlsocket, instance, request,
691 sqlippool_command(data->start_commit, sqlsocket, instance, request,
694 sql_release_socket(data->sql_inst, sqlsocket);
696 return RLM_MODULE_OK;
699 static int sqlippool_accounting_alive(void * instance, REQUEST * request)
701 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
704 if (pairfind(request->packet->vps, PW_NAS_PORT) == NULL) {
705 DEBUG("rlm_ippool: Could not find port number in packet.");
706 return RLM_MODULE_NOOP;
709 if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
710 DEBUG("rlm_ippool: Could not find nas information in packet.");
711 return RLM_MODULE_NOOP;
714 sqlsocket = sql_get_socket(data->sql_inst);
715 if (sqlsocket == NULL) {
716 DEBUG("rlm_sqlippool: cannot allocate sql connection");
717 return RLM_MODULE_NOOP;
723 sqlippool_command(data->alive_begin, sqlsocket, instance, request,
729 sqlippool_command(data->alive_update, sqlsocket, instance, request,
735 sqlippool_command(data->alive_commit, sqlsocket, instance, request,
738 sql_release_socket(data->sql_inst, sqlsocket);
740 return RLM_MODULE_OK;
743 static int sqlippool_accounting_stop(void * instance, REQUEST * request)
745 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
748 if (pairfind(request->packet->vps, PW_NAS_PORT) == NULL) {
749 DEBUG("rlm_ippool: Could not find port number in packet.");
750 return RLM_MODULE_NOOP;
753 if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
754 DEBUG("rlm_ippool: Could not find nas information in packet.");
755 return RLM_MODULE_NOOP;
758 sqlsocket = sql_get_socket(data->sql_inst);
759 if (sqlsocket == NULL) {
760 DEBUG("rlm_sqlippool: cannot allocate sql connection");
761 return RLM_MODULE_NOOP;
767 sqlippool_command(data->stop_begin, sqlsocket, instance, request,
773 sqlippool_command(data->stop_clear, sqlsocket, instance, request,
779 sqlippool_command(data->stop_commit, sqlsocket, instance, request,
782 sql_release_socket(data->sql_inst, sqlsocket);
784 return RLM_MODULE_OK;
787 static int sqlippool_accounting_on(void * instance, REQUEST * request)
789 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
792 if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
793 DEBUG("rlm_ippool: Could not find nas information in packet.");
794 return RLM_MODULE_NOOP;
797 sqlsocket = sql_get_socket(data->sql_inst);
798 if (sqlsocket == NULL) {
799 DEBUG("rlm_sqlippool: cannot allocate sql connection");
800 return RLM_MODULE_NOOP;
806 sqlippool_command(data->on_begin, sqlsocket, instance, request,
812 sqlippool_command(data->on_clear, sqlsocket, instance, request,
818 sqlippool_command(data->on_commit, sqlsocket, instance, request,
821 sql_release_socket(data->sql_inst, sqlsocket);
823 return RLM_MODULE_OK;
826 static int sqlippool_accounting_off(void * instance, REQUEST * request)
828 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
831 if (pairfind(request->packet->vps, PW_NAS_IP_ADDRESS) == NULL) {
832 DEBUG("rlm_ippool: Could not find nas information in packet.");
833 return RLM_MODULE_NOOP;
836 sqlsocket = sql_get_socket(data->sql_inst);
837 if (sqlsocket == NULL) {
838 DEBUG("rlm_sqlippool: cannot allocate sql connection");
839 return RLM_MODULE_NOOP;
845 sqlippool_command(data->off_begin, sqlsocket, instance, request,
851 sqlippool_command(data->off_clear, sqlsocket, instance, request,
857 sqlippool_command(data->off_commit, sqlsocket, instance, request,
860 sql_release_socket(data->sql_inst, sqlsocket);
862 return RLM_MODULE_OK;
866 * Check for an Accounting-Stop
867 * If we find one and we have allocated an IP to this nas/port combination, deallocate it.
869 static int sqlippool_accounting(void * instance, REQUEST * request)
872 int acct_status_type;
874 vp = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE);
876 DEBUG("rlm_sqlippool: Could not find account status type in packet.");
877 return RLM_MODULE_NOOP;
879 acct_status_type = vp->lvalue;
881 switch (acct_status_type) {
882 case PW_STATUS_START:
883 return sqlippool_accounting_start(instance, request);
885 case PW_STATUS_ALIVE:
886 return sqlippool_accounting_alive(instance, request);
889 return sqlippool_accounting_stop(instance, request);
891 case PW_STATUS_ACCOUNTING_ON:
892 return sqlippool_accounting_on(instance, request);
894 case PW_STATUS_ACCOUNTING_OFF:
895 return sqlippool_accounting_off(instance, request);
898 /* We don't care about any other accounting packet */
899 return RLM_MODULE_NOOP;
903 static int sqlippool_detach(void *instance)
905 rlm_sqlippool_t * data = (rlm_sqlippool_t *) instance;
907 free(data->sql_instance_name);
908 free(data->pool_name);
912 free(data->allocate_begin);
913 free(data->allocate_clear);
914 free(data->allocate_find);
915 free(data->allocate_update);
916 free(data->allocate_commit);
917 free(data->allocate_rollback);
919 free(data->start_begin);
920 free(data->start_update);
921 free(data->start_commit);
922 free(data->start_rollback);
924 free(data->alive_begin);
925 free(data->alive_update);
926 free(data->alive_commit);
927 free(data->alive_rollback);
929 free(data->stop_begin);
930 free(data->stop_clear);
931 free(data->stop_commit);
932 free(data->stop_rollback);
934 free(data->on_begin);
935 free(data->on_clear);
936 free(data->on_commit);
937 free(data->on_rollback);
939 free(data->off_begin);
940 free(data->off_clear);
941 free(data->off_commit);
942 free(data->off_rollback);
944 free(data->log_exists);
945 free(data->log_failed);
946 free(data->log_nopool);
947 free(data->log_success);
948 free(data->defaultpool);
956 * The module name should be the only globally exported symbol.
957 * That is, everything else should be 'static'.
959 * If the module needs to temporarily modify it's instantiation
960 * data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
961 * The server will then take care of ensuring that the module
962 * is single-threaded.
964 module_t rlm_sqlippool = {
967 RLM_TYPE_THREAD_SAFE, /* type */
968 sqlippool_instantiate, /* instantiation */
969 sqlippool_detach, /* detach */
971 NULL, /* authentication */
972 NULL, /* authorization */
973 NULL, /* preaccounting */
974 sqlippool_accounting, /* accounting */
975 NULL, /* checksimul */
976 NULL, /* pre-proxy */
977 NULL, /* post-proxy */
978 sqlippool_postauth /* post-auth */