From b132600ab26caed1b48a927a4714e6ed5db2ecef Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Sun, 19 Apr 2009 22:29:16 +0000 Subject: [PATCH] In divert_packet(), lock the interface address list before iterating over it in search of an address. MFC after: 2 weeks --- sys/netinet/ip_divert.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index f39c655f90bb..8a2fc25faaa6 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -244,18 +244,22 @@ divert_packet(struct mbuf *m, int incoming) divsrc.sin_port = divert_cookie(mtag); /* record matching rule */ if (incoming) { struct ifaddr *ifa; + struct ifnet *ifp; /* Sanity check */ M_ASSERTPKTHDR(m); /* Find IP address for receive interface */ - TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrhead, ifa_link) { + ifp = m->m_pkthdr.rcvif; + IF_ADDR_LOCK(ifp); + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != AF_INET) continue; divsrc.sin_addr = ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr; break; } + IF_ADDR_UNLOCK(ifp); } /* * Record the incoming interface name whenever we have one.