diff options
-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 |