X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/00938663e2f7f3ea00aa7fbe53174636d293bf27..38fd142fbb02ebeb12adf32032a49e8d5cd6a17a:/package/base-files/files/lib/network/config.sh?ds=sidebyside diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh index 76ba32497..00e372a1f 100755 --- a/package/base-files/files/lib/network/config.sh +++ b/package/base-files/files/lib/network/config.sh @@ -9,6 +9,23 @@ do_sysctl() { sysctl -n -e "$1" } +map_sysctls() { + local cfg="$1" + local ifn="$2" + + local fam + for fam in ipv4 ipv6; do + if [ -d /proc/sys/net/$fam ]; then + local key + for key in /proc/sys/net/$fam/*/$ifn/*; do + local val + config_get val "$cfg" "${fam}_${key##*/}" + [ -n "$val" ] && echo -n "$val" > "$key" + done + fi + done +} + find_config() { local iftype device iface ifaces ifn for ifn in $interfaces; do @@ -89,15 +106,15 @@ 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 } done [ -n "$cfg" ] && { - uci_set_state network "$cfg" dns "$add" - uci_set_state network "$cfg" resolv_dns "$add" + uci_toggle_state network "$cfg" dns "$add" + uci_toggle_state network "$cfg" resolv_dns "$add" } } @@ -109,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 } @@ -156,6 +173,9 @@ prepare_interface() { ifconfig "$iface" down ifconfig "$iface" hw ether "$vifmac" up } + + # Apply sysctl settings + map_sysctls "$config" "$iface" } # Setup VLAN interfaces @@ -176,7 +196,7 @@ prepare_interface() { for dev in $(sort_list "$devices" "$iface"); do append newdevs "$dev" done - uci_set_state network "$config" device "$newdevs" + uci_toggle_state network "$config" device "$newdevs" $DEBUG ifconfig "$iface" 0.0.0.0 $DEBUG do_sysctl "net.ipv6.conf.$iface.disable_ipv6" 1 $DEBUG brctl addif "br-$config" "$iface" @@ -210,8 +230,8 @@ set_interface_ifname() { local device config_get device "$1" device - uci_set_state network "$config" ifname "$ifname" - uci_set_state network "$config" device "$device" + uci_toggle_state network "$config" ifname "$ifname" + uci_toggle_state network "$config" device "$device" } setup_interface_none() { @@ -237,13 +257,13 @@ setup_interface_static() { case "$ip6addr" in */*) ;; - *:*) ip6addr="$ip6addr/128" ;; + *:*) ip6addr="$ip6addr/64" ;; esac [ -z "$ipaddr" ] || $DEBUG ifconfig "$iface" "$ipaddr" netmask "$netmask" broadcast "${bcast:-+}" - [ -z "$ip6addr" ] || $DEBUG ifconfig "$iface" add "$ip6addr" + [ -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