summaryrefslogtreecommitdiffstats
path: root/sys/netinet6
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2015-04-17 11:57:06 +0000
committerglebius <glebius@FreeBSD.org>2015-04-17 11:57:06 +0000
commit14b7122d6dee034c5e3a8364b50fd099c0fed264 (patch)
treec9714052c3ff2d16c4996256c3dca0f6d0acc086 /sys/netinet6
parent330cbf85da1b4cdaca636b9ce05aab68901f9516 (diff)
downloadFreeBSD-src-14b7122d6dee034c5e3a8364b50fd099c0fed264.zip
FreeBSD-src-14b7122d6dee034c5e3a8364b50fd099c0fed264.tar.gz
Provide functions to determine presence of a given address
configured on a given interface. Discussed with: np Sponsored by: Nginx, Inc.
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/in6.c30
-rw-r--r--sys/netinet6/in6.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index ae68f26..ee197b6 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1684,6 +1684,36 @@ in6_localip(struct in6_addr *in6)
IN6_IFADDR_RUNLOCK();
return (0);
}
+
+/*
+ * Return 1 if an internet address is configured on an interface.
+ */
+int
+in6_ifhasaddr(struct ifnet *ifp, struct in6_addr *addr)
+{
+ struct in6_addr in6;
+ struct ifaddr *ifa;
+ struct in6_ifaddr *ia6;
+
+ in6 = *addr;
+ if (in6_clearscope(&in6) || in6_clearscope(&in6))
+ return (0);
+ in6_setscope(&in6, ifp, NULL);
+
+ IF_ADDR_RLOCK(ifp);
+ TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
+ if (ifa->ifa_addr->sa_family != AF_INET6)
+ continue;
+ ia6 = (struct in6_ifaddr *)ifa;
+ if (IN6_ARE_ADDR_EQUAL(&ia6->ia_addr.sin6_addr, &in6)) {
+ IF_ADDR_RUNLOCK(ifp);
+ return (1);
+ }
+ }
+ IF_ADDR_RUNLOCK(ifp);
+
+ return (0);
+}
int
in6_is_addr_deprecated(struct sockaddr_in6 *sa6)
diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index 1a33527..50ca387 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -650,6 +650,7 @@ int in6_cksum_partial(struct mbuf *, u_int8_t, u_int32_t, u_int32_t,
u_int32_t);
int in6_localaddr(struct in6_addr *);
int in6_localip(struct in6_addr *);
+int in6_ifhasaddr(struct ifnet *, struct in6_addr *);
int in6_addrscope(const struct in6_addr *);
char *ip6_sprintf(char *, const struct in6_addr *);
struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
OpenPOWER on IntegriCloud