]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add counter to DHCP ippool schema
authorNick Porter <nick@portercomputing.co.uk>
Fri, 11 Sep 2020 12:51:35 +0000 (13:51 +0100)
committerAlan DeKok <aland@freeradius.org>
Wed, 16 Sep 2020 12:47:35 +0000 (08:47 -0400)
By updating a counter every time a REQUEST is responded to successfully
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.

raddb/mods-config/sql/ippool-dhcp/mssql/queries.conf
raddb/mods-config/sql/ippool-dhcp/mssql/schema.sql
raddb/mods-config/sql/ippool-dhcp/mysql/queries.conf
raddb/mods-config/sql/ippool-dhcp/mysql/schema.sql
raddb/mods-config/sql/ippool-dhcp/oracle/queries.conf
raddb/mods-config/sql/ippool-dhcp/oracle/schema.sql
raddb/mods-config/sql/ippool-dhcp/postgresql/queries.conf
raddb/mods-config/sql/ippool-dhcp/postgresql/schema.sql
raddb/mods-config/sql/ippool-dhcp/sqlite/queries.conf
raddb/mods-config/sql/ippool-dhcp/sqlite/schema.sql

index 3d5a26fe9f7be54068d67c984d9cfe1db0299e04..bd7db3e98eed7951d18aec29464b538e293797c6 100644 (file)
@@ -201,7 +201,9 @@ update_free = "\
 #
 update_update = "\
        UPDATE ${ippool_table} \
-       SET expiry_time = DATEADD(SECOND,${lease_duration},CURRENT_TIMESTAMP) \
+       SET \
+               expiry_time = DATEADD(SECOND,${lease_duration},CURRENT_TIMESTAMP), \
+               counter = counter + 1 \
        WHERE pool_name = '%{control:${pool_name}}' \
        AND pool_key = '${pool_key}' \
        AND framedipaddress = '%{%{DHCP-Requested-IP-Address}:-%{DHCP-Client-IP-Address}}'"
index 628f2249181bdf2bfb59b672c5ac6163ba3e96f2..dae4eff16fbc42068bd5eba983c2e59fffc49ff8 100644 (file)
@@ -23,6 +23,7 @@ CREATE TABLE dhcpippool (
        gateway                 varchar(15) NOT NULL default '',
        expiry_time             DATETIME NOT NULL default CURRENT_TIMESTAMP,
        status_id               int NOT NULL default 1,
+       counter                 int NOT NULL default 0,
        CONSTRAINT fk_status_id FOREIGN KEY (status_id) REFERENCES dhcpstatus (status_id),
        PRIMARY KEY (id)
 )
index 9309a3e1500d642b775d17b6854ef8b23a823902..1a05397ba7c6c577f7bb6d22c22f72e810a54eac 100644 (file)
@@ -161,7 +161,9 @@ update_free = "\
 #
 update_update = "\
        UPDATE ${ippool_table} \
-       SET expiry_time = 'now'::timesheet(0) + '${lease_duration} second'::interval \
+       SET \
+               expiry_time = NOW() + INTERVAL ${lease_duration} SECOND, \
+               counter = counter + 1 \
        WHERE pool_name = '%{control:${pool_name}}' \
        AND pool_key = '${pool_key}' \
        AND framedipaddress = '%{%{DHCP-Requested-IP-Address}:-%{DHCP-Client-IP-Address}}'"
index 6bfc48c3b1254ea9fff13e0ea0b09bcc20339696..743b219ea2fdb7fe22b75a4ec38fd83e638b5485 100644 (file)
@@ -2,13 +2,14 @@
 # Table structure for table 'dhcpippool'
 #
 CREATE TABLE dhcpippool (
-       id                      int(11) unsigned NOT NULL auto_increment,
+       id                      int unsigned NOT NULL auto_increment,
        pool_name               varchar(30) NOT NULL,
        framedipaddress         varchar(15) NOT NULL DEFAULT '',
        pool_key                varchar(30) NOT NULL DEFAULT '',
        gateway                 varchar(15) NOT NULL DEFAULT '',
        expiry_time             DATETIME NOT NULL DEFAULT NOW(),
        status                  ENUM('dynamic', 'static', 'declined', 'disabled') DEFAULT 'dynamic',
+       counter                 int unsigned NOT NULL DEFAULT 0,
        PRIMARY KEY (id),
        KEY dhcpippool_poolname_expire (pool_name, expiry_time),
        KEY framedipaddress (framedipaddress),
index 61dac32f7645508a2bc4db269e426b260d855554..25cb77331411745fe542d963eb3e91c99e148e50 100644 (file)
@@ -120,7 +120,9 @@ pool_check = "\
 update_begin = "commit"
 update_update = "\
        UPDATE ${ippool_table} \
-       SET expiry_time = current_timestamp + INTERVAL '${lease_duration}' second(1) \
+       SET \
+               expiry_time = current_timestamp + INTERVAL '${lease_duration}' second(1), \
+               counter = counter + 1 \
        WHERE pool_name = '%{control:${pool_name}}' \
        AND pool_key = '${pool_key}' \
        AND framedipaddress = '%{%{DHCP-Requested-IP-Address}:-%{DHCP-Client-IP-Address}}'"
index af30a0dc95cfadcf1a5a76a9f384bbcf7ed9058a..88dba699ed2fae46ca1c414575add150c1852914 100644 (file)
@@ -18,6 +18,7 @@ CREATE TABLE dhcpippool (
        gateway                 VARCHAR(15) NOT NULL,
        expiry_time             TIMESTAMP(0) NOT NULL,
        status_id               INT DEFAULT 1,
+       counter                 INT DEFAULT 0,
        FOREIGN KEY (status_id) REFERENCES dhcpstatus(status_id)
 );
 
index ba02186f2f3261c8019da3e6057d06e569ca25c2..10acb3d62fc1f075e6d8b31a7ed1b34b6af8630f 100644 (file)
@@ -181,7 +181,9 @@ update_free = "\
 #
 update_update = "\
        UPDATE ${ippool_table} \
-       SET expiry_time = 'now'::timestamp(0) + '${lease_duration} second'::interval \
+       SET \
+               expiry_time = 'now'::timestamp(0) + '${lease_duration} second'::interval, \
+               counter = counter + 1 \
        WHERE pool_name = '%{control:${pool_name}}' \
        AND pool_key = '${pool_key}' \
        AND framedipaddress = '%{%{DHCP-Requested-IP-Address}:-%{DHCP-Client-IP-Address}}'"
index 348341f9803f112216b3b538c1724d6b3e24a345..8b2bfb40787212f7d01466701782bb2d490dbc1b 100644 (file)
@@ -14,7 +14,8 @@ CREATE TABLE dhcpippool (
        pool_key                VARCHAR(64) NOT NULL default '0',
        gateway                 VARCHAR(16) NOT NULL default '',
        expiry_time             TIMESTAMP(0) without time zone NOT NULL default NOW(),
-       status                  dhcp_status DEFAULT 'dynamic'
+       status                  dhcp_status DEFAULT 'dynamic',
+       counter                 INT NOT NULL DEFAULT 0
 );
 
 CREATE INDEX dhcpippool_poolname_expire ON dhcpippool USING btree (pool_name, expiry_time);
index 7d486ee92b6feab89be5c9bccd2079f0607127d3..23c1c6b9e6f1f8e622020ae788a859a3b948c017 100644 (file)
@@ -132,7 +132,9 @@ update_free = "\
 #
 update_update = "\
        UPDATE ${ippool_table} \
-       SET expiry_time = datetime(strftime('%%s', 'now') + ${lease_duration}, 'unixepoch') \
+       SET \
+               expiry_time = datetime(strftime('%%s', 'now') + ${lease_duration}, 'unixepoch'), \
+               counter = counter + 1 \
        WHERE pool_name = '%{control:${pool_name}}' \
        AND pool_key = '${pool_key}' \
        AND framedipaddress = '%{%{DHCP-Requested-IP-Address}:-%{DHCP-Client-IP-Address}}'"
index 85b5723d693d1b66d04613933d8014a81d9811c4..2efde522b87a50e9108a24b807b5e4c1b69ab895 100644 (file)
@@ -16,6 +16,7 @@ CREATE TABLE dhcpippool (
        gateway                 varchar(15) NOT NULL DEFAULT '',
        expiry_time             DATETIME NOT NULL default (DATETIME('now')),
        status_id               int NOT NULL DEFAULT 1,
+       counter                 int NOT NULL DEFAULT 0,
        FOREIGN KEY(status_id) REFERENCES dhcpstatus(status_id)
 );