[package] base-files: make ip matching in dns add/remove functions more explicit...
[openwrt.git] / package / base-files / files / lib / network / config.sh
index 5975f17..00e372a 100755 (executable)
@@ -106,7 +106,7 @@ add_dns() {
        local dns
        local add
        for dns in "$@"; do
-               grep -qsF "nameserver $dns" /tmp/resolv.conf.auto || {
+               grep -qsE "^nameserver ${dns//./\\.}$" /tmp/resolv.conf.auto || {
                        add="${add:+$add }$dns"
                        echo "nameserver $dns" >> /tmp/resolv.conf.auto
                }
@@ -126,7 +126,7 @@ remove_dns() {
                [ -f /tmp/resolv.conf.auto ] && {
                        local dns=$(uci_get_state network "$cfg" resolv_dns)
                        for dns in $dns; do
-                               sed -i -e "/^nameserver $dns$/d" /tmp/resolv.conf.auto
+                               sed -i -e "/^nameserver ${dns//./\\.}$/d" /tmp/resolv.conf.auto
                        done
                }
 
@@ -242,10 +242,10 @@ setup_interface_static() {
        local iface="$1"
        local config="$2"
 
-       local ipaddr netmask ip6addrs ipaddr
+       local ipaddr netmask ip6addr
        config_get ipaddr "$config" ipaddr
        config_get netmask "$config" netmask
-       config_get ip6addrs "$config" ip6addr
+       config_get ip6addr "$config" ip6addr
        [ -z "$ipaddr" -o -z "$netmask" ] && [ -z "$ip6addr" ] && return 1
 
        local gateway ip6gw dns bcast metric
@@ -255,16 +255,15 @@ setup_interface_static() {
        config_get bcast "$config" broadcast
        config_get metric "$config" metric
 
+       case "$ip6addr" in
+               */*) ;;
+               *:*) ip6addr="$ip6addr/64" ;;
+       esac
+
        [ -z "$ipaddr" ] || $DEBUG ifconfig "$iface" "$ipaddr" netmask "$netmask" broadcast "${bcast:-+}"
-       for ip6addr in $ip6addrs; do          
-               case "$ip6addr" in
-                       */*) ;;
-                       *:*) ip6addr="$ip6addr/64" ;;
-               esac
-               $DEBUG ifconfig "$iface" add "$ip6addr"
-       done 
+       [ -z "$ip6addr" ] || $DEBUG ifconfig "${iface%:*}" add "$ip6addr"
        [ -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 "$ip6gw" ] || $DEBUG route -A inet6 add default gw "$ip6gw" ${metric:+metric $metric} dev "${iface%:*}"
        [ -z "$dns" ] || add_dns "$config" $dns
 
        config_get type "$config" TYPE
This page took 0.027057 seconds and 4 git commands to generate.