Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 2019 18:05:43 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353806 - head/sys/dev/al_eth
Message-ID:  <201910211805.x9LI5h3h064760@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Mon Oct 21 18:05:43 2019
New Revision: 353806
URL: https://svnweb.freebsd.org/changeset/base/353806

Log:
  Convert to if_foreach_llmaddr() KPI.
  
  This driver seems to have a bug.  The bug was carefully saved during
  conversion.  In the al_eth_mac_table_unicast_add() the argument 'addr',
  which is the actual address is unused.  So, the function is called as
  many times as we have addresses, but with the exactly same argument
  list.  This doesn't make any sense, but was preserved.

Modified:
  head/sys/dev/al_eth/al_eth.c

Modified: head/sys/dev/al_eth/al_eth.c
==============================================================================
--- head/sys/dev/al_eth/al_eth.c	Mon Oct 21 18:00:17 2019	(r353805)
+++ head/sys/dev/al_eth/al_eth.c	Mon Oct 21 18:05:43 2019	(r353806)
@@ -603,7 +603,7 @@ al_dma_free_coherent(bus_dma_tag_t tag, bus_dmamap_t m
 
 static void
 al_eth_mac_table_unicast_add(struct al_eth_adapter *adapter,
-    uint8_t idx, uint8_t *addr, uint8_t udma_mask)
+    uint8_t idx, uint8_t udma_mask)
 {
 	struct al_eth_fwd_mac_table_entry entry = { { 0 } };
 
@@ -2876,6 +2876,30 @@ al_get_counter(struct ifnet *ifp, ift_counter cnt)
 	}
 }
 
+static u_int
+al_count_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
+{
+	unsigned char *mac;
+
+	mac = LLADDR(sdl);
+	/* default mc address inside mac address */
+	if (mac[3] != 0 && mac[4] != 0 && mac[5] != 1)
+		return (1);
+	else
+		return (0);
+}
+
+static u_int
+al_program_addr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
+{
+	struct al_eth_adapter *adapter = arg;
+
+	al_eth_mac_table_unicast_add(adapter,
+	    AL_ETH_MAC_TABLE_UNICAST_IDX_BASE + 1 + cnt, 1);
+
+	return (1);
+}
+
 /*
  *  Unicast, Multicast and Promiscuous mode set
  *
@@ -2884,44 +2908,17 @@ al_get_counter(struct ifnet *ifp, ift_counter cnt)
  *  responsible for configuring the hardware for proper unicast, multicast,
  *  promiscuous mode, and all-multi behavior.
  */
-#define	MAX_NUM_MULTICAST_ADDRESSES 32
-#define	MAX_NUM_ADDRESSES           32
-
 static void
 al_eth_set_rx_mode(struct al_eth_adapter *adapter)
 {
 	struct ifnet *ifp = adapter->netdev;
-	struct ifmultiaddr *ifma; /* multicast addresses configured */
-	struct ifaddr *ifua; /* unicast address */
-	int mc = 0;
-	int uc = 0;
+	int mc, uc;
 	uint8_t i;
-	unsigned char *mac;
 
-	if_maddr_rlock(ifp);
-	CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
-		if (ifma->ifma_addr->sa_family != AF_LINK)
-			continue;
-		if (mc == MAX_NUM_MULTICAST_ADDRESSES)
-			break;
+	/* XXXGL: why generic count won't work? */
+	mc = if_foreach_llmaddr(ifp, al_count_maddr, NULL);
+	uc = if_lladdr_count(ifp);
 
-		mac = LLADDR((struct sockaddr_dl *) ifma->ifma_addr);
-		/* default mc address inside mac address */
-		if (mac[3] != 0 && mac[4] != 0 && mac[5] != 1)
-			mc++;
-	}
-	if_maddr_runlock(ifp);
-
-	if_addr_rlock(ifp);
-	CK_STAILQ_FOREACH(ifua, &ifp->if_addrhead, ifa_link) {
-		if (ifua->ifa_addr->sa_family != AF_LINK)
-			continue;
-		if (uc == MAX_NUM_ADDRESSES)
-			break;
-		uc++;
-	}
-	if_addr_runlock(ifp);
-
 	if ((ifp->if_flags & IFF_PROMISC) != 0) {
 		al_eth_mac_table_promiscuous_set(adapter, true);
 	} else {
@@ -2957,18 +2954,7 @@ al_eth_set_rx_mode(struct al_eth_adapter *adapter)
 			}
 
 			/* set new addresses */
-			i = AL_ETH_MAC_TABLE_UNICAST_IDX_BASE + 1;
-			if_addr_rlock(ifp);
-			CK_STAILQ_FOREACH(ifua, &ifp->if_addrhead, ifa_link) {
-				if (ifua->ifa_addr->sa_family != AF_LINK) {
-					continue;
-				}
-				al_eth_mac_table_unicast_add(adapter, i,
-				    (unsigned char *)ifua->ifa_addr, 1);
-				i++;
-			}
-			if_addr_runlock(ifp);
-
+			if_foreach_lladdr(ifp, al_program_addr, adapter);
 		}
 		al_eth_mac_table_promiscuous_set(adapter, false);
 	}
@@ -3001,7 +2987,7 @@ al_eth_config_rx_fwd(struct al_eth_adapter *adapter)
 	 * MAC address and all broadcast. all the rest will be dropped.
 	 */
 	al_eth_mac_table_unicast_add(adapter, AL_ETH_MAC_TABLE_UNICAST_IDX_BASE,
-	    adapter->mac_addr, 1);
+	    1);
 	al_eth_mac_table_broadcast_add(adapter, AL_ETH_MAC_TABLE_BROADCAST_IDX, 1);
 	al_eth_mac_table_promiscuous_set(adapter, false);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910211805.x9LI5h3h064760>