]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow "attribute_name" to make it generic. Helps with #2094
authorAlan T. DeKok <aland@freeradius.org>
Tue, 24 Oct 2017 18:59:36 +0000 (14:59 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 24 Oct 2017 19:17:20 +0000 (15:17 -0400)
raddb/mods-available/sqlippool
src/modules/rlm_sqlippool/rlm_sqlippool.c

index b32b77aa4ca134d608a1140da73434bdc7d14895..84d69e59616b756970f90a57b138eb6c7d916e42 100644 (file)
@@ -24,8 +24,20 @@ sqlippool {
        # IP lease duration. (Leases expire even if Acct Stop packet is lost)
        lease_duration = 3600
 
-       # protocol to use.  The default is IPv4.
-#      ipv6 = yes
+       #
+       #  As of 3.0.16, the 'ipv6 = yes' configuration is deprecated.
+       #  You should use the "attribute_name" configuration item
+       #  below, instead.
+       #
+
+       #
+       #  The attribute to use for IP address assignment.  The
+       #  default is Framed-IP-Address.  You can change this to any
+       #  attribute which is IPv4 or IPv6.
+       #
+       #  e.g. Framed-IPv6-Address, or Delegated-IPv6-Prefix.
+       #
+       attribute_name = Framed-IP-Address
 
        # Attribute which should be considered unique per NAS
        #
@@ -53,11 +65,11 @@ sqlippool {
        #  which writes Module-Success-Message message.
        #
        messages {
-               exists = "Existing IP: %{reply:Framed-IP-Address} (did %{Called-Station-Id} cli %{Calling-Station-Id} port %{NAS-Port} user %{User-Name})"
+               exists = "Existing IP: %{reply:${..attribute_name}} (did %{Called-Station-Id} cli %{Calling-Station-Id} port %{NAS-Port} user %{User-Name})"
 
                success = "Allocated IP: %{reply:Framed-IP-Address} from %{control:Pool-Name} (did %{Called-Station-Id} cli %{Calling-Station-Id} port %{NAS-Port} user %{User-Name})"
 
-               clear = "Released IP %{Framed-IP-Address} (did %{Called-Station-Id} cli %{Calling-Station-Id} user %{User-Name})"
+               clear = "Released IP ${..attribute_name} (did %{Called-Station-Id} cli %{Calling-Station-Id} user %{User-Name})"
 
                failed = "IP Allocation FAILED from %{control:Pool-Name} (did %{Called-Station-Id} cli %{Calling-Station-Id} port %{NAS-Port} user %{User-Name})"
 
index 40245bc997453862fcc0ad481f710da2dc6699a0..78a0c106c46e7c722b11e34608d215617c0f08d1 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * $Id$
  * @file rlm_sqlippool.c
- * @brief Allocates an IPv4 address from pools stored in SQL.
+ * @brief Allocates an IP address / prefix from pools stored in SQL.
  *
  * @copyright 2002  Globe.Net Communications Limited
  * @copyright 2006  The FreeRADIUS server project
@@ -46,6 +46,8 @@ typedef struct rlm_sqlippool_t {
 
        char const      *pool_name;
        bool            ipv6;                   //!< Whether or not we do IPv6 pools.
+       char const      *attribute_name;        //!< name of the IP address attribute
+
        int             framed_ip_address;      //!< the attribute number for Framed-IP(v6)-Address
 
        time_t          last_clear;             //!< So we only do it once a second.
@@ -127,6 +129,7 @@ static CONF_PARSER module_config[] = {
 
 
        { "ipv6", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_sqlippool_t, ipv6), NULL},
+       { "attribute_name", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_sqlippool_t, attribute_name), NULL},
 
        { "allocate-begin", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_XLAT | PW_TYPE_DEPRECATED, rlm_sqlippool_t, allocate_begin), NULL },
        { "allocate_begin", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_XLAT, rlm_sqlippool_t, allocate_begin), "START TRANSACTION" },
@@ -421,10 +424,42 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                return -1;
        }
 
-       if (!inst->ipv6) {
-               inst->framed_ip_address = PW_FRAMED_IP_ADDRESS;
+       if (inst->attribute_name) {
+               DICT_ATTR const *da;
+
+               da = dict_attrbyname(inst->attribute_name);
+               if (!da) {
+                       cf_log_err_cs(conf, "Unknown attribute 'attribute_name = %s'", inst->attribute_name);
+                       return -1;
+               }
+
+               if (da->vendor != 0) {
+                       cf_log_err_cs(conf, "Cannot use VSAs for 'attribute_name = %s'", inst->attribute_name);
+                       return -1;
+               }
+
+               switch (da->type) {
+               default:
+                       cf_log_err_cs(conf, "Cannot use non-IP attributes for 'attribute_name = %s'", inst->attribute_name);
+                       return -1;
+
+               case PW_TYPE_IPV4_ADDR:
+               case PW_TYPE_IPV6_ADDR:
+               case PW_TYPE_IPV4_PREFIX:
+               case PW_TYPE_IPV6_PREFIX:
+                       break;
+
+               }
+
+               inst->framed_ip_address = da->attr;
        } else {
-               inst->framed_ip_address = PW_FRAMED_IPV6_PREFIX;
+               if (!inst->ipv6) {
+                       inst->framed_ip_address = PW_FRAMED_IP_ADDRESS;
+                       inst->attribute_name = "Framed-IP-Address";
+               } else {
+                       inst->framed_ip_address = PW_FRAMED_IPV6_PREFIX;
+                       inst->attribute_name = "Framed-IPv6-Prefix";
+               }
        }
 
        if (strcmp(sql_inst->entry->name, "rlm_sql") != 0) {
@@ -474,10 +509,10 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
        time_t now;
 
        /*
-        *      If there is a Framed-IP-Address attribute in the reply do nothing
+        *      If there is already an attribute in the reply do nothing
         */
        if (fr_pair_find_by_num(request->reply->vps, inst->framed_ip_address, 0, TAG_ANY) != NULL) {
-               RDEBUG("Framed-IP-Address already exists");
+               RDEBUG("%s already exists", inst->attribute_name);
 
                return do_logging(request, inst->log_exists, RLM_MODULE_NOOP);
        }