Subversion Repositories configs

Rev

Rev 8 | Rev 57 | Go to most recent revision | Details | Compare with Previous | 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}
8 - 64
      [ -n "${PRIO}" ] && /usr/sbin/brctl setbridgeprio ${DEVICE} ${PRIO}
65
      [ -n "${AGEING}" ] && /usr/sbin/brctl setageing ${DEVICE} ${AGEING}
3 - 66
      # add the bits to setup driver parameters here
67
      for arg in $BRIDGING_OPTS ; do
68
          key=${arg%%=*};
69
          value=${arg##*=};
70
          echo $value > /sys/class/net/${DEVICE}/bridge/$key
71
      done
72
fi
73
 
74
# If the device is a tap device, create it with tunctl, if available.
75
if [ "${TYPE}" = "Tap" ]; then
76
      if [ ! -x /usr/sbin/tunctl ]; then
77
          net_log  $"Tap support not available: tunctl not found"
78
          exit 1
79
      fi
80
      [ -n "${OWNER}" ] && OWNER="-u ${OWNER}"
81
      /usr/sbin/tunctl ${OWNER} -t ${DEVICE} > /dev/null
82
fi
83
 
84
# now check the real state
85
is_available ${REALDEVICE} || {
86
      if [ -n "$alias" ]; then
87
         net_log $"$alias device ${DEVICE} does not seem to be present, delaying initialization."
88
      else
89
         net_log $"Device ${DEVICE} does not seem to be present, delaying initialization."
90
      fi
91
      exit 1
92
}
93
 
94
 
95
# this isn't the same as the MAC in the configuration filename.  It is
96
# available as a configuration option in the config file, forcing the kernel
97
# to think an ethernet card has a different MAC address than it really has.
98
if [ -n "${MACADDR}" ]; then
99
   ip link set dev ${DEVICE} address ${MACADDR}
100
fi
101
if [ -n "${MTU}" ]; then
102
   ip link set dev ${DEVICE} mtu ${MTU}
103
fi
104
 
105
# is the device wireless? If so, configure wireless device specifics
106
is_wireless_device ${DEVICE} && . ./ifup-wireless
107
 
108
# slave device?
109
if [ "${SLAVE}" = yes -a "${ISALIAS}" = no -a "${MASTER}" != "" ]; then
110
    install_bonding_driver ${MASTER}
111
    grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null || {
112
	/sbin/ip link set dev ${DEVICE} down
113
	echo "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
114
    }
115
    ethtool_set
116
 
117
    exit 0
118
fi
119
 
120
# Bonding initialization. For DHCP, we need to enslave the devices early,
121
# so it can actually get an IP.
122
if [ "$ISALIAS" = no ] && is_bonding_device ${DEVICE} ; then
123
    install_bonding_driver ${DEVICE}
124
    /sbin/ip link set dev ${DEVICE} up
125
    for device in $(LANG=C grep -l "^[[:space:]]*MASTER=\"\?${DEVICE}\"\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; do
126
	    is_ignored_file "$device" && continue
127
	    /sbin/ifup ${device##*/}
128
    done
129
 
130
    [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
131
 
132
    # add the bits to setup the needed post enslavement parameters
133
    for arg in $BONDING_OPTS ; do
134
        key=${arg%%=*};
135
        value=${arg##*=};
136
	if [ "${key}" = "primary" ]; then
137
            echo $value > /sys/class/net/${DEVICE}/bonding/$key
138
	fi
139
    done
140
fi
141
 
142
# If the device is part of a bridge, add the device to the bridge
143
if [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; then
144
      if [ ! -d /sys/class/net/${BRIDGE}/bridge ]; then
145
	  /usr/sbin/brctl addbr ${BRIDGE} 2>/dev/null
146
      fi
147
      /sbin/ip addr flush dev ${DEVICE} 2>/dev/null
148
      /sbin/ip link set dev ${DEVICE} up
149
      ethtool_set
150
      [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
151
      /usr/sbin/brctl addif ${BRIDGE} ${DEVICE}
152
      # add the bits to setup driver parameters here
153
      for arg in $BRIDGING_OPTS ; do
154
          key=${arg%%=*};
155
          value=${arg##*=};
156
          echo $value > /sys/class/net/${DEVICE}/brport/$key
157
      done
158
      # Upon adding a device to a bridge,
159
      # it's necessary to make radvd reload its config
160
      [ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid)
161
      exit 0
162
fi
163
 
164
if [ -n "${DYNCONFIG}" -a -x /sbin/dhclient ]; then
165
    if [[ "${PERSISTENT_DHCLIENT}" =  [yY1]* ]]; then
166
       ONESHOT="";
167
    else
168
       ONESHOT="-1";
169
    fi;
170
    generate_config_file_name
171
    # copy any lease obtained by the initrd
172
    for file in /dev/.dhclient-${DEVICE}.leases /dev/.initramfs/net.${DEVICE}.lease ; do
173
        if [ -f "${file}" ]; then
174
            mv -f $file /var/lib/dhclient/dhclient-${DEVICE}.leases
175
            [ -x /sbin/restorecon ] && restorecon /var/lib/dhclient/dhclient-${DEVICE}.leases > /dev/null 2>&1
176
        fi
177
    done
178
    DHCLIENTARGS="${DHCLIENTARGS} ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${ONESHOT} -q ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid"
179
    echo
180
    echo -n $"Determining IP information for ${DEVICE}..."
181
    if [[ "${PERSISTENT_DHCLIENT}" !=  [yY1]* ]] && check_link_down ${DEVICE}; then
182
	echo $" failed; no link present.  Check cable?"
183
	exit 1
184
    fi
185
 
186
    ethtool_set
187
 
188
    if /sbin/dhclient ${DHCLIENTARGS} ${DEVICE} ; then
189
		echo $" done."
190
		dhcpipv4="good"
191
    else
192
		echo $" failed."
193
		if [[ "${IPV4_FAILURE_FATAL}"  = [Yy1]* ]] ; then
194
			exit 1
195
		fi
196
		if [[ "$IPV6INIT" != [yY1]* && "$DHCPV6C" != [yY1]* ]] ; then
197
			exit 1
198
		fi
199
		net_log "Unable to obtain IPv4 DHCP address ${DEVICE}." warning
200
    fi
201
# end dynamic device configuration
202
else
203
    if [ -z "${IPADDR}" -a -z "${IPADDR0}" -a -z "${IPADDR1}" -a -z "${IPADDR2}" ]; then
204
         # enable device without IP, useful for e.g. PPPoE
205
	 ip link set dev ${REALDEVICE} up
206
	 ethtool_set
207
	 [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
208
    else
209
 
210
    expand_config
211
 
212
    [ -n "${ARP}" ] && \
213
	ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)
214
 
215
    if ! ip link set dev ${REALDEVICE} up ; then
216
	net_log $"Failed to bring up ${DEVICE}."
217
	exit 1
218
    fi
219
 
220
    ethtool_set
221
 
222
    [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
223
 
224
    if [ "${DEVICE}" = "lo" ]; then
225
    	SCOPE="scope host"
226
    else
227
        SCOPE=${SCOPE:-}
228
    fi
229
 
230
    if [ -n "$SRCADDR" ]; then
231
       SRC="src $SRCADDR"
232
    else
233
       SRC=
234
    fi
235
 
236
    # set IP address(es)
237
    for idx in {0..256} ; do
238
	if [ -z "${ipaddr[$idx]}" ]; then
239
            break
240
        fi
241
 
242
        if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then
243
            if [ "${REALDEVICE}" != "lo" ] && [ "${arpcheck[$idx]}" != "no" ] ; then
244
				echo $"Determining if ip address ${ipaddr[$idx]} is already in use for device ${REALDEVICE}..."
8 - 245
				if ! /sbin/arping -q -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]} ; then
3 - 246
					net_log $"Error, some other host already uses address ${ipaddr[$idx]}."
247
					exit 1
248
				fi
249
			fi
250
 
251
            if ! ip addr add ${ipaddr[$idx]}/${prefix[$idx]} \
252
              brd ${broadcast[$idx]:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
253
                net_log $"Error adding address ${ipaddr[$idx]} for ${DEVICE}."
254
            fi
255
        fi
256
 
257
        if [ -n "$SRCADDR" ]; then
258
               sysctl -w "net.ipv4.conf.${SYSCTLDEVICE}.arp_filter=1" >/dev/null 2>&1
259
        fi
260
 
261
        # update ARP cache of neighboring computers
262
        if [ "${REALDEVICE}" != "lo" ]; then
263
          /sbin/arping -q -A -c 1 -I ${REALDEVICE} ${ipaddr[$idx]}
264
          ( sleep 2;
265
            /sbin/arping -q -U -c 1 -I ${REALDEVICE} ${ipaddr[$idx]} ) > /dev/null 2>&1 < /dev/null &
266
        fi
267
    done
268
 
269
    # Set a default route.
270
    if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
271
	# set up default gateway. replace if one already exists
272
	if [ -n "${GATEWAY}" ] && [ "$(ipcalc --network ${GATEWAY} ${netmask[0]} 2>/dev/null)" = "NETWORK=${NETWORK}" ]; then
273
	    ip route replace default ${METRIC:+metric $METRIC} \
274
		via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} \
275
		${GATEWAYDEV:+dev $GATEWAYDEV} ||
276
			net_log $"Error adding default gateway ${GATEWAY} for ${DEVICE}."
277
	elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
278
	    ip route replace default ${METRIC:+metric $METRIC} \
279
		${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE} ||
280
			net_log $"Erorr adding default gateway for ${REALDEVICE}."
281
	fi
282
    fi
283
    fi
284
fi
285
 
286
# Add Zeroconf route.
287
if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" -a "${REALDEVICE}" != "lo" ]; then
288
    ip route add 169.254.0.0/16 dev ${REALDEVICE} metric $((1000 + $(cat /sys/class/net/${REALDEVICE}/ifindex))) scope link
289
fi
290
 
8 - 291
if [ "${TYPE}" = "Bridge" ]; then
292
    for arg in $BRIDGING_OPTS ; do
293
        key=${arg%%=*};
294
        value=${arg##*=};
12 - 295
        if [ "${key}" = "multicast_router" -o "${key}" = "hash_max" -o "${key}" = "multicast_snooping" ]; then
8 - 296
            echo $value > /sys/class/net/${DEVICE}/bridge/$key
297
        fi
298
    done
299
fi
300
 
3 - 301
# IPv6 initialisation?
302
/etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}
303
if [[ "${DHCPV6C}"  = [Yy1]* ]] && [ -x /sbin/dhclient ]; then
304
    generate_config_file_name 6
305
    echo
306
    echo -n $"Determining IPv6 information for ${DEVICE}..."
307
    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
308
        echo $" done."
309
    else
310
        echo $" failed."
311
        if [ "${dhcpipv4}" = "good" -o -n "${IPADDR}" ]; then
312
            net_log "Unable to obtain IPv6 DHCP address ${DEVICE}." warning
313
        else
314
            exit 1
315
        fi
316
    fi
317
fi
318
 
319
exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
320