Alan T. DeKok [Fri, 6 Nov 2020 16:00:17 +0000 (11:00 -0500)]
add "SELECT true" as fail-over for on/off queries
If there are no rows to update, then the on/off queries will
return "no rows updated". The server will then fail over to the
next query, which says "that's fine"
Terry Burton [Mon, 2 Nov 2020 23:46:10 +0000 (23:46 +0000)]
rlm_sql: Use the non-xlat escape function for the group membership query
Use the basic sql_escape_func when expanding the group membership query that
uses our existing SQL handle.
If we use sql_escape_for_xlat_func, which reserves a connection, then when the
connection pool is exhausted we erroneously conclude that the user is not a
member of any groups.
Terry Burton [Sun, 11 Oct 2020 03:47:02 +0000 (04:47 +0100)]
DHCP: Dedicated rlm_sql instance to support option lookup
New dhcp_sql instance of rlm_sql for use with DHCP:
- Separate queries.conf and schema.sql, etc. for DHCP vs RADIUS.
- Group lookup is disabled by default and there are no check queries provided
to reduce query load for typical use cases.
- No accounting-related configuration items and queries.
The schema provides dhcpreply, dhcpgroupreply and dhcpgroup (née "usergroup")
tables as per corresponding RADIUS authorize schema, except:
- Rename column Username -> Identifier since the lookup key varies based on
"contexts". There will typically be multiple option merges from different
context to set network-specific options, device-specific options, classes,
etc.
- Set Identifier for lookup using the DHCP-SQL-Option-Identifier internal
attribute (which gets escaped into SQL-User-Name, as usual).
- Add a Context column ("network", "subnet", "group", "class-abc", etc.) to
support lookups using the same tables but with the options data partitioned
between contexts.
- Set current Context using the DHCP-SQL-Option-Context internal attribute.
This is not SQL escaped, however it is not set from tainted data.
Example policy for performing SQL options lookup from SQL provided in
policy.d/dhcp.
Terry Burton [Fri, 25 Sep 2020 12:55:09 +0000 (13:55 +0100)]
DHCP: Policy support for shared-network: Layer 2 with multiple subnets
Many networks support multiple co-existing subnets without VLAN separation,
i.e. we have one pool containing equally valid IP addresses from each subnet.
To support this configuration we differentiate selecting a pool based on the
default or overriden DHCP-Network-IP-Address (indicating the Layer 2 network
originating the request) versus setting the reply options for the subnet to
which the allocated IP address belongs, in particular DHCP-Subnet-Mask,
DHCP-Router-Address and DHCP-Broadcast-Address.
Nick Porter [Mon, 28 Sep 2020 16:41:08 +0000 (17:41 +0100)]
v3: Remove requirement for Perl Template::Toolkit (#3668)
* Remove requirement for Perl Template::Toolkit
Template Toolkit is only needed if the perl IP pool tools are to produce
SQL output rather than directly operate on the database - so it is not a
hard requirement.
* Split perl utils into new package for .deb
Remove Perl dependencies from freeradius-utils and create a new
freeradius-perl-util for helper Perl scripts
* Split perl utils into new package for .rpm
Remove Perl dependencies from freeradius-utils and create a new
freeradius-perl-util for helper Perl scripts
Nick Porter [Tue, 22 Sep 2020 09:51:18 +0000 (10:51 +0100)]
Sample config to allow for DHCP group options
Defines an internal attribute of DHCP-Group-Name. Clients are then
looked up in a "passwd" style file to determine group membership,
followed by a lookup into a "files" instance to add appropriate options.
Nick Porter [Mon, 21 Sep 2020 15:00:00 +0000 (16:00 +0100)]
Move subnet test to instance of rlm_files
To keep config in config files as much as possible, replace
determine_subnet with an instance of the rlm_files module. This
instance can set global DHCP options along with subnet specific options
and the Pool-Name for SQL ippool lookups.
Alan T. DeKok [Tue, 22 Sep 2020 12:59:06 +0000 (08:59 -0400)]
don't use for (init ... next_by_num)
fr_cursor_next_by_* functions start at the current cursor position
unless they have been previously called. This resulted in the first key
attribute value being looked up twice - once as a result of
fr_cursor_init and once after the first call to fr_cursor_next_by_num
Nick Porter [Wed, 16 Sep 2020 13:08:54 +0000 (14:08 +0100)]
Calculate DHCP-Network-IP-Address as the basis of identifying a client's subnet (#3650)
* Add new internal attributes to DHCP dictionary
DHCP-Network-IP-Address - used to store the address to be used in
determining the subnet a client belongs to
DHCP-Subnet-Name - an internal name for the selected subnet.
Also, correct the type for option 118.
* Determine the address to be used to identify client subnet
After parsing the DHCP packet, check Relay-Link-Selection option,
Subnet-Selection-Option option then giaddr and finally ciaddr to
determine address to lookup client's subnet.
* Add sample config for looking up DHCP subnet name
Create a policy that maps DHCP-Network-IP-Address to DHCP-Subnet-Name
and then call that from each processing section.
Nick Porter [Fri, 11 Sep 2020 12:36:10 +0000 (13:36 +0100)]
Add counter to DHCP ippool schema
By updating a counter every time a REQUEST is responded to sucessfully
we ensure that records are changed, thus all database engines return an
affected row count of 1 for successful matches. This safeguards the new
DHCP site config which uses the affected row count to determine between
ACK and NAK responses.
Nick Porter [Fri, 11 Sep 2020 08:35:34 +0000 (09:35 +0100)]
Move common DHCP reply attributes to a single policy
DISCOVER, REQUEST and INFORM all have a common set of reply attributes.
Rather than explicity set them in each section, call a common policy to
set them in one place.
Also, move the commented out setting of reply packet type for DISCOVER
so it reads more clearly.
Nick Porter [Wed, 9 Sep 2020 14:19:40 +0000 (15:19 +0100)]
Default _begin and _commit queries to blank
Most databases are autocommit, so where a method only calls a single
update there is no need to wrap in "START TRANSACTION" and "COMMIT".
Also different databases have different syntax for this. Safer to have
blank and only explicitly add transaction commands where needed (Oracle)