svn commit: r365384 - stable/12/sys/net

Oleksandr Tymoshenko gonzo at FreeBSD.org
Sun Sep 6 18:20:26 UTC 2020


Author: gonzo
Date: Sun Sep  6 18:20:25 2020
New Revision: 365384
URL: https://svnweb.freebsd.org/changeset/base/365384

Log:
  MFC r353419:
  
  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:
  stable/12/sys/net/if.c
  stable/12/sys/net/if_var.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/net/if.c
==============================================================================
--- stable/12/sys/net/if.c	Sun Sep  6 17:40:35 2020	(r365383)
+++ stable/12/sys/net/if.c	Sun Sep  6 18:20:25 2020	(r365384)
@@ -4313,6 +4313,53 @@ 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 ifaddr *ifa;
+	u_int count;
+
+	MPASS(cb);
+
+	count = 0;
+	IF_ADDR_RLOCK(ifp);
+	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);
+	}
+	IF_ADDR_RUNLOCK(ifp);
+
+	return (count);
+}
+
+u_int
+if_foreach_llmaddr(if_t ifp, iflladdr_cb_t cb, void *cb_arg)
+{
+	struct ifmultiaddr *ifma;
+	u_int count;
+
+	MPASS(cb);
+
+	count = 0;
+	IF_ADDR_RLOCK(ifp);
+	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);
+	}
+	IF_ADDR_RUNLOCK(ifp);
+
+	return (count);
+}
+
 int
 if_setsoftc(if_t ifp, void *softc)
 {

Modified: stable/12/sys/net/if_var.h
==============================================================================
--- stable/12/sys/net/if_var.h	Sun Sep  6 17:40:35 2020	(r365383)
+++ stable/12/sys/net/if_var.h	Sun Sep  6 18:20:25 2020	(r365384)
@@ -735,11 +735,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