X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/564ea3531fda823c933161fd0dc18c7b4d26bf99..4df90b50819f595145d956e7e148aeff3342d14c:/package/base-files/default/lib/network/config.sh diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 18f794a31..502377b60 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -27,6 +27,11 @@ scan_interfaces() { local mode iftype iface ifname device interfaces= config_cb() { + case "$1" in + interface) + config_set "$2" auto 1 + ;; + esac config_get iftype "$CONFIG_SECTION" TYPE case "$iftype" in interface) @@ -70,6 +75,11 @@ setup_interface() { proto="${3:-$(config_get "$config" proto)}" config_get iftype "$config" type + ifconfig "$iface" 2>/dev/null >/dev/null && { + # make sure the interface is removed from any existing bridge + unbridge "$iface" + } + # Setup VLAN interfaces add_vlan "$iface" @@ -115,8 +125,13 @@ setup_interface() { env -i ACTION="ifup" INTERFACE="config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" & ;; dhcp) + # prevent udhcpc from starting more than once + lock "/var/lock/dhcp-$iface" pid="$(cat "$pidfile" 2>/dev/null)" - [ -n "$pid" -a -d "/proc/$pid" ] && kill -9 "$pid" + [ -d "/proc/$pid" ] && grep udhcpc "/proc/${pid}/cmdline" >/dev/null 2>/dev/null && { + lock -u "/var/lock/dhcp-$iface" + return 0 + } config_get ipaddr "$config" ipaddr config_get netmask "$config" netmask @@ -129,6 +144,7 @@ setup_interface() { # don't stay running in background if dhcp is not the main proto on the interface (e.g. when using pptp) [ "$proto1" != "$proto" ] && dhcpopts="-n -q" $DEBUG udhcpc -i "$iface" ${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} -b -p "$pidfile" ${dhcpopts:- -R &} + lock -u "/var/lock/dhcp-$iface" ;; *) if ( eval "type setup_interface_$proto" ) >/dev/null 2>/dev/null; then @@ -141,3 +157,15 @@ setup_interface() { esac } +unbridge() { + local dev="$1" + local brdev + + brctl show | grep "$dev" >/dev/null && { + # interface is still part of a bridge, correct that + + for brdev in $(brctl show | awk '$2 ~ /^[0-9].*\./ { print $1 }'); do + brctl delif "$brdev" "$dev" 2>/dev/null >/dev/null + done + } +}