diff -pruN 2.10/debian/changelog 2.10ubuntu3/debian/changelog
--- 2.10/debian/changelog	2020-04-26 19:09:15.000000000 +0000
+++ 2.10ubuntu3/debian/changelog	2020-07-29 11:10:22.000000000 +0000
@@ -1,15 +1,24 @@
-ifenslave (2.10) unstable; urgency=medium
+ifenslave (2.10ubuntu3) groovy; urgency=medium
 
-  * Drop the transitional ifenslave-2.6 packages. Closes: #878601
-  * Update Vcs-* links to point to Salsa.
-  * Add support for tlb_dynamic_lb: Closes: #926881
-  * Remove the ifenslave binary, use iproute2 instead.
-  * Fix typo in bonding example. Closes: #914308
-  * Bump Standards-Version.
-  * Remove debian/compat, use Build-Depends: debhelper-compat instead.
-  * Set Rules-Requires-Root: no.
+  * Revert 2.10ubuntu1, back to 2.9ubuntu1, as 2.10ubuntu1 is miss-merged.
+  * Do not reintroduce transitional package.
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Wed, 29 Jul 2020 12:10:22 +0100
+
+ifenslave (2.9ubuntu1) bionic; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Upstart event based bond bringup:
+      + Drop ethernet+wifi example
+      + Drop two_ethernet example
+      + Update ethernet+hotplug_wifi example
+      + Update two_hotplug_ethernet example
+      + Update pre-up and post-down scripts for event bringup
+      + Update README.Debian examples
+    - Update scripts to use /run/network/ifstate instead of
+      /etc/network/run/ifstate
 
- -- Guus Sliepen <guus@debian.org>  Sun, 26 Apr 2020 21:09:15 +0200
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Fri, 16 Mar 2018 16:04:23 -0700
 
 ifenslave (2.9) unstable; urgency=medium
 
@@ -34,6 +43,22 @@ ifenslave (2.8) unstable; urgency=medium
 
  -- Guus Sliepen <guus@debian.org>  Tue, 27 Sep 2016 14:24:35 +0200
 
+ifenslave (2.7ubuntu1) wily; urgency=medium
+
+  * Merge from Debian unstable. Remaining changes:
+    - Upstart event based bond bringup:
+      + Drop ethernet+wifi example
+      + Drop two_ethernet example
+      + Update ethernet+hotplug_wifi example
+      + Update two_hotplug_ethernet example
+      + Update pre-up and post-down scripts for event bringup
+      + Update README.Debian examples
+    - Update scripts to use /run/network/ifstate instead of
+      /etc/network/run/ifstate
+    (LP: #1477928)
+
+ -- Louis Bouchard <louis.bouchard@ubuntu.com>  Fri, 24 Jul 2015 11:54:55 -0400
+
 ifenslave (2.7) unstable; urgency=low
 
   * Fix change in /sys/class/net/{bond}/slave_ naming after k3.13
@@ -52,6 +77,21 @@ ifenslave (2.6) unstable; urgency=low
 
  -- Dmitry Smirnov <onlyjob@debian.org>  Sun, 31 Aug 2014 11:05:09 +1000
 
+ifenslave (2.5ubuntu1) utopic; urgency=medium
+
+  * Merge from Debian unstable. Remaining changes:
+    - Upstart event based bond bringup:
+      + Drop ethernet+wifi example
+      + Drop two_ethernet example
+      + Update ethernet+hotplug_wifi example
+      + Update two_hotplug_ethernet example
+      + Update pre-up and post-down scripts for event bringup
+      + Update README.Debian examples
+    - Update scripts to use /run/network/ifstate instead of
+      /etc/network/run/ifstate
+
+ -- Stéphane Graber <stgraber@ubuntu.com>  Fri, 02 May 2014 15:39:48 -0400
+
 ifenslave (2.5) unstable; urgency=low
 
   * "ifupdown (>= 0.7.46)" compatibility update (Closes: #742410).
@@ -60,6 +100,12 @@ ifenslave (2.5) unstable; urgency=low
 
  -- Dmitry Smirnov <onlyjob@debian.org>  Mon, 24 Mar 2014 18:26:30 +1100
 
+ifenslave (2.4ubuntu1) trusty; urgency=medium
+
+  * Re-apply Ubuntu delta to new source.
+
+ -- Stéphane Graber <stgraber@ubuntu.com>  Mon, 03 Mar 2014 10:39:30 -0500
+
 ifenslave (2.4) unstable; urgency=medium
 
   * Added "ifenslave-2.6.prerm" to remove dangling alternatives
@@ -352,3 +398,4 @@ ifenslave (0.07-1) unstable; urgency=low
   * Created manpage.
 
  -- Guus Sliepen <guus@sliepen.warande.net>  Wed, 13 Jun 2001 09:31:56 +0200
+
diff -pruN 2.10/debian/control 2.10ubuntu3/debian/control
--- 2.10/debian/control	2020-04-26 19:02:57.000000000 +0000
+++ 2.10ubuntu3/debian/control	2020-07-29 11:10:22.000000000 +0000
@@ -1,7 +1,8 @@
 Source: ifenslave
 Section: net
 Priority: optional
-Maintainer: Guus Sliepen <guus@debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Guus Sliepen <guus@debian.org>
 Uploaders: Dmitry Smirnov <onlyjob@debian.org>
 Build-Depends: debhelper-compat (= 13)
 Rules-Requires-Root: no
diff -pruN 2.10/debian/examples/ethernet+hotplug_wifi 2.10ubuntu3/debian/examples/ethernet+hotplug_wifi
--- 2.10/debian/examples/ethernet+hotplug_wifi	2016-09-27 12:23:58.000000000 +0000
+++ 2.10ubuntu3/debian/examples/ethernet+hotplug_wifi	2016-09-27 22:47:49.000000000 +0000
@@ -2,14 +2,11 @@ A configuration with one ethernet (wire)
 
 -----8<----------8<----------8<----------8<----------8<-----
 
-auto bond0
-iface bond0 inet dhcp
-	bond-slaves eth0
-	bond-mode 1
-	bond-miimon 100
-	bond-primary eth0
+auto eth0
+iface eth0 inet manual
+	bond-master bond0
 
-allow-hotplug wlan0
+auto wlan0
 iface wlan0 inet manual
 	bond-master bond0
 	bond-mode 1
@@ -22,6 +19,12 @@ iface wlan0 inet manual
 	wpa-ssid my-ssid
 	wpa-psk "my-secret-password"
 
+auto bond0
+iface bond0 inet dhcp
+	bond-mode 1
+	bond-miimon 100
+	bond-primary eth0 wlan0
+
 -----8<----------8<----------8<----------8<----------8<-----
 
 You do not need an "iface eth0" stanza.
diff -pruN 2.10/debian/examples/ethernet+wifi 2.10ubuntu3/debian/examples/ethernet+wifi
--- 2.10/debian/examples/ethernet+wifi	2016-09-27 12:23:58.000000000 +0000
+++ 2.10ubuntu3/debian/examples/ethernet+wifi	1970-01-01 00:00:00.000000000 +0000
@@ -1,31 +0,0 @@
-A configuration with one ethernet (wire) interfaces and one wifi interface.
-
------8<----------8<----------8<----------8<----------8<-----
-
-auto bond0
-iface bond0 inet dhcp
-	bond-slaves eth0 wlan0
-	bond-mode 1
-	bond-miimon 100
-	bond-primary eth0
-
-allow-bond0 wlan0
-iface wlan0 inet manual
-	bond-give-a-chance 10
-	wpa-bridge bond0
-	wpa-key-mgmt WPA-PSK
-	wpa-proto WPA
-	wpa-group CCMP
-	wpa-ssid my-ssid
-	wpa-psk "my-secret-password"
-
------8<----------8<----------8<----------8<----------8<-----
-
-You do not need an "iface eth0" stanza.
-
-The "auto bond0" stanza is required, else bond0 won't be brought up.
-
-The "allow-bond0 wlan0" stanza is required, to bring wlan0 up together with bond0.
-
-The "wpa-bridge bond0" stanza is required to inform wpa_supplicant that wifi link-level packets will arrive on bond0, not on wlan0.
-The "bond-give-a-chance 10" stanza is required to give a chance for wifi authentication to succeed.
diff -pruN 2.10/debian/examples/two_ethernet 2.10ubuntu3/debian/examples/two_ethernet
--- 2.10/debian/examples/two_ethernet	2012-07-13 09:03:40.000000000 +0000
+++ 2.10ubuntu3/debian/examples/two_ethernet	1970-01-01 00:00:00.000000000 +0000
@@ -1,14 +0,0 @@
-A simple configuration with two ethernet (wire) interfaces.
-
------8<----------8<----------8<----------8<----------8<-----
-
-auto bond0
-iface bond0 inet dhcp
-	bond-slaves eth0 eth1
-	bond-mode 1
-	bond-miimon 100
-	bond-primary eth0 eth1
-
------8<----------8<----------8<----------8<----------8<-----
-
-You do not need an "iface eth0" nor an "iface eth1" stanza.
diff -pruN 2.10/debian/examples/two_hotplug_ethernet 2.10ubuntu3/debian/examples/two_hotplug_ethernet
--- 2.10/debian/examples/two_hotplug_ethernet	2020-04-26 18:54:06.000000000 +0000
+++ 2.10ubuntu3/debian/examples/two_hotplug_ethernet	2016-09-27 22:47:49.000000000 +0000
@@ -2,20 +2,18 @@ A configuration with two hotplug etherne
 
 -----8<----------8<----------8<----------8<----------8<-----
 
-auto bond0
-iface bond0 inet dhcp
-	bond-slaves none
-	bond-mode 1
-	bond-miimon 100
-
-allow-hotplug eth0
+auto eth0
 iface eth0 inet manual
 	bond-master bond0
-	bond-primary eth0 eth1
 
-allow-hotplug eth1
+auto eth1
 iface eth1 inet manual
 	bond-master bond0
+
+auto bond0
+iface bond0 inet dhcp
+	bond-mode 1
+	bond-miimon 100
 	bond-primary eth0 eth1
 
 -----8<----------8<----------8<----------8<----------8<-----
diff -pruN 2.10/debian/ifenslave.8 2.10ubuntu3/debian/ifenslave.8
--- 2.10/debian/ifenslave.8	1970-01-01 00:00:00.000000000 +0000
+++ 2.10ubuntu3/debian/ifenslave.8	2016-09-27 22:47:49.000000000 +0000
@@ -0,0 +1,63 @@
+.Dd 2012-07-13
+.Dt IFENSLAVE 8
+.Os "Debian GNU/Linux"
+.\" Manual page created by Guus Sliepen <guus@debian.org>
+.Sh NAME
+.Nm ifenslave
+.Nd Attach and detach slave network devices to a bonding device.
+.Sh SYNOPSIS
+.Nm
+.Op Fl acdfhuvV
+.Op Fl -all-interfaces
+.Op Fl -change-active
+.Op Fl -detach
+.Op Fl -force
+.Op Fl -help
+.Op Fl -usage
+.Op Fl -verbose
+.Op Fl -version
+.Ar master
+.Ar slave
+.No ...
+.Sh DESCRIPTION
+.Nm
+is a tool to attach and detach slave network devices to a bonding device.
+A bonding device will act like a normal Ethernet network device to the kernel,
+but will send out the packets via the slave devices using a simple round-robin scheduler.
+This allows for simple load-balancing,
+identical to "channel bonding" or "trunking" techniques used in switches.
+.Pp
+The kernel must have support for bonding devices for
+.Nm
+to be useful.
+.Sh OPTIONS
+.Bl -tag -width indent
+.It Fl a, -all-interfaces
+Show information about all interfaces.
+.It Fl c, -change-active
+Change active slave.
+.It Fl d, -detach
+Removes slave interfaces from the bonding device.
+.It Fl f, -force
+Force actions to be taken if one of the specified interfaces appears not to belong to an Ethernet device.
+.It Fl h, -help
+Display a help message and exit.
+.It Fl u, -usage
+Show usage information and exit.
+.It Fl v, -verbose
+Print warning and debug messages.
+.It Fl V, -version
+Show version information and exit.
+.El
+.Pp
+If no options are given, the default action will be to enslave interfaces.
+.Sh EXAMPLE
+The following example shows how to setup a bonding device and
+enslave two real Ethernet devices to it:
+.Bd -literal
+# modprobe bonding
+# ifconfig bond0 192.168.0.1 netmask 255.255.0.0
+# ifenslave bond0 eth0 eth1
+.Ed
+.Sh AUTHOR
+.An Guus Sliepen Aq guus@debian.org
diff -pruN 2.10/debian/ifenslave.if-post-down 2.10ubuntu3/debian/ifenslave.if-post-down
--- 2.10/debian/ifenslave.if-post-down	2016-09-27 12:23:58.000000000 +0000
+++ 2.10ubuntu3/debian/ifenslave.if-post-down	2016-09-27 22:47:49.000000000 +0000
@@ -62,3 +62,7 @@ for slave in $slaves ; do
 		echo "-$slave" > "$BOND_PARAMS/slaves" 2> /dev/null
 	fi
 done
+
+# Remove the master itself
+echo "-$IFACE" > /sys/class/net/bonding_masters
+rm /run/network/ifenslave.$IFACE
diff -pruN 2.10/debian/ifenslave.if-pre-up 2.10ubuntu3/debian/ifenslave.if-pre-up
--- 2.10/debian/ifenslave.if-pre-up	2018-05-08 21:01:37.000000000 +0000
+++ 2.10ubuntu3/debian/ifenslave.if-pre-up	2018-03-16 23:04:23.000000000 +0000
@@ -6,10 +6,36 @@
 
 add_master()
 {
-	# Return if $IFACE is already a bonding interface.
-	[ -f "/sys/class/net/$IFACE/bonding/slaves" ] && return
+	# Return if $BOND_MASTER is already a bonding interface.
+	[ -f "/sys/class/net/$BOND_MASTER/bonding/slaves" ] && return
 
-	ip link add dev "$IFACE" type bond
+	# If the bonding module is not yet loaded, load it.
+	if [ ! -r /sys/class/net/bonding_masters ]; then
+		modprobe -q bonding
+
+		FAILED=1
+		echo "Waiting for bonding kernel module to be ready (will timeout after 5s)"
+		count=0
+		while [ "$count" -lt "50" ]; do
+			if [ -r /sys/class/net/bonding_masters ]; then
+				FAILED=0
+				break
+			fi
+			sleep 0.1
+			count=$(($count+1))
+		done
+
+		if [ "$FAILED" = "1" ]; then
+			echo "/sys/class/net/bonding_masters doesn't exist. Unable to create $BOND_MASTER"
+			exit 1
+		fi
+
+	fi
+
+	# Create the master interface.
+	if ! grep -sq "\\<$BOND_MASTER\\>" /sys/class/net/bonding_masters; then
+		echo "+$BOND_MASTER" > /sys/class/net/bonding_masters
+	fi
 }
 
 sysfs_change_down()
@@ -17,7 +43,7 @@ sysfs_change_down()
 	# Called with :
 	# $1 = basename of the file in bonding/ to write to.
 	# $2 = value to write. Won't write if $2 is empty.
-	if [ -n "$2" ] ; then
+	if [ "$2" ] ; then
 		# If the value we plan to write is different from the current one...
 		if ! grep -sq "\\<$2\\>" "/sys/class/net/$BOND_MASTER/bonding/$1" ; then
 			# ...and the master is up...
@@ -35,7 +61,7 @@ sysfs()
 	# Called with :
 	# $1 = basename of the file in bonding/ to write to.
 	# $2 = value to write. Won't write if $2 is empty.
-	if [ -n "$2" ] ; then
+	if [ "$2" ] ; then
 		echo "$2" > "/sys/class/net/$BOND_MASTER/bonding/$1"
 		return $?
 	fi
@@ -67,6 +93,40 @@ early_setup_master()
 	sysfs fail_over_mac "$IF_BOND_FAIL_OVER_MAC"
 }
 
+# late_setup_master runs actions that need to happen after enslavement
+late_setup_master()
+{
+	# primary must be set after mode (because only supported in some modes) and after enslavement.
+	# The first slave in bond-primary found in current slaves becomes the primary.
+	# If no slave in bond-primary is found, then the primary does not change.
+	for slave in $IF_BOND_PRIMARY ; do
+		if grep -sq "\\<$slave\\>" "/sys/class/net/$BOND_MASTER/bonding/slaves" ; then
+			sysfs primary "$slave"
+			break
+		fi
+	done
+
+	# primary_reselect should be set after mode (because only supported in some modes), after enslavement
+	# and after primary. This is currently (2.6.35-rc1) not enforced by the bonding driver, but it is
+	# probably safer to do it in that order.
+	sysfs primary_reselect "$IF_BOND_PRIMARY_RESELECT"
+
+	# queue_id must be set after enslavement.
+	for iface_queue_id in $IF_BOND_QUEUE_ID
+	do
+		sysfs iface_queue_id $iface_queue_id
+	done
+
+	# active_slave must be set after mode and after enslavement.
+	# The slave must be up and the underlying link must be up too.
+	# FIXME: We should have a way to write an empty string to active_slave, to set the active_slave to none.
+	if [ "$IF_BOND_ACTIVE_SLAVE" ] ; then
+		# Need to force interface up before. Bonding will refuse to activate a down interface.
+		ip link set "$IF_BOND_ACTIVE_SLAVE" up
+		sysfs active_slave "$IF_BOND_ACTIVE_SLAVE"
+	fi
+}
+
 enslave_slaves()
 {
 	case "$BOND_SLAVES" in
@@ -74,23 +134,29 @@ enslave_slaves()
 			BOND_SLAVES=""
 			;;
 		all)
-			BOND_SLAVES=`sed -ne 's/ *\(eth[^:]*\):.*/\1/p' /proc/net/dev`
+			BOND_SLAVES=""
+			for device in /sys/class/net/*/device; do
+				name=$(basename ${device%*/device})
+				[ -n "$BOND_SLAVES" ] && BOND_SLAVES="$BOND_SLAVES $name" || BOND_SLAVES="$name"
+			done
 			AUTOIF="yes"
 			;;
 	esac
 
 	[ "$VERBOSITY" = 1 ] && v=-v
 	for slave in $BOND_SLAVES ; do
-		if ifquery --state $slave 2>/dev/null || [ -n "IFUPDOWN_$IFACE" ]; then
-			# Skipping interface that's already up or being configured
-			continue
+		if ( [ "$AUTOIF" ] && ifquery --state $slave ) ; then
+			echo "Not enslaving interface $slave since it is already configured"
 		else
-			if ifquery -l $slave 2>/dev/null; then
-				ifup $slave
+			# Ensure $slave is down.
+			ip link set "$slave" down 2>/dev/null
+			if ! sysfs_add slaves "$slave" 2>/dev/null ; then
+				echo "Failed to enslave $slave to $BOND_MASTER. Is $BOND_MASTER ready and a bonding interface ?" >&2
 			else
-				ip link set "$slave" down 2>/dev/null
-				if ! sysfs_add slaves "$slave" 2>/dev/null ; then
-					echo "Failed to enslave $slave to $IFACE." >&2
+				# Bring up slave if it is the target of an allow-bondX stanza.
+				# This is useful to bring up slaves that need extra setup.
+				if [ -z "$(which ifquery)" ] || ifquery --allow \"$BOND_MASTER\" --list | grep -q $slave; then
+					ifup $v --allow "$BOND_MASTER" "$slave"
 				fi
 			fi
 		fi
@@ -110,6 +176,10 @@ setup_master()
 	# num_unsol_na can be set anytime.
 	sysfs num_unsol_na "$IF_BOND_NUM_UNSOL_NA"
 
+	# xmit_hash_policy can be set anytime.
+	# Changing xmit_hash_policy requires $BOND_MASTER to be down.
+	sysfs_change_down xmit_hash_policy "$IF_BOND_XMIT_HASH_POLICY"
+
 	# arp_ip_target must be set before arp_interval.
 	sysfs_add arp_ip_target "$IF_BOND_ARP_IP_TARGET"
 	sysfs arp_interval "$IF_BOND_ARP_INTERVAL"
@@ -126,10 +196,6 @@ setup_master()
 	# Mode should be set after miimon or arp_interval, to avoid a warning in syslog.
 	sysfs_change_down mode "$IF_BOND_MODE"
 
-	# Requires $BOND_MASTER to be down and mode to be configured
-	sysfs_change_down xmit_hash_policy "$IF_BOND_XMIT_HASH_POLICY"
-	sysfs_change_down tlb_dynamic_lb "$IF_BOND_TLB_DYNAMIC_LB"
-
 	# packets_per_slave allowed for mode balance-rr only.
 	sysfs packets_per_slave "$IF_BOND_PACKETS_PER_SLAVE"
 
@@ -140,83 +206,81 @@ setup_master()
 	# Changing lacp_rate requires $BOND_MASTER to be down.
 	sysfs_change_down lacp_rate "$IF_BOND_LACP_RATE"
 
-	# queue_id must be set after enslavement.
-	for iface_queue_id in $IF_BOND_QUEUE_ID
-	do
-		sysfs iface_queue_id $iface_queue_id
-	done
+	# Finally bring the bond up, note that without a slave it won't be usable though
+	ip link set dev $BOND_MASTER up
+}
 
-	# active_slave must be set after mode and after enslavement.
-	# The slave must be up and the underlying link must be up too.
-	# FIXME: We should have a way to write an empty string to active_slave, to set the active_slave to none.
-	if [ -n "$IF_BOND_ACTIVE_SLAVE" ] ; then
-		if [ "$IF_BOND_ACTIVE_SLAVE" = "none" ] ; then
-			sysfs active_slave ""
-		else
-			# Need to force interface up before. Bonding will refuse to activate a down interface.
-			if ifquery -l $IF_BOND_ACTIVE_SLAVE 2>/dev/null ; then
-				ifup $IF_BOND_ACTIVE_SLAVE
-			else
-				ip link set "$IF_BOND_ACTIVE_SLAVE" up
-			fi
-			sysfs active_slave "$IF_BOND_ACTIVE_SLAVE"
-		fi
+# Option slaves deprecated, replaced by bond-slaves, but still supported for backward compatibility.
+IF_BOND_SLAVES=${IF_BOND_SLAVES:-$IF_SLAVES}
+
+if [ "$IF_BOND_MASTER" ] ; then
+	BOND_MASTER="$IF_BOND_MASTER"
+	BOND_SLAVES="$IFACE"
+else
+	if [ "$IF_BOND_SLAVES" ] ; then
+		BOND_MASTER="$IFACE"
+		BOND_SLAVES="$IF_BOND_SLAVES"
 	fi
-}
+fi
 
-setup_primary() {
-	# primary must be set after mode (because only supported in some modes) and after enslavement.
-	# The first slave in bond-primary found in current slaves becomes the primary.
-	# If no slave in bond-primary is found, then the primary does not change.
-	for slave in $IF_BOND_PRIMARY ; do
-		if grep -sq "\\<$slave\\>" "/sys/class/net/$BOND_MASTER/bonding/slaves" ; then
-			sysfs primary "$slave"
-			break
-		fi
-	done
+# Exit if nothing to do...
+[ -z "$BOND_MASTER$BOND_SLAVES" ] && exit
 
-	# primary_reselect should be set after mode (it is only supported in some modes), after enslavement
-	# and after primary. This is currently (2.6.35-rc1) not enforced by the bonding driver, but it is
-	# probably safer to do it in that order.
-	sysfs primary_reselect "$IF_BOND_PRIMARY_RESELECT"
-}
+# Always try to create the master, returns if already exists
+add_master
 
-setup_master() {
-	add_master
+if [ "$BOND_MASTER" = "$IFACE" ]; then
+	# Setup the master interface
 	early_setup_master
 	setup_master
-	enslave_slaves
-	setup_primary
-}
 
-setup_slave() {
-	# Require the bond master to have an iface stanza
-	if ! ifstate -l "$IF_BOND_MASTER" 2>/dev/null ; then
-		echo "No iface stanza found for master $IF_BOND_MASTER" >&2
-		exit 1
-	fi
-
-	# Ensure the master is up or being configured
-	if [ -z "IFENSLAVE_$IF_BOND_MASTER" ] ; then
-		ifquery --state "$IF_BOND_MASTER" 2>/dev/null || ifup "$IF_BOND_MASTER"
-	fi
+	# Indicate that we're done setting up the master
+	# this is required as ifstate is modified at the beginning
+	# of the interface setup, not at the end
+	touch /run/network/ifenslave.$IFACE
+
+	# Wait for a slave to join, continuing without a slave
+	# would make dhclient, vconfig or brctl fail, so better wait
+	# Timeout after a minute
+	FAILED=1
+	echo "Waiting for a slave to join $BOND_MASTER (will timeout after 60s)"
+	count=0
+	while [ "$count" -lt "600" ]; do
+		if [ -n "$(cat /sys/class/net/$BOND_MASTER/bonding/slaves)" ]; then
+			FAILED=0
+			break
+		fi
+		sleep 0.1
+		count=$(($count+1))
+	done
+	if [ "$FAILED" = "1" ]; then
+		echo "No slave joined $BOND_MASTER, continuing anyway"
+	else
+		# Trigger the udev bridging hook to bridge the bond if needed
+		if [ -x /lib/udev/bridge-network-interface ]; then
+			INTERFACE=$BOND_MASTER /lib/udev/bridge-network-interface
+		fi
 
-	# Enslave it to the master
-	ip link set "$slave" down 2>/dev/null
-	if ! sysfs_add slaves "$slave" 2>/dev/null ; then
-		echo "Failed to enslave $slave to $BOND_MASTER." >&2
+		# Trigger the udev bridging hook to tag the bond if needed
+		if [ -x /lib/udev/vlan-network-interface ]; then
+			INTERFACE=$BOND_MASTER /lib/udev/vlan-network-interface
+		fi
 	fi
+else
+	# Wait for the master to be ready
+	[ ! -f /run/network/ifenslave.$BOND_MASTER ] && echo "Waiting for bond master $BOND_MASTER to be ready"
+	while :; do
+		if [ -f /run/network/ifenslave.$BOND_MASTER ]; then
+			break
+		fi
+		sleep 0.1
+	done
 
-	setup_primary
-}
-
-# Option slaves deprecated, replaced by bond-slaves, but still supported for backward compatibility.
-IF_BOND_SLAVES=${IF_BOND_SLAVES:-$IF_SLAVES}
+	# Only setup one slave at once
+	BOND_SLAVES=$IFACE enslave_slaves
 
-if [ -n "$IF_BOND_MASTER" ] ; then
-	setup_slave "$IFACE"
-elif [ -n "$IF_BOND_SLAVES" -o -n "$IF_BOND_MODE" ] ; then
-	setup_master "$IFACE"
+	# Call late_setup_master every time we add a slave as we don't have a way to know
+	# when all the slaves are up
+	BOND_SLAVES=$IFACE late_setup_master
 fi
-
 exit 0
diff -pruN 2.10/debian/ifenslave.install 2.10ubuntu3/debian/ifenslave.install
--- 2.10/debian/ifenslave.install	1970-01-01 00:00:00.000000000 +0000
+++ 2.10ubuntu3/debian/ifenslave.install	2016-09-27 22:47:49.000000000 +0000
@@ -0,0 +1 @@
+ifenslave		sbin/
diff -pruN 2.10/debian/ifenslave.links 2.10ubuntu3/debian/ifenslave.links
--- 2.10/debian/ifenslave.links	1970-01-01 00:00:00.000000000 +0000
+++ 2.10ubuntu3/debian/ifenslave.links	2016-09-27 22:47:49.000000000 +0000
@@ -0,0 +1,2 @@
+/sbin/ifenslave			/sbin/ifenslave-2.6
+/usr/share/man/man8/ifenslave.8	/usr/share/man/man8/ifenslave-2.6.8
diff -pruN 2.10/debian/ifenslave.manpages 2.10ubuntu3/debian/ifenslave.manpages
--- 2.10/debian/ifenslave.manpages	1970-01-01 00:00:00.000000000 +0000
+++ 2.10ubuntu3/debian/ifenslave.manpages	2016-09-27 22:47:49.000000000 +0000
@@ -0,0 +1 @@
+debian/*.8
diff -pruN 2.10/debian/NEWS 2.10ubuntu3/debian/NEWS
--- 2.10/debian/NEWS	2018-05-08 20:49:43.000000000 +0000
+++ 2.10ubuntu3/debian/NEWS	1970-01-01 00:00:00.000000000 +0000
@@ -1,7 +0,0 @@
-ifenslave (2.10) UNRELEASED; urgency=medium
-
-  This version of the ifenslave package no longer provides /sbin/ifenslave. The
-  /sbin/ip command from the iproute2 package supports creating bonding masters
-  and enslaving other interfaces to it.
-
- -- Guus Sliepen <guus@debian.org>  Tue, 08 May 2018 22:47:07 +0200
diff -pruN 2.10/debian/README.Debian 2.10ubuntu3/debian/README.Debian
--- 2.10/debian/README.Debian	2018-05-08 20:46:20.000000000 +0000
+++ 2.10ubuntu3/debian/README.Debian	2016-09-27 22:47:49.000000000 +0000
@@ -1,18 +1,14 @@
 ifenslave for Debian
 ----------------------
 
-This package used to provide a program named ifenslave that could be used to
-manually configure a bond interface and enslave other interfaces to it.
-However, since a while now the "ip" command supports creating a bond interface:
+The ifenslave program distributed with the Linux kernel sources has not always
+been up to date, and several modified versions have been floating around. The
+latest kernels now contain an updated version though, but the best way to
+configure bonding is via the files in /sys/class/net/$master/bonding/. This
+Debian package therefore does not contain the binary from the kernel sources,
+but provides a shell script with identical functionality.
 
-    ip link add bond0 type bond
-
-And enslaving another interface to it:
-
-    ip link set eth1 master bond0
-
-This package no longer ships with the program named "ifenslave", it only
-provides hooks for ifupdown to support network bonding in several ways:
+You can also enslave interfaces using Debian's /etc/network/interfaces file:
 
 - You can specify in the stanza of a bonding interface which slaves it
   has.
@@ -34,25 +30,31 @@ A bonding master is defined like this:
 iface bond0 inet static
 	address 208.77.188.166
 	...
-	bond-slaves eth0 eth1
+	bond-primary eth0 eth1
 
-The "bond-slaves" option can take a list of network interfaces, the keyword
-"none" (with obvious results) and the keyword "all" (which selects all
-interfaces with "eth" in their name). Additionally you can set bonding options
-by adding them to the interface section:
+The bonding slaves should then be defined like this:
 
-	bond-mode    active-backup
-	bond-primary eth0
+auto eth0
+iface eth0 inet manual
+	bond-master bond0
 
-This would run the bonding device in active backup mode with eth0 as primary.
+auto eth1
+iface eth1 inet manual
+	bond-master bond0
 
-You can also allow regular interfaces to be enslaved, like this:
+Previous versions of the package supported specifying the slaves all in the
+stanza for the bonding interface, using the "bond-slaves" option.  However,
+in such a configuration there is a race condition between bringing up the
+hardware driver for the ethernet devices and attempting to bring up the
+bonded interface; the bonding interface needs to be initiated from the slave
+interfaces instead.
 
-iface eth2 inet manual
-	bond-master bond0
+You can set additional bonding options by adding them to the interface
+section:
 
-The latter can be used in conjunction with allow-hotplug to automatically add
-hotplugged interfaces to a bonding interface.
+	bond-mode    active-backup
+
+This would run the bonding device in active backup mode with eth0 as primary.
 
 If the master interface is not available at the time the first slave is setup,
 it will be created and setup according to bond-* options in the *slave* stanza.
@@ -62,10 +64,6 @@ possible slave stanzas. However, there e
 different options in a different stanza - for example, to change the primary slave
 when hotpluging a new slave.
 
-Using ifup on a master interface will call ifup for all slaves that are
-flagged with allow-bondX. (bondX being replaced by the master interface
-name). This will allow for extra setup for special slave interfaces.
-
 Using ifdown on a master interface will cause all slaves to be freed and
 disabled. The master is also cleaned-up to ensure reliable results if the
 master is brought up later.
@@ -88,14 +86,15 @@ Most of these options are used to write
 subdirectories of /sys.
 
 For the expected effects of writing into bonding-related /sys files, please read
-the Linux kernel bonding documentation, which can be found here:
-
-https://www.kernel.org/doc/Documentation/networking/bonding.txt
+the bonding documentation (Documentation/networking/bonding.txt) in the linux
+Kernel source tree.
 
 If you think that a bond-* option should exist to write into a bonding-related
 *writable* file in /sys, but no bond-* option exists for that, please report a
 bug against the ifenslave package.
 
+Last checked for kernel version 2.6.35-rc1.
+
 * bond-active-slave:
 	Write into /sys/class/net/<bond>/bonding/active_slave
 	Also force the slave to be up.
@@ -200,9 +199,6 @@ bug against the ifenslave package.
 	be ignored.
 	You must not add a + sign in front of the slave interface names.
 
-* bond-tlb-dynamic-lb:
-	Write into /sys/class/net/<bond>/bonding/tlb_dynamic_lb
-
 * bond-updelay:
 	Write into /sys/class/net/<bond>/bonding/updelay
 
diff -pruN 2.10/debian/source/options 2.10ubuntu3/debian/source/options
--- 2.10/debian/source/options	1970-01-01 00:00:00.000000000 +0000
+++ 2.10ubuntu3/debian/source/options	2016-09-27 22:47:49.000000000 +0000
@@ -0,0 +1 @@
+compression = "xz"
diff -pruN 2.10/ifenslave 2.10ubuntu3/ifenslave
--- 2.10/ifenslave	1970-01-01 00:00:00.000000000 +0000
+++ 2.10ubuntu3/ifenslave	2016-09-27 22:47:49.000000000 +0000
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+#    Copyright (C) 2012-2013  Guus Sliepen <guus@debian.org>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    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, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+version() {
+	echo 'ifenslave.sh version 2 (2013-05-05)'
+	echo 'Copyright (c) 2012-2013 Guus Sliepen <guus@debian.org>'
+	exit 0
+}
+
+usage() {
+	echo 'Usage: ifenslave [-acdfhuvV] <master> <slave> ...'
+	exit 0
+}
+
+error() {
+	echo "$@" >&2
+	exit 1
+}
+
+all_interfaces() {
+	# I guess this was a debugging feature.
+	ip link show
+	exit 0
+}
+
+# Parse options
+
+while true; do
+	if [ "$1" = "-a" -o "$1" = "--all-interfaces" ]; then
+		all_interfaces
+	elif [ "$1" = "-c" -o "$1" = "--change-active" ]; then
+		CHANGE_ACTIVE=1; shift
+	elif [ "$1" = "-d" -o "$1" = "--detach" ]; then
+		DETACH=1; shift
+	elif [ "$1" = "-f" -o "$1" = "--force" ]; then
+		FORCE=1; shift
+	elif [ "$1" = "-h" -o "$1" = "--help" ]; then
+		exec man 8 ifenslave
+	elif [ "$1" = "-u" -o "$1" = "--usage" ]; then
+		usage
+	elif [ "$1" = "-v" -o "$1" = "--verbose" ]; then
+		VERBOSE=1; shift
+	elif [ "$1" = "-V" -o "$1" = "--version" ]; then
+		version
+	elif [ "$1" = "--" ]; then
+		shift
+		break
+	else
+		break
+	fi
+done
+
+# Check that we have enough arguments remaining.
+
+[ -z "$2" ] && error "Not enough arguments"
+
+master="$1"
+shift
+
+# Check that the master is really a bonding interface.
+
+[ -d "/sys/class/net/$master" ] || error "$master: no such interface"
+[ -d "/sys/class/net/$master/bonding" ] || error "$master: is not a bonding interface"
+
+# Do we need to change the active interface?
+
+if [ "$CHANGE_ACTIVE" = 1 ]; then
+	[ -z "$2" ] || error 'You can only set one interface to be the active slave!'
+	[ "$VERBOSE" = 1 ] && echo "Changing active slave of $master to $slave"
+	echo "$1" >"/sys/class/net/$master/bonding/active_slave" || error "$master: could not set $slave to active slave"
+	exit 0
+fi
+
+# Otherwise, loop over all slaves and either attach or detach them.
+
+for slave in "$@"; do
+	[ -d "/sys/class/net/$slave" ] || error "$slave: no such interface"
+
+	if [ -z "$DETACH" ]; then
+		if [ -h "/sys/class/net/$master/slave_$slave" ] ||
+		   [ -h "/sys/class/net/$master/lower_$slave" ]; then
+			echo "$slave: already enslaved to $master" >&2
+			continue
+		fi
+
+		read type <"/sys/class/net/$slave/type"
+		if [ -z "$FORCE" -a "$type" != "1" ]; then
+			error "$slave: does not appear to be an Ethernet interface (use -f to force)"
+		fi
+
+		[ "$VERBOSE" = 1 ] && echo "Adding slave $slave to master $master"
+		ip link set "$slave" down
+		echo "+$slave" >"/sys/class/net/$master/bonding/slaves" || error "$slave: could not add interface"
+	else
+		if [ ! -h "/sys/class/net/$master/slave_$slave" ] &&
+		   [ ! -h "/sys/class/net/$master/lower_$slave" ]; then
+			echo "$slave: is not enslaved to $master" >&2
+			continue
+		fi
+
+		[ "$VERBOSE" = 1 ] && echo "Detaching slave $slave from master $master"
+		echo "-$slave" >"/sys/class/net/$master/bonding/slaves" || error "$slave: could not detach interface"
+	fi
+done
+
+exit 0
