blob: 124f349263c88920d6705e0e5a6895b3b3886dad [file] [log] [blame]
Chetan Gaonker7f4bf742016-05-04 15:56:08 -07001# -*- text -*-
2#
3# ippool-dhcp/sqlite/queries.conf -- SQLite queries for rlm_sqlippool
4#
5# $Id: 8709a562ee8877f02a43118464371eae101f3fbc $
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 <= datetime(strftime('%%s', 'now') - 1, 'unixepoch') \
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 (\
46 ((expiry_time < datetime('now')) OR expiry_time IS NULL) \
47 OR (callingstationid = '%{Calling-Station-Id}') \
48 AND expiry_time > datetime('now')\
49 ) \
50 ORDER BY \
51 (callingstationid <> '%{Calling-Station-Id}'), \
52 expiry_time \
53 LIMIT 1"
54
55#
56# If you prefer to allocate a random IP address every time, use this query instead
57#
58#allocate_find = "\
59# SELECT framedipaddress FROM ${ippool_table} \
60# WHERE pool_name = '%{control:Pool-Name}' \
61# AND expiry_time IS NULL \
62# ORDER BY RAND() \
63# LIMIT 1 \
64# FOR UPDATE"
65
66#
67# If an IP could not be allocated, check to see if the pool exists or not
68# This allows the module to differentiate between a full pool and no pool
69# Note: If you are not running redundant pool modules this query may be
70# commented out to save running this query every time an ip is not allocated.
71#
72pool_check = "\
73 SELECT id \
74 FROM ${ippool_table} \
75 WHERE pool_name='%{control:Pool-Name}' \
76 LIMIT 1"
77
78#
79# This is the final IP Allocation query, which saves the allocated ip details
80#
81allocate_update = "\
82 UPDATE ${ippool_table} \
83 SET \
84 nasipaddress = '%{NAS-IP-Address}', \
85 pool_key = '${pool_key}', \
86 callingstationid = '%{Calling-Station-Id}', \
87 username = '%{User-Name}', \
88 expiry_time = datetime(strftime('%%s', 'now') + ${lease_duration}, 'unixepoch') \
89 WHERE framedipaddress = '%I' \
90 AND expiry_time IS NULL"
91
92#
93# The following queries are not used for DHCP IP assignment.
94#
95
96#
97# This series of queries frees an IP number when an accounting START record arrives
98#
99start_update = "\
100 UPDATE ${ippool_table} \
101 SET \
102 expiry_time = datetime(strftime('%%s', 'now') + ${lease_duration}, 'unixepoch') \
103 WHERE nasipaddress = '%{NAS-IP-Address}' \
104 AND pool_key = '${pool_key}' \
105 AND username = '%{User-Name}' \
106 AND callingstationid = '%{Calling-Station-Id}' \
107 AND framedipaddress = '%{Framed-IP-Address}'"
108
109#
110# This series of queries frees an IP number when an accounting STOP record arrives
111#
112stop_clear = "\
113 UPDATE ${ippool_table} \
114 SET \
115 nasipaddress = '', \
116 pool_key = 0, \
117 callingstationid = '', \
118 username = '', \
119 expiry_time = NULL \
120 WHERE nasipaddress = '%{Nas-IP-Address}' \
121 AND pool_key = '${pool_key}' \
122 AND username = '%{User-Name}' \
123 AND callingstationid = '%{Calling-Station-Id}' \
124 AND framedipaddress = '%{Framed-IP-Address}'"
125
126#
127# This series of queries frees an IP number when an accounting ALIVE record arrives
128#
129alive_update = "\
130 UPDATE ${ippool_table} \
131 SET \
132 expiry_time = datetime(strftime('%%s', 'now') + ${lease_duration}, 'unixepoch') \
133 WHERE nasipaddress = '%{Nas-IP-Address}' \
134 AND pool_key = '${pool_key}' \
135 AND username = '%{User-Name}' \
136 AND callingstationid = '%{Calling-Station-Id}' \
137 AND framedipaddress = '%{Framed-IP-Address}'"
138
139#
140# This series of queries frees the IP numbers allocate to a
141# NAS when an accounting ON record arrives
142#
143on_clear = "\
144 UPDATE ${ippool_table} \
145 SET \
146 nasipaddress = '', \
147 pool_key = 0, \
148 callingstationid = '', \
149 username = '', \
150 expiry_time = NULL \
151 WHERE \nasipaddress = '%{Nas-IP-Address}'"
152
153#
154# This series of queries frees the IP numbers allocate to a
155# NAS when an accounting OFF record arrives
156#
157off_clear = "\
158 UPDATE ${ippool_table} \
159 SET \
160 nasipaddress = '', \
161 pool_key = 0, \
162 callingstationid = '', \
163 username = '', \
164 expiry_time = NULL \
165 WHERE nasipaddress = '%{Nas-IP-Address}'"