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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2547 - (show annotations) (download) (as text)
Thu Apr 5 11:18:42 2007 UTC (7 years, 7 months ago) by uberlord
File MIME type: text/x-sh
File size: 2428 byte(s)
    Rewrite the core parts in C. We now provide librc so other programs can
    query runlevels, services and state without using bash. We also provide
    libeinfo so other programs can easily use our informational functions.

    As such, we have dropped the requirement of using bash as the init script
    shell. We now use /bin/sh and have strived to make the scripts as portable
    as possible. Shells that work are bash and dash. busybox works provided
    you disable s-s-d. If you have WIPE_TMP set to yes in conf.d/bootmisc you
    should disable find too.
    zsh and ksh do not work at this time.

    Networking support is currently being re-vamped also as it was heavily bash
    array based. As such, a new config format is available like so
    config_eth0="1.2.3.4/24 5.6.7.8/16"
    or like so
    config_eth0="'1.2.3.4 netmask 255.255.255.0' '5.6.7.8 netmask 255.255.0.0'"

    We will still support the old bash array format provided that /bin/sh IS
    a link it bash.

    ChangeLog for baselayout-1 can be found in our SVN repo.
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 [ -e /dev/net/"${IFACE}" ]
11 }
12
13 _get_mac_address() {
14 local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
15 sed -n -e 's/^[[:space:]]*ether \(..:..:..:..:..:..\).*/\1/p')
16
17 case "${mac}" in
18 00:00:00:00:00:00) ;;
19 44:44:44:44:44:44) ;;
20 FF:FF:FF:FF:FF:FF) ;;
21 *) echo "${mac}"; return 0 ;;
22 esac
23
24 return 1
25 }
26
27 _up () {
28 ifconfig "${IFACE}" up
29 }
30
31 _down () {
32 ifconfig "${IFACE}" down
33 }
34
35 _ifindex() {
36 local x=
37 for x in /dev/net[0-9]* ; do
38 if [ "${x}" -ef /dev/net/"${IFACE}" ] ; then
39 echo "${x#/dev/net}"
40 return 0
41 fi
42 done
43 return 1
44 }
45
46 _is_wireless() {
47 LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | \
48 grep -q "^[[:space:]]*media: IEEE 802.11 Wireless"
49 }
50
51 _get_inet_address() {
52 set -- $(LC_ALL=C ifconfig "${IFACE}" |
53 sed -n -e 's/^[[:space:]]*inet \([^ ]*\) netmask 0x\(..\)\(..\)\(..\)\(..\).*/\1 0x\2.0x\3.0x\4/p')
54 echo -n "$1"
55 shift
56
57 echo "/$(_netmask2cidr "$1")"
58 }
59
60 _add_address() {
61 if [ "${metric:-0}" != "0" ] ; then
62 set -- "$@" metric ${metric}
63 fi
64
65 ifconfig "${IFACE}" add "$@"
66 }
67
68 _add_route() {
69 if [ $# -gt 3 ] ; then
70 if [ "$3" = "gw" -o "$3" = "via" ] ; then
71 local one=$1 two=$2
72 shift ; shift; shift
73 set -- "${one}" "${two}" "$@"
74 fi
75 fi
76
77 route add "$@"
78 }
79
80 _delete_addresses() {
81 # We don't remove addresses from aliases
82 case "${IFACE}" in
83 *:*) return 0 ;;
84 esac
85
86 einfo "Removing addresses"
87 eindent
88 local addr=
89 for addr in $(LC_ALL=C ifconfig "${IFACE}" |
90 sed -n -e 's/^[[:space:]]*inet \([^ ]*\).*/\1/p') ; do
91 if [ "${addr}" = "127.0.0.1" ] ; then
92 # Don't delete the loopback address
93 [ "$1" = "lo" -o "$1" = "lo0" ] && continue
94 fi
95 einfo "${addr}"
96 /sbin/ifconfig "$1" delete "${addr}"
97 eend $?
98 done
99
100 # Remove IPv6 addresses
101 for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
102 sed -n -e 's/^[[:space:]]*inet6 \([^ ]*\).*/\1/p') ; do
103 case "${addr}" in
104 *"%${IFACE}") continue ;;
105 ::1) continue ;;
106 esac
107 einfo "${addr}"
108 /sbin/ifconfig "${IFACE}" inet6 delete "${addr}"
109 eend $?
110 done
111
112 return 0
113 }
114
115 _show_address() {
116 einfo "received address $(_get_inet_address "${IFACE}")"
117 }
118
119 _has_carrier() {
120 local s=$(LC_ALL=C ifconfig "${IFACE}" | \
121 sed -n -e 's/^[[:space:]]status: \(.*\)$/\1/p')
122 [ -z "${s}" -o "${s}" = "active" -o "${s}" = "associated" ]
123 }
124
125 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20