Skip to content

Commit

Permalink
Merge pull request #3250 from c-po/dhcpv6-T2590-equuleus
Browse files Browse the repository at this point in the history
dhcpv6-client: T2590: fix vyos-hostsd update for nameserver and search domains (backport #3224)
  • Loading branch information
c-po authored Apr 5, 2024
2 parents ae96118 + acb0152 commit d5750f0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
31 changes: 31 additions & 0 deletions data/templates/dhcp-client/dhcp6c-script.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
# Update DNS information for DHCPv6 clients
# should be used only if vyos-hostsd is running

if /usr/bin/systemctl -q is-active vyos-hostsd; then
hostsd_client="/usr/bin/vyos-hostsd-client"
hostsd_changes=

if [ -n "$new_domain_name" ]; then
logmsg info "Deleting search domains with tag \"dhcpv6-{{ ifname }}\" via vyos-hostsd-client"
$hostsd_client --delete-search-domains --tag "dhcpv6-{{ ifname }}"
logmsg info "Adding domain name \"$new_domain_name\" as search domain with tag \"dhcpv6-{{ ifname }}\" via vyos-hostsd-client"
$hostsd_client --add-search-domains "$new_domain_name" --tag "dhcpv6-{{ ifname }}"
hostsd_changes=y
fi

if [ -n "$new_domain_name_servers" ]; then
logmsg info "Deleting nameservers with tag \"dhcpv6-{{ ifname }}\" via vyos-hostsd-client"
$hostsd_client --delete-name-servers --tag "dhcpv6-{{ ifname }}"
logmsg info "Adding nameservers \"$new_domain_name_servers\" with tag \"dhcpv6-{{ ifname }}\" via vyos-hostsd-client"
$hostsd_client --add-name-servers $new_domain_name_servers --tag "dhcpv6-{{ ifname }}"
hostsd_changes=y
fi

if [ $hostsd_changes ]; then
logmsg info "Applying changes via vyos-hostsd-client"
$hostsd_client --apply
else
logmsg info "No changes to apply via vyos-hostsd-client"
fi
fi
1 change: 1 addition & 0 deletions data/templates/dhcp-client/ipv6.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface {{ ifname }} {
send ia-pd {{ pd }}; # prefix delegation #{{ pd }}
{% endfor %}
{% endif %}
script "{{ dhcp6_script_file }}";
};

{% if address is defined and 'dhcpv6' in address %}
Expand Down
16 changes: 12 additions & 4 deletions python/vyos/ifconfig/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -1186,12 +1186,18 @@ def set_dhcpv6(self, enable):

ifname = self.ifname
config_file = f'/run/dhcp6c/dhcp6c.{ifname}.conf'
script_file = f'/etc/wide-dhcpv6/dhcp6c.{ifname}.script' # can not live under /run b/c of noexec mount option
systemd_override_file = f'/run/systemd/system/dhcp6c@{ifname}.service.d/10-override.conf'
systemd_service = f'dhcp6c@{ifname}.service'

if enable and 'disable' not in self.config:
render(systemd_override_file, 'dhcp-client/ipv6.override.conf.j2', self.config)
render(config_file, 'dhcp-client/ipv6.tmpl', self.config)
# Rendered client configuration files require additional settings
config = deepcopy(self.config)
config['dhcp6_script_file'] = script_file

if enable and 'disable' not in config:
render(systemd_override_file, 'dhcp-client/ipv6.override.conf.j2', config)
render(config_file, 'dhcp-client/ipv6.tmpl', config)
render(script_file, 'dhcp-client/dhcp6c-script.j2', config, permission=0o755)

# Reload systemd unit definitons as some options are dynamically generated
self._cmd('systemctl daemon-reload')
Expand All @@ -1204,6 +1210,8 @@ def set_dhcpv6(self, enable):
self._cmd(f'systemctl stop {systemd_service}')
if os.path.isfile(config_file):
os.remove(config_file)
if os.path.isfile(script_file):
os.remove(script_file)

def set_mirror(self):
# Please refer to the document for details
Expand Down
16 changes: 0 additions & 16 deletions src/etc/dhcp/dhclient-enter-hooks.d/04-vyos-resolvconf
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ if /usr/bin/systemctl -q is-active vyos-hostsd; then
hostsd_changes=y
fi

if [ -n "$new_dhcp6_domain_search" ]; then
logmsg info "Deleting search domains with tag \"dhcpv6-$interface\" via vyos-hostsd-client"
$hostsd_client --delete-search-domains --tag "dhcpv6-$interface"
logmsg info "Adding search domain \"$new_dhcp6_domain_search\" with tag \"dhcpv6-$interface\" via vyos-hostsd-client"
$hostsd_client --add-search-domains "$new_dhcp6_domain_search" --tag "dhcpv6-$interface"
hostsd_changes=y
fi

if [ -n "$new_domain_name_servers" ]; then
logmsg info "Deleting nameservers with tag \"dhcp-$interface\" via vyos-hostsd-client"
$hostsd_client --delete-name-servers --tag "dhcp-$interface"
Expand All @@ -30,14 +22,6 @@ if /usr/bin/systemctl -q is-active vyos-hostsd; then
hostsd_changes=y
fi

if [ -n "$new_dhcp6_name_servers" ]; then
logmsg info "Deleting nameservers with tag \"dhcpv6-$interface\" via vyos-hostsd-client"
$hostsd_client --delete-name-servers --tag "dhcpv6-$interface"
logmsg info "Adding nameservers \"$new_dhcp6_name_servers\" with tag \"dhcpv6-$interface\" via vyos-hostsd-client"
$hostsd_client --add-name-servers $new_dhcp6_name_servers --tag "dhcpv6-$interface"
hostsd_changes=y
fi

if [ $hostsd_changes ]; then
logmsg info "Applying changes via vyos-hostsd-client"
$hostsd_client --apply
Expand Down

0 comments on commit d5750f0

Please sign in to comment.