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