From 340978273f4b9595e5e63634a7d16e7bc0ae8b25 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Thu, 2 Mar 2017 09:07:00 +0000 Subject: Use the routing table rather than the global list of IPv6 address. ok bluhm@ --- sys/netinet6/icmp6.c | 28 +++++++++++++++------------- 1 file 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; @@ -1230,6 +1229,13 @@ icmp6_reflect(struct mbuf *m, size_t off) in6_recoverscope(&sa6_dst, &t); 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. @@ -1237,19 +1243,15 @@ icmp6_reflect(struct mbuf *m, size_t off) * 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) { -- cgit v1.2.3