Subversion Repositories configs

Rev

Rev 8 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/bash
2
# Network Interface Configuration System
3
# Copyright (c) 1996-2010 Red Hat, Inc. all rights reserved.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License, version 2,
7
# as published by the Free Software Foundation.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17
 
18
. /etc/init.d/functions
19
 
20
cd /etc/sysconfig/network-scripts
21
. ./network-functions
22
 
23
[ -f ../network ] && . ../network
24
 
25
CONFIG=${1}
26
 
27
need_config "${CONFIG}"
28
 
29
source_config
30
 
31
# Old BOOTP variable
32
if [ "${BOOTP}" = "yes" ]; then
33
    BOOTPROTO=bootp
34
fi
35
 
36
if [ "${BOOTPROTO}" = "bootp" -o "${BOOTPROTO}" = "dhcp" ]; then
37
    DYNCONFIG=true
38
fi
39
 
40
# load the module associated with that device
41
# /sbin/modprobe ${REALDEVICE}
42
is_available ${REALDEVICE}
43
 
44
# bail out, if the MAC does not fit
45
if [ -n "${HWADDR}" ]; then
46
    FOUNDMACADDR=$(get_hwaddr ${REALDEVICE})
47
    if [ "${FOUNDMACADDR}" != "${HWADDR}" -a "${FOUNDMACADDR}" != "${MACADDR}" ]; then
48
	    net_log $"Device ${DEVICE} has different MAC address than expected, ignoring."
49
	    exit 1
50
    fi
51
fi
52
 
53
# If the device is a bridge, create it with brctl, if available.
54
if [ "${TYPE}" = "Bridge" ]; then
55
      if [ ! -x /usr/sbin/brctl ]; then
56
	  net_log $"Bridge support not available: brctl not found"
57
	  exit 1
58
      fi
59
      if [ ! -d /sys/class/net/${DEVICE}/bridge ]; then
60
		/usr/sbin/brctl addbr ${DEVICE} || exit 1
61
      fi
62
      [ -n "${DELAY}" ] && /usr/sbin/brctl setfd ${DEVICE} ${DELAY}
63
      [ -n "${STP}" ] && /usr/sbin/brctl stp ${DEVICE} ${STP}
64
      # add the bits to setup driver parameters here
65
      for arg in $BRIDGING_OPTS ; do
66
          key=${arg%%=*};
67
          value=${arg##*=};
68
          echo $value > /sys/class/net/${DEVICE}/bridge/$key
69
      done
70
fi
71
 
72
# If the device is a tap device, create it with tunctl, if available.
73
if [ "${TYPE}" = "Tap" ]; then
74
      if [ ! -x /usr/sbin/tunctl ]; then
75
          net_log  $"Tap support not available: tunctl not found"
76
          exit 1
77
      fi
78
      [ -n "${OWNER}" ] && OWNER="-u ${OWNER}"
79
      /usr/sbin/tunctl ${OWNER} -t ${DEVICE} > /dev/null
80
fi
81
 
82
# now check the real state
83
is_available ${REALDEVICE} || {
84
      if [ -n "$alias" ]; then
85
         net_log $"$alias device ${DEVICE} does not seem to be present, delaying initialization."
86
      else
87
         net_log $"Device ${DEVICE} does not seem to be present, delaying initialization."
88
      fi
89
      exit 1
90
}
91
 
92
 
93
# this isn't the same as the MAC in the configuration filename.  It is
94
# available as a configuration option in the config file, forcing the kernel
95
# to think an ethernet card has a different MAC address than it really has.
96
if [ -n "${MACADDR}" ]; then
97
   ip link set dev ${DEVICE} address ${MACADDR}
98
fi
99
if [ -n "${MTU}" ]; then
100
   ip link set dev ${DEVICE} mtu ${MTU}
101
fi
102
 
103
# is the device wireless? If so, configure wireless device specifics
104
is_wireless_device ${DEVICE} && . ./ifup-wireless
105
 
106
# slave device?
107
if [ "${SLAVE}" = yes -a "${ISALIAS}" = no -a "${MASTER}" != "" ]; then
108
    install_bonding_driver ${MASTER}
109
    grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null || {
110
	/sbin/ip link set dev ${DEVICE} down
111
	echo "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
112
    }
113
    ethtool_set
114
 
115
    exit 0
116
fi
117
 
118
# Bonding initialization. For DHCP, we need to enslave the devices early,
119
# so it can actually get an IP.
120
if [ "$ISALIAS" = no ] && is_bonding_device ${DEVICE} ; then
121
    install_bonding_driver ${DEVICE}
122
    /sbin/ip link set dev ${DEVICE} up
123
    for device in $(LANG=C grep -l "^[[:space:]]*MASTER=\"\?${DEVICE}\"\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; do
124
	    is_ignored_file "$device" && continue
125
	    /sbin/ifup ${device##*/}
126
    done
127
 
128
    [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
129
 
130
    # add the bits to setup the needed post enslavement parameters
131
    for arg in $BONDING_OPTS ; do
132
        key=${arg%%=*};
133
        value=${arg##*=};
134
	if [ "${key}" = "primary" ]; then
135
            echo $value > /sys/class/net/${DEVICE}/bonding/$key
136
	fi
137
    done
138
fi
139
 
140
# If the device is part of a bridge, add the device to the bridge
141
if [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; then
142
      if [ ! -d /sys/class/net/${BRIDGE}/bridge ]; then
143
	  /usr/sbin/brctl addbr ${BRIDGE} 2>/dev/null
144
      fi
145
      /sbin/ip addr flush dev ${DEVICE} 2>/dev/null
146
      /sbin/ip link set dev ${DEVICE} up
147
      ethtool_set
148
      [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
149
      /usr/sbin/brctl addif ${BRIDGE} ${DEVICE}
150
      # add the bits to setup driver parameters here
151
      for arg in $BRIDGING_OPTS ; do
152
          key=${arg%%=*};
153
          value=${arg##*=};
154
          echo $value > /sys/class/net/${DEVICE}/brport/$key
155
      done
156
      # Upon adding a device to a bridge,
157
      # it's necessary to make radvd reload its config
158
      [ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid)
159
      exit 0
160
fi
161
 
162
if [ -n "${DYNCONFIG}" -a -x /sbin/dhclient ]; then
163
    if [[ "${PERSISTENT_DHCLIENT}" =  [yY1]* ]]; then
164
       ONESHOT="";
165
    else
166
       ONESHOT="-1";
167
    fi;
168
    generate_config_file_name
169
    # copy any lease obtained by the initrd
170
    for file in /dev/.dhclient-${DEVICE}.leases /dev/.initramfs/net.${DEVICE}.lease ; do
171
        if [ -f "${file}" ]; then
172
            mv -f $file /var/lib/dhclient/dhclient-${DEVICE}.leases
173
            [ -x /sbin/restorecon ] && restorecon /var/lib/dhclient/dhclient-${DEVICE}.leases > /dev/null 2>&1
174
        fi
175
    done
176
    DHCLIENTARGS="${DHCLIENTARGS} ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${ONESHOT} -q ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid"
177
    echo
178
    echo -n $"Determining IP information for ${DEVICE}..."
179
    if [[ "${PERSISTENT_DHCLIENT}" !=  [yY1]* ]] && check_link_down ${DEVICE}; then
180
	echo $" failed; no link present.  Check cable?"
181
	exit 1
182
    fi
183
 
184
    ethtool_set
185
 
186
    if /sbin/dhclient ${DHCLIENTARGS} ${DEVICE} ; then
187
		echo $" done."
188
		dhcpipv4="good"
189
    else
190
		echo $" failed."
191
		if [[ "${IPV4_FAILURE_FATAL}"  = [Yy1]* ]] ; then
192
			exit 1
193
		fi
194
		if [[ "$IPV6INIT" != [yY1]* && "$DHCPV6C" != [yY1]* ]] ; then
195
			exit 1
196
		fi
197
		net_log "Unable to obtain IPv4 DHCP address ${DEVICE}." warning
198
    fi
199
# end dynamic device configuration
200
else
201
    if [ -z "${IPADDR}" -a -z "${IPADDR0}" -a -z "${IPADDR1}" -a -z "${IPADDR2}" ]; then
202
         # enable device without IP, useful for e.g. PPPoE
203
	 ip link set dev ${REALDEVICE} up
204
	 ethtool_set
205
	 [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
206
    else
207
 
208
    expand_config
209
 
210
    [ -n "${ARP}" ] && \
211
	ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)
212
 
213
    if ! ip link set dev ${REALDEVICE} up ; then
214
	net_log $"Failed to bring up ${DEVICE}."
215
	exit 1
216
    fi
217
 
218
    ethtool_set
219
 
220
    [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
221
 
222
    if [ "${DEVICE}" = "lo" ]; then
223
    	SCOPE="scope host"
224
    else
225
        SCOPE=${SCOPE:-}
226
    fi
227
 
228
    if [ -n "$SRCADDR" ]; then
229
       SRC="src $SRCADDR"
230
    else
231
       SRC=
232
    fi
233
 
234
    # set IP address(es)
235
    for idx in {0..256} ; do
236
	if [ -z "${ipaddr[$idx]}" ]; then
237
            break
238
        fi
239
 
240
        if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then
241
            if [ "${REALDEVICE}" != "lo" ] && [ "${arpcheck[$idx]}" != "no" ] ; then
242
				echo $"Determining if ip address ${ipaddr[$idx]} is already in use for device ${REALDEVICE}..."
243
				if ! /sbin/arping -q -c 2 -w 3 -D -I ${REALDEVICE} ${ipaddr[$idx]} ; then
244
					net_log $"Error, some other host already uses address ${ipaddr[$idx]}."
245
					exit 1
246
				fi
247
			fi
248
 
249
            if ! ip addr add ${ipaddr[$idx]}/${prefix[$idx]} \
250
              brd ${broadcast[$idx]:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
251
                net_log $"Error adding address ${ipaddr[$idx]} for ${DEVICE}."
252
            fi
253
        fi
254
 
255
        if [ -n "$SRCADDR" ]; then
256
               sysctl -w "net.ipv4.conf.${SYSCTLDEVICE}.arp_filter=1" >/dev/null 2>&1
257
        fi
258
 
259
        # update ARP cache of neighboring computers
260
        if [ "${REALDEVICE}" != "lo" ]; then
261
          /sbin/arping -q -A -c 1 -I ${REALDEVICE} ${ipaddr[$idx]}
262
          ( sleep 2;
263
            /sbin/arping -q -U -c 1 -I ${REALDEVICE} ${ipaddr[$idx]} ) > /dev/null 2>&1 < /dev/null &
264
        fi
265
    done
266
 
267
    # Set a default route.
268
    if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
269
	# set up default gateway. replace if one already exists
270
	if [ -n "${GATEWAY}" ] && [ "$(ipcalc --network ${GATEWAY} ${netmask[0]} 2>/dev/null)" = "NETWORK=${NETWORK}" ]; then
271
	    ip route replace default ${METRIC:+metric $METRIC} \
272
		via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} \
273
		${GATEWAYDEV:+dev $GATEWAYDEV} ||
274
			net_log $"Error adding default gateway ${GATEWAY} for ${DEVICE}."
275
	elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
276
	    ip route replace default ${METRIC:+metric $METRIC} \
277
		${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE} ||
278
			net_log $"Erorr adding default gateway for ${REALDEVICE}."
279
	fi
280
    fi
281
    fi
282
fi
283
 
284
# Add Zeroconf route.
285
if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" -a "${REALDEVICE}" != "lo" ]; then
286
    ip route add 169.254.0.0/16 dev ${REALDEVICE} metric $((1000 + $(cat /sys/class/net/${REALDEVICE}/ifindex))) scope link
287
fi
288
 
289
# IPv6 initialisation?
290
/etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}
291
if [[ "${DHCPV6C}"  = [Yy1]* ]] && [ -x /sbin/dhclient ]; then
292
    generate_config_file_name 6
293
    echo
294
    echo -n $"Determining IPv6 information for ${DEVICE}..."
295
    if /sbin/dhclient -6 -1 ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient6-${DEVICE}.leases -pf /var/run/dhclient6-${DEVICE}.pid ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${DEVICE} ; then
296
        echo $" done."
297
    else
298
        echo $" failed."
299
        if [ "${dhcpipv4}" = "good" -o -n "${IPADDR}" ]; then
300
            net_log "Unable to obtain IPv6 DHCP address ${DEVICE}." warning
301
        else
302
            exit 1
303
        fi
304
    fi
305
fi
306
 
307
if [ "${IPX}" = yes ]; then
308
       /etc/sysconfig/network-scripts/ifup-ipx ${DEVICE}
309
fi
310
 
311
exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
312