@@ -1725,6 +1725,20 @@ void bond_lower_state_changed(struct slave *slave)
17251725 netdev_lower_state_changed (slave -> dev , & info );
17261726}
17271727
1728+ #define BOND_NL_ERR (bond_dev , extack , errmsg ) do { \
1729+ if (extack) \
1730+ NL_SET_ERR_MSG(extack, errmsg); \
1731+ else \
1732+ netdev_err(bond_dev, "Error: %s\n", errmsg); \
1733+ } while (0)
1734+
1735+ #define SLAVE_NL_ERR (bond_dev , slave_dev , extack , errmsg ) do { \
1736+ if (extack) \
1737+ NL_SET_ERR_MSG(extack, errmsg); \
1738+ else \
1739+ slave_err(bond_dev, slave_dev, "Error: %s\n", errmsg); \
1740+ } while (0)
1741+
17281742/* enslave device <slave> to bond device <master> */
17291743int bond_enslave (struct net_device * bond_dev , struct net_device * slave_dev ,
17301744 struct netlink_ext_ack * extack )
@@ -1738,9 +1752,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
17381752
17391753 if (slave_dev -> flags & IFF_MASTER &&
17401754 !netif_is_bond_master (slave_dev )) {
1741- NL_SET_ERR_MSG (extack , "Device with IFF_MASTER cannot be enslaved" );
1742- netdev_err (bond_dev ,
1743- "Error: Device with IFF_MASTER cannot be enslaved\n" );
1755+ BOND_NL_ERR (bond_dev , extack ,
1756+ "Device with IFF_MASTER cannot be enslaved" );
17441757 return - EPERM ;
17451758 }
17461759
@@ -1752,15 +1765,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
17521765
17531766 /* already in-use? */
17541767 if (netdev_is_rx_handler_busy (slave_dev )) {
1755- NL_SET_ERR_MSG (extack , "Device is in use and cannot be enslaved" );
1756- slave_err (bond_dev , slave_dev ,
1757- "Error: Device is in use and cannot be enslaved\n" );
1768+ SLAVE_NL_ERR (bond_dev , slave_dev , extack ,
1769+ "Device is in use and cannot be enslaved" );
17581770 return - EBUSY ;
17591771 }
17601772
17611773 if (bond_dev == slave_dev ) {
1762- NL_SET_ERR_MSG (extack , "Cannot enslave bond to itself." );
1763- netdev_err (bond_dev , "cannot enslave bond to itself.\n" );
1774+ BOND_NL_ERR (bond_dev , extack , "Cannot enslave bond to itself." );
17641775 return - EPERM ;
17651776 }
17661777
@@ -1769,8 +1780,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
17691780 if (slave_dev -> features & NETIF_F_VLAN_CHALLENGED ) {
17701781 slave_dbg (bond_dev , slave_dev , "is NETIF_F_VLAN_CHALLENGED\n" );
17711782 if (vlan_uses_dev (bond_dev )) {
1772- NL_SET_ERR_MSG ( extack , "Can not enslave VLAN challenged device to VLAN enabled bond" );
1773- slave_err ( bond_dev , slave_dev , "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n " );
1783+ SLAVE_NL_ERR ( bond_dev , slave_dev , extack ,
1784+ "Can not enslave VLAN challenged device to VLAN enabled bond" );
17741785 return - EPERM ;
17751786 } else {
17761787 slave_warn (bond_dev , slave_dev , "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n" );
@@ -1788,8 +1799,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
17881799 * enslaving it; the old ifenslave will not.
17891800 */
17901801 if (slave_dev -> flags & IFF_UP ) {
1791- NL_SET_ERR_MSG ( extack , "Device can not be enslaved while up" );
1792- slave_err ( bond_dev , slave_dev , "slave is up - this may be due to an out of date ifenslave\n " );
1802+ SLAVE_NL_ERR ( bond_dev , slave_dev , extack ,
1803+ "Device can not be enslaved while up " );
17931804 return - EPERM ;
17941805 }
17951806
@@ -1828,17 +1839,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
18281839 bond_dev );
18291840 }
18301841 } else if (bond_dev -> type != slave_dev -> type ) {
1831- NL_SET_ERR_MSG (extack , "Device type is different from other slaves" );
1832- slave_err (bond_dev , slave_dev , "ether type (%d) is different from other slaves (%d), can not enslave it\n" ,
1833- slave_dev -> type , bond_dev -> type );
1842+ SLAVE_NL_ERR (bond_dev , slave_dev , extack ,
1843+ "Device type is different from other slaves" );
18341844 return - EINVAL ;
18351845 }
18361846
18371847 if (slave_dev -> type == ARPHRD_INFINIBAND &&
18381848 BOND_MODE (bond ) != BOND_MODE_ACTIVEBACKUP ) {
1839- NL_SET_ERR_MSG (extack , "Only active-backup mode is supported for infiniband slaves" );
1840- slave_warn (bond_dev , slave_dev , "Type (%d) supports only active-backup mode\n" ,
1841- slave_dev -> type );
1849+ SLAVE_NL_ERR (bond_dev , slave_dev , extack ,
1850+ "Only active-backup mode is supported for infiniband slaves" );
18421851 res = - EOPNOTSUPP ;
18431852 goto err_undo_flags ;
18441853 }
@@ -1852,8 +1861,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
18521861 bond -> params .fail_over_mac = BOND_FOM_ACTIVE ;
18531862 slave_warn (bond_dev , slave_dev , "Setting fail_over_mac to active for active-backup mode\n" );
18541863 } else {
1855- NL_SET_ERR_MSG ( extack , "Slave device does not support setting the MAC address, but fail_over_mac is not set to active" );
1856- slave_err ( bond_dev , slave_dev , "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n " );
1864+ SLAVE_NL_ERR ( bond_dev , slave_dev , extack ,
1865+ "Slave device does not support setting the MAC address, but fail_over_mac is not set to active" );
18571866 res = - EOPNOTSUPP ;
18581867 goto err_undo_flags ;
18591868 }
@@ -2149,8 +2158,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
21492158 if (!slave_dev -> netdev_ops -> ndo_bpf ||
21502159 !slave_dev -> netdev_ops -> ndo_xdp_xmit ) {
21512160 if (bond -> xdp_prog ) {
2152- NL_SET_ERR_MSG ( extack , "Slave does not support XDP" );
2153- slave_err ( bond_dev , slave_dev , "Slave does not support XDP\n " );
2161+ SLAVE_NL_ERR ( bond_dev , slave_dev , extack ,
2162+ "Slave does not support XDP" );
21542163 res = - EOPNOTSUPP ;
21552164 goto err_sysfs_del ;
21562165 }
@@ -2163,10 +2172,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
21632172 };
21642173
21652174 if (dev_xdp_prog_count (slave_dev ) > 0 ) {
2166- NL_SET_ERR_MSG (extack ,
2167- "Slave has XDP program loaded, please unload before enslaving" );
2168- slave_err (bond_dev , slave_dev ,
2169- "Slave has XDP program loaded, please unload before enslaving\n" );
2175+ SLAVE_NL_ERR (bond_dev , slave_dev , extack ,
2176+ "Slave has XDP program loaded, please unload before enslaving" );
21702177 res = - EOPNOTSUPP ;
21712178 goto err_sysfs_del ;
21722179 }
@@ -5190,17 +5197,15 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
51905197
51915198 if (!slave_dev -> netdev_ops -> ndo_bpf ||
51925199 !slave_dev -> netdev_ops -> ndo_xdp_xmit ) {
5193- NL_SET_ERR_MSG ( extack , "Slave device does not support XDP" );
5194- slave_err ( dev , slave_dev , "Slave does not support XDP\n " );
5200+ SLAVE_NL_ERR ( dev , slave_dev , extack ,
5201+ "Slave device does not support XDP" );
51955202 err = - EOPNOTSUPP ;
51965203 goto err ;
51975204 }
51985205
51995206 if (dev_xdp_prog_count (slave_dev ) > 0 ) {
5200- NL_SET_ERR_MSG (extack ,
5201- "Slave has XDP program loaded, please unload before enslaving" );
5202- slave_err (dev , slave_dev ,
5203- "Slave has XDP program loaded, please unload before enslaving\n" );
5207+ SLAVE_NL_ERR (dev , slave_dev , extack ,
5208+ "Slave has XDP program loaded, please unload before enslaving" );
52045209 err = - EOPNOTSUPP ;
52055210 goto err ;
52065211 }
0 commit comments