/[baselayout]/trunk/net.BSD/ifconfig.sh
Gentoo

Contents of /trunk/net.BSD/ifconfig.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2813 - (show annotations) (download) (as text)
Fri Aug 3 13:54:46 2007 UTC (7 years, 2 months ago) by uberlord
File MIME type: text/x-sh
File size: 3331 byte(s)
Fix adding multiple IP addresses, #187526.
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 local inet6=
82
83 case "$@" in
84 *:*) inet6=inet6 ;;
85 esac
86
87 if [ "${metric:-0}" != "0" ] ; then
88 set -- "$@" metric ${metric}
89 fi
90
91 # ifconfig doesn't like CIDR addresses
92 case "${RC_UNAME}" in
93 NetBSD|OpenBSD)
94 local ip="${1%%/*}" cidr="${1##*/}" netmask=
95 if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then
96 netmask="$(_cidr2netmask "${cidr}")"
97 shift
98 set -- "${ip}" netmask "${netmask}" "$@"
99 fi
100 ;;
101 esac
102
103 ifconfig "${IFACE}" ${inet6} alias "$@"
104 }
105
106 _add_route() {
107 if [ $# -gt 3 ] ; then
108 if [ "$3" = "gw" -o "$3" = "via" ] ; then
109 local one=$1 two=$2
110 shift ; shift; shift
111 set -- "${one}" "${two}" "$@"
112 fi
113 fi
114
115 case "$@" in
116 *:*) route add -inet6 "$@" ;;
117 *) route add "$@" ;;
118 esac
119 }
120
121 _delete_addresses() {
122 # We don't remove addresses from aliases
123 case "${IFACE}" in
124 *:*) return 0 ;;
125 esac
126
127 einfo "Removing addresses"
128 eindent
129 local addr=
130 for addr in $(LC_ALL=C ifconfig "${IFACE}" |
131 sed -n -e 's/^[[:space:]]*inet \([^ ]*\).*/\1/p') ; do
132 if [ "${addr}" = "127.0.0.1" ] ; then
133 # Don't delete the loopback address
134 [ "$1" = "lo" -o "$1" = "lo0" ] && continue
135 fi
136 einfo "${addr}"
137 ifconfig "$1" delete "${addr}"
138 eend $?
139 done
140
141 # Remove IPv6 addresses
142 for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
143 sed -n -e 's/^[[:space:]]*inet6 \([^ ]*\).*/\1/p') ; do
144 case "${addr}" in
145 *"%${IFACE}") continue ;;
146 ::1) continue ;;
147 esac
148 einfo "${addr}"
149 ifconfig "${IFACE}" inet6 delete "${addr}"
150 eend $?
151 done
152
153 return 0
154 }
155
156 _show_address() {
157 einfo "received address $(_get_inet_address "${IFACE}")"
158 }
159
160 _has_carrier() {
161 local s=$(LC_ALL=C ifconfig "${IFACE}" | \
162 sed -n -e 's/^[[:space:]]status: \(.*\)$/\1/p')
163 [ -z "${s}" -o "${s}" = "active" -o "${s}" = "associated" ]
164 }
165
166 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20