Skip to contentSkip to conversation

bonding: correct the MAC address for "follow" fail_over_mac policy

PATCH In review Ding Tianhong 3 participants 9 messages Jul 16, 2015 – Jul 21, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bonding: correct the MAC address for "follow" fail_over_mac policy

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/bonding/bond_main.c +20 -0
index 317a494..efdb6a4 100644
@@ -625,6 +625,23 @@ static void bond_set_dev_addr(struct net_device *bond_dev,
 	call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
 }
 
+static struct slave *bond_get_old_active(struct bonding *bond,
+					 struct slave *new_active)
+{
+	struct slave *slave;
+	struct list_head *iter;
+
+	bond_for_each_slave(bond, slave, iter) {
+		if (slave == new_active)
+			continue;
+
+		if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr))
+			return slave;
+	}
+
+	return NULL;
+}
+
 /* bond_do_fail_over_mac
  *
  * Perform special MAC address swapping for fail_over_mac settings
@@ -652,6 +669,9 @@ static void bond_do_fail_over_mac(struct bonding *bond,
 		if (!new_active)
 			return;
 
+		if (!old_active)
+			old_active = bond_get_old_active(bond, new_active);
+
 		if (old_active) {
 			ether_addr_copy(tmp_mac, new_active->dev->dev_addr);
 			ether_addr_copy(saddr.sa_data,
Signature · 1 line
1.8.0
#1 lore raw
Quoted 24 lines · Ding Tianhong

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 8 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

This doesn't seem to be true:
~# cat /sys/class/net/bond0/bonding/fail_over_mac
follow 2

root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth1 is the first and active slave and bond0 has taken its mac. Now trying your steps:
Step 3) (bringing down the active eth1)

root@debian:~# ip l set eth1 down
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The mac addresses of eth1 and eth2 are correctly swapped, so far so good.

Step 4) (bringing down the active eth2)

root@debian:~# ip l set eth2 down
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
26: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth2 has kept the mac address of the bond and they're both down now

Step 5) (bring eth1 up again and observe the macs)
~# ip l set eth1 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The macs are correctly swapped and there's no such bug.

Step 6(?) bring eth2 up
~# ip l set eth2 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*Still correct.

Also the mac address that gets set is dev_addr which is changed when the swapping is done, if you'd like to get the original mac address you should be using slave->perm_hwaddr.

Cheers,
Nik

#2 lore raw
Quoted 94 lines · Nikolay Aleksandrov
Quoted 24 lines · Ding Tianhong

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 8 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

This doesn't seem to be true:
~# cat /sys/class/net/bond0/bonding/fail_over_mac
follow 2

root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth1 is the first and active slave and bond0 has taken its mac. Now trying your steps:
Step 3) (bringing down the active eth1)

root@debian:~# ip l set eth1 down
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The mac addresses of eth1 and eth2 are correctly swapped, so far so good.

Step 4) (bringing down the active eth2)

root@debian:~# ip l set eth2 down
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
26: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth2 has kept the mac address of the bond and they're both down now

Step 5) (bring eth1 up again and observe the macs)
~# ip l set eth1 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The macs are correctly swapped and there's no such bug.

Step 6(?) bring eth2 up
~# ip l set eth2 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
Quoted 6 lines

*Still correct.

Also the mac address that gets set is dev_addr which is changed when the swapping is done, if you'd like to get the original mac address you should be using slave->perm_hwaddr.

Hi Nik:

Which kernel version do you use, I test this on kernel 3.19.8 and 4.2-rc2, this problem exist on both version, maybe I miss something?

Ding

Quoted 5 lines

Cheers,
Nik

.

#3 lore raw
Quoted 102 lines · Ding Tianhong
Quoted 94 lines · Nikolay Aleksandrov
Quoted 24 lines · Ding Tianhong

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 8 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

This doesn't seem to be true:
~# cat /sys/class/net/bond0/bonding/fail_over_mac
follow 2

root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth1 is the first and active slave and bond0 has taken its mac. Now trying your steps:
Step 3) (bringing down the active eth1)

root@debian:~# ip l set eth1 down
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The mac addresses of eth1 and eth2 are correctly swapped, so far so good.

Step 4) (bringing down the active eth2)

root@debian:~# ip l set eth2 down
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
26: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth2 has kept the mac address of the bond and they're both down now

Step 5) (bring eth1 up again and observe the macs)
~# ip l set eth1 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The macs are correctly swapped and there's no such bug.

Step 6(?) bring eth2 up
~# ip l set eth2 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
Quoted 6 lines

*Still correct.

Also the mac address that gets set is dev_addr which is changed when the swapping is done, if you'd like to get the original mac address you should be using slave->perm_hwaddr.

Quoted 8 lines

Hi Nik:

Which kernel version do you use, I test this on kernel 3.19.8 and 4.2-rc2, this problem exist on both version, maybe I miss something?

Ding

It's current net-next.
~# uname -a
Linux debian 4.2.0-rc2+ #8 SMP Wed Jul 15 21:22:14 CEST 2015 x86_64 GNU/Linux

Quoted 7 lines
Quoted 5 lines

Cheers,
Nik

.

#4 lore raw
Quoted 108 lines · Nikolay Aleksandrov
Quoted 107 lines · Ding Tianhong
Quoted 94 lines · Nikolay Aleksandrov
Quoted 24 lines · Ding Tianhong

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 8 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

This doesn't seem to be true:
~# cat /sys/class/net/bond0/bonding/fail_over_mac
follow 2

root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth1 is the first and active slave and bond0 has taken its mac. Now trying your steps:
Step 3) (bringing down the active eth1)

root@debian:~# ip l set eth1 down
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The mac addresses of eth1 and eth2 are correctly swapped, so far so good.

Step 4) (bringing down the active eth2)

root@debian:~# ip l set eth2 down
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
26: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth2 has kept the mac address of the bond and they're both down now

Step 5) (bring eth1 up again and observe the macs)
~# ip l set eth1 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The macs are correctly swapped and there's no such bug.

Step 6(?) bring eth2 up
~# ip l set eth2 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
Quoted 6 lines

*Still correct.

Also the mac address that gets set is dev_addr which is changed when the swapping is done, if you'd like to get the original mac address you should be using slave->perm_hwaddr.

Hi Nik:

Which kernel version do you use, I test this on kernel 3.19.8 and 4.2-rc2, this problem exist on both version, maybe I miss something?

Quoted 8 lines
Quoted 3 lines

Ding

It's current net-next.
~# uname -a
Linux debian 4.2.0-rc2+ #8 SMP Wed Jul 15 21:22:14 CEST 2015 x86_64 GNU/Linux

Ah this is my bad, my setup was polluted from previous tests and the bonding wasn't clean, you're right - this does reproduce.
Sorry about that

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

Cheers,
Nik

.

#5 lore raw
Quoted 113 lines · Nikolay Aleksandrov
Quoted 112 lines · Nikolay Aleksandrov
Quoted 110 lines · Ding Tianhong
Quoted 94 lines · Nikolay Aleksandrov
Quoted 24 lines · Ding Tianhong

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 8 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

This doesn't seem to be true:
~# cat /sys/class/net/bond0/bonding/fail_over_mac
follow 2

root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth1 is the first and active slave and bond0 has taken its mac. Now trying your steps:
Step 3) (bringing down the active eth1)

root@debian:~# ip l set eth1 down
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The mac addresses of eth1 and eth2 are correctly swapped, so far so good.

Step 4) (bringing down the active eth2)

root@debian:~# ip l set eth2 down
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
26: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth2 has kept the mac address of the bond and they're both down now

Step 5) (bring eth1 up again and observe the macs)
~# ip l set eth1 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The macs are correctly swapped and there's no such bug.

Step 6(?) bring eth2 up
~# ip l set eth2 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
Quoted 6 lines

*Still correct.

Also the mac address that gets set is dev_addr which is changed when the swapping is done, if you'd like to get the original mac address you should be using slave->perm_hwaddr.

Hi Nik:

Which kernel version do you use, I test this on kernel 3.19.8 and 4.2-rc2, this problem exist on both version, maybe I miss something?

Ding

Quoted 9 lines
Quoted 4 lines

It's current net-next.
~# uname -a
Linux debian 4.2.0-rc2+ #8 SMP Wed Jul 15 21:22:14 CEST 2015 x86_64 GNU/Linux

Ah this is my bad, my setup was polluted from previous tests and the bonding wasn't clean, you're right - this does reproduce.
Sorry about that

Just tried it and it fixes it for me so

#6 lore raw
In reply to Nikolay Aleksandrov
Quoted 113 lines · Nikolay Aleksandrov
Quoted 112 lines · Nikolay Aleksandrov
Quoted 110 lines · Ding Tianhong
Quoted 94 lines · Nikolay Aleksandrov
Quoted 24 lines · Ding Tianhong

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 8 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

---
 drivers/net/bonding/bond_main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

This doesn't seem to be true:
~# cat /sys/class/net/bond0/bonding/fail_over_mac
follow 2

root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth1 is the first and active slave and bond0 has taken its mac. Now trying your steps:
Step 3) (bringing down the active eth1)

root@debian:~# ip l set eth1 down
root@debian:~# ip l sh bond0
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth1
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
root@debian:~# ip l sh eth2
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The mac addresses of eth1 and eth2 are correctly swapped, so far so good.

Step 4) (bringing down the active eth2)

root@debian:~# ip l set eth2 down
3: eth1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
26: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*eth2 has kept the mac address of the bond and they're both down now

Step 5) (bring eth1 up again and observe the macs)
~# ip l set eth1 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff

*The macs are correctly swapped and there's no such bug.

Step 6(?) bring eth2 up
~# ip l set eth2 up
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000

    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:4f:a5:99 brd ff:ff:ff:ff:ff:ff
26: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 52:54:00:3f:47:69 brd ff:ff:ff:ff:ff:ff
Quoted 6 lines

*Still correct.

Also the mac address that gets set is dev_addr which is changed when the swapping is done, if you'd like to get the original mac address you should be using slave->perm_hwaddr.

Hi Nik:

Which kernel version do you use, I test this on kernel 3.19.8 and 4.2-rc2, this problem exist on both version, maybe I miss something?

Ding

Quoted 9 lines
Quoted 4 lines

It's current net-next.
~# uname -a
Linux debian 4.2.0-rc2+ #8 SMP Wed Jul 15 21:22:14 CEST 2015 x86_64 GNU/Linux

Ah this is my bad, my setup was polluted from previous tests and the bonding wasn't clean, you're right - this does reproduce.
Sorry about that

:)

Quoted 12 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

Cheers,
Nik

.

.

maintainer
#7 lore raw
In reply to Ding Tianhong

From: Ding Tianhong <[email protected]>
Date: Thu, 16 Jul 2015 16:30:02 +0800

Quoted 21 lines

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Quoted 7 lines

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

Applied and queued up for -stable, thanks.

#8 lore raw
Quoted 27 lines · David Miller

From: Ding Tianhong <[email protected]>
Date: Thu, 16 Jul 2015 16:30:02 +0800

Quoted 24 lines

The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy:

1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1.

2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2.

3) ifconfig eth0 down
eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2.

4) ifconfig eth1 down
there is no active slave, and eth1 still has MAC1, eth2 has MAC2.

5) ifconfig eth0 up
the eth0 became active slave again, the bond set eth0 to MAC1.

Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode.

Quoted 6 lines
Quoted 4 lines

This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave.

Applied and queued up for -stable, thanks.

Thanks David.

hi zefan:

Could you please apply this patch to 3.4 stable tree, I think it will fix the same problem for this version.

Ding

Quoted 7 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

.