summaryrefslogtreecommitdiffstats
path: root/sys/netinet6
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2016-03-17 10:59:30 +0000
committerae <ae@FreeBSD.org>2016-03-17 10:59:30 +0000
commita3a4fe00396dd61399083b8fe95b3cfc27f5b697 (patch)
tree7b54af035163ef03ee4e2d002cd151828fd35f42 /sys/netinet6
parent8eb97b7d66d37a484a1f259dbd63fbe401b7b89e (diff)
downloadFreeBSD-src-a3a4fe00396dd61399083b8fe95b3cfc27f5b697.zip
FreeBSD-src-a3a4fe00396dd61399083b8fe95b3cfc27f5b697.tar.gz
Change in6_selectsrc() to allow usage of non-local IPv6 addresses in
IPV6_PKTINFO ancillary data when IPV6_BINDANY socket option is set. Submitted by: n_hibma MFC after: 2 weeks
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/in6_src.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 4029402..97347bc 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -256,19 +256,27 @@ in6_selectsrc(uint32_t fibnum, struct sockaddr_in6 *dstsock,
(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);
}
OpenPOWER on IntegriCloud