Skip to content

Commit 7978367

Browse files
Chiradeep VittalAlena Prokharchyk
authored andcommitted
bug 10804: add default dns provider
1 parent 8de5916 commit 7978367

3 files changed

Lines changed: 119 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
# $ip : the associated ip address
2525
# $host : the hostname
2626
# $4 : default router
27-
# $5 : comma separated static routes
27+
# $5 : nameserver on default nic
28+
# $6 : comma separated static routes
2829

2930
mac=$1
3031
ip=$2
3132
host=$3
3233
dflt=$4
33-
routes=$5
34+
dns=$5
35+
routes=$6
3436

3537
DHCP_HOSTS=/etc/dhcphosts.txt
3638
DHCP_OPTS=/etc/dhcpopts.txt
@@ -99,13 +101,19 @@ echo "$ip $host" >> $HOSTS
99101

100102
if [ "$dflt" != "" ]
101103
then
104+
logger -t cloud "$0: setting default router to $dflt"
102105
#make sure dnsmasq looks into options file
103106
sed -i /dhcp-optsfile/d /etc/dnsmasq.conf
104107
echo "dhcp-optsfile=$DHCP_OPTS" >> /etc/dnsmasq.conf
105108

106109
tag=$(echo $ip | tr '.' '_')
107110
sed -i /$tag/d $DHCP_OPTS
108111
echo "$tag,3,$dflt" >> $DHCP_OPTS
112+
if [ "$dns" != "" ]
113+
then
114+
logger -t cloud "$0: setting dns server to $dns"
115+
echo "$tag,6,$dns" >> $DHCP_OPTS
116+
fi
109117
[ "$routes" != "" ] && echo "$tag,121,$routes" >> $DHCP_OPTS
110118
#delete entry we just put in because we need a tag
111119
sed -i /$mac/d $DHCP_HOSTS
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
3+
4+
5+
#
6+
# Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
7+
#
8+
# This software is licensed under the GNU General Public License v3 or later.
9+
#
10+
# It is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or any later version.
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
22+
# edithosts.sh -- edit the dhcphosts file on the routing domain
23+
# $1 : the mac address
24+
# $2 : the associated ip address
25+
# $3 : the hostname
26+
27+
source /root/func.sh
28+
29+
lock="biglock"
30+
locked=$(getLockFile $lock)
31+
if [ "$locked" != "1" ]
32+
then
33+
exit 1
34+
fi
35+
36+
lock_rr="rrouter"
37+
locked_rr=$(getLockFile $lock_rr)
38+
if [ "$locked_rr" != "1" ]
39+
then
40+
exit 1
41+
fi
42+
43+
grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null
44+
no_redundant=$?
45+
46+
wait_for_dnsmasq () {
47+
local _pid=$(pidof dnsmasq)
48+
for i in 0 1 2 3 4 5 6 7 8 9 10
49+
do
50+
sleep 1
51+
_pid=$(pidof dnsmasq)
52+
[ "$_pid" != "" ] && break;
53+
done
54+
[ "$_pid" != "" ] && return 0;
55+
logger -t cloud "edithosts: timed out waiting for dnsmasq to start"
56+
return 1
57+
}
58+
59+
logger -t cloud "edithosts: update $1 $2 $3 to hosts"
60+
61+
[ ! -f /etc/dhcphosts.txt ] && touch /etc/dhcphosts.txt
62+
[ ! -f /var/lib/misc/dnsmasq.leases ] && touch /var/lib/misc/dnsmasq.leases
63+
64+
#delete any previous entries from the dhcp hosts file
65+
sed -i /$1/d /etc/dhcphosts.txt
66+
sed -i /$2,/d /etc/dhcphosts.txt
67+
sed -i /$3,/d /etc/dhcphosts.txt
68+
69+
#put in the new entry
70+
echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt
71+
72+
#delete leases to supplied mac and ip addresses
73+
sed -i /$1/d /var/lib/misc/dnsmasq.leases
74+
sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases
75+
sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases
76+
77+
#put in the new entry
78+
echo "0 $1 $2 $3 *" >> /var/lib/misc/dnsmasq.leases
79+
80+
#edit hosts file as well
81+
sed -i /"$2 "/d /etc/hosts
82+
sed -i /"$3"/d /etc/hosts
83+
echo "$2 $3" >> /etc/hosts
84+
85+
# make dnsmasq re-read files
86+
pid=$(pidof dnsmasq)
87+
if [ "$pid" != "" ]
88+
then
89+
service dnsmasq restart
90+
else
91+
if [ $no_redundant -eq 1 ]
92+
then
93+
wait_for_dnsmasq
94+
else
95+
logger -t cloud "edithosts: skip wait dnsmasq due to redundant virtual router"
96+
fi
97+
fi
98+
99+
ret=$?
100+
releaseLockFile $lock_rr $locked_rr
101+
unlock_exit $ret $lock $locked

scripts/network/domr/dhcp_entry.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ add_dhcp_entry() {
3838
local ip=$3
3939
local vm=$4
4040
local dfltrt=$5
41-
local staticrt=$6
42-
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $staticrt" >/dev/null
41+
local ns=$6
42+
local staticrt=$7
43+
ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null
4344
return $?
4445
}
4546

@@ -49,8 +50,9 @@ vmIp=
4950
vmName=
5051
staticrt=
5152
dfltrt=
53+
dns=
5254

53-
while getopts 'r:m:v:n:d:s:' OPTION
55+
while getopts 'r:m:v:n:d:s:N:' OPTION
5456
do
5557
case $OPTION in
5658
r) domrIp="$OPTARG"
@@ -65,12 +67,14 @@ do
6567
;;
6668
d) dfltrt="$OPTARG"
6769
;;
70+
N) dns="$OPTARG"
71+
;;
6872
?) usage
6973
exit 1
7074
;;
7175
esac
7276
done
7377

74-
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $staticrt
78+
add_dhcp_entry $domrIp $vmMac $vmIp $vmName $dfltrt $dns $staticrt
7579

7680
exit $?

0 commit comments

Comments
 (0)