diff options
author | Indrajit Raychaudhuri <irc@indrajit.com> | 2023-12-16 19:04:36 -0600 |
---|---|---|
committer | Indrajit Raychaudhuri <irc@indrajit.com> | 2023-12-17 00:28:49 -0600 |
commit | 04e958c15364abd9ed6f82ee9453e8d72f04b547 (patch) | |
tree | a8f94107ec235e969aaaedc740596e9b4a892516 /src | |
parent | 03202504d559417266e437bbf53eb26ade187c07 (diff) | |
download | vyos-1x-04e958c15364abd9ed6f82ee9453e8d72f04b547.tar.gz vyos-1x-04e958c15364abd9ed6f82ee9453e8d72f04b547.zip |
dhcp: T3316: Adjust dhcp-run script to align with kea hooks
The hook arguments passed to `on-dhcp-event.sh` have changed in Kea.
Adjust the script to align with the new arguments.
Additionally, remove FQDN mangling from the script. No need to extract
the domain name from `LEASE4_HOSTNAME` only to append it again.
See: https://kea.readthedocs.io/en/latest/arm/hooks.html#hooks-run-script
Diffstat (limited to 'src')
-rwxr-xr-x | src/system/on-dhcp-event.sh | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/system/on-dhcp-event.sh b/src/system/on-dhcp-event.sh index 7b25bf338..03574bdc3 100755 --- a/src/system/on-dhcp-event.sh +++ b/src/system/on-dhcp-event.sh @@ -8,7 +8,7 @@ # Thanks to forum user "ruudboon" for multiple domain fix # Thanks to forum user "chibby85" for expire patch and static-mapping -if [ $# -lt 5 ]; then +if [ $# -lt 1 ]; then echo Invalid args logger -s -t on-dhcp-event "Invalid args \"$@\"" exit 1 @@ -18,36 +18,30 @@ action=$1 client_name=$LEASE4_HOSTNAME client_ip=$LEASE4_ADDRESS client_mac=$LEASE4_HWADDR -domain=$(echo "$client_name" | cut -d"." -f2-) hostsd_client="/usr/bin/vyos-hostsd-client" case "$action" in - leases4_renew|lease4_recover) # add mapping for new lease + lease4_renew|lease4_recover) # add mapping for new/recovered lease address if [ -z "$client_name" ]; then logger -s -t on-dhcp-event "Client name was empty, using MAC \"$client_mac\" instead" - client_name=$(echo "client-"$client_mac | tr : -) + client_name=$(echo "host-$client_mac" | tr : -) fi - if [ -z "$domain" ]; then - client_fqdn_name=$client_name - client_search_expr=$client_name - else - client_fqdn_name=$client_name.$domain - client_search_expr="$client_name\\.$domain" - fi - $hostsd_client --add-hosts "$client_fqdn_name,$client_ip" --tag "dhcp-server-$client_ip" --apply + $hostsd_client --add-hosts "$client_name,$client_ip" --tag "dhcp-server-$client_ip" --apply exit 0 ;; - lease4_release|lease4_expire) # delete mapping for released address) + lease4_release|lease4_expire|lease4_decline) # delete mapping for released/declined address $hostsd_client --delete-hosts --tag "dhcp-server-$client_ip" --apply exit 0 ;; + leases4_committed) # nothing to do + exit 0 + ;; + *) logger -s -t on-dhcp-event "Invalid command \"$1\"" exit 1 ;; esac - -exit 0 |