Commit 095f2ce1 authored by David Johnson's avatar David Johnson
Browse files

Workaround smart dhclient on centos7; fixes #54.

From the comments:

  Work around dhclient-scripts that forcibly set preferred_lft and
  valid_lft.  We cannot override the lease time sent from the server
  with a real infinite value (our best bet would be UINT32_MAX, and that
  sucks), so we intercept dhclient's name for the new lease time it's
  about to feed to the ip command.  Does this suck any less?  We cannot
  ex post facto run `ip addr change ...` just to reset the preferred_lft
  and valid_lft fields to "forever"; that seems to be tightly coupled
  with assigning an address to an interface (and we don't want to re-add
  the address; that is the whole point of dhclient-script!).  (Some
  dhclients also do not process "expire never" in dhclient.conf
  correctly, so this is what we are left with!)
parent 225d295c
#
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -100,6 +100,10 @@ etc-install: dir-install sysetc-remove sysetc-install
@echo "centos-specific etc-install done"
sysetc-install: ifcfgs dir-install
# Install our version of dhclient-enter-hooks that overrides the
# lease time in dhclient-script's invocation of the `ip addr
# ... valid_lft ... preferred_lft ...` command to "forever".
$(INSTALL) -m 755 $(SRCDIR)/dhclient-enter-hooks $(SYSETCDIR)/dhclient-enter-hooks
# Clean up stuff from the base linux install. Ick.
# See ntpd.service below.
ln -sf /etc/dhclient-enter-hooks $(SYSETCDIR)/dhcp/
......
#!/bin/sh
#
# Copyright (c) 2004-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file 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 Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
OLDETCDIR="$ETCDIR"
. /etc/emulab/paths.sh
#
# Sweet! dhclient on linux wants to DHCP on the loopback interface
# thus screwing up its default setting. Put a stop to that early on!
#
if [ xxx$interface = xxxlo ]; then
ETCDIR="$OLDETCDIR"
export ETCDIR
exit_status=1
return
fi
echo "`date`: ${interface}: ${reason}" >>$LOGDIR/dhclient-enter.log 2>&1
#
# Work around dhclient-scripts that forcibly set preferred_lft and
# valid_lft. We cannot override the lease time sent from the server
# with a real infinite value (our best bet would be UINT32_MAX, and that
# sucks), so we intercept dhclient's name for the new lease time it's
# about to feed to the ip command. Does this suck any less? We cannot
# ex post facto run `ip addr change ...` just to reset the preferred_lft
# and valid_lft fields to "forever"; that seems to be tightly coupled
# with assigning an address to an interface (and we don't want to re-add
# the address; that is the whole point of dhclient-script!). (Some
# dhclients also do not process "expire never" in dhclient.conf
# correctly, so this is what we are left with!)
#
export new_dhcp_lease_time="forever"
#
# XXX Hack to force the duplex on interfaces
#
setduplex() {
_if=$1
_rc=0
_out=`/sbin/ethtool $_if`
if [ $? -eq 0 ]; then
_hmb=`echo $_out | grep -c 'Speed: 100Mb/s'`
_fdx=`echo $_out | grep -c 'Duplex: Full'`
else
_out=`/sbin/mii-tool $_if`
_hmb=`echo $_out | grep -c '100 Mbit'`
_fdx=`echo $_out | grep -c 'full duplex'`
fi
if [ $_hmb -ne 0 -a $_fdx -ne 0 ]; then
echo "$_if: speed/duplex correct"
else
echo -n "$_if: fixing speed/duplex..."
if /sbin/ethtool $_if >/dev/null 2>&1; then
/sbin/ethtool -s $_if autoneg off speed 100 duplex full
else
/sbin/mii-tool --force=100baseTx-FD $_if
fi
_rc=$?
echo "returns $_rc"
fi
return $_rc
}
if [ x$reason != xREBOOT -a x$reason != xBOUND -a x$reason != xRENEW -a x$reason != xREBIND ]
then
# do nothing
true
elif [ x"$new_domain_name_servers" = "x1.1.1.1" ]; then
#
# ElabinElab support.
#
# XXX oh so hacky. Real boss is set to return 1.1.1.1 as a name server
# for nodes in inner elabs. This is the hack de jour for determining
# who has responded to our DHCP request. If it is outer boss and we are
# an inner node, we want to decline this offer and not configure the
# interface
#
exit_status=1
#
# XXX since we now know that we are in an inner elab and we know which
# interface is the real control net, we force 100Mb full-duplex on all
# other (experimental) interfaces. This is necessary to ensure a
# response from the inner control net.
#
for _if in `ifconfig -s | awk '{ print $1 }' | grep -v Iface`
do
if [ $_if != "lo" -a x$_if != x$interface ]; then
setduplex $_if >>$LOGDIR/dhclient-enter.log 2>&1
fi
done
#
# XXX sleep here so we don't pummel boss with REQUEST/DECLINE pairs.
#
sleep 5
elif [ "$new_network_number" = "10.200.1.0" ]; then
#
# XXX sometime we can get a reply even if the duplex is wrong.
# If we get such a reply and we are inside an inner elab, again
# force 100Mb full-duplex to make sure we continue to communicate
# with the server.
#
setduplex $interface >>$LOGDIR/dhclient-enter.log 2>&1
fi
echo "`date`: ${interface}: ${reason}: done" >>$LOGDIR/dhclient-enter.log 2>&1
ETCDIR="$OLDETCDIR"
export ETCDIR
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment