2006-10-04 23:05:48 +03:00
|
|
|
#!/bin/sh /etc/rc.common
|
2012-07-01 14:32:46 +03:00
|
|
|
# Copyright (C) 2007-2012 OpenWrt.org
|
2006-10-04 23:05:48 +03:00
|
|
|
|
2006-11-13 23:16:03 +02:00
|
|
|
START=60
|
2011-11-08 00:58:45 +02:00
|
|
|
|
|
|
|
SERVICE_USE_PID=1
|
|
|
|
|
2007-09-10 23:24:18 +03:00
|
|
|
DNS_SERVERS=""
|
2009-10-05 19:58:06 +03:00
|
|
|
DOMAIN=""
|
2007-03-17 15:31:13 +02:00
|
|
|
|
2012-07-01 14:32:46 +03:00
|
|
|
ADD_LOCAL_DOMAIN=1
|
|
|
|
ADD_LOCAL_HOSTNAME=1
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
CONFIGFILE="/var/etc/dnsmasq.conf"
|
|
|
|
|
|
|
|
xappend() {
|
|
|
|
local value="$1"
|
|
|
|
|
|
|
|
echo "${value#--}" >> $CONFIGFILE
|
|
|
|
}
|
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
dhcp_calc() {
|
|
|
|
local ip="$1"
|
|
|
|
local res=0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
while [ -n "$ip" ]; do
|
|
|
|
part="${ip%%.*}"
|
|
|
|
res="$(($res * 256))"
|
|
|
|
res="$(($res + $part))"
|
|
|
|
[ "${ip%.*}" != "$ip" ] && ip="${ip#*.}" || ip=
|
|
|
|
done
|
|
|
|
echo "$res"
|
|
|
|
}
|
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
append_bool() {
|
|
|
|
local section="$1"
|
|
|
|
local option="$2"
|
|
|
|
local value="$3"
|
2007-09-26 02:16:31 +03:00
|
|
|
local _loctmp
|
2010-07-17 16:36:13 +03:00
|
|
|
config_get_bool _loctmp "$section" "$option" 0
|
2012-04-03 01:31:21 +03:00
|
|
|
[ $_loctmp -gt 0 ] && xappend "$value"
|
2007-09-26 02:16:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
append_parm() {
|
|
|
|
local section="$1"
|
|
|
|
local option="$2"
|
|
|
|
local switch="$3"
|
|
|
|
local _loctmp
|
|
|
|
config_get _loctmp "$section" "$option"
|
|
|
|
[ -z "$_loctmp" ] && return 0
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "$switch=$_loctmp"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
2009-01-28 00:58:11 +02:00
|
|
|
append_server() {
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--server=$1"
|
2009-01-28 00:58:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-05 12:33:56 +03:00
|
|
|
append_interface() {
|
2010-08-04 20:09:31 +03:00
|
|
|
local ifname=$(uci_get_state network "$1" ifname "$1")
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--interface=$ifname"
|
2009-05-05 12:33:56 +03:00
|
|
|
}
|
|
|
|
|
2009-09-16 21:15:31 +03:00
|
|
|
append_notinterface() {
|
2010-08-04 20:09:31 +03:00
|
|
|
local ifname=$(uci_get_state network "$1" ifname "$1")
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--except-interface=$ifname"
|
2009-09-16 21:15:31 +03:00
|
|
|
}
|
|
|
|
|
2009-11-22 13:52:08 +02:00
|
|
|
append_addnhosts() {
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--addn-hosts=$1"
|
2009-11-22 13:52:08 +02:00
|
|
|
}
|
|
|
|
|
2010-08-11 13:37:33 +03:00
|
|
|
append_bogusnxdomain() {
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--bogus-nxdomain=$1"
|
2010-08-11 13:37:33 +03:00
|
|
|
}
|
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
dnsmasq() {
|
|
|
|
local cfg="$1"
|
2012-04-03 01:31:21 +03:00
|
|
|
append_bool "$cfg" authoritative "--dhcp-authoritative"
|
|
|
|
append_bool "$cfg" nodaemon "--no-daemon"
|
|
|
|
append_bool "$cfg" domainneeded "--domain-needed"
|
|
|
|
append_bool "$cfg" filterwin2k "--filterwin2k"
|
|
|
|
append_bool "$cfg" nohosts "--no-hosts"
|
|
|
|
append_bool "$cfg" nonegcache "--no-negcache"
|
|
|
|
append_bool "$cfg" strictorder "--strict-order"
|
|
|
|
append_bool "$cfg" logqueries "--log-queries"
|
|
|
|
append_bool "$cfg" noresolv "--no-resolv"
|
|
|
|
append_bool "$cfg" localise_queries "--localise-queries"
|
|
|
|
append_bool "$cfg" readethers "--read-ethers"
|
|
|
|
append_bool "$cfg" dbus "--enable-dbus"
|
|
|
|
append_bool "$cfg" boguspriv "--bogus-priv"
|
|
|
|
append_bool "$cfg" expandhosts "--expand-hosts"
|
2008-10-13 10:39:56 +03:00
|
|
|
append_bool "$cfg" enable_tftp "--enable-tftp"
|
2012-04-03 01:31:21 +03:00
|
|
|
append_bool "$cfg" nonwildcard "--bind-interfaces"
|
2012-07-01 14:32:45 +03:00
|
|
|
append_bool "$cfg" fqdn "--dhcp-fqdn"
|
2012-04-03 01:31:21 +03:00
|
|
|
|
|
|
|
append_parm "$cfg" dhcpscript "--dhcp-script"
|
|
|
|
append_parm "$cfg" cachesize "--cache-size"
|
|
|
|
append_parm "$cfg" dnsforwardmax "--dns-forward-max"
|
|
|
|
append_parm "$cfg" port "--port"
|
|
|
|
append_parm "$cfg" ednspacket_max "--edns-packet-max"
|
|
|
|
append_parm "$cfg" dhcpleasemax "--dhcp-lease-max"
|
|
|
|
append_parm "$cfg" "queryport" "--query-port"
|
|
|
|
append_parm "$cfg" "domain" "--domain"
|
|
|
|
append_parm "$cfg" "local" "--server"
|
2009-01-28 00:58:11 +02:00
|
|
|
config_list_foreach "$cfg" "server" append_server
|
2009-05-05 12:33:56 +03:00
|
|
|
config_list_foreach "$cfg" "interface" append_interface
|
2009-09-16 21:15:31 +03:00
|
|
|
config_list_foreach "$cfg" "notinterface" append_notinterface
|
2009-11-22 13:52:08 +02:00
|
|
|
config_list_foreach "$cfg" "addnhosts" append_addnhosts
|
2010-08-11 13:37:33 +03:00
|
|
|
config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
|
2012-04-03 01:31:21 +03:00
|
|
|
append_parm "$cfg" "leasefile" "--dhcp-leasefile"
|
|
|
|
append_parm "$cfg" "resolvfile" "--resolv-file"
|
2008-10-13 10:39:56 +03:00
|
|
|
append_parm "$cfg" "tftp_root" "--tftp-root"
|
|
|
|
append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
|
2008-02-14 23:17:14 +02:00
|
|
|
|
2009-10-05 19:58:06 +03:00
|
|
|
config_get DOMAIN "$cfg" domain
|
|
|
|
|
2012-07-01 14:32:46 +03:00
|
|
|
config_get_bool ADD_LOCAL_DOMAIN "$cfg" add_local_domain 1
|
|
|
|
config_get_bool ADD_LOCAL_HOSTNAME "$cfg" add_local_hostname 1
|
|
|
|
|
2010-03-14 23:33:02 +02:00
|
|
|
config_get_bool readethers "$cfg" readethers
|
2011-02-14 21:42:53 +02:00
|
|
|
[ "$readethers" = "1" -a \! -e "/etc/ethers" ] && touch /etc/ethers
|
2010-03-14 23:33:02 +02:00
|
|
|
|
2008-02-14 23:17:14 +02:00
|
|
|
config_get leasefile $cfg leasefile
|
2011-02-14 21:42:53 +02:00
|
|
|
[ -n "$leasefile" -a \! -e "$leasefile" ] && touch "$leasefile"
|
2008-09-02 04:37:06 +03:00
|
|
|
config_get_bool cachelocal "$cfg" cachelocal 1
|
2009-05-10 01:34:04 +03:00
|
|
|
|
|
|
|
config_get hostsfile "$cfg" dhcphostsfile
|
2012-04-03 01:31:21 +03:00
|
|
|
[ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile"
|
2010-07-16 03:06:59 +03:00
|
|
|
|
|
|
|
local rebind
|
|
|
|
config_get_bool rebind "$cfg" rebind_protection 1
|
|
|
|
[ $rebind -gt 0 ] && {
|
|
|
|
logger -t dnsmasq \
|
|
|
|
"DNS rebinding protection is active," \
|
|
|
|
"will discard upstream RFC1918 responses!"
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--stop-dns-rebind"
|
2010-07-16 03:06:59 +03:00
|
|
|
|
|
|
|
local rebind_localhost
|
|
|
|
config_get_bool rebind_localhost "$cfg" rebind_localhost 0
|
|
|
|
[ $rebind_localhost -gt 0 ] && {
|
|
|
|
logger -t dnsmasq "Allowing 127.0.0.0/8 responses"
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--rebind-localhost-ok"
|
2010-07-16 03:06:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
append_rebind_domain() {
|
|
|
|
logger -t dnsmasq "Allowing RFC1918 responses for domain $1"
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--rebind-domain-ok=$1"
|
2010-07-16 03:06:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
config_list_foreach "$cfg" rebind_domain append_rebind_domain
|
|
|
|
}
|
2012-04-03 01:31:21 +03:00
|
|
|
|
2012-07-01 14:32:29 +03:00
|
|
|
dhcp_option_add "$cfg" "" 0
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
echo >> $CONFIGFILE
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_subscrid_add() {
|
|
|
|
local cfg="$1"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
config_get subscriberid "$cfg" subscriberid
|
|
|
|
[ -n "$subscriberid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-subscrid=$networkid,$subscriberid"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
|
|
|
dhcp_option_add "$cfg" "$networkid" "$force"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_remoteid_add() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
config_get remoteid "$cfg" remoteid
|
|
|
|
[ -n "$remoteid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-remoteid=$networkid,$remoteid"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
|
|
|
dhcp_option_add "$cfg" "$networkid" "$force"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_circuitid_add() {
|
|
|
|
local cfg="$1"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
config_get circuitid "$cfg" circuitid
|
|
|
|
[ -n "$circuitid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-circuitid=$networkid,$circuitid"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
|
|
|
dhcp_option_add "$cfg" "$networkid" "$force"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_userclass_add() {
|
|
|
|
local cfg="$1"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
config_get userclass "$cfg" userclass
|
|
|
|
[ -n "$userclass" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-userclass=$networkid,$userclass"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
|
|
|
dhcp_option_add "$cfg" "$networkid" "$force"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_vendorclass_add() {
|
|
|
|
local cfg="$1"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
config_get vendorclass "$cfg" vendorclass
|
|
|
|
[ -n "$vendorclass" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-vendorclass=$networkid,$vendorclass"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
|
|
|
dhcp_option_add "$cfg" "$networkid" "$force"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_host_add() {
|
|
|
|
local cfg="$1"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
2012-05-19 23:17:56 +03:00
|
|
|
[ -n "$networkid" ] && dhcp_option_add "$cfg" "$networkid" "$force"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2011-05-24 12:12:50 +03:00
|
|
|
config_get name "$cfg" name
|
2007-11-05 16:14:06 +02:00
|
|
|
config_get ip "$cfg" ip
|
dnsmasq: add support for set: and tag: pairs
On my network, I have a variety of machines and appliances, some of which need different configuration issues than the default options.
For example:
config host
option name 'client'
option mac '00:01:02:03:04:05'
option ip '192.168.1.20'
option tag 'acme'
config tag acme
option force '1'
list dhcp_option 'option:router,192.168.1.253'
list dhcp_option 'option:domain-name,acme.com'
list dhcp_option 'option:domain-search,acme.com,redfish-solutions.com'
which allows me to override the default router for my client's host, as well as its domain-name, and its domain-search.
this causes the following config lines:
dhcp-host=00:01:02:03:04:05,set:acme,192.168.1.20,client
dhcp-option-force=tag:acme,option:router,192.168.1.253
dhcp-option-force=tag:acme,option:domain-name,acme.com
dhcp-option-force=tag:acme,option:domain-search:acme.com,redfish-solutions.com
This could be useful elsewhere, for instance, if you have an IP CCTV that you don't want to have a default-route, etc.
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@31815 3c298f89-4303-0410-b956-a3cf2f4a3e73
2012-05-19 23:17:54 +03:00
|
|
|
[ -n "$ip" -o -n "$name" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-03-09 01:28:55 +02:00
|
|
|
macs=""
|
|
|
|
config_get mac "$cfg" mac
|
|
|
|
for m in $mac; do append macs "$m" ","; done
|
|
|
|
[ -n "$macs" ] || return 0
|
|
|
|
|
dnsmasq: add support for set: and tag: pairs
On my network, I have a variety of machines and appliances, some of which need different configuration issues than the default options.
For example:
config host
option name 'client'
option mac '00:01:02:03:04:05'
option ip '192.168.1.20'
option tag 'acme'
config tag acme
option force '1'
list dhcp_option 'option:router,192.168.1.253'
list dhcp_option 'option:domain-name,acme.com'
list dhcp_option 'option:domain-search,acme.com,redfish-solutions.com'
which allows me to override the default router for my client's host, as well as its domain-name, and its domain-search.
this causes the following config lines:
dhcp-host=00:01:02:03:04:05,set:acme,192.168.1.20,client
dhcp-option-force=tag:acme,option:router,192.168.1.253
dhcp-option-force=tag:acme,option:domain-name,acme.com
dhcp-option-force=tag:acme,option:domain-search:acme.com,redfish-solutions.com
This could be useful elsewhere, for instance, if you have an IP CCTV that you don't want to have a default-route, etc.
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@31815 3c298f89-4303-0410-b956-a3cf2f4a3e73
2012-05-19 23:17:54 +03:00
|
|
|
config_get tag "$cfg" tag
|
|
|
|
|
|
|
|
xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_tag_add() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
|
|
|
tag="$cfg"
|
|
|
|
|
|
|
|
[ -n "$tag" ] || return 0
|
|
|
|
|
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
[ "$force" = "0" ] && force=
|
|
|
|
|
|
|
|
config_get option "$cfg" dhcp_option
|
|
|
|
for o in $option; do
|
|
|
|
xappend "--dhcp-option${force:+-force}=tag:$tag,$o"
|
|
|
|
done
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dhcp_mac_add() {
|
2007-03-17 15:31:13 +02:00
|
|
|
local cfg="$1"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
config_get mac "$cfg" mac
|
|
|
|
[ -n "$mac" ] || return 0
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-mac=$networkid,$mac"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
dhcp_option_add "$cfg" "$networkid"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
2007-03-17 15:31:13 +02:00
|
|
|
|
2008-07-05 16:43:55 +03:00
|
|
|
dhcp_boot_add() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
2008-07-05 16:43:55 +03:00
|
|
|
|
|
|
|
config_get filename "$cfg" filename
|
|
|
|
[ -n "$filename" ] || return 0
|
|
|
|
|
|
|
|
config_get servername "$cfg" servername
|
|
|
|
[ -n "$servername" ] || return 0
|
|
|
|
|
|
|
|
config_get serveraddress "$cfg" serveraddress
|
|
|
|
[ -n "$serveraddress" ] || return 0
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-boot=${networkid:+net:$networkid,}$filename,$servername,$serveraddress"
|
2008-07-05 16:43:55 +03:00
|
|
|
|
2012-05-19 23:17:56 +03:00
|
|
|
config_get_bool force "$cfg" force 0
|
|
|
|
|
|
|
|
dhcp_option_add "$cfg" "$networkid" "$force"
|
2008-07-05 16:43:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
dhcp_add() {
|
|
|
|
local cfg="$1"
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get net "$cfg" interface
|
|
|
|
[ -n "$net" ] || return 0
|
2007-08-29 21:40:52 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
config_get networkid "$cfg" networkid
|
|
|
|
[ -n "$networkid" ] || networkid="$net"
|
2007-08-29 21:40:52 +03:00
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get ifname "$net" ifname
|
|
|
|
[ -n "$ifname" ] || return 0
|
2007-08-29 21:40:52 +03:00
|
|
|
|
2007-09-10 23:24:18 +03:00
|
|
|
config_get dnsserver "$net" dns
|
2008-09-02 04:37:06 +03:00
|
|
|
[ "$cachelocal" = "0" -a -n "$dnsserver" ] && {
|
2007-09-10 23:24:18 +03:00
|
|
|
DNS_SERVERS="$DNS_SERVERS $dnsserver"
|
|
|
|
}
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
append_bool "$cfg" ignore "--no-dhcp-interface=$ifname" && return 0
|
2007-08-29 21:40:52 +03:00
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get proto "$net" proto
|
|
|
|
[ static = "$proto" ] || return 0
|
2007-08-29 21:40:52 +03:00
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get ipaddr "$net" ipaddr
|
2008-01-17 03:15:50 +02:00
|
|
|
config_get netmask "$cfg" netmask
|
|
|
|
[ -n "$netmask" ] || config_get netmask "$net" netmask
|
2007-03-17 15:31:13 +02:00
|
|
|
|
2007-08-29 21:40:52 +03:00
|
|
|
#check for an already active dhcp server on the interface, unless 'force' is set
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get_bool force "$cfg" force 0
|
2010-07-17 16:36:13 +03:00
|
|
|
[ $force -gt 0 ] || {
|
2010-11-21 15:53:27 +02:00
|
|
|
udhcpc -n -q -s /bin/true -t 1 -i $ifname >&- && {
|
|
|
|
logger -t dnsmasq \
|
|
|
|
"found already running DHCP-server on interface '$ifname'" \
|
|
|
|
"refusing to start, use 'option force 1' to override"
|
|
|
|
return 0
|
|
|
|
}
|
2007-03-17 15:31:13 +02:00
|
|
|
}
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get start "$cfg" start
|
2007-08-19 23:50:52 +03:00
|
|
|
config_get limit "$cfg" limit
|
2007-03-17 15:31:13 +02:00
|
|
|
config_get leasetime "$cfg" leasetime
|
2007-03-31 03:39:55 +03:00
|
|
|
config_get options "$cfg" options
|
2007-11-28 05:02:20 +02:00
|
|
|
config_get_bool dynamicdhcp "$cfg" dynamicdhcp 1
|
2007-03-17 15:31:13 +02:00
|
|
|
|
|
|
|
leasetime="${leasetime:-12h}"
|
|
|
|
start="$(dhcp_calc "${start:-100}")"
|
2010-03-18 17:50:05 +02:00
|
|
|
limit="${limit:-150}"
|
2011-01-26 13:33:33 +02:00
|
|
|
[ "$limit" -gt 0 ] && limit=$((limit-1))
|
2007-09-09 19:05:14 +03:00
|
|
|
eval "$(ipcalc.sh $ipaddr $netmask $start $limit)"
|
2007-11-28 05:02:20 +02:00
|
|
|
if [ "$dynamicdhcp" = "0" ]; then END="static"; fi
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--dhcp-range=$networkid,$START,$END,$NETMASK,$leasetime${options:+ $options}"
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2010-01-08 02:03:08 +02:00
|
|
|
dhcp_option_add "$cfg" "$networkid"
|
2007-08-29 21:40:52 +03:00
|
|
|
}
|
|
|
|
|
2007-09-26 02:16:31 +03:00
|
|
|
dhcp_option_add() {
|
2007-08-29 21:40:52 +03:00
|
|
|
local cfg="$1"
|
2010-01-08 02:03:08 +02:00
|
|
|
local networkid="$2"
|
2012-05-19 23:17:56 +03:00
|
|
|
local force="$3"
|
|
|
|
|
|
|
|
[ "$force" = "0" ] && force=
|
2007-09-26 02:16:31 +03:00
|
|
|
|
2008-09-07 23:07:55 +03:00
|
|
|
config_get dhcp_option "$cfg" dhcp_option
|
|
|
|
for o in $dhcp_option; do
|
2012-07-01 14:32:29 +03:00
|
|
|
xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$o"
|
2007-08-29 21:40:52 +03:00
|
|
|
done
|
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
}
|
|
|
|
|
2009-10-05 19:58:06 +03:00
|
|
|
dhcp_domain_add() {
|
|
|
|
local cfg="$1"
|
2010-04-03 01:56:22 +03:00
|
|
|
local ip name names
|
2009-10-05 19:58:06 +03:00
|
|
|
|
2011-12-01 23:34:45 +02:00
|
|
|
config_get names "$cfg" name "$2"
|
2010-04-03 01:56:22 +03:00
|
|
|
[ -n "$names" ] || return 0
|
2009-10-05 19:58:06 +03:00
|
|
|
|
2011-12-01 23:34:45 +02:00
|
|
|
config_get ip "$cfg" ip "$3"
|
2009-10-05 19:58:06 +03:00
|
|
|
[ -n "$ip" ] || return 0
|
|
|
|
|
|
|
|
local oIFS="$IFS"; IFS="."; set -- $ip; IFS="$oIFS"
|
2010-04-03 01:56:22 +03:00
|
|
|
local raddr="${4:+$4.$3.$2.$1.in-addr.arpa}"
|
|
|
|
|
|
|
|
for name in $names; do
|
2010-04-23 16:40:50 +03:00
|
|
|
local fqdn="$name"
|
|
|
|
|
|
|
|
[ "${fqdn%.*}" == "$fqdn" ] && \
|
|
|
|
fqdn="$fqdn${DOMAIN:+.$DOMAIN}"
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--address=/$fqdn/$ip"
|
2011-12-01 23:34:45 +02:00
|
|
|
|
2010-04-23 16:40:50 +03:00
|
|
|
[ -n "$raddr" ] && {
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--ptr-record=$raddr,$fqdn"
|
2010-04-23 16:40:50 +03:00
|
|
|
raddr=""
|
|
|
|
}
|
2010-04-03 01:56:22 +03:00
|
|
|
done
|
2009-10-05 19:58:06 +03:00
|
|
|
}
|
|
|
|
|
2010-05-08 15:35:29 +03:00
|
|
|
dhcp_srv_add() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
|
|
|
config_get srv "$cfg" srv
|
|
|
|
[ -n "$srv" ] || return 0
|
|
|
|
|
|
|
|
config_get target "$cfg" target
|
|
|
|
[ -n "$target" ] || return 0
|
|
|
|
|
|
|
|
config_get port "$cfg" port
|
2012-03-23 13:19:56 +02:00
|
|
|
[ -n "$port" ] || return 0
|
2010-05-08 15:35:29 +03:00
|
|
|
|
2012-03-23 13:19:56 +02:00
|
|
|
config_get class "$cfg" class
|
|
|
|
config_get weight "$cfg" weight
|
|
|
|
|
|
|
|
local service="$srv,$target,$port${class:+,$class${weight:+,$weight}}"
|
2010-05-08 15:35:29 +03:00
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--srv-host=$service"
|
2010-05-08 15:35:29 +03:00
|
|
|
}
|
|
|
|
|
2012-03-23 13:19:58 +02:00
|
|
|
dhcp_mx_add() {
|
|
|
|
local cfg="$1"
|
2012-03-23 13:26:47 +02:00
|
|
|
local domain relay pref
|
2012-03-23 13:19:58 +02:00
|
|
|
|
2012-03-23 13:26:47 +02:00
|
|
|
config_get domain "$cfg" domain
|
2012-03-23 13:19:58 +02:00
|
|
|
[ -n "$domain" ] || return 0
|
|
|
|
|
|
|
|
config_get relay "$cfg" relay
|
|
|
|
[ -n "$relay" ] || return 0
|
|
|
|
|
|
|
|
config_get pref "$cfg" pref 0
|
|
|
|
|
|
|
|
local service="$domain,$relay,$pref"
|
|
|
|
|
2012-05-19 23:17:19 +03:00
|
|
|
xappend "--mx-host=$service"
|
2012-03-23 13:19:58 +02:00
|
|
|
}
|
|
|
|
|
2011-10-20 15:12:26 +03:00
|
|
|
dhcp_cname_add() {
|
|
|
|
local cfg="$1"
|
|
|
|
local cname target
|
|
|
|
|
|
|
|
config_get cname "$cfg" cname
|
|
|
|
[ -n "$cname" ] || return 0
|
|
|
|
|
|
|
|
config_get target "$cfg" target
|
|
|
|
[ -n "$target" ] || return 0
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
xappend "--cname=${cname},${target}"
|
2011-10-20 15:12:26 +03:00
|
|
|
}
|
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
start() {
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
2011-12-01 23:34:45 +02:00
|
|
|
|
|
|
|
local lanaddr
|
|
|
|
config_get lanaddr "lan" ipaddr
|
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
config_load dhcp
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
# before we can call xappend
|
|
|
|
mkdir -p $(dirname $CONFIGFILE)
|
|
|
|
|
|
|
|
echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE
|
|
|
|
|
|
|
|
# if we did this last, we could override auto-generated config
|
|
|
|
[ -f /etc/dnsmasq.conf ] && {
|
|
|
|
xappend "--conf-file=/etc/dnsmasq.conf"
|
|
|
|
}
|
|
|
|
|
2007-03-17 15:31:13 +02:00
|
|
|
args=""
|
2007-08-29 21:40:52 +03:00
|
|
|
config_foreach dnsmasq dnsmasq
|
|
|
|
config_foreach dhcp_host_add host
|
2012-04-03 01:31:21 +03:00
|
|
|
echo >> $CONFIGFILE
|
2008-07-05 16:43:55 +03:00
|
|
|
config_foreach dhcp_boot_add boot
|
2007-08-29 21:40:52 +03:00
|
|
|
config_foreach dhcp_mac_add mac
|
dnsmasq: add support for set: and tag: pairs
On my network, I have a variety of machines and appliances, some of which need different configuration issues than the default options.
For example:
config host
option name 'client'
option mac '00:01:02:03:04:05'
option ip '192.168.1.20'
option tag 'acme'
config tag acme
option force '1'
list dhcp_option 'option:router,192.168.1.253'
list dhcp_option 'option:domain-name,acme.com'
list dhcp_option 'option:domain-search,acme.com,redfish-solutions.com'
which allows me to override the default router for my client's host, as well as its domain-name, and its domain-search.
this causes the following config lines:
dhcp-host=00:01:02:03:04:05,set:acme,192.168.1.20,client
dhcp-option-force=tag:acme,option:router,192.168.1.253
dhcp-option-force=tag:acme,option:domain-name,acme.com
dhcp-option-force=tag:acme,option:domain-search:acme.com,redfish-solutions.com
This could be useful elsewhere, for instance, if you have an IP CCTV that you don't want to have a default-route, etc.
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@31815 3c298f89-4303-0410-b956-a3cf2f4a3e73
2012-05-19 23:17:54 +03:00
|
|
|
config_foreach dhcp_tag_add tag
|
2007-08-29 21:40:52 +03:00
|
|
|
config_foreach dhcp_vendorclass_add vendorclass
|
|
|
|
config_foreach dhcp_userclass_add userclass
|
|
|
|
config_foreach dhcp_circuitid_add circuitid
|
|
|
|
config_foreach dhcp_remoteid_add remoteid
|
|
|
|
config_foreach dhcp_subscrid_add subscrid
|
2009-10-05 19:58:06 +03:00
|
|
|
config_foreach dhcp_domain_add domain
|
2012-04-03 01:31:21 +03:00
|
|
|
echo >> $CONFIGFILE
|
2010-05-08 15:35:29 +03:00
|
|
|
config_foreach dhcp_srv_add srvhost
|
2012-03-23 13:19:58 +02:00
|
|
|
config_foreach dhcp_mx_add mxhost
|
2012-04-03 01:31:21 +03:00
|
|
|
echo >> $CONFIGFILE
|
2007-03-17 15:31:13 +02:00
|
|
|
config_foreach dhcp_add dhcp
|
2012-04-03 01:31:21 +03:00
|
|
|
echo >> $CONFIGFILE
|
2011-10-20 15:12:26 +03:00
|
|
|
config_foreach dhcp_cname_add cname
|
2012-04-03 01:31:21 +03:00
|
|
|
echo >> $CONFIGFILE
|
2007-08-29 21:40:52 +03:00
|
|
|
|
2011-12-01 23:34:45 +02:00
|
|
|
# add own hostname
|
2012-07-01 14:32:46 +03:00
|
|
|
[ $ADD_LOCAL_HOSTNAME -eq 1 ] && [ -n "$lanaddr" ] && {
|
2011-12-01 23:34:45 +02:00
|
|
|
local hostname="$(uci_get system.@system[0].hostname)"
|
|
|
|
dhcp_domain_add "" "${hostname:-OpenWrt}" "$lanaddr"
|
|
|
|
}
|
|
|
|
|
2012-04-03 01:31:21 +03:00
|
|
|
service_start /usr/sbin/dnsmasq -C $CONFIGFILE && {
|
2007-01-08 23:33:53 +02:00
|
|
|
rm -f /tmp/resolv.conf
|
2012-07-01 14:32:46 +03:00
|
|
|
[ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
|
|
|
|
echo "search $DOMAIN" >> /tmp/resolv.conf
|
|
|
|
}
|
2007-09-10 23:24:18 +03:00
|
|
|
DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
|
|
|
|
for DNS_SERVER in $DNS_SERVERS ; do
|
|
|
|
echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
|
2007-09-26 02:16:31 +03:00
|
|
|
done
|
2007-01-08 23:33:53 +02:00
|
|
|
}
|
2006-10-04 23:05:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2011-11-08 00:58:45 +02:00
|
|
|
service_stop /usr/sbin/dnsmasq && {
|
|
|
|
[ -f /tmp/resolv.conf ] && {
|
|
|
|
rm -f /tmp/resolv.conf
|
|
|
|
ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
|
|
|
|
}
|
2008-09-07 18:22:25 +03:00
|
|
|
}
|
2006-10-04 23:05:48 +03:00
|
|
|
}
|