summaryrefslogtreecommitdiff
path: root/network
blob: fc684ba479618d5bb876f1a978846fe1c0607478 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

# look for wireless settings
[ -f /etc/conf.d/wireless ] && . /etc/conf.d/wireless

# look for dhcpcd settings
[ -f /etc/conf.d/dhcpcd ] && . /etc/conf.d/dhcpcd

ifup()
{
	if [ "$1" = "" ]; then
		echo "usage: $0 ifup <interface_name>"
		return 1
	fi
	for wif in ${WLAN_INTERFACES[@]}; do
		if [ "$wif" = "${1}" ]; then
			wvarname="\$wlan_${1}"
			eval wif_line=$wvarname
			/usr/sbin/iwconfig $wif_line
			/usr/bin/sleep 2
		fi
	done
	varname="\$${1}"
	eval new_ifline=$varname
	if [ "$new_ifline" = "dhcp" ]; then
		# remove the .pid file if it exists
		rm -f /etc/dhcpc/dhcpcd-${1}.{pid,cache} >/dev/null 2>&1
		/usr/sbin/dhcpcd $DHCPCD_ARGS $1
	else
		/sbin/ifconfig $new_ifline
	fi
	return $?
}

ifdown()
{
	if [ "$1" = "" ]; then
		echo "usage: $0 ifdown <interface_name>"
		return 1
	fi
	varname="\$${1}"
	eval new_ifline=$varname
	if [ "$new_ifline" = "dhcp" ]; then
		if [ -f /etc/dhcpc/dhcpcd-${1}.pid ]; then
			/bin/kill `cat /etc/dhcpc/dhcpcd-${1}.pid`
		else
			# No .pid file, just bring the interface itself down
			/sbin/ifconfig $1 down
		fi
	else
		/sbin/ifconfig $new_ifline down
	fi
	return $?
}

iflist()
{
	for ifline in ${INTERFACES[@]}; do
		if echo $ifline | grep '^[^\!]' >/dev/null 2>&1; then
			echo -en " $ifline:\t"
		else
			echo -en "$ifline:\t"
		fi
		eval real_ifline=\$${ifline#!}
		echo $real_ifline
	done
}

rtup()
{
	if [ "$1" = "" ]; then
		echo "usage: $0 rtup <route_name>"
		return 1
	fi
	varname="\$${1}"
	eval new_rtline=$varname
	/sbin/route add $new_rtline
	return $?
}

rtdown()
{
	if [ "$1" = "" ]; then
		echo "usage: $0 rtdown <route_name>"
		return 1
	fi
	varname="\$${1}"
	eval new_rtline=$varname
	/sbin/route del $new_rtline
	return $?
}

rtlist()
{
	for rtline in ${ROUTES[@]}; do
		if echo $rtline | grep '^[^\!]' >/dev/null 2>&1; then
			echo -en " $rtline:\t"
		else
			echo -en "$rtline:\t"
		fi
		eval real_rtline=\$${rtline#!}
		echo $real_rtline
	done
}

case "$1" in
	start)
	if ! ck_daemon network; then
		echo "Network is already running.  Try 'network restart'"
		exit
	fi
	stat_busy "Starting Network"
	error=0
	for ifline in ${INTERFACES[@]}; do
		if echo $ifline | grep '^[^\!]' >/dev/null 2>&1; then
			ifup $ifline || error=1
		fi
	done
	for rtline in "${ROUTES[@]}"; do
		if echo $rtline | grep '^[^\!]' 2>&1 >/dev/null; then
			rtup $rtline || error=1
		fi
	done
	if [ $error -eq 0 ]; then
		add_daemon network
		stat_done
	else
		stat_fail
	fi
	;;
	stop)
	if ck_daemon network; then
		echo "Network is not running.  Try 'network start'"
		exit
	fi
	stat_busy "Stopping Network"
	rm_daemon network
	error=0
	for rtline in "${ROUTES[@]}"; do
		if echo $rtline | grep '^[^\!]' 2>&1 >/dev/null; then
			rtdown $rtline || error=1
		fi
	done
	for ifline in ${INTERFACES[@]}; do
		if echo $ifline | grep '^[^\!]' 2>&1 >/dev/null; then
			ifdown $ifline || error=1
		fi
	done
	if [ $error -eq 0 ]; then
		stat_done
	else
		stat_fail
	fi
	;;
	restart)
	$0 stop
	/usr/bin/sleep 2
	$0 start
	;;
	ifup|ifdown|iflist|rtup|rtdown|rtlist)
	$1 $2
	;;
	*)
	echo "usage: $0 {start|stop|restart}"  
	echo "       $0 {ifup|ifdown|iflist|rtup|rtdown|rtlist}"
esac