Skip to contentSkip to conversation

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

PATCH In review Denys Zagorui 2 participants 3 messages Aug 17, 2020 – Aug 26, 2020

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

PATCH v2 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         | 13 ++++++-
 4 files changed, 71 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 +11 -2
index b2cf9b7bb7b8..7883bfd920fd 100644
@@ -7,6 +7,7 @@
 #include <linux/wireless.h>
 #include <net/dsa.h>
 #include <net/wext.h>
+#include <linux/if_arp.h>
 
 /*
  *	Map an interface index to its name (SIOCGIFNAME)
@@ -299,7 +300,11 @@ 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 (dev->type == ARPHRD_ETHER &&
+		    is_unicast_ether_addr(ifr->ifr_hwaddr.sa_data))
+			return dev_uc_add_global(dev, ifr->ifr_hwaddr.sa_data);
+		else
+			return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data);
 
 	case SIOCDELMULTI:
 		if (!ops->ndo_set_rx_mode ||
@@ -307,7 +312,11 @@ 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 (dev->type == ARPHRD_ETHER &&
+		    is_unicast_ether_addr(ifr->ifr_hwaddr.sa_data))
+			return dev_uc_del_global(dev, ifr->ifr_hwaddr.sa_data);
+		else
+			return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data);
 
 	case SIOCSIFTXQLEN:
 		if (ifr->ifr_qlen < 0)
Signature · 1 line
2.19.1
maintainer
#1 lore raw

From: Denys Zagorui <[email protected]>
Date: Mon, 17 Aug 2020 10:52:24 -0700

Quoted 6 lines

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 doesn't seem appropriate at all. If anything UC addresses should be blocked and the Intel driver change reverted. We have a well defined way to add secondary UC addresses and the MC interfaces are not it.

Furthermore, even if this was appropriate, "fixing" this only for ethernet is definitely not appropriate. The fix would need to be able to handle any address type. Having a generic interface work inconsistently for one link type vs. another is a non-starter.

Thanks.

#2 lore raw
Quoted 4 lines

This doesn't seem appropriate at all. If anything UC addresses should be blocked and the Intel driver change reverted. We have a well defined way to add secondary UC addresses and the MC interfaces are not it.

As I understand by ‘well defined way’ you mean macvlan feature. But macvlan is more virtualisation thing where an additional netdevice is created and for each skb passed to linux stack hash_lookup is made to find a netdevice to which this skb belongs to based on mac_dst. In case if someone want to have a network protocol on top of physical layer (AF_PACKET) where NIC should allow several uc mac addr without enabling promiscuous mode i am not sure that for this simple task macvlan is needed.

Quoted 4 lines

Furthermore, even if this was appropriate, "fixing" this only for ethernet is definitely not appropriate. The fix would need to be able to handle any address type. Having a generic interface work inconsistently for one link type vs. another is a non-starter.

Maybe overusing multicast api isn’t the best choice for this purpose, but i noticed that it is already overused by i40 for the same purpose, that is why i suggested this diff. Anyway i can add separate ioctls for add/del secondary uc, if this is worth it.