tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Network bonding problem (eth0 + wlan0)

Tue Nov 22, 2016 4:35 pm

Hello,


I'm quite new to Raspberry Pi and Linux in general (playing with it for 2 months now).

I have a RPi 3 with Openmediavault 3 installed to use it as a NAS + Plex server (globally it works well).

I'm trying to create a network bonding named 'bond1' with the 'eth0' + 'wlan0' interfaces (mode active-backup), but it's not working. The goal is to set ethernet as primary and wifi in case of ethernet failure.

For now only wlan0 is up on startup, here is 'dmesg | grep eth0' :

Code: Select all

[email protected]:~# dmesg | grep eth0
[    2.683346] smsc95xx 1-1.1:1.0 eth0: register 'smsc95xx' at usb-3f980000.usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:fd:d1:cc
[    5.141959] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[    6.794529] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC5E1
[    7.550260] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[    7.563773] bond1: Adding slave eth0
[    7.632090] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[    7.637715] bond1: Enslaving eth0 as a backup interface with an up link
[    7.656650] bond1: Setting eth0 as primary slave
[    7.679615] bond1: link status definitely up for interface eth0, 10 Mbps half duplex
[    7.685983] bond1: making interface eth0 the new active one
[    7.874701] smsc95xx 1-1.1:1.0 eth0: link down
[    7.989640] bond1: link status down for active interface eth0, disabling it in 150 ms
[    8.569633] bond1: link status definitely down for interface eth0, disabling it
[    8.578465] bond1: Setting eth0 as primary slave
[   10.599685] bond1: Setting eth0 as primary slave
[   55.146556] bond1: Setting eth0 as primary slave
/proc/net/bonding/bond1 :

Code: Select all

[email protected]:~# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: wlan0
MII Status: up
MII Polling Interval (ms): 150
Up Delay (ms): 150
Down Delay (ms): 150

Slave Interface: eth0
MII Status: down
Speed: 100 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: b8:27:eb:fd:d1:cc
Slave queue ID: 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: b8:27:eb:a8:84:99
Slave queue ID: 0

Here is my actual /etc/network/interfaces :

Code: Select all

# The loopback network interface
auto lo
iface lo inet loopback

# eth0 network interface
auto eth0
#allow-hotplug eth0
iface eth0 inet manual
    link-speed 100
    link-duplex full
    ethernet-autoneg off
    bond-master bond1
    bond-primary eth0
    bond-mode active-backup
    bond-miimon 150
    bond-downdelay 200
    bond-updelay 200
iface eth0 inet6 manual
    pre-down ip -6 addr flush dev $IFACE

# wlan0 network interface
auto wlan0
#allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    bond-master bond1
    bond-primary eth0
    bond-mode active-backup
    bond-miimon 150
    bond-downdelay 200
    bond-updelay 200
iface wlan0 inet6 manual
    pre-down ip -6 addr flush dev $IFACE

# bond1 network interface
auto bond1
iface bond1 inet static
    address 192.168.0.20
    netmask 255.255.255.0
    gateway 192.168.0.1
    dns-search google.com
    dns-nameservers 192.168.0.1 8.8.8.8
    bond-slaves none
    bond-primary eth0
    bond-mode active-backup
    bond-miimon 150
    bond-downdelay 200
    bond-updelay 200
iface bond1 inet6 manual
    pre-down ip -6 addr flush dev $IFACE
I already tried to move the 'bond1' part in /etc/network/interfaces at the beginning and set 'bond-slaves eth0 wlan0' but then only eth0 was up, wlan0 was shown at all with 'ifconfig'..

I'm looking your assistance. Thanks a lot for any help. I can try many things.


Best regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Wed Nov 23, 2016 11:58 am

I remember trying things with wifi bonding, and it being tricky because of MAC issues. Your message piqued my interest, I've fired up a Pi 2 with an Edimax dongle and see if I can get a working active-backup bond.

In the meantime, my question is do you really require bonding? AFAIK in Raspbian Jessie both ether and wifi interfaces can be up at the same time but route priorities are used to select ethernet when it is up. A wifi link isn't that reliable in itself...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Wed Nov 23, 2016 12:52 pm

Hi epoch1970,

Thanks for your answer.
I'm not really sure i need bonding, i just want not to be disconnected if the ethernet cable is unplugged by mistake for example.

Thanks again.
Regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Wed Nov 23, 2016 8:50 pm

This post is obsolete. See below https://www.raspberrypi.org/forums/view ... 4#p1420729

If your OS is based on Raspbian Jessie and you have dhcpcd5 installed -that's installed by default- then you can do without bonding AFAIK. You have to live with 2 IPs and 2 hostnames but at least it is simple.

Right now on my desk I have bonding working, and it was some struggle.
  • First off I had to remove dhcpcd which was messing with the interfaces. I'll try to deny the interfaces rather than remove the package later.
  • Second I had trouble with MAC address assignment. Normally a bond would give its MAC address to all slaves, but for some reason eth0 doesn't want to be spoofed. So the bond takes the MAC address of eth0, but wlan0 authenticates with its AP using its own MAC address. So when wlan0 becomes the active, nothing goes through due to the wrong MAC on bond0.
    All right, it is possible to fix that with an option that makes bond0 change its own MAC to follow the active. Sadly that option works only when bond0 starts without slaves.
  • Third, how do you get a DHCP lease for bond0 when that interface starts without any slaves? Well, it looks like I've found a way around this too...
According to my tests, I have now a system that can start without any slaves, enslave any interface that appears over time, and grab an address via DHCP.

I need to test a bit more to be sure, try to reduce the amount of directives in the interfaces file and try to make it all work in the blessed presence of dhcpcd. After that I'll post example files.

In the meantime, one neat trick I just learnt with dnsmasq (a package I've been using for a decade...)

Code: Select all

# Pi2 server
# Ether + Edimax wifi interface, possibly in a trunk w/ its MAC dancing
dhcp-host=b8:27:eb:01:02:03,74:da:38:0a:0b:0c,joinville,192.168.1.200,12h
This dhcp-host stanza links 2 MACs to 1 IP and hostname. (Use instead 1 stanza for each MAC and dnsmasq fails complaining about an IP conflict in its config files.)
Last edited by epoch1970 on Sun Jan 27, 2019 10:21 pm, edited 1 time in total.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Thu Nov 24, 2016 11:04 am

Thanks a lot for your assistance :-)

In fact i would like to have only 1 IP address for both eth0 & wlan0 because this IP address is used after in my router.

At the moment the bond1 always uses the MAC address of eth0 (but it's always wlan0 that is up and eth0 down, as you saw in my 1st post from my /proc/net/bonding/bond1).

I will read with attention your last message.

Regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Thu Nov 24, 2016 7:02 pm

tealc59 wrote:In fact i would like to have only 1 IP address for both eth0 & wlan0 because this IP address is used after in my router.
Then, if you're using a DHCP address, you can look in your router (or DHCP server) how it copes with provisioning the same hostname and IP address for 2 different MAC addresses.
My solution looks like it's working, it's getting cleaner, but each interface keeps its own MAC, so if you want a single IP and use DHCP, you need to provision the IP twice...
With a static address assignment in the Pi for bond0 it is much simpler, but since I rely almost exclusively on DHCP, I target this use-case.
I'll post this w-e I think. Won't be tested on Pi 3 at first.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Fri Nov 25, 2016 8:58 am

Hello,

Yes, i would like to keep the possibility to use a static IP address for the bond interface (with rules in my router for this static IP address).

What i don't really understand is my /etc/network/interfaces file seems to work for people when searching on the internet, but not for me.

In any case, thank you for your time.


Best regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Sat Nov 26, 2016 1:19 pm

This post is obsolete. See below https://www.raspberrypi.org/forums/view ... 4#p1420729

This is my recipe to trunk/bond one ethernet (eth0) and one wifi client (wlan0) interfaces over a single link (bond0) on Raspbian Jessie Lite.
The bonded interface has a static IP configuration. I wanted DHCP but I can't get it to work reliably yet, network configuration is too racy. So static IP it is.

What follows was tested on a Pi 2 with an extra Edimax nano adapter, and on a Pi 3 with the internal Broadcom interface.
The test to pass was: boot with either 0, 1 or 2 links available and see if we get a ping, then login to the machine and see if it reaches the Internet. While connected disconnect/reconnect/remove/add interfaces and see if the bond shuffles slaves correctly.
(and before someone asks, yes I am posting this because the test passed on Pi 2 and Pi 3...)

First you need a current copy of Raspbian Lite and to install the ifenslave package. Your system should look like that in the end:
Note: Don't copy lines that start with "[email protected]:~#". It is the command used to show the interesting bits.

Code: Select all

[email protected]:~# uname -a
Linux joinville 4.4.32-v7+ #924 SMP Tue Nov 15 18:11:28 GMT 2016 armv7l GNU/Linux

[email protected]:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie

[email protected]:~# dpkg -l | grep bond
ii  ifenslave                             2.6                            all          configure network interfaces for parallel routing (bonding)
Of course make sure your wifi interface actually works in client mode. I don't post my wpa_supplicant.conf file here but you need a working one.

Now we need to block dhcpcd nosing into our stuff. It tried to play nice with it but when it didn't break routing it wiped out resolv.conf. So I completely neuter it for our interfaces by adding a denyinterfaces option in dhcpcd.conf:

Code: Select all

[email protected]:~# tail -5 /etc/dhcpcd.conf 
nohook lookup-hostname

# Dhcpcd breaks bonding
denyinterfaces eth0 wlan0 bond0
Next, interfaces definitions. This is a complete, stock Raspbian file with additions. There are redundant stanzas in the bonding configuration, it seems they are needed otherwise bond0 might not end up with the configuration you want.
You can use options in the bonding kernel module (create /etc/modprobe.d/bonding.conf) rather than runtime configuration through "bond-" stanzas. That's more stable, but all your bonds will default to these options.
Bonding documentation is there: https://www.kernel.org/doc/Documentatio ... onding.txt

Code: Select all

[email protected]:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

# bond0 denied in dhcpcd.conf
# bond0 ignored by ifplugd
auto bond0
iface bond0 inet static
address 192.168.100.20
netmask 255.255.255.0
network 192.168.100.0
broadcast 192.168.100.255
gateway 192.168.100.254
# Setup resolv.conf
dns-domain mydomain
dns-search mydomain other.domain
dns-nameservers 192.168.100.254
bond-mode active-backup
# bond0 MAC changes to the active (for wifi)
bond-fail_over_mac active
# Required by fail_over_mac active
bond-slaves none
# Prefer ethernet. primary_reselect better no worky?
bond-primary eth0
bond-primary_reselect always
bond-miimon 250
# ifplugd/ifupdown/dhclient race w/ bond config
# 0 internal delay is better
bond-downdelay 0
bond-updelay 0

# eth0 denied in dhcpcd.conf
auto eth0
iface eth0 inet manual
bond-master bond0
bond-mode active-backup
# This is the primary slave
bond-primary eth0

# wlan0 denied in dhcpcd.conf
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
bond-master bond0
bond-mode active-backup
# Don't pretend to be primary slave
bond-primary eth0

#allow-hotplug wlan0
#iface wlan0 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
A few notable elements in bond configuration:
  1. We want active-backup, i.e. the Pi will respond to a ping to 192.168.100.20 on bond0 as long as either eth0 or wlan0 are connected and up. Option "mode active-backup" is used to override the default mode, which is round-robin.
  2. One of the interfaces is a wifi client. Wifi clients authenticate with an access point, and the MAC address that connects to the AP is used in the authentication process. APs reject traffic from unauthenticated MACs, so this means the wifi interface must use the same MAC at all times.
  3. Upon creation, a bonding interface receives an auto-generated MAC address. By default it tries to change the MAC of all its slave interfaces (e.i. eth0, wlan0) to its own. For some reason this doesn't work with the interfaces I've used. When this fails the behavior of a bonding interface is to change its own MAC address to the MAC of the first enslaved interface, and stick to it. That's no good because we don't know if wlan0 will be the 1st interface up --in fact with an external USB dongle on Pi 2 it is likely this will not be the case.
    So we're using option "fail_over_mac active", which makes bond0 change its own MAC to follow the MAC of the slave that is active at that moment. With that, wlan0 will be able to communicate with the AP it has authenticated with when active.
  4. The bonding module requires that the bonding interface stands alone with no slaves for "fail_over_mac active" to be set. As a consequence, we must use "slaves none" in the definition of bond0 (instead of "slaves eth0 wlan0"), and add "bond-" stanzas in the definitions of interfaces eth0 and wlan0 in order to make them enslave under bond0 when they start.
  5. Since we have to use "fail_over_mac active", it means the MAC address linked to 192.168.100.20 will change when the active link changes. Normally that shouldn't be too much of a problem, but don't be surprised if SSH complains, for example.
    If you intend to use a MAC-based fixed DHCP lease for the bonding interface, you have to associate the same IP to 2 (in our case) MAC addresses in the DHCP's server configuration. I wasn't able to get reliable operation with bond0 as a DHCP client, so the point is somewhat moot.
Once you've modified your config files you can reboot and test for yourself. Hopefully you will be able to connect to the machine and should see something like this:

Code: Select all

[email protected]:~# lsmod | grep bond
bonding               104844  0 

[email protected]:~# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: wlan0
MII Status: up
MII Polling Interval (ms): 250
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: b8:27:eb:01:02:03
Slave queue ID: 0

Slave Interface: eth0
MII Status: down
Speed: 10 Mbps
Duplex: half
Link Failure Count: 1
Permanent HW addr: b8:27:eb:0a:0b:0c
Slave queue ID: 0
I will be glad to read from others on how to make a bonding interface (eth0+wlan0) work reliably in DHCP mode, or on improvements to this recipe.

HTH
Last edited by epoch1970 on Sun Jan 27, 2019 10:22 pm, edited 1 time in total.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Sun Nov 27, 2016 6:30 pm

This post is obsolete. See below https://www.raspberrypi.org/forums/view ... 4#p1420729

I finally hacked my way out of the clusterflurry of events and daemons Raspbian Jessie Lite launches when doing bonding (eth0+wlan0) in DHCP mode, and can report success.

Here is the recipe:
  • disable dhcpcd on all slaves and the bonding interfaces ("denyinterfaces eth0 wlan0 bond0", see my post above)
  • bonding module options, to enforce options like "fail_over_mac active" before the interface has any slave. This is needed because the order of interface declarations in /etc/network/interfaces is significant.
  • ifplugd, in its standard configuration (which is rendered more or less useless by systemd.)
  • Our own service that starts another instance of ifplugd (when the stock ones have finished failing at boot) to monitor bond0
  • A small ifplugd "action" file that activates when bond0 status changes from down to up, and refreshes the DHCP lease if necessary.
  • A special configuration of the DHCP server to hand out the same IP when the request comes from either eth0 or wlan0 MACs.

With that, I can report connectivity success on Pi 2 (eth0+Edimax USB wifi thinggy) and Pi 3 (built-in eth0 and wlan0). I'm posting here the files and a bit of syslog to show how it goes dynamically.

I ended up setting "active-backup", "primary-reselect always" and "fail-over-mac active" as module options. This is a simple way of making sure bond0 gets properly configured even with /etc/network/interfaces as it stands now.

Code: Select all

[email protected]:~# cat /etc/modprobe.d/bonding.conf 
options bonding max_bonds=1 mode=1 primary_reselect=0 fail_over_mac=1 miimon=250
/etc/network/interfaces is a bit tricky. Normally ifplugd (installed by default on Raspbian Lite) should monitor at boot all "auto" and "allow-hotplug" interfaces for link up/down events (eg. cable connected.) But not really. Systemd doesn't start it if the machine boots with cable disconnected (!), and never starts an instance targeted at bond0. So we need our own service to monitor bond0.
Also, if bond0 appears first in this file, then at boot dhclient will be launched before bond0 has flipped its MAC to the one of an active slave. The DHCP server sees a MAC it doesn't know, and bond0 doesn't acquire the offered address because it has changed its MAC since dhclient was launched... To solve this, the definition of bond0 is pushed after those of the slaves, and now dhclient queries the DHCP server with one of the "true" MACs. In turn this calls for setting the necessary "early" options elsewhere, and I chose /etc/modprobe.d/bonding.conf.

Code: Select all

[email protected]:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

# eth0 denied in dhcpcd.conf
# ifplugd fails to start if disconnected @ boot
# time... We don't really need it anyway.
auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0

# wlan0 denied in dhcpcd.conf
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
bond-master bond0
bond-primary eth0

# bond0 denied in dhcpcd.conf
# ifplugd should take care of it but doesn't. We run our own
# service: /etc/systemd/system/bond-dhcp.service
# To make sure the 1st DHCP lease is acquired w/ the MAC
# of an active slave this interface must be declared last.
# Key options are set beforehand in /etc/modprobe.d/bonding.conf
auto bond0
iface bond0 inet dhcp
bond-primary eth0

#allow-hotplug wlan0
#iface wlan0 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
This systemd service is hacked from the standard sshd service unit. From the console I think I see the service is being started two times at boot, but I couldn't care less as long as the daemon is effectively running at the end of the boot process. There is room for improvement here, no doubt:

Code: Select all

[email protected]:~# cat /etc/systemd/system/bond-dhcp.service 
[Unit]
Description=Custom DHCP lease manager for bonding device
After=network.target
ConditionPathExists=/usr/sbin/ifplugd

[Service]
ExecStart=/usr/sbin/ifplugd -f -u0 -d0 -w -I -q -p -m ethtool -r /usr/local/bin/bond-dhcp-action.sh -i bond0
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
This is the ifplugd action I use. It's written in bourne shell, not my forte -if any- so feel free to improve upon it.
Ifplugd calls it whenever bond0 link status goes down or up. The script does nothing when the interface goes down. When it goes up, it tries to see if bond0 already has a valid DHCP lease: it goes through the list of addresses found on bond0, keeps the first octet of each and matches that to 192, 172 or 10, i.e. LAN address classes (an imposture in the case of 192, but my shell skills are limited.) If a LAN address is found, the script does nothing. If no LAN address is available, the script re-launches dhclient to try and get an address.
(Refreshing the lease without testing would be simpler, but the process is disruptive and could break streaming and established connections.)

Code: Select all

[email protected]:~# cat /usr/local/bin/bond-dhcp-action.sh 
#!/bin/sh
IF=$1
UPDOWN=$2
DEBUG=1
[ "$DEBUG" != 0 ] && echo "Status change on [$IF]: $IFPLUGD_PREVIOUS -> $IFPLUGD_CURRENT"
# Don't do anything if we go down
[ "$UPDOWN" != "up" ] && exit 0

IPS=$(/sbin/ip address show "$IF" 2>/dev/null | /bin/grep -Po '(?<=inet )\d{1,3}(?=\.)')
N=$(echo "$IPS" | wc -l)
IPLIST=$(echo "$IPS" | xargs)
if [ "$DEBUG" != 0 ]; then 
[ -z "$IPS" ] && MSG="No IP found on [$IF]" || MSG="[$N] IP found on [$IF], starting with: [$IPLIST]"
echo "$MSG"
fi

# Renew lease on anything but private ipv4 address classes
MATCH=0
for CLASS in 192 172 10; do
[ "${IPLIST#*$CLASS}" != "$IPLIST" ] && MATCH=1
done

if [ "$MATCH" = 0 ]; then
PIDFILE="/run/dhclient.$IF.pid"
LEASEFILE="/var/lib/dhcp/dhclient.$IF.leases"
[ "$DEBUG" != 0 ] && echo "Renewing DHCP lease on device [$IF] [$PIDFILE] [$LEASEFILE]"
/sbin/dhclient -r -v -pf "$PIDFILE" -lf "$LEASEFILE" "$IF" >/dev/null 2>&1 || exit 1
/sbin/dhclient -v -pf "$PIDFILE" -lf "$LEASEFILE" "$IF" >/dev/null 2>&1 || exit 1
else
[ "$DEBUG" != 0 ] && echo "Valid lease found, nothing to do"
fi

exit 0
For the DHCP server provisioning bit, you're on your own unless you like dnsmasq as much as I do. Here is the form dnsmasq expects to associate multiple MAC addresses to a single IP and hostname, here with 4 (redacted) MACs needed to test on my 2 Pis (and a ridiculously short lease time for testing):

Code: Select all

[email protected]:~$ grep joinville /etc/dnsmasq.d/dhcp_leases.conf
dhcp-host=b8:27:eb:01:02:03,b8:27:eb:f1:f2:f3,b8:27:eb:0a:0b:0c,74:da:38:fa:fb:fc,joinville,192.168.100.200,5m
And now in motion. This is what happens when a slave interface is added after the bonding interface was down for a good while (no DHCP lease):

Code: Select all

Nov 27 15:05:51 joinville kernel: [  851.955917] bond0: Setting eth0 as primary slave
Nov 27 15:05:51 joinville systemd[1]: Reloading OpenBSD Secure Shell server.
Nov 27 15:05:51 joinville ifplugd(bond0)[620]: Link beat detected.
Nov 27 15:05:51 joinville systemd[1]: Reloaded OpenBSD Secure Shell server.
Nov 27 15:05:51 joinville ifplugd(bond0)[620]: Executing '/usr/local/bin/bond-dhcp-action.sh bond0 up'.
Nov 27 15:05:51 joinville ifplugd(bond0)[620]: client: Status change on [bond0]: down -> up
Nov 27 15:05:51 joinville ifplugd(bond0)[620]: client: No IP found on [bond0]
Nov 27 15:05:51 joinville ifplugd(bond0)[620]: client: Renewing DHCP lease on device [bond0] [/run/dhclient.bond0.pid] [/var/lib/dhcp/dhclient.bond0.leases]
Nov 27 15:05:51 joinville dhclient: Internet Systems Consortium DHCP Client 4.3.1
Nov 27 15:05:51 joinville dhclient: Copyright 2004-2014 Internet Systems Consortium.
...
Nov 27 15:06:00 joinville ntpd[2491]: peers refreshed
Nov 27 15:06:00 joinville ntpd[2491]: Listening on routing socket on fd #22 for interface updates
Nov 27 15:06:00 joinville dhclient: bound to 192.168.100.200 -- renewal in 128 seconds.
Nov 27 15:06:00 joinville ifplugd(bond0)[620]: Program executed successfully.
And this in case of short connection breakup (with DHCP lease):

Code: Select all

Nov 27 15:21:47 joinville kernel: [ 1808.455102] smsc95xx 1-1.1:1.0 eth0: link down
Nov 27 15:21:47 joinville kernel: [ 1808.478495] bond0: link status definitely down for interface eth0, disabling it
Nov 27 15:21:47 joinville kernel: [ 1808.478648] bond0: now running without any active interface!
Nov 27 15:21:47 joinville ifplugd(eth0)[665]: Link beat lost.
Nov 27 15:21:48 joinville ifplugd(bond0)[620]: Link beat lost.
Nov 27 15:21:48 joinville ifplugd(bond0)[620]: Executing '/usr/local/bin/bond-dhcp-action.sh bond0 down'.
Nov 27 15:21:48 joinville ifplugd(bond0)[620]: client: Status change on [bond0]: up -> down
Nov 27 15:21:48 joinville ifplugd(bond0)[620]: Program executed successfully.
Nov 27 15:21:50 joinville kernel: [ 1810.839745] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC1E1
Nov 27 15:21:50 joinville kernel: [ 1810.978430] bond0: link status definitely up for interface eth0, 100 Mbps full duplex
Nov 27 15:21:50 joinville kernel: [ 1810.978461] bond0: making interface eth0 the new active one
Nov 27 15:21:50 joinville kernel: [ 1810.979107] bond0: first active interface up!
Nov 27 15:21:50 joinville ifplugd(bond0)[620]: Link beat detected.
Nov 27 15:21:50 joinville ifplugd(bond0)[620]: Executing '/usr/local/bin/bond-dhcp-action.sh bond0 up'.
Nov 27 15:21:50 joinville ifplugd(bond0)[620]: client: Status change on [bond0]: down -> up
Nov 27 15:21:50 joinville ifplugd(bond0)[620]: client: [1] IP found on [bond0], starting with: [192]
Nov 27 15:21:50 joinville ifplugd(bond0)[620]: client: Valid lease found, nothing to do
Nov 27 15:21:50 joinville ifplugd(eth0)[665]: Link beat detected.
Nov 27 15:21:50 joinville ifplugd(bond0)[620]: Program executed successfully.
HTH
Last edited by epoch1970 on Sun Jan 27, 2019 10:23 pm, edited 1 time in total.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Mon Nov 28, 2016 1:41 pm

Hello,


Thanks a lot.

I modified my /etc/network/interfaces :

Code: Select all

# The loopback network interface
auto lo
iface lo inet loopback

# bond1 network interface
auto bond1
iface bond1 inet static
    address 192.168.0.20
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1
    dns-search google.com
    dns-nameservers 192.168.0.1 8.8.8.8
    bond-mode active-backup
    bond-fail_over_mac active   #bond0 MAC changes to the active (for wifi)
    bond-slaves none             #Required by fail_over_mac active
    bond-primary eth0
    bond-primary_reselect always
    bond-miimon 250
    bond-downdelay 0            #ifplugd/ifupdown/dhclient race with bond config, 0 internal delay is better
    bond-updelay 0
#iface bond1 inet6 manual
#    pre-down ip -6 addr flush dev $IFACE

# eth0 network interface
auto eth0
allow-hotplug eth0
iface eth0 inet manual
    link-speed 100
#    link-duplex full
#    ethernet-autoneg off
    bond-master bond1
    bond-mode active-backup
    bond-primary eth0
#iface eth0 inet6 manual
#    pre-down ip -6 addr flush dev $IFACE

# wlan0 network interface
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    bond-master bond1
    bond-mode active-backup
    bond-primary eth0
#iface wlan0 inet6 manual
#    pre-down ip -6 addr flush dev $IFACE
At reboot, eth0 was chosen & correctly connected !
So I tried to start a ping on the RPi then unplugged the ethernet cable, but unfortunately the wlan didn't take the connection and i couldn't access the RPi anymore :-\
After a reboot (ethernet cable still unplugged), wlan still wasn't connected, and no access.
So i plugged the ethernet cable back + rebooted (ok with eth0 only).

Here is my actual /proc/net/bonding/bond1 :

Code: Select all

[email protected]:~# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 250
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: b8:27:eb:fd:d1:cc
Slave queue ID: 0

Slave Interface: wlan0
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: b8:27:eb:a8:84:99
Slave queue ID: 0
I had to set in /etc/network/interfaces for eth0 + wlan0 :
auto eth0/wlan0
allow-hotplug eth0/wlan0


For now, i still don't know why unplugging the eth0 cable does not switch to a working wlan0.
Separately each interface is correctly working.


Best regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Mon Nov 28, 2016 9:19 pm

Now that's interesting.
I took your interfaces file and used it instead of mine. 1st boot it looked like everything was ok so I altered network settings to fit my LAN.
Result, the bond works perfectly well, I tested streaming an Internet radio to an airplay speaker and disconnecting eth0 or wlan0. The program went on unaffected.
I booted with both interfaces plugged in and with both missing (this is on the Pi 2 with USB wlan), same result.

=> Have you disabled dhcpcd on the interfaces as in my post?
=> What is this Openmediavault O.S. already? Can you test with a stock, up-to-date, Raspbian Lite install?

BTW, in your previous post, this doesn't feel quite right:

Code: Select all

Slave Interface: wlan0
MII Status: down
It should be up, but in stasis until it becomes the active slave. You could try to "ip link set wlan0 up" and see if it works better then.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Tue Nov 29, 2016 9:17 am

Hello,

OpenMediaVault is based on Debian, it's a NAS OS distribution including one for Raspberry PI.
(http://www.openmediavault.org/)
You confirmed that my actual /etc/network/interfaces seems now correct.

- There is no "dhcpcd", i can only find /etc/dhcp or /sbin/dhclient.
- I can't test another Raspbian Lite install for now, because i only have 1 SD card and the RPi is used every days.
- "ip link set wlan0 up" does nothing. "ip link show wlan0" result is :

Code: Select all

3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond1 state DOWN mode DORMANT group default qlen 1000
    link/ether b8:27:eb:fd:d1:cc brd ff:ff:ff:ff:ff:ff
(please find below "ip link show eth0" if needed)

Code: Select all

2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:fd:d1:cc brd ff:ff:ff:ff:ff:ff

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Tue Nov 29, 2016 9:55 am

tealc59 wrote:- "ip link set wlan0 up" does nothing. "ip link show wlan0" result is :

Code: Select all

3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond1 state DOWN mode DORMANT group default qlen 1000
    link/ether b8:27:eb:fd:d1:cc brd ff:ff:ff:ff:ff:ff
(please find below "ip link show eth0" if needed)

Code: Select all

2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:fd:d1:cc brd ff:ff:ff:ff:ff:ff
Mhh. Both interfaces have the same MAC address now?
Perhaps later in the week (more probably w-e) I can take a Pi 3 out of service and see how it behaves exactly to compare better w/ your system. With its external USB wifi card the Pi 2 might behave a bit differently.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Tue Nov 29, 2016 11:40 am

Thank you very much for your help, it's very nice ! :-)

If nothing works i'll try to remove all the configuration (if i can), then recreate the bonding.

Regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Wed Nov 30, 2016 12:53 pm

2 things:
1) The interfaces files you posted works with Pi 3, same as with Pi 2, running Raspbian Lite current version.
2) I found by chance an SD with a stock Raspbian Lite install and a bonding config dating back July this year. I suppose I abandoned the project (and forgot about it...) because it wasn't working perfectly well, but the interfaces file looked much simpler, with bonding options only in the bond interface definition. It uses "fail-over-mac active" as well. It works but runs a bit rough, so I prefer not to post that config file.

If with Raspbian there is more than one way to do it, I suggest your issue is specific to the Openmediavault O.S.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Wed Nov 30, 2016 1:34 pm

Thanks for your reply.

Yesterday evening i deleted all the network configuration, no more bonding at all i wanted to try with only simple eth0 + wlan0 interfaces configured separately.

Keeping only eth0 + wlan0 interfaces, i had big troubles with Internet access in wlan (to have access to a hdmi + monitor i had to move the RPi so no ethernet cable anymore only wifi).
Symptoms of DNS problems & 'network unreachable' : i could ping google with 8.8.8.8 but not with 'google.com'.
I finally managed to have a working wlan0 with Internet but only with eth0 down.

Actual /etc/network/interfaces :

Code: Select all

# The loopback network interface
auto lo
iface lo inet loopback

# eth0 network interface
#auto eth0
#allow-hotplug eth0
#iface eth0 inet static
#    address 192.168.0.20
#    gateway 192.168.0.1
#    netmask 255.255.255.0
#    dns-search google.com
#    dns-nameservers 192.168.0.1 8.8.8.8
#iface eth0 inet6 manual
#    pre-down ip -6 addr flush dev $IFACE

# wlan0 network interface
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.0.20
    gateway 192.168.0.1
    netmask 255.255.255.0
    dns-search google.com
    dns-nameservers 192.168.0.1 8.8.8.8
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet6 manual
    pre-down ip -6 addr flush dev $IFACE
route -n :

Code: Select all

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
I'll make a SD Card backup this evening then try to have working interfaces with static IP 192.168.0.20.

It gives me noob headaches :-\

Regards,

tealc59
Posts: 9
Joined: Tue Nov 22, 2016 4:18 pm

Re: Network bonding problem (eth0 + wlan0)

Fri Dec 02, 2016 9:20 am

Hello,

some good news :-)

After completely removing bonding & network interfaces, PI reboots, i recreated this /etc/network/interfaces :

Code: Select all

# The loopback network interface
auto lo
iface lo inet loopback

# bond0 network interface
auto bond0
iface bond0 inet static
    address 192.168.0.20
    netmask 255.255.255.0
    network 192.168.0.0
    #broadcast 192.168.0.255
    gateway 192.168.0.1
    dns-search google.com
    dns-nameservers 192.168.0.1 8.8.8.8
    bond-mode active-backup
    bond-fail_over_mac active   #bond0 MAC changes to the active (for wifi)
    bond-slaves none            #Required by fail_over_mac active
    bond-primary eth0
    bond-primary_reselect always
    bond-miimon 250
    bond-downdelay 0            #ifplugd/ifupdown/dhclient race with bond config, 0 internal delay is better
    bond-updelay 0

# eth0 network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
    link-speed 100
    link-duplex full
    ethernet-autoneg off
    address 192.168.0.20
    gateway 192.168.0.1
    netmask 255.255.255.0
    dns-search google.com
    dns-nameservers 192.168.0.1 8.8.8.8
    bond-master bond0
    bond-mode active-backup
    bond-primary eth0
iface eth0 inet6 manual
    pre-down ip -6 addr flush dev $IFACE

# wlan0 network interface
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.0.20
    gateway 192.168.0.1
    netmask 255.255.255.0
    dns-search google.com
    dns-nameservers 192.168.0.1 8.8.8.8
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    bond-master bond0
    bond-mode active-backup
    bond-primary eth0
iface wlan0 inet6 manual
    pre-down ip -6 addr flush dev $IFACE
/proc/net/bonding/bond0 :

Code: Select all

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 250
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 10 Mbps
Duplex: half
Link Failure Count: 2
Permanent HW addr: b8:27:eb:fd:d1:cc
Slave queue ID: 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 3
Permanent HW addr: b8:27:eb:a8:84:99
Slave queue ID: 0
config working with eth0 or wlan0.

I didn't try to unplug the ethernet cable when on eth0 yet, but i'll check that major point very soon..

Regards,

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Fri Dec 02, 2016 4:05 pm

Looking good...
For me the acid test is booting with cable disconnected. If you get wifi connectivity in the end (boot is longer), then I'd say you're golden.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

marcelser
Posts: 5
Joined: Thu Jun 01, 2017 8:47 pm

Re: Network bonding problem (eth0 + wlan0)

Thu Jan 24, 2019 7:40 am

On my Pi Zero W I added a USB LAN adapter and had great success with setting failover_mac to 'none' and set a fixed hw-address for the bonding device in /etc/network/interfaces of one of my real interfaces (in my case eth0). Then bond0 will always talk to the router with its fixed mac address and get proper dhcp in return. This works perfectly in recent Raspbian Stretch Lite. I can also start with unplugged cable without a problem as bond0 will still talk the router with it's hw-address of eth0 even if eth0 is down when powering on. This also removes the need for ifplugd which is not preinstalled on recent stretch-lite anyway.

so my /etc/modprobe.d/bonding.conf looks like this

Code: Select all

options bonding fail_over_mac=none mode=active-backup primary=eth0 primary_reselect=always


and /etc/network/interfaces

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual
        bond-master     bond0
        bond-mode       active-backup

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
        bond-master     bond0
        bond-mode       active-backup

auto bond0
iface bond0 inet dhcp
    bond-slaves           none
    bond-primary          eth0
    bond-mode             active-backup
    bond-miimon           200
    bond-fail_over_mac    none
    bond-primary_reselect always
    bond-updelay          200
    bond-downdelay        0
    hw-address            8c:ae:4c:eb:94:90


ifconfig now shows that all interfaces now have the same mac which is the default behaviour if failover_mac set to none:

Code: Select all

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.10.72  netmask 255.255.255.0  broadcast 192.168.10.255
        ether 8c:ae:4c:eb:94:90  txqueuelen 1000  (Ethernet)
        RX packets 1077  bytes 115865 (113.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 337  bytes 49835 (48.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 8c:ae:4c:eb:94:90  txqueuelen 1000  (Ethernet)
        RX packets 63  bytes 6081 (5.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29  bytes 3938 (3.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1  bytes 29 (29.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1  bytes 29 (29.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 8c:ae:4c:eb:94:90  txqueuelen 1000  (Ethernet)
        RX packets 1014  bytes 109784 (107.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 308  bytes 45897 (44.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


and also /proc/net/bonding/bond0 it's working fine:

Code: Select all

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 200
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 8c:ae:4c:eb:94:90
Slave queue ID: 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: b8:27:eb:79:39:6b
Slave queue ID: 0


You can even see that on eth0 the Link Failoure Count is set to 1. That's because I booted the pi with cable unplugged.

What I also did was disabling eth0 and wlan0 in /etc/dhcpcd.conf with "denyinterfaces eth0 wlan0" just to make sure that dhcpcd will not interfere when it is bringing up the devices.

Hope this helps some people in trying to easily bond eth0 and wlan0 with dhcp on bond interface with using raspbian-stretch-lite

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Sun Jan 27, 2019 10:19 pm

marcelser wrote:
Thu Jan 24, 2019 7:40 am
On my Pi Zero W I added a USB LAN adapter and had great success with setting failover_mac to 'none'
I see that too on a Pi 3B. Bonding just works, now. This is excellent news, thanks for the heads-up!
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

no3rpi
Posts: 13
Joined: Fri Mar 31, 2017 11:44 am

Re: Network bonding problem (eth0 + wlan0)

Sun Jan 27, 2019 10:36 pm

I was using a identical configuration ( except my bonding interface it have static IP ) for some time on my rpi3, and I seen in time a serious problem after wifi loss with wifi not auto reconnecting.
For some time I had this solved with using: wpa-roam ...
Now after I updated to:

Code: Select all

Linux rpi3 4.14.93-v7+ #1191 SMP Wed Jan 16 11:53:33 GMT 2019 armv7l GNU/Linux
it seem something changed and wpa-roam it not helping any more to have wifi auto reconnect back.
Anybody that use bonding can test on his rpi the behavior of wifi auto reconnecting ?
thx

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Mon Jan 28, 2019 3:01 pm

How would you generate "wifi loss"? By rebooting the AP? (I didn't try that.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

no3rpi
Posts: 13
Joined: Fri Mar 31, 2017 11:44 am

Re: Network bonding problem (eth0 + wlan0)

Mon Jan 28, 2019 4:17 pm

Yes Reboot AP.

epoch1970
Posts: 3781
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Network bonding problem (eth0 + wlan0)

Wed Jan 30, 2019 10:39 am

Well rebooting the AP, the bond still works fine for me.
I first tried w/ wlan0 as active and solo link: ping stops and then resumes.
Then with eth0 as the active link and wlan0 as the passive backup:

Code: Select all

...
[  883.225131] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC1E1
[  883.343295] bond0: link status up for interface eth0, enabling it in 400 ms
[  883.765016] bond0: link status definitely up for interface eth0, 100 Mbps full duplex
[  883.765027] bond0: making interface eth0 the new active one
64 bytes from 74.125.206.99: seq=89 ttl=44 time=6.557 ms
...
64 bytes from 74.125.206.99: seq=108 ttl=44 time=7.174 ms
[  903.712997] bond0: link status definitely down for interface wlan0, disabling it <- AP power loss
64 bytes from 74.125.206.99: seq=109 ttl=44 time=7.177 ms
...
64 bytes from 74.125.206.99: seq=153 ttl=44 time=7.155 ms
[  948.652852] bond0: link status up for interface wlan0, enabling it in 400 ms <- AP rebooted, wpa_supplicant reconnected
[  949.072841] bond0: link status definitely up for interface wlan0, 0 Mbps full duplex
64 bytes from 74.125.206.99: seq=154 ttl=44 time=7.042 ms
...
[  955.257114] smsc95xx 1-1.1:1.0 eth0: link down  <- just to make sure, disconnect eth0
[  955.372926] bond0: link status definitely down for interface eth0, disabling it
[  955.372937] bond0: making interface wlan0 the new active one
64 bytes from 74.125.206.99: seq=162 ttl=44 time=18.942 ms
64 bytes from 74.125.206.99: seq=163 ttl=44 time=65.584 ms
...
Interfaces status after the test:

Code: Select all

# ip -d link show bond0
10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond mode active-backup active_slave wlan0 miimon 200 updelay 400 downdelay 0 use_carrier 1 arp_interval 0 arp_validate none arp_all_targets any primary eth0 primary_reselect always fail_over_mac none xmit_hash_policy layer2 resend_igmp 1 num_grat_arp 1 all_slaves_active 0 min_links 0 lp_interval 1 packets_per_slave 1 lacp_rate slow ad_select stable tlb_dynamic_lb 1 addrgenmode eui64 numtxqueues 16 numrxqueues 16 gso_max_size 65536 gso_max_segs 65535 
# ip -d link show eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond_slave state BACKUP mii_status DOWN link_failure_count 2 perm_hwaddr b8:27:eb:XX:XX:XX queue_id 0 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
# ip -d link show wlan0
3: wlan0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DORMANT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond_slave state ACTIVE mii_status UP link_failure_count 2 perm_hwaddr b8:27:eb:YY:YY:YY queue_id 0 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: wlan0
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 400
Down Delay (ms): 0

Slave Interface: eth0
MII Status: down
Speed: 10 Mbps
Duplex: half
Link Failure Count: 2
Permanent HW addr: b8:27:eb:XX:XX:XX
Slave queue ID: 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 2
Permanent HW addr: b8:27:eb:YY:YY:YY
Slave queue ID: 0
Kernel version 4.14.79-v7 (as in the current Raspian release) recompiled for my OS (sysVinit, not systemd)
bond was compiled as a module this time, but I had success with it integrated to the kernel.
Completely standard wpa_supplicant config file. wpa_supplicant version 2.7, recompiled as well but nothing fancy wrt wifi features.

HTH
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

no3rpi
Posts: 13
Joined: Fri Mar 31, 2017 11:44 am

Re: Network bonding problem (eth0 + wlan0)

Wed Jan 30, 2019 6:16 pm

Thank you for your reply.
I start with all networks working/connected and just disconnect wifi ( I turn OFF AP to simulate power failure, RPI and LAN switch it is on UPS ).
Bonding looks it works ok, only wifi is not reconnecting back if AP is down more than few minutes...

Here are my details for rpi3:
stock kernel after current rpi-update:

Code: Select all

 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
#############################################################
This update bumps to rpi-4.14.y linux tree
...
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.14.94-v7+
 *** depmod 4.14.94+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to 699879be36d90225232de87e9ae589be7209b14c
 *** A reboot is needed to activate the new firmware

uname -a
Linux rpi3 4.14.94-v7+ #1193 SMP Tue Jan 22 15:34:30 GMT 2019 armv7l GNU/Linux
I use a slim wpa_config only with country code, SSID, ssid scan and password.

Code: Select all

wpa_supplicant -v
wpa_supplicant v2.3
wpa_cli -v
wpa_cli v2.3 ( cli it is present only if I use wpa_roam )
I made some tests:
- if wifi is connected if I use wpa_cli scan will display all network available with of course current connected wifi.
- if wifi is disconected ( AP is ON and working for other clients ) wpa_cli scan will not find any network at all... so here must be the problem.

Code: Select all

ip -d link show wlan0
4: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DORMANT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond_slave state BACKUP mii_status DOWN link_failure_count 2 perm_hwaddr b8:27:eb:YY:YY:YY queue_id 0 
restarting wpa_supplicant and wpa_cli does not solve the problem...
after reboot:

Code: Select all

cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 200
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 100 Mbps
Duplex: half
Link Failure Count: 0
Permanent HW addr: b8:27:eb:XX:XX:XX
Slave queue ID: 0

Slave Interface: wlan0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: b8:27:eb:YY:YY:YY
Slave queue ID: 0

Code: Select all

ip -d link show bond0

3: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond mode active-backup active_slave eth0 miimon 200 updelay 200 downdelay 0 use_carrier 1 arp_interval 0 arp_validate none arp_all_targets any primary eth0 primary_reselect always fail_over_mac none xmit_hash_policy layer2 resend_igmp 1 num_grat_arp 1 all_slaves_active 0 min_links 0 lp_interval 1 packets_per_slave 1 lacp_rate slow ad_select stable 
ip -d link show eth0
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond_slave state ACTIVE mii_status UP link_failure_count 0 perm_hwaddr b8:27:eb:XX:XX:XX queue_id 0 
ip -d link show wlan0
4: wlan0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DORMANT group default qlen 1000
    link/ether b8:27:eb:XX:XX:XX brd ff:ff:ff:ff:ff:ff promiscuity 0 
    bond_slave state BACKUP mii_status UP link_failure_count 1 perm_hwaddr b8:27:eb:YY:YY:YY queue_id 0 

Return to “Troubleshooting”