Adds 'option search <domainname>' to manually set search domains in resolv.conf

Signed-off-by: John Hansen <j...@geeknet.com.au>

Index: package/base-files/files/lib/network/config.sh
===================================================================
--- package/base-files/files/lib/network/config.sh      (revision 28057)
+++ package/base-files/files/lib/network/config.sh      (working copy)
@@ -118,6 +118,34 @@
        }
 }
 
+add_search() {
+       local cfg="$1"; shift
+
+       remove_search "$cfg"
+
+       # We may be called by pppd's ip-up which has a nonstandard umask set.
+       # Create an empty file here and force its permission to 0644, otherwise
+       # dnsmasq will not be able to re-read the resolv.conf.auto .
+       [ ! -f /tmp/resolv.conf.auto ] && {
+               touch /tmp/resolv.conf.auto
+               chmod 0644 /tmp/resolv.conf.auto
+       }
+
+       local search
+       local add
+       for search in "$@"; do
+               grep -qsF "search $search" /tmp/resolv.conf.auto || {
+                       add="${add:+$add }$search"
+                       echo "search $search" >> /tmp/resolv.conf.auto
+               }
+       done
+
+       [ -n "$cfg" ] && {
+               uci_toggle_state network "$cfg" dns "$add"
+               uci_toggle_state network "$cfg" resolv_dns "$add"
+       }
+}
+
 # remove dns entries of the given iface
 remove_dns() {
        local cfg="$1"
@@ -135,6 +163,22 @@
        }
 }
 
+remove_search() {
+       local cfg="$1"
+
+       [ -n "$cfg" ] && {
+               [ -f /tmp/resolv.conf.auto ] && {
+                       local search=$(uci_get_state network "$cfg" resolv_dns)
+                       for search in $search; do
+                               sed -i -e "/^search $search$/d" 
/tmp/resolv.conf.auto
+                       done
+               }
+
+               uci_revert_state network "$cfg" dns
+               uci_revert_state network "$cfg" resolv_dns
+       }
+}
+
 # sort the device list, drop duplicates
 sort_list() {
        local arg="$*"
@@ -248,10 +292,11 @@
        config_get ip6addr "$config" ip6addr
        [ -z "$ipaddr" -o -z "$netmask" ] && [ -z "$ip6addr" ] && return 1
 
-       local gateway ip6gw dns bcast metric
+       local gateway ip6gw dns bcast metric search
        config_get gateway "$config" gateway
        config_get ip6gw "$config" ip6gw
        config_get dns "$config" dns
+       config_get search "$config" search
        config_get bcast "$config" broadcast
        config_get metric "$config" metric
 
@@ -265,6 +310,7 @@
        [ -z "$gateway" ] || $DEBUG route add default gw "$gateway" 
${metric:+metric $metric} dev "$iface"
        [ -z "$ip6gw" ] || $DEBUG route -A inet6 add default gw "$ip6gw" 
${metric:+metric $metric} dev "$iface"
        [ -z "$dns" ] || add_dns "$config" $dns
+       [ -z "$search" ] || add_search "$config" $search
 
        config_get type "$config" TYPE
        [ "$type" = "alias" ] && return 0

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to