svn commit: r353419 - head/sys/net

Gleb Smirnoff glebius at FreeBSD.org
Thu Oct 10 23:42:57 UTC 2019


Author: glebius
Date: Thu Oct 10 23:42:55 2019
New Revision: 353419
URL: https://svnweb.freebsd.org/changeset/base/353419

Log:
  Provide new KPI for network drivers to access lists of interface
  addresses.  The KPI doesn't reveal neither how addresses are stored,
  how the access to them is synchronized, neither reveal struct ifaddr
  and struct ifmaddr.
  
  Reviewed by:	gallatin, erj, hselasky, philip, stevek
  Differential Revision:	https://reviews.freebsd.org/D21943

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:27:02 2019	(r353418)
+++ head/sys/net/if.c	Thu Oct 10 23:42:55 2019	(r353419)
@@ -4263,6 +4263,55 @@ if_getmtu_family(if_t ifp, int family)
 	return (((struct ifnet *)ifp)->if_mtu);
 }
 
+/*
+ * Methods for drivers to access interface unicast and multicast
+ * link level addresses.  Driver shall not know 'struct ifaddr' neither
+ * 'struct ifmultiaddr'.
+ */
+u_int
+if_foreach_lladdr(if_t ifp, iflladdr_cb_t cb, void *cb_arg)
+{
+	struct epoch_tracker et;
+	struct ifaddr *ifa;
+	u_int count;
+
+	MPASS(cb);
+
+	count = 0;
+	NET_EPOCH_ENTER(et);
+	CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
+		if (ifa->ifa_addr->sa_family != AF_LINK)
+			continue;
+		count += (*cb)(cb_arg, (struct sockaddr_dl *)ifa->ifa_addr,
+		    count);
+	}
+	NET_EPOCH_EXIT(et);
+
+	return (count);
+}
+
+u_int
+if_foreach_llmaddr(if_t ifp, iflladdr_cb_t cb, void *cb_arg)
+{
+	struct epoch_tracker et;
+	struct ifmultiaddr *ifma;
+	u_int count;
+
+	MPASS(cb);
+
+	count = 0;
+	NET_EPOCH_ENTER(et);
+	CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
+		if (ifma->ifma_addr->sa_family != AF_LINK)
+			continue;
+		count += (*cb)(cb_arg, (struct sockaddr_dl *)ifma->ifma_addr,
+		    count);
+	}
+	NET_EPOCH_EXIT(et);
+
+	return (count);
+}
+
 int
 if_setsoftc(if_t ifp, void *softc)
 {

Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h	Thu Oct 10 23:27:02 2019	(r353418)
+++ head/sys/net/if_var.h	Thu Oct 10 23:42:55 2019	(r353419)
@@ -765,11 +765,20 @@ void if_bpfmtap(if_t ifp, struct mbuf *m);
 void if_etherbpfmtap(if_t ifp, struct mbuf *m);
 void if_vlancap(if_t ifp);
 
-int if_setupmultiaddr(if_t ifp, void *mta, int *cnt, int max);
-int if_multiaddr_array(if_t ifp, void *mta, int *cnt, int max);
+/*
+ * Traversing through interface address lists.
+ */
+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 *);
 int if_multiaddr_count(if_t ifp, int max);
 
+/* Obsoleted multicast management functions. */
+int if_setupmultiaddr(if_t ifp, void *mta, int *cnt, int max);
+int if_multiaddr_array(if_t ifp, void *mta, int *cnt, int max);
 int if_multi_apply(struct ifnet *ifp, int (*filter)(void *, struct ifmultiaddr *, int), void *arg);
+
 int if_getamcount(if_t ifp);
 struct ifaddr * if_getifaddr(if_t ifp);
 


More information about the svn-src-all mailing list