IPv6: Enable VR's ability to provide DHCPv6 service

This commit is contained in:
Sheng Yang 2013-01-24 20:09:37 -08:00
parent f89c66070b
commit 8f66d266b3
7 changed files with 120 additions and 24 deletions

View File

@ -569,7 +569,9 @@ public class VirtualRoutingResource implements Manager {
protected synchronized Answer execute (final DhcpEntryCommand cmd) {
final Script command = new Script(_dhcpEntryPath, _timeout, s_logger);
command.add("-r", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
command.add("-v", cmd.getVmIpAddress());
if (cmd.getVmIpAddress() != null) {
command.add("-v", cmd.getVmIpAddress());
}
command.add("-m", cmd.getVmMac());
command.add("-n", cmd.getVmName());
@ -583,6 +585,11 @@ public class VirtualRoutingResource implements Manager {
if (cmd.getDefaultDns() != null) {
command.add("-N", cmd.getDefaultDns());
}
if (cmd.getVmIp6Address() != null) {
command.add("-6", cmd.getVmIp6Address());
command.add("-u", cmd.getDuid());
}
final String result = command.execute();
return new Answer(cmd, result==null, result);

View File

@ -141,7 +141,8 @@ domain=2.vmops-test.vmops.com
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
dhcp-range=10.1.1.1,static
dhcp-range_ip4=10.1.1.1,static
dhcp-range_ip6=::1,static
dhcp-hostsfile=/etc/dhcphosts.txt
# This is an example of a DHCP range where the netmask is given. This

View File

@ -398,7 +398,8 @@ setup_common() {
setup_dnsmasq() {
log_it "Setting up dnsmasq"
[ -z $DHCP_RANGE ] && DHCP_RANGE=$ETH0_IP
[ -z $DHCP_RANGE ] && [ $ETH0_IP ] && DHCP_RANGE=$ETH0_IP
[ $ETH0_IP6 ] && DHCP_RANGE_IP6=$ETH0_IP6
[ -z $DOMAIN ] && DOMAIN="cloudnine.internal"
if [ -n "$DOMAIN" ]
@ -422,8 +423,20 @@ setup_dnsmasq() {
sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\""$DNS_SEARCH_ORDER"\"/ /etc/dnsmasq.conf
fi
sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf
sed -i -e "s/^[#]*listen-address=.*$/listen-address=$ETH0_IP/" /etc/dnsmasq.conf
if [ $DHCP_RANGE ]
then
sed -i -e "s/^dhcp-range_ip4=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf
else
sed -i -e "s/^dhcp-range_ip4=.*$//" /etc/dnsmasq.conf
fi
if [ $DHCP_RANGE_IP6 ]
then
sed -i -e "s/^dhcp-range_ip6=.*$/dhcp-range=$DHCP_RANGE_IP6,static/" /etc/dnsmasq.conf
else
sed -i -e "s/^dhcp-range_ip6=.*$//" /etc/dnsmasq.conf
fi
sed -i -e "s/^[#]*listen-address=.*$/listen-address=$LOCAL_ADDRS/" /etc/dnsmasq.conf
if [ "$RROUTER" == "1" ]
then
@ -707,14 +720,15 @@ setup_dhcpsrvr() {
if [ "$DEFAULTROUTE" != "false" ]
then
sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf
echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf
[ $GW ] && echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf
#for now set up ourself as the dns server as well
sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf
if [ "$USE_EXTERNAL_DNS" == "true" ]
then
echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf
else
echo "dhcp-option=6,$ETH0_IP,$NS" >> /etc/dnsmasq.conf
[ $ETH0_IP ] && echo "dhcp-option=6,$ETH0_IP,$NS" >> /etc/dnsmasq.conf
[ $ETH0_IP6 ] && echo "dhcp-option=option6:dns-server,[::]" >> /etc/dnsmasq.conf
fi
else
sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf
@ -1034,8 +1048,11 @@ for i in $CMDLINE
;;
esac
done
}
[ $ETH0_IP ] && LOCAL_ADDRS=$ETH0_IP
[ $ETH0_IP6 ] && LOCAL_ADDRS=$ETH0_IP6
[ $ETH0_IP ] && [ $ETH0_IP6 ] && LOCAL_ADDRS="$ETH0_IP,$ETH0_IP6"
}
case "$1" in
start)

View File

@ -27,23 +27,29 @@
# $6 : comma separated static routes
usage() {
printf "Usage: %s: -m <MAC address> -4 <IPv4 address> -h <hostname> -d <default router> -n <name server address> -s <Routes> \n" $(basename $0) >&2
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
}
mac=
ipv4=
ipv6=
host=
dflt=
dns=
routes=
duid=
while getopts 'm:4:h:d:n:s:' OPTION
while getopts 'm:4:h:d:n:s:6:u:' OPTION
do
case $OPTION in
m) mac="$OPTARG"
;;
4) ipv4="$OPTARG"
;;
6) ipv6="$OPTARG"
;;
u) duid="$OPTARG"
;;
h) host="$OPTARG"
;;
d) dflt="$OPTARG"
@ -95,26 +101,69 @@ logger -t cloud "edithosts: update $1 $2 $3 to hosts"
[ ! -f $DHCP_LEASES ] && touch $DHCP_LEASES
#delete any previous entries from the dhcp hosts file
sed -i /$mac/d $DHCP_HOSTS
sed -i /$ipv4,/d $DHCP_HOSTS
sed -i /$host,/d $DHCP_HOSTS
sed -i /$mac/d $DHCP_HOSTS
if [ $ipv4 ]
then
sed -i /$ipv4,/d $DHCP_HOSTS
fi
if [ $ipv6 ]
then
sed -i /$ipv6,/d $DHCP_HOSTS
fi
sed -i /$host,/d $DHCP_HOSTS
#put in the new entry
echo "$mac,$ipv4,$host,infinite" >>$DHCP_HOSTS
if [ $ipv4 ]
then
echo "$mac,$ipv4,$host,infinite" >>$DHCP_HOSTS
fi
if [ $ipv6 ]
then
echo "id:$duid,[$ipv6],$host,infinite" >>$DHCP_HOSTS
fi
#delete leases to supplied mac and ip addresses
sed -i /$mac/d $DHCP_LEASES
sed -i /"$ipv4 "/d $DHCP_LEASES
if [ $ipv4 ]
then
sed -i /$mac/d $DHCP_LEASES
sed -i /"$ipv4 "/d $DHCP_LEASES
fi
if [ $ipv6 ]
then
sed -i /$duid/d $DHCP_LEASES
sed -i /"$ipv6 "/d $DHCP_LEASES
fi
sed -i /"$host "/d $DHCP_LEASES
#put in the new entry
echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES
if [ $ipv4 ]
then
echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES
fi
if [ $ipv6 ]
then
echo "0 $duid $ipv6 $host *" >> $DHCP_LEASES
fi
#edit hosts file as well
sed -i /"$ipv4 "/d $HOSTS
if [ $ipv4 ]
then
sed -i /"$ipv4 "/d $HOSTS
fi
if [ $ipv6 ]
then
sed -i /"$ipv6 "/d $HOSTS
fi
sed -i /" $host$"/d $HOSTS
echo "$ipv4 $host" >> $HOSTS
if [ $ipv4 ]
then
echo "$ipv4 $host" >> $HOSTS
fi
if [ $ipv6 ]
then
echo "$ipv6 $host" >> $HOSTS
fi
if [ "$dflt" != "" ]
then

View File

@ -1630,7 +1630,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
// ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
String args = " -m " + cmd.getVmMac();
args += " -4 " + cmd.getVmIpAddress();
if (cmd.getVmIpAddress() != null) {
args += " -4 " + cmd.getVmIpAddress();
}
args += " -h " + cmd.getVmName();
if (cmd.getDefaultRouter() != null) {
@ -1642,7 +1644,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
if (cmd.getStaticRoutes() != null) {
args += " -s " + cmd.getStaticRoutes();
args += " -s " + cmd.getStaticRoutes();
}
if (cmd.getVmIp6Address() != null) {
args += " -6 " + cmd.getVmIp6Address();
args += " -u " + cmd.getDuid();
}
if (s_logger.isDebugEnabled()) {

View File

@ -1750,7 +1750,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
protected synchronized Answer execute(final DhcpEntryCommand cmd) {
Connection conn = getConnection();
String args = "-r " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
args += " -v " + cmd.getVmIpAddress();
if (cmd.getVmIpAddress() != null) {
args += " -v " + cmd.getVmIpAddress();
}
args += " -m " + cmd.getVmMac();
args += " -n " + cmd.getVmName();
if (cmd.getDefaultRouter() != null) {
@ -1764,6 +1766,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
args += " -N " + cmd.getDefaultDns();
}
if (cmd.getVmIp6Address() != null) {
args += " -6 " + cmd.getVmIp6Address();
args += " -u " + cmd.getDuid();
}
String result = callHostPlugin(conn, "vmops", "saveDhcpEntry", "args", args);
if (result == null || result.isEmpty()) {
return new Answer(cmd, false, "DhcpEntry failed");

View File

@ -22,7 +22,7 @@
# @VERSION@
usage() {
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
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
exit 2
}
@ -35,10 +35,12 @@ vmName=
staticrt=
dfltrt=
dns=
ipv6=
duid=
opts=
while getopts 'r:m:v:n:d:s:N:' OPTION
while getopts 'r:m:v:n:d:s:N:6:u:' OPTION
do
case $OPTION in
r) domrIp="$OPTARG"
@ -61,6 +63,12 @@ do
N) dns="$OPTARG"
opts="$opts -n $dns"
;;
6) ipv6="$OPTARG"
opts="$opts -6 $ipv6"
;;
u) duid="$OPTARG"
opts="$opts -u $duid"
;;
?) usage
exit 1
;;