diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 39e77e999b8f..9bf7a8f44e5d 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -2017,6 +2017,27 @@ in6_localaddr(struct in6_addr *in6) return (0); } +/* + * Return 1 if an internet address is for the local host and configured + * on one of its interfaces. + */ +int +in6_localip(struct in6_addr *in6) +{ + struct in6_ifaddr *ia; + + IN6_IFADDR_RLOCK(); + TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) { + if (IN6_ARE_ADDR_EQUAL(in6, &ia->ia_addr.sin6_addr)) { + IN6_IFADDR_RUNLOCK(); + return (1); + } + } + IN6_IFADDR_RUNLOCK(); + return (0); +} + + int in6_is_addr_deprecated(struct sockaddr_in6 *sa6) { diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h index ae0da6aa0fff..5b552c9158d9 100644 --- a/sys/netinet6/in6.h +++ b/sys/netinet6/in6.h @@ -631,6 +631,7 @@ struct cmsghdr; int in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t)); int in6_localaddr __P((struct in6_addr *)); +int in6_localip(struct in6_addr *); int in6_addrscope __P((struct in6_addr *)); struct in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *)); extern void in6_if_up __P((struct ifnet *));