summaryrefslogtreecommitdiff
path: root/package/base-files/files/lib/network
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-05-07 01:17:47 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-05-07 01:17:47 +0000
commitbe41fdd01aba63b91c0a644ed33229c5b1f74037 (patch)
tree869b37bbcd2feafcce3c50ff924cc02b19fe54eb /package/base-files/files/lib/network
parentdcbb5a19e737d52d7f31f8b48a490676ef90a04d (diff)
downloadmtk-20170518-be41fdd01aba63b91c0a644ed33229c5b1f74037.zip
mtk-20170518-be41fdd01aba63b91c0a644ed33229c5b1f74037.tar.gz
mtk-20170518-be41fdd01aba63b91c0a644ed33229c5b1f74037.tar.bz2
base-files: add add_dns() and remove_dns() helpers to network config, useful to merge dns entries from multiple interfaces
SVN-Revision: 21391
Diffstat (limited to 'package/base-files/files/lib/network')
-rwxr-xr-xpackage/base-files/files/lib/network/config.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh
index 4336244..1a77145 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="$*"