]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Oracle DHCP queries
authorNick Porter <nick@portercomputing.co.uk>
Thu, 10 Sep 2020 15:33:51 +0000 (16:33 +0100)
committerAlan DeKok <aland@freeradius.org>
Wed, 16 Sep 2020 12:47:35 +0000 (08:47 -0400)
raddb/mods-config/sql/ippool-dhcp/oracle/procedure.sql
raddb/mods-config/sql/ippool-dhcp/oracle/queries.conf

index c5c9753492a0355c65290d89e2c27eb735d1d26e..630522fe3a5a46e82d67cfd32c345852d42de0c7 100644 (file)
@@ -21,7 +21,8 @@
 --              '%{control:${pool_name}}', \
 --              '%{DHCP-Gateway-IP-Address}', \
 --              '${pool_key}', \
---              ${lease_duration} \
+--              ${lease_duration}, \
+--              '%{%{${req_attribute_name}}:-0.0.0.0}'
 --      ) FROM dual"
 -- allocate_update = ""
 -- allocate_commit = ""
@@ -31,7 +32,8 @@ CREATE OR REPLACE FUNCTION fr_dhcp_allocate_previous_or_new_framedipaddress (
        v_pool_name IN VARCHAR2,
        v_gateway IN VARCHAR2,
        v_pool_key IN VARCHAR2,
-       v_lease_duration IN INTEGER
+       v_lease_duration IN INTEGER,
+       v_requsted_address IN VARCHAR2
 )
 RETURN varchar2 IS
        PRAGMA AUTONOMOUS_TRANSACTION;
@@ -117,6 +119,48 @@ BEGIN
        --              r_address := NULL;
        -- END;
 
+       -- Issue the requested IP address if it is available
+       --
+       IF r_address IS NULL AND v_requested_address <> '0.0.0.0' THEN
+               BEGIN
+               SELECT framedipaddress INTO r_address FROM dhcpippool WHERE id IN (
+                       SELECT id FROM (
+                               SELECT *
+                               FROM dhcpippool
+                               JOIN dhcpstatus
+                               ON dhcpstatus.status_id = dhcpippool.status_id
+                               WHERE pool_name = v_pool_name
+                                       AND framedipaddress = v_requested_address
+                                       AND dhcpstatus.status = 'dynamic'
+                                       AND expiry_time < CURRENT_TIMESTAMP
+                               ) WHERE ROWNUM <= 1
+               ) FOR UPDATE SKIP LOCKED;
+               EXCEPTION
+               WHEN NO_DATA_FOUND THEN
+                       r_address := NULL;
+               END;
+       END IF;
+
+       -- Oracle >= 12c version of the above query
+       --
+       -- IF r_address IS NULL AND v_requested_address <> '0.0.0.0' THEN
+       --      BEGIN
+       --      SELECT framedipaddress INTO r_address FROM dhcpippool WHERE id IN (
+       --              SELECT id FROM dhcpippool
+       --              JOIN dhcpstatus
+       --              ON dhcpstatus.status_id = dhcpippool.status_id
+       --              WHERE pool_name = v_pool_name
+       --                      AND framedipaddress = v_requested_address
+       --                      AND dhcpstatus.status = 'dynamic'
+       --                      AND expiry_time < CURRENT_TIMESTAMP
+       --              FETCH FIRST 1 ROWS ONLY
+       --      ) FOR UPDATE SKIP LOCKED;
+       --      EXCEPTION
+       --      WHEN NO_DATA_FOUND THEN
+       --              r_address := NULL;
+       --      END;
+       -- END IF;
+
        -- If we didn't reallocate a previous address then pick the least
        -- recently used address from the pool which maximises the likelihood
        -- of re-assigning the other addresses to their recent user
index 9f1b551b255b5d6bca3b12cc02317719857be4af..1c4a40901fcfb23c8079cf6b163f7e4734b01216 100644 (file)
@@ -7,6 +7,12 @@
 #
 #  Due to Oracle's transaction focus, update queries further down are
 #  wrapped in "commit" statements.
+
+
+#  *****************
+#  * DHCP DISCOVER *
+#  *****************
+
 #
 #  Use a stored procedure to find AND allocate the address. Read and customise
 #  `procedure.sql` in this directory to determine the optimal configuration.
@@ -19,7 +25,8 @@ alloc_find = "\
                '%{control:${pool_name}}', \
                '%{DHCP-Gateway-IP-Address}', \
                '${pool_key}', \
-               '${lease_duration}' \
+               '${offer_duration}', \
+               '%{%{${req_attribute_name}}:-0.0.0.0}'
        )"
 alloc_update = ""
 alloc_commit = ""
@@ -92,16 +99,21 @@ pool_check = "\
 
 #
 #  This query marks the IP address handed out by "alloc_find" as used
-#  for the period of "lease_duration" after which time it may be reused.
+#  for the period of "offer_duration" after which time it may be reused.
 #
 #alloc_update = "\
 #      UPDATE ${ippool_table} \
 #      SET \
 #              gateway = '%{DHCP-Gateway-IP-Address}', \
 #              pool_key = '${pool_key}', \
-#              expiry_time = current_timestamp + INTERVAL '${lease_duration}' second(1) \
+#              expiry_time = current_timestamp + INTERVAL '${offer_duration}' second(1) \
 #      WHERE framedipaddress = '%I'"
 
+
+#  ****************
+#  * DHCP REQUEST *
+#  ****************
+
 #
 #  Queries to update a lease - used in response to DHCP-Request packets
 #