diff options
Diffstat (limited to 'main/openrc/networking.initd')
-rw-r--r-- | main/openrc/networking.initd | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/main/openrc/networking.initd b/main/openrc/networking.initd index 0d22582ea9..c37be9956d 100644 --- a/main/openrc/networking.initd +++ b/main/openrc/networking.initd @@ -2,27 +2,68 @@ # note that the spoofprotect, syncoockies and ip_forward options are set in # /etc/sysctl.conf + +ifconf=/etc/network/interfaces +ifstate=/var/run/ifstate + +single_iface="${SVCNAME#*.}" +if [ "$single_iface" = "$SVCNAME" ]; then + single_iface= +fi + depend() { after bootmisc hwdrivers modules provide net keyword nojail noprefix novserver } -start() { - ebegin "Configuring network interfaces" - ifup -a >/dev/null 2>&1 - eend $? +# find interfaces we want to start +find_ifaces() { + if [ -n "$single_iface" ]; then + echo $single_iface + else + awk '$1 == "auto" { print $2}' $ifconf + fi } -stop() { - ebegin "Deconfiguring network interfaces" - ifdown -a >/dev/null 2>&1 - eend $? +# return the list of interfaces we should try stop +find_running_ifaces() { + if [ -n "$single_iface" ]; then + echo $single_iface + else + awk -F= '{print $2}' $ifstate + fi } -restart() { - ebegin "Reconfiguring network interfaces" - ifdown -a >/dev/null 2>&1 && ifup -a >/dev/null 2>&1 - eend $? +start() { + local iface= ret=1 + ebegin "Starting networking" + eindent + for iface in $(find_ifaces); do + local r=0 + ebegin "$iface" + if ! ifup $iface >/dev/null; then + ifdown $iface >/dev/null 2>&1 + r=1 + fi + # atleast one interface needs to be started for action + # to be success + eend $r && ret=0 + done + eoutdent + return $ret +} + +stop() { + local iface= + ebegin "Stopping networking" + eindent + for iface in $(find_running_ifaces); do + ebegin "$iface" + ifdown -f $iface >/dev/null + eend $? + done + eoutdent + return 0 } |