Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Oct 2019 23:44:56 +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: r353420 - head/sys/net
Message-ID:  <201910102344.x9ANiuoI084146@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Thu Oct 10 23:44:56 2019
New Revision: 353420
URL: https://svnweb.freebsd.org/changeset/base/353420

Log:
  Add two extra functions that basically give count of addresses
  on interface.  Such function could been implemented on top of
  the if_foreach_llm?addr(), but several drivers need counting,
  so avoid copy-n-paste inside the drivers.

Modified:
  head/sys/net/if.c
  head/sys/net/if_var.h

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c	Thu Oct 10 23:42:55 2019	(r353419)
+++ head/sys/net/if.c	Thu Oct 10 23:44:56 2019	(r353420)
@@ -4269,6 +4269,23 @@ if_getmtu_family(if_t ifp, int family)
  * 'struct ifmultiaddr'.
  */
 u_int
+if_lladdr_count(if_t ifp)
+{
+	struct epoch_tracker et;
+	struct ifaddr *ifa;
+	u_int count;
+
+	count = 0;
+	NET_EPOCH_ENTER(et);
+	CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
+		if (ifa->ifa_addr->sa_family == AF_LINK)
+			count++;
+	NET_EPOCH_EXIT(et);
+
+	return (count);
+}
+
+u_int
 if_foreach_lladdr(if_t ifp, iflladdr_cb_t cb, void *cb_arg)
 {
 	struct epoch_tracker et;
@@ -4285,6 +4302,23 @@ if_foreach_lladdr(if_t ifp, iflladdr_cb_t cb, void *cb
 		count += (*cb)(cb_arg, (struct sockaddr_dl *)ifa->ifa_addr,
 		    count);
 	}
+	NET_EPOCH_EXIT(et);
+
+	return (count);
+}
+
+u_int
+if_llmaddr_count(if_t ifp)
+{
+	struct epoch_tracker et;
+	struct ifmultiaddr *ifma;
+	int count;
+
+	count = 0;
+	NET_EPOCH_ENTER(et);
+	CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
+		if (ifma->ifma_addr->sa_family == AF_LINK)
+			count++;
 	NET_EPOCH_EXIT(et);
 
 	return (count);

Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h	Thu Oct 10 23:42:55 2019	(r353419)
+++ head/sys/net/if_var.h	Thu Oct 10 23:44:56 2019	(r353420)
@@ -772,6 +772,8 @@ struct sockaddr_dl;
 typedef u_int iflladdr_cb_t(void *, struct sockaddr_dl *, u_int);
 u_int if_foreach_lladdr(if_t, iflladdr_cb_t, void *);
 u_int if_foreach_llmaddr(if_t, iflladdr_cb_t, void *);
+u_int if_lladdr_count(if_t);
+u_int if_llmaddr_count(if_t);
 int if_multiaddr_count(if_t ifp, int max);
 
 /* Obsoleted multicast management functions. */



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