X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fstaging%2Fchunkeey.git;a=blobdiff_plain;f=package%2Fnetwork%2Fservices%2Fdnsmasq%2Ffiles%2Fdnsmasq.init;h=9f16d5f5d45f9543cf8dc8c08b11a15337376eff;hp=a0aee8e02b4efa3221c623ea659a2dfd1781111d;hb=132cbe5e29a0f7e4f2b5b80dec42dec974571eac;hpb=f87409440298121ae1fbd718a17267cc180438e4 diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init index a0aee8e02b..9f16d5f5d4 100644 --- a/package/network/services/dnsmasq/files/dnsmasq.init +++ b/package/network/services/dnsmasq/files/dnsmasq.init @@ -13,6 +13,8 @@ ADD_LOCAL_DOMAIN=1 ADD_LOCAL_HOSTNAME=1 CONFIGFILE="/var/etc/dnsmasq.conf" +HOSTFILE="/tmp/hosts/dhcp" +TRUSTANCHORSFILE="/usr/share/dnsmasq/trust-anchors.conf" xappend() { local value="$1" @@ -33,6 +35,29 @@ dhcp_calc() { echo "$res" } +dhcp_check() { + local ifname="$1" + local stamp="/var/run/dnsmasq.$ifname.dhcp" + local rv=0 + + [ -s "$stamp" ] && return $(cat "$stamp") + + udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0 + + [ $rv -eq 1 ] && \ + logger -t dnsmasq \ + "found already running DHCP-server on interface '$ifname'" \ + "refusing to start, use 'option force 1' to override" + + echo $rv > "$stamp" + return $rv +} + +log_once() { + pidof dnsmasq >/dev/null || \ + logger -t dnsmasq "$@" +} + append_bool() { local section="$1" local option="$2" @@ -75,7 +100,7 @@ append_addnhosts() { } append_bogusnxdomain() { - xappend "--bogus-nxdomain=$1" + xappend "--bogus-nxdomain=$1" } dnsmasq() { @@ -135,13 +160,14 @@ dnsmasq() { config_get hostsfile "$cfg" dhcphostsfile [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile" - mkdir -p /tmp/hosts + mkdir -p /tmp/hosts /tmp/dnsmasq.d xappend "--addn-hosts=/tmp/hosts" + xappend "--conf-dir=/tmp/dnsmasq.d" local rebind config_get_bool rebind "$cfg" rebind_protection 1 [ $rebind -gt 0 ] && { - logger -t dnsmasq \ + log_once \ "DNS rebinding protection is active," \ "will discard upstream RFC1918 responses!" xappend "--stop-dns-rebind" @@ -149,20 +175,29 @@ dnsmasq() { 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" + log_once "Allowing 127.0.0.0/8 responses" xappend "--rebind-localhost-ok" } append_rebind_domain() { - logger -t dnsmasq "Allowing RFC1918 responses for domain $1" + log_once "Allowing RFC1918 responses for domain $1" xappend "--rebind-domain-ok=$1" } config_list_foreach "$cfg" rebind_domain append_rebind_domain } + config_get dnssec "$cfg" dnssec + [ "$dnssec" -gt 0 ] && { + xappend "--conf-file=$TRUSTANCHORSFILE" + xappend "--dnssec" + append_bool "$cfg" dnsseccheckunsigned "--dnssec-check-unsigned" + } + dhcp_option_add "$cfg" "" 0 + xappend "--dhcp-broadcast=tag:needs-broadcast" + echo >> $CONFIGFILE } @@ -270,7 +305,15 @@ dhcp_host_add() { config_get tag "$cfg" tag - xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}" + config_get_bool broadcast "$cfg" broadcast 0 + [ "$broadcast" = "0" ] && broadcast= + + xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}" + + config_get_bool dns "$cfg" dns 0 + [ "$dns" = "1" ] && { + echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE + } } dhcp_tag_add() { @@ -333,33 +376,25 @@ dhcp_add() { config_get networkid "$cfg" networkid [ -n "$networkid" ] || networkid="$net" - config_get ifname "$net" ifname - [ -n "$ifname" ] || return 0 + network_get_subnet subnet "$net" || return 0 + network_get_device ifname "$net" || return 0 + network_get_protocol proto "$net" || return 0 - config_get dnsserver "$net" dns - [ "$cachelocal" = "0" -a -n "$dnsserver" ] && { + [ "$cachelocal" = "0" ] && network_get_dnsserver dnsserver "$net" && { DNS_SERVERS="$DNS_SERVERS $dnsserver" } append_bool "$cfg" ignore "--no-dhcp-interface=$ifname" && return 0 - config_get proto "$net" proto + # Do not support non-static interfaces for now [ static = "$proto" ] || return 0 - config_get ipaddr "$net" ipaddr - config_get netmask "$cfg" netmask - [ -n "$netmask" ] || config_get netmask "$net" netmask + # Override interface netmask with dhcp config if applicable + config_get netmask "$cfg" netmask "${subnet##*/}" #check for an already active dhcp server on the interface, unless 'force' is set config_get_bool force "$cfg" force 0 - [ $force -gt 0 ] || { - 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 - } - } + [ $force -gt 0 ] || dhcp_check "$ifname" || return 0 config_get start "$cfg" start config_get limit "$cfg" limit @@ -371,7 +406,7 @@ dhcp_add() { start="$(dhcp_calc "${start:-100}")" limit="${limit:-150}" [ "$limit" -gt 0 ] && limit=$((limit-1)) - eval "$(ipcalc.sh $ipaddr $netmask $start $limit)" + eval "$(ipcalc.sh "${subnet%%/*}" $netmask $start $limit)" if [ "$dynamicdhcp" = "0" ]; then END="static"; fi xappend "--dhcp-range=$networkid,$START,$END,$NETMASK,$leasetime${options:+ $options}" @@ -403,6 +438,9 @@ dhcp_domain_add() { [ -n "$ip" ] || return 0 for name in $names; do + [ "${name%.*}" == "$name" ] && \ + name="$name${DOMAIN:+.$DOMAIN}" + record="${record:+$record/}$name" done @@ -485,23 +523,26 @@ service_triggers() procd_add_reload_trigger "dhcp" } -start_service() { - include /lib/network - scan_interfaces +boot() { + # Will be launched through hotplug + return 0 +} - local lanaddr - config_get lanaddr "lan" ipaddr +start_service() { + include /lib/functions config_load dhcp procd_open_instance procd_set_param command $PROG -C $CONFIGFILE -k + procd_set_param file $CONFIGFILE procd_close_instance # before we can call xappend mkdir -p $(dirname $CONFIGFILE) echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE + echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE # if we did this last, we could override auto-generated config [ -f /etc/dnsmasq.conf ] && { @@ -524,16 +565,22 @@ start_service() { config_foreach dhcp_hostrecord_add hostrecord # add own hostname - [ $ADD_LOCAL_HOSTNAME -eq 1 ] && [ -n "$lanaddr" ] && { + local lanaddr + [ $ADD_LOCAL_HOSTNAME -eq 1 ] && network_get_ipaddr lanaddr "lan" && { local hostname="$(uci_get system @system[0] hostname OpenWrt)" - dhcp_hostrecord_add "" "$hostname${DOMAIN:+.$DOMAIN $hostname}" "$lanaddr" + dhcp_hostrecord_add "" "${hostname%.$DOMAIN}${DOMAIN:+.$DOMAIN ${hostname%.$DOMAIN}}" "$lanaddr" } echo >> $CONFIGFILE config_foreach dhcp_srv_add srvhost config_foreach dhcp_mx_add mxhost echo >> $CONFIGFILE - config_foreach dhcp_add dhcp + + config_get odhcpd_is_active odhcpd maindhcp + if [ "$odhcpd_is_active" != "1" ]; then + config_foreach dhcp_add dhcp + fi + echo >> $CONFIGFILE config_foreach dhcp_cname_add cname echo >> $CONFIGFILE @@ -548,9 +595,15 @@ start_service() { done } +reload_service() { + rc_procd start_service "$@" + return 0 +} + stop_service() { [ -f /tmp/resolv.conf ] && { rm -f /tmp/resolv.conf ln -s /tmp/resolv.conf.auto /tmp/resolv.conf } + rm -f /var/run/dnsmasq.*.dhcp }