networking.initd 1.35 KB
Newer Older
1
#!/sbin/openrc-run
2 3 4

# note that the spoofprotect, syncoockies and ip_forward options are set in 
# /etc/sysctl.conf
5 6 7 8 9 10 11 12 13

ifconf=/etc/network/interfaces
ifstate=/var/run/ifstate

single_iface="${SVCNAME#*.}"
if [ "$single_iface" = "$SVCNAME" ]; then
	single_iface=
fi

14
depend() {
15
	need localmount
16
	after bootmisc hwdrivers modules
17
	provide net
18
	keyword -jail -prefix -vserver -docker
19 20
}

21 22 23 24 25
# find interfaces we want to start
find_ifaces() {
	if [ -n "$single_iface" ]; then
		echo $single_iface
	else
26
		awk '$1 == "auto" {for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)}' $ifconf
27
	fi
28 29
}

30 31 32 33 34 35 36
# 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
37 38
}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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=
60 61 62
	# Don't stop the network at shutdown.
	yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0

63 64 65 66 67 68 69 70 71
	ebegin "Stopping networking"
	eindent
	for iface in $(find_running_ifaces); do
		ebegin "$iface"
		ifdown -f $iface >/dev/null
		eend $?
	done
	eoutdent
	return 0
72 73
}