diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2017-03-02 09:07:00 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2017-03-02 09:07:00 +0000 |
commit | 340978273f4b9595e5e63634a7d16e7bc0ae8b25 (patch) | |
tree | ae21f07a4b4ddb5f45a32372e51f3faf7a8bb69b | |
parent | 90af7a467abd85b4959c7db57e355b8d4d0e214c (diff) |
Use the routing table rather than the global list of IPv6 address.
ok bluhm@
-rw-r--r-- | sys/netinet6/icmp6.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index ca38b62dc7f..8fa5848672a 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.201 2017/02/09 20:31:29 jca Exp $ */ +/* $OpenBSD: icmp6.c,v 1.202 2017/03/02 09:06:59 mpi Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -1158,7 +1158,6 @@ icmp6_reflect(struct mbuf *m, size_t off) struct rtentry *rt = NULL; struct ip6_hdr *ip6; struct icmp6_hdr *icmp6; - struct in6_ifaddr *ia6; struct in6_addr t, *src = NULL; struct sockaddr_in6 sa6_src, sa6_dst; @@ -1231,25 +1230,28 @@ icmp6_reflect(struct mbuf *m, size_t off) in6_embedscope(&t, &sa6_dst, NULL); /* + * This is the case if the dst is our link-local address + * and the sender is also ourselves. + */ + if (IN6_IS_ADDR_LINKLOCAL(&t) && (m->m_flags & M_LOOP)) + src = &t; + + /* * If the incoming packet was addressed directly to us (i.e. unicast), * use dst as the src for the reply. * The IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED case would be VERY rare, * but is possible (for example) when we encounter an error while * forwarding procedure destined to a duplicated address of ours. */ - TAILQ_FOREACH(ia6, &in6_ifaddr, ia_list) - if (IN6_ARE_ADDR_EQUAL(&t, &ia6->ia_addr.sin6_addr) && - (ia6->ia6_flags & (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE| - IN6_IFF_DUPLICATED)) == 0) { + if (src == NULL) { + rt = rtalloc(sin6tosa(&sa6_dst), 0, m->m_pkthdr.ph_rtableid); + if (rtisvalid(rt) && ISSET(rt->rt_flags, RTF_LOCAL) && + !ISSET(ifatoia6(rt->rt_ifa)->ia6_flags, + IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED)) { src = &t; - break; } - if (ia6 == NULL && IN6_IS_ADDR_LINKLOCAL(&t) && (m->m_flags & M_LOOP)) { - /* - * This is the case if the dst is our link-local address - * and the sender is also ourselves. - */ - src = &t; + rtfree(rt); + rt = NULL; } if (src == NULL) { |