From 9f5ac89c9a01619bff61bacb94182bae7e0336eb Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Mon, 4 Oct 2021 11:40:25 +0200 Subject: [PATCH] VR: fix data-server if shared network has multiple ip ranges (#5530) * VR: fix data-server if shared network has multiple ip ranges This fixes #5518 * Update PR #5530: fix nameserver in vm with IP in additional IP ranges without this change ``` root@r-757-VM:~# cat /etc/dnsmasq.d/cloud.conf listen-address=127.0.0.1,10.10.12.31,10.10.13.19 dhcp-range=set:interface-eth0-0,10.10.12.31,static dhcp-option=tag:interface-eth0-0,15,cs1cloud.internal dhcp-option=tag:interface-eth0-0,6,10.10.12.31,10.0.32.1,8.8.8.8 dhcp-option=tag:interface-eth0-0,3,10.10.12.254 dhcp-option=tag:interface-eth0-0,1,255.255.255.0 dhcp-range=set:interface-eth0-1,10.10.13.19,static dhcp-option=tag:interface-eth0-1,15,cs1cloud.internal dhcp-option=tag:interface-eth0-1,6,10.10.12.31,10.0.32.1,8.8.8.8 <<< nameserver 10.10.12.31 dhcp-option=tag:interface-eth0-1,3,10.10.13.254 dhcp-option=tag:interface-eth0-1,1,255.255.255.0 ``` with this change ``` root@r-757-VM:~# cat /etc/dnsmasq.d/cloud.conf listen-address=127.0.0.1,10.10.12.31,10.10.13.19 dhcp-range=set:interface-eth0-0,10.10.12.31,static dhcp-option=tag:interface-eth0-0,15,cs1cloud.internal dhcp-option=tag:interface-eth0-0,6,10.10.12.31,10.0.32.1,8.8.8.8 dhcp-option=tag:interface-eth0-0,3,10.10.12.254 dhcp-option=tag:interface-eth0-0,1,255.255.255.0 dhcp-range=set:interface-eth0-1,10.10.13.19,static dhcp-option=tag:interface-eth0-1,15,cs1cloud.internal dhcp-option=tag:interface-eth0-1,6,10.10.13.19,10.0.32.1,8.8.8.8 <<< nameserver 10.10.13.19 dhcp-option=tag:interface-eth0-1,3,10.10.13.254 dhcp-option=tag:interface-eth0-1,1,255.255.255.0 ``` * Update #5530: add 'localise-queries' to /etc/dnsmasq.conf --- systemvm/debian/etc/dnsmasq.conf.tmpl | 1 + systemvm/debian/opt/cloud/bin/cs/CsDhcp.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/systemvm/debian/etc/dnsmasq.conf.tmpl b/systemvm/debian/etc/dnsmasq.conf.tmpl index 4e9d2496293..f0925541090 100644 --- a/systemvm/debian/etc/dnsmasq.conf.tmpl +++ b/systemvm/debian/etc/dnsmasq.conf.tmpl @@ -636,3 +636,4 @@ log-facility=/var/log/dnsmasq.log conf-dir=/etc/dnsmasq.d dhcp-optsfile=/etc/dhcpopts.txt +localise-queries diff --git a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py index 0caba6dea26..964cf7a860d 100755 --- a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py +++ b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py @@ -108,6 +108,12 @@ class CsDhcp(CsDataBag): if gn.get_dns() and device: sline = "dhcp-option=tag:interface-%s-%s,6" % (device, idx) dns_list = [x for x in gn.get_dns() if x] + if self.config.is_dhcp() and not self.config.use_extdns(): + guest_ip = self.config.address().get_guest_ip() + if guest_ip and guest_ip in dns_list and ip not in dns_list: + ## Replace the default guest IP in VR with the ip in additional IP ranges, if shared network has multiple IP ranges. + dns_list.remove(guest_ip) + dns_list.insert(0, ip) line = "dhcp-option=tag:interface-%s-%s,6,%s" % (device, idx, ','.join(dns_list)) self.conf.search(sline, line) if gateway != '0.0.0.0': @@ -129,8 +135,10 @@ class CsDhcp(CsDataBag): else: listen_address.append(ip) # Add localized "data-server" records in /etc/hosts for VPC routers - if self.config.is_vpc(): + if self.config.is_vpc() or self.config.is_router(): self.add_host(gateway, "%s data-server" % CsHelper.get_hostname()) + elif self.config.is_dhcp(): + self.add_host(ip, "%s data-server" % CsHelper.get_hostname()) idx += 1 # Listen Address @@ -166,8 +174,6 @@ class CsDhcp(CsDataBag): self.add_host("::1", "localhost ip6-localhost ip6-loopback") self.add_host("ff02::1", "ip6-allnodes") self.add_host("ff02::2", "ip6-allrouters") - if self.config.is_router() or self.config.is_dhcp(): - self.add_host(self.config.address().get_guest_ip(), "%s data-server" % CsHelper.get_hostname()) def write_hosts(self): file = CsFile("/etc/hosts")