diff options
Diffstat (limited to 'network-scripts/ifup-eth')
-rwxr-xr-x | network-scripts/ifup-eth | 223 |
1 files changed, 209 insertions, 14 deletions
diff --git a/network-scripts/ifup-eth b/network-scripts/ifup-eth index 178b5173..63387733 100755 --- a/network-scripts/ifup-eth +++ b/network-scripts/ifup-eth @@ -15,14 +15,20 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +PATH=/sbin:/usr/sbin:/bin:/usr/bin +TEXTDOMAIN=initscripts + . /etc/init.d/functions cd /etc/sysconfig/network-scripts . ./network-functions -[ -f ../network ] && . ../network +[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network CONFIG=${1} +boot=${2} +daemon= +[ "foo${boot}" = "fooboot" -o "foo${boot}" = "foodaemon" ] && daemon=1 need_config "${CONFIG}" @@ -30,6 +36,7 @@ source_config if [ "${BOOTPROTO}" = "bootp" -o "${BOOTPROTO}" = "dhcp" ]; then DYNCONFIG=true + [ "${BOOTPROTO}" = bootp ] && DHCP_CLIENT=/sbin/pump fi # load the module associated with that device @@ -41,6 +48,7 @@ if [ -n "${HWADDR}" ]; then FOUNDMACADDR=$(get_hwaddr ${REALDEVICE}) if [ "${FOUNDMACADDR}" != "${HWADDR}" -a "${FOUNDMACADDR}" != "${MACADDR}" ]; then net_log $"Device ${DEVICE} has different MAC address than expected, ignoring." + mdv-network-event connection_failure ${DEVICE} exit 1 fi fi @@ -124,9 +132,67 @@ is_available_wait ${REALDEVICE} ${DEVTIMEOUT} || { else net_log $"Device ${DEVICE} does not seem to be present, delaying initialization." fi + mdv-network-event connection_failure ${DEVICE} exit 1 } +# is the device wireless? If so, configure wireless device specifics +IS_WIRELESS= +if is_wireless_device ${DEVICE}; then + # ralink devices need to be up for wireless-tools to work + ip link set dev ${DEVICE} up + if [ -n "${daemon}" -o "$MII_NOT_SUPPORTED" = "yes" ]; then + # try to trigger association (and always load wireless settings) + WIRELESS_CONFIG="wireless.d/$WIRELESS_ESSID" + [ -f "$WIRELESS_CONFIG" ] && source "$WIRELESS_CONFIG" + . ./ifup-wireless + if [ -n "$WIRELESS_WPA_DRIVER" -a -x /usr/sbin/wpa_supplicant -a -f /etc/wpa_supplicant.conf ]; then + if wpa_cli -i${DEVICE} status &>/dev/null; then + echo "Another wpa_supplicant instance is already running for device $DEVICE" + else + /usr/sbin/wpa_supplicant -B -i ${DEVICE} \ + -c /etc/wpa_supplicant.conf \ + -D ${WIRELESS_WPA_DRIVER} + fi + if [ "$WIRELESS_WPA_REASSOCIATE" = "yes" ]; then + sleep 2 + wpa_cli reassociate + fi + fi + elif [ -n "$WIRELESS_WPA_DRIVER" ]; then + # roaming enabled, on association + # source interface parameters related to current ESSID or AP if any + WIRELESS_CURRENT_ESSID=`iwgetid -r ${DEVICE}` + if [ -n "$WIRELESS_CURRENT_ESSID" ]; then + WIRELESS_CONFIG="wireless.d/$WIRELESS_CURRENT_ESSID" + if [ ! -f "$WIRELESS_CONFIG" ]; then + WIRELESS_CURRENT_AP=`iwgetid -r -a ${DEVICE}` + WIRELESS_CONFIG="wireless.d/$WIRELESS_CURRENT_AP" + fi + if [ -f "$WIRELESS_CONFIG" ]; then + source "$WIRELESS_CONFIG" + else + echo "Wireless device $DEVICE is associated with $WIRELESS_CURRENT_ESSID but configuration is missing" + fi + else + echo "Wireless device $DEVICE is configured with a roaming daemon but isn't associated" + fi + fi + IS_WIRELESS=1 +fi + +# DVB Card +if [ -n "${DVB_ADAPTER_ID}" -a -n "${DVB_NETWORK_DEMUX}" -a -n "${DVB_NETWORK_PID}" ]; then + dvbnet -a ${DVB_ADAPTER_ID} -n ${DVB_NETWORK_DEMUX} -p ${DVB_NETWORK_PID} +fi + +# ATMARP protocol support, enabled if ATM_ADDR is defined (VCI.VPI) +# useful for modems using the atm kernel module (e.g. Speedtouch) +# and ISP using "RFC 1483 Routed VC MUX" (e.g. Free Degroupe) +if [ -n "${ATM_ADDR}" -a -x /usr/sbin/atmarpd -a -x /usr/sbin/atmarp ]; then + pidof atmarpd >/dev/null 2>&1 || /usr/sbin/atmarpd -b -l syslog >/dev/null 2>&1 + atmarp -c ${DEVICE} 2>/dev/null +fi # 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 @@ -138,9 +204,6 @@ if [ -n "${MTU}" ]; then ip link set dev ${DEVICE} mtu ${MTU} fi -# is the device wireless? If so, configure wireless device specifics -is_wireless_device ${DEVICE} && . ./ifup-wireless - # Team slave device? if [ -n "${TEAM_MASTER}" ] && [ ! "${DEVICETYPE}" = "TeamPort" ] && [ -x ./ifup-TeamPort ]; then ./ifup-TeamPort ${CONFIG} $2 @@ -204,37 +267,155 @@ if [ -n "${BRIDGE}" ]; then exit 0 fi -if [ -n "${DYNCONFIG}" ] && [ -x /sbin/dhclient ]; then - if is_true "${PERSISTENT_DHCLIENT}"; then - ONESHOT=""; +# exec ifplugd daemon at boot if supported +if [ -n "${daemon}" -a "$MII_NOT_SUPPORTED" != "yes" ]; then + IFPLUGD_ARGS="${IFPLUGD_ARGS=-I -b}" + exec /sbin/ifplugd $IFPLUGD_ARGS -i $DEVICE +fi + + +BLURB="# temporary ifup addition" + +if [ -n "$DYNCONFIG" -a "XXX$DHCP_CLIENT" = "XXX" ];then + if [ -x /sbin/dhclient ];then + DHCP_CLIENT=/sbin/dhclient + # Remove any temporary references which were previously added to dhclient config + if [ -w /etc/dhclient-${DEVICE}.conf -a -x /sbin/dhclient ] ; then + grep -v "$BLURB" /etc/dhclient-${DEVICE}.conf > /etc/dhclient-${DEVICE}.conf.ifupnew 2> /dev/null + cat /etc/dhclient-${DEVICE}.conf.ifupnew > /etc/dhclient-${DEVICE}.conf + rm -f /etc/dhclient-${DEVICE}.conf.ifupnew + fi + elif [ -x /sbin/dhcpcd ];then + DHCP_CLIENT=/sbin/dhcpcd + elif [ -x /sbin/pump ];then + DHCP_CLIENT=/sbin/pump + elif [ -x /sbin/dhcpxd ];then + DHCP_CLIENT=/sbin/dhcpxd else - ONESHOT="-1"; - fi; + echo $"Can't find a dhcp client" + mdv-network-event connection_failure ${DEVICE} + exit 1; + fi +fi + +if [ "$DHCP_HOSTNAME" ] && [ "$DOMAINNAME" ] +then + DHCP_HOSTNAME=`echo $DHCP_HOSTNAME | sed -e "s/\.$DOMAINNAME//g"` +fi + +DHCP_ARGS= +if [ "XXX$DHCP_CLIENT" != "XXX" ];then +case $(basename $DHCP_CLIENT) in + dhcpcd) + DHCP_ARGS="--waitip" + [ -n "${DHCP_HOSTNAME}" ] && DHCP_ARGS="${DHCP_ARGS} -h ${DHCP_HOSTNAME}" + [ "${PEERDNS}" = "no" ] && DHCP_ARGS="${DHCP_ARGS} -C resolv.conf" + [ "${PEERGATEWAY}" = "no" ] && DHCP_ARGS="${DHCP_ARGS} -G" + [ -n "${DHCP_TIMEOUT}" ] && DHCP_ARGS="${DHCP_ARGS} -t ${DHCP_TIMEOUT}" + [ "${NEEDHOSTNAME}" = "no" ] && DHCP_ARGS="${DHCP_ARGS} -C lookup-hostname" + if [ "${PEERNTPD}" = "yes" ]; then + DHCP_ARGS="${DHCP_ARGS} -o ntp_servers" + else + DHCP_ARGS="${DHCP_ARGS} -C ntp.conf -O ntp_servers" + fi + if [ "${PEERYP}" = "yes" ]; then + DHCP_ARGS="${DHCP_ARGS} -o nis_domain -o nis_servers" + else + DHCP_ARGS="${DHCP_ARGS} -C yp.conf -C ypbind -O nis_domain -O nis_servers" + fi + + DHCP_ARGS="${DHCP_ARGS} ${DEVICE}" + PIDF=/var/run/dhcpcd-${DEVICE}.pid + if [[ -f ${PIDF} ]]; then + PID=$(cat ${PIDF}) + if [[ -n ${PID} ]]; then + echo "dhcpcd is running, ifdown the interface first" + exit; + fi + /bin/rm -f ${PIDF}; #clear it + fi + ;; + pump) + [ -n "$DHCP_HOSTNAME" ] && DHCP_ARGS="-h $DHCP_HOSTNAME" + [ "${NEEDHOSTNAME}" = "yes" ] && DHCP_ARGS="$DHCP_ARGS --lookup-hostname" + [ "${PEERDNS}" = "no" ] && DHCP_ARGS="$DHCP_ARGS -d" + [ "${PEERGATEWAY}" = "no" ] && DHCP_ARGS="$DHCP_ARGS --no-gateway" + DHCP_ARGS="$DHCP_ARGS -i $DEVICE" + ;; + dhcpxd) + # dhcpxd don't support NEEDHOSTNAME, PEERGATEWAY + [ -n "$DHCP_HOSTNAME" ] && DHCP_ARGS="-H $HOSTNAME" + DHCP_ARGS="$DHCP_ARGS --wait $DEVICE" + ;; + dhclient) + if [[ "${PERSISTENT_DHCLIENT}" = [yY1]* ]]; then + ONESHOT= + else + ONESHOT="-1" + fi generate_config_file_name generate_lease_file_name + DHCP_ARGS="$DHCP_ARGS $ONESHOT -q ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient-${DEVICE}.pid $DEVICE" + if [ -n "$DHCP_HOSTNAME" ]; then + if [ ! -e /etc/dhclient-${DEVICE}.conf ] || ! grep -q "[^# ]*send *host-name" /etc/dhclient-${DEVICE}.conf; then + echo "send host-name \"${DHCP_HOSTNAME}\"; $BLURB" >> /etc/dhclient-${DEVICE}.conf + fi + fi + if [ -n "$DHCP_TIMEOUT" ]; then + if [ ! -e /etc/dhclient-${DEVICE}.conf ] || ! grep -q "[^# ]*timeout" /etc/dhclient-${DEVICE}.conf; then + echo "timeout $DHCP_TIMEOUT; $BLURB" >> /etc/dhclient-${DEVICE}.conf + fi + fi + ;; +esac +fi - # Initialize the dhclient args and obtain the hostname options if needed: - DHCLIENTARGS="${DHCLIENTARGS} ${ONESHOT} -q ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /run/dhclient-${DEVICE}.pid" - set_hostname_options DHCLIENTARGS +# Remove any temporary references which were previously added to dhclient config +if [ -w /etc/dhclient-${DEVICE}.conf ] && [ -x /sbin/dhclient ] ; then + LC_ALL=C grep -v "# temporary MDK ifup addition" /etc/dhclient-${DEVICE}.conf > /etc/dhclient-${DEVICE}.conf.ifupnew 2> /dev/null + cat /etc/dhclient-${DEVICE}.conf.ifupnew > /etc/dhclient-${DEVICE}.conf + rm -f /etc/dhclient-${DEVICE}.conf.ifupnew +fi +if [ -n "${DYNCONFIG}" ]; then echo echo -n $"Determining IP information for ${DEVICE}..." if ! is_true "${PERSISTENT_DHCLIENT}" && check_link_down ${DEVICE}; then echo $" failed; no link present. Check cable?" + ip link set dev ${DEVICE} down >/dev/null 2>&1 + mdv-network-event connection_failure ${DEVICE} exit 1 fi ethtool_set - if /sbin/dhclient ${DHCLIENTARGS} ${DEVICE} ; then + mdv-network-event dhcp_request ${DEVICE} + if $DHCP_CLIENT $DHCP_ARGS ; then + mdv-network-event dhcp_success ${DEVICE} echo $" done." dhcpipv4="good" else + mdv-network-event dhcp_failure ${DEVICE} + # Associate a zeroconf IP address to an alias of the interface + if [ -x /sbin/zcip ]; then + mdv-network-event zcip_request ${DEVICE} + if /sbin/zcip -s -i $DEVICE:${ZEROCONF_ALIAS_NUMER=9}; then + mdv-network-event zcip_success ${DEVICE} + echo $" done." + if [ -x /etc/init.d/tmdns ]; then + /etc/init.d/tmdns reload > /dev/null 2>&1 + fi + exit 0 + fi + fi + mdv-network-event zcip_failure ${DEVICE} echo $" failed." if is_true "${IPV4_FAILURE_FATAL}"; then + mdv-network-event connection_failure ${DEVICE} exit 1 fi if is_false "$IPV6INIT" || ! is_true "$DHCPV6C"; then + mdv-network-event connection_failure ${DEVICE} exit 1 fi net_log "Unable to obtain IPv4 DHCP address ${DEVICE}." warning @@ -255,6 +436,7 @@ else if ! ip link set dev ${REALDEVICE} up ; then net_log $"Failed to bring up ${DEVICE}." + mdv-network-event connection_failure ${DEVICE} exit 1 fi @@ -274,18 +456,21 @@ else SRC= fi + if [ "${REALDEVICE}" != "lo" ]; then # set IP address(es) for idx in {0..256} ; do if [ -z "${ipaddr[$idx]}" ]; then break fi + if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then if [ "${REALDEVICE}" != "lo" ] && ! is_false "${arpcheck[$idx]}"; then ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]}) if [ $? = 1 ]; then ARPINGMAC=$(echo $ARPING | sed -ne 's/.*\[\(.*\)\].*/\1/p') net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}." + mdv-network-event connection_failure ${DEVICE} exit 1 fi fi @@ -310,6 +495,7 @@ else # set lifetime of address to forever ip addr change ${ipaddr[$idx]}/${prefix[$idx]} dev ${REALDEVICE} valid_lft forever preferred_lft forever done + fi # Set a default route. if ! is_false "${DEFROUTE}" && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then @@ -365,6 +551,7 @@ if is_true "${DHCPV6C}" && [ -x /sbin/dhclient ]; then echo -n $"Determining IPv6 information for ${DEVICE}..." # Initialize the dhclient args for IPv6 and obtain the hostname options if needed: + if is_true "${PERSISTENT_DHCLIENT}"; then ONESHOT=""; else @@ -372,7 +559,15 @@ if is_true "${DHCPV6C}" && [ -x /sbin/dhclient ]; then fi; DHCLIENTARGS="-6 ${ONESHOT} ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /run/dhclient6-${DEVICE}.pid ${DEVICE}" - set_hostname_options DHCLIENTARGS + + # We need to wait for duplicate address detection to complete before running dhclient -6 + for i in $(seq 5); do + lladdress=$(ip -6 -o a s dev "$DEVICE" scope link -tentative) + if [ -n "$lladdress" ]; then + break + fi + sleep 1 + done if /sbin/dhclient $DHCLIENTARGS; then echo $" done." |