diff options
author | ae <ae@FreeBSD.org> | 2016-03-31 09:55:21 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2016-03-31 09:55:21 +0000 |
commit | 8dd17d694b5acc40fd8afe42eb42629de9db5cae (patch) | |
tree | dd07f88654e73ba9d03388ef27e31620368c5304 /sys/netinet6/in6_src.c | |
parent | e2f5e1b2b4a4f650458299eb8f8288ff7a7f8c7c (diff) | |
download | FreeBSD-src-8dd17d694b5acc40fd8afe42eb42629de9db5cae.zip FreeBSD-src-8dd17d694b5acc40fd8afe42eb42629de9db5cae.tar.gz |
MFC r296984:
Change in6_selectsrc() to allow usage of non-local IPv6 addresses in
IPV6_PKTINFO ancillary data when IPV6_BINDANY socket option is set.
Diffstat (limited to 'sys/netinet6/in6_src.c')
-rw-r--r-- | sys/netinet6/in6_src.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index c700969..d997335 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -249,19 +249,27 @@ in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) return (error); - ia6 = (struct in6_ifaddr *)ifa_ifwithaddr( - (struct sockaddr *)&srcsock); - if (ia6 == NULL || - (ia6->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { - if (ia6 != NULL) - ifa_free(&ia6->ia_ifa); - return (EADDRNOTAVAIL); - } + /* + * If IPV6_BINDANY socket option is set, we allow to specify + * non local addresses as source address in IPV6_PKTINFO + * ancillary data. + */ + if ((inp->inp_flags & INP_BINDANY) == 0) { + ia6 = (struct in6_ifaddr *)ifa_ifwithaddr( + (struct sockaddr *)&srcsock); + if (ia6 == NULL || (ia6->ia6_flags & (IN6_IFF_ANYCAST | + IN6_IFF_NOTREADY))) { + if (ia6 != NULL) + ifa_free(&ia6->ia_ifa); + return (EADDRNOTAVAIL); + } + bcopy(&ia6->ia_addr.sin6_addr, srcp, sizeof(*srcp)); + ifa_free(&ia6->ia_ifa); + } else + bcopy(&srcsock.sin6_addr, srcp, sizeof(*srcp)); pi->ipi6_addr = srcsock.sin6_addr; /* XXX: this overrides pi */ if (ifpp) *ifpp = ifp; - bcopy(&ia6->ia_addr.sin6_addr, srcp, sizeof(*srcp)); - ifa_free(&ia6->ia_ifa); return (0); } |