... | ... | ||
---|---|---|---|
31 | dev_addr is the same, swap the old active eth0's MAC (MAC0) with eth1. | 31 | dev_addr is the same, swap the old active eth0's MAC (MAC0) with eth1. |
32 | Swap new active eth1's permanent MAC (MAC1) to eth0. | 32 | Swap new active eth1's permanent MAC (MAC1) to eth0. |
33 | The MAC addresses are now correctly differentiated. | 33 | The MAC addresses are now correctly differentiated. |
34 | 34 | ||
35 | Fixes: 3915c1e8634a ("bonding: Add "follow" option to fail_over_mac") | 35 | Fixes: 3915c1e8634a ("bonding: Add "follow" option to fail_over_mac") |
36 | Reported-by: Liang Li <liali@redhat.com> | ||
37 | Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> | 36 | Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> |
38 | --- | 37 | --- |
38 | v2: use memcmp directly instead of adding a redundant helper (Jakub Kicinski) | ||
39 | --- | ||
39 | drivers/net/bonding/bond_main.c | 9 +++++++-- | 40 | drivers/net/bonding/bond_main.c | 9 +++++++-- |
40 | include/net/bonding.h | 8 ++++++++ | 41 | 1 file changed, 7 insertions(+), 2 deletions(-) |
41 | 2 files changed, 15 insertions(+), 2 deletions(-) | ||
42 | 42 | ||
43 | diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c | 43 | diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c |
44 | index XXXXXXX..XXXXXXX 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/drivers/net/bonding/bond_main.c | 45 | --- a/drivers/net/bonding/bond_main.c |
46 | +++ b/drivers/net/bonding/bond_main.c | 46 | +++ b/drivers/net/bonding/bond_main.c |
47 | @@ -XXX,XX +XXX,XX @@ static void bond_do_fail_over_mac(struct bonding *bond, | 47 | @@ -XXX,XX +XXX,XX @@ static void bond_do_fail_over_mac(struct bonding *bond, |
48 | old_active = bond_get_old_active(bond, new_active); | 48 | old_active = bond_get_old_active(bond, new_active); |
49 | 49 | ||
50 | if (old_active) { | 50 | if (old_active) { |
51 | - bond_hw_addr_copy(tmp_mac, new_active->dev->dev_addr, | 51 | - bond_hw_addr_copy(tmp_mac, new_active->dev->dev_addr, |
52 | - new_active->dev->addr_len); | 52 | - new_active->dev->addr_len); |
53 | + if (bond_hw_addr_equal(old_active->dev->dev_addr, new_active->dev->dev_addr, | 53 | + if (memcmp(old_active->dev->dev_addr, new_active->dev->dev_addr, |
54 | + new_active->dev->addr_len)) | 54 | + new_active->dev->addr_len) == 0) |
55 | + bond_hw_addr_copy(tmp_mac, new_active->perm_hwaddr, | 55 | + bond_hw_addr_copy(tmp_mac, new_active->perm_hwaddr, |
56 | + new_active->dev->addr_len); | 56 | + new_active->dev->addr_len); |
57 | + else | 57 | + else |
58 | + bond_hw_addr_copy(tmp_mac, new_active->dev->dev_addr, | 58 | + bond_hw_addr_copy(tmp_mac, new_active->dev->dev_addr, |
59 | + new_active->dev->addr_len); | 59 | + new_active->dev->addr_len); |
60 | bond_hw_addr_copy(ss.__data, | 60 | bond_hw_addr_copy(ss.__data, |
61 | old_active->dev->dev_addr, | 61 | old_active->dev->dev_addr, |
62 | old_active->dev->addr_len); | 62 | old_active->dev->addr_len); |
63 | diff --git a/include/net/bonding.h b/include/net/bonding.h | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/include/net/bonding.h | ||
66 | +++ b/include/net/bonding.h | ||
67 | @@ -XXX,XX +XXX,XX @@ static inline void bond_hw_addr_copy(u8 *dst, const u8 *src, unsigned int len) | ||
68 | memcpy(dst, src, len); | ||
69 | } | ||
70 | |||
71 | +static inline bool bond_hw_addr_equal(const u8 *dst, const u8 *src, unsigned int len) | ||
72 | +{ | ||
73 | + if (len == ETH_ALEN) | ||
74 | + return ether_addr_equal(dst, src); | ||
75 | + else | ||
76 | + return (memcmp(dst, src, len) == 0); | ||
77 | +} | ||
78 | + | ||
79 | #define BOND_PRI_RESELECT_ALWAYS 0 | ||
80 | #define BOND_PRI_RESELECT_BETTER 1 | ||
81 | #define BOND_PRI_RESELECT_FAILURE 2 | ||
82 | -- | 63 | -- |
83 | 2.46.0 | 64 | 2.46.0 |
84 | 65 | diff view generated by jsdifflib |