git: 66ff55d4830a - stable/12 - iavf(4): Replace functions with compatible implementations

From: Eric Joyner <erj_at_FreeBSD.org>
Date: Wed, 19 Oct 2022 23:23:41 UTC
The branch stable/12 has been updated by erj:

URL: https://cgit.FreeBSD.org/src/commit/?id=66ff55d4830a0b02e3b7b1c208cb3bba22cbf61a

commit 66ff55d4830a0b02e3b7b1c208cb3bba22cbf61a
Author:     Eric Joyner <erj@FreeBSD.org>
AuthorDate: 2022-10-19 22:16:41 +0000
Commit:     Eric Joyner <erj@FreeBSD.org>
CommitDate: 2022-10-19 22:16:41 +0000

    iavf(4): Replace functions with compatible implementations
    
    Since FreeBSD 12.4 is missing functions found in newer versions,
    replace some of the usages of missing ones with implementations
    that work for 12.4.
    
    This is a direct commit to stable/12; this fix isn't necessary on
    newer branches.
    
    Signed-off-by: Eric Joyner <erj@FreeBSD.org>
---
 sys/dev/iavf/iavf_lib.c | 41 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/sys/dev/iavf/iavf_lib.c b/sys/dev/iavf/iavf_lib.c
index 9b4ec425f1a9..e2b01b518985 100644
--- a/sys/dev/iavf/iavf_lib.c
+++ b/sys/dev/iavf/iavf_lib.c
@@ -43,6 +43,41 @@
 
 static void iavf_init_hw(struct iavf_hw *hw, device_t dev);
 static u_int iavf_mc_filter_apply(void *arg, struct sockaddr_dl *sdl, u_int cnt);
+static bool iavf_zero_mac(const uint8_t *addr);
+static u_int iavf_llmaddr_count(if_t ifp);
+
+/**
+ * iavf_zero_mac - Check if MAC address is 0 or not
+ *
+ * Returns true if MAC address is all 0's
+ */
+static bool
+iavf_zero_mac(const uint8_t *addr)
+{
+	uint8_t zero[ETHER_ADDR_LEN] = {0, 0, 0, 0, 0, 0};
+
+	return (cmp_etheraddr(addr, zero));
+}
+
+/**
+ * iavf_llmaddr_count - Return count of multicast MAC addresses in ifp
+ *
+ * Similar to "if_llmaddr_count()" found in newer FreeBSD versions
+ */
+static u_int
+iavf_llmaddr_count(if_t ifp)
+{
+	struct ifmultiaddr *ifma;
+	int count = 0;
+
+	if_maddr_rlock(ifp);
+	CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
+		if (ifma->ifma_addr->sa_family == AF_LINK)
+			count++;
+	if_maddr_runlock(ifp);
+
+	return (count);
+}
 
 /**
  * iavf_msec_pause - Pause for at least the specified number of milliseconds
@@ -540,7 +575,7 @@ iavf_set_mac_addresses(struct iavf_sc *sc)
 	u8 addr[ETHER_ADDR_LEN];
 
 	/* If no mac address was assigned just make a random one */
-	if (ETHER_IS_ZERO(hw->mac.addr)) {
+	if (iavf_zero_mac(hw->mac.addr)) {
 		arc4rand(&addr, sizeof(addr), 0);
 		addr[0] &= 0xFE;
 		addr[0] |= 0x02;
@@ -1215,7 +1250,7 @@ iavf_config_promisc(struct iavf_sc *sc, int flags)
 	sc->promisc_flags = 0;
 
 	if (flags & IFF_ALLMULTI ||
-		if_llmaddr_count(ifp) == MAX_MULTICAST_ADDR)
+		iavf_llmaddr_count(ifp) >= MAX_MULTICAST_ADDR)
 		sc->promisc_flags |= FLAG_VF_MULTICAST_PROMISC;
 	if (flags & IFF_PROMISC)
 		sc->promisc_flags |= FLAG_VF_UNICAST_PROMISC;
@@ -1287,7 +1322,7 @@ iavf_multi_set(struct iavf_sc *sc)
 
 	IOCTL_DEBUGOUT("iavf_multi_set: begin");
 
-	mcnt = if_llmaddr_count(ifp);
+	mcnt = iavf_llmaddr_count(ifp);
 	if (__predict_false(mcnt == MAX_MULTICAST_ADDR)) {
 		/* Delete MC filters and enable mulitcast promisc instead */
 		iavf_init_multi(sc);