93 lines
3.2 KiB
Bash
Executable File
93 lines
3.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Library used by /etc/bewan/scripts/update-dns
|
|
|
|
[ ${IPV4_DNS_LIB:-0} = 1 ] && return
|
|
IPV4_DNS_LIB=1
|
|
|
|
# This function will append informations on current interface to $dns_list and $defdns_list variables
|
|
|
|
append_dns4() {
|
|
[ ! -d $WAND/$i/ip ] && return
|
|
local servers=''
|
|
# Interface is up ?
|
|
local ipaddr=`cat $WAND/$i/ip/ipaddr 2>/dev/null`
|
|
if [ "$ipaddr" != '' ]; then
|
|
# DNS servers retrieved by DHCP or PPP negotiation
|
|
servers="`cat $WAND/$i/ip/servers 2>/dev/null`"
|
|
|
|
# Get DNS Domain list
|
|
local dnsdomain_with_server=''
|
|
local dnsdomains="`cat $WAND/$i/ip/dnsdomains 2>/dev/null`"
|
|
if [ "$dnsdomains" != '' ]; then
|
|
for domain in $dnsdomains; do
|
|
for server in $servers; do
|
|
# Domian DNS servers will be written in the following format
|
|
# /www.google.com/1.2.3.4
|
|
# will send queries for www.google.com to 1.2.3.4
|
|
dnsdomain_with_server="$dnsdomain_with_server /$domain/$server"
|
|
done
|
|
done
|
|
fi
|
|
# Bind these dns domain servers to the wan interface ip address
|
|
local listdnsdomain=''
|
|
for server in $dnsdomain_with_server; do
|
|
listdnsdomain="$listdnsdomain $server@$ipaddr"
|
|
done
|
|
# Add domain name servers even if DNSEnable field is 0
|
|
if [ "$listdnsdomain" != '' ]; then
|
|
dns_list="$dns_list $listdnsdomain"
|
|
fi
|
|
|
|
# Force static DNS if required
|
|
local staticdns="`cat $WAND/$i/ip/staticdns 2>/dev/null`"
|
|
if [ "$staticdns" != '' ]; then
|
|
# Override static by dynamic DNS servers (TR-098)
|
|
if [ -f "$WAND/$i/ip/dnsover" ]; then
|
|
servers="$servers $staticdns"
|
|
else
|
|
servers="$staticdns"
|
|
fi
|
|
fi
|
|
# Store the result for status information
|
|
echo $servers > $WAND/$i/ip/dnssrvlst
|
|
|
|
# Bind these servers to the wan interface ip address
|
|
local list=''
|
|
for server in $servers; do
|
|
list="$list $server@$ipaddr"
|
|
done
|
|
servers="$list"
|
|
|
|
# Interface is down
|
|
else
|
|
# NOTE for PPP on demand
|
|
# We have a fake DNS server, so that a DNS request will trigger the connection
|
|
# bind this server to the wan interface
|
|
local fakedns=`cat $WAND/$i/ip/fakednsserver 2>/dev/null`
|
|
local ifname=`cat $WAND/$i/ip/ifname 2>/dev/null`
|
|
[ "$fakedns" != "" ] && [ "$ifname" != "" ] && servers=$fakedns@$ifname
|
|
# For status information
|
|
rm -f $WAND/$i/ip/dnssrvlst
|
|
fi
|
|
|
|
# Add these servers to the global list if required by config
|
|
if [ -f "$WAND/$i/ip/enabledns" ] && [ "$servers" != '' ]; then
|
|
alt=`cat $WAND/$i/ip/altdns 2>/dev/null`
|
|
if [ "$alt" != '' ]; then
|
|
# DNS servers of alternate DNS forwarder
|
|
servers=`echo $servers | sed "s/ /,/g"`
|
|
local srv; eval srv=\${dns_list_$alt}
|
|
srv="$srv,$servers"
|
|
eval dns_list_$alt=$srv
|
|
|
|
elif [ "$i" = "$defroute" ] || [ -d "$ROUTED/wan$i/default" ]; then
|
|
# DNS servers of a default route (main and alternate default routes)
|
|
defdns_list="$defdns_list $servers"
|
|
|
|
else
|
|
# DNS servers of other interfaces
|
|
dns_list="$dns_list $servers"
|
|
fi
|
|
fi
|
|
}
|