| 1 |
# Copyright 2004-2007 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
|
| 4 |
ifconfig_depend() { |
| 5 |
program /sbin/ifconfig |
| 6 |
provide interface |
| 7 |
} |
| 8 |
|
| 9 |
_exists() { |
| 10 |
# Only FreeBSD sees to have /dev/net .... is there something |
| 11 |
# other than ifconfig we can use for the others? |
| 12 |
if [ -d /dev/net ] ; then |
| 13 |
[ -e /dev/net/"${IFACE}" ] |
| 14 |
else |
| 15 |
ifconfig "${IFACE}" >/dev/null 2>&1 |
| 16 |
fi |
| 17 |
} |
| 18 |
|
| 19 |
_get_mac_address() { |
| 20 |
local mac=$(LC_ALL=C ifconfig "${IFACE}" | \ |
| 21 |
sed -n -e 's/^[[:space:]]*ether \(..:..:..:..:..:..\).*/\1/p') |
| 22 |
|
| 23 |
case "${mac}" in |
| 24 |
00:00:00:00:00:00) ;; |
| 25 |
44:44:44:44:44:44) ;; |
| 26 |
FF:FF:FF:FF:FF:FF) ;; |
| 27 |
*) echo "${mac}"; return 0 ;; |
| 28 |
esac |
| 29 |
|
| 30 |
return 1 |
| 31 |
} |
| 32 |
|
| 33 |
_up () { |
| 34 |
ifconfig "${IFACE}" up |
| 35 |
} |
| 36 |
|
| 37 |
_down () { |
| 38 |
ifconfig "${IFACE}" down |
| 39 |
} |
| 40 |
|
| 41 |
_ifindex() { |
| 42 |
local x= i=1 |
| 43 |
case "${RC_UNAME}" in |
| 44 |
FreeBSD|DragonFly) |
| 45 |
for x in /dev/net[0-9]* ; do |
| 46 |
if [ "${x}" -ef /dev/net/"${IFACE}" ] ; then |
| 47 |
echo "${x#/dev/net}" |
| 48 |
return 0 |
| 49 |
fi |
| 50 |
done |
| 51 |
;; |
| 52 |
default) |
| 53 |
for x in $(ifconfig -a | sed -n -e 's/^\([^[:space:]]*\):.*/\1/p') ; do |
| 54 |
if [ "${x}" = "${IFACE}" ] ; then |
| 55 |
echo "${i}" |
| 56 |
return 0 |
| 57 |
fi |
| 58 |
i=$((${i} + 1)) |
| 59 |
done |
| 60 |
;; |
| 61 |
esac |
| 62 |
return 1 |
| 63 |
} |
| 64 |
|
| 65 |
_is_wireless() { |
| 66 |
LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | \ |
| 67 |
grep -q "^[[:space:]]*media: IEEE 802.11 Wireless" |
| 68 |
} |
| 69 |
|
| 70 |
_get_inet_address() { |
| 71 |
set -- $(LC_ALL=C ifconfig "${IFACE}" | |
| 72 |
sed -n -e 's/^[[:space:]]*inet \([^ ]*\) netmask 0x\(..\)\(..\)\(..\)\(..\).*/\1 0x\2.0x\3.0x\4/p') |
| 73 |
[ -z "$1" ] && return 1 |
| 74 |
|
| 75 |
echo -n "$1" |
| 76 |
shift |
| 77 |
echo "/$(_netmask2cidr "$1")" |
| 78 |
} |
| 79 |
|
| 80 |
_add_address() { |
| 81 |
if [ "${metric:-0}" != "0" ] ; then |
| 82 |
set -- "$@" metric ${metric} |
| 83 |
fi |
| 84 |
|
| 85 |
# ifconfig doesn't like CIDR addresses |
| 86 |
case "${RC_UNAME}" in |
| 87 |
NetBSD|OpenBSD) |
| 88 |
local ip="${1%%/*}" cidr="${1##*/}" netmask= |
| 89 |
if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then |
| 90 |
netmask="$(_cidr2netmask "${cidr}")" |
| 91 |
shift |
| 92 |
set -- "${ip}" netmask "${netmask}" "$@" |
| 93 |
fi |
| 94 |
;; |
| 95 |
esac |
| 96 |
|
| 97 |
case "$@" in |
| 98 |
*:*) ifconfig "${IFACE}" inet6 "$@" ;; |
| 99 |
*) ifconfig "${IFACE}" "$@" ;; |
| 100 |
esac |
| 101 |
} |
| 102 |
|
| 103 |
_add_route() { |
| 104 |
if [ $# -gt 3 ] ; then |
| 105 |
if [ "$3" = "gw" -o "$3" = "via" ] ; then |
| 106 |
local one=$1 two=$2 |
| 107 |
shift ; shift; shift |
| 108 |
set -- "${one}" "${two}" "$@" |
| 109 |
fi |
| 110 |
fi |
| 111 |
|
| 112 |
case "$@" in |
| 113 |
*:*) route add -inet6 "$@" ;; |
| 114 |
*) route add "$@" ;; |
| 115 |
esac |
| 116 |
} |
| 117 |
|
| 118 |
_delete_addresses() { |
| 119 |
# We don't remove addresses from aliases |
| 120 |
case "${IFACE}" in |
| 121 |
*:*) return 0 ;; |
| 122 |
esac |
| 123 |
|
| 124 |
einfo "Removing addresses" |
| 125 |
eindent |
| 126 |
local addr= |
| 127 |
for addr in $(LC_ALL=C ifconfig "${IFACE}" | |
| 128 |
sed -n -e 's/^[[:space:]]*inet \([^ ]*\).*/\1/p') ; do |
| 129 |
if [ "${addr}" = "127.0.0.1" ] ; then |
| 130 |
# Don't delete the loopback address |
| 131 |
[ "$1" = "lo" -o "$1" = "lo0" ] && continue |
| 132 |
fi |
| 133 |
einfo "${addr}" |
| 134 |
ifconfig "$1" delete "${addr}" |
| 135 |
eend $? |
| 136 |
done |
| 137 |
|
| 138 |
# Remove IPv6 addresses |
| 139 |
for addr in $(LC_ALL=C ifconfig "${IFACE}" | \ |
| 140 |
sed -n -e 's/^[[:space:]]*inet6 \([^ ]*\).*/\1/p') ; do |
| 141 |
case "${addr}" in |
| 142 |
*"%${IFACE}") continue ;; |
| 143 |
::1) continue ;; |
| 144 |
esac |
| 145 |
einfo "${addr}" |
| 146 |
ifconfig "${IFACE}" inet6 delete "${addr}" |
| 147 |
eend $? |
| 148 |
done |
| 149 |
|
| 150 |
return 0 |
| 151 |
} |
| 152 |
|
| 153 |
_show_address() { |
| 154 |
einfo "received address $(_get_inet_address "${IFACE}")" |
| 155 |
} |
| 156 |
|
| 157 |
_has_carrier() { |
| 158 |
local s=$(LC_ALL=C ifconfig "${IFACE}" | \ |
| 159 |
sed -n -e 's/^[[:space:]]status: \(.*\)$/\1/p') |
| 160 |
[ -z "${s}" -o "${s}" = "active" -o "${s}" = "associated" ] |
| 161 |
} |
| 162 |
|
| 163 |
# vim: set ts=4 : |