/[baselayout]/trunk/net.Linux/iproute2.sh
Gentoo

Contents of /trunk/net.Linux/iproute2.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2754 - (show annotations) (download) (as text)
Mon Jul 9 09:14:19 2007 UTC (7 years, 5 months ago) by uberlord
File MIME type: text/x-sh
File size: 3625 byte(s)
Fix iproute handling of -host and improve iwconfig scanning
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 iproute2_depend() {
5 program /sbin/ip
6 provide interface
7 after ifconfig
8 }
9
10 _up() {
11 ip link set up dev "${IFACE}"
12 }
13
14 _down() {
15 ip link set down dev "${IFACE}"
16 }
17
18 _exists() {
19 grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/dev
20 }
21
22 _ifindex() {
23 local line= i=-2
24 while read line ; do
25 i=$((${i} + 1))
26 [ ${i} -lt 1 ] && continue
27 case "${line}" in
28 "${IFACE}:"*) echo "${i}"; return 0;;
29 esac
30 done < /proc/net/dev
31 return 1
32 }
33
34 _is_wireless() {
35 # Support new sysfs layout
36 [ -d /sys/class/net/"${IFACE}"/wireless ] && return 0
37
38 [ ! -e /proc/net/wireless ] && return 1
39 grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
40 }
41
42 _get_mac_address() {
43 local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \
44 -e 'y/abcdef/ABCDEF/' \
45 -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
46
47 case "${mac}" in
48 00:00:00:00:00:00) ;;
49 44:44:44:44:44:44) ;;
50 FF:FF:FF:FF:FF:FF) ;;
51 "") ;;
52 *) echo "${mac}"; return 0 ;;
53 esac
54
55 return 1
56 }
57
58 _set_mac_address() {
59 ip link set address "$1" dev "${IFACE}"
60 }
61
62 _get_inet_addresses() {
63 LC_ALL=C ip -family inet addr show "${IFACE}" | \
64 sed -n -e 's/.*inet \([^ ]*\).*/\1/p'
65 }
66
67 _get_inet_address() {
68 set -- $(_get_inet_addresses)
69 [ $# = "0" ] && return 1
70 echo "$1"
71 }
72
73 _add_address() {
74 if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ] ; then
75 ip addr add "$@" dev "${IFACE}" 2>/dev/null
76 return 0
77 fi
78
79 # Convert an ifconfig line to iproute2
80 if [ "$2" = "netmask" ] ; then
81 local one="$1" three="$3"
82 shift ; shift ; shift
83 set -- "${one}/$(_netmask2cidr "${three}")" "$@"
84 fi
85
86 #config=( "${config[@]//pointopoint/peer}" )
87
88 # Always scope lo addresses as host unless specified otherwise
89 if [ "${IFACE}" = "lo" ] ; then
90 set -- "$@" "scope" "host"
91 fi
92
93 # IPv4 specifics
94 case "$1" in
95 *.*.*.*)
96 case "$@" in
97 *" brd "*) ;;
98 *" broadcast "*) ;;
99 *) set -- "$@" brd + ;;
100 esac
101 ;;
102 esac
103
104 ip addr add dev "${IFACE}" "$@"
105 }
106
107 _add_route() {
108 if [ $# -eq 3 ] ; then
109 set -- "$1" "$2" via "$3"
110 elif [ "$3" = "gw" ] ; then
111 local one=$1 two=$2
112 shift ; shift; shift
113 set -- "${one}" "${two}" gw "$@"
114 fi
115
116 local cmd= have_metric=false
117 while [ -n "$1" ] ; do
118 case "$1" in
119 metric) cmd="${cmd} $1"; have_metric=true ;;
120 netmask) cmd="${cmd}/$(_netmask2cidr "$2")"; shift ;;
121 -host|-net) ;;
122 -A) [ "$2" = "inet6" ] && shift ;;
123 *) cmd="${cmd} $1" ;;
124 esac
125 shift
126 done
127
128 if ! ${have_metric} && [ -n "${metric}" ] ; then
129 cmd="${cmd} metric ${metric}"
130 fi
131
132 ip route append ${cmd} dev "${IFACE}"
133 eend $?
134 }
135
136 _delete_addresses() {
137 ip addr flush dev "${IFACE}" scope global 2>/dev/null
138 ip addr flush dev "${IFACE}" scope site 2>/dev/null
139 if [ "${IFACE}" != "lo" ] ; then
140 ip addr flush dev "${IFACE}" scope host 2>/dev/null
141 fi
142 return 0
143 }
144
145 _has_carrier() {
146 return 0
147 }
148
149 _tunnel() {
150 ip tunnel "$@"
151 }
152
153 iproute2_pre_start() {
154 # MTU support
155 local mtu=
156 eval mtu=\$mtu_${IFVAR}
157 [ -n "${mtu}" ] && ip link set mtu "${mtu}" dev "${IFACE}"
158
159 local tunnel=
160 eval tunnel=\$iptunnel_${IFVAR}
161 if [ -n "${tunnel}" ] ; then
162 # Set our base metric to 1000
163 metric=1000
164
165 ebegin "Creating tunnel ${IFVAR}"
166 ip tunnel add ${tunnel} name "${IFACE}"
167 eend $? || return 1
168 _up
169 fi
170
171 return 0
172 }
173
174 iproute2_post_start() {
175 ip route flush cache dev "${IFACE}"
176 }
177
178 iproute2_post_stop() {
179 # Don't delete sit0 as it's a special tunnel
180 if [ "${IFACE}" != "sit0" ] ; then
181 if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ] ; then
182 ebegin "Destroying tunnel ${IFACE}"
183 ip tunnel del "${IFACE}"
184 eend $?
185 fi
186 fi
187 }
188
189 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20