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)
507 if checkyesno ipv6_gateway_enable; then
515 _tmpargs=`_ifconfig_getargs $_if ipv6`
516 for _arg in $_tmpargs; do
524 # backward compatibility: $ipv6_ifconfig_IF
525 _tmpargs=`get_if_var $_if ipv6_ifconfig_IF`
526 for _arg in $_tmpargs; do
538 # Returns 0 if the interface exists and 1 otherwise.
541 [ -z "$1" ] && return 1
542 ifconfig -n $1 > /dev/null 2>&1
546 # add IPv4 addresses to the interface $if
553 # Add 127.0.0.1/8 to lo0 unless otherwise specified.
554 if [ "${_if}" = "lo0" ]; then
555 ifconfig_args=`get_if_var ${_if} ifconfig_IF`
556 if [ -z "${ifconfig_args}" ]; then
557 ifconfig ${_if} inet 127.0.0.1/8 alias
560 ifalias_up ${_if} inet && _ret=0
561 ipv4_addrs_common ${_if} alias && _ret=0
567 # add IPv6 addresses to the interface $if
574 if ! ipv6if $_if; then
578 ifalias_up ${_if} inet6 && _ret=0
579 ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0
580 ipv6_accept_rtadv_up ${_if} && _ret=0
586 # remove IPv4 addresses from the interface $if
589 local _if _ifs _ret inetList oldifs _inet
594 inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
598 for _inet in $inetList ; do
599 # get rid of extraneous line
600 [ -z "$_inet" ] && break
602 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
605 ifconfig ${_if} ${_inet} delete
611 ifalias_down ${_if} inet && _ret=0
612 ipv4_addrs_common ${_if} -alias && _ret=0
618 # remove IPv6 addresses from the interface $if
621 local _if _ifs _ret inetList oldifs _inet6
626 if ! ipv6if $_if; then
630 ipv6_accept_rtadv_down ${_if} && _ret=0
631 ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0
632 ifalias_down ${_if} inet6 && _ret=0
634 inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`"
638 for _inet6 in $inetList ; do
639 # get rid of extraneous line
640 [ -z "$_inet6" ] && break
642 _inet6=`expr "$_inet6" : '.*\(inet6 \([0-9a-f:]*\)\).*'`
645 ifconfig ${_if} ${_inet6} -alias
654 # ipv4_addrs_common if action
655 # Evaluate the ifconfig_if_ipv4 arguments for interface $if and
656 # use $action to add or remove IPv4 addresses from $if.
659 local _ret _if _action _cidr _cidr_addr
660 local _ipaddr _netmask _range _ipnet _iplow _iphigh _ipcount
666 cidr_addr=`get_if_var $_if ipv4_addrs_IF`
668 for _cidr in ${cidr_addr}; do
670 _netmask="/"${_cidr##*/}
671 _range=${_ipaddr##*.}
676 # clear netmask when removing aliases
677 if [ "${_action}" = "-alias" ]; then
682 while [ "${_ipcount}" -le "${_iphigh}" ]; do
683 eval "ifconfig ${_if} ${_action} ${_ipnet}.${_ipcount}${_netmask}"
684 _ipcount=$((${_ipcount}+1))
687 # only the first ipaddr in a subnet need the real netmask
688 if [ "${_action}" != "-alias" ]; then
698 # Configure aliases for network interface $if.
699 # It returns 0 if at least one alias was configured or
700 # 1 if there were none.
709 _ret=`ifalias_ipv4_up "$1"`
712 _ret=`ifalias_ipv6_up "$1"`
720 # Helper function for ifalias_up(). Handles IPv4.
724 local _ret alias ifconfig_args
727 # ifconfig_IF_aliasN which starts with "inet"
730 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
731 case "${ifconfig_args}" in
733 ifconfig $1 ${ifconfig_args} alias && _ret=0
741 warn "\$ifconfig_$1_alias${alias} needs " \
742 "\"inet\" keyword for an IPv4 address."
743 ifconfig $1 ${ifconfig_args} alias && _ret=0
746 alias=$((${alias} + 1))
753 # Helper function for ifalias_up(). Handles IPv6.
757 local _ret alias ifconfig_args
760 # ifconfig_IF_aliasN which starts with "inet6"
763 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
764 case "${ifconfig_args}" in
766 ifconfig $1 ${ifconfig_args} alias && _ret=0
772 alias=$((${alias} + 1))
775 # backward compatibility: ipv6_ifconfig_IF_aliasN.
778 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
779 case "${ifconfig_args}" in
784 ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0
785 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
786 " Use ifconfig_$1_aliasN instead."
789 alias=$((${alias} + 1))
796 # Remove aliases for network interface $if.
797 # It returns 0 if at least one alias was removed or
798 # 1 if there were none.
807 _ret=`ifalias_ipv4_down "$1"`
810 _ret=`ifalias_ipv6_down "$1"`
817 # ifalias_ipv4_down if
818 # Helper function for ifalias_down(). Handles IPv4.
822 local _ret alias ifconfig_args
825 # ifconfig_IF_aliasN which starts with "inet"
828 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
829 case "${ifconfig_args}" in
831 ifconfig $1 ${ifconfig_args} -alias && _ret=0
837 alias=$((${alias} + 1))
843 # ifalias_ipv6_down if
844 # Helper function for ifalias_down(). Handles IPv6.
848 local _ret alias ifconfig_args
851 # ifconfig_IF_aliasN which starts with "inet6"
854 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
855 case "${ifconfig_args}" in
857 ifconfig $1 ${ifconfig_args} -alias && _ret=0
863 alias=$((${alias} + 1))
866 # backward compatibility: ipv6_ifconfig_IF_aliasN.
869 ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
870 case "${ifconfig_args}" in
875 ifconfig $1 inet6 ${ifconfig_args} -alias && _ret=0
876 warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
877 " Use ifconfig_$1_aliasN instead."
880 alias=$((${alias} + 1))
886 # ipv6_prefix_hostid_addr_common if action
887 # Add or remove IPv6 prefix + hostid addr on the interface $if
889 ipv6_prefix_hostid_addr_common()
891 local _if _action prefix laddr hostid j address
894 prefix=`get_if_var ${_if} ipv6_prefix_IF`
896 if [ -n "${prefix}" ]; then
897 laddr=`network6_getladdr ${_if}`
898 hostid=${laddr#fe80::}
901 for j in ${prefix}; do
902 address=$j\:${hostid}
903 ifconfig ${_if} inet6 ${address} prefixlen 64 ${_action}
905 # if I am a router, add subnet router
906 # anycast address (RFC 2373).
907 if checkyesno ipv6_gateway_enable; then
908 ifconfig ${_if} inet6 $j:: prefixlen 64 \
915 # ipv6_accept_rtadv_up if
916 # Enable accepting Router Advertisement and send Router
917 # Solicitation message
918 ipv6_accept_rtadv_up()
920 if ipv6_autoconfif $1; then
921 ifconfig $1 inet6 accept_rtadv up
922 if ! checkyesno rtsold_enable; then
923 rtsol ${rtsol_flags} $1
928 # ipv6_accept_rtadv_down if
929 # Disable accepting Router Advertisement
930 ipv6_accept_rtadv_down()
932 if ipv6_autoconfif $1; then
933 ifconfig $1 inet6 -accept_rtadv
938 # Evaluate a startup script for the $if interface.
939 # It returns 0 if a script was found and processed or
940 # 1 if no script was found.
944 if [ -r /etc/start_if.$1 ]; then
953 # Evaluate a shutdown script for the $if interface.
954 # It returns 0 if a script was found and processed or
955 # 1 if no script was found.
959 if [ -r /etc/stop_if.$1 ]; then
968 # Create cloneable interfaces.
972 local _prefix _list ifn
977 for ifn in ${cloned_interfaces}; do
978 ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF`
979 if [ $? -eq 0 ]; then
980 _list="${_list}${_prefix}${ifn}"
981 [ -z "$_prefix" ] && _prefix=' '
984 debug "Cloned: ${_list}"
988 # Destroy cloned interfaces. Destroyed interfaces are echoed to
993 local _prefix _list ifn
997 for ifn in ${cloned_interfaces}; do
998 ifconfig -n ${ifn} destroy
999 if [ $? -eq 0 ]; then
1000 _list="${_list}${_prefix}${ifn}"
1001 [ -z "$_prefix" ] && _prefix=' '
1004 debug "Destroyed clones: ${_list}"
1008 # Create and configure child interfaces. Return 0 if child
1009 # interfaces are created.
1013 local cfg child child_vlans child_wlans create_args debug_flags ifn i
1017 # Create wireless interfaces
1018 child_wlans=`get_if_var $ifn wlans_IF`
1020 for child in ${child_wlans}; do
1021 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
1022 debug_flags="`get_if_var $child wlandebug_IF`"
1024 if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then
1025 ifconfig $child create ${create_args} && cfg=0
1026 if [ -n "${debug_flags}" ]; then
1027 wlandebug -i $child ${debug_flags}
1030 i=`ifconfig wlan create ${create_args}`
1031 if [ -n "${debug_flags}" ]; then
1032 wlandebug -i $i ${debug_flags}
1034 ifconfig $i name $child && cfg=0
1036 if autoif $child; then
1041 # Create vlan interfaces
1042 child_vlans=`get_if_var $ifn vlans_IF`
1044 if [ -n "${child_vlans}" ]; then
1048 for child in ${child_vlans}; do
1049 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
1050 child="${ifn}.${child}"
1051 create_args=`get_if_var $child create_args_IF`
1052 ifconfig $child create ${create_args} && cfg=0
1054 create_args="vlandev $ifn `get_if_var $child create_args_IF`"
1055 if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
1056 ifconfig $child create ${create_args} && cfg=0
1058 i=`ifconfig vlan create ${create_args}`
1059 ifconfig $i name $child && cfg=0
1062 if autoif $child; then
1071 # Destroy child interfaces.
1075 local cfg child child_vlans child_wlans ifn
1078 child_wlans=`get_if_var $ifn wlans_IF`
1079 for child in ${child_wlans}; do
1080 if ! ifexists $child; then
1083 ifconfig -n $child destroy && cfg=0
1086 child_vlans=`get_if_var $ifn vlans_IF`
1087 for child in ${child_vlans}; do
1088 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
1089 child="${ifn}.${child}"
1091 if ! ifexists $child; then
1094 ifconfig -n $child destroy && cfg=0
1101 # Create netgraph nodes.
1105 ngctl -f - 2> /dev/null <<EOF
1112 # Create netgraph nodes.
1118 ng_mkpeer $* | while read line; do
1119 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
1120 if [ -n "${t}" ]; then
1128 # Create gif(4) tunnel interfaces.
1133 for i in ${gif_interfaces}; do
1134 peers=`get_if_var $i gifconfig_IF`
1140 if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then
1141 ifconfig $i create >/dev/null 2>&1
1143 gif=`ifconfig gif create`
1144 ifconfig $gif name $i
1146 ifconfig $i tunnel ${peers}
1154 # Configure Fast EtherChannel for interface $ifn. Returns 0 if
1155 # FEC arguments were found and configured; returns !0 otherwise.
1158 local req_iface iface bogus
1161 ngctl shutdown ${req_iface}: > /dev/null 2>&1
1165 iface=`ng_create_one fec dummy fec`
1166 if [ -z "${iface}" ]; then
1169 if [ "${iface}" = "${req_iface}" ]; then
1172 bogus="${bogus} ${iface}"
1175 for iface in ${bogus}; do
1176 ngctl shutdown ${iface}:
1181 # Create Fast EtherChannel interfaces.
1186 for i in ${fec_interfaces}; do
1188 for j in `get_if_var $i fecconfig_IF`; do
1194 ngctl msg ${i}: add_iface "\"${j}\""
1202 # Configure any IPX addresses for interface $ifn. Returns 0 if
1203 # IPX arguments were found and configured; returns 1 otherwise.
1211 ifconfig_args=`_ifconfig_getargs $ifn ipx`
1212 if [ -n "${ifconfig_args}" ]; then
1213 ifconfig ${ifn} ${ifconfig_args}
1221 # Remove IPX addresses for interface $ifn. Returns 0 if IPX
1222 # addresses were found and unconfigured. It returns 1, otherwise.
1226 local _if _ifs _ret ipxList oldifs _ipx
1230 ipxList="`ifconfig ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`"
1234 for _ipx in $ipxList ; do
1235 # get rid of extraneous line
1236 [ -z "$_ipx" ] && break
1238 _ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'`
1241 ifconfig ${_if} ${_ipx} delete
1251 # Rename all requested interfaces.
1258 for _if in `ifconfig -l`; do
1259 _ifname=`get_if_var $_if ifconfig_IF_name`
1260 if [ ! -z "$_ifname" ]; then
1261 ifconfig $_if name $_ifname
1268 # list_net_interfaces type
1269 # List all network interfaces. The type of interface returned
1270 # can be controlled by the type argument. The type
1271 # argument can be any of the following:
1272 # nodhcp - all interfaces, excluding DHCP configured interfaces
1273 # dhcp - list only DHCP configured interfaces
1274 # noautoconf - all interfaces, excluding IPv6 Stateless
1275 # Address Autoconf configured interfaces
1276 # autoconf - list only IPv6 Stateless Address Autoconf
1277 # configured interfaces
1278 # If no argument is specified all network interfaces are output.
1279 # Note that the list will include cloned interfaces if applicable.
1280 # Cloned interfaces must already exist to have a chance to appear
1281 # in the list if ${network_interfaces} is set to `auto'.
1283 list_net_interfaces()
1285 local type _tmplist _list _autolist _lo _if
1288 # Get a list of ALL the interfaces and make lo0 first if it's there.
1291 case ${network_interfaces} in
1293 _autolist="`ifconfig -l`"
1295 for _if in ${_autolist} ; do
1296 if autoif $_if; then
1297 if [ "$_if" = "lo0" ]; then
1300 _tmplist="${_tmplist} ${_if}"
1304 _tmplist="${_lo}${_tmplist# }"
1307 _tmplist="${network_interfaces} ${cloned_interfaces}"
1309 # lo0 is effectively mandatory, so help prevent foot-shooting
1312 lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
1313 *) _tmplist="lo0 ${_tmplist}" ;;
1321 for _if in ${_tmplist} ; do
1322 if ! dhcpif $_if && \
1323 [ -n "`_ifconfig_getargs $_if`" ]; then
1324 _list="${_list# } ${_if}"
1329 for _if in ${_tmplist} ; do
1330 if dhcpif $_if; then
1331 _list="${_list# } ${_if}"
1336 for _if in ${_tmplist} ; do
1337 if ! ipv6_autoconfif $_if && \
1338 [ -n "`_ifconfig_getargs $_if ipv6`" ]; then
1339 _list="${_list# } ${_if}"
1344 for _if in ${_tmplist} ; do
1345 if ipv6_autoconfif $_if; then
1346 _list="${_list# } ${_if}"
1360 # get_default_if -address_family
1361 # Get the interface of the default route for the given address family.
1362 # The -address_family argument must be suitable passing to route(8).
1366 local routeget oldifs defif line
1371 for line in `route -n get $1 default 2>/dev/null`; do
1384 # Echo decimal number $arg (single digit) in hexadecimal format.
1391 # Echo decimal number $arg (multiple digits) in hexadecimal format.
1397 is_wired_interface()
1401 case `ifconfig $1 2>/dev/null` in
1402 *media:?Ethernet*) media=Ethernet ;;
1405 test "$media" = "Ethernet"
1408 # network6_getladdr if [flag]
1409 # Echo link-local address from $if if any.
1410 # If flag is defined, tentative ones will be excluded.
1413 local proto addr rest
1414 ifconfig $1 2>/dev/null | while read proto addr rest; do
1419 if [ -z "$2" ]; then