From: Alan T. DeKok Date: Tue, 24 Oct 2017 18:59:36 +0000 (-0400) Subject: allow "attribute_name" to make it generic. Helps with #2094 X-Git-Tag: release_3_0_16~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b874752041b8cbbb20b59bb5a8d39becbb8a1101;p=thirdparty%2Ffreeradius-server.git allow "attribute_name" to make it generic. Helps with #2094 --- diff --git a/raddb/mods-available/sqlippool b/raddb/mods-available/sqlippool index b32b77aa4ca..84d69e59616 100644 --- a/raddb/mods-available/sqlippool +++ b/raddb/mods-available/sqlippool @@ -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})" diff --git a/src/modules/rlm_sqlippool/rlm_sqlippool.c b/src/modules/rlm_sqlippool/rlm_sqlippool.c index 40245bc9974..78a0c106c46 100644 --- a/src/modules/rlm_sqlippool/rlm_sqlippool.c +++ b/src/modules/rlm_sqlippool/rlm_sqlippool.c @@ -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); }