Skip to contentSkip to conversation

net: core: SIOCADDMULTI/SIOCDELMULTI distinguish between uc and mc

RFC PATCH Superseded Denys Zagorui 1 participant 1 message Aug 14, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 net: core: SIOCADDMULTI/SIOCDELMULTI distinguish between uc and mc

SIOCADDMULTI API allows adding multicast/unicast mac addresses but doesn't deferentiate them so if someone tries to add secondary unicast mac addr it will be added to multicast netdev list which is confusing. There is at least one user that allows adding secondary unicast through this API.
(2f41f3358672 i40e/i40evf: fix unicast mac address add)

This patch adds check whether passed mac addr is uc or mc and adds this mac addr to the corresponding list. Add 'global' variant for adding/removing uc addresses similarly to mc.

---
 include/linux/netdevice.h    |  2 +
 include/uapi/linux/sockios.h |  2 +-
 net/core/dev_addr_lists.c    | 75 +++++++++++++++++++++++++++---------
 net/core/dev_ioctl.c         | 10 ++++-
 4 files changed, 68 insertions(+), 21 deletions(-)
include/linux/netdevice.h +2 -0
index b0e303f6603f..9394f369be33 100644
@@ -4345,8 +4345,10 @@ int dev_addr_init(struct net_device *dev);
 
 /* Functions used for unicast addresses handling */
 int dev_uc_add(struct net_device *dev, const unsigned char *addr);
+int dev_uc_add_global(struct net_device *dev, const unsigned char *addr);
 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
 int dev_uc_del(struct net_device *dev, const unsigned char *addr);
+int dev_uc_del_global(struct net_device *dev, const unsigned char *addr);
 int dev_uc_sync(struct net_device *to, struct net_device *from);
 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
 void dev_uc_unsync(struct net_device *to, struct net_device *from);
include/uapi/linux/sockios.h +1 -1
index 7d1bccbbef78..f41b152b0268 100644
@@ -80,7 +80,7 @@
 #define SIOCGIFHWADDR	0x8927		/* Get hardware address		*/
 #define SIOCGIFSLAVE	0x8929		/* Driver slaving support	*/
 #define SIOCSIFSLAVE	0x8930
-#define SIOCADDMULTI	0x8931		/* Multicast address lists	*/
+#define SIOCADDMULTI	0x8931		/* Mac address lists	*/
 #define SIOCDELMULTI	0x8932
 #define SIOCGIFINDEX	0x8933		/* name -> if_index mapping	*/
 #define SIOGIFINDEX	SIOCGIFINDEX	/* misprint compatibility :-)	*/
net/core/dev_addr_lists.c +57 -18

99 lines not on this page · raw message

net/core/dev_ioctl.c +8 -2
index b2cf9b7bb7b8..774418f64c05 100644
@@ -299,7 +299,10 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 			return -EINVAL;
 		if (!netif_device_present(dev))
 			return -ENODEV;
-		return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data);
+		if (is_multicast_ether_addr(ifr->ifr_hwaddr.sa_data))
+			return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data);
+		else
+			return dev_uc_add_global(dev, ifr->ifr_hwaddr.sa_data);
 
 	case SIOCDELMULTI:
 		if (!ops->ndo_set_rx_mode ||
@@ -307,7 +310,10 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 			return -EINVAL;
 		if (!netif_device_present(dev))
 			return -ENODEV;
-		return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data);
+		if (is_multicast_ether_addr(ifr->ifr_hwaddr.sa_data))
+			return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data);
+		else
+			return dev_uc_del_global(dev, ifr->ifr_hwaddr.sa_data);
 
 	case SIOCSIFTXQLEN:
 		if (ifr->ifr_qlen < 0)
Signature · 1 line
2.19.1