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 if ! checkyesno ipv6_gateway_enable; then
113 _ipv6_opts="${_ipv6_opts} accept_rtadv"
118 case $ipv6_cpe_wanif in
120 _ipv6_opts="${_ipv6_opts} -no_radr accept_rtadv"
124 if [ -n "${_ipv6_opts}" ]; then
125 ifconfig $1 inet6 ${_ipv6_opts}
129 ifconfig_args=`ifconfig_getargs $1 ipv6`
130 if [ -n "${ifconfig_args}" ]; then
131 # backward compatibility: inet6 keyword
132 case "${ifconfig_args}" in
134 warn "\$ifconfig_$1_ipv6 needs " \
135 "\"inet6\" keyword for an IPv6 address."
136 ifconfig_args="inet6 ${ifconfig_args}"
139 ifconfig $1 inet6 -ifdisabled
140 eval ifconfig $1 ${ifconfig_args}
144 # $ipv6_prefix_IF will be handled in
145 # ipv6_prefix_hostid_addr_common().
146 ifconfig_args=`get_if_var $1 ipv6_prefix_IF`
147 if [ -n "${ifconfig_args}" ]; then
148 ifconfig $1 inet6 -ifdisabled
152 # backward compatibility: $ipv6_ifconfig_IF
153 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF`
154 if [ -n "${ifconfig_args}" ]; then
155 warn "\$ipv6_ifconfig_$1 is obsolete." \
156 " Use ifconfig_$1_ipv6 instead."
157 ifconfig $1 inet6 -ifdisabled
158 eval ifconfig $1 inet6 ${ifconfig_args}
163 if [ ${_cfg} -eq 0 ]; then
168 /etc/rc.d/wpa_supplicant start $1
169 _cfg=0 # XXX: not sure this should count
173 if [ $_cfg -ne 0 ] ; then
176 if syncdhcpif $1; then
177 /etc/rc.d/dhclient start $1
186 # returns 1 if wpa_supplicant or dhclient was stopped or
187 # the interface exists.
195 /etc/rc.d/wpa_supplicant stop $1
200 /etc/rc.d/dhclient stop $1
212 # get_if_var if var [default]
213 # Return the value of the pseudo-hash corresponding to $if where
214 # $var is a string containg the sub-string "IF" which will be
215 # replaced with $if after the characters defined in _punct are
216 # replaced with '_'. If the variable is unset, replace it with
220 local _if _punct _punct_c _var _default prefix suffix
222 if [ $# -ne 2 -a $# -ne 3 ]; then
223 err 3 'USAGE: get_if_var name var [default]'
228 for _punct_c in $_punct; do
229 _if=`ltr ${_if} ${_punct_c} '_'`
236 eval echo \${${prefix}${_if}${suffix}-${_default}}
239 # _ifconfig_getargs if [af]
240 # Prints the arguments for the supplied interface to stdout.
241 # Returns 1 if empty. In general, ifconfig_getargs should be used
249 if [ -z "$_ifn" ]; then
253 get_if_var $_ifn ifconfig_IF$_af "$ifconfig_DEFAULT"
256 # ifconfig_getargs if [af]
257 # Takes the result from _ifconfig_getargs and removes pseudo
258 # args such as DHCP and WPA.
261 local _tmpargs _arg _args
262 _tmpargs=`_ifconfig_getargs $1 $2`
263 if [ $? -eq 1 ]; then
268 for _arg in $_tmpargs; do
271 [Nn][Oo][Aa][Uu][Tt][Oo]) ;;
272 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;;
273 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;;
285 # Returns 0 if the interface should be automatically configured at
286 # boot time and 1 otherwise.
290 _tmpargs=`_ifconfig_getargs $1`
292 for _arg in $_tmpargs; do
294 [Nn][Oo][Aa][Uu][Tt][Oo])
304 # Returns 0 if the interface is a DHCP interface and 1 otherwise.
308 _tmpargs=`_ifconfig_getargs $1`
314 for _arg in $_tmpargs; do
319 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
322 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
332 # Returns 0 if the interface should be configured synchronously and
337 _tmpargs=`_ifconfig_getargs $1`
343 for _arg in $_tmpargs; do
345 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
348 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp])
354 checkyesno synchronous_dhclient
358 # Returns 0 if the interface is a WPA interface and 1 otherwise.
362 _tmpargs=`_ifconfig_getargs $1`
364 for _arg in $_tmpargs; do
376 # Returns 0 if the address family is enabled in the kernel
385 check_kern_features ${_af}
388 ${SYSCTL_N} net.ipx > /dev/null 2>&1
391 if [ -x /sbin/atmconfig ]; then
392 /sbin/atmconfig diag list > /dev/null 2>&1
398 err 1 "afexists(): Unsupported address family: $_af"
404 # Returns 0 if the interface has no af configuration and 1 otherwise.
431 # Returns 0 if the interface should be configured for IPv6 and
438 if ! afexists inet6; then
442 # lo0 is always IPv6-enabled
449 case "${ipv6_network_interfaces}" in
450 $_if|"$_if "*|*" $_if"|*" $_if "*|[Aa][Uu][Tt][Oo])
451 # True if $ifconfig_IF_ipv6 is defined.
452 _tmpargs=`_ifconfig_getargs $_if ipv6`
453 if [ -n "${_tmpargs}" ]; then
457 # True if $ipv6_prefix_IF is defined.
458 _tmpargs=`get_if_var $_if ipv6_prefix_IF`
459 if [ -n "${_tmpargs}" ]; then
463 # backward compatibility: True if $ipv6_ifconfig_IF is defined.
464 _tmpargs=`get_if_var $_if ipv6_ifconfig_IF`
465 if [ -n "${_tmpargs}" ]; then
475 # Returns 0 if the interface should be configured for IPv6 with
476 # Stateless Address Configuration; 1 otherwise.
479 local _if _tmpargs _arg
494 if ! ipv6if $_if; then
497 if checkyesno ipv6_gateway_enable; then
500 _tmpargs=`get_if_var $_if ipv6_prefix_IF`
501 if [ -n "${_tmpargs}" ]; then
504 # backward compatibility: $ipv6_enable
506 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
511 _tmpargs=`_ifconfig_getargs $_if ipv6`
512 for _arg in $_tmpargs; do
520 # backward compatibility: $ipv6_ifconfig_IF
521 _tmpargs=`get_if_var $_if ipv6_ifconfig_IF`
522 for _arg in $_tmpargs; do
534 # Returns 0 if the interface exists and 1 otherwise.
537 [ -z "$1" ] && return 1
538 ifconfig -n $1 > /dev/null 2>&1
542 # add IPv4 addresses to the interface $if
549 # Add 127.0.0.1/8 to lo0 unless otherwise specified.
550 if [ "${_if}" = "lo0" ]; then
551 ifconfig_args=`get_if_var ${_if} ifconfig_IF`
552 if [ -z "${ifconfig_args}" ]; then
553 ifconfig ${_if} inet 127.0.0.1/8 alias
556 ifalias_up ${_if} inet && _ret=0
557 ipv4_addrs_common ${_if} alias && _ret=0
563 # add IPv6 addresses to the interface $if
570 if ! ipv6if $_if; then
574 ifalias_up ${_if} inet6 && _ret=0
575 ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0
576 ipv6_accept_rtadv_up ${_if} && _ret=0
582 # remove IPv4 addresses from the interface $if
585 local _if _ifs _ret inetList oldifs _inet
590 inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
594 for _inet in $inetList ; do
595 # get rid of extraneous line
596 [ -z "$_inet" ] && break
598 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
601 ifconfig ${_if} ${_inet} delete
607 ifalias_down ${_if} inet && _ret=0
608 ipv4_addrs_common ${_if} -alias && _ret=0
614 # remove IPv6 addresses from the interface $if
617 local _if _ifs _ret inetList oldifs _inet6
622 if ! ipv6if $_if; then
626 ipv6_accept_rtadv_down ${_if} && _ret=0
627 ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0
628 ifalias_down ${_if} inet6 && _ret=0
630 inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`"
634 for _inet6 in $inetList ; do
635 # get rid of extraneous line
636 [ -z "$_inet6" ] && break
638 _inet6=`expr "$_inet6" : '.*\(inet6 \([0-9a-f:]*\)\).*'`
641 ifconfig ${_if} ${_inet6} -alias
650 # ipv4_addrs_common if action
651 # Evaluate the ifconfig_if_ipv4 arguments for interface $if and
652 # use $action to add or remove IPv4 addresses from $if.
655 local _ret _if _action _cidr _cidr_addr
656 local _ipaddr _netmask _range _ipnet _iplow _iphigh _ipcount
662 cidr_addr=`get_if_var $_if ipv4_addrs_IF`
664 for _cidr in ${cidr_addr}; do
666 _netmask="/"${_cidr##*/}
667 _range=${_ipaddr##*.}
672 # clear netmask when removing aliases
673 if [ "${_action}" = "-alias" ]; then
678 while [ "${_ipcount}" -le "${_iphigh}" ]; do
679 eval "ifconfig ${_if} ${_action} ${_ipnet}.${_ipcount}${_netmask}"
680 _ipcount=$((${_ipcount}+1))
683 # only the first ipaddr in a subnet need the real netmask
684 if [ "${_action}" != "-alias" ]; then
694 # Configure aliases for network interface $if.
695 # It returns 0 if at least one alias was configured or
696 # 1 if there were none.
705 _ret=`ifalias_ipv4_up "$1"`
708 _ret=`ifalias_ipv6_up "$1"`
716 # Helper function for ifalias_up(). Handles IPv4.
720 local _ret alias ifconfig_args
723 # ifconfig_IF_aliasN which starts with "inet"
726 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
727 case "${ifconfig_args}" in
729 ifconfig $1 ${ifconfig_args} alias && _ret=0
737 warn "\$ifconfig_$1_alias${alias} needs " \
738 "\"inet\" keyword for an IPv4 address."
739 ifconfig $1 ${ifconfig_args} alias && _ret=0
742 alias=$((${alias} + 1))
749 # Helper function for ifalias_up(). Handles IPv6.
753 local _ret alias ifconfig_args
756 # ifconfig_IF_aliasN which starts with "inet6"
759 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
760 case "${ifconfig_args}" in
762 ifconfig $1 ${ifconfig_args} alias && _ret=0
768 alias=$((${alias} + 1))
771 # backward compatibility: ipv6_ifconfig_IF_aliasN.
774 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
775 case "${ifconfig_args}" in
780 ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0
781 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
782 " Use ifconfig_$1_aliasN instead."
785 alias=$((${alias} + 1))
792 # Remove aliases for network interface $if.
793 # It returns 0 if at least one alias was removed or
794 # 1 if there were none.
803 _ret=`ifalias_ipv4_down "$1"`
806 _ret=`ifalias_ipv6_down "$1"`
813 # ifalias_ipv4_down if
814 # Helper function for ifalias_down(). Handles IPv4.
818 local _ret alias ifconfig_args
821 # ifconfig_IF_aliasN which starts with "inet"
824 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
825 case "${ifconfig_args}" in
827 ifconfig $1 ${ifconfig_args} -alias && _ret=0
833 alias=$((${alias} + 1))
839 # ifalias_ipv6_down if
840 # Helper function for ifalias_down(). Handles IPv6.
844 local _ret alias ifconfig_args
847 # ifconfig_IF_aliasN which starts with "inet6"
850 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
851 case "${ifconfig_args}" in
853 ifconfig $1 ${ifconfig_args} -alias && _ret=0
859 alias=$((${alias} + 1))
862 # backward compatibility: ipv6_ifconfig_IF_aliasN.
865 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
866 case "${ifconfig_args}" in
871 ifconfig $1 inet6 ${ifconfig_args} -alias && _ret=0
872 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
873 " Use ifconfig_$1_aliasN instead."
876 alias=$((${alias} + 1))
882 # ipv6_prefix_hostid_addr_common if action
883 # Add or remove IPv6 prefix + hostid addr on the interface $if
885 ipv6_prefix_hostid_addr_common()
887 local _if _action prefix laddr hostid j address
890 prefix=`get_if_var ${_if} ipv6_prefix_IF`
892 if [ -n "${prefix}" ]; then
893 laddr=`network6_getladdr ${_if}`
894 hostid=${laddr#fe80::}
897 for j in ${prefix}; do
898 address=$j\:${hostid}
899 ifconfig ${_if} inet6 ${address} prefixlen 64 ${_action}
901 # if I am a router, add subnet router
902 # anycast address (RFC 2373).
903 if checkyesno ipv6_gateway_enable; then
904 ifconfig ${_if} inet6 $j:: prefixlen 64 \
911 # ipv6_accept_rtadv_up if
912 # Enable accepting Router Advertisement and send Router
913 # Solicitation message
914 ipv6_accept_rtadv_up()
916 if ipv6_autoconfif $1; then
917 ifconfig $1 inet6 accept_rtadv up
918 if ! checkyesno rtsold_enable; then
919 rtsol ${rtsol_flags} $1
924 # ipv6_accept_rtadv_down if
925 # Disable accepting Router Advertisement
926 ipv6_accept_rtadv_down()
928 if ipv6_autoconfif $1; then
929 ifconfig $1 inet6 -accept_rtadv
934 # Evaluate a startup script for the $if interface.
935 # It returns 0 if a script was found and processed or
936 # 1 if no script was found.
940 if [ -r /etc/start_if.$1 ]; then
949 # Evaluate a shutdown script for the $if interface.
950 # It returns 0 if a script was found and processed or
951 # 1 if no script was found.
955 if [ -r /etc/stop_if.$1 ]; then
964 # Create cloneable interfaces.
968 local _prefix _list ifn
973 for ifn in ${cloned_interfaces}; do
974 ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF`
975 if [ $? -eq 0 ]; then
976 _list="${_list}${_prefix}${ifn}"
977 [ -z "$_prefix" ] && _prefix=' '
980 debug "Cloned: ${_list}"
984 # Destroy cloned interfaces. Destroyed interfaces are echoed to
989 local _prefix _list ifn
993 for ifn in ${cloned_interfaces}; do
994 ifconfig -n ${ifn} destroy
995 if [ $? -eq 0 ]; then
996 _list="${_list}${_prefix}${ifn}"
997 [ -z "$_prefix" ] && _prefix=' '
1000 debug "Destroyed clones: ${_list}"
1004 # Create and configure child interfaces. Return 0 if child
1005 # interfaces are created.
1009 local cfg child child_vlans child_wlans create_args debug_flags ifn i
1013 # Create wireless interfaces
1014 child_wlans=`get_if_var $ifn wlans_IF`
1016 for child in ${child_wlans}; do
1017 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
1018 debug_flags="`get_if_var $child wlandebug_IF`"
1020 if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then
1021 ifconfig $child create ${create_args} && cfg=0
1022 if [ -n "${debug_flags}" ]; then
1023 wlandebug -i $child ${debug_flags}
1026 i=`ifconfig wlan create ${create_args}`
1027 if [ -n "${debug_flags}" ]; then
1028 wlandebug -i $i ${debug_flags}
1030 ifconfig $i name $child && cfg=0
1032 if autoif $child; then
1037 # Create vlan interfaces
1038 child_vlans=`get_if_var $ifn vlans_IF`
1040 if [ -n "${child_vlans}" ]; then
1044 for child in ${child_vlans}; do
1045 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
1046 child="${ifn}.${child}"
1047 create_args=`get_if_var $child create_args_IF`
1048 ifconfig $child create ${create_args} && cfg=0
1050 create_args="vlandev $ifn `get_if_var $child create_args_IF`"
1051 if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
1052 ifconfig $child create ${create_args} && cfg=0
1054 i=`ifconfig vlan create ${create_args}`
1055 ifconfig $i name $child && cfg=0
1058 if autoif $child; then
1067 # Destroy child interfaces.
1071 local cfg child child_vlans child_wlans ifn
1074 child_wlans=`get_if_var $ifn wlans_IF`
1075 for child in ${child_wlans}; do
1076 if ! ifexists $child; then
1079 ifconfig -n $child destroy && cfg=0
1082 child_vlans=`get_if_var $ifn vlans_IF`
1083 for child in ${child_vlans}; do
1084 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
1085 child="${ifn}.${child}"
1087 if ! ifexists $child; then
1090 ifconfig -n $child destroy && cfg=0
1097 # Create netgraph nodes.
1101 ngctl -f - 2> /dev/null <<EOF
1108 # Create netgraph nodes.
1114 ng_mkpeer $* | while read line; do
1115 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
1116 if [ -n "${t}" ]; then
1124 # Create gif(4) tunnel interfaces.
1129 for i in ${gif_interfaces}; do
1130 peers=`get_if_var $i gifconfig_IF`
1136 if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then
1137 ifconfig $i create >/dev/null 2>&1
1139 gif=`ifconfig gif create`
1140 ifconfig $gif name $i
1142 ifconfig $i tunnel ${peers}
1150 # Configure Fast EtherChannel for interface $ifn. Returns 0 if
1151 # FEC arguments were found and configured; returns !0 otherwise.
1154 local req_iface iface bogus
1157 ngctl shutdown ${req_iface}: > /dev/null 2>&1
1161 iface=`ng_create_one fec dummy fec`
1162 if [ -z "${iface}" ]; then
1165 if [ "${iface}" = "${req_iface}" ]; then
1168 bogus="${bogus} ${iface}"
1171 for iface in ${bogus}; do
1172 ngctl shutdown ${iface}:
1177 # Create Fast EtherChannel interfaces.
1182 for i in ${fec_interfaces}; do
1184 for j in `get_if_var $i fecconfig_IF`; do
1190 ngctl msg ${i}: add_iface "\"${j}\""
1198 # Configure any IPX addresses for interface $ifn. Returns 0 if
1199 # IPX arguments were found and configured; returns 1 otherwise.
1207 ifconfig_args=`_ifconfig_getargs $ifn ipx`
1208 if [ -n "${ifconfig_args}" ]; then
1209 ifconfig ${ifn} ${ifconfig_args}
1217 # Remove IPX addresses for interface $ifn. Returns 0 if IPX
1218 # addresses were found and unconfigured. It returns 1, otherwise.
1222 local _if _ifs _ret ipxList oldifs _ipx
1226 ipxList="`ifconfig ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`"
1230 for _ipx in $ipxList ; do
1231 # get rid of extraneous line
1232 [ -z "$_ipx" ] && break
1234 _ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'`
1237 ifconfig ${_if} ${_ipx} delete
1247 # Rename all requested interfaces.
1254 for _if in `ifconfig -l`; do
1255 _ifname=`get_if_var $_if ifconfig_IF_name`
1256 if [ ! -z "$_ifname" ]; then
1257 ifconfig $_if name $_ifname
1264 # list_net_interfaces type
1265 # List all network interfaces. The type of interface returned
1266 # can be controlled by the type argument. The type
1267 # argument can be any of the following:
1268 # nodhcp - all interfaces, excluding DHCP configured interfaces
1269 # dhcp - list only DHCP configured interfaces
1270 # noautoconf - all interfaces, excluding IPv6 Stateless
1271 # Address Autoconf configured interfaces
1272 # autoconf - list only IPv6 Stateless Address Autoconf
1273 # configured interfaces
1274 # If no argument is specified all network interfaces are output.
1275 # Note that the list will include cloned interfaces if applicable.
1276 # Cloned interfaces must already exist to have a chance to appear
1277 # in the list if ${network_interfaces} is set to `auto'.
1279 list_net_interfaces()
1281 local type _tmplist _list _autolist _lo _if
1284 # Get a list of ALL the interfaces and make lo0 first if it's there.
1287 case ${network_interfaces} in
1289 _autolist="`ifconfig -l`"
1291 for _if in ${_autolist} ; do
1292 if autoif $_if; then
1293 if [ "$_if" = "lo0" ]; then
1296 _tmplist="${_tmplist} ${_if}"
1300 _tmplist="${_lo}${_tmplist# }"
1303 _tmplist="${network_interfaces} ${cloned_interfaces}"
1305 # lo0 is effectively mandatory, so help prevent foot-shooting
1308 lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
1309 *) _tmplist="lo0 ${_tmplist}" ;;
1317 for _if in ${_tmplist} ; do
1318 if ! dhcpif $_if && \
1319 [ -n "`_ifconfig_getargs $_if`" ]; then
1320 _list="${_list# } ${_if}"
1325 for _if in ${_tmplist} ; do
1326 if dhcpif $_if; then
1327 _list="${_list# } ${_if}"
1332 for _if in ${_tmplist} ; do
1333 if ! ipv6_autoconfif $_if && \
1334 [ -n "`_ifconfig_getargs $_if ipv6`" ]; then
1335 _list="${_list# } ${_if}"
1340 for _if in ${_tmplist} ; do
1341 if ipv6_autoconfif $_if; then
1342 _list="${_list# } ${_if}"
1356 # get_default_if -address_family
1357 # Get the interface of the default route for the given address family.
1358 # The -address_family argument must be suitable passing to route(8).
1362 local routeget oldifs defif line
1367 for line in `route -n get $1 default 2>/dev/null`; do
1380 # Echo decimal number $arg (single digit) in hexadecimal format.
1387 # Echo decimal number $arg (multiple digits) in hexadecimal format.
1393 is_wired_interface()
1397 case `ifconfig $1 2>/dev/null` in
1398 *media:?Ethernet*) media=Ethernet ;;
1401 test "$media" = "Ethernet"
1404 # network6_getladdr if [flag]
1405 # Echo link-local address from $if if any.
1406 # If flag is defined, tentative ones will be excluded.
1409 local proto addr rest
1410 ifconfig $1 2>/dev/null | while read proto addr rest; do
1415 if [ -z "$2" ]; then