Subversion Repositories configs

Rev

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