From: Nick Porter Date: Thu, 10 Sep 2020 15:33:51 +0000 (+0100) Subject: Oracle DHCP queries X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6d2d7eb4725b25e751caec100e72c68faa86fd5;p=thirdparty%2Ffreeradius-server.git Oracle DHCP queries --- diff --git a/raddb/mods-config/sql/ippool-dhcp/oracle/procedure.sql b/raddb/mods-config/sql/ippool-dhcp/oracle/procedure.sql index c5c9753492a..630522fe3a5 100644 --- a/raddb/mods-config/sql/ippool-dhcp/oracle/procedure.sql +++ b/raddb/mods-config/sql/ippool-dhcp/oracle/procedure.sql @@ -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 diff --git a/raddb/mods-config/sql/ippool-dhcp/oracle/queries.conf b/raddb/mods-config/sql/ippool-dhcp/oracle/queries.conf index 9f1b551b255..1c4a40901fc 100644 --- a/raddb/mods-config/sql/ippool-dhcp/oracle/queries.conf +++ b/raddb/mods-config/sql/ippool-dhcp/oracle/queries.conf @@ -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 #