[1108] | 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 | |
---|
| 14 | cd /etc/sysconfig/network-scripts |
---|
[2573] | 15 | . /etc/sysconfig/network-scripts/network-functions |
---|
[1108] | 16 | |
---|
[2573] | 17 | [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network |
---|
[1108] | 18 | |
---|
| 19 | CONFIG=${1} |
---|
| 20 | |
---|
| 21 | [ -z "${CONFIG}" ] && { |
---|
| 22 | echo $"Usage: ifup <device name>" >&2 |
---|
| 23 | exit 1 |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | need_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 | |
---|
| 34 | source_config |
---|
| 35 | |
---|
| 36 | # Old BOOTP variable |
---|
| 37 | if [ "${BOOTP}" = "yes" ]; then |
---|
| 38 | BOOTPROTO=bootp |
---|
| 39 | fi |
---|
| 40 | |
---|
| 41 | if [ "${BOOTPROTO}" = "bootp" -o "${BOOTPROTO}" = "dhcp" ]; then |
---|
| 42 | echo $"This device does not (yet) support dynamic IP configuration." >&2 |
---|
| 43 | exit 1 |
---|
| 44 | fi |
---|
| 45 | |
---|
| 46 | # load the module associated with that device |
---|
| 47 | # /sbin/modprobe ${REALDEVICE} |
---|
| 48 | is_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 |
---|
| 52 | if [ -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 |
---|
| 61 | fi |
---|
| 62 | |
---|
| 63 | # now check the real state |
---|
| 64 | is_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? |
---|
| 74 | if [ "${SLAVE}" = yes ]; then |
---|
| 75 | echo $"This device does not slave operation." >&2 |
---|
| 76 | exit 1 |
---|
| 77 | fi |
---|
| 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. |
---|
| 82 | if [ -n "${MACADDR}" ]; then |
---|
| 83 | ip link set dev ${DEVICE} address ${MACADDR} |
---|
| 84 | fi |
---|
| 85 | if [ -n "${MTU}" ]; then |
---|
| 86 | ip link set dev ${DEVICE} mtu ${MTU} |
---|
| 87 | fi |
---|
| 88 | |
---|
| 89 | # Is there a firewall running, and does it look like one we configured? |
---|
| 90 | FWACTIVE= |
---|
| 91 | if iptables -L -n 2>/dev/null | LC_ALL=C grep -q RH-Lokkit-0-50-INPUT ; then |
---|
| 92 | FWACTIVE=1 |
---|
| 93 | else |
---|
| 94 | modprobe -r iptable_filter >/dev/null 2>&1 |
---|
| 95 | fi |
---|
| 96 | |
---|
| 97 | if [ -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} |
---|
| 105 | fi |
---|
| 106 | |
---|
| 107 | expand_config |
---|
| 108 | |
---|
| 109 | [ -n "${ARP}" ] && \ |
---|
| 110 | ip link set dev ${REALDEVICE} $(toggle_value arp $ARP) |
---|
| 111 | |
---|
| 112 | if ! ip link set dev ${REALDEVICE} up ; then |
---|
| 113 | echo $"Failed to bring up ${DEVICE}." |
---|
| 114 | exit 1 |
---|
| 115 | fi |
---|
| 116 | |
---|
| 117 | SCOPE=${SCOPE:-} |
---|
| 118 | |
---|
| 119 | if ! 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 |
---|
| 124 | fi |
---|
| 125 | |
---|
| 126 | if [ -n "$SRCADDR" ]; then |
---|
| 127 | sysctl -w "net.ipv4.conf.${REALDEVICE}.arp_filter=1" >/dev/null 2>&1 |
---|
| 128 | fi |
---|
| 129 | |
---|
| 130 | # Set a default route. |
---|
| 131 | if [ -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 |
---|
| 138 | fi |
---|
| 139 | |
---|
| 140 | # Add Zeroconf route. |
---|
| 141 | if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" ]; then |
---|
| 142 | ip route replace 169.254.0.0/16 dev ${REALDEVICE} |
---|
| 143 | fi |
---|
| 144 | |
---|
| 145 | # IPv6 initialisation? |
---|
| 146 | if [ "${NETWORKING_IPV6}" = "yes" ]; then |
---|
| 147 | /etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG} |
---|
| 148 | fi |
---|
| 149 | |
---|
| 150 | exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2} |
---|
| 151 | |
---|