From 7f0eb037a2d85cfb4f8befd26b38eaedc0e02908 Mon Sep 17 00:00:00 2001 From: jow Date: Fri, 7 May 2010 01:17:47 +0000 Subject: [package] base-files: add add_dns() and remove_dns() helpers to network config, useful to merge dns entries from multiple interfaces git-svn-id: svn://svn.openwrt.org/openwrt/trunk@21391 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/network/config.sh | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'package/base-files/files/lib') diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh index 4336244f6..1a77145f5 100755 --- a/package/base-files/files/lib/network/config.sh +++ b/package/base-files/files/lib/network/config.sh @@ -66,6 +66,35 @@ add_vlan() { return 1 } +# add dns entries if they are not in resolv.conf yet +add_dns() { + local cfg="$1"; shift + + local dns + local add + for dns in "$@"; do + grep -qsF "nameserver $dns" /tmp/resolv.conf.auto || { + add="${add:+$add }$dns" + echo "nameserver $dns" >> /tmp/resolv.conf.auto + } + done + + uci_set_state network "$cfg" dns "$add" +} + +# remove dns entries of the given iface +remove_dns() { + local cfg="$1" + + local dns + config_get dns "$cfg" dns + for dns in $dns; do + sed -i -e "/^nameserver $dns$/d" /tmp/resolv.conf.auto + done + + uci_revert_state network "$cfg" dns +} + # sort the device list, drop duplicates sort_list() { local arg="$*" -- cgit v1.2.3