Date: Tue, 22 Jan 2013 12:34:22 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r245790 - user/ae/inet6/sys/netinet6 Message-ID: <201301221234.r0MCYMHd050948@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ae Date: Tue Jan 22 12:34:22 2013 New Revision: 245790 URL: http://svnweb.freebsd.org/changeset/base/245790 Log: Add in6ifa_ifwithaddr() function. It is similar to ifa_ifwithaddr(), but optimized for IPv6. Modified: user/ae/inet6/sys/netinet6/in6.c user/ae/inet6/sys/netinet6/in6_var.h Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Tue Jan 22 12:10:51 2013 (r245789) +++ user/ae/inet6/sys/netinet6/in6.c Tue Jan 22 12:34:22 2013 (r245790) @@ -1904,6 +1904,33 @@ in6ifa_ifpwithaddr(struct ifnet *ifp, st } /* + * find the internet address corresponding to a given address. + * ifaddr is returned referenced. + */ +struct in6_ifaddr * +in6ifa_ifwithaddr(const struct sockaddr_in6 *sa6) +{ + struct in6_ifaddr *ia; + + IN6_IFADDR_RLOCK(); + LIST_FOREACH(ia, IN6ADDR_HASH(&sa6->sin6_addr), ia6_hash) { + if (IN6_ARE_ADDR_EQUAL(IA6_IN6(ia), &sa6->sin6_addr)) { + /* + * XXX: should we determine the scope and compare + * sin6_scope_id with corresponding zone id? + */ + if (sa6->sin6_scope_id != 0 && + sa6->sin6_scope_id != in6_getlinkzone(ia->ia_ifp)) + continue; + ifa_ref(ia); + break; + } + } + IN6_IFADDR_RUNLOCK(); + return (ia); +} + +/* * Convert IP6 address to printable (loggable) representation. Caller * has to make sure that ip6buf is at least INET6_ADDRSTRLEN long. */ Modified: user/ae/inet6/sys/netinet6/in6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_var.h Tue Jan 22 12:10:51 2013 (r245789) +++ user/ae/inet6/sys/netinet6/in6_var.h Tue Jan 22 12:34:22 2013 (r245790) @@ -801,6 +801,7 @@ void in6_setmaxmtu(void); int in6_if2idlen(struct ifnet *); struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); +struct in6_ifaddr *in6ifa_ifwithaddr(const struct sockaddr_in6 *); char *ip6_sprintf(char *, const struct in6_addr *); int in6_addr2zoneid(struct ifnet *, struct in6_addr *, u_int32_t *); int in6_matchlen(struct in6_addr *, struct in6_addr *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301221234.r0MCYMHd050948>