Skip to content

Commit e35ce65

Browse files
author
Sheng Yang
committed
CLOUDSTACK-1461: Don't set dns server for non-default ipv6 network
The non-default parameter can be used by ipv4 as well in the future.
1 parent e40ebcc commit e35ce65

8 files changed

Lines changed: 44 additions & 9 deletions

File tree

api/src/com/cloud/agent/api/routing/DhcpEntryCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class DhcpEntryCommand extends NetworkElementCommand {
3131
String vmIp6Address;
3232
String ip6Gateway;
3333
String duid;
34+
private boolean isDefault;
3435

3536
protected DhcpEntryCommand() {
3637

@@ -46,6 +47,7 @@ public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName, String
4647
this.vmIpAddress = vmIpAddress;
4748
this.vmName = vmName;
4849
this.vmIp6Address = vmIp6Address;
50+
this.setDefault(true);
4951
}
5052

5153
public DhcpEntryCommand(String vmMac, String vmIpAddress, String vmName, String vmIp6Address, String dns, String gateway, String ip6Gateway) {
@@ -129,4 +131,12 @@ public String getVmIp6Address() {
129131
public void setVmIp6Address(String ip6Address) {
130132
this.vmIp6Address = ip6Address;
131133
}
134+
135+
public boolean isDefault() {
136+
return isDefault;
137+
}
138+
139+
public void setDefault(boolean isDefault) {
140+
this.isDefault = isDefault;
141+
}
132142
}

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,10 @@ protected synchronized Answer execute (final DhcpEntryCommand cmd) {
600600
command.add("-6", cmd.getVmIp6Address());
601601
command.add("-u", cmd.getDuid());
602602
}
603+
604+
if (!cmd.isDefault()) {
605+
command.add("-z");
606+
}
603607

604608
final String result = command.execute();
605609
return new Answer(cmd, result==null, result);

patches/systemvm/debian/config/etc/init.d/cloud-early-config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ setup_dnsmasq() {
425425
sed -r -i s/^[#]?domain=.*$/domain=$DOMAIN/ /etc/dnsmasq.conf
426426
#answer all local domain queries
427427
sed -i -e "s/^[#]*local=.*$/local=\/$DOMAIN\//" /etc/dnsmasq.conf
428-
429428
fi
430429

431430
if [ -n "$DNS_SEARCH_ORDER" ]
@@ -447,6 +446,9 @@ setup_dnsmasq() {
447446
if [ $DHCP_RANGE_IP6 ]
448447
then
449448
sed -i -e "s/^dhcp-range_ip6=.*$/dhcp-range=$DHCP_RANGE_IP6,static/" /etc/dnsmasq.conf
449+
# For nondefault6 tagged host, don't send dns-server information
450+
sed -i /nondefault6/d /etc/dnsmasq.conf
451+
echo "dhcp-option=nondefault6,option6:dns-server" >> /etc/dnsmasq.conf
450452
else
451453
sed -i -e "s/^dhcp-range_ip6=.*$//" /etc/dnsmasq.conf
452454
fi

patches/systemvm/debian/config/root/edithosts.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# $6 : comma separated static routes
2828

2929
usage() {
30-
printf "Usage: %s: -m <MAC address> -4 <IPv4 address> -6 <IPv6 address> -h <hostname> -d <default router> -n <name server address> -s <Routes> -u <DUID>\n" $(basename $0) >&2
30+
printf "Usage: %s: -m <MAC address> -4 <IPv4 address> -6 <IPv6 address> -h <hostname> -d <default router> -n <name server address> -s <Routes> -u <DUID> [-N]\n" $(basename $0) >&2
3131
}
3232

3333
mac=
@@ -38,8 +38,9 @@ dflt=
3838
dns=
3939
routes=
4040
duid=
41+
nondefault=
4142

42-
while getopts 'm:4:h:d:n:s:6:u:' OPTION
43+
while getopts 'm:4:h:d:n:s:6:u:N' OPTION
4344
do
4445
case $OPTION in
4546
m) mac="$OPTARG"
@@ -58,6 +59,8 @@ do
5859
;;
5960
s) routes="$OPTARG"
6061
;;
62+
N) nondefault=1
63+
;;
6164
?) usage
6265
exit 2
6366
;;
@@ -120,7 +123,12 @@ then
120123
fi
121124
if [ $ipv6 ]
122125
then
123-
echo "id:$duid,[$ipv6],$host,infinite" >>$DHCP_HOSTS
126+
if [ $nondefault ]
127+
then
128+
echo "id:$duid,set:nondefault6,[$ipv6],$host,infinite" >>$DHCP_HOSTS
129+
else
130+
echo "id:$duid,[$ipv6],$host,infinite" >>$DHCP_HOSTS
131+
fi
124132
fi
125133

126134
#delete leases to supplied mac and ip addresses
@@ -176,8 +184,8 @@ then
176184
if [ "$dflt" == "0.0.0.0" ]
177185
then
178186
logger -t cloud "$0: unset default router for $ipv4"
187+
logger -t cloud "$0: unset dns server for $ipv4"
179188
echo "$tag,3" >> $DHCP_OPTS
180-
logger -t cloud "$0: setting dns server for $ipv4 to $dns"
181189
echo "$tag,6" >> $DHCP_OPTS
182190
echo "$tag,15" >> $DHCP_OPTS
183191
fi

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,11 @@ protected Answer execute(DhcpEntryCommand cmd) {
17551755
args += " -6 " + cmd.getVmIp6Address();
17561756
args += " -u " + cmd.getDuid();
17571757
}
1758-
1758+
1759+
if (!cmd.isDefault()) {
1760+
args += " -N";
1761+
}
1762+
17591763
if (s_logger.isDebugEnabled()) {
17601764
s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/edithosts.sh " + args);
17611765
}

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,10 @@ protected synchronized Answer execute(final DhcpEntryCommand cmd) {
18901890
args += " -u " + cmd.getDuid();
18911891
}
18921892

1893+
if (!cmd.isDefault()) {
1894+
args += " -z";
1895+
}
1896+
18931897
String result = callHostPlugin(conn, "vmops", "saveDhcpEntry", "args", args);
18941898
if (result == null || result.isEmpty()) {
18951899
return new Answer(cmd, false, "DhcpEntry failed");

scripts/network/domr/dhcp_entry.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# @VERSION@
2323

2424
usage() {
25-
printf "Usage: %s: -r <domr-ip> -m <vm mac> -v <vm ip> -n <vm name> -s <static route> -d <default router> -N <dns> -6 <vm IPv6> -u <duid>\n" $(basename $0) >&2
25+
printf "Usage: %s: -r <domr-ip> -m <vm mac> -v <vm ip> -n <vm name> -s <static route> -d <default router> -N <dns> -6 <vm IPv6> -u <duid> [-z]\n" $(basename $0) >&2
2626
exit 2
2727
}
2828

@@ -40,7 +40,7 @@ duid=
4040

4141
opts=
4242

43-
while getopts 'r:m:v:n:d:s:N:6:u:' OPTION
43+
while getopts 'r:m:v:n:d:s:N:6:u:z' OPTION
4444
do
4545
case $OPTION in
4646
r) domrIp="$OPTARG"
@@ -69,6 +69,8 @@ do
6969
u) duid="$OPTARG"
7070
opts="$opts -u $duid"
7171
;;
72+
z) opts="$opts -N"
73+
;;
7274
?) usage
7375
exit 1
7476
;;

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,16 +3116,17 @@ private void createDhcpEntryCommand(VirtualRouter router, UserVm vm, NicVO nic,
31163116
if (guestOS.getDisplayName().startsWith(name)) {
31173117
needGateway = true;
31183118
break;
3119+
}
31193120
}
31203121
}
3121-
}
31223122
if (!needGateway) {
31233123
gatewayIp = "0.0.0.0";
31243124
}
31253125
dhcpCommand.setDefaultRouter(gatewayIp);
31263126
dhcpCommand.setIp6Gateway(nic.getIp6Gateway());
31273127
dhcpCommand.setDefaultDns(findDefaultDnsIp(vm.getId()));
31283128
dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
3129+
dhcpCommand.setDefault(nic.isDefaultNic());
31293130

31303131
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
31313132
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());

0 commit comments

Comments
 (0)