blob: eb1a79d74cb812a80f0dd7561bb2617bf5c6d1fb [file] [log] [blame]
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001# -*- text -*-
2#
3# ippool-dhcp/mysql/queries.conf -- MySQL queries for rlm_sqlippool
4#
5# $Id: ac9476e5091010d39c9212e424efb360a99a1e71 $
6
7#
8# This series of queries allocates an IP address
9#
10#allocate_clear = "\
11# UPDATE ${ippool_table} \
12# SET \
13# nasipaddress = '', \
14# pool_key = 0, \
15# callingstationid = '', \
16# username = '', \
17# expiry_time = NULL \
18# WHERE pool_key = '${pool_key}'"
19
20#
21# This series of queries allocates an IP address
22# (Note: If your pool_key is set to Calling-Station-Id and not NAS-Port
23# then you may wish to delete the "AND nasipaddress = '%{Nas-IP-Address}'
24# from the WHERE clause)
25#
26allocate_clear = "\
27 UPDATE ${ippool_table} \
28 SET \
29 nasipaddress = '', \
30 pool_key = 0, \
31 callingstationid = '', \
32 username = '', \
33 expiry_time = NULL \
34 WHERE expiry_time <= NOW() - INTERVAL 1 SECOND \
35 AND nasipaddress = '%{Nas-IP-Address}'"
36
37#
38# The ORDER BY clause of this query tries to allocate the same IP-address
39# which user had last session...
40#
41allocate_find = "\
42 SELECT framedipaddress \
43 FROM ${ippool_table} \
44 WHERE pool_name = '%{control:Pool-Name}' \
45 AND (expiry_time < NOW() OR expiry_time IS NULL) \
46 ORDER BY \
47 (username <> '%{User-Name}'), \
48 (callingstationid <> '%{Calling-Station-Id}'), \
49 expiry_time \
50 LIMIT 1 \
51 OR UPDATE"
52
53#
54# If you prefer to allocate a random IP address every time, use this query instead
55#
56#allocate_find = "\
57# SELECT framedipaddress \
58# FROM ${ippool_table} \
59# WHERE pool_name = '%{control:Pool-Name}' \
60# AND expiry_time IS NULL \
61# ORDER BY RAND() \
62# LIMIT 1 \
63# FOR UPDATE"
64
65#
66# If an IP could not be allocated, check to see if the pool exists or not
67# This allows the module to differentiate between a full pool and no pool
68# Note: If you are not running redundant pool modules this query may be
69# commented out to save running this query every time an ip is not allocated.
70#
71pool_check = "\
72 SELECT id \
73 FROM ${ippool_table} \
74 WHERE pool_name='%{control:Pool-Name}' \
75 LIMIT 1"
76
77#
78# This is the final IP Allocation query, which saves the allocated ip details
79#
80allocate_update = "\
81 UPDATE ${ippool_table} \
82 SET \
83 nasipaddress = '%{NAS-IP-Address}', \
84 pool_key = '${pool_key}', \
85 callingstationid = '%{Calling-Station-Id}', \
86 username = '%{User-Name}', \
87 expiry_time = NOW() + INTERVAL ${lease_duration} SECOND \
88 WHERE framedipaddress = '%I' AND expiry_time IS NULL"
89
90#
91# This series of queries frees an IP number when an accounting
92# START record arrives
93#
94start_update = "\
95 UPDATE ${ippool_table} \
96 SET \
97 expiry_time = NOW() + INTERVAL ${lease_duration} SECOND \
98 WHERE nasipaddress = '%{NAS-IP-Address}' \
99 AND pool_key = '${pool_key}' \
100 AND username = '%{User-Name}' \
101 AND callingstationid = '%{Calling-Station-Id}' \
102 AND framedipaddress = '%{Framed-IP-Address}'"
103
104#
105# This series of queries frees an IP number when an accounting
106# STOP record arrives
107#
108stop_clear = "UPDATE ${ippool_table} \
109 SET \
110 nasipaddress = '', \
111 pool_key = 0, \
112 callingstationid = '', \
113 username = '', \
114 expiry_time = NULL \
115 WHERE nasipaddress = '%{Nas-IP-Address}' \
116 AND pool_key = '${pool_key}' \
117 AND username = '%{User-Name}' \
118 AND callingstationid = '%{Calling-Station-Id}' \
119 AND framedipaddress = '%{Framed-IP-Address}'"
120
121#
122# This series of queries frees an IP number when an accounting
123# ALIVE record arrives
124#
125alive_update = "\
126 UPDATE ${ippool_table} \
127 SET \
128 expiry_time = NOW() + INTERVAL ${lease_duration} SECOND \
129 WHERE nasipaddress = '%{Nas-IP-Address}' \
130 AND pool_key = '${pool_key}' \
131 AND username = '%{User-Name}' \
132 AND callingstationid = '%{Calling-Station-Id}' \
133 AND framedipaddress = '%{Framed-IP-Address}'"
134
135#
136# This series of queries frees the IP numbers allocate to a
137# NAS when an accounting ON record arrives
138#
139on_clear = "\
140 UPDATE ${ippool_table} \
141 SET \
142 nasipaddress = '', \
143 pool_key = 0, \
144 callingstationid = '', \
145 username = '', \
146 expiry_time = NULL \
147 WHERE nasipaddress = '%{Nas-IP-Address}'"
148
149#
150# This series of queries frees the IP numbers allocate to a
151# NAS when an accounting OFF record arrives
152#
153off_clear = "\
154 UPDATE ${ippool_table} \
155 SET \
156 nasipaddress = '', \
157 pool_key = 0, \
158 callingstationid = '', \
159 username = '', \
160 expiry_time = NULL \
161 WHERE nasipaddress = '%{Nas-IP-Address}'"