Skip to contentSkip to conversation

bond: have random dev address by default instead of zeroes

PATCH Superseded Jiri Pirko 2 participants 5 messages Jan 29, 2013

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH v3 1/1 bond: have random dev address by default instead of zeroes

Makes more sense to have randomly generated address by default than to have all zeroes. It also allows user to for example put the bond into bridge without need to have any slaves in it.

Also note that this changes only behaviour of bonds with no slaves. Once the first slave device is enslaved, its address will be used (no change here).

Also, fix dev_assign_type values on the way.

---

v2->v3:
- call_netdevice_notifiers is called after dev_addr change.
- use bond->get_dev_addr_from_first_slave to know when to get addr from the first slave
v1->v2:
- fixed assign value of bond_dev->addr_assign_type in bond_set_dev_addr()
- added note to patch description

 drivers/net/bonding/bond_main.c | 38 +++++++++++++++++++-------------------
 drivers/net/bonding/bonding.h   |  1 +
 2 files changed, 20 insertions(+), 19 deletions(-)
drivers/net/bonding/bond_main.c +19 -19
index 564cf42..8692df8 100644
@@ -1320,14 +1320,15 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev,
-			  struct net_device *slave_dev)
+static void bond_set_dev_addr(struct net_device *bond_dev,
+			      struct net_device *slave_dev)
 {
 	pr_debug("bond_dev=%p\n", bond_dev);
 	pr_debug("slave_dev=%p\n", slave_dev);
 	pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
 	memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
-	return 0;
+	bond_dev->addr_assign_type = NET_ADDR_SET;
+	call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
 }
 
 static netdev_features_t bond_fix_features(struct net_device *dev,
@@ -1628,10 +1629,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	/* If this is the first slave, then we need to set the master's hardware
 	 * address to be the same as the slave's. */
-	if (is_zero_ether_addr(bond->dev->dev_addr))
-		memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
-		       slave_dev->addr_len);
-
+	if (bond->get_dev_addr_from_first_slave)
+		bond_set_dev_addr(bond->dev, slave_dev);
 
 	new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
 	if (!new_slave) {
@@ -2048,12 +2047,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	if (bond->slave_cnt == 0) {
 		bond_set_carrier(bond);
-
-		/* if the last slave was removed, zero the mac address
-		 * of the master so it will be set by the application
-		 * to the mac address of the first slave
-		 */
-		memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
 
 		if (bond_vlan_used(bond)) {
 			pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2234,11 +2229,8 @@ static int bond_release_all(struct net_device *bond_dev)
 		write_lock_bh(&bond->lock);
 	}
 
-	/* zero the mac address of the master so it will be
-	 * set by the application to the mac address of the
-	 * first slave
-	 */
-	memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+	eth_hw_addr_random(bond_dev);
+	bond->get_dev_addr_from_first_slave = true;
 
 	if (bond_vlan_used(bond)) {
 		pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -3708,7 +3700,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_SETHWADDR_OLD:
 		case SIOCBONDSETHWADDR:
-			res = bond_sethwaddr(bond_dev, slave_dev);
+			bond_set_dev_addr(bond_dev, slave_dev);
+			res = 0;
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
@@ -4858,6 +4851,13 @@ static int bond_init(struct net_device *bond_dev)
 
 	bond_debug_register(bond);
 
+	/* Ensure valid dev_addr */
+	if (is_zero_ether_addr(bond_dev->dev_addr) &&
+	    bond_dev->addr_assign_type == NET_ADDR_PERM) {
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
+	}
+
 	__hw_addr_init(&bond->mc_list);
 	return 0;
 }
drivers/net/bonding/bonding.h +1 -0
index 0d282d2..3200638 100644
@@ -248,6 +248,7 @@ struct bonding {
 	/* debugging support via debugfs */
 	struct	 dentry *debug_dir;
 #endif /* CONFIG_DEBUG_FS */
+	bool	get_dev_addr_from_first_slave;
 };
 
 static inline bool bond_vlan_used(struct bonding *bond)
Signature · 1 line
1.8.1
#1 lore raw
Quoted 10 lines · Jiri Pirko

Makes more sense to have randomly generated address by default than to have all zeroes. It also allows user to for example put the bond into bridge without need to have any slaves in it.

Also note that this changes only behaviour of bonds with no slaves. Once the first slave device is enslaved, its address will be used (no change here).

Also, fix dev_assign_type values on the way.

Quoted 8 lines

---

v2->v3:
- call_netdevice_notifiers is called after dev_addr change.
- use bond->get_dev_addr_from_first_slave to know when to get addr from the first slave

Was there a problem with using the dev_addr_type to determine
this? If it's really necessary, I think the name of this field is really verbose; even "addr_from_first" should be sufficient in my mind.

	-J

---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]

Quoted 112 lines

v1->v2:
- fixed assign value of bond_dev->addr_assign_type in bond_set_dev_addr()
- added note to patch description

drivers/net/bonding/bond_main.c | 38 +++++++++++++++++++-------------------
drivers/net/bonding/bonding.h | 1 +

2 files changed, 20 insertions(+), 19 deletions(-)
drivers/net/bonding/bond_main.c +19 -19
index 564cf42..8692df8 100644
@@ -1320,14 +1320,15 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev,
-			  struct net_device *slave_dev)
+static void bond_set_dev_addr(struct net_device *bond_dev,
+			      struct net_device *slave_dev)
 {
 	pr_debug("bond_dev=%p\n", bond_dev);
 	pr_debug("slave_dev=%p\n", slave_dev);
 	pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
 	memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
-	return 0;
+	bond_dev->addr_assign_type = NET_ADDR_SET;
+	call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
 }
 
 static netdev_features_t bond_fix_features(struct net_device *dev,
@@ -1628,10 +1629,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	/* If this is the first slave, then we need to set the master's hardware
 	 * address to be the same as the slave's. */
-	if (is_zero_ether_addr(bond->dev->dev_addr))
-		memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
-		       slave_dev->addr_len);
-
+	if (bond->get_dev_addr_from_first_slave)
+		bond_set_dev_addr(bond->dev, slave_dev);
 
 	new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
 	if (!new_slave) {
@@ -2048,12 +2047,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	if (bond->slave_cnt == 0) {
 		bond_set_carrier(bond);
-
-		/* if the last slave was removed, zero the mac address
-		 * of the master so it will be set by the application
-		 * to the mac address of the first slave
-		 */
-		memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
 
 		if (bond_vlan_used(bond)) {
 			pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2234,11 +2229,8 @@ static int bond_release_all(struct net_device *bond_dev)
 		write_lock_bh(&bond->lock);
 	}
 
-	/* zero the mac address of the master so it will be
-	 * set by the application to the mac address of the
-	 * first slave
-	 */
-	memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+	eth_hw_addr_random(bond_dev);
+	bond->get_dev_addr_from_first_slave = true;
 
 	if (bond_vlan_used(bond)) {
 		pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -3708,7 +3700,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_SETHWADDR_OLD:
 		case SIOCBONDSETHWADDR:
-			res = bond_sethwaddr(bond_dev, slave_dev);
+			bond_set_dev_addr(bond_dev, slave_dev);
+			res = 0;
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
@@ -4858,6 +4851,13 @@ static int bond_init(struct net_device *bond_dev)
 
 	bond_debug_register(bond);
 
+	/* Ensure valid dev_addr */
+	if (is_zero_ether_addr(bond_dev->dev_addr) &&
+	    bond_dev->addr_assign_type == NET_ADDR_PERM) {
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
+	}
+
 	__hw_addr_init(&bond->mc_list);
 	return 0;
 }
drivers/net/bonding/bonding.h +1 -0
index 0d282d2..3200638 100644
@@ -248,6 +248,7 @@ struct bonding {
 	/* debugging support via debugfs */
 	struct	 dentry *debug_dir;
 #endif /* CONFIG_DEBUG_FS */
+	bool	get_dev_addr_from_first_slave;
 };
 
 static inline bool bond_vlan_used(struct bonding *bond)
Signature · 1 line
1.8.1
author
#2 lore raw
Quoted 16 lines · Tue, Jan 29, 2013 at 07:32:36PM CET, [email protected] wrote:
Quoted 14 lines · Jiri Pirko

Makes more sense to have randomly generated address by default than to have all zeroes. It also allows user to for example put the bond into bridge without need to have any slaves in it.

Also note that this changes only behaviour of bonds with no slaves. Once the first slave device is enslaved, its address will be used (no change here).

Also, fix dev_assign_type values on the way.

---

Quoted 8 lines
Quoted 4 lines

v2->v3:
- call_netdevice_notifiers is called after dev_addr change.
- use bond->get_dev_addr_from_first_slave to know when to get addr from the first slave

Was there a problem with using the dev_addr_type to determine
this? If it's really necessary, I think the name of this field is really verbose; even "addr_from_first" should be sufficient in my mind.

It is necessary. Bridge call dev_set_mac_address() which sets dev->addr_assign_type = NET_ADDR_SET and that causes unwanted behaviour.

And as for the verbosity thing, I like more verbose better in situations like this. Zero room for confusion.

Quoted 124 lines
	-J

---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]

Quoted 112 lines

v1->v2:
- fixed assign value of bond_dev->addr_assign_type in bond_set_dev_addr()
- added note to patch description

drivers/net/bonding/bond_main.c | 38 +++++++++++++++++++-------------------
drivers/net/bonding/bonding.h | 1 +

2 files changed, 20 insertions(+), 19 deletions(-)
drivers/net/bonding/bond_main.c +19 -19
index 564cf42..8692df8 100644
@@ -1320,14 +1320,15 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev,
-			  struct net_device *slave_dev)
+static void bond_set_dev_addr(struct net_device *bond_dev,
+			      struct net_device *slave_dev)
 {
 	pr_debug("bond_dev=%p\n", bond_dev);
 	pr_debug("slave_dev=%p\n", slave_dev);
 	pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
 	memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
-	return 0;
+	bond_dev->addr_assign_type = NET_ADDR_SET;
+	call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
 }
 
 static netdev_features_t bond_fix_features(struct net_device *dev,
@@ -1628,10 +1629,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	/* If this is the first slave, then we need to set the master's hardware
 	 * address to be the same as the slave's. */
-	if (is_zero_ether_addr(bond->dev->dev_addr))
-		memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
-		       slave_dev->addr_len);
-
+	if (bond->get_dev_addr_from_first_slave)
+		bond_set_dev_addr(bond->dev, slave_dev);
 
 	new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
 	if (!new_slave) {
@@ -2048,12 +2047,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	if (bond->slave_cnt == 0) {
 		bond_set_carrier(bond);
-
-		/* if the last slave was removed, zero the mac address
-		 * of the master so it will be set by the application
-		 * to the mac address of the first slave
-		 */
-		memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
 
 		if (bond_vlan_used(bond)) {
 			pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2234,11 +2229,8 @@ static int bond_release_all(struct net_device *bond_dev)
 		write_lock_bh(&bond->lock);
 	}
 
-	/* zero the mac address of the master so it will be
-	 * set by the application to the mac address of the
-	 * first slave
-	 */
-	memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+	eth_hw_addr_random(bond_dev);
+	bond->get_dev_addr_from_first_slave = true;
 
 	if (bond_vlan_used(bond)) {
 		pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -3708,7 +3700,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_SETHWADDR_OLD:
 		case SIOCBONDSETHWADDR:
-			res = bond_sethwaddr(bond_dev, slave_dev);
+			bond_set_dev_addr(bond_dev, slave_dev);
+			res = 0;
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
@@ -4858,6 +4851,13 @@ static int bond_init(struct net_device *bond_dev)
 
 	bond_debug_register(bond);
 
+	/* Ensure valid dev_addr */
+	if (is_zero_ether_addr(bond_dev->dev_addr) &&
+	    bond_dev->addr_assign_type == NET_ADDR_PERM) {
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
+	}
+
 	__hw_addr_init(&bond->mc_list);
 	return 0;
 }
drivers/net/bonding/bonding.h +1 -0
index 0d282d2..3200638 100644
@@ -248,6 +248,7 @@ struct bonding {
 	/* debugging support via debugfs */
 	struct	 dentry *debug_dir;
 #endif /* CONFIG_DEBUG_FS */
+	bool	get_dev_addr_from_first_slave;
 };
 
 static inline bool bond_vlan_used(struct bonding *bond)
Signature · 1 line
1.8.1

--
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

#3 lore raw
Quoted 22 lines · Jiri Pirko
Quoted 21 lines · Tue, Jan 29, 2013 at 07:32:36PM CET, [email protected] wrote:
Quoted 18 lines · Jiri Pirko

Makes more sense to have randomly generated address by default than to have all zeroes. It also allows user to for example put the bond into bridge without need to have any slaves in it.

Also note that this changes only behaviour of bonds with no slaves. Once the first slave device is enslaved, its address will be used (no change here).

Also, fix dev_assign_type values on the way.

---

v2->v3:
- call_netdevice_notifiers is called after dev_addr change.
- use bond->get_dev_addr_from_first_slave to know when to get addr from the first slave

Quoted 6 lines
Quoted 3 lines

Was there a problem with using the dev_addr_type to determine
this? If it's really necessary, I think the name of this field is really verbose; even "addr_from_first" should be sufficient in my mind.

It is necessary. Bridge call dev_set_mac_address() which sets dev->addr_assign_type = NET_ADDR_SET and that causes unwanted behaviour.

	Ok.
Quoted 2 lines

And as for the verbosity thing, I like more verbose better in situations like this. Zero room for confusion.

Fair enough, but the name doesn't need to be a whole sentence.
I think something like "mac_from_first_slave" is just as clear, and I'd even go as far as "mac_from_first". If it's really that complicated (and I don't think this is), add a comment somewhere.

	-J
Quoted 124 lines
Quoted 123 lines
	-J

---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]

Quoted 112 lines

v1->v2:
- fixed assign value of bond_dev->addr_assign_type in bond_set_dev_addr()
- added note to patch description

drivers/net/bonding/bond_main.c | 38 +++++++++++++++++++-------------------
drivers/net/bonding/bonding.h | 1 +

2 files changed, 20 insertions(+), 19 deletions(-)
drivers/net/bonding/bond_main.c +19 -19
index 564cf42..8692df8 100644
@@ -1320,14 +1320,15 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev,
-			  struct net_device *slave_dev)
+static void bond_set_dev_addr(struct net_device *bond_dev,
+			      struct net_device *slave_dev)
 {
 	pr_debug("bond_dev=%p\n", bond_dev);
 	pr_debug("slave_dev=%p\n", slave_dev);
 	pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
 	memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
-	return 0;
+	bond_dev->addr_assign_type = NET_ADDR_SET;
+	call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
 }
 
 static netdev_features_t bond_fix_features(struct net_device *dev,
@@ -1628,10 +1629,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	/* If this is the first slave, then we need to set the master's hardware
 	 * address to be the same as the slave's. */
-	if (is_zero_ether_addr(bond->dev->dev_addr))
-		memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
-		       slave_dev->addr_len);
-
+	if (bond->get_dev_addr_from_first_slave)
+		bond_set_dev_addr(bond->dev, slave_dev);
 
 	new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
 	if (!new_slave) {
@@ -2048,12 +2047,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	if (bond->slave_cnt == 0) {
 		bond_set_carrier(bond);
-
-		/* if the last slave was removed, zero the mac address
-		 * of the master so it will be set by the application
-		 * to the mac address of the first slave
-		 */
-		memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
 
 		if (bond_vlan_used(bond)) {
 			pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2234,11 +2229,8 @@ static int bond_release_all(struct net_device *bond_dev)
 		write_lock_bh(&bond->lock);
 	}
 
-	/* zero the mac address of the master so it will be
-	 * set by the application to the mac address of the
-	 * first slave
-	 */
-	memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+	eth_hw_addr_random(bond_dev);
+	bond->get_dev_addr_from_first_slave = true;
 
 	if (bond_vlan_used(bond)) {
 		pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -3708,7 +3700,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_SETHWADDR_OLD:
 		case SIOCBONDSETHWADDR:
-			res = bond_sethwaddr(bond_dev, slave_dev);
+			bond_set_dev_addr(bond_dev, slave_dev);
+			res = 0;
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
@@ -4858,6 +4851,13 @@ static int bond_init(struct net_device *bond_dev)
 
 	bond_debug_register(bond);
 
+	/* Ensure valid dev_addr */
+	if (is_zero_ether_addr(bond_dev->dev_addr) &&
+	    bond_dev->addr_assign_type == NET_ADDR_PERM) {
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
+	}
+
 	__hw_addr_init(&bond->mc_list);
 	return 0;
 }
drivers/net/bonding/bonding.h +1 -0
index 0d282d2..3200638 100644
@@ -248,6 +248,7 @@ struct bonding {
 	/* debugging support via debugfs */
 	struct	 dentry *debug_dir;
 #endif /* CONFIG_DEBUG_FS */
+	bool	get_dev_addr_from_first_slave;
 };
 
 static inline bool bond_vlan_used(struct bonding *bond)
Signature · 1 line
1.8.1

--
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

author
#4 lore raw
Quoted 33 lines · Tue, Jan 29, 2013 at 11:17:49PM CET, [email protected] wrote:
Quoted 22 lines · Jiri Pirko
Quoted 21 lines · Tue, Jan 29, 2013 at 07:32:36PM CET, [email protected] wrote:
Quoted 18 lines · Jiri Pirko

Makes more sense to have randomly generated address by default than to have all zeroes. It also allows user to for example put the bond into bridge without need to have any slaves in it.

Also note that this changes only behaviour of bonds with no slaves. Once the first slave device is enslaved, its address will be used (no change here).

Also, fix dev_assign_type values on the way.

---

v2->v3:
- call_netdevice_notifiers is called after dev_addr change.
- use bond->get_dev_addr_from_first_slave to know when to get addr from the first slave

Quoted 6 lines
Quoted 3 lines

Was there a problem with using the dev_addr_type to determine
this? If it's really necessary, I think the name of this field is really verbose; even "addr_from_first" should be sufficient in my mind.

It is necessary. Bridge call dev_set_mac_address() which sets dev->addr_assign_type = NET_ADDR_SET and that causes unwanted behaviour.

	Ok.
Quoted 7 lines
Quoted 2 lines

And as for the verbosity thing, I like more verbose better in situations like this. Zero room for confusion.

Fair enough, but the name doesn't need to be a whole sentence.
I think something like "mac_from_first_slave" is just as clear, and I'd even go as far as "mac_from_first". If it's really that complicated (and I don't think this is), add a comment somewhere.

Okay - I will redo this.

Quoted 129 lines
	-J
Quoted 124 lines
Quoted 123 lines
	-J

---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]

Quoted 112 lines

v1->v2:
- fixed assign value of bond_dev->addr_assign_type in bond_set_dev_addr()
- added note to patch description

drivers/net/bonding/bond_main.c | 38 +++++++++++++++++++-------------------
drivers/net/bonding/bonding.h | 1 +

2 files changed, 20 insertions(+), 19 deletions(-)
drivers/net/bonding/bond_main.c +19 -19
index 564cf42..8692df8 100644
@@ -1320,14 +1320,15 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-static int bond_sethwaddr(struct net_device *bond_dev,
-			  struct net_device *slave_dev)
+static void bond_set_dev_addr(struct net_device *bond_dev,
+			      struct net_device *slave_dev)
 {
 	pr_debug("bond_dev=%p\n", bond_dev);
 	pr_debug("slave_dev=%p\n", slave_dev);
 	pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
 	memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
-	return 0;
+	bond_dev->addr_assign_type = NET_ADDR_SET;
+	call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
 }
 
 static netdev_features_t bond_fix_features(struct net_device *dev,
@@ -1628,10 +1629,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	/* If this is the first slave, then we need to set the master's hardware
 	 * address to be the same as the slave's. */
-	if (is_zero_ether_addr(bond->dev->dev_addr))
-		memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
-		       slave_dev->addr_len);
-
+	if (bond->get_dev_addr_from_first_slave)
+		bond_set_dev_addr(bond->dev, slave_dev);
 
 	new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
 	if (!new_slave) {
@@ -2048,12 +2047,8 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
 
 	if (bond->slave_cnt == 0) {
 		bond_set_carrier(bond);
-
-		/* if the last slave was removed, zero the mac address
-		 * of the master so it will be set by the application
-		 * to the mac address of the first slave
-		 */
-		memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
 
 		if (bond_vlan_used(bond)) {
 			pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -2234,11 +2229,8 @@ static int bond_release_all(struct net_device *bond_dev)
 		write_lock_bh(&bond->lock);
 	}
 
-	/* zero the mac address of the master so it will be
-	 * set by the application to the mac address of the
-	 * first slave
-	 */
-	memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
+	eth_hw_addr_random(bond_dev);
+	bond->get_dev_addr_from_first_slave = true;
 
 	if (bond_vlan_used(bond)) {
 		pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
@@ -3708,7 +3700,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 			break;
 		case BOND_SETHWADDR_OLD:
 		case SIOCBONDSETHWADDR:
-			res = bond_sethwaddr(bond_dev, slave_dev);
+			bond_set_dev_addr(bond_dev, slave_dev);
+			res = 0;
 			break;
 		case BOND_CHANGE_ACTIVE_OLD:
 		case SIOCBONDCHANGEACTIVE:
@@ -4858,6 +4851,13 @@ static int bond_init(struct net_device *bond_dev)
 
 	bond_debug_register(bond);
 
+	/* Ensure valid dev_addr */
+	if (is_zero_ether_addr(bond_dev->dev_addr) &&
+	    bond_dev->addr_assign_type == NET_ADDR_PERM) {
+		eth_hw_addr_random(bond_dev);
+		bond->get_dev_addr_from_first_slave = true;
+	}
+
 	__hw_addr_init(&bond->mc_list);
 	return 0;
 }
drivers/net/bonding/bonding.h +1 -0
index 0d282d2..3200638 100644
@@ -248,6 +248,7 @@ struct bonding {
 	/* debugging support via debugfs */
 	struct	 dentry *debug_dir;
 #endif /* CONFIG_DEBUG_FS */
+	bool	get_dev_addr_from_first_slave;
 };
 
 static inline bool bond_vlan_used(struct bonding *bond)
Signature · 1 line
1.8.1

--
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