Merge "Support adding DHCP interfaces one at a time."

This commit is contained in:
Jenkins 2014-03-17 19:52:41 +00:00 committed by Gerrit Code Review
commit 5af4c268f9
4 changed files with 24 additions and 25 deletions

View File

@ -9,6 +9,5 @@ DIB_INIT_SYSTEM=$(dib-init-system)
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.conf /etc/init/dhcp-all-interfaces.conf
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.service /usr/lib/systemd/system/dhcp-all-interfaces.service
systemctl enable dhcp-all-interfaces.service
install -D -g root -o root -m 0644 ${SCRIPTDIR}/udev.rules /etc/udev/rules.d/99-dhcp-all-interfaces.rules
fi

View File

@ -1,14 +0,0 @@
[Unit]
Description=DHCP All Interfaces Service
Wants=local-fs.target systemd-udev-settle.service
After=local-fs.target systemd-udev-settle.service
Before=network.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/dhcp-all-interfaces.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Alias=dhcp-all-interfaces.service

View File

@ -1,7 +1,10 @@
#!/bin/bash
INTERFACE=${1:-} #optional, if not specified configure all available interfaces
ENI_FILE="/etc/network/interfaces"
PATH=/sbin:$PATH
if [ -d "/etc/network" ]; then
CONF_TYPE="eni"
elif [ -d "/etc/sysconfig/network-scripts/" ]; then
@ -13,9 +16,9 @@ fi
if [ "$CONF_TYPE" == "eni" ]; then
# Serialize runs so that we don't miss hot-add interfaces
FLOCK=${1:-}
if [ -z "$FLOCK" ] ; then
exec flock -x $ENI_FILE $0 flocked
FLOCKED=${FLOCKED:-}
if [ -z "$FLOCKED" ] ; then
FLOCKED=true exec flock -x $ENI_FILE $0
fi
fi
@ -63,16 +66,17 @@ function config_exists() {
fi
}
for interface in $(ls /sys/class/net | grep -v ^lo$) ; do
MAC_ADDR_TYPE="$(cat /sys/class/net/${interface}/addr_assign_type)"
function inspect_interface() {
local interface=$1
local mac_addr_type="$(cat /sys/class/net/${interface}/addr_assign_type)"
echo -n "Inspecting interface: $interface..."
if config_exists $interface; then
echo "Has config, skipping."
elif [ "$MAC_ADDR_TYPE" != "0" ]; then
elif [ "$mac_addr_type" != "0" ]; then
echo "Device has generated MAC, skipping."
else
ip link set dev $interface up >/dev/null 2>&1
else
ip link set dev $interface up &>/dev/null
HAS_LINK="$(get_if_link $interface)"
TRIES=10
@ -91,4 +95,13 @@ for interface in $(ls /sys/class/net | grep -v ^lo$) ; do
disable_interface "$interface"
fi
fi
done
}
if [ -n "$INTERFACE" ]; then
inspect_interface $INTERFACE
else
for iface in $(ls /sys/class/net | grep -v ^lo$); do
inspect_interface $iface
done
fi

View File

@ -0,0 +1 @@
SUBSYSTEM=="net", ACTION=="add", RUN+="/usr/local/sbin/dhcp-all-interfaces.sh $name", RUN+="/sbin/ifup $name"