network.subr: Properly bring up/down interfaces
[dragonfly.git] / etc / network.subr
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.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 #    notice, this list of conditions and the following disclaimer in the
11 #    documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
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: src/etc/network.subr,v 1.163 2005/06/30 04:52:47 brooks Exp $
26 #
27
28 #
29 # Subroutines commonly used from network startup scripts.
30 # Requires that /etc/rc.subr be loaded first.
31 #
32
33 # ifconfig_up if
34 #       Evaluate ifconfig(8) arguments for interface $if and
35 #       run ifconfig(8) with those arguments. It returns 0 if
36 #       arguments were found and executed or 1 if the interface
37 #       had no arguments.  Pseudo arguments DHCP and WPA are handled
38 #       here.
39 #
40 ifconfig_up()
41 {
42         local _cfg ifconfig_args
43         _cfg=1
44
45         ifconfig_args=`ifconfig_getargs $1`
46         if [ -n "${ifconfig_args}" ]; then
47                 ifconfig $1 ${ifconfig_args}
48                 ifconfig $1 up
49                 _cfg=0
50         fi
51
52         if wpaif $1; then
53                 ifconfig $1 up
54                 /etc/rc.d/wpa_supplicant start $1
55                 _cfg=0          # XXX: not sure this should count
56         fi
57
58         if dhcpif $1; then
59                 /etc/rc.d/dhcp_client start $1
60                 _cfg=0
61         fi
62
63         return $_cfg
64 }
65
66 # ifconfig_down if
67 #       Remove all inet entries from the $if interface. It returns
68 #       0 if inet entries were found and removed. It returns 1 if
69 #       no entries were found or they could not be removed.
70 #
71 ifconfig_down()
72 {
73         local _cfg _ifs oldifs _inet inetList
74
75         [ -z "$1" ] && return 1
76         _ifs="^"
77         _cfg=1
78
79         inetList="`ifconfig $1 | grep 'inet ' | tr "\n" "$_ifs"`"
80
81         oldifs="$IFS"
82         IFS="$_ifs"
83         for _inet in $inetList ; do
84                 # get rid of extraneous line
85                 [ -z "$_inet" ] && break
86
87                 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
88
89                 IFS="$oldifs"
90                 ifconfig $1 ${_inet} delete
91                 IFS="$_ifs"
92                 _cfg=0
93         done
94         IFS="$oldifs"
95
96         if wpaif $1; then
97                 /etc/rc.d/wpa_supplicant stop $1
98         fi
99
100         if dhcpif $1; then
101                 /etc/rc.d/dhcp_client stop $1
102                 _cfg=0
103         fi
104
105         if ifexists $1; then
106                 ifconfig $1 down
107                 _cfg=0
108         fi
109
110         return $_cfg
111 }
112
113 # get_if_var if var [default]
114 #       Return the value of the pseudo-hash corresponding to $if where
115 #       $var is a string containg the sub-string "IF" which will be
116 #       replaced with $if after the characters defined in _punct are
117 #       replaced with '_'. If the variable is unset, replace it with
118 #       $default if given.
119 #
120 get_if_var()
121 {
122         local _if _punct_c _punct _var _default prefix suffix
123
124         if [ $# -ne 2 -a $# -ne 3 ]; then
125                 err 3 'USAGE: get_if_var name var [default]'
126         fi
127
128         _if=$1
129         _punct=". - / +"
130         for _punct_c in $_punct; do
131                 _if=`ltr ${_if} ${_punct_c} '_'`
132         done
133         _var=$2
134         _default=$3
135
136         prefix=${_var%%IF*}
137         suffix=${_var##*IF}
138         eval echo \${${prefix}${_if}${suffix}-${_default}}
139 }
140
141 # _ifconfig_getargs if [af]
142 #       Echos the arguments for the supplied interface to stdout.
143 #       Returns 1 if no interface is specified.
144 #       In general, the ifconfig_getargs() below should be used outside
145 #       this file.
146 #
147 _ifconfig_getargs()
148 {
149         local _if _ifn _af _args
150
151         _ifn=$1
152         _af=${2:+${2}_}
153
154         if [ -z "$_ifn" ]; then
155                 return 1
156         fi
157
158         _args=`get_if_var $_ifn ${_af}ifconfig_IF`
159         if [ -z "$_args" -a -n "${pccard_ifconfig}" ]; then
160                 for _if in ${removable_interfaces} ; do
161                         if [ "$_if" = "$_ifn" ] ; then
162                                 _args=${pccard_ifconfig}
163                                 break
164                         fi
165                 done
166         fi
167
168         echo $_args
169 }
170
171 # ifconfig_getargs if [af]
172 #       Takes the result from _ifconfig_getargs() and removes pseudo
173 #       args such as DHCP and WPA.
174 #
175 ifconfig_getargs()
176 {
177         local _tmpargs _arg _args is_optarg
178
179         _tmpargs=`_ifconfig_getargs $1 $2`
180         if [ $? -eq 1 ]; then
181                 return 1
182         fi
183         _args=
184
185         is_optarg=no
186         for _arg in $_tmpargs; do
187                 if [ "$is_optarg" = "no" ]; then
188                         case $_arg in
189                         [Dd][Hh][Cc][Pp])
190                                 ;;
191                         [Ww][Pp][Aa])
192                                 ;;
193                         *)
194                                 _args="$_args $_arg"
195                                 case $_arg in
196                                 authmode)
197                                         is_optarg=yes
198                                         ;;
199                                 esac
200                                 ;;
201                         esac
202                 else
203                         _args="$_args $_arg"
204                         is_optarg=no
205                 fi
206         done
207
208         echo $_args
209 }
210
211 # ipv6if if
212 #       Returns 0 if the interface should be configured for IPv6 and
213 #       1 otherwise.
214 #
215 ipv6if()
216 {
217         local _if _tmpargs
218         _if=$1
219
220         # lo0 is always IPv6-enabled
221         if [ "$_if" = "lo0" ]; then
222                 return 0
223         fi
224
225         case ${ipv6_enable} in
226         [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
227                 return 1
228                 ;;
229         esac
230
231         case "${ipv6_network_interfaces}" in
232         $_if|"$_if "*|*" $_if"|*" $_if "*|[Aa][Uu][Tt][Oo])
233                 # True if $ipv6_ifconfig_IF is defined.
234                 _tmpargs=`_ifconfig_getargs $_if ipv6`
235                 if [ -n "${_tmpargs}" ]; then
236                         return 0
237                 fi
238
239                 # True if $ipv6_prefix_IF is defined.
240                 _tmpargs=`get_if_var $_if ipv6_prefix_IF`
241                 if [ -n "${_tmpargs}" ]; then
242                         return 0
243                 fi
244
245                 ;;
246         esac
247
248         return 1
249 }
250
251 # dhcpif if [ipv4|ipv6]
252 #       Returns 0 if the interface needs DHCP for IPv4/IPv6 and 1 otherwise.
253 #       If the second argument is "ipv4" (or "ipv6"), then only IPv4 (or
254 #       IPv6) is checked, otherwise both are checked.
255 #
256 dhcpif()
257 {
258         local _tmpargs _arg _if _af
259         _if=$1
260         _af=$2
261
262         if [ -z "$_af" -o "$_af" = "ipv4" ]; then
263                 _tmpargs=`_ifconfig_getargs $_if`
264                 for _arg in $_tmpargs; do
265                         case $_arg in
266                         [Dd][Hh][Cc][Pp])
267                                 return 0
268                                 ;;
269                         esac
270                 done
271         fi
272
273         if [ -z "$_af" -o "$_af" = "ipv6" ] && ipv6if $_if; then
274                 _tmpargs=`_ifconfig_getargs $_if ipv6`
275                 for _arg in $_tmpargs; do
276                         case $_arg in
277                         [Dd][Hh][Cc][Pp])
278                                 return 0
279                                 ;;
280                         esac
281                 done
282         fi
283
284         return 1
285 }
286
287 # wpaif if
288 #       Returns 0 if the interface is a WPA interface and 1 otherwise.
289 #
290 wpaif()
291 {
292         local _tmpargs _arg is_optarg
293
294         _tmpargs=`_ifconfig_getargs $1`
295         is_optarg=no
296         for _arg in $_tmpargs; do
297                 if [ "$is_optarg" = "no" ]; then
298                         case $_arg in
299                         [Ww][Pp][Aa])
300                                 return 0
301                                 ;;
302                         authmode)
303                                 is_optarg=yes
304                                 ;;
305                         esac
306                 else
307                         is_optarg=no
308                 fi
309         done
310
311         return 1
312 }
313
314 # ifexists if
315 #       Returns 0 if the interface exists and 1 otherwise.
316 #
317 ifexists()
318 {
319         [ -z "$1" ] && return 1
320         ifconfig -n $1 >/dev/null 2>&1
321 }
322
323 # ifalias_common if action [ipv6]
324 #       Helper function for ifalias_up() and ifalias_down().
325 #       The $action argument can be either "alias" (to add an
326 #       alias) or "-alias" (to remove an alias).
327 #       Returns 0 if at least one alias was added/removed or
328 #       1 if there were none.
329 #
330 ifalias_common()
331 {
332         local _if _action _af _af2 _ret _var _args _alias
333         _if=$1
334         _action=$2
335         _af=$3
336
337         _ret=1
338         _alias=0
339         while : ; do
340                 if [ "${_af}" = "ipv6" ]; then
341                         _af2="inet6"
342                         _var="ipv6_ifconfig_IF_alias${_alias}"
343                 else
344                         _af2="inet"
345                         _var="ifconfig_IF_alias${_alias}"
346                 fi
347                 _args=`get_if_var $_if $_var`
348                 _args="${_args#${_af2} }"
349                 if [ -z "${_args}" ]; then
350                         break
351                 fi
352                 ifconfig $_if $_af2 $_args $_action
353                 _alias=$((${_alias} + 1))
354                 _ret=0
355         done
356         return $_ret
357 }
358
359 # ifalias_up if [ipv6]
360 #       Configure IPv4 aliases for network interface $if or
361 #       IPv6 aliases if the second argument is "ipv6".
362 #       It returns 0 if at least one alias was configured or
363 #       1 if there were none.
364 #
365 ifalias_up()
366 {
367         ifalias_common $1 alias $2
368 }
369
370 # ifalias_down if [ipv6]
371 #       Remove IPv4 aliases for network interface $if or
372 #       IPv6 aliases if the second argument is "ipv6".
373 #       It returns 0 if at least one alias was removed or
374 #       1 if there were none.
375 #
376 ifalias_down()
377 {
378         ifalias_common $1 -alias $2
379 }
380
381 # ifscript_up if
382 #       Evaluate a startup script for the $if interface.
383 #       It returns 0 if a script was found and processed or
384 #       1 if no script was found.
385 #
386 ifscript_up()
387 {
388         if [ -r /etc/start_if.$1 ]; then
389                 . /etc/start_if.$1
390                 return 0
391         fi
392         return 1
393 }
394
395 # ifscript_down if
396 #       Evaluate a shutdown script for the $if interface.
397 #       It returns 0 if a script was found and processed or
398 #       1 if no script was found.
399 #
400 ifscript_down()
401 {
402         if [ -r /etc/stop_if.$1 ]; then
403                 . /etc/stop_if.$1
404                 return 0
405         fi
406         return 1
407 }
408
409 # clone_up
410 #       Create cloneable interfaces.
411 #
412 clone_up()
413 {
414         local _prefix _list ifn
415         _prefix=
416         _list=
417
418         for ifn in ${cloned_interfaces}; do
419                 ifconfig ${ifn} create
420                 if [ $? -eq 0 ]; then
421                         _list="${_list}${_prefix}${ifn}"
422                         [ -z "$_prefix" ] && _prefix=' '
423                 fi
424         done
425         if [ -n "${_list}" ]; then
426                 echo "Created clone interfaces: ${_list}"
427         fi
428         debug "Created clone interfaces: ${_list}"
429 }
430
431 # clone_down
432 #       Destroy cloned interfaces.
433 #
434 clone_down()
435 {
436         local _prefix _list ifn
437         _prefix=
438         _list=
439
440         for ifn in ${cloned_interfaces}; do
441                 ifconfig ${ifn} destroy
442                 if [ $? -eq 0 ]; then
443                         _list="${_list}${_prefix}${ifn}"
444                         [ -z "$_prefix" ] && _prefix=' '
445                 fi
446         done
447         if [ -n "${_list}" ]; then
448                 echo "Destroyed clone interfaces: ${_list}"
449         fi
450         debug "Destroyed clone interfaces: ${_list}"
451 }
452
453 # gif_up
454 #       Create IPv6<-->IPv4 tunnels
455 #
456 gif_up() {
457         local _if _peers
458
459         case ${gif_interfaces} in
460         [Nn][Oo] | '')
461                 return
462                 ;;
463         esac
464
465         for _if in ${gif_interfaces}; do
466                 eval _peers=\$gifconfig_${_if}
467                 case ${_peers} in
468                 '')
469                         continue
470                         ;;
471                 *)
472                         ifconfig $_if create >/dev/null 2>&1
473                         ifconfig $_if tunnel ${_peers}
474                         ifconfig $_if up
475                         ;;
476                 esac
477         done
478 }
479
480 # ifnet_rename
481 #       Rename all requested interfaces.
482 #
483 ifnet_rename()
484 {
485         local _ifn_list _if _ifname
486
487         _ifn_list=$(ifconfig -l)
488         [ -z "$_ifn_list" ] && return 0
489
490         for _if in ${_ifn_list} ; do
491                 _ifname=`get_if_var $_if ifconfig_IF_name`
492                 if [ -n "$_ifname" ]; then
493                         ifconfig $_if name $_ifname
494                 fi
495         done
496         return 0
497 }
498
499 # list_net_interfaces
500 #       List all network interfaces.
501 #       Note that the list will include cloned interfaces if applicable.
502 #       Cloned interfaces must already exist to have a chance to appear
503 #       in the list if ${network_interfaces} is set to `auto'.
504 #
505 list_net_interfaces()
506 {
507         local _tmplist _autolist _lo _if
508
509         case ${network_interfaces} in
510         [Aa][Uu][Tt][Oo])
511                 _autolist="`ifconfig -l` `sysctl -in net.wlan.devices`"
512                 _lo=
513                 for _if in ${_autolist} ; do
514                         if [ "$_if" = "lo0" ]; then
515                                 _lo="lo0"
516                         else
517                                 _tmplist="${_tmplist} ${_if}"
518                         fi
519                 done
520                 _tmplist="${_lo} ${_tmplist}"
521                 ;;
522         *)
523                 _tmplist="${network_interfaces} ${cloned_interfaces}"
524                 ;;
525         esac
526
527         echo $_tmplist
528 }
529
530 hexdigit()
531 {
532         if [ $1 -lt 10 ]; then
533                 echo $1
534         else
535                 case $1 in
536                 10)     echo a ;;
537                 11)     echo b ;;
538                 12)     echo c ;;
539                 13)     echo d ;;
540                 14)     echo e ;;
541                 15)     echo f ;;
542                 esac
543         fi
544 }
545
546 hexprint()
547 {
548         local val str dig
549         val=$1
550         str=''
551
552         dig=`hexdigit $((${val} & 15))`
553         str=${dig}${str}
554         val=$((${val} >> 4))
555         while [ ${val} -gt 0 ]; do
556                 dig=`hexdigit $((${val} & 15))`
557                 str=${dig}${str}
558                 val=$((${val} >> 4))
559         done
560
561         echo ${str}
562 }
563
564
565 #
566 # IPv6-specific setup subroutines
567 #
568
569 # Setup the interfaces for IPv6
570 network6_interface_setup()
571 {
572         local interfaces rtsol_interfaces ipv6_ifconfig
573         local rtsol_available rtsol_interface
574         local prefix laddr hostid address
575         local _if j
576
577         interfaces=$*
578         rtsol_interfaces=''
579         case ${ipv6_gateway_enable} in
580         [Yy][Ee][Ss])
581                 rtsol_available=no
582                 ;;
583         *)
584                 rtsol_available=yes
585                 ;;
586         esac
587         for _if in $interfaces; do
588                 rtsol_interface=yes
589                 prefix=`get_if_var $_if ipv6_prefix_IF`
590                 if [ -n "${prefix}" ]; then
591                         rtsol_available=no
592                         rtsol_interface=no
593                         laddr=`network6_getladdr $_if`
594                         hostid=`expr "${laddr}" : 'fe80::\(.*\)%\(.*\)'`
595                         for j in ${prefix}; do
596                                 address=$j\:${hostid}
597                                 ifconfig $_if inet6 ${address} prefixlen 64 alias
598
599                                 case ${ipv6_gateway_enable} in
600                                 [Yy][Ee][Ss])
601                                         # subnet-router anycast address
602                                         # (rfc2373)
603                                         ifconfig $_if inet6 $j:: prefixlen 64 \
604                                                 alias anycast
605                                         ;;
606                                 esac
607                         done
608                 fi
609                 ipv6_ifconfig=`ifconfig_getargs $_if ipv6`
610                 if [ -n "${ipv6_ifconfig}" ]; then
611                         rtsol_available=no
612                         rtsol_interface=no
613                         ifconfig $_if inet6 ${ipv6_ifconfig} alias
614                 fi
615
616                 if [ "${rtsol_available}" = "yes" -a \
617                      "${rtsol_interface}" = "yes" ]; then
618                         case ${i} in
619                         lo0|gif[0-9]*|stf[0-9]*|lp[0-9]*|sl[0-9]*|tun[0-9]*)
620                                 ;;
621                         *)
622                                 rtsol_interfaces="${rtsol_interfaces} ${_if}"
623                                 ;;
624                         esac
625                 else
626                         ifconfig $_if inet6
627                 fi
628         done
629
630         if [ "${rtsol_available}" = "yes" -a -n "${rtsol_interfaces}" ]; then
631                 # Act as endhost - automatically configured.
632                 # You can configure only single interface, as
633                 # specification assumes that autoconfigured host has
634                 # single interface only.
635                 ${SYSCTL_W} net.inet6.ip6.accept_rtadv=1
636                 set ${rtsol_interfaces}
637                 ifconfig $1 up
638                 echo "Auto configuring interface $1 ..."
639                 rtsol $1
640         fi
641
642         for _if in $interfaces; do
643                 ifalias_up $_if ipv6
644         done
645 }
646
647 # Setup IPv6 to IPv4 mapping
648 network6_stf_setup()
649 {
650         local stf_prefixlen stf_interface_ipv6_ifid
651         local hexfrag1 hexfrag2 ipv4_in_hexformat laddr
652         local _if OIFS
653
654         case ${stf_interface_ipv4addr} in
655         [Nn][Oo] | '')
656                 ;;
657         *)
658                 # assign IPv6 addr and interface route for 6to4 interface
659                 stf_prefixlen=$((16+${stf_interface_ipv4plen:-0}))
660                 OIFS="$IFS"
661                 IFS=".$IFS"
662                 set ${stf_interface_ipv4addr}
663                 IFS="$OIFS"
664                 hexfrag1=`hexprint $(($1*256 + $2))`
665                 hexfrag2=`hexprint $(($3*256 + $4))`
666                 ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
667                 case ${stf_interface_ipv6_ifid} in
668                 [Aa][Uu][Tt][Oo] | '')
669                         for _if in ${ipv6_network_interfaces}; do
670                                 laddr=`network6_getladdr $_if`
671                                 case ${laddr} in
672                                 '')
673                                         ;;
674                                 *)
675                                         break
676                                         ;;
677                                 esac
678                         done
679                         stf_interface_ipv6_ifid=`expr "${laddr}" : \
680                                                       'fe80::\(.*\)%\(.*\)'`
681                         case ${stf_interface_ipv6_ifid} in
682                         '')
683                                 stf_interface_ipv6_ifid=0:0:0:1
684                                 ;;
685                         esac
686                         ;;
687                 esac
688                 ifconfig stf0 create >/dev/null 2>&1
689                 ifconfig stf0 inet6 2002:${ipv4_in_hexformat}:${stf_interface_ipv6_slaid:-0}:${stf_interface_ipv6_ifid} \
690                         prefixlen ${stf_prefixlen}
691                 # disallow packets to malicious 6to4 prefix
692                 route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
693                 route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
694                 route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
695                 route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
696                 ;;
697         esac
698 }
699
700 # Setup static routes
701 network6_static_routes_setup()
702 {
703         local _rt
704
705         # Set up any static routes.
706         case ${ipv6_defaultrouter} in
707         [Nn][Oo] | '')
708                 ;;
709         *)
710                 ipv6_static_routes="default ${ipv6_static_routes}"
711                 ipv6_route_default="default ${ipv6_defaultrouter}"
712                 ;;
713         esac
714         case ${ipv6_static_routes} in
715         [Nn][Oo] | '')
716                 ;;
717         *)
718                 for _rt in ${ipv6_static_routes}; do
719                         eval ipv6_route_args=\$ipv6_route_${_rt}
720                         route add -inet6 ${ipv6_route_args}
721                 done
722                 ;;
723         esac
724 }
725
726 # Install the "default interface" to kernel, which will be used
727 # as the default route when there's no router.
728 network6_default_interface_setup()
729 {
730         local _if laddr
731
732         # Choose IPv6 default interface if it is not clearly specified.
733         case ${ipv6_default_interface} in
734         '')
735                 for _if in ${ipv6_network_interfaces}; do
736                         if [ "${_if}" = "lo0" ]; then
737                                 continue
738                         fi
739
740                         laddr=`network6_getladdr $_if exclude_tentative`
741                         case ${laddr} in
742                         '')
743                                 ;;
744                         *)
745                                 ipv6_default_interface=$_if
746                                 break
747                                 ;;
748                         esac
749                 done
750                 ;;
751         esac
752
753         # Disallow unicast packets without outgoing scope identifiers,
754         # or route such packets to a "default" interface, if it is specified.
755         route add -inet6 fe80:: -prefixlen 10 ::1 -reject
756         case ${ipv6_default_interface} in
757         [Nn][Oo] | '')
758                 route add -inet6 ff02:: -prefixlen 16 ::1 -reject
759                 ;;
760         *)
761                 laddr=`network6_getladdr ${ipv6_default_interface}`
762                 route add -inet6 ff02:: ${laddr} -prefixlen 16 -interface \
763                         -cloning
764
765                 # Disable installing the default interface with the
766                 # case net.inet6.ip6.forwarding=0 and
767                 # net.inet6.ip6.accept_rtadv=0, due to avoid conflict
768                 # between the default router list and the manual
769                 # configured default route.
770                 case ${ipv6_gateway_enable} in
771                 [Yy][Ee][Ss])
772                         ;;
773                 *)
774                         if [ `${SYSCTL_N} net.inet6.ip6.accept_rtadv` -eq 1 ]
775                         then
776                                 ndp -I ${ipv6_default_interface}
777                         fi
778                         ;;
779                 esac
780                 ;;
781         esac
782 }
783
784 network6_getladdr()
785 {
786         local proto addr rest
787
788         ifconfig $1 2>/dev/null | while read proto addr rest; do
789                 case ${proto} in
790                 inet6)
791                         case ${addr} in
792                         fe80::*)
793                                 if [ -z "$2" ]; then
794                                         echo ${addr}
795                                         return
796                                 fi
797                                 case ${rest} in
798                                 *tentative*)
799                                         continue
800                                         ;;
801                                 *)
802                                         echo ${addr}
803                                         return
804                                 esac
805                         esac
806                 esac
807         done
808 }