-- '%{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 = ""
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;
-- 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
#
# 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.
'%{control:${pool_name}}', \
'%{DHCP-Gateway-IP-Address}', \
'${pool_key}', \
- '${lease_duration}' \
+ '${offer_duration}', \
+ '%{%{${req_attribute_name}}:-0.0.0.0}'
)"
alloc_update = ""
alloc_commit = ""
#
# 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
#