2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
ifconfig_depend()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
program /sbin/ifconfig
|
|
|
|
provide interface
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_exists()
|
|
|
|
{
|
2007-07-26 02:28:23 +05:30
|
|
|
# Only FreeBSD sees to have /dev/net .... is there something
|
|
|
|
# other than ifconfig we can use for the others?
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -d /dev/net ]; then
|
2007-07-26 02:28:23 +05:30
|
|
|
[ -e /dev/net/"${IFACE}" ]
|
|
|
|
else
|
|
|
|
ifconfig "${IFACE}" >/dev/null 2>&1
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_up()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
ifconfig "${IFACE}" up
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_down()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
ifconfig "${IFACE}" down
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_ifindex()
|
|
|
|
{
|
2007-07-26 02:28:23 +05:30
|
|
|
local x= i=1
|
|
|
|
case "${RC_UNAME}" in
|
|
|
|
FreeBSD|DragonFly)
|
2007-11-28 21:15:03 +05:30
|
|
|
for x in /dev/net[0-9]*; do
|
|
|
|
if [ "${x}" -ef /dev/net/"${IFACE}" ]; then
|
2007-07-26 02:28:23 +05:30
|
|
|
echo "${x#/dev/net}"
|
|
|
|
return 0
|
|
|
|
fi
|
2011-11-11 08:16:08 +05:30
|
|
|
: $(( i += 1 ))
|
2007-07-26 02:28:23 +05:30
|
|
|
done
|
|
|
|
;;
|
|
|
|
default)
|
2007-12-04 19:49:47 +05:30
|
|
|
for x in $(ifconfig -l); do
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ "${x}" = "${IFACE}" ]; then
|
2007-07-26 02:28:23 +05:30
|
|
|
echo "${i}"
|
|
|
|
return 0
|
|
|
|
fi
|
2011-11-11 08:16:08 +05:30
|
|
|
: $(( i += 1 ))
|
2007-07-26 02:28:23 +05:30
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
2007-08-08 02:34:27 +05:30
|
|
|
|
|
|
|
# Return the next available index
|
|
|
|
echo "${i}"
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_ifconfig_ent()
|
|
|
|
{
|
2007-12-04 19:49:47 +05:30
|
|
|
LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | while read ent rest; do
|
|
|
|
case "${ent}" in
|
2008-03-11 05:34:49 +05:30
|
|
|
$1) echo "${rest}";;
|
2007-12-04 19:49:47 +05:30
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2008-03-11 05:34:49 +05:30
|
|
|
_get_mac_address()
|
|
|
|
{
|
|
|
|
local ent="ether"
|
|
|
|
case "${RC_UNAME}" in
|
|
|
|
NetBSD|OpenBSD) ent="address:";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $(_ifconfig_ent "${ent}") in
|
|
|
|
00:00:00:00:00:00);;
|
|
|
|
44:44:44:44:44:44);;
|
|
|
|
FF:FF:FF:FF:FF:FF);;
|
|
|
|
"") return 1;;
|
|
|
|
*) echo "${address}";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_is_wireless()
|
|
|
|
{
|
2007-12-04 19:49:47 +05:30
|
|
|
case "$(_ifconfig_ent "media:")" in
|
2008-01-11 23:05:39 +05:30
|
|
|
IEEE802.11*|"IEEE 802.11 Wireless"*) return 0;;
|
2007-12-04 19:49:47 +05:30
|
|
|
*) return 1;;
|
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_get_inet_address()
|
|
|
|
{
|
2007-12-04 19:49:47 +05:30
|
|
|
local inet= address= n= netmask= rest=
|
|
|
|
LC_ALL=C ifconfig "${IFACE}" | while read inet address n netmask rest; do
|
|
|
|
if [ "${inet}" = "inet" ]; then
|
|
|
|
echo "${address}/$(_netmask2cidr "${netmask}")"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_add_address()
|
|
|
|
{
|
2007-08-03 19:24:46 +05:30
|
|
|
local inet6=
|
|
|
|
|
|
|
|
case "$@" in
|
2007-11-28 21:15:03 +05:30
|
|
|
*:*) inet6=inet6;;
|
2007-08-03 19:24:46 +05:30
|
|
|
esac
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ "${metric:-0}" != "0" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
set -- "$@" metric ${metric}
|
|
|
|
fi
|
|
|
|
|
2007-07-26 02:28:23 +05:30
|
|
|
# ifconfig doesn't like CIDR addresses
|
|
|
|
case "${RC_UNAME}" in
|
2008-01-11 04:52:46 +05:30
|
|
|
OpenBSD)
|
2007-07-26 02:28:23 +05:30
|
|
|
local ip="${1%%/*}" cidr="${1##*/}" netmask=
|
|
|
|
if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then
|
|
|
|
netmask="$(_cidr2netmask "${cidr}")"
|
|
|
|
shift
|
|
|
|
set -- "${ip}" netmask "${netmask}" "$@"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2007-12-04 15:25:59 +05:30
|
|
|
ifconfig "${IFACE}" ${inet6} "$@" alias
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_add_route()
|
|
|
|
{
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ $# -gt 3 ]; then
|
|
|
|
if [ "$3" = "gw" -o "$3" = "via" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
local one=$1 two=$2
|
2007-11-28 21:15:03 +05:30
|
|
|
shift; shift; shift
|
2007-04-05 16:48:42 +05:30
|
|
|
set -- "${one}" "${two}" "$@"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2007-07-06 23:33:17 +05:30
|
|
|
case "$@" in
|
2007-11-28 21:15:03 +05:30
|
|
|
*:*) route add -inet6 "$@";;
|
|
|
|
*) route add "$@";;
|
2007-07-06 23:33:17 +05:30
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_delete_addresses()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "Removing addresses"
|
|
|
|
eindent
|
2008-04-23 18:47:13 +05:30
|
|
|
LC_ALL=C ifconfig "${IFACE}" | while read inet address ali rest; do
|
2007-12-04 19:49:47 +05:30
|
|
|
case "${inet}" in
|
|
|
|
inet|inet6)
|
2008-04-23 18:47:13 +05:30
|
|
|
if [ "${address}" = "alias" ]; then
|
|
|
|
address="${ali}"
|
|
|
|
fi
|
2007-12-04 19:49:47 +05:30
|
|
|
case "${address}" in
|
|
|
|
*"%${IFACE}"|::1) continue;;
|
|
|
|
127.0.0.1) [ "${IFACE}" = "lo0" ] && continue;;
|
|
|
|
esac
|
|
|
|
einfo "${address}"
|
|
|
|
ifconfig "${IFACE}" "${inet}" "${address}" -alias
|
|
|
|
eend $?
|
|
|
|
;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
done
|
2007-09-25 17:50:25 +05:30
|
|
|
eoutdent
|
2007-04-05 16:48:42 +05:30
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_show_address()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "received address $(_get_inet_address "${IFACE}")"
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_has_carrier()
|
|
|
|
{
|
2007-12-04 19:49:47 +05:30
|
|
|
case "$(_ifconfig_ent "status:")" in
|
|
|
|
""|active|associated) return 0;;
|
|
|
|
*) return 1;;
|
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
ifconfig_pre_start()
|
|
|
|
{
|
2007-11-22 18:55:20 +05:30
|
|
|
local config="$(_get_array "ifconfig_${IFVAR}")" conf= arg= args=
|
|
|
|
local IFS="$__IFS"
|
|
|
|
|
|
|
|
[ -z "${config}" ] && return 0
|
|
|
|
|
|
|
|
veinfo "Running ifconfig commands"
|
|
|
|
eindent
|
|
|
|
for conf in ${config}; do
|
|
|
|
unset IFS
|
|
|
|
args=
|
|
|
|
for arg in ${conf}; do
|
|
|
|
case ${arg} in
|
2007-11-28 21:15:03 +05:30
|
|
|
[Dd][Hh][Cc][Pp]);;
|
|
|
|
[Nn][Oo][Aa][Uu][Tt][Oo]);;
|
|
|
|
[Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]);;
|
|
|
|
[Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]);;
|
|
|
|
[Ww][Pp][Aa]);;
|
2007-11-22 18:55:20 +05:30
|
|
|
*) args="${args} ${arg}";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ -z "${args}" ] && continue
|
|
|
|
vebegin "ifconfig${args}"
|
|
|
|
eval ifconfig "${IFACE}" "${args}"
|
|
|
|
veend $?
|
|
|
|
done
|
|
|
|
eoutdent
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_ifconfig_ipv6_tentative()
|
|
|
|
{
|
2007-12-04 19:49:47 +05:30
|
|
|
local inet= address= rest=
|
|
|
|
LC_ALL=C ifconfig "${IFACE}" | while read inet address rest; do
|
|
|
|
case "${inet}" in
|
|
|
|
inet6)
|
|
|
|
case "${rest}" in
|
|
|
|
*" "tentative*) return 2;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
[ $? = 2 ]
|
2007-12-04 15:25:59 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
ifconfig_post_start()
|
|
|
|
{
|
2007-12-04 15:25:59 +05:30
|
|
|
if _ifconfig_ipv6_tentative; then
|
|
|
|
ebegin "Waiting for IPv6 addresses"
|
|
|
|
while true; do
|
|
|
|
_ifconfig_ipv6_tentative || break
|
|
|
|
done
|
|
|
|
eend 0
|
|
|
|
fi
|
2007-12-03 23:32:57 +05:30
|
|
|
}
|
2011-12-13 08:18:11 +05:30
|
|
|
|
|
|
|
# Is the interface administratively/operationally up?
|
|
|
|
# The 'UP' status in ifconfig is the administrative status
|
|
|
|
# Operational state does not seem to be available in BSD?
|
|
|
|
# 0: up
|
|
|
|
# 1: down
|
|
|
|
# 2: invalid arguments
|
|
|
|
is_admin_up()
|
|
|
|
{
|
|
|
|
local iface="$1"
|
|
|
|
[ -z "$iface" ] && iface="$IFACE"
|
|
|
|
ifconfig "${iface}" | \
|
|
|
|
sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; '
|
|
|
|
}
|
|
|
|
|
|
|
|
is_oper_up()
|
|
|
|
{
|
|
|
|
eerror "TODO: is_oper_up not available on BSD"
|
|
|
|
return 2
|
|
|
|
}
|