aboutsummaryrefslogtreecommitdiff
path: root/init.d/staticroute.in
blob: 0b49ca9a426b9a054339b89f7ba6f399623f5105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!@PREFIX@/sbin/runscript
# Copyright (c) 2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.

# This script was inspired by the equivalent rc.d staticroute from NetBSD.

description="Configures static routes."
__nl="
"

depend()
{
	provide net
	use network
	keyword -jail -prefix -vserver
}

dump_args()
{
	if [ -s /etc/route.conf ]; then
		cat /etc/route.conf
	else
		case "$staticroute" in
		*"$__nl"*)
			echo "$staticroute"
			;;
		*)
			(
		 		set -o noglob
				IFS=';'; set -- $staticroute
				IFS="$__nl"; echo "$*"
			)
			;;
		esac
	fi
}

do_routes()
{
	local xtra=
	[ "$RC_UNAME" != Linux ] && xtra=-q

	ebegin "$1 static routes"
	dump_args | while read args; do
		[ -z "$args" ] && continue
		case "$args" in
		"#"*)
			;;
		"+"*)
			[ $2 = "add" ] && eval ${args#*+}
			;;
		"-"*)
			[ $2 = "del" -o $2 = "delete" ] && eval ${args#*-}
			;;
		*)
			route $xtra $2 -$args
			;;
		esac
	done
	eend 0
}

start()
{
	do_routes "Adding" "add"
}

stop()
{
	local cmd="delete"
	[ "$RC_UNAME" = Linux ] && cmd="del"
	do_routes "Deleting" "$cmd"
}