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