summaryrefslogtreecommitdiff
path: root/src/system/on-dhcp-event.sh
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2024-01-09 22:44:16 +0100
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2024-01-10 00:42:22 +0100
commit39bf15289ca10ff5b61eb4070292ffb13f53e94e (patch)
tree46a8adca0a3eb5af6d251a54556a5c2bf92e10f5 /src/system/on-dhcp-event.sh
parent0cd74e0795eaa9d71c9546cb6a4766661ffb6026 (diff)
downloadvyos-1x-39bf15289ca10ff5b61eb4070292ffb13f53e94e.tar.gz
vyos-1x-39bf15289ca10ff5b61eb4070292ffb13f53e94e.zip
dhcp: T3316: Workaround to append domain suffix to hostfile entries
Diffstat (limited to 'src/system/on-dhcp-event.sh')
-rwxr-xr-xsrc/system/on-dhcp-event.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/system/on-dhcp-event.sh b/src/system/on-dhcp-event.sh
index 3534fe601..e1a9f1884 100755
--- a/src/system/on-dhcp-event.sh
+++ b/src/system/on-dhcp-event.sh
@@ -17,6 +17,32 @@ fi
action=$1
hostsd_client="/usr/bin/vyos-hostsd-client"
+get_subnet_domain_name () {
+ python3 <<EOF
+from vyos.kea import kea_get_active_config
+from vyos.utils.dict import dict_search_args
+
+config = kea_get_active_config('4')
+shared_networks = dict_search_args(config, 'arguments', f'Dhcp4', 'shared-networks')
+
+found = False
+
+if shared_networks:
+ for network in shared_networks:
+ for subnet in network[f'subnet4']:
+ if subnet['id'] == $1:
+ for option in subnet['option-data']:
+ if option['name'] == 'domain-name':
+ print(option['data'])
+ found = True
+
+ if not found:
+ for option in network['option-data']:
+ if option['name'] == 'domain-name':
+ print(option['data'])
+EOF
+}
+
case "$action" in
lease4_renew|lease4_recover)
exit 0
@@ -45,6 +71,12 @@ case "$action" in
client_name=$(echo "host-$client_mac" | tr : -)
fi
+ client_domain=$(get_subnet_domain_name $client_subnet_id)
+
+ if [ -n "$client_domain" ]; then
+ client_name="$client_name.$client_domain"
+ fi
+
$hostsd_client --add-hosts "$client_name,$client_ip" --tag "dhcp-server-$client_ip" --apply
done