-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkea-lease-unbound-control.sh
539 lines (489 loc) · 18.3 KB
/
kea-lease-unbound-control.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
#!/bin/sh
###
# kea-lease-unbound-control.sh
# version: 0.1
# git: https://github.com/nvandamme/kea-lease-unbound-control
# licence: GPL3
###
# kea-lease-unbound-control.sh
PROGNAME="$(basename $0)"
# version
VERSION="0.1"
# Load environment variables from known locations
if [ -f "/etc/kea/kea-lease-unbound-control.conf" ]; then
. "/etc/kea/kea-lease-unbound-control.conf"
elif [ -f "/etc/kea-lease-unbound-control.conf" ]; then
. "/etc/kea-lease-unbound-control.conf"
elif [ -f "/usr/local/etc/kea/kea-lease-unbound-control.conf" ]; then
. "/usr/local/etc/kea/kea-lease-unbound-control.conf"
elif [ -f "/usr/local/etc/kea-lease-unbound-control.conf" ]; then
. "/usr/local/etc/kea-lease-unbound-control.conf"
elif [ -f "$0.env" ]; then
. "$0.env"
elif [ -f "/etc/default/kea-lease-unbound-control.conf" ]; then
. "/etc/default/kea-lease-unbound-control.conf"
fi
# Set default values
if [ -z "$UNBOUND_CONTROL_PATH" ]; then
UNBOUND_CONTROL_PATH="/usr/sbin/unbound-control"
fi
if [ -z "$UNBOUND_CONFIG_PATH" ]; then
UNBOUND_CONFIG_PATH="/etc/unbound/unbound.conf"
fi
if [ -z "$UNBOUND_CONTROL_IP" ]; then
UNBOUND_CONTROL_IP="127.0.0.1"
fi
if [ -z "$UNBOUND_CONTROL_PORT" ]; then
UNBOUND_CONTROL_PORT="953"
fi
if [ -z "$LOCAL_DOMAIN" ]; then
LOCAL_DOMAIN="lan"
fi
if [ -z "$LOG_FILE" ]; then
LOG_FILE="/var/log/kea-lease-unbound-control.log"
fi
# Set unbound-control command
UNBOUND_CONTROL="${UNBOUND_CONTROL_PATH} -c ${UNBOUND_CONFIG_PATH} -s ${UNBOUND_CONTROL_IP}@${UNBOUND_CONTROL_PORT}"
# Display help
HELP=$(cat <<-'EOF'
Usage: kea-lease-unbound-control.sh <kea_hook_point_function> [kea_hook_point_function_arguments]
Script to manage unbound local data entries for kea leases
Refer to the Kea documentation for the hook points and their arguments:
- https://kea.readthedocs.io/en/latest/arm/hooks.html#libdhcp-run-script-so-run-script-support-for-external-hook-scripts
Options:
-h, --help Display this help and exit
-v, --version Output version information and exit
-s, --setup Display setup instructions
EOF
)
# Display setup instructions
SETUP=$(cat <<-'EOF'
Setup:
- Install kea
- Install unbound
- Configure unbound-control to listen on 127.0.0.1:953
- Configure unbound local_zone with a local domain
```sh
local-zone: "lan." transparent
```
- Configure kea to call this script with the appropriate hook (using kea's default `libdhcp_run_script.so`)
```json
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
"parameters": {
"name": "/usr/local/bin/kea-lease-unbound-control.sh",
"sync": "false"
}
}
]
```
- Configure kea to add DCHP option domain-search match the unbound default local-zone
```json
"option-data": [
{
"name": "domain-name-servers",
"data": "192.168.1.1, fe80::ffff:ffff:ffff:ffff"
},
{
"name": "domain-name",
"data": "lan"
}
]
```
- Configure environment variables via `/path/to/kea-lease-unbound-control.sh.env` or your preferred `etc` location
```sh
UNBOUND_CONTROL_PATH="/usr/sbin/unbound-control"
UNBOUND_CONFIG_PATH="/etc/unbound/unbound.conf"
UNBOUND_CONTROL_IP="127.0.0.1"
UNBOUND_CONTROL_PORT="953"
LOCAL_DOMAIN="lan"
LOG_ENABLED=1
LOG_FILE="/var/log/kea-lease-unbound-control.log"
```
- Ensure the config is readable and the script is executable and readable by kea's process user:
```sh
chown kea:kea /path/to/kea-lease-unbound-control.sh
chmod +x /path/to/kea-lease-unbound-control.sh
chown kea:kea /path/to/kea-lease-unbound-control.sh.env
```
EOF
)
# Log function
log() {
if [ $LOG_ENABLED=1 ]; then
echo "$(date) ${PROGNAME}: ${*}" >> $LOG_FILE
fi
}
# Check if string is an IPv4 address
is_ipv4() {
echo $1 |\
grep -qs "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" ||\
return 1
return 0
}
# Convert IPv4 address to PTR record
ip_to_ptr() {
echo $1 | awk -F. '{print $4"."$3"."$2"."$1".in-addr.arpa"}'
}
# Expand IPv6 address
# > https://stackoverflow.com/questions/14697403/expand-ipv6-address-in-shell-script
# > credits to https://stackoverflow.com/users/1009901/yeti
expand_ipv6() {
__expand_ipv6_ip="${1%%/*}"
__expand_ipv6_mask=""
case "$1" in
*/*)
__expand_ipv6_mask="${1#*/}"
__expand_ipv6_mask="/${__expand_ipv6_mask%%[^0-9/]*}"
esac
case "$__expand_ipv6_ip" in
:*) __expand_ipv6_ip="0$__expand_ipv6_ip"
esac
case "$__expand_ipv6_ip" in
*::*)
__expand_ipv6_colons="$(echo "$__expand_ipv6_ip" | tr -c -d ':')"
__expand_ipv6_expanded="$(echo ":::::::::" | sed -e "s/$__expand_ipv6_colons//" -e 's/:/:0/g')"
__expand_ipv6_ip="$(echo "$__expand_ipv6_ip" | sed "s/::/$__expand_ipv6_expanded/")"
;;
esac
__expand_ipv6_blocks="$(echo "$__expand_ipv6_ip" | grep -o '[0-9a-f]\+' | while read -r __expand_ipv6_hex; do [ -n "$__expand_ipv6_hex" ] && printf " %d" "$((0x$__expand_ipv6_hex % 65536))"; done)"
printf "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x" $__expand_ipv6_blocks
printf "%s\n" "$__expand_ipv6_mask"
}
# Compress IPv6 address
# > https://stackoverflow.com/questions/14697403/expand-ipv6-address-in-shell-script
# > credits to https://stackoverflow.com/users/1009901/yeti
compress_ipv6() {
__compress_ipv6_ip="$(echo "$1" | sed -e 's/::/:0:/g' | grep -o "[0-9a-f]\+" | while read -r __compress_ipv6_hex; do [ -n "$__compress_ipv6_hex" ] && printf ":%x" "$((0x$__compress_ipv6_hex))"; done)"
for __compress_ipv6_chain in :0:0:0:0:0:0:0:0 :0:0:0:0:0:0:0 :0:0:0:0:0:0 :0:0:0:0:0 :0:0:0:0 :0:0:0 :0:0 :0
do
case "$__compress_ipv6_ip" in
*$__compress_ipv6_chain*)
__compress_ipv6_ip="$(echo "$__compress_ipv6_ip" | sed -e "s/$__compress_ipv6_chain/::/" -e 's/:::/::/')"
break
esac
done
case "$__compress_ipv6_ip" in
::*) ;;
:*) __compress_ipv6_ip="${__compress_ipv6_ip#:}"
esac
echo "$__compress_ipv6_ip"
}
# Check if string is an IPv6 address
is_ipv6() {
echo $1 |\
grep -qs "[0-9a-f:]\{1,39\}" ||\
return 1
return 0
}
# Clean hostname for local data entry (remove trailing dot, replace dots with hyphens)
clean_hostname() {
echo "$1" | sed 's/\.$//' | sed 's/\./-/'
}
# Convert IPv6 address to PTR record
ip6_to_ptr6() {
is_ipv6 $1 || return 1
expanded=$(expand_ipv6 $1)
echo $expanded | awk -F: '{
gsub(/:/,"")
for (i=length($0); i>0; i--) {
printf "%s.", substr($0,i,1)
}
print "ip6.arpa"
}'
}
# Convert PTR record to IPv4 address
ptr_to_ip() {
echo $1 | awk -F. '{print $4"."$3"."$2"."$1}'
}
# Convert PTR record to IPv6 address
ptr6_to_ip6() {
echo $1 | awk -F. '{print $32$31$30$29":"$28$27$26$25":"$24$23$22$21":"$20$19$18$17":"$16$15$14$13":"$12$11$10$9":"$8$7$6$5":"$4$3$2$1}'
}
# Handle unknown function calls
unknown_handle() {
echo "Unhandled function call ${*}"
exit 123
}
# Add lease4 entry to unbound local data
add_lease4() {
# $1 = hostname (LEASE4_HOSTNAME)
# $2 = ipv4 address (LEASE4_ADDRESS)
HOSTNAME=$(clean_hostname $1)
log "Adding A and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2"
PTR=$(ip_to_ptr $2)
$UNBOUND_CONTROL local_data "${HOSTNAME}"."${LOCAL_DOMAIN}" A "${2}"
$UNBOUND_CONTROL local_data "${PTR}" PTR "${HOSTNAME}"."${LOCAL_DOMAIN}"
log "Added A and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2 -> ${PTR}"
}
# Remove lease4 entry from unbound local data
del_lease4() {
# $1 = hostname (LEASE4_HOSTNAME)
# $2 = ipv4 address (LEASE4_ADDRESS)
HOSTNAME=$(clean_hostname $1)
log "Removing A and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2"
PTR=$(ip_to_ptr $2)
$UNBOUND_CONTROL local_data_remove "${HOSTNAME}"."${LOCAL_DOMAIN}" A "${2}"
$UNBOUND_CONTROL local_data_remove "${PTR}" PTR "${HOSTNAME}"
log "Removed A and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2 -> ${PTR}"
}
# Add lease6 entry to unbound local data
add_lease6() {
# $1 = hostname (LEASE6_HOSTNAME)
# $2 = ipv6 address (LEASE6_ADDRESS)
# $3 = ipv6 local address (QUERY6_REMOTE_ADDR)
HOSTNAME=$(clean_hostname $1)
log "Adding AAAA and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2"
PTR6=$(ip6_to_ptr6 $2)
$UNBOUND_CONTROL local_data "${HOSTNAME}"."${LOCAL_DOMAIN}" AAAA "${2}"
$UNBOUND_CONTROL local_data "${PTR6}" PTR "${HOSTNAME}"."${LOCAL_DOMAIN}"
if [ $3 ]; then
PTR6LOCAL=$(ip6_to_ptr6 $3)
$UNBOUND_CONTROL local_data "${HOSTNAME}"."${LOCAL_DOMAIN}" AAAA "${3}"
$UNBOUND_CONTROL local_data "${PTR6LOCAL}"."${LOCAL_DOMAIN}" PTR "${HOSTNAME}"
log "Added AAAA and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2, $3 -> ${PTR6}, ${PTR6LOCAL}"
else
log "Added AAAA and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2, $3 -> ${PTR6}"
fi
}
# Remove lease6 entry from unbound local data
del_lease6() {
# $1 = hostname (LEASE6_HOSTNAME)
# $2 = ipv6 address (LEASE6_ADDRESS)
# $3 = ipv6 local address (QUERY6_REMOTE_ADDR)
HOSTNAME=$(clean_hostname $1)
log "Removing AAAA and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2"
PTR6=$(ip6_to_ptr6 $2)
$UNBOUND_CONTROL local_data_remove "${HOSTNAME}"."${LOCAL_DOMAIN}" AAAA "${2}"
$UNBOUND_CONTROL local_data_remove "${PTR6}" PTR "${HOSTNAME}"."${LOCAL_DOMAIN}"
if [ $3 ]; then
PTR6LOCAL=$(ip6_to_ptr6 $3)
$UNBOUND_CONTROL local_data_remove "${HOSTNAME}"."${LOCAL_DOMAIN}" AAAA "${3}"
$UNBOUND_CONTROL local_data_remove "${PTR6LOCAL}" PTR "${HOSTNAME}"."${LOCAL_DOMAIN}"
log "Removed AAAA and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2, $3 -> ${PTR6}, ${PTR6LOCAL}"
else
log "Removed AAAA and PTR records for ${HOSTNAME}.${LOCAL_DOMAIN} -> $2 -> ${PTR6}"
fi
}
# Handle kea hook point lease4_renew
lease4_renew () {
log "Renewing lease4 ${LEASE4_ADDRESS} for ${LEASE4_HOSTNAME}"
add_lease4 $LEASE4_HOSTNAME $LEASE4_ADDRESS
return 0 # handled by leases4_committed in case of multiple leases
}
# Handle kea hook point lease4_expire
lease4_expire () {
log "Expiring lease4 ${LEASE4_ADDRESS} for ${LEASE4_HOSTNAME}"
del_lease4 $LEASE4_HOSTNAME $LEASE4_ADDRESS
return 0 # handled by leases4_committed in case of multiple leases
}
# Handle kea hook point lease4_recover
lease4_recover () {
log "Recovering lease4 ${LEASE4_ADDRESS} for ${LEASE4_HOSTNAME}"
add_lease4 $LEASE4_HOSTNAME $LEASE4_ADDRESS
return 0 # handled by leases4_committed in case of multiple leases
}
# Handle kea hook point leases4_committed
leases4_committed () {
if [ $LEASES4_SIZE -gt 0 ]; then
MAX_LEASES=$((${LEASES4_SIZE} - 1))
SEQ=$(seq 0 $MAX_LEASES)
for i in $SEQ; do
LEASE4_HOSTNAME=$(eval echo "\$LEASES4_AT${i}_HOSTNAME")
LEASE4_ADDRESS=$(eval echo "\$LEASES4_AT${i}_ADDRESS")
log "Committed lease4 ${LEASE4_ADDRESS} for ${LEASE4_HOSTNAME}"
add_lease4 $LEASE4_HOSTNAME $LEASE4_ADDRESS
done
elif [ $LEASES4_AT0_ADDRESS ]; then
log "Committed lease4 ${LEASES4_AT0_ADDRESS} for ${LEASES4_AT0_HOSTNAME}"
add_lease4 $LEASES4_AT0_HOSTNAME $LEASES4_AT0_ADDRESS
elif [ $LEASE4_ADDRESS ]; then
log "Committed lease4 ${LEASE4_ADDRESS} for ${LEASE4_HOSTNAME}"
add_lease4 $LEASE4_HOSTNAME $LEASE4_ADDRESS
fi
if [ $DELETED_LEASES4_SIZE -gt 0 ]; then
MAX_LEASES=$((${DELETED_LEASES4_SIZE} - 1))
SEQ=$(seq 0 $MAX_LEASES)
for i in $SEQ; do
DELETED_LEASE4_HOSTNAME=$(eval echo "\$DELETED_LEASES4_AT${i}_HOSTNAME")
DELETED_LEASE4_ADDRESS=$(eval echo "\$DELETED_LEASES4_AT${i}_ADDRESS")
log "Deleted lease4 ${DELETED_LEASE4_ADDRESS} for ${DELETED_LEASE4_HOSTNAME}"
del_lease4 $DELETED_LEASE4_HOSTNAME $DELETED_LEASE4_ADDRESS
done
elif [ $DELETED_LEASES4_AT0_ADDRESS ]; then
log "Deleted lease4 ${DELETED_LEASES4_AT0_ADDRESS} for ${DELETED_LEASES4_AT0_HOSTNAME}"
del_lease4 $DELETED_LEASES4_AT0_HOSTNAME $DELETED_LEASES4_AT0_ADDRESS
elif [ $DELETED_LEASE4_ADDRESS ]; then
log "Deleted lease4 ${DELETED_LEASE4_ADDRESS} for ${DELETED_LEASE4_HOSTNAME}"
del_lease4 $DELETED_LEASE4_HOSTNAME $DELETED_LEASE4_ADDRESS
fi
return 0
}
# Handle kea hook point lease4_release
lease4_release () {
log "Releasing lease4 ${LEASE4_ADDRESS} for ${LEASE4_HOSTNAME}"
del_lease4 $LEASE4_HOSTNAME $LEASE4_ADDRESS
return 0 # handled by leases4_committed in case of multiple leases
}
# Handle kea hook point lease4_decline
lease4_decline () {
return 0 # handled by leases4_committed
}
# Handle kea hook point lease6_renew
lease6_renew () {
log "Renewing lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
return 0 # handled by leases6_committed in case of multiple leases
}
# Handle kea hook point lease6_rebind
lease6_rebind () {
log "Rebinding lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
return 0 # handled by leases6_committed in case of multiple leases
}
# Handle kea hook point lease6_expire
lease6_expire () {
log "Expiring lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
del_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
return 0 # handled by leases6_committed in case of multiple leases
}
# Handle kea hook point lease6_recover
lease6_recover () {
log "Recovering lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
return 0 # handled by leases6_committed in case of multiple leases
}
# Handle kea hook point leases6_committed
leases6_committed () {
if [ $LEASES6_SIZE -gt 0 ]; then
MAX_LEASES=$((${LEASES6_SIZE} - 1))
SEQ=$(seq 0 $MAX_LEASES)
for i in $SEQ; do
LEASE6_ADDRESS=$(eval echo "\$LEASES6_AT${i}_ADDRESS")
LEASE6_HOSTNAME=$(eval echo "\$LEASES6_AT${i}_HOSTNAME")
if [ $QUERY6_REMOTE_ADDR ]; then
log "Committed lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
else
log "Committed lease6 ${LEASE6_ADDRESS} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS
fi
done
elif [ $LEASES6_AT0_ADDRESS ]; then
if [ $QUERY6_REMOTE_ADDR ]; then
log "Committed lease6 ${LEASES6_AT0_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASES6_AT0_HOSTNAME}"
add_lease6 $LEASES6_AT0_HOSTNAME $LEASES6_AT0_ADDRESS $QUERY6_REMOTE_ADDR
else
log "Committed lease6 ${LEASES6_AT0_ADDRESS} for ${LEASES6_AT0_HOSTNAME}"
add_lease6 $LEASES6_AT0_HOSTNAME $LEASES6_AT0_ADDRESS
fi
elif [ $LEASE6_ADDRESS ]; then
if [ $QUERY6_REMOTE_ADDR ]; then
log "Committed lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
else
log "Committed lease6 ${LEASE6_ADDRESS} for ${LEASE6_HOSTNAME}"
add_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS
fi
fi
if [ $DELETED_LEASES6_SIZE -gt 0 ]; then
MAX_LEASES=$((${DELETED_LEASES6_SIZE} - 1))
SEQ=$(seq 0 $MAX_LEASES)
for i in $SEQ; do
DELETED_LEASE6_ADDRESS=$(eval echo "\$DELETED_LEASES6_AT${i}_ADDRESS")
DELETED_LEASE6_HOSTNAME=$(eval echo "\$DELETED_LEASES6_AT${i}_HOSTNAME")
if [ $QUERY6_REMOTE_ADDR ]; then
log "Deleted lease6 ${DELETED_LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${DELETED_LEASE6_HOSTNAME}"
del_lease6 $DELETED_LEASE6_HOSTNAME $DELETED_LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
else
log "Deleted lease6 ${DELETED_LEASE6_ADDRESS} for ${DELETED_LEASE6_HOSTNAME}"
del_lease6 $DELETED_LEASE6_HOSTNAME $DELETED_LEASE6_ADDRESS
fi
done
elif [ $DELETED_LEASES6_AT0_ADDRESS ]; then
if [ $QUERY6_REMOTE_ADDR ]; then
log "Deleted lease6 ${DELETED_LEASES6_AT0_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${DELETED_LEASES6_AT0_HOSTNAME}"
del_lease6 $DELETED_LEASES6_AT0_HOSTNAME $DELETED_LEASES6_AT0_ADDRESS $QUERY6_REMOTE_ADDR
else
log "Deleted lease6 ${DELETED_LEASES6_AT0_ADDRESS} for ${DELETED_LEASE6_AT0_HOSTNAME}"
del_lease6 $DELETED_LEASE6_AT0_HOSTNAME $DELETED_LEASES6_AT0_ADDRESS
fi
elif [ $DELETED_LEASE6_ADDRESS ]; then
if [ $QUERY6_REMOTE_ADDR ]; then
log "Deleted lease6 ${DELETED_LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${DELETED_LEASE6_HOSTNAME}"
del_lease6 $DELETED_LEASE6_HOSTNAME $DELETED_LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
else
log "Deleted lease6 ${DELETED_LEASE6_ADDRESS} for ${DELETED_LEASE6_HOSTNAME}"
del_lease6 $DELETED_LEASE6_HOSTNAME $DELETED_LEASE6_ADDRESS
fi
fi
return 0
}
# Handle kea hook point lease6_release
lease6_release () {
log "Releasing lease6 ${LEASE6_ADDRESS}, ${QUERY6_REMOTE_ADDR} for ${LEASE6_HOSTNAME}"
del_lease6 $LEASE6_HOSTNAME $LEASE6_ADDRESS $QUERY6_REMOTE_ADDR
return 0 # handled by leases6_committed in case of multiple leases
}
# Handle kea hook point lease6_decline
lease6_decline () {
return 0 # handled by leases6_committed
}
# Handle function calls
case "$1" in
"lease4_renew")
lease4_renew
;;
"lease4_expire")
lease4_expire
;;
"lease4_recover")
lease4_recover
;;
"leases4_committed")
leases4_committed
;;
"lease4_release")
lease4_release
;;
"lease4_decline")
lease4_decline
;;
"lease6_renew")
lease6_renew
;;
"lease6_rebind")
lease6_rebind
;;
"lease6_expire")
lease6_expire
;;
"lease6_recover")
lease6_recover
;;
"leases6_committed")
leases6_committed
;;
"lease6_release")
lease6_release
;;
"lease6_decline")
lease6_decline
;;
"-h"|"--help")
echo "$HELP"
exit 0
;;
"-v"|"--version")
echo "$PROGNAME 0.1"
exit 0
;;
"-s"|"--setup")
echo "$SETUP"
exit 0
;;
*)
unknown_handle "${@}"
;;
esac