Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 2019 18:08:13 +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: r353831 - head/sys/dev/vge
Message-ID:  <201910211808.x9LI8Dsm066072@repo.freebsd.org>

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

Log:
  Convert to if_foreach_llmaddr() KPI.

Modified:
  head/sys/dev/vge/if_vge.c

Modified: head/sys/dev/vge/if_vge.c
==============================================================================
--- head/sys/dev/vge/if_vge.c	Mon Oct 21 18:08:03 2019	(r353830)
+++ head/sys/dev/vge/if_vge.c	Mon Oct 21 18:08:12 2019	(r353831)
@@ -529,6 +529,34 @@ vge_setvlan(struct vge_softc *sc)
 	CSR_WRITE_1(sc, VGE_RXCFG, cfg);
 }
 
+static u_int
+vge_set_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
+{
+	struct vge_softc *sc = arg;
+
+        if (sc->vge_camidx == VGE_CAM_MAXADDRS)
+		return (0);
+
+	(void )vge_cam_set(sc, LLADDR(sdl));
+
+	return (1);
+}
+
+static u_int
+vge_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
+{
+	uint32_t h, *hashes = arg;
+
+	h = ether_crc32_be(LLADDR(sdl), ETHER_ADDR_LEN) >> 26;
+	if (h < 32)
+		hashes[0] |= (1 << h);
+	else
+		hashes[1] |= (1 << (h - 32));
+
+	return (1);
+}
+
+
 /*
  * Program the multicast filter. We use the 64-entry CAM filter
  * for perfect filtering. If there's more than 64 multicast addresses,
@@ -538,10 +566,8 @@ static void
 vge_rxfilter(struct vge_softc *sc)
 {
 	struct ifnet *ifp;
-	struct ifmultiaddr *ifma;
-	uint32_t h, hashes[2];
+	uint32_t hashes[2];
 	uint8_t rxcfg;
-	int error = 0;
 
 	VGE_LOCK_ASSERT(sc);
 
@@ -572,33 +598,15 @@ vge_rxfilter(struct vge_softc *sc)
 	}
 
 	vge_cam_clear(sc);
+
 	/* Now program new ones */
-	if_maddr_rlock(ifp);
-	CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
-		if (ifma->ifma_addr->sa_family != AF_LINK)
-			continue;
-		error = vge_cam_set(sc,
-		    LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
-		if (error)
-			break;
-	}
+	if_foreach_llmaddr(ifp, vge_set_maddr, sc);
 
 	/* If there were too many addresses, use the hash filter. */
-	if (error) {
+        if (sc->vge_camidx == VGE_CAM_MAXADDRS) {
 		vge_cam_clear(sc);
-
-		CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
-			if (ifma->ifma_addr->sa_family != AF_LINK)
-				continue;
-			h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
-			    ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
-			if (h < 32)
-				hashes[0] |= (1 << h);
-			else
-				hashes[1] |= (1 << (h - 32));
-		}
+		 if_foreach_llmaddr(ifp, vge_hash_maddr, hashes);
 	}
-	if_maddr_runlock(ifp);
 
 done:
 	if (hashes[0] != 0 || hashes[1] != 0)



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