Deleted Added
full compact
network.subr (196589) network.subr (197139)
1#
2# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.

--- 8 unchanged lines hidden (view full) ---

17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
1#
2# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.

--- 8 unchanged lines hidden (view full) ---

17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25# $FreeBSD: head/etc/network.subr 196589 2009-08-27 15:24:26Z dougb $
25# $FreeBSD: head/etc/network.subr 197139 2009-09-12 22:13:41Z hrs $
26#
27
28#
29# Subroutines commonly used from network startup scripts.
30# Requires that rc.conf be loaded first.
31#
32
33# ifn_start ifn

--- 6 unchanged lines hidden (view full) ---

40 ifn="$1"
41 cfg=1
42
43 [ -z "$ifn" ] && err 1 "ifn_start called without an interface"
44
45 ifscript_up ${ifn} && cfg=0
46 ifconfig_up ${ifn} && cfg=0
47 ipv4_up ${ifn} && cfg=0
26#
27
28#
29# Subroutines commonly used from network startup scripts.
30# Requires that rc.conf be loaded first.
31#
32
33# ifn_start ifn

--- 6 unchanged lines hidden (view full) ---

40 ifn="$1"
41 cfg=1
42
43 [ -z "$ifn" ] && err 1 "ifn_start called without an interface"
44
45 ifscript_up ${ifn} && cfg=0
46 ifconfig_up ${ifn} && cfg=0
47 ipv4_up ${ifn} && cfg=0
48 ipv6_up ${ifn} && cfg=0
48 ipx_up ${ifn} && cfg=0
49 ipx_up ${ifn} && cfg=0
49 childif_create ${ifn}
50 childif_create ${ifn} && cfg=0
50
51 return $cfg
52}
53
51
52 return $cfg
53}
54
54# ifn_start ifn
55# ifn_stop ifn
55# Shutdown and de-configure an interface. If action is taken print the
56# interface name.
57#
58ifn_stop()
59{
60 local ifn cfg
61 ifn="$1"
62 cfg=1
63
56# Shutdown and de-configure an interface. If action is taken print the
57# interface name.
58#
59ifn_stop()
60{
61 local ifn cfg
62 ifn="$1"
63 cfg=1
64
64 [ -z "$ifn" ] && return 1
65 [ -z "$ifn" ] && err 1 "ifn_stop called without an interface"
65
66 ipx_down ${ifn} && cfg=0
66
67 ipx_down ${ifn} && cfg=0
68 ipv6_down ${ifn} && cfg=0
67 ipv4_down ${ifn} && cfg=0
68 ifconfig_down ${ifn} && cfg=0
69 ifscript_down ${ifn} && cfg=0
69 ipv4_down ${ifn} && cfg=0
70 ifconfig_down ${ifn} && cfg=0
71 ifscript_down ${ifn} && cfg=0
70 childif_destroy ${ifn}
72 childif_destroy ${ifn} && cfg=0
71
72 return $cfg
73}
74
75# ifconfig_up if
76# Evaluate ifconfig(8) arguments for interface $if and
77# run ifconfig(8) with those arguments. It returns 0 if
78# arguments were found and executed or 1 if the interface
79# had no arguments. Pseudo arguments DHCP and WPA are handled
80# here.
81#
82ifconfig_up()
83{
73
74 return $cfg
75}
76
77# ifconfig_up if
78# Evaluate ifconfig(8) arguments for interface $if and
79# run ifconfig(8) with those arguments. It returns 0 if
80# arguments were found and executed or 1 if the interface
81# had no arguments. Pseudo arguments DHCP and WPA are handled
82# here.
83#
84ifconfig_up()
85{
86 local _cfg _ipv6_opts ifconfig_args
84 _cfg=1
85
87 _cfg=1
88
89 # ifconfig_IF
86 ifconfig_args=`ifconfig_getargs $1`
87 if [ -n "${ifconfig_args}" ]; then
88 ifconfig $1 ${ifconfig_args}
90 ifconfig_args=`ifconfig_getargs $1`
91 if [ -n "${ifconfig_args}" ]; then
92 ifconfig $1 ${ifconfig_args}
89 ifconfig $1 up
90 _cfg=0
91 fi
92
93 _cfg=0
94 fi
95
96 # inet6 specific
97 if afexists inet6; then
98 if ipv6if $1; then
99 if checkyesno ipv6_gateway_enable; then
100 _ipv6_opts="-accept_rtadv auto_linklocal"
101 else
102 _ipv6_opts="auto_linklocal"
103 fi
104 else
105 _ipv6_opts="-auto_linklocal ifdisabled"
106 fi
107
108 ifconfig $1 inet6 ${_ipv6_opts}
109
110 # ifconfig_IF_ipv6
111 ifconfig_args=`ifconfig_getargs $1 ipv6`
112 if [ -n "${ifconfig_args}" ]; then
113 ifconfig $1 inet6 -ifdisabled
114 ifconfig $1 ${ifconfig_args}
115 _cfg=0
116 fi
117
118 # backward compatiblity: $ipv6_ifconfig_IF
119 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF`
120 if [ -n "${ifconfig_args}" ]; then
121 warn "\$ipv6_ifconfig_$1 is obsolete." \
122 " Use ifconfig_$1_ipv6 instead."
123 ifconfig $1 inet6 -ifdisabled
124 ifconfig $1 inet6 ${ifconfig_args}
125 _cfg=0
126 fi
127 fi
128
129 if [ ${_cfg} -eq 0 ]; then
130 ifconfig $1 up
131 fi
132
93 if wpaif $1; then
94 /etc/rc.d/wpa_supplicant start $1
95 _cfg=0 # XXX: not sure this should count
96 fi
97
98 if dhcpif $1; then
99 if [ $_cfg -ne 0 ] ; then
100 ifconfig $1 up

--- 8 unchanged lines hidden (view full) ---

109}
110
111# ifconfig_down if
112# returns 1 if wpa_supplicant or dhclient was stopped or
113# the interface exists.
114#
115ifconfig_down()
116{
133 if wpaif $1; then
134 /etc/rc.d/wpa_supplicant start $1
135 _cfg=0 # XXX: not sure this should count
136 fi
137
138 if dhcpif $1; then
139 if [ $_cfg -ne 0 ] ; then
140 ifconfig $1 up

--- 8 unchanged lines hidden (view full) ---

149}
150
151# ifconfig_down if
152# returns 1 if wpa_supplicant or dhclient was stopped or
153# the interface exists.
154#
155ifconfig_down()
156{
117 [ -z "$1" ] && return 1
157 local _cfg
118 _cfg=1
119
120 if wpaif $1; then
121 /etc/rc.d/wpa_supplicant stop $1
122 _cfg=0
123 fi
124
125 if dhcpif $1; then

--- 12 unchanged lines hidden (view full) ---

138# get_if_var if var [default]
139# Return the value of the pseudo-hash corresponding to $if where
140# $var is a string containg the sub-string "IF" which will be
141# replaced with $if after the characters defined in _punct are
142# replaced with '_'. If the variable is unset, replace it with
143# $default if given.
144get_if_var()
145{
158 _cfg=1
159
160 if wpaif $1; then
161 /etc/rc.d/wpa_supplicant stop $1
162 _cfg=0
163 fi
164
165 if dhcpif $1; then

--- 12 unchanged lines hidden (view full) ---

178# get_if_var if var [default]
179# Return the value of the pseudo-hash corresponding to $if where
180# $var is a string containg the sub-string "IF" which will be
181# replaced with $if after the characters defined in _punct are
182# replaced with '_'. If the variable is unset, replace it with
183# $default if given.
184get_if_var()
185{
186 local _if _punct _var _default prefix suffix
187
146 if [ $# -ne 2 -a $# -ne 3 ]; then
147 err 3 'USAGE: get_if_var name var [default]'
148 fi
149
150 _if=$1
151 _punct=". - / +"
152 for _punct_c in $_punct; do
153 _if=`ltr ${_if} ${_punct_c} '_'`
154 done
155 _var=$2
156 _default=$3
157
158 prefix=${_var%%IF*}
159 suffix=${_var##*IF}
160 eval echo \${${prefix}${_if}${suffix}-${_default}}
161}
162
188 if [ $# -ne 2 -a $# -ne 3 ]; then
189 err 3 'USAGE: get_if_var name var [default]'
190 fi
191
192 _if=$1
193 _punct=". - / +"
194 for _punct_c in $_punct; do
195 _if=`ltr ${_if} ${_punct_c} '_'`
196 done
197 _var=$2
198 _default=$3
199
200 prefix=${_var%%IF*}
201 suffix=${_var##*IF}
202 eval echo \${${prefix}${_if}${suffix}-${_default}}
203}
204
163# _ifconfig_getargs if
205# _ifconfig_getargs if [af]
164# Echos the arguments for the supplied interface to stdout.
165# returns 1 if empty. In general, ifconfig_getargs should be used
166# outside this file.
167_ifconfig_getargs()
168{
206# Echos the arguments for the supplied interface to stdout.
207# returns 1 if empty. In general, ifconfig_getargs should be used
208# outside this file.
209_ifconfig_getargs()
210{
211 local _ifn _af
169 _ifn=$1
212 _ifn=$1
213 _af=${2+_$2}
214
170 if [ -z "$_ifn" ]; then
171 return 1
172 fi
173
215 if [ -z "$_ifn" ]; then
216 return 1
217 fi
218
174 get_if_var $_ifn ifconfig_IF "$ifconfig_DEFAULT"
219 get_if_var $_ifn ifconfig_IF$_af "$ifconfig_DEFAULT"
175}
176
220}
221
177# ifconfig_getargs if
222# ifconfig_getargs if [af]
178# Takes the result from _ifconfig_getargs and removes pseudo
179# args such as DHCP and WPA.
180ifconfig_getargs()
181{
223# Takes the result from _ifconfig_getargs and removes pseudo
224# args such as DHCP and WPA.
225ifconfig_getargs()
226{
182 _tmpargs=`_ifconfig_getargs $1`
227 local _tmpargs _arg _args
228 _tmpargs=`_ifconfig_getargs $1 $2`
183 if [ $? -eq 1 ]; then
184 return 1
185 fi
186 _args=
187
188 for _arg in $_tmpargs; do
189 case $_arg in
190 [Dd][Hh][Cc][Pp]) ;;

--- 10 unchanged lines hidden (view full) ---

201 echo $_args
202}
203
204# autoif
205# Returns 0 if the interface should be automaticly configured at
206# boot time and 1 otherwise.
207autoif()
208{
229 if [ $? -eq 1 ]; then
230 return 1
231 fi
232 _args=
233
234 for _arg in $_tmpargs; do
235 case $_arg in
236 [Dd][Hh][Cc][Pp]) ;;

--- 10 unchanged lines hidden (view full) ---

247 echo $_args
248}
249
250# autoif
251# Returns 0 if the interface should be automaticly configured at
252# boot time and 1 otherwise.
253autoif()
254{
255 local _tmpargs _arg
209 _tmpargs=`_ifconfig_getargs $1`
256 _tmpargs=`_ifconfig_getargs $1`
257
210 for _arg in $_tmpargs; do
211 case $_arg in
212 [Nn][Oo][Aa][Uu][Tt][Oo])
213 return 1
214 ;;
215 esac
216 done
258 for _arg in $_tmpargs; do
259 case $_arg in
260 [Nn][Oo][Aa][Uu][Tt][Oo])
261 return 1
262 ;;
263 esac
264 done
265
217 return 0
218}
219
220# dhcpif if
221# Returns 0 if the interface is a DHCP interface and 1 otherwise.
222dhcpif()
223{
266 return 0
267}
268
269# dhcpif if
270# Returns 0 if the interface is a DHCP interface and 1 otherwise.
271dhcpif()
272{
273 local _tmpargs _arg
224 _tmpargs=`_ifconfig_getargs $1`
274 _tmpargs=`_ifconfig_getargs $1`
275
225 for _arg in $_tmpargs; do
226 case $_arg in
227 [Dd][Hh][Cc][Pp])
228 return 0
229 ;;
230 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
231 return 0
232 ;;
233 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
234 return 0
235 ;;
236 esac
237 done
276 for _arg in $_tmpargs; do
277 case $_arg in
278 [Dd][Hh][Cc][Pp])
279 return 0
280 ;;
281 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
282 return 0
283 ;;
284 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
285 return 0
286 ;;
287 esac
288 done
289
238 return 1
239}
240
241# syncdhcpif
242# Returns 0 if the interface should be configured synchronously and
243# 1 otherwise.
244syncdhcpif()
245{
290 return 1
291}
292
293# syncdhcpif
294# Returns 0 if the interface should be configured synchronously and
295# 1 otherwise.
296syncdhcpif()
297{
298 local _tmpargs _arg
246 _tmpargs=`_ifconfig_getargs $1`
299 _tmpargs=`_ifconfig_getargs $1`
300
247 for _arg in $_tmpargs; do
248 case $_arg in
249 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
250 return 1
251 ;;
252 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
253 return 0
254 ;;
255 esac
256 done
301 for _arg in $_tmpargs; do
302 case $_arg in
303 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
304 return 1
305 ;;
306 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
307 return 0
308 ;;
309 esac
310 done
257 if checkyesno synchronous_dhclient; then
258 return 0
259 else
260 return 1
261 fi
311
312 checkyesno synchronous_dhclient
262}
263
264# wpaif if
265# Returns 0 if the interface is a WPA interface and 1 otherwise.
266wpaif()
267{
313}
314
315# wpaif if
316# Returns 0 if the interface is a WPA interface and 1 otherwise.
317wpaif()
318{
319 local _tmpargs _arg
268 _tmpargs=`_ifconfig_getargs $1`
320 _tmpargs=`_ifconfig_getargs $1`
321
269 for _arg in $_tmpargs; do
270 case $_arg in
271 [Ww][Pp][Aa])
272 return 0
273 ;;
274 esac
275 done
322 for _arg in $_tmpargs; do
323 case $_arg in
324 [Ww][Pp][Aa])
325 return 0
326 ;;
327 esac
328 done
329
276 return 1
277}
278
330 return 1
331}
332
333# afexists af
334# Returns 0 if the address family is enabled in the kernel
335# 1 otherwise.
336afexists()
337{
338 local _af
339 _af=$1
340
341 case ${_af} in
342 inet)
343 ${SYSCTL_N} net.inet > /dev/null 2>&1
344 ;;
345 inet6)
346 ${SYSCTL_N} net.inet6 > /dev/null 2>&1
347 ;;
348 *)
349 err 1 "afexists(): Unsupported address family: $_af"
350 ;;
351 esac
352}
353
354# noafif if
355# Returns 0 if the interface has no af configuration and 1 otherwise.
356noafif()
357{
358 local _if
359 _if=$1
360
361 case $_if in
362 pflog[0-9]*|\
363 pfsync[0-9]*|\
364 an[0-9]*|\
365 ath[0-9]*|\
366 ipw[0-9]*|\
367 iwi[0-9]*|\
368 iwn[0-9]*|\
369 ral[0-9]*|\
370 wi[0-9]*|\
371 wl[0-9]*|\
372 wpi[0-9]*)
373 return 0
374 ;;
375 esac
376
377 return 1
378}
379
279# ipv6if if
280# Returns 0 if the interface should be configured for IPv6 and
281# 1 otherwise.
282ipv6if()
283{
380# ipv6if if
381# Returns 0 if the interface should be configured for IPv6 and
382# 1 otherwise.
383ipv6if()
384{
284 if ! checkyesno ipv6_enable; then
385 local _if i
386 _if=$1
387
388 if ! afexists inet6; then
285 return 1
286 fi
389 return 1
390 fi
391
392 # lo0 is always IPv6-enabled
393 case $_if in
394 lo0)
395 return 0
396 ;;
397 esac
398
287 case "${ipv6_network_interfaces}" in
288 [Aa][Uu][Tt][Oo])
289 return 0
290 ;;
291 ''|[Nn][Oo][Nn][Ee])
292 return 1
293 ;;
294 esac
399 case "${ipv6_network_interfaces}" in
400 [Aa][Uu][Tt][Oo])
401 return 0
402 ;;
403 ''|[Nn][Oo][Nn][Ee])
404 return 1
405 ;;
406 esac
295 for v6if in ${ipv6_network_interfaces}; do
296 if [ "${v6if}" = "${1}" ]; then
407
408 for i in ${ipv6_network_interfaces}; do
409 if [ "$i" = "$_if" ]; then
297 return 0
298 fi
299 done
410 return 0
411 fi
412 done
413
300 return 1
301}
302
414 return 1
415}
416
417# ipv6_autoconfif if
418# Returns 0 if the interface should be configured for IPv6 with
419# Stateless Address Configuration, 1 otherwise.
420ipv6_autoconfif()
421{
422 local _if _tmpargs _arg
423 _if=$1
424
425 if ! ipv6if $_if; then
426 return 1
427 fi
428 if noafif $_if; then
429 return 1
430 fi
431 if checkyesno ipv6_gateway_enable; then
432 return 1
433 fi
434
435 case $_if in
436 lo0|\
437 stf[0-9]*|\
438 faith[0-9]*|\
439 lp[0-9]*|\
440 sl[0-9]*)
441 return 1
442 ;;
443 esac
444
445 _tmpargs=`_ifconfig_getargs $_if ipv6`
446 for _arg in $_tmpargs; do
447 case $_arg in
448 accept_rtadv)
449 return 0
450 ;;
451 esac
452 done
453
454 return 1
455}
456
303# ifexists if
304# Returns 0 if the interface exists and 1 otherwise.
305ifexists()
306{
457# ifexists if
458# Returns 0 if the interface exists and 1 otherwise.
459ifexists()
460{
461 [ -z "$1" ] && return 1
307 ifconfig -n $1 > /dev/null 2>&1
308}
309
310# ipv4_up if
311# add IPv4 addresses to the interface $if
312ipv4_up()
313{
462 ifconfig -n $1 > /dev/null 2>&1
463}
464
465# ipv4_up if
466# add IPv4 addresses to the interface $if
467ipv4_up()
468{
469 local _if _ret
314 _if=$1
470 _if=$1
315 ifalias_up ${_if}
316 ipv4_addrs_common ${_if} alias
471 _ret=1
472
473 ifalias_up ${_if} inet && _ret=0
474 ipv4_addrs_common ${_if} alias && _ret=0
475
476 return $_ret
317}
318
477}
478
479# ipv6_up if
480# add IPv6 addresses to the interface $if
481ipv6_up()
482{
483 local _if _ret
484 _if=$1
485 _ret=1
486
487 if ! ipv6if $_if; then
488 return 0
489 fi
490
491 ifalias_up ${_if} inet6 && _ret=0
492 ipv6_prefix_hostid_addr_up ${_if} && _ret=0
493 ipv6_accept_rtadv_up ${_if} && _ret=0
494
495 # wait for DAD
496 sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
497 sleep 1
498
499 return $_ret
500}
501
319# ipv4_down if
320# remove IPv4 addresses from the interface $if
321ipv4_down()
322{
502# ipv4_down if
503# remove IPv4 addresses from the interface $if
504ipv4_down()
505{
506 local _if _ifs _ret inetList oldifs _inet
323 _if=$1
324 _ifs="^"
325 _ret=1
326
507 _if=$1
508 _ifs="^"
509 _ret=1
510
327 ifexists ${_if} || return 1
328
329 inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
330
331 oldifs="$IFS"
332 IFS="$_ifs"
333 for _inet in $inetList ; do
334 # get rid of extraneous line
335 [ -z "$_inet" ] && break
336
337 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
338
339 IFS="$oldifs"
340 ifconfig ${_if} ${_inet} delete
341 IFS="$_ifs"
342 _ret=0
343 done
344 IFS="$oldifs"
345
511 inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
512
513 oldifs="$IFS"
514 IFS="$_ifs"
515 for _inet in $inetList ; do
516 # get rid of extraneous line
517 [ -z "$_inet" ] && break
518
519 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
520
521 IFS="$oldifs"
522 ifconfig ${_if} ${_inet} delete
523 IFS="$_ifs"
524 _ret=0
525 done
526 IFS="$oldifs"
527
346 ifalias_down ${_if} && _ret=0
528 ifalias_down ${_if} inet && _ret=0
347 ipv4_addrs_common ${_if} -alias && _ret=0
348
349 return $_ret
350}
351
529 ipv4_addrs_common ${_if} -alias && _ret=0
530
531 return $_ret
532}
533
534# ipv6_down if
535# remove IPv6 addresses from the interface $if
536ipv6_down()
537{
538 local _if _ifs _ret inetList oldifs _inet6
539 _if=$1
540 _ifs="^"
541 _ret=1
542
543 if ! ipv6if $_if; then
544 return 0
545 fi
546
547 ipv6_accept_rtadv_down ${_if} && _ret=0
548 ifalias_down ${_if} inet6 && _ret=0
549
550 inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`"
551
552 oldifs="$IFS"
553 IFS="$_ifs"
554 for _inet6 in $inetList ; do
555 # get rid of extraneous line
556 [ -z "$_inet6" ] && break
557
558 _inet6=`expr "$_inet6" : '.*\(inet6 \([0-9a-f:]*\)\).*'`
559
560 IFS="$oldifs"
561 ifconfig ${_if} ${_inet6} -alias
562 IFS="$_ifs"
563 _ret=0
564 done
565 IFS="$oldifs"
566
567 return $_ret
568}
569
352# ipv4_addrs_common if action
353# Evaluate the ifconfig_if_ipv4 arguments for interface $if
354# and use $action to add or remove IPv4 addresses from $if.
355ipv4_addrs_common()
356{
570# ipv4_addrs_common if action
571# Evaluate the ifconfig_if_ipv4 arguments for interface $if
572# and use $action to add or remove IPv4 addresses from $if.
573ipv4_addrs_common()
574{
575 local _ret _if _action _cidr _cidr_addr
576 local _ipaddr _netmask _range _ipnet _iplow _iphigh _ipcount
357 _ret=1
358 _if=$1
359 _action=$2
360
361 # get ipv4-addresses
362 cidr_addr=`get_if_var $_if ipv4_addrs_IF`
363
364 for _cidr in ${cidr_addr}; do

--- 16 unchanged lines hidden (view full) ---

381 _ret=0
382
383 # only the first ipaddr in a subnet need the real netmask
384 if [ "${_action}" != "-alias" ]; then
385 _netmask="/32"
386 fi
387 done
388 done
577 _ret=1
578 _if=$1
579 _action=$2
580
581 # get ipv4-addresses
582 cidr_addr=`get_if_var $_if ipv4_addrs_IF`
583
584 for _cidr in ${cidr_addr}; do

--- 16 unchanged lines hidden (view full) ---

601 _ret=0
602
603 # only the first ipaddr in a subnet need the real netmask
604 if [ "${_action}" != "-alias" ]; then
605 _netmask="/32"
606 fi
607 done
608 done
609
389 return $_ret
390}
391
610 return $_ret
611}
612
392# ifalias_up if
613# ifalias_up if af
393# Configure aliases for network interface $if.
394# It returns 0 if at least one alias was configured or
395# 1 if there were none.
396#
397ifalias_up()
398{
614# Configure aliases for network interface $if.
615# It returns 0 if at least one alias was configured or
616# 1 if there were none.
617#
618ifalias_up()
619{
620 local _ret
399 _ret=1
621 _ret=1
622
623 case "$2" in
624 inet)
625 _ret=`ifalias_ipv4_up "$1"`
626 ;;
627 inet6)
628 _ret=`ifalias_ipv6_up "$1"`
629 ;;
630 esac
631
632 return $_ret
633}
634
635# ifalias_ipv4_up if
636# Helper function for ifalias_up(). Handles IPv4.
637#
638ifalias_ipv4_up()
639{
640 local _ret alias ifconfig_args
641 _ret=1
642
643 # ifconfig_IF_aliasN which starts with "inet"
400 alias=0
401 while : ; do
402 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
644 alias=0
645 while : ; do
646 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
403 if [ -n "${ifconfig_args}" ]; then
404 ifconfig $1 ${ifconfig_args} alias
647 case "${ifconfig_args}" in
648 inet\ *)
649 ifconfig $1 ${ifconfig_args} alias && _ret=0
650 ;;
651 "")
652 break
653 ;;
654 esac
405 alias=$((${alias} + 1))
655 alias=$((${alias} + 1))
406 _ret=0
407 else
656 done
657
658 return $_ret
659}
660
661# ifalias_ipv6_up if
662# Helper function for ifalias_up(). Handles IPv6.
663#
664ifalias_ipv6_up()
665{
666 local _ret alias ifconfig_args
667 _ret=1
668
669 # ifconfig_IF_aliasN which starts with "inet6"
670 alias=0
671 while : ; do
672 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
673 case "${ifconfig_args}" in
674 inet6\ *)
675 ifconfig $1 ${ifconfig_args} alias && _ret=0
676 ;;
677 "")
408 break
678 break
409 fi
679 ;;
680 esac
681 alias=$((${alias} + 1))
410 done
682 done
683
684 # backward compatibility: ipv6_ifconfig_IF_aliasN.
685 alias=0
686 while : ; do
687 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
688 case "${ifconfig_args}" in
689 "")
690 break
691 ;;
692 *)
693 ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0
694 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete."
695 " Use ifconfig_$1_aliasN instead."
696 ;;
697 esac
698 alias=$((${alias} + 1))
699 done
700
411 return $_ret
412}
413
701 return $_ret
702}
703
414#ifalias_down if
704#ifalias_down if af
415# Remove aliases for network interface $if.
416# It returns 0 if at least one alias was removed or
417# 1 if there were none.
418#
419ifalias_down()
420{
705# Remove aliases for network interface $if.
706# It returns 0 if at least one alias was removed or
707# 1 if there were none.
708#
709ifalias_down()
710{
711 local _ret
421 _ret=1
712 _ret=1
713
714 case "$2" in
715 inet)
716 _ret=`ifalias_ipv4_down "$1"`
717 ;;
718 inet6)
719 _ret=`ifalias_ipv6_down "$1"`
720 ;;
721 esac
722
723 return $_ret
724}
725
726#ifalias_ipv4_down if
727# Helper function for ifalias_down(). Handles IPv4.
728#
729ifalias_ipv4_down()
730{
731 local _ret alias ifconfig_args
732 _ret=1
733
734 # ifconfig_IF_aliasN which starts with "inet"
422 alias=0
423 while : ; do
424 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
735 alias=0
736 while : ; do
737 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
425 if [ -n "${ifconfig_args}" ]; then
426 ifconfig $1 ${ifconfig_args} -alias
738 case "${ifconfig_args}" in
739 inet\ *)
740 ifconfig $1 ${ifconfig_args} -alias && _ret=0
741 ;;
742 "")
743 break
744 ;;
745 esac
427 alias=$((${alias} + 1))
746 alias=$((${alias} + 1))
428 _ret=0
429 else
747 done
748
749 return $_ret
750}
751
752#ifalias_ipv6_down if
753# Helper function for ifalias_down(). Handles IPv6.
754#
755ifalias_ipv6_down()
756{
757 local _ret alias ifconfig_args
758 _ret=1
759
760 # ifconfig_IF_aliasN which starts with "inet6"
761 alias=0
762 while : ; do
763 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
764 case "${ifconfig_args}" in
765 inet6\ *)
766 ifconfig $1 ${ifconfig_args} -alias && _ret=0
767 ;;
768 "")
430 break
769 break
431 fi
770 ;;
771 esac
772 alias=$((${alias} + 1))
432 done
773 done
774
775 # backward compatibility: ipv6_ifconfig_IF_aliasN.
776 while : ; do
777 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
778 case "${ifconfig_args}" in
779 "")
780 break
781 ;;
782 *)
783 ifconfig $1 inet6 ${ifconfig_args} -alias
784 alias=$((${alias} + 1))
785 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete."
786 " Use ifconfig_$1_aliasN instead."
787 _ret=0
788 ;;
789 esac
790 done
791
433 return $_ret
434}
435
792 return $_ret
793}
794
795# ipv6_prefix_hostid_addr_up if
796# add IPv6 prefix + hostid addr to the interface $if
797ipv6_prefix_hostid_addr_up()
798{
799 local _if prefix laddr hostid j address
800 _if=$1
801 prefix=`get_if_var ${_if} ipv6_prefix_IF`
802
803 if [ -n "${prefix}" ]; then
804 laddr=`network6_getladdr ${_if}`
805 hostid=${laddr#fe80::}
806 hostid=${hostid%\%*}
807
808 for j in ${prefix}; do
809 address=$j\:${hostid}
810 ifconfig ${_if} inet6 ${address} prefixlen 64 alias
811
812 # if I am a router, add subnet router
813 # anycast address (RFC 2373).
814 if checkyesno ipv6_gateway_enable; then
815 ifconfig ${_if} inet6 $j:: prefixlen 64 \
816 alias anycast
817 fi
818 done
819 fi
820}
821
822# ipv6_accept_rtadv_up if
823# Enable accepting Router Advertisement and send Router
824# Solicitation message
825ipv6_accept_rtadv_up()
826{
827 if ipv6_autoconfif $1; then
828 ifconfig $1 inet6 accept_rtadv up
829 rtsol ${rtsol_flags} $1
830 fi
831}
832
833# ipv6_accept_rtadv_down if
834# Disable accepting Router Advertisement
835ipv6_accept_rtadv_down()
836{
837 if ipv6_autoconfif $1; then
838 ifconfig $1 inet6 -accept_rtadv
839 fi
840}
841
436# ifscript_up if
437# Evaluate a startup script for the $if interface.
438# It returns 0 if a script was found and processed or
439# 1 if no script was found.
440#
441ifscript_up()
442{
443 if [ -r /etc/start_if.$1 ]; then
444 . /etc/start_if.$1
445 return 0
842# ifscript_up if
843# Evaluate a startup script for the $if interface.
844# It returns 0 if a script was found and processed or
845# 1 if no script was found.
846#
847ifscript_up()
848{
849 if [ -r /etc/start_if.$1 ]; then
850 . /etc/start_if.$1
851 return 0
852 else
853 return 1
446 fi
854 fi
447 return 1
448}
449
450# ifscript_down if
451# Evaluate a shutdown script for the $if interface.
452# It returns 0 if a script was found and processed or
453# 1 if no script was found.
454#
455ifscript_down()
456{
457 if [ -r /etc/stop_if.$1 ]; then
458 . /etc/stop_if.$1
459 return 0
855}
856
857# ifscript_down if
858# Evaluate a shutdown script for the $if interface.
859# It returns 0 if a script was found and processed or
860# 1 if no script was found.
861#
862ifscript_down()
863{
864 if [ -r /etc/stop_if.$1 ]; then
865 . /etc/stop_if.$1
866 return 0
867 else
868 return 1
460 fi
869 fi
461 return 1
462}
463
464# Create cloneable interfaces.
465#
466clone_up()
467{
870}
871
872# Create cloneable interfaces.
873#
874clone_up()
875{
876 local _prefix _list ifn
468 _prefix=
469 _list=
877 _prefix=
878 _list=
879
880 # create_args_IF
470 for ifn in ${cloned_interfaces}; do
471 ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF`
472 if [ $? -eq 0 ]; then
473 _list="${_list}${_prefix}${ifn}"
474 [ -z "$_prefix" ] && _prefix=' '
475 fi
476 done
477 debug "Cloned: ${_list}"
478}
479
480# Destroy cloned interfaces. Destroyed interfaces are echoed
481# to standard output.
482#
483clone_down()
484{
881 for ifn in ${cloned_interfaces}; do
882 ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF`
883 if [ $? -eq 0 ]; then
884 _list="${_list}${_prefix}${ifn}"
885 [ -z "$_prefix" ] && _prefix=' '
886 fi
887 done
888 debug "Cloned: ${_list}"
889}
890
891# Destroy cloned interfaces. Destroyed interfaces are echoed
892# to standard output.
893#
894clone_down()
895{
896 local _prefix _list ifn
485 _prefix=
486 _list=
897 _prefix=
898 _list=
899
487 for ifn in ${cloned_interfaces}; do
488 ifconfig ${ifn} destroy
489 if [ $? -eq 0 ]; then
490 _list="${_list}${_prefix}${ifn}"
491 [ -z "$_prefix" ] && _prefix=' '
492 fi
493 done
494 debug "Destroyed clones: ${_list}"
495}
496
497# Create and configure child interfaces.
498# Return 0 if child interfaces are created.
499#
500childif_create()
501{
502 local cfg child child_wlans create_args debug_flags ifn i
503 cfg=1
900 for ifn in ${cloned_interfaces}; do
901 ifconfig ${ifn} destroy
902 if [ $? -eq 0 ]; then
903 _list="${_list}${_prefix}${ifn}"
904 [ -z "$_prefix" ] && _prefix=' '
905 fi
906 done
907 debug "Destroyed clones: ${_list}"
908}
909
910# Create and configure child interfaces.
911# Return 0 if child interfaces are created.
912#
913childif_create()
914{
915 local cfg child child_wlans create_args debug_flags ifn i
916 cfg=1
504
505 ifn=$1
506
507 # Create wireless interfaces
508 child_wlans=`get_if_var $ifn wlans_IF`
509
510 for child in ${child_wlans}; do
511 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
512 debug_flags="`get_if_var $child wlandebug_IF`"

--- 18 unchanged lines hidden (view full) ---

531 return ${cfg}
532}
533
534# Destroy child interfaces.
535#
536childif_destroy()
537{
538 local cfg child child_wlans ifn
917 ifn=$1
918
919 # Create wireless interfaces
920 child_wlans=`get_if_var $ifn wlans_IF`
921
922 for child in ${child_wlans}; do
923 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
924 debug_flags="`get_if_var $child wlandebug_IF`"

--- 18 unchanged lines hidden (view full) ---

943 return ${cfg}
944}
945
946# Destroy child interfaces.
947#
948childif_destroy()
949{
950 local cfg child child_wlans ifn
951 cfg=1
539
540 child_wlans="`get_if_var $ifn wlans_IF` `get_if_var $ifn vaps_IF`"
541 for child in ${child_wlans}; do
542 ifconfig $child destroy && cfg=0
543 done
952
953 child_wlans="`get_if_var $ifn wlans_IF` `get_if_var $ifn vaps_IF`"
954 for child in ${child_wlans}; do
955 ifconfig $child destroy && cfg=0
956 done
957
958 return ${cfg}
544}
545
546# Create netgraph nodes.
547#
548ng_mkpeer() {
549 ngctl -f - 2> /dev/null <<EOF
550mkpeer $*
551msg dummy nodeinfo
552EOF
553}
554
555ng_create_one() {
959}
960
961# Create netgraph nodes.
962#
963ng_mkpeer() {
964 ngctl -f - 2> /dev/null <<EOF
965mkpeer $*
966msg dummy nodeinfo
967EOF
968}
969
970ng_create_one() {
971 local t
972
556 ng_mkpeer $* | while read line; do
557 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
558 if [ -n "${t}" ]; then
559 echo ${t}
560 return
561 fi
562 done
563}
564
565gif_up() {
973 ng_mkpeer $* | while read line; do
974 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
975 if [ -n "${t}" ]; then
976 echo ${t}
977 return
978 fi
979 done
980}
981
982gif_up() {
983 local i peers
984
566 for i in ${gif_interfaces}; do
567 peers=`get_if_var $i gifconfig_IF`
568 case ${peers} in
569 '')
570 continue
571 ;;
572 *)
573 if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then

--- 7 unchanged lines hidden (view full) ---

581 ;;
582 esac
583 done
584}
585
586# ng_fec_create ifn
587# Configure Fast EtherChannel for interface $ifn. Returns 0 if FEC
588# arguments were found and configured; returns !0 otherwise.
985 for i in ${gif_interfaces}; do
986 peers=`get_if_var $i gifconfig_IF`
987 case ${peers} in
988 '')
989 continue
990 ;;
991 *)
992 if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then

--- 7 unchanged lines hidden (view full) ---

1000 ;;
1001 esac
1002 done
1003}
1004
1005# ng_fec_create ifn
1006# Configure Fast EtherChannel for interface $ifn. Returns 0 if FEC
1007# arguments were found and configured; returns !0 otherwise.
589ng_fec_create() {
1008ng_fec_create()
1009{
590 local req_iface iface bogus
591 req_iface="$1"
592
593 ngctl shutdown ${req_iface}: > /dev/null 2>&1
594
595 bogus=""
596 while true; do
597 iface=`ng_create_one fec dummy fec`

--- 7 unchanged lines hidden (view full) ---

605 done
606
607 for iface in ${bogus}; do
608 ngctl shutdown ${iface}:
609 done
610}
611
612fec_up() {
1010 local req_iface iface bogus
1011 req_iface="$1"
1012
1013 ngctl shutdown ${req_iface}: > /dev/null 2>&1
1014
1015 bogus=""
1016 while true; do
1017 iface=`ng_create_one fec dummy fec`

--- 7 unchanged lines hidden (view full) ---

1025 done
1026
1027 for iface in ${bogus}; do
1028 ngctl shutdown ${iface}:
1029 done
1030}
1031
1032fec_up() {
1033 local i j
1034
613 for i in ${fec_interfaces}; do
614 ng_fec_create $i
615 for j in `get_if_var $i fecconfig_IF`; do
616 case ${j} in
617 '')
618 continue
619 ;;
620 *)

--- 6 unchanged lines hidden (view full) ---

627
628#
629# ipx_up ifn
630# Configure any IPX addresses for interface $ifn. Returns 0 if IPX
631# arguments were found and configured; returns 1 otherwise.
632#
633ipx_up()
634{
1035 for i in ${fec_interfaces}; do
1036 ng_fec_create $i
1037 for j in `get_if_var $i fecconfig_IF`; do
1038 case ${j} in
1039 '')
1040 continue
1041 ;;
1042 *)

--- 6 unchanged lines hidden (view full) ---

1049
1050#
1051# ipx_up ifn
1052# Configure any IPX addresses for interface $ifn. Returns 0 if IPX
1053# arguments were found and configured; returns 1 otherwise.
1054#
1055ipx_up()
1056{
1057 local ifn
635 ifn="$1"
1058 ifn="$1"
636 ifconfig_args=`get_if_var $ifn ifconfig_IF_ipx`
1059
1060 # ifconfig_IF_ipx
1061 ifconfig_args=`_ifconfig_getargs $ifn ipx`
637 if [ -n "${ifconfig_args}" ]; then
638 ifconfig ${ifn} ${ifconfig_args}
639 return 0
640 fi
1062 if [ -n "${ifconfig_args}" ]; then
1063 ifconfig ${ifn} ${ifconfig_args}
1064 return 0
1065 fi
1066
641 return 1
642}
643
644# ipx_down ifn
645# Remove IPX addresses for interface $ifn. Returns 0 if IPX
646# addresses were found and unconfigured. It returns 1, otherwise.
647#
648ipx_down()
649{
1067 return 1
1068}
1069
1070# ipx_down ifn
1071# Remove IPX addresses for interface $ifn. Returns 0 if IPX
1072# addresses were found and unconfigured. It returns 1, otherwise.
1073#
1074ipx_down()
1075{
650 [ -z "$1" ] && return 1
1076 local _if _ifs _ret ipxList oldifs _ipx
1077 _if=$1
651 _ifs="^"
652 _ret=1
1078 _ifs="^"
1079 _ret=1
653
654 ifexists $1 || return 1
655
656 ipxList="`ifconfig $1 | grep 'ipx ' | tr "\n" "$_ifs"`"
657
1080 ipxList="`ifconfig ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`"
658 oldifs="$IFS"
1081 oldifs="$IFS"
1082
659 IFS="$_ifs"
660 for _ipx in $ipxList ; do
661 # get rid of extraneous line
662 [ -z "$_ipx" ] && break
663
664 _ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'`
665
666 IFS="$oldifs"
1083 IFS="$_ifs"
1084 for _ipx in $ipxList ; do
1085 # get rid of extraneous line
1086 [ -z "$_ipx" ] && break
1087
1088 _ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'`
1089
1090 IFS="$oldifs"
667 ifconfig $1 ${_ipx} delete
1091 ifconfig ${_if} ${_ipx} delete
668 IFS="$_ifs"
669 _ret=0
670 done
671 IFS="$oldifs"
672
673 return $_ret
674}
675
676# ifnet_rename
677# Rename all requested interfaces.
678#
679ifnet_rename()
680{
1092 IFS="$_ifs"
1093 _ret=0
1094 done
1095 IFS="$oldifs"
1096
1097 return $_ret
1098}
1099
1100# ifnet_rename
1101# Rename all requested interfaces.
1102#
1103ifnet_rename()
1104{
1105 local _if _ifname
681
1106
682 _ifn_list="`ifconfig -l`"
683 [ -z "$_ifn_list" ] && return 0
684 for _if in ${_ifn_list} ; do
1107 # ifconfig_IF_name
1108 for _if in `ifconfig -l`; do
685 _ifname=`get_if_var $_if ifconfig_IF_name`
686 if [ ! -z "$_ifname" ]; then
687 ifconfig $_if name $_ifname
688 fi
689 done
1109 _ifname=`get_if_var $_if ifconfig_IF_name`
1110 if [ ! -z "$_ifname" ]; then
1111 ifconfig $_if name $_ifname
1112 fi
1113 done
1114
690 return 0
691}
692
1115 return 0
1116}
1117
693#
694# list_net_interfaces type
695# List all network interfaces. The type of interface returned
696# can be controlled by the type argument. The type
697# argument can be any of the following:
698# nodhcp - all interfaces, excluding DHCP configured interfaces
699# dhcp - list only DHCP configured interfaces
1118# list_net_interfaces type
1119# List all network interfaces. The type of interface returned
1120# can be controlled by the type argument. The type
1121# argument can be any of the following:
1122# nodhcp - all interfaces, excluding DHCP configured interfaces
1123# dhcp - list only DHCP configured interfaces
1124# noautoconf - all interfaces, excluding IPv6 Stateless
1125# Address Autoconf configured interfaces
1126# autoconf - list only IPv6 Stateless Address Autoconf
1127# configured interfaces
700# If no argument is specified all network interfaces are output.
701# Note that the list will include cloned interfaces if applicable.
702# Cloned interfaces must already exist to have a chance to appear
703# in the list if ${network_interfaces} is set to `auto'.
704#
705list_net_interfaces()
706{
1128# If no argument is specified all network interfaces are output.
1129# Note that the list will include cloned interfaces if applicable.
1130# Cloned interfaces must already exist to have a chance to appear
1131# in the list if ${network_interfaces} is set to `auto'.
1132#
1133list_net_interfaces()
1134{
1135 local type _tmplist _list _autolist _lo _if
707 type=$1
708
709 # Get a list of ALL the interfaces and make lo0 first if it's there.
710 #
1136 type=$1
1137
1138 # Get a list of ALL the interfaces and make lo0 first if it's there.
1139 #
1140 _tmplist=
711 case ${network_interfaces} in
712 [Aa][Uu][Tt][Oo])
1141 case ${network_interfaces} in
1142 [Aa][Uu][Tt][Oo])
713 _prefix=''
714 _autolist="`ifconfig -l`"
715 _lo=
716 for _if in ${_autolist} ; do
717 if autoif $_if; then
718 if [ "$_if" = "lo0" ]; then
719 _lo="lo0 "
720 else
1143 _autolist="`ifconfig -l`"
1144 _lo=
1145 for _if in ${_autolist} ; do
1146 if autoif $_if; then
1147 if [ "$_if" = "lo0" ]; then
1148 _lo="lo0 "
1149 else
721 _tmplist="${_tmplist}${_prefix}${_if}"
722 [ -z "$_prefix" ] && _prefix=' '
1150 _tmplist="${_tmplist} ${_if}"
723 fi
724 fi
725 done
1151 fi
1152 fi
1153 done
726 _tmplist="${_lo}${_tmplist}"
1154 _tmplist="${_lo}${_tmplist# }"
727 ;;
728 *)
729 _tmplist="${network_interfaces} ${cloned_interfaces}"
730
731 # lo0 is effectively mandatory, so help prevent foot-shooting
732 #
733 case "$_tmplist" in
734 lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
735 *) _tmplist="lo0 ${_tmplist}" ;;
736 esac
737 ;;
738 esac
739
1155 ;;
1156 *)
1157 _tmplist="${network_interfaces} ${cloned_interfaces}"
1158
1159 # lo0 is effectively mandatory, so help prevent foot-shooting
1160 #
1161 case "$_tmplist" in
1162 lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
1163 *) _tmplist="lo0 ${_tmplist}" ;;
1164 esac
1165 ;;
1166 esac
1167
740 if [ -z "$type" ]; then
741 echo $_tmplist
742 return 0
1168 _list=
1169 case "$type" in
1170 nodhcp)
1171 for _if in ${_tmplist} ; do
1172 if ! dhcpif $_if && \
1173 [ -n "`_ifconfig_getargs $_if`" ]; then
1174 _list="${_list# } ${_if}"
743 fi
1175 fi
744
745 # Separate out dhcp and non-dhcp interfaces
746 #
747 _aprefix=
748 _bprefix=
1176 done
1177 ;;
1178 dhcp)
749 for _if in ${_tmplist} ; do
750 if dhcpif $_if; then
1179 for _if in ${_tmplist} ; do
1180 if dhcpif $_if; then
751 _dhcplist="${_dhcplist}${_aprefix}${_if}"
752 [ -z "$_aprefix" ] && _aprefix=' '
753 elif [ -n "`_ifconfig_getargs $_if`" ]; then
754 _nodhcplist="${_nodhcplist}${_bprefix}${_if}"
755 [ -z "$_bprefix" ] && _bprefix=' '
1181 _list="${_list# } ${_if}"
756 fi
757 done
1182 fi
1183 done
758
759 case "$type" in
760 nodhcp)
761 echo $_nodhcplist
762 ;;
1184 ;;
763 dhcp)
764 echo $_dhcplist
1185 noautoconf)
1186 for _if in ${_tmplist} ; do
1187 if ! ipv6_autoconfif $_if && \
1188 [ -n "`_ifconfig_getargs $_if ipv6`" ]; then
1189 _list="${_list# } ${_if}"
1190 fi
1191 done
765 ;;
1192 ;;
1193 autoconf)
1194 for _if in ${_tmplist} ; do
1195 if ipv6_autoconfif $_if; then
1196 _list="${_list# } ${_if}"
1197 fi
1198 done
1199 ;;
1200 *)
1201 _list=${_tmplist}
1202 ;;
766 esac
1203 esac
1204
1205 echo $_list
1206
767 return 0
768}
769
770# get_default_if -address_family
771# Get the interface of the default route for the given address family.
772# The -address_family argument must be suitable passing to route(8).
773#
774get_default_if()
775{
1207 return 0
1208}
1209
1210# get_default_if -address_family
1211# Get the interface of the default route for the given address family.
1212# The -address_family argument must be suitable passing to route(8).
1213#
1214get_default_if()
1215{
776 routeget="`route -n get $1 default 2>/dev/null`"
1216 local routeget oldifs defif line
1217 defif=
777 oldifs="$IFS"
778 IFS="
779"
1218 oldifs="$IFS"
1219 IFS="
1220"
780 defif=
781 for line in $routeget ; do
1221 for line in `route -n get $1 default 2>/dev/null`; do
782 case $line in
783 *interface:*)
784 defif=${line##*: }
785 ;;
786 esac
787 done
788 IFS=${oldifs}
789

--- 13 unchanged lines hidden (view full) ---

803 14) echo e ;;
804 15) echo f ;;
805 esac
806 fi
807}
808
809hexprint()
810{
1222 case $line in
1223 *interface:*)
1224 defif=${line##*: }
1225 ;;
1226 esac
1227 done
1228 IFS=${oldifs}
1229

--- 13 unchanged lines hidden (view full) ---

1243 14) echo e ;;
1244 15) echo f ;;
1245 esac
1246 fi
1247}
1248
1249hexprint()
1250{
1251 local val str dig
811 val=$1
812 str=''
1252 val=$1
1253 str=''
813
814 dig=`hexdigit $((${val} & 15))`
815 str=${dig}${str}
816 val=$((${val} >> 4))
1254 dig=`hexdigit $((${val} & 15))`
1255 str=${dig}${str}
1256 val=$((${val} >> 4))
1257
817 while [ ${val} -gt 0 ]; do
818 dig=`hexdigit $((${val} & 15))`
819 str=${dig}${str}
820 val=$((${val} >> 4))
821 done
822
823 echo ${str}
824}

--- 4 unchanged lines hidden (view full) ---

829
830 case `ifconfig $1 2>/dev/null` in
831 *media:?Ethernet*) media=Ethernet ;;
832 esac
833
834 test "$media" = "Ethernet"
835}
836
1258 while [ ${val} -gt 0 ]; do
1259 dig=`hexdigit $((${val} & 15))`
1260 str=${dig}${str}
1261 val=$((${val} >> 4))
1262 done
1263
1264 echo ${str}
1265}

--- 4 unchanged lines hidden (view full) ---

1270
1271 case `ifconfig $1 2>/dev/null` in
1272 *media:?Ethernet*) media=Ethernet ;;
1273 esac
1274
1275 test "$media" = "Ethernet"
1276}
1277
837# Setup the interfaces for IPv6
838network6_interface_setup()
839{
840 interfaces=$*
841 rtsol_interfaces=''
842 case ${ipv6_gateway_enable} in
843 [Yy][Ee][Ss])
844 rtsol_available=no
845 ;;
846 *)
847 rtsol_available=yes
848 ;;
849 esac
850 for i in $interfaces; do
851 rtsol_interface=yes
852 prefix=`get_if_var $i ipv6_prefix_IF`
853 if [ -n "${prefix}" ]; then
854 rtsol_available=no
855 rtsol_interface=no
856 laddr=`network6_getladdr $i`
857 hostid=`expr "${laddr}" : 'fe80::\(.*\)%\(.*\)'`
858 for j in ${prefix}; do
859 address=$j\:${hostid}
860 ifconfig $i inet6 ${address} prefixlen 64 alias
861
862 case ${ipv6_gateway_enable} in
863 [Yy][Ee][Ss])
864 # subnet-router anycast address
865 # (rfc2373)
866 ifconfig $i inet6 $j:: prefixlen 64 \
867 alias anycast
868 ;;
869 esac
870 done
871 fi
872 ipv6_ifconfig=`get_if_var $i ipv6_ifconfig_IF`
873 if [ -n "${ipv6_ifconfig}" ]; then
874 rtsol_available=no
875 rtsol_interface=no
876 ifconfig $i inet6 ${ipv6_ifconfig} alias
877 fi
878
879 # Wireless NIC cards are virtualized through the wlan interface
880 if ! is_wired_interface ${i}; then
881 case "${i}" in
882 wlan*) rtsol_interface=yes ;;
883 *) rtsol_interface=no ;;
884 esac
885 fi
886
887 if [ ${rtsol_available} = yes -a ${rtsol_interface} = yes ]
888 then
889 case ${i} in
890 lo0|gif[0-9]*|stf[0-9]*|faith[0-9]*|lp[0-9]*|sl[0-9]*|tun[0-9]*|pflog[0-9]*|pfsync[0-9]*)
891 ;;
892 *)
893 rtsol_interfaces="${rtsol_interfaces} ${i}"
894 ;;
895 esac
896 else
897 ifconfig $i inet6
898 fi
899 done
900
901 if [ ${rtsol_available} = yes -a -n "${rtsol_interfaces}" ]; then
902 # Act as endhost - automatically configured.
903 # You can configure only single interface, as
904 # specification assumes that autoconfigured host has
905 # single interface only.
906 sysctl net.inet6.ip6.accept_rtadv=1
907 set ${rtsol_interfaces}
908 ifconfig $1 up
909 rtsol ${rtsol_flags} $1
910 fi
911
912 for i in $interfaces; do
913 alias=0
914 while : ; do
915 ipv6_ifconfig=`get_if_var $i ipv6_ifconfig_IF_alias${alias}`
916 if [ -z "${ipv6_ifconfig}" ]; then
917 break;
918 fi
919 ifconfig $i inet6 ${ipv6_ifconfig} alias
920 alias=$((${alias} + 1))
921 done
922 done
923}
924
925# Setup IPv6 to IPv4 mapping
926network6_stf_setup()
927{
928 case ${stf_interface_ipv4addr} in
929 [Nn][Oo] | '')
930 ;;
931 *)
932 # assign IPv6 addr and interface route for 6to4 interface
933 stf_prefixlen=$((16+${stf_interface_ipv4plen:-0}))
934 OIFS="$IFS"
935 IFS=".$IFS"
936 set ${stf_interface_ipv4addr}
937 IFS="$OIFS"
938 hexfrag1=`hexprint $(($1*256 + $2))`
939 hexfrag2=`hexprint $(($3*256 + $4))`
940 ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
941 case ${stf_interface_ipv6_ifid} in
942 [Aa][Uu][Tt][Oo] | '')
943 for i in ${ipv6_network_interfaces}; do
944 laddr=`network6_getladdr ${i}`
945 case ${laddr} in
946 '')
947 ;;
948 *)
949 break
950 ;;
951 esac
952 done
953 stf_interface_ipv6_ifid=`expr "${laddr}" : \
954 'fe80::\(.*\)%\(.*\)'`
955 case ${stf_interface_ipv6_ifid} in
956 '')
957 stf_interface_ipv6_ifid=0:0:0:1
958 ;;
959 esac
960 ;;
961 esac
962 ifconfig stf0 create >/dev/null 2>&1
963 ifconfig stf0 inet6 2002:${ipv4_in_hexformat}:${stf_interface_ipv6_slaid:-0}:${stf_interface_ipv6_ifid} \
964 prefixlen ${stf_prefixlen}
965 # disallow packets to malicious 6to4 prefix
966 route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
967 route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
968 route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
969 route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
970 ;;
971 esac
972}
973
974# Setup static routes
975network6_static_routes_setup()
976{
977 # Set up any static routes.
978 case ${ipv6_defaultrouter} in
979 [Nn][Oo] | '')
980 ;;
981 *)
982 ipv6_static_routes="default ${ipv6_static_routes}"
983 ipv6_route_default="default ${ipv6_defaultrouter}"
984 ;;
985 esac
986 case ${ipv6_static_routes} in
987 [Nn][Oo] | '')
988 ;;
989 *)
990 for i in ${ipv6_static_routes}; do
991 ipv6_route_args=`get_if_var $i ipv6_route_IF`
992 route add -inet6 ${ipv6_route_args}
993 done
994 ;;
995 esac
996}
997
998# Setup faith
999network6_faith_setup()
1000{
1001 case ${ipv6_faith_prefix} in
1002 [Nn][Oo] | '')
1003 ;;
1004 *)
1005 sysctl net.inet6.ip6.keepfaith=1
1006 ifconfig faith0 create >/dev/null 2>&1
1007 ifconfig faith0 up
1008 for prefix in ${ipv6_faith_prefix}; do
1009 prefixlen=`expr "${prefix}" : ".*/\(.*\)"`
1010 case ${prefixlen} in
1011 '')
1012 prefixlen=96
1013 ;;
1014 *)
1015 prefix=`expr "${prefix}" : \
1016 "\(.*\)/${prefixlen}"`
1017 ;;
1018 esac
1019 route add -inet6 ${prefix} -prefixlen ${prefixlen} ::1
1020 route change -inet6 ${prefix} -prefixlen ${prefixlen} \
1021 -ifp faith0
1022 done
1023 ;;
1024 esac
1025}
1026
1027# Install the "default interface" to kernel, which will be used
1028# as the default route when there's no router.
1029network6_default_interface_setup()
1030{
1031 # Choose IPv6 default interface if it is not clearly specified.
1032 case ${ipv6_default_interface} in
1033 '')
1034 for i in ${ipv6_network_interfaces}; do
1035 case $i in
1036 lo0|faith[0-9]*)
1037 continue
1038 ;;
1039 esac
1040 laddr=`network6_getladdr $i exclude_tentative`
1041 case ${laddr} in
1042 '')
1043 ;;
1044 *)
1045 ipv6_default_interface=$i
1046 break
1047 ;;
1048 esac
1049 done
1050 ;;
1051 esac
1052
1053 # Disallow unicast packets without outgoing scope identifiers,
1054 # or route such packets to a "default" interface, if it is specified.
1055 route add -inet6 fe80:: -prefixlen 10 ::1 -reject
1056 case ${ipv6_default_interface} in
1057 [Nn][Oo] | '')
1058 route add -inet6 ff02:: -prefixlen 16 ::1 -reject
1059 ;;
1060 *)
1061 laddr=`network6_getladdr ${ipv6_default_interface}`
1062 route add -inet6 ff02:: ${laddr} -prefixlen 16 -interface \
1063 -cloning
1064
1065 # Disable installing the default interface with the
1066 # case net.inet6.ip6.forwarding=0 and
1067 # net.inet6.ip6.accept_rtadv=0, due to avoid conflict
1068 # between the default router list and the manual
1069 # configured default route.
1070 case ${ipv6_gateway_enable} in
1071 [Yy][Ee][Ss])
1072 ;;
1073 *)
1074 if [ `sysctl -n net.inet6.ip6.accept_rtadv` -eq 1 ]
1075 then
1076 ndp -I ${ipv6_default_interface}
1077 fi
1078 ;;
1079 esac
1080 ;;
1081 esac
1082}
1083
1084network6_getladdr()
1085{
1278network6_getladdr()
1279{
1280 local proto addr rest
1086 ifconfig $1 2>/dev/null | while read proto addr rest; do
1087 case ${proto} in
1088 inet6)
1089 case ${addr} in
1090 fe80::*)
1091 if [ -z "$2" ]; then
1092 echo ${addr}
1093 return

--- 13 unchanged lines hidden ---
1281 ifconfig $1 2>/dev/null | while read proto addr rest; do
1282 case ${proto} in
1283 inet6)
1284 case ${addr} in
1285 fe80::*)
1286 if [ -z "$2" ]; then
1287 echo ${addr}
1288 return

--- 13 unchanged lines hidden ---