Rev 8 | Rev 95 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/bash# Network Interface Configuration System# Copyright (c) 1996-2010 Red Hat, Inc. all rights reserved.## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License, version 2,# as published by the Free Software Foundation.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /etc/init.d/functionscd /etc/sysconfig/network-scripts. ./network-functions[ -f ../network ] && . ../networkCONFIG=${1}need_config "${CONFIG}"source_config# Old BOOTP variableif [ "${BOOTP}" = "yes" ]; thenBOOTPROTO=bootpfiif [ "${BOOTPROTO}" = "bootp" -o "${BOOTPROTO}" = "dhcp" ]; thenDYNCONFIG=truefi# load the module associated with that device# /sbin/modprobe ${REALDEVICE}is_available ${REALDEVICE}# bail out, if the MAC does not fitif [ -n "${HWADDR}" ]; thenFOUNDMACADDR=$(get_hwaddr ${REALDEVICE})if [ "${FOUNDMACADDR}" != "${HWADDR}" -a "${FOUNDMACADDR}" != "${MACADDR}" ]; thennet_log $"Device ${DEVICE} has different MAC address than expected, ignoring."exit 1fifi# If the device is a bridge, create it with brctl, if available.if [ "${TYPE}" = "Bridge" ]; thenif [ ! -x /usr/sbin/brctl ]; thennet_log $"Bridge support not available: brctl not found"exit 1fiif [ ! -d /sys/class/net/${DEVICE}/bridge ]; then/usr/sbin/brctl addbr ${DEVICE} || exit 1fi[ -n "${DELAY}" ] && /usr/sbin/brctl setfd ${DEVICE} ${DELAY}[ -n "${STP}" ] && /usr/sbin/brctl stp ${DEVICE} ${STP}[ -n "${PRIO}" ] && /usr/sbin/brctl setbridgeprio ${DEVICE} ${PRIO}[ -n "${AGEING}" ] && /usr/sbin/brctl setageing ${DEVICE} ${AGEING}# add the bits to setup driver parameters herefor arg in $BRIDGING_OPTS ; dokey=${arg%%=*};value=${arg##*=};echo $value > /sys/class/net/${DEVICE}/bridge/$keydonefi# If the device is a tap device, create it with tunctl, if available.if [ "${TYPE}" = "Tap" ]; thenif [ ! -x /usr/sbin/tunctl ]; thennet_log $"Tap support not available: tunctl not found"exit 1fi[ -n "${OWNER}" ] && OWNER="-u ${OWNER}"/usr/sbin/tunctl ${OWNER} -t ${DEVICE} > /dev/nullfi# now check the real stateis_available ${REALDEVICE} || {if [ -n "$alias" ]; thennet_log $"$alias device ${DEVICE} does not seem to be present, delaying initialization."elsenet_log $"Device ${DEVICE} does not seem to be present, delaying initialization."fiexit 1}# this isn't the same as the MAC in the configuration filename. It is# available as a configuration option in the config file, forcing the kernel# to think an ethernet card has a different MAC address than it really has.if [ -n "${MACADDR}" ]; thenip link set dev ${DEVICE} address ${MACADDR}fiif [ -n "${MTU}" ]; thenip link set dev ${DEVICE} mtu ${MTU}fi# is the device wireless? If so, configure wireless device specificsis_wireless_device ${DEVICE} && . ./ifup-wireless# slave device?if [ "${SLAVE}" = yes -a "${ISALIAS}" = no -a "${MASTER}" != "" ]; theninstall_bonding_driver ${MASTER}grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null || {/sbin/ip link set dev ${DEVICE} downecho "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null}ethtool_setexit 0fi# Bonding initialization. For DHCP, we need to enslave the devices early,# so it can actually get an IP.if [ "$ISALIAS" = no ] && is_bonding_device ${DEVICE} ; theninstall_bonding_driver ${DEVICE}/sbin/ip link set dev ${DEVICE} upfor device in $(LANG=C grep -l "^[[:space:]]*MASTER=\"\?${DEVICE}\"\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; dois_ignored_file "$device" && continue/sbin/ifup ${device##*/}done[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}# add the bits to setup the needed post enslavement parametersfor arg in $BONDING_OPTS ; dokey=${arg%%=*};value=${arg##*=};if [ "${key}" = "primary" ]; thenecho $value > /sys/class/net/${DEVICE}/bonding/$keyfidonefi# If the device is part of a bridge, add the device to the bridgeif [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; thenif [ ! -d /sys/class/net/${BRIDGE}/bridge ]; then/usr/sbin/brctl addbr ${BRIDGE} 2>/dev/nullfi/sbin/ip addr flush dev ${DEVICE} 2>/dev/null/sbin/ip link set dev ${DEVICE} upethtool_set[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}/usr/sbin/brctl addif ${BRIDGE} ${DEVICE}# add the bits to setup driver parameters herefor arg in $BRIDGING_OPTS ; dokey=${arg%%=*};value=${arg##*=};echo $value > /sys/class/net/${DEVICE}/brport/$keydone# Upon adding a device to a bridge,# it's necessary to make radvd reload its config[ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid)exit 0fiif [ -n "${DYNCONFIG}" -a -x /sbin/dhclient ]; thenif [[ "${PERSISTENT_DHCLIENT}" = [yY1]* ]]; thenONESHOT="";elseONESHOT="-1";fi;generate_config_file_name# copy any lease obtained by the initrdfor file in /dev/.dhclient-${DEVICE}.leases /dev/.initramfs/net.${DEVICE}.lease ; doif [ -f "${file}" ]; thenmv -f $file /var/lib/dhclient/dhclient-${DEVICE}.leases[ -x /sbin/restorecon ] && restorecon /var/lib/dhclient/dhclient-${DEVICE}.leases > /dev/null 2>&1fidoneDHCLIENTARGS="${DHCLIENTARGS} ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${ONESHOT} -q ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid"echoecho -n $"Determining IP information for ${DEVICE}..."if [[ "${PERSISTENT_DHCLIENT}" != [yY1]* ]] && check_link_down ${DEVICE}; thenecho $" failed; no link present. Check cable?"exit 1fiethtool_setif /sbin/dhclient ${DHCLIENTARGS} ${DEVICE} ; thenecho $" done."dhcpipv4="good"elseecho $" failed."if [[ "${IPV4_FAILURE_FATAL}" = [Yy1]* ]] ; thenexit 1fiif [[ "$IPV6INIT" != [yY1]* && "$DHCPV6C" != [yY1]* ]] ; thenexit 1finet_log "Unable to obtain IPv4 DHCP address ${DEVICE}." warningfi# end dynamic device configurationelseif [ -z "${IPADDR}" -a -z "${IPADDR0}" -a -z "${IPADDR1}" -a -z "${IPADDR2}" ]; then# enable device without IP, useful for e.g. PPPoEip link set dev ${REALDEVICE} upethtool_set[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}elseexpand_config[ -n "${ARP}" ] && \ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)if ! ip link set dev ${REALDEVICE} up ; thennet_log $"Failed to bring up ${DEVICE}."exit 1fiethtool_set[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}if [ "${DEVICE}" = "lo" ]; thenSCOPE="scope host"elseSCOPE=${SCOPE:-}fiif [ -n "$SRCADDR" ]; thenSRC="src $SRCADDR"elseSRC=fi# set IP address(es)for idx in {0..256} ; doif [ -z "${ipaddr[$idx]}" ]; thenbreakfiif ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; thenif [ "${REALDEVICE}" != "lo" ] && [ "${arpcheck[$idx]}" != "no" ] ; thenecho $"Determining if ip address ${ipaddr[$idx]} is already in use for device ${REALDEVICE}..."if ! /sbin/arping -q -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]} ; thennet_log $"Error, some other host already uses address ${ipaddr[$idx]}."exit 1fifiif ! ip addr add ${ipaddr[$idx]}/${prefix[$idx]} \brd ${broadcast[$idx]:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; thennet_log $"Error adding address ${ipaddr[$idx]} for ${DEVICE}."fifiif [ -n "$SRCADDR" ]; thensysctl -w "net.ipv4.conf.${SYSCTLDEVICE}.arp_filter=1" >/dev/null 2>&1fi# update ARP cache of neighboring computersif [ "${REALDEVICE}" != "lo" ]; then/sbin/arping -q -A -c 1 -I ${REALDEVICE} ${ipaddr[$idx]}( sleep 2;/sbin/arping -q -U -c 1 -I ${REALDEVICE} ${ipaddr[$idx]} ) > /dev/null 2>&1 < /dev/null &fidone# Set a default route.if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then# set up default gateway. replace if one already existsif [ -n "${GATEWAY}" ] && [ "$(ipcalc --network ${GATEWAY} ${netmask[0]} 2>/dev/null)" = "NETWORK=${NETWORK}" ]; thenip route replace default ${METRIC:+metric $METRIC} \via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} \${GATEWAYDEV:+dev $GATEWAYDEV} ||net_log $"Error adding default gateway ${GATEWAY} for ${DEVICE}."elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; thenip route replace default ${METRIC:+metric $METRIC} \${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE} ||net_log $"Erorr adding default gateway for ${REALDEVICE}."fifififi# Add Zeroconf route.if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" -a "${REALDEVICE}" != "lo" ]; thenip route add 169.254.0.0/16 dev ${REALDEVICE} metric $((1000 + $(cat /sys/class/net/${REALDEVICE}/ifindex))) scope linkfiif [ "${TYPE}" = "Bridge" ]; thenfor arg in $BRIDGING_OPTS ; dokey=${arg%%=*};value=${arg##*=};if [ "${key}" = "multicast_router" -o "${key}" = "hash_max" -o "${key}" = "multicast_snooping" ]; thenecho $value > /sys/class/net/${DEVICE}/bridge/$keyfidonefi# IPv6 initialisation?/etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}if [[ "${DHCPV6C}" = [Yy1]* ]] && [ -x /sbin/dhclient ]; thengenerate_config_file_name 6echoecho -n $"Determining IPv6 information for ${DEVICE}..."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} ; thenecho $" done."elseecho $" failed."if [ "${dhcpipv4}" = "good" -o -n "${IPADDR}" ]; thennet_log "Unable to obtain IPv6 DHCP address ${DEVICE}." warningelseexit 1fififiexec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}