1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Id$ |
3 |
|
|
4 |
#%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k |
#%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k |
5 |
#%start: 20 |
#%start: 20 |
10 |
#%before: |
#%before: |
11 |
#%after: |
#%after: |
12 |
|
|
13 |
source /etc/sysconfig/rc |
source /etc/conf.d/rc |
14 |
source ${rc_functions} |
source ${rc_functions} |
15 |
|
|
16 |
checkconfig() { |
# read values from files |
17 |
if [ -z "${NETWORKING}" ] |
read_value() |
18 |
|
{ |
19 |
|
local var="$1" |
20 |
|
local file="$2" |
21 |
|
local value |
22 |
|
|
23 |
|
# local all possible vars |
24 |
|
# global |
25 |
|
local ONBOOT |
26 |
|
local NETWORKING |
27 |
|
|
28 |
|
# static |
29 |
|
local IP |
30 |
|
local NETMASK |
31 |
|
local BROADCAST |
32 |
|
local NETWORKING |
33 |
|
local FORCE_MAC_TO |
34 |
|
|
35 |
|
# dhcp |
36 |
|
local DHCP_PROG |
37 |
|
local DHCP_START |
38 |
|
local DHCP_STOP |
39 |
|
|
40 |
|
# default gw |
41 |
|
local GATEWAY |
42 |
|
local GATEWAY_IF |
43 |
|
|
44 |
|
# wireless extensions |
45 |
|
local WIRELESS_AP |
46 |
|
local WIRELESS_AUTH_MODE |
47 |
|
local WIRELESS_BITRATE |
48 |
|
local WIRELESS_CHANNEL |
49 |
|
local WIRELESS_DEFAULT_KEY |
50 |
|
local WIRELESS_ESSID |
51 |
|
local WIRELESS_FREQUENCY |
52 |
|
local WIRELESS_KEY |
53 |
|
local WIRELESS_KEY_ASCII |
54 |
|
local WIRELESS_KEY_0 |
55 |
|
local WIRELESS_KEY_1 |
56 |
|
local WIRELESS_KEY_2 |
57 |
|
local WIRELESS_KEY_3 |
58 |
|
local WIRELESS_KEY_LENGTH |
59 |
|
local WIRELESS_MODE |
60 |
|
local WIRELESS_NICK |
61 |
|
local WIRELESS_NWID |
62 |
|
local WIRELESS_POWER |
63 |
|
local WIRELESS_WPA_DRIVER |
64 |
|
|
65 |
|
local BRIDGE_INTERFACES |
66 |
|
local BRIDGE_STP |
67 |
|
local BRIDGE_AGEING_TIME |
68 |
|
local BRIDGE_PRIORITY |
69 |
|
local BRIDGE_FORWARD_DELAY |
70 |
|
local BRIDGE_HELLO_TIME |
71 |
|
local BRIDGE_MAX_MESSAGE_AGE |
72 |
|
local BRIDGE_PATH_COST |
73 |
|
local BRIDGE_PORT_PRIORITY |
74 |
|
|
75 |
|
source ${file} |
76 |
|
eval value=\$$(echo ${var}) |
77 |
|
echo "${value}" |
78 |
|
} |
79 |
|
|
80 |
|
checkconfig() |
81 |
|
{ |
82 |
|
if [[ -z ${NETWORKING} ]] |
83 |
then |
then |
84 |
echo "NETWORKING missing in net.${interface}, aborted" |
rc_echo "NETWORKING missing in net.${iface}, aborted" |
85 |
exit 1 |
exit 1 |
86 |
fi |
fi |
87 |
|
|
88 |
case "${NETWORKING}" in |
case "${NETWORKING}" in |
89 |
static) |
static) |
90 |
if [ -z "${IP}" ] |
if [[ -z ${IP} ]] |
91 |
then |
then |
92 |
echo "IP missing in net.${interface}, aborted" |
rc_echo "IP missing in net.${iface}, aborted" |
93 |
exit 1 |
exit 1 |
94 |
fi |
fi |
95 |
|
|
96 |
if [ -z "${NETMASK}" ] |
if [[ -z ${NETMASK} ]] |
97 |
then |
then |
98 |
echo -n "NETMASK missing in net.${interface}, " |
rc_echo -n "NETMASK missing in net.${iface}, " |
99 |
echo "using 255.255.255.0" |
rc_echo "using 255.255.255.0" |
100 |
NETMASK=255.255.255.0 |
NETMASK=255.255.255.0 |
101 |
fi |
fi |
102 |
|
|
103 |
if [ -z "${BROADCAST}" ] |
if [[ -z ${BROADCAST} ]] |
104 |
then |
then |
105 |
echo -n "BROADCAST missing in net.${interface}, " |
rc_echo -n "BROADCAST missing in net.${iface}, " |
106 |
echo "using default address" |
rc_echo "using default address" |
107 |
fi |
fi |
108 |
;; |
;; |
109 |
|
|
110 |
dhcp) |
dhcp) |
111 |
if [ -z "${DHCP_PROG}" ] |
if [[ -z ${DHCP_PROG} ]] |
112 |
then |
then |
113 |
echo "DHCP_PROG missing in net.${interface}, aborted" |
rc_echo -n "DHCP_PROG missing in net.${iface}," |
114 |
exit 1 |
rc_echo "using default programm /sbin/dhcpcd" |
115 |
|
DHCP_PROG="/sbin/dhcpcd" |
116 |
fi |
fi |
117 |
|
[[ -z ${DHCP_START} ]] && DHCP_START="-t 10" |
118 |
|
[[ -z ${DHCP_STOP} ]] && DHCP_STOP="-k" |
119 |
;; |
;; |
120 |
|
|
121 |
esac |
esac |
122 |
} |
} |
123 |
|
|
124 |
|
# onboot_interface_list /path/to/files* |
125 |
|
onboot_interface_list() |
126 |
|
{ |
127 |
|
local file |
128 |
|
local devices |
129 |
|
local iface |
130 |
|
|
131 |
|
# get list of all devices |
132 |
|
for file in $@ |
133 |
|
do |
134 |
|
iface="$(basename ${file} | sed s/net.//)" |
135 |
|
|
136 |
|
# exclude backup files and exclude net.routes and net.sample too |
137 |
|
case "${iface}" in |
138 |
|
*~) continue ;; |
139 |
|
routes) continue ;; |
140 |
|
sample) continue ;; |
141 |
|
esac |
142 |
|
|
143 |
case "$1" in |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
144 |
start) |
then |
145 |
for file in $(grep -il "ONBOOT=\"yes\"" ${network_settings}/net.*) |
devices="${devices} ${iface}" |
146 |
|
fi |
147 |
|
done |
148 |
|
|
149 |
|
echo "${devices}" |
150 |
|
} |
151 |
|
|
152 |
|
config_wireless_wep() |
153 |
|
{ |
154 |
|
local iface="$1" |
155 |
|
|
156 |
|
if [[ -z ${iface} ]] |
157 |
|
then |
158 |
|
rc_echo "WEP: no \$iface given. Aborting setup." |
159 |
|
return 1 |
160 |
|
fi |
161 |
|
|
162 |
|
${CURS_UP} |
163 |
|
${SET_WWCOL} |
164 |
|
rc_echo "[AUTH: WEP]" |
165 |
|
|
166 |
|
iwconfig "${iface}" enc on |
167 |
|
[[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
168 |
|
[[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
169 |
|
[[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" |
170 |
|
} |
171 |
|
|
172 |
|
config_wireless_wpa() |
173 |
|
{ |
174 |
|
local iface="$1" |
175 |
|
|
176 |
|
if [[ -z ${iface} ]] |
177 |
|
then |
178 |
|
rc_echo "WPA: no \$iface given. Aborting setup." |
179 |
|
return 1 |
180 |
|
fi |
181 |
|
|
182 |
|
if [ ! -x /sbin/wpa_supplicant ] |
183 |
|
then |
184 |
|
rc_echo "WPA: wpa_supplicant not installed. Aborting setup." |
185 |
|
return 1 |
186 |
|
fi |
187 |
|
|
188 |
|
${CURS_UP} |
189 |
|
${SET_WWCOL} |
190 |
|
rc_echo "[AUTH: WPA]" |
191 |
|
|
192 |
|
# get default settings |
193 |
|
[[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant |
194 |
|
|
195 |
|
# check the configuration |
196 |
|
[[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto |
197 |
|
[[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel |
198 |
|
|
199 |
|
# use wext as default driver, do not abort here anymore |
200 |
|
[[ -z ${WIRELESS_WPA_DRIVER} ]] && WIRELESS_WPA_DRIVER=wext |
201 |
|
|
202 |
|
# write a config with the settings from net.${iface} |
203 |
|
# only wpa-psk ! all other needs manual setup |
204 |
|
if [[ ${WIRELESS_WPA_AUTOCONF} = true ]] |
205 |
|
then |
206 |
|
# write default cfg from skeleton |
207 |
|
cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} |
208 |
|
|
209 |
|
local wpa_proto |
210 |
|
case ${WIRELESS_AUTH_MODE} in |
211 |
|
wpa) wpa_proto="WPA" ;; |
212 |
|
wpa2) wpa_proto="WPA2" ;; |
213 |
|
esac |
214 |
|
|
215 |
|
# setup the network entry |
216 |
|
sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ |
217 |
|
-e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \ |
218 |
|
-e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \ |
219 |
|
${WIRELESS_WPA_CONFIG} |
220 |
|
fi |
221 |
|
|
222 |
|
# remove old state dir |
223 |
|
[ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant |
224 |
|
|
225 |
|
# now run the wpa_supplicant dameon |
226 |
|
wpa_supplicant -B \ |
227 |
|
-D"${WIRELESS_WPA_DRIVER}" \ |
228 |
|
-c"${WIRELESS_WPA_CONFIG}" \ |
229 |
|
-i"${iface}" \ |
230 |
|
${WIRELESS_WPA_OPTS} |
231 |
|
|
232 |
|
# echo wait 5 seconds |
233 |
|
rc_echo " Waiting 5 seconds to retrieve authentification reply ... " |
234 |
|
sleep 5 |
235 |
|
} |
236 |
|
|
237 |
|
setup_wireless_extensions() |
238 |
|
{ |
239 |
|
local iface="$1" |
240 |
|
|
241 |
|
if [[ -z ${iface} ]] |
242 |
|
then |
243 |
|
rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." |
244 |
|
return 1 |
245 |
|
fi |
246 |
|
|
247 |
|
if [[ -n ${WIRELESS_BITRATE} ]] || |
248 |
|
[[ -n ${WIRELESS_CHANNEL} ]] || |
249 |
|
[[ -n ${WIRELESS_ESSID} ]] || |
250 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] || |
251 |
|
[[ -n ${WIRELESS_MODE} ]] || |
252 |
|
[[ -n ${WIRELESS_NICK} ]] || |
253 |
|
[[ -n ${WIRELESS_AUTH_MODE} ]] |
254 |
|
then |
255 |
|
rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
256 |
|
fi |
257 |
|
|
258 |
|
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
259 |
|
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
260 |
|
[[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" |
261 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}" |
262 |
|
[[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}" |
263 |
|
[[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" |
264 |
|
|
265 |
|
case "${WIRELESS_AUTH_MODE}" in |
266 |
|
wpa|wpa2) config_wireless_wpa "${iface}" ;; |
267 |
|
wep|on) config_wireless_wep "${iface}" ;; |
268 |
|
off) iwconfig "${iface}" enc off ;; |
269 |
|
esac |
270 |
|
} |
271 |
|
|
272 |
|
config_bridge_options() |
273 |
|
{ |
274 |
|
local iface="$1" |
275 |
|
local i |
276 |
|
local port |
277 |
|
local cost |
278 |
|
local prio |
279 |
|
|
280 |
|
# enable spanning-tree protocol |
281 |
|
case ${BRIDGE_STP} in |
282 |
|
on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;; |
283 |
|
*) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; |
284 |
|
esac |
285 |
|
|
286 |
|
# configure ageing time |
287 |
|
if [[ ! -z ${BRIDGE_AGEING_TIME} ]] |
288 |
|
then |
289 |
|
brctl setageing "${iface}" "${BRIDGE_AGEING_TIME}" |
290 |
|
fi |
291 |
|
|
292 |
|
# configure bridge priority |
293 |
|
if [[ ! -z ${BRIDGE_PRIORITY} ]] |
294 |
|
then |
295 |
|
brctl setbridgeprio "${iface}" "${BRIDGE_PRIORITY}" |
296 |
|
fi |
297 |
|
|
298 |
|
# configure forward delay |
299 |
|
if [[ ! -z ${BRIDGE_FORWARD_DELAY} ]] |
300 |
|
then |
301 |
|
brctl setfd "${iface}" "${BRIDGE_FORWARD_DELAY}" |
302 |
|
fi |
303 |
|
|
304 |
|
# configure hello time |
305 |
|
if [[ ! -z ${BRIDGE_HELLO_TIME} ]] |
306 |
|
then |
307 |
|
brctl sethello "${iface}" "${BRIDGE_HELLO_TIME}" |
308 |
|
fi |
309 |
|
|
310 |
|
# configure maximal message age |
311 |
|
if [[ ! -z ${BRIDGE_MAX_MESSAGE_AGE} ]] |
312 |
|
then |
313 |
|
brctl setmaxage "${iface}" "${BRIDGE_MAX_MESSAGE_AGE}" |
314 |
|
fi |
315 |
|
|
316 |
|
# configure path cost for every port |
317 |
|
if [[ ! -z ${BRIDGE_PATH_COST} ]] |
318 |
|
then |
319 |
|
for i in ${BRIDGE_PATH_COST} |
320 |
do |
do |
321 |
interface=$(basename ${file} | sed s/net.//) |
port="${i%=*}" |
322 |
case "${interface}" in |
cost="${i#*=}" |
323 |
*~) ;; |
[[ ! -z ${port} ]] && brctl pathcost "${iface}" "${port}" "${cost}" |
324 |
*) |
done |
325 |
source ${network_settings}/net.${interface} || exit 1 |
fi |
326 |
checkconfig |
|
327 |
case "${NETWORKING}" in |
# configure port priority for every port |
328 |
dhcp) |
if [[ ! -z ${BRIDGE_PORT_PRIORITY} ]] |
329 |
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${interface}${COLDEFAULT} ..." |
then |
330 |
${CURS_UP} |
for i in ${BRIDGE_PORT_PRIORITY} |
331 |
${SET_WWCOL} |
do |
332 |
echo "[DHCP]" |
port="${i%=*}" |
333 |
loadproc ${DHCP_PROG} ${DHCP_START} |
prio="${i#*=}" |
334 |
;; |
[[ ! -z ${port} ]] && brctl setportprio "${iface}" "${port}" "${prio}" |
335 |
static) |
done |
336 |
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${interface}${COLDEFAULT} ..." |
fi |
337 |
${CURS_UP} |
} |
338 |
${SET_WWCOL} |
|
339 |
echo "[STATIC]" |
config_bridge_devices() |
340 |
ifconfig ${interface} ${IP} netmask ${NETMASK} broadcast ${BROADCAST} |
{ |
341 |
evaluate_retval |
local iface="$1" |
342 |
;; |
local method="$2" |
343 |
esac |
local bport |
344 |
;; |
|
345 |
|
if [[ -z ${iface} ]] |
346 |
|
then |
347 |
|
rc_echo "BRIDGE: no \$iface given. Aborting setup." |
348 |
|
return 1 |
349 |
|
fi |
350 |
|
|
351 |
|
if [[ -z ${method} ]] |
352 |
|
then |
353 |
|
rc_echo "BRIDGE: no \$method given. Aborting setup." |
354 |
|
return 1 |
355 |
|
fi |
356 |
|
|
357 |
|
# first check for brctl |
358 |
|
if [[ -z $(which brctl) ]] |
359 |
|
then |
360 |
|
rc_echo "brctl not found! Please install 'net-misc/bridge-utils'." |
361 |
|
return 1 |
362 |
|
fi |
363 |
|
|
364 |
|
# check the config |
365 |
|
if [[ -z ${BRIDGE_INTERFACES} ]] |
366 |
|
then |
367 |
|
rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." |
368 |
|
return 1 |
369 |
|
fi |
370 |
|
|
371 |
|
case ${method} in |
372 |
|
add) |
373 |
|
# setup the bridge device |
374 |
|
brctl addbr "${iface}" |
375 |
|
for bport in ${BRIDGE_INTERFACES} |
376 |
|
do |
377 |
|
# enter promiscous mode |
378 |
|
ifconfig "${bport}" 0.0.0.0 promisc |
379 |
|
# now setup the bridge |
380 |
|
brctl addif "${iface}" "${bport}" |
381 |
|
done |
382 |
|
# configure all other options |
383 |
|
config_bridge_options "${iface}" |
384 |
|
;; |
385 |
|
|
386 |
|
remove) |
387 |
|
for bport in ${BRIDGE_INTERFACE} |
388 |
|
do |
389 |
|
# bring the interface down |
390 |
|
ifconfig "${bport}" down |
391 |
|
# remove the interface from the bridge |
392 |
|
brctl delif "${iface}" "${bport}" |
393 |
|
done |
394 |
|
# bring the bridge down |
395 |
|
brctl delbr "${iface}" |
396 |
|
;; |
397 |
|
esac |
398 |
|
|
399 |
|
# unset the bridge variable to be safe |
400 |
|
unset BRIDGE_INTERFACES |
401 |
|
# continue to setup generic networking |
402 |
|
} |
403 |
|
|
404 |
|
config_routes() |
405 |
|
{ |
406 |
|
local method="$1" |
407 |
|
local message |
408 |
|
|
409 |
|
# only add and del are allowed |
410 |
|
case ${method} in |
411 |
|
add) message="Adding" ;; |
412 |
|
del) message="Removing" ;; |
413 |
|
*) |
414 |
|
rc_echo "config_routes: unsupported \$method '${method}'." |
415 |
|
exit 1 |
416 |
|
;; |
417 |
|
esac |
418 |
|
|
419 |
|
# adds/delete user routes |
420 |
|
if [[ -f /etc/conf.d/net.routes ]] |
421 |
|
then |
422 |
|
( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end |
423 |
|
while read route |
424 |
|
do |
425 |
|
case "${route}" in |
426 |
|
\#*|"") continue ;; |
427 |
esac |
esac |
428 |
|
rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..." |
429 |
|
# do not esacpe ${route} or it breaks! |
430 |
|
route "${method}" ${route} |
431 |
|
evaluate_retval |
432 |
done |
done |
433 |
|
fi |
434 |
|
} |
435 |
|
|
436 |
if [ -n "${GATEWAY}" -a -n "${GATEWAY_IF}" ] |
networking_start() |
437 |
|
{ |
438 |
|
local iface dns routes ALL_INTERFACES |
439 |
|
|
440 |
|
if [[ -z $1 ]] |
441 |
|
then |
442 |
|
ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) |
443 |
|
else |
444 |
|
if [[ -e ${rc_network_settings}/net.$1 ]] |
445 |
then |
then |
446 |
echo -e ${COLOREDSTAR}"Setting up default gateway ..." |
ALL_INTERFACES="$1" |
447 |
route add default gateway ${GATEWAY} metric 1 \ |
else |
448 |
dev ${GATEWAY_IF} |
${FAILURE} |
449 |
|
rc_echo "Interface $1 does not exist. Aborting" |
450 |
|
${NORMAL} |
451 |
|
exit 1 |
452 |
|
fi |
453 |
|
fi |
454 |
|
|
455 |
|
# get list of all devices |
456 |
|
for iface in ${ALL_INTERFACES} |
457 |
|
do |
458 |
|
# checkconfig |
459 |
|
source ${rc_network_settings}/net.${iface} || exit 1 |
460 |
|
checkconfig |
461 |
|
|
462 |
|
# setup mac |
463 |
|
if [[ -n ${FORCE_MAC_TO} ]] |
464 |
|
then |
465 |
|
rc_print "Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " |
466 |
|
ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" |
467 |
evaluate_retval |
evaluate_retval |
468 |
fi |
fi |
469 |
|
|
470 |
update_svcstatus $1 |
# setup bridges |
471 |
splash svc_started "$(basename $0)" 0 |
if [[ ${iface} = br[0-9]* ]] |
472 |
;; |
then |
473 |
|
config_bridge_devices "${iface}" add |
474 |
|
fi |
475 |
|
|
476 |
stop) |
# now configure wireless_extensions |
477 |
if [ -n "${GATEWAY}" ] |
[ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" |
478 |
|
|
479 |
|
rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
480 |
|
|
481 |
|
# activate the interface |
482 |
|
ifconfig "${iface}" up |
483 |
|
|
484 |
|
# setup static or dhcp |
485 |
|
case ${NETWORKING} in |
486 |
|
dhcp|DHCP) |
487 |
|
${CURS_UP} |
488 |
|
${SET_WWCOL} |
489 |
|
rc_echo "[DHCP]" |
490 |
|
loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" |
491 |
|
;; |
492 |
|
static|STATIC) |
493 |
|
${CURS_UP} |
494 |
|
${SET_WWCOL} |
495 |
|
rc_echo "[STATIC]" |
496 |
|
ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" |
497 |
|
evaluate_retval |
498 |
|
;; |
499 |
|
esac |
500 |
|
|
501 |
|
# setup def gw |
502 |
|
if [[ -n ${GATEWAY} ]] |
503 |
then |
then |
504 |
echo -e ${COLOREDSTAR}"Removing default gateway ..." |
rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
505 |
|
route add default gateway "${GATEWAY}" metric 1 dev "${iface}" |
506 |
|
evaluate_retval |
507 |
|
|
508 |
|
unset GATEWAY |
509 |
|
fi |
510 |
|
|
511 |
|
# setup /etc/resolv.conf |
512 |
|
# add given nameserver |
513 |
|
if [[ -n ${NAMESERVER} ]] |
514 |
|
then |
515 |
|
rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." |
516 |
|
|
517 |
|
# whipe out the old one |
518 |
|
echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf |
519 |
|
# include head |
520 |
|
if [ -f /etc/resolv.conf.head ] |
521 |
|
then |
522 |
|
cat /etc/resolv.conf.head >> /etc/resolv.conf |
523 |
|
else |
524 |
|
echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf |
525 |
|
fi |
526 |
|
|
527 |
|
for dns in ${NAMESERVER} |
528 |
|
do |
529 |
|
echo "nameserver ${dns}" >> /etc/resolv.conf |
530 |
|
done |
531 |
|
|
532 |
|
# include tail |
533 |
|
if [ -f /etc/resolv.conf.tail ] |
534 |
|
then |
535 |
|
cat /etc/resolv.conf.tail >> /etc/resolv.conf |
536 |
|
else |
537 |
|
echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf |
538 |
|
fi |
539 |
|
|
540 |
|
unset NAMESERVER |
541 |
|
fi |
542 |
|
done |
543 |
|
|
544 |
|
# setup user routes |
545 |
|
config_routes add |
546 |
|
} |
547 |
|
|
548 |
|
networking_stop() |
549 |
|
{ |
550 |
|
if [[ -z $1 ]] |
551 |
|
then |
552 |
|
ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) |
553 |
|
else |
554 |
|
if [[ -e ${rc_network_settings}/net.$1 ]] |
555 |
|
then |
556 |
|
ALL_INTERFACES="$1" |
557 |
|
else |
558 |
|
${FAILURE} |
559 |
|
rc_echo "Interface $1 does not exist. Aborting" |
560 |
|
${NORMAL} |
561 |
|
exit 1 |
562 |
|
fi |
563 |
|
fi |
564 |
|
|
565 |
|
# get list of all devices |
566 |
|
for iface in ${ALL_INTERFACES} |
567 |
|
do |
568 |
|
source ${rc_network_settings}/net.${iface} || exit 1 |
569 |
|
checkconfig |
570 |
|
|
571 |
|
if [[ -n ${GATEWAY} ]] |
572 |
|
then |
573 |
|
rc_print "Removing default gateway ..." |
574 |
route del -net default |
route del -net default |
575 |
evaluate_retval |
evaluate_retval |
576 |
fi |
fi |
577 |
|
|
578 |
for file in $(grep -il "ONBOOT=\"yes\"" ${network_settings}/net.*) |
rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
579 |
do |
ifconfig "${iface}" down |
580 |
interface=$(basename ${file} | sed s/net.//) |
evaluate_retval |
581 |
case "${interface}" in |
|
582 |
*~) ;; |
# remove bridges |
583 |
*) |
if [[ ${iface} = br[0-9]* ]] |
584 |
#$network_devices/ifdown $interface |
then |
585 |
source ${network_settings}/net.${interface} || exit 1 |
config_bridge_devices "${iface}" remove |
586 |
checkconfig |
fi |
587 |
echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${interface}${COLDEFAULT} ..." |
|
588 |
ifconfig ${interface} down |
# shutdown dhcp-daemon |
589 |
evaluate_retval |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]] |
590 |
|
then |
591 |
#shutdown dhcp-daemon |
rc_print "Stopping the dhcp-daemon ..." |
592 |
if [ "${NETWORKING}" == dhcp ] |
${CURS_UP} |
593 |
then |
${SET_WWCOL} |
594 |
my_runlevel="`runlevel | cut -d ' ' -f2`" |
rc_echo "[$(basename ${DHCP_PROG})]" |
595 |
if [ -n "$(pidof ${DHCP_PROG})" ] |
if [[ -z ${DHCP_STOP} ]] |
596 |
then |
then |
597 |
echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." |
killproc ${DHCP_PROG} |
598 |
${CURS_UP} |
evaluate_retval |
599 |
${SET_WWCOL} |
else |
600 |
echo "[$(basename ${DHCP_PROG})]" |
${DHCP_PROG} ${DHCP_STOP} "${iface}" |
601 |
${DHCP_PROG} ${DHCP_STOP} |
evaluate_retval |
602 |
evaluate_retval |
fi |
603 |
fi |
fi |
|
fi |
|
|
;; |
|
|
esac |
|
|
done |
|
604 |
|
|
605 |
|
# shutdown wpa_supplicant daemon |
606 |
|
if [[ -n $(pidof wpa_supplicant) ]] |
607 |
|
then |
608 |
|
killall wpa_supplicant |
609 |
|
fi |
610 |
|
done |
611 |
|
|
612 |
|
# remove state dir |
613 |
|
if [ -d /var/run/wpa_supplicant ] |
614 |
|
then |
615 |
|
rm -rf /var/run/wpa_supplicant |
616 |
|
fi |
617 |
|
|
618 |
|
# delete user routes |
619 |
|
config_routes del |
620 |
|
} |
621 |
|
|
622 |
|
case $1 in |
623 |
|
start) |
624 |
|
networking_start $2 |
625 |
|
update_svcstatus $1 |
626 |
|
splash svc_started "$(basename $0)" 0 |
627 |
|
;; |
628 |
|
|
629 |
|
stop) |
630 |
|
networking_stop $2 |
631 |
update_svcstatus $1 |
update_svcstatus $1 |
632 |
splash svc_stopped "$(basename $0)" 0 |
splash svc_stopped "$(basename $0)" 0 |
633 |
;; |
;; |
639 |
;; |
;; |
640 |
|
|
641 |
*) |
*) |
642 |
echo "Usage: $0 {start|stop|restart}" |
rc_echo "Usage: $0 {start|stop|restart} [interface]" |
643 |
exit 1 |
exit 1 |
644 |
;; |
;; |
645 |
esac |
esac |