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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3087 - (hide annotations) (download) (as text)
Fri Nov 2 07:26:51 2007 UTC (6 years, 10 months ago) by uberlord
File MIME type: text/x-sh
File size: 4064 byte(s)
Fixor IP comment and logic thanks to vapier
1 uberlord 2547 # Copyright 2004-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3    
4     iproute2_depend() {
5 uberlord 2812 program /sbin/ip
6 uberlord 2547 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 uberlord 2610 grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/dev
20 uberlord 2547 }
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 uberlord 2610 "${IFACE}:"*) echo "${i}"; return 0;;
29 uberlord 2547 esac
30     done < /proc/net/dev
31 uberlord 2820
32     # Return the next available index
33     i=$((${i} + 1))
34     echo "${i}"
35 uberlord 2547 return 1
36     }
37    
38     _is_wireless() {
39     # Support new sysfs layout
40     [ -d /sys/class/net/"${IFACE}"/wireless ] && return 0
41    
42     [ ! -e /proc/net/wireless ] && return 1
43 uberlord 2610 grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
44 uberlord 2547 }
45    
46 uberlord 3086 _set_flag() {
47     local flag=$1 opt="on"
48     if [ "${flag#-}" != "${flag}" ]; then
49     flag=${flag#-}
50     opt="off"
51     fi
52     ip link set "${IFACE}" "${flag}" "${opt}"
53     }
54    
55 uberlord 2567 _get_mac_address() {
56     local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \
57     -e 'y/abcdef/ABCDEF/' \
58     -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
59    
60     case "${mac}" in
61     00:00:00:00:00:00) ;;
62     44:44:44:44:44:44) ;;
63     FF:FF:FF:FF:FF:FF) ;;
64     "") ;;
65     *) echo "${mac}"; return 0 ;;
66     esac
67    
68     return 1
69     }
70    
71     _set_mac_address() {
72     ip link set address "$1" dev "${IFACE}"
73     }
74    
75 uberlord 2547 _get_inet_addresses() {
76     LC_ALL=C ip -family inet addr show "${IFACE}" | \
77     sed -n -e 's/.*inet \([^ ]*\).*/\1/p'
78     }
79    
80     _get_inet_address() {
81     set -- $(_get_inet_addresses)
82     [ $# = "0" ] && return 1
83     echo "$1"
84     }
85    
86     _add_address() {
87     if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ] ; then
88     ip addr add "$@" dev "${IFACE}" 2>/dev/null
89     return 0
90     fi
91    
92     # Convert an ifconfig line to iproute2
93     if [ "$2" = "netmask" ] ; then
94     local one="$1" three="$3"
95     shift ; shift ; shift
96     set -- "${one}/$(_netmask2cidr "${three}")" "$@"
97     fi
98    
99     #config=( "${config[@]//pointopoint/peer}" )
100    
101     # Always scope lo addresses as host unless specified otherwise
102     if [ "${IFACE}" = "lo" ] ; then
103     set -- "$@" "scope" "host"
104     fi
105    
106     # IPv4 specifics
107     case "$1" in
108     *.*.*.*)
109     case "$@" in
110     *" brd "*) ;;
111     *" broadcast "*) ;;
112     *) set -- "$@" brd + ;;
113     esac
114     ;;
115     esac
116    
117     ip addr add dev "${IFACE}" "$@"
118     }
119    
120     _add_route() {
121     if [ $# -eq 3 ] ; then
122     set -- "$1" "$2" via "$3"
123     elif [ "$3" = "gw" ] ; then
124     local one=$1 two=$2
125     shift ; shift; shift
126     set -- "${one}" "${two}" gw "$@"
127     fi
128    
129     local cmd= have_metric=false
130     while [ -n "$1" ] ; do
131     case "$1" in
132     metric) cmd="${cmd} $1"; have_metric=true ;;
133     netmask) cmd="${cmd}/$(_netmask2cidr "$2")"; shift ;;
134 uberlord 2754 -host|-net) ;;
135 uberlord 2547 -A) [ "$2" = "inet6" ] && shift ;;
136     *) cmd="${cmd} $1" ;;
137     esac
138     shift
139     done
140    
141     if ! ${have_metric} && [ -n "${metric}" ] ; then
142     cmd="${cmd} metric ${metric}"
143     fi
144    
145     ip route append ${cmd} dev "${IFACE}"
146     eend $?
147     }
148    
149     _delete_addresses() {
150     ip addr flush dev "${IFACE}" scope global 2>/dev/null
151     ip addr flush dev "${IFACE}" scope site 2>/dev/null
152     if [ "${IFACE}" != "lo" ] ; then
153     ip addr flush dev "${IFACE}" scope host 2>/dev/null
154     fi
155     return 0
156     }
157    
158     _has_carrier() {
159     return 0
160     }
161    
162     _tunnel() {
163     ip tunnel "$@"
164     }
165    
166     iproute2_pre_start() {
167     # MTU support
168     local mtu=
169     eval mtu=\$mtu_${IFVAR}
170     [ -n "${mtu}" ] && ip link set mtu "${mtu}" dev "${IFACE}"
171    
172 uberlord 3012 # TX Queue Length support
173     local len=
174     eval len=\$txqueuelen_${IFVAR}
175     [ -n "${len}" ] && ip link set txqueuelen "${len}" dev "${IFACE}"
176    
177 uberlord 2547 local tunnel=
178     eval tunnel=\$iptunnel_${IFVAR}
179     if [ -n "${tunnel}" ] ; then
180     # Set our base metric to 1000
181     metric=1000
182    
183     ebegin "Creating tunnel ${IFVAR}"
184 uberlord 2567 ip tunnel add ${tunnel} name "${IFACE}"
185 uberlord 2547 eend $? || return 1
186 uberlord 2567 _up
187 uberlord 2547 fi
188    
189     return 0
190     }
191    
192     iproute2_post_start() {
193 uberlord 3087 # Kernel may not have IP built in
194     if [ -e /proc/net/route ]; then
195     ip route flush table cache dev "${IFACE}"
196     fi
197 uberlord 2547 }
198    
199     iproute2_post_stop() {
200     # Don't delete sit0 as it's a special tunnel
201     if [ "${IFACE}" != "sit0" ] ; then
202     if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ] ; then
203     ebegin "Destroying tunnel ${IFACE}"
204     ip tunnel del "${IFACE}"
205     eend $?
206     fi
207     fi
208     }
209    
210     # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20