Skip to content

Commit 8f66d26

Browse files
author
Sheng Yang
committed
IPv6: Enable VR's ability to provide DHCPv6 service
1 parent f89c660 commit 8f66d26

7 files changed

Lines changed: 120 additions & 24 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,9 @@ protected synchronized Answer execute(final SavePasswordCommand cmd) {
569569
protected synchronized Answer execute (final DhcpEntryCommand cmd) {
570570
final Script command = new Script(_dhcpEntryPath, _timeout, s_logger);
571571
command.add("-r", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
572-
command.add("-v", cmd.getVmIpAddress());
572+
if (cmd.getVmIpAddress() != null) {
573+
command.add("-v", cmd.getVmIpAddress());
574+
}
573575
command.add("-m", cmd.getVmMac());
574576
command.add("-n", cmd.getVmName());
575577

@@ -583,6 +585,11 @@ protected synchronized Answer execute (final DhcpEntryCommand cmd) {
583585
if (cmd.getDefaultDns() != null) {
584586
command.add("-N", cmd.getDefaultDns());
585587
}
588+
589+
if (cmd.getVmIp6Address() != null) {
590+
command.add("-6", cmd.getVmIp6Address());
591+
command.add("-u", cmd.getDuid());
592+
}
586593

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

patches/systemvm/debian/config/etc/dnsmasq.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ domain=2.vmops-test.vmops.com
141141
# a lease time. If you have more than one network, you will need to
142142
# repeat this for each network on which you want to supply DHCP
143143
# service.
144-
dhcp-range=10.1.1.1,static
144+
dhcp-range_ip4=10.1.1.1,static
145+
dhcp-range_ip6=::1,static
145146
dhcp-hostsfile=/etc/dhcphosts.txt
146147

147148
# This is an example of a DHCP range where the netmask is given. This

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ setup_common() {
398398

399399
setup_dnsmasq() {
400400
log_it "Setting up dnsmasq"
401-
[ -z $DHCP_RANGE ] && DHCP_RANGE=$ETH0_IP
401+
[ -z $DHCP_RANGE ] && [ $ETH0_IP ] && DHCP_RANGE=$ETH0_IP
402+
[ $ETH0_IP6 ] && DHCP_RANGE_IP6=$ETH0_IP6
402403
[ -z $DOMAIN ] && DOMAIN="cloudnine.internal"
403404

404405
if [ -n "$DOMAIN" ]
@@ -422,8 +423,20 @@ setup_dnsmasq() {
422423
sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\""$DNS_SEARCH_ORDER"\"/ /etc/dnsmasq.conf
423424
fi
424425

425-
sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf
426-
sed -i -e "s/^[#]*listen-address=.*$/listen-address=$ETH0_IP/" /etc/dnsmasq.conf
426+
if [ $DHCP_RANGE ]
427+
then
428+
sed -i -e "s/^dhcp-range_ip4=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf
429+
else
430+
sed -i -e "s/^dhcp-range_ip4=.*$//" /etc/dnsmasq.conf
431+
fi
432+
if [ $DHCP_RANGE_IP6 ]
433+
then
434+
sed -i -e "s/^dhcp-range_ip6=.*$/dhcp-range=$DHCP_RANGE_IP6,static/" /etc/dnsmasq.conf
435+
else
436+
sed -i -e "s/^dhcp-range_ip6=.*$//" /etc/dnsmasq.conf
437+
fi
438+
439+
sed -i -e "s/^[#]*listen-address=.*$/listen-address=$LOCAL_ADDRS/" /etc/dnsmasq.conf
427440

428441
if [ "$RROUTER" == "1" ]
429442
then
@@ -707,14 +720,15 @@ setup_dhcpsrvr() {
707720
if [ "$DEFAULTROUTE" != "false" ]
708721
then
709722
sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf
710-
echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf
723+
[ $GW ] && echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf
711724
#for now set up ourself as the dns server as well
712725
sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf
713726
if [ "$USE_EXTERNAL_DNS" == "true" ]
714727
then
715728
echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf
716729
else
717-
echo "dhcp-option=6,$ETH0_IP,$NS" >> /etc/dnsmasq.conf
730+
[ $ETH0_IP ] && echo "dhcp-option=6,$ETH0_IP,$NS" >> /etc/dnsmasq.conf
731+
[ $ETH0_IP6 ] && echo "dhcp-option=option6:dns-server,[::]" >> /etc/dnsmasq.conf
718732
fi
719733
else
720734
sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf
@@ -1034,8 +1048,11 @@ for i in $CMDLINE
10341048
;;
10351049
esac
10361050
done
1037-
}
10381051

1052+
[ $ETH0_IP ] && LOCAL_ADDRS=$ETH0_IP
1053+
[ $ETH0_IP6 ] && LOCAL_ADDRS=$ETH0_IP6
1054+
[ $ETH0_IP ] && [ $ETH0_IP6 ] && LOCAL_ADDRS="$ETH0_IP,$ETH0_IP6"
1055+
}
10391056

10401057
case "$1" in
10411058
start)

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

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,29 @@
2727
# $6 : comma separated static routes
2828

2929
usage() {
30-
printf "Usage: %s: -m <MAC address> -4 <IPv4 address> -h <hostname> -d <default router> -n <name server address> -s <Routes> \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" $(basename $0) >&2
3131
}
3232

3333
mac=
3434
ipv4=
35+
ipv6=
3536
host=
3637
dflt=
3738
dns=
3839
routes=
40+
duid=
3941

40-
while getopts 'm:4:h:d:n:s:' OPTION
42+
while getopts 'm:4:h:d:n:s:6:u:' OPTION
4143
do
4244
case $OPTION in
4345
m) mac="$OPTARG"
4446
;;
4547
4) ipv4="$OPTARG"
4648
;;
49+
6) ipv6="$OPTARG"
50+
;;
51+
u) duid="$OPTARG"
52+
;;
4753
h) host="$OPTARG"
4854
;;
4955
d) dflt="$OPTARG"
@@ -95,26 +101,69 @@ logger -t cloud "edithosts: update $1 $2 $3 to hosts"
95101
[ ! -f $DHCP_LEASES ] && touch $DHCP_LEASES
96102

97103
#delete any previous entries from the dhcp hosts file
98-
sed -i /$mac/d $DHCP_HOSTS
99-
sed -i /$ipv4,/d $DHCP_HOSTS
100-
sed -i /$host,/d $DHCP_HOSTS
104+
sed -i /$mac/d $DHCP_HOSTS
105+
if [ $ipv4 ]
106+
then
107+
sed -i /$ipv4,/d $DHCP_HOSTS
108+
fi
109+
if [ $ipv6 ]
110+
then
111+
sed -i /$ipv6,/d $DHCP_HOSTS
112+
fi
113+
sed -i /$host,/d $DHCP_HOSTS
101114

102115

103116
#put in the new entry
104-
echo "$mac,$ipv4,$host,infinite" >>$DHCP_HOSTS
117+
if [ $ipv4 ]
118+
then
119+
echo "$mac,$ipv4,$host,infinite" >>$DHCP_HOSTS
120+
fi
121+
if [ $ipv6 ]
122+
then
123+
echo "id:$duid,[$ipv6],$host,infinite" >>$DHCP_HOSTS
124+
fi
105125

106126
#delete leases to supplied mac and ip addresses
107-
sed -i /$mac/d $DHCP_LEASES
108-
sed -i /"$ipv4 "/d $DHCP_LEASES
127+
if [ $ipv4 ]
128+
then
129+
sed -i /$mac/d $DHCP_LEASES
130+
sed -i /"$ipv4 "/d $DHCP_LEASES
131+
fi
132+
if [ $ipv6 ]
133+
then
134+
sed -i /$duid/d $DHCP_LEASES
135+
sed -i /"$ipv6 "/d $DHCP_LEASES
136+
fi
109137
sed -i /"$host "/d $DHCP_LEASES
110138

111139
#put in the new entry
112-
echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES
140+
if [ $ipv4 ]
141+
then
142+
echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES
143+
fi
144+
if [ $ipv6 ]
145+
then
146+
echo "0 $duid $ipv6 $host *" >> $DHCP_LEASES
147+
fi
113148

114149
#edit hosts file as well
115-
sed -i /"$ipv4 "/d $HOSTS
150+
if [ $ipv4 ]
151+
then
152+
sed -i /"$ipv4 "/d $HOSTS
153+
fi
154+
if [ $ipv6 ]
155+
then
156+
sed -i /"$ipv6 "/d $HOSTS
157+
fi
116158
sed -i /" $host$"/d $HOSTS
117-
echo "$ipv4 $host" >> $HOSTS
159+
if [ $ipv4 ]
160+
then
161+
echo "$ipv4 $host" >> $HOSTS
162+
fi
163+
if [ $ipv6 ]
164+
then
165+
echo "$ipv6 $host" >> $HOSTS
166+
fi
118167

119168
if [ "$dflt" != "" ]
120169
then

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,9 @@ protected Answer execute(DhcpEntryCommand cmd) {
16301630

16311631
// ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
16321632
String args = " -m " + cmd.getVmMac();
1633-
args += " -4 " + cmd.getVmIpAddress();
1633+
if (cmd.getVmIpAddress() != null) {
1634+
args += " -4 " + cmd.getVmIpAddress();
1635+
}
16341636
args += " -h " + cmd.getVmName();
16351637

16361638
if (cmd.getDefaultRouter() != null) {
@@ -1642,7 +1644,12 @@ protected Answer execute(DhcpEntryCommand cmd) {
16421644
}
16431645

16441646
if (cmd.getStaticRoutes() != null) {
1645-
args += " -s " + cmd.getStaticRoutes();
1647+
args += " -s " + cmd.getStaticRoutes();
1648+
}
1649+
1650+
if (cmd.getVmIp6Address() != null) {
1651+
args += " -6 " + cmd.getVmIp6Address();
1652+
args += " -u " + cmd.getDuid();
16461653
}
16471654

16481655
if (s_logger.isDebugEnabled()) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,9 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) {
17501750
protected synchronized Answer execute(final DhcpEntryCommand cmd) {
17511751
Connection conn = getConnection();
17521752
String args = "-r " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
1753-
args += " -v " + cmd.getVmIpAddress();
1753+
if (cmd.getVmIpAddress() != null) {
1754+
args += " -v " + cmd.getVmIpAddress();
1755+
}
17541756
args += " -m " + cmd.getVmMac();
17551757
args += " -n " + cmd.getVmName();
17561758
if (cmd.getDefaultRouter() != null) {
@@ -1764,6 +1766,11 @@ protected synchronized Answer execute(final DhcpEntryCommand cmd) {
17641766
args += " -N " + cmd.getDefaultDns();
17651767
}
17661768

1769+
if (cmd.getVmIp6Address() != null) {
1770+
args += " -6 " + cmd.getVmIp6Address();
1771+
args += " -u " + cmd.getDuid();
1772+
}
1773+
17671774
String result = callHostPlugin(conn, "vmops", "saveDhcpEntry", "args", args);
17681775
if (result == null || result.isEmpty()) {
17691776
return new Answer(cmd, false, "DhcpEntry failed");

scripts/network/domr/dhcp_entry.sh

Lines changed: 10 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>\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>\n" $(basename $0) >&2
2626
exit 2
2727
}
2828

@@ -35,10 +35,12 @@ vmName=
3535
staticrt=
3636
dfltrt=
3737
dns=
38+
ipv6=
39+
duid=
3840

3941
opts=
4042

41-
while getopts 'r:m:v:n:d:s:N:' OPTION
43+
while getopts 'r:m:v:n:d:s:N:6:u:' OPTION
4244
do
4345
case $OPTION in
4446
r) domrIp="$OPTARG"
@@ -61,6 +63,12 @@ do
6163
N) dns="$OPTARG"
6264
opts="$opts -n $dns"
6365
;;
66+
6) ipv6="$OPTARG"
67+
opts="$opts -6 $ipv6"
68+
;;
69+
u) duid="$OPTARG"
70+
opts="$opts -u $duid"
71+
;;
6472
?) usage
6573
exit 1
6674
;;

0 commit comments

Comments
 (0)