2 # Copyright (c) 2003 The FreeBSD Project. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
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.
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
29 # Subroutines commonly used from network startup scripts.
30 # Requires that rc.conf be loaded first.
34 # Bring up and configure an interface. If some configuration is
35 # applied, print the interface configuration.
43 [ -z "$ifn" ] && err 1 "ifn_start called without an interface"
45 ifscript_up ${ifn} && cfg=0
46 ifconfig_up ${ifn} && cfg=0
47 afexists inet && ipv4_up ${ifn} && cfg=0
48 afexists inet6 && ipv6_up ${ifn} && cfg=0
49 afexists ipx && ipx_up ${ifn} && cfg=0
50 childif_create ${ifn} && cfg=0
56 # Shutdown and de-configure an interface. If action is taken,
57 # print the interface name.
65 [ -z "$ifn" ] && err 1 "ifn_stop called without an interface"
67 afexists ipx && ipx_down ${ifn} && cfg=0
68 afexists inet6 && ipv6_down ${ifn} && cfg=0
69 afexists inet && ipv4_down ${ifn} && cfg=0
70 ifconfig_down ${ifn} && cfg=0
71 ifscript_down ${ifn} && cfg=0
72 childif_destroy ${ifn} && cfg=0
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
86 local _cfg _ipv6_opts ifconfig_args
89 # Make sure lo0 always comes up.
90 if [ "$1" = "lo0" ]; then
95 ifconfig_args=`ifconfig_getargs $1`
96 if [ -n "${ifconfig_args}" ]; then
97 eval ifconfig $1 ${ifconfig_args}
102 if afexists inet6; then
103 if checkyesno ipv6_activate_all_interfaces; then
104 _ipv6_opts="-ifdisabled"
105 elif [ "$1" != "lo0" ]; then
106 _ipv6_opts="ifdisabled"
109 # backward compatibility: $ipv6_enable
111 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
112 _ipv6_opts="${_ipv6_opts} accept_rtadv"
116 case $ipv6_cpe_wanif in
118 _ipv6_opts="${_ipv6_opts} -no_radr accept_rtadv"
122 if [ -n "${_ipv6_opts}" ]; then
123 ifconfig $1 inet6 ${_ipv6_opts}
127 ifconfig_args=`ifconfig_getargs $1 ipv6`
128 if [ -n "${ifconfig_args}" ]; then
129 # backward compatibility: inet6 keyword
130 case "${ifconfig_args}" in
132 warn "\$ifconfig_$1_ipv6 needs " \
133 "\"inet6\" keyword for an IPv6 address."
134 ifconfig_args="inet6 ${ifconfig_args}"
137 ifconfig $1 inet6 -ifdisabled
138 eval ifconfig $1 ${ifconfig_args}
142 # backward compatiblity: $ipv6_ifconfig_IF
143 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF`
144 if [ -n "${ifconfig_args}" ]; then
145 warn "\$ipv6_ifconfig_$1 is obsolete." \
146 " Use ifconfig_$1_ipv6 instead."
147 ifconfig $1 inet6 -ifdisabled
148 eval ifconfig $1 inet6 ${ifconfig_args}
153 if [ ${_cfg} -eq 0 ]; then
158 /etc/rc.d/wpa_supplicant start $1
159 _cfg=0 # XXX: not sure this should count
163 if [ $_cfg -ne 0 ] ; then
166 if syncdhcpif $1; then
167 /etc/rc.d/dhclient start $1
176 # returns 1 if wpa_supplicant or dhclient was stopped or
177 # the interface exists.
185 /etc/rc.d/wpa_supplicant stop $1
190 /etc/rc.d/dhclient stop $1
202 # get_if_var if var [default]
203 # Return the value of the pseudo-hash corresponding to $if where
204 # $var is a string containg the sub-string "IF" which will be
205 # replaced with $if after the characters defined in _punct are
206 # replaced with '_'. If the variable is unset, replace it with
210 local _if _punct _punct_c _var _default prefix suffix
212 if [ $# -ne 2 -a $# -ne 3 ]; then
213 err 3 'USAGE: get_if_var name var [default]'
218 for _punct_c in $_punct; do
219 _if=`ltr ${_if} ${_punct_c} '_'`
226 eval echo \${${prefix}${_if}${suffix}-${_default}}
229 # _ifconfig_getargs if [af]
230 # Prints the arguments for the supplied interface to stdout.
231 # Returns 1 if empty. In general, ifconfig_getargs should be used
239 if [ -z "$_ifn" ]; then
243 get_if_var $_ifn ifconfig_IF$_af "$ifconfig_DEFAULT"
246 # ifconfig_getargs if [af]
247 # Takes the result from _ifconfig_getargs and removes pseudo
248 # args such as DHCP and WPA.
251 local _tmpargs _arg _args
252 _tmpargs=`_ifconfig_getargs $1 $2`
253 if [ $? -eq 1 ]; then
258 for _arg in $_tmpargs; do
261 [Nn][Oo][Aa][Uu][Tt][Oo]) ;;
262 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;;
263 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;;
275 # Returns 0 if the interface should be automatically configured at
276 # boot time and 1 otherwise.
280 _tmpargs=`_ifconfig_getargs $1`
282 for _arg in $_tmpargs; do
284 [Nn][Oo][Aa][Uu][Tt][Oo])
294 # Returns 0 if the interface is a DHCP interface and 1 otherwise.
298 _tmpargs=`_ifconfig_getargs $1`
304 for _arg in $_tmpargs; do
309 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
312 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
322 # Returns 0 if the interface should be configured synchronously and
327 _tmpargs=`_ifconfig_getargs $1`
333 for _arg in $_tmpargs; do
335 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
338 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
344 checkyesno synchronous_dhclient
348 # Returns 0 if the interface is a WPA interface and 1 otherwise.
352 _tmpargs=`_ifconfig_getargs $1`
354 for _arg in $_tmpargs; do
366 # Returns 0 if the address family is enabled in the kernel
375 check_kern_features ${_af}
378 ${SYSCTL_N} net.ipx > /dev/null 2>&1
381 if [ -x /sbin/atmconfig ]; then
382 /sbin/atmconfig diag list > /dev/null 2>&1
388 err 1 "afexists(): Unsupported address family: $_af"
394 # Returns 0 if the interface has no af configuration and 1 otherwise.
421 # Returns 0 if the interface should be configured for IPv6 and
428 if ! afexists inet6; then
432 # lo0 is always IPv6-enabled
439 case "${ipv6_network_interfaces}" in
440 $_if|"$_if "*|*" $_if"|*" $_if "*|[Aa][Uu][Tt][Oo])
441 # True if $ifconfig_IF_ipv6 is defined.
442 _tmpargs=`_ifconfig_getargs $_if ipv6`
443 if [ -n "${_tmpargs}" ]; then
447 # backward compatibility: True if $ipv6_ifconfig_IF is defined.
448 _tmpargs=`get_if_var $_if ipv6_ifconfig_IF`
449 if [ -n "${_tmpargs}" ]; then
459 # Returns 0 if the interface should be configured for IPv6 with
460 # Stateless Address Configuration; 1 otherwise.
463 local _if _tmpargs _arg
478 if ! ipv6if $_if; then
481 if checkyesno ipv6_gateway_enable; then
484 _tmpargs=`get_if_var $_if ipv6_prefix_IF`
485 if [ -n "${_tmpargs}" ]; then
488 # backward compatibility: $ipv6_enable
490 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
495 _tmpargs=`_ifconfig_getargs $_if ipv6`
496 for _arg in $_tmpargs; do
504 # backward compatibility: $ipv6_ifconfig_IF
505 _tmpargs=`get_if_var $_if ipv6_ifconfig_IF`
506 for _arg in $_tmpargs; do
518 # Returns 0 if the interface exists and 1 otherwise.
521 [ -z "$1" ] && return 1
522 ifconfig -n $1 > /dev/null 2>&1
526 # add IPv4 addresses to the interface $if
533 # Add 127.0.0.1/8 to lo0 unless otherwise specified.
534 if [ "${_if}" = "lo0" ]; then
535 ifconfig_args=`get_if_var ${_if} ifconfig_IF`
536 if [ -z "${ifconfig_args}" ]; then
537 ifconfig ${_if} inet 127.0.0.1/8 alias
540 ifalias_up ${_if} inet && _ret=0
541 ipv4_addrs_common ${_if} alias && _ret=0
547 # add IPv6 addresses to the interface $if
554 if ! ipv6if $_if; then
558 ifalias_up ${_if} inet6 && _ret=0
559 ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0
560 ipv6_accept_rtadv_up ${_if} && _ret=0
563 sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
570 # remove IPv4 addresses from the interface $if
573 local _if _ifs _ret inetList oldifs _inet
578 inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
582 for _inet in $inetList ; do
583 # get rid of extraneous line
584 [ -z "$_inet" ] && break
586 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
589 ifconfig ${_if} ${_inet} delete
595 ifalias_down ${_if} inet && _ret=0
596 ipv4_addrs_common ${_if} -alias && _ret=0
602 # remove IPv6 addresses from the interface $if
605 local _if _ifs _ret inetList oldifs _inet6
610 if ! ipv6if $_if; then
614 ipv6_accept_rtadv_down ${_if} && _ret=0
615 ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0
616 ifalias_down ${_if} inet6 && _ret=0
618 inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`"
622 for _inet6 in $inetList ; do
623 # get rid of extraneous line
624 [ -z "$_inet6" ] && break
626 _inet6=`expr "$_inet6" : '.*\(inet6 \([0-9a-f:]*\)\).*'`
629 ifconfig ${_if} ${_inet6} -alias
638 # ipv4_addrs_common if action
639 # Evaluate the ifconfig_if_ipv4 arguments for interface $if and
640 # use $action to add or remove IPv4 addresses from $if.
643 local _ret _if _action _cidr _cidr_addr
644 local _ipaddr _netmask _range _ipnet _iplow _iphigh _ipcount
650 cidr_addr=`get_if_var $_if ipv4_addrs_IF`
652 for _cidr in ${cidr_addr}; do
654 _netmask="/"${_cidr##*/}
655 _range=${_ipaddr##*.}
660 # clear netmask when removing aliases
661 if [ "${_action}" = "-alias" ]; then
666 while [ "${_ipcount}" -le "${_iphigh}" ]; do
667 eval "ifconfig ${_if} ${_action} ${_ipnet}.${_ipcount}${_netmask}"
668 _ipcount=$((${_ipcount}+1))
671 # only the first ipaddr in a subnet need the real netmask
672 if [ "${_action}" != "-alias" ]; then
682 # Configure aliases for network interface $if.
683 # It returns 0 if at least one alias was configured or
684 # 1 if there were none.
693 _ret=`ifalias_ipv4_up "$1"`
696 _ret=`ifalias_ipv6_up "$1"`
704 # Helper function for ifalias_up(). Handles IPv4.
708 local _ret alias ifconfig_args
711 # ifconfig_IF_aliasN which starts with "inet"
714 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
715 case "${ifconfig_args}" in
717 ifconfig $1 ${ifconfig_args} alias && _ret=0
725 warn "\$ifconfig_$1_alias${alias} needs " \
726 "\"inet\" keyword for an IPv4 address."
727 ifconfig $1 ${ifconfig_args} alias && _ret=0
730 alias=$((${alias} + 1))
737 # Helper function for ifalias_up(). Handles IPv6.
741 local _ret alias ifconfig_args
744 # ifconfig_IF_aliasN which starts with "inet6"
747 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
748 case "${ifconfig_args}" in
750 ifconfig $1 ${ifconfig_args} alias && _ret=0
756 alias=$((${alias} + 1))
759 # backward compatibility: ipv6_ifconfig_IF_aliasN.
762 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
763 case "${ifconfig_args}" in
768 ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0
769 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
770 " Use ifconfig_$1_aliasN instead."
773 alias=$((${alias} + 1))
780 # Remove aliases for network interface $if.
781 # It returns 0 if at least one alias was removed or
782 # 1 if there were none.
791 _ret=`ifalias_ipv4_down "$1"`
794 _ret=`ifalias_ipv6_down "$1"`
801 # ifalias_ipv4_down if
802 # Helper function for ifalias_down(). Handles IPv4.
806 local _ret alias ifconfig_args
809 # ifconfig_IF_aliasN which starts with "inet"
812 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
813 case "${ifconfig_args}" in
815 ifconfig $1 ${ifconfig_args} -alias && _ret=0
821 alias=$((${alias} + 1))
827 # ifalias_ipv6_down if
828 # Helper function for ifalias_down(). Handles IPv6.
832 local _ret alias ifconfig_args
835 # ifconfig_IF_aliasN which starts with "inet6"
838 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
839 case "${ifconfig_args}" in
841 ifconfig $1 ${ifconfig_args} -alias && _ret=0
847 alias=$((${alias} + 1))
850 # backward compatibility: ipv6_ifconfig_IF_aliasN.
853 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
854 case "${ifconfig_args}" in
859 ifconfig $1 inet6 ${ifconfig_args} -alias && _ret=0
860 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
861 " Use ifconfig_$1_aliasN instead."
864 alias=$((${alias} + 1))
870 # ipv6_prefix_hostid_addr_common if action
871 # Add or remove IPv6 prefix + hostid addr on the interface $if
873 ipv6_prefix_hostid_addr_common()
875 local _if _action prefix laddr hostid j address
878 prefix=`get_if_var ${_if} ipv6_prefix_IF`
880 if [ -n "${prefix}" ]; then
881 laddr=`network6_getladdr ${_if}`
882 hostid=${laddr#fe80::}
885 for j in ${prefix}; do
886 address=$j\:${hostid}
887 ifconfig ${_if} inet6 ${address} prefixlen 64 ${_action}
889 # if I am a router, add subnet router
890 # anycast address (RFC 2373).
891 if checkyesno ipv6_gateway_enable; then
892 ifconfig ${_if} inet6 $j:: prefixlen 64 \
899 # ipv6_accept_rtadv_up if
900 # Enable accepting Router Advertisement and send Router
901 # Solicitation message
902 ipv6_accept_rtadv_up()
904 if ipv6_autoconfif $1; then
905 ifconfig $1 inet6 accept_rtadv up
906 if ! checkyesno rtsold_enable; then
907 rtsol ${rtsol_flags} $1
912 # ipv6_accept_rtadv_down if
913 # Disable accepting Router Advertisement
914 ipv6_accept_rtadv_down()
916 if ipv6_autoconfif $1; then
917 ifconfig $1 inet6 -accept_rtadv
922 # Evaluate a startup script for the $if interface.
923 # It returns 0 if a script was found and processed or
924 # 1 if no script was found.
928 if [ -r /etc/start_if.$1 ]; then
937 # Evaluate a shutdown script for the $if interface.
938 # It returns 0 if a script was found and processed or
939 # 1 if no script was found.
943 if [ -r /etc/stop_if.$1 ]; then
952 # Create cloneable interfaces.
956 local _prefix _list ifn
961 for ifn in ${cloned_interfaces}; do
962 ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF`
963 if [ $? -eq 0 ]; then
964 _list="${_list}${_prefix}${ifn}"
965 [ -z "$_prefix" ] && _prefix=' '
968 debug "Cloned: ${_list}"
972 # Destroy cloned interfaces. Destroyed interfaces are echoed to
977 local _prefix _list ifn
981 for ifn in ${cloned_interfaces}; do
982 ifconfig -n ${ifn} destroy
983 if [ $? -eq 0 ]; then
984 _list="${_list}${_prefix}${ifn}"
985 [ -z "$_prefix" ] && _prefix=' '
988 debug "Destroyed clones: ${_list}"
992 # Create and configure child interfaces. Return 0 if child
993 # interfaces are created.
997 local cfg child child_vlans child_wlans create_args debug_flags ifn i
1001 # Create wireless interfaces
1002 child_wlans=`get_if_var $ifn wlans_IF`
1004 for child in ${child_wlans}; do
1005 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
1006 debug_flags="`get_if_var $child wlandebug_IF`"
1008 if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then
1009 ifconfig $child create ${create_args} && cfg=0
1010 if [ -n "${debug_flags}" ]; then
1011 wlandebug -i $child ${debug_flags}
1014 i=`ifconfig wlan create ${create_args}`
1015 if [ -n "${debug_flags}" ]; then
1016 wlandebug -i $i ${debug_flags}
1018 ifconfig $i name $child && cfg=0
1020 if autoif $child; then
1025 # Create vlan interfaces
1026 child_vlans=`get_if_var $ifn vlans_IF`
1028 if [ -n "${child_vlans}" ]; then
1032 for child in ${child_vlans}; do
1033 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
1034 child="${ifn}.${child}"
1035 create_args=`get_if_var $child create_args_IF`
1036 ifconfig $child create ${create_args} && cfg=0
1038 create_args="vlandev $ifn `get_if_var $child create_args_IF`"
1039 if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
1040 ifconfig $child create ${create_args} && cfg=0
1042 i=`ifconfig vlan create ${create_args}`
1043 ifconfig $i name $child && cfg=0
1046 if autoif $child; then
1055 # Destroy child interfaces.
1059 local cfg child child_vlans child_wlans ifn
1062 child_wlans=`get_if_var $ifn wlans_IF`
1063 for child in ${child_wlans}; do
1064 if ! ifexists $child; then
1067 ifconfig -n $child destroy && cfg=0
1070 child_vlans=`get_if_var $ifn vlans_IF`
1071 for child in ${child_vlans}; do
1072 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
1073 child="${ifn}.${child}"
1075 if ! ifexists $child; then
1078 ifconfig -n $child destroy && cfg=0
1085 # Create netgraph nodes.
1089 ngctl -f - 2> /dev/null <<EOF
1096 # Create netgraph nodes.
1102 ng_mkpeer $* | while read line; do
1103 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
1104 if [ -n "${t}" ]; then
1112 # Create gif(4) tunnel interfaces.
1117 for i in ${gif_interfaces}; do
1118 peers=`get_if_var $i gifconfig_IF`
1124 if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then
1125 ifconfig $i create >/dev/null 2>&1
1127 gif=`ifconfig gif create`
1128 ifconfig $gif name $i
1130 ifconfig $i tunnel ${peers}
1138 # Configure Fast EtherChannel for interface $ifn. Returns 0 if
1139 # FEC arguments were found and configured; returns !0 otherwise.
1142 local req_iface iface bogus
1145 ngctl shutdown ${req_iface}: > /dev/null 2>&1
1149 iface=`ng_create_one fec dummy fec`
1150 if [ -z "${iface}" ]; then
1153 if [ "${iface}" = "${req_iface}" ]; then
1156 bogus="${bogus} ${iface}"
1159 for iface in ${bogus}; do
1160 ngctl shutdown ${iface}:
1165 # Create Fast EtherChannel interfaces.
1170 for i in ${fec_interfaces}; do
1172 for j in `get_if_var $i fecconfig_IF`; do
1178 ngctl msg ${i}: add_iface "\"${j}\""
1186 # Configure any IPX addresses for interface $ifn. Returns 0 if
1187 # IPX arguments were found and configured; returns 1 otherwise.
1195 ifconfig_args=`_ifconfig_getargs $ifn ipx`
1196 if [ -n "${ifconfig_args}" ]; then
1197 ifconfig ${ifn} ${ifconfig_args}
1205 # Remove IPX addresses for interface $ifn. Returns 0 if IPX
1206 # addresses were found and unconfigured. It returns 1, otherwise.
1210 local _if _ifs _ret ipxList oldifs _ipx
1214 ipxList="`ifconfig ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`"
1218 for _ipx in $ipxList ; do
1219 # get rid of extraneous line
1220 [ -z "$_ipx" ] && break
1222 _ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'`
1225 ifconfig ${_if} ${_ipx} delete
1235 # Rename all requested interfaces.
1242 for _if in `ifconfig -l`; do
1243 _ifname=`get_if_var $_if ifconfig_IF_name`
1244 if [ ! -z "$_ifname" ]; then
1245 ifconfig $_if name $_ifname
1252 # list_net_interfaces type
1253 # List all network interfaces. The type of interface returned
1254 # can be controlled by the type argument. The type
1255 # argument can be any of the following:
1256 # nodhcp - all interfaces, excluding DHCP configured interfaces
1257 # dhcp - list only DHCP configured interfaces
1258 # noautoconf - all interfaces, excluding IPv6 Stateless
1259 # Address Autoconf configured interfaces
1260 # autoconf - list only IPv6 Stateless Address Autoconf
1261 # configured interfaces
1262 # If no argument is specified all network interfaces are output.
1263 # Note that the list will include cloned interfaces if applicable.
1264 # Cloned interfaces must already exist to have a chance to appear
1265 # in the list if ${network_interfaces} is set to `auto'.
1267 list_net_interfaces()
1269 local type _tmplist _list _autolist _lo _if
1272 # Get a list of ALL the interfaces and make lo0 first if it's there.
1275 case ${network_interfaces} in
1277 _autolist="`ifconfig -l`"
1279 for _if in ${_autolist} ; do
1280 if autoif $_if; then
1281 if [ "$_if" = "lo0" ]; then
1284 _tmplist="${_tmplist} ${_if}"
1288 _tmplist="${_lo}${_tmplist# }"
1291 _tmplist="${network_interfaces} ${cloned_interfaces}"
1293 # lo0 is effectively mandatory, so help prevent foot-shooting
1296 lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
1297 *) _tmplist="lo0 ${_tmplist}" ;;
1305 for _if in ${_tmplist} ; do
1306 if ! dhcpif $_if && \
1307 [ -n "`_ifconfig_getargs $_if`" ]; then
1308 _list="${_list# } ${_if}"
1313 for _if in ${_tmplist} ; do
1314 if dhcpif $_if; then
1315 _list="${_list# } ${_if}"
1320 for _if in ${_tmplist} ; do
1321 if ! ipv6_autoconfif $_if && \
1322 [ -n "`_ifconfig_getargs $_if ipv6`" ]; then
1323 _list="${_list# } ${_if}"
1328 for _if in ${_tmplist} ; do
1329 if ipv6_autoconfif $_if; then
1330 _list="${_list# } ${_if}"
1344 # get_default_if -address_family
1345 # Get the interface of the default route for the given address family.
1346 # The -address_family argument must be suitable passing to route(8).
1350 local routeget oldifs defif line
1355 for line in `route -n get $1 default 2>/dev/null`; do
1368 # Echo decimal number $arg (single digit) in hexadecimal format.
1375 # Echo decimal number $arg (multiple digits) in hexadecimal format.
1381 is_wired_interface()
1385 case `ifconfig $1 2>/dev/null` in
1386 *media:?Ethernet*) media=Ethernet ;;
1389 test "$media" = "Ethernet"
1392 # network6_getladdr if [flag]
1393 # Echo link-local address from $if if any.
1394 # If flag is defined, tentative ones will be excluded.
1397 local proto addr rest
1398 ifconfig $1 2>/dev/null | while read proto addr rest; do
1403 if [ -z "$2" ]; then