source: projects/initscripts/tags/initscripts-8.91.0/sysconfig/network-scripts/ifup-ib @ 2576

Revision 2576, 4.3 KB checked in by daisuke, 13 years ago (diff)

tagging as initscripts-8.91.0

Line 
1#!/bin/bash
2# Network Interface Configuration System
3# Copyright (c) 1996-2001 Red Hat, Inc. all rights reserved.
4#
5# This software may be freely redistributed under the terms of the GNU
6# public license.
7#
8# You should have received a copy of the GNU General Public License
9# along with this program; if not, write to the Free Software
10# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
11
12. /etc/rc.d/init.d/functions
13
14cd /etc/sysconfig/network-scripts
15. /etc/sysconfig/network-scripts/network-functions
16
17[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
18
19CONFIG=${1}
20
21[ -z "${CONFIG}" ] && {
22    echo $"Usage: ifup <device name>" >&2
23    exit 1
24}
25
26need_config ${CONFIG}
27
28[ -f "${CONFIG}" ] || {
29    echo $"$0: configuration for ${1} not found." >&2
30    echo $"Usage: ifup <device name>" >&2
31    exit 1
32}
33
34source_config
35
36# Old BOOTP variable
37if [ "${BOOTP}" = "yes" ]; then
38    BOOTPROTO=bootp
39fi
40
41if [ "${BOOTPROTO}" = "bootp" -o "${BOOTPROTO}" = "dhcp" ]; then
42    echo $"This device does not (yet) support dynamic IP configuration." >&2
43    exit 1
44fi
45
46# load the module associated with that device
47# /sbin/modprobe ${REALDEVICE}
48is_available ${REALDEVICE}
49
50# remap, if the device is bound with a MAC address and not the right device num
51# bail out, if the MAC does not fit
52if [ -n "${HWADDR}" ]; then
53    FOUNDMACADDR=`get_hwaddr ${REALDEVICE}`
54    if [ "${FOUNDMACADDR}" != "${HWADDR}" ]; then
55        curdev=`ip -o link | awk -F ':' -vIGNORECASE=1 "/$HWADDR/ { print \\$2 }"`
56        [ -n "$curdev" ] && rename_device "${REALDEVICE}" "${HWADDR}" "${curdev}" || {
57            echo $"Device ${DEVICE} has different MAC address than expected, ignoring."
58            exit 1
59        }
60    fi
61fi
62
63# now check the real state
64is_available ${REALDEVICE} || {
65      if [ "$?" = "1" ] ; then
66         echo $"$alias device ${DEVICE} does not seem to be present, delaying initialization."
67         exit 1
68      else
69         exit 0
70      fi
71}
72
73# slave device?
74if [ "${SLAVE}" = yes ]; then
75    echo $"This device does not slave operation." >&2
76    exit 1
77fi
78
79# this isn't the same as the MAC in the configuration filename.  It is
80# available as a configuration option in the config file, forcing the kernel
81# to think an ethernet card has a different MAC address than it really has.
82if [ -n "${MACADDR}" ]; then
83   ip link set dev ${DEVICE} address ${MACADDR}
84fi
85if [ -n "${MTU}" ]; then
86   ip link set dev ${DEVICE} mtu ${MTU}
87fi
88
89# Is there a firewall running, and does it look like one we configured?
90FWACTIVE=
91if iptables -L -n 2>/dev/null | LC_ALL=C grep -q RH-Lokkit-0-50-INPUT ; then
92    FWACTIVE=1
93else
94    modprobe -r iptable_filter >/dev/null 2>&1
95fi
96
97if [ -z "${IPADDR}" ]; then
98    # enable device without IP, useful for e.g. PPPoE
99    ip link set dev ${REALDEVICE} up
100
101    if [ "${NETWORKING_IPV6}" = "yes" ]; then
102        /etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}
103    fi
104    exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
105fi
106 
107expand_config
108   
109[ -n "${ARP}" ] && \
110        ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)
111   
112if ! ip link set dev ${REALDEVICE} up ; then
113        echo $"Failed to bring up ${DEVICE}."
114        exit 1
115fi
116
117SCOPE=${SCOPE:-}
118   
119if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${IPADDR}/${PREFIX}" ; then
120    if ! ip addr add ${IPADDR}/${PREFIX} \
121        brd ${BROADCAST:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
122        echo $"Error adding address ${IPADDR} for ${DEVICE}."
123    fi
124fi
125   
126if [ -n "$SRCADDR" ]; then
127    sysctl -w "net.ipv4.conf.${REALDEVICE}.arp_filter=1" >/dev/null 2>&1
128fi
129
130# Set a default route.
131if [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
132    # set up default gateway. replace if one already exists
133    if [ -n "${GATEWAY}" -a "`ipcalc --network ${GATEWAY} ${NETMASK} 2>/dev/null`" = "NETWORK=${NETWORK}" ]; then
134        ip route replace default via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} ${GATEWAYDEV:+dev $GATEWAYDEV}
135    elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
136        ip route replace default ${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE}
137    fi
138fi
139
140# Add Zeroconf route.
141if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" ]; then
142    ip route replace 169.254.0.0/16 dev ${REALDEVICE}
143fi
144
145# IPv6 initialisation?
146if [ "${NETWORKING_IPV6}" = "yes" ]; then
147    /etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}
148fi
149
150exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
151
Note: See TracBrowser for help on using the repository browser.