From 4f21a4270498385160a1a301a54e77e225c54659 Mon Sep 17 00:00:00 2001 From: ozaki-r Date: Wed, 20 Jul 2016 07:37:51 +0000 Subject: [PATCH] Apply pserialize to some iterations of IP address lists --- sys/compat/svr4/svr4_sockio.c | 6 ++++-- sys/dev/qbus/if_dmc.c | 9 ++++++--- sys/dist/pf/net/pf_if.c | 9 +++++++-- sys/net/agr/if_agr.c | 8 ++++++-- sys/netinet6/in6.c | 18 ++++++++++++++---- sys/netinet6/in6_ifattach.c | 6 ++++-- sys/netinet6/mld6.c | 8 ++++++-- sys/netinet6/nd6_rtr.c | 8 ++++++-- sys/netipsec/key.c | 19 +++++++++++++++---- 9 files changed, 68 insertions(+), 23 deletions(-) diff --git a/sys/compat/svr4/svr4_sockio.c b/sys/compat/svr4/svr4_sockio.c index 0cac5af9cf84..7310922ec509 100644 --- a/sys/compat/svr4/svr4_sockio.c +++ b/sys/compat/svr4/svr4_sockio.c @@ -1,4 +1,4 @@ -/* $NetBSD: svr4_sockio.c,v 1.38 2016/07/07 09:32:02 ozaki-r Exp $ */ +/* $NetBSD: svr4_sockio.c,v 1.39 2016/07/20 07:37:51 ozaki-r Exp $ */ /*- * Copyright (c) 1995, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: svr4_sockio.c,v 1.38 2016/07/07 09:32:02 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: svr4_sockio.c,v 1.39 2016/07/20 07:37:51 ozaki-r Exp $"); #include #include @@ -87,10 +87,12 @@ svr4_count_ifnum(struct ifnet *ifp) { struct ifaddr *ifa; int ifnum = 0; + int s = pserialize_read_enter(); IFADDR_READER_FOREACH(ifa, ifp) ifnum++; + pserialize_read_exit(s); return MAX(1, ifnum); } diff --git a/sys/dev/qbus/if_dmc.c b/sys/dev/qbus/if_dmc.c index 2dfa14333092..a8997037bcf2 100644 --- a/sys/dev/qbus/if_dmc.c +++ b/sys/dev/qbus/if_dmc.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_dmc.c,v 1.25 2016/07/07 09:32:02 ozaki-r Exp $ */ +/* $NetBSD: if_dmc.c,v 1.26 2016/07/20 07:37:51 ozaki-r Exp $ */ /* * Copyright (c) 1982, 1986 Regents of the University of California. * All rights reserved. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_dmc.c,v 1.25 2016/07/07 09:32:02 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_dmc.c,v 1.26 2016/07/20 07:37:51 ozaki-r Exp $"); #undef DMCDEBUG /* for base table dump on fatal error */ @@ -313,9 +313,12 @@ dmcinit(struct ifnet *ifp) * Check to see that an address has been set * (both local and destination for an address family). */ - IFADDR_READER_FOREACH(ifa, ifp) + s = pserialize_read_enter(); + IFADDR_READER_FOREACH(ifa, ifp) { if (ifa->ifa_addr->sa_family && ifa->ifa_dstaddr->sa_family) break; + } + pserialize_read_exit(s); if (ifa == NULL) return 0; diff --git a/sys/dist/pf/net/pf_if.c b/sys/dist/pf/net/pf_if.c index 02fa0a54336b..5f8a9af95b95 100644 --- a/sys/dist/pf/net/pf_if.c +++ b/sys/dist/pf/net/pf_if.c @@ -1,4 +1,4 @@ -/* $NetBSD: pf_if.c,v 1.30 2016/07/07 09:32:02 ozaki-r Exp $ */ +/* $NetBSD: pf_if.c,v 1.31 2016/07/20 07:37:51 ozaki-r Exp $ */ /* $OpenBSD: pf_if.c,v 1.47 2007/07/13 09:17:48 markus Exp $ */ /* @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pf_if.c,v 1.30 2016/07/07 09:32:02 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pf_if.c,v 1.31 2016/07/20 07:37:51 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -556,9 +556,13 @@ pfi_instance_add(struct ifnet *ifp, int net, int flags) struct ifaddr *ia; int got4 = 0, got6 = 0; int net2, af; + int s; if (ifp == NULL) return; + + /* Depends on pfi_address_add doesn't sleep */ + s = pserialize_read_enter(); IFADDR_READER_FOREACH(ia, ifp) { af = ia->ifa_addr->sa_family; if (af != AF_INET && af != AF_INET6) @@ -603,6 +607,7 @@ pfi_instance_add(struct ifnet *ifp, int net, int flags) else pfi_address_add(ia->ifa_addr, af, net2); } + pserialize_read_exit(s); } void diff --git a/sys/net/agr/if_agr.c b/sys/net/agr/if_agr.c index ac0ee6081800..d5020c771587 100644 --- a/sys/net/agr/if_agr.c +++ b/sys/net/agr/if_agr.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_agr.c,v 1.37 2016/07/07 09:32:02 ozaki-r Exp $ */ +/* $NetBSD: if_agr.c,v 1.38 2016/07/20 07:37:51 ozaki-r Exp $ */ /*- * Copyright (c)2005 YAMAMOTO Takashi, @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.37 2016/07/07 09:32:02 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.38 2016/07/20 07:37:51 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -567,6 +567,7 @@ agr_addport(struct ifnet *ifp, struct ifnet *ifp_port) struct agr_softc *sc = ifp->if_softc; struct agr_port *port = NULL; int error = 0; + int s; if (ifp_port->if_ioctl == NULL) { error = EOPNOTSUPP; @@ -591,12 +592,15 @@ agr_addport(struct ifnet *ifp, struct ifnet *ifp_port) } port->port_flags = AGRPORT_LARVAL; + s = pserialize_read_enter(); IFADDR_READER_FOREACH(ifa, ifp_port) { if (ifa->ifa_addr->sa_family != AF_LINK) { + pserialize_read_exit(s); error = EBUSY; goto out; } } + pserialize_read_exit(s); if (sc->sc_nports == 0) { switch (ifp_port->if_type) { diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index d14cd15f02c0..985512107f76 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6.c,v 1.209 2016/07/15 07:40:09 ozaki-r Exp $ */ +/* $NetBSD: in6.c,v 1.210 2016/07/20 07:37:51 ozaki-r Exp $ */ /* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.209 2016/07/15 07:40:09 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.210 2016/07/20 07:37:51 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1832,15 +1832,20 @@ int in6_localaddr(const struct in6_addr *in6) { struct in6_ifaddr *ia; + int s; if (IN6_IS_ADDR_LOOPBACK(in6) || IN6_IS_ADDR_LINKLOCAL(in6)) return 1; + s = pserialize_read_enter(); IN6_ADDRLIST_READER_FOREACH(ia) { if (IN6_ARE_MASKED_ADDR_EQUAL(in6, &ia->ia_addr.sin6_addr, - &ia->ia_prefixmask.sin6_addr)) + &ia->ia_prefixmask.sin6_addr)) { + pserialize_read_exit(s); return 1; + } } + pserialize_read_exit(s); return 0; } @@ -1849,18 +1854,23 @@ int in6_is_addr_deprecated(struct sockaddr_in6 *sa6) { struct in6_ifaddr *ia; + int s; + s = pserialize_read_enter(); IN6_ADDRLIST_READER_FOREACH(ia) { if (IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, &sa6->sin6_addr) && #ifdef SCOPEDROUTING ia->ia_addr.sin6_scope_id == sa6->sin6_scope_id && #endif - (ia->ia6_flags & IN6_IFF_DEPRECATED) != 0) + (ia->ia6_flags & IN6_IFF_DEPRECATED) != 0) { + pserialize_read_exit(s); return 1; /* true */ + } /* XXX: do we still have to go thru the rest of the list? */ } + pserialize_read_exit(s); return 0; /* false */ } diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index a5532e019b31..932dc644d58f 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_ifattach.c,v 1.101 2016/07/07 09:32:03 ozaki-r Exp $ */ +/* $NetBSD: in6_ifattach.c,v 1.102 2016/07/20 07:37:51 ozaki-r Exp $ */ /* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.101 2016/07/07 09:32:03 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.102 2016/07/20 07:37:51 ozaki-r Exp $"); #include #include @@ -244,6 +244,7 @@ generate_tmp_ifid(u_int8_t *seed0, const u_int8_t *seed1, u_int8_t *ret) badid = 1; else { struct in6_ifaddr *ia; + int s = pserialize_read_enter(); IN6_ADDRLIST_READER_FOREACH(ia) { if (!memcmp(&ia->ia_addr.sin6_addr.s6_addr[8], @@ -252,6 +253,7 @@ generate_tmp_ifid(u_int8_t *seed0, const u_int8_t *seed1, u_int8_t *ret) break; } } + pserialize_read_exit(s); } /* diff --git a/sys/netinet6/mld6.c b/sys/netinet6/mld6.c index bbfc1b283218..356008b60e30 100644 --- a/sys/netinet6/mld6.c +++ b/sys/netinet6/mld6.c @@ -1,4 +1,4 @@ -/* $NetBSD: mld6.c,v 1.72 2016/07/08 04:33:30 ozaki-r Exp $ */ +/* $NetBSD: mld6.c,v 1.73 2016/07/20 07:37:51 ozaki-r Exp $ */ /* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */ /* @@ -102,7 +102,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.72 2016/07/08 04:33:30 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.73 2016/07/20 07:37:51 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -723,6 +723,8 @@ in6_delmulti(struct in6_multi *in6m) mld_stoptimer(in6m); if (--in6m->in6m_refcount == 0) { + int _s; + /* * No remaining claims to this record; let MLD6 know * that we are leaving the multicast group. @@ -742,6 +744,7 @@ in6_delmulti(struct in6_multi *in6m) * Delete all references of this multicasting group from * the membership arrays */ + _s = pserialize_read_enter(); IN6_ADDRLIST_READER_FOREACH(ia) { struct in6_multi_mship *imm; LIST_FOREACH(imm, &ia->ia6_memberships, i6mm_chain) { @@ -749,6 +752,7 @@ in6_delmulti(struct in6_multi *in6m) imm->i6mm_maddr = NULL; } } + pserialize_read_exit(_s); /* * Notify the network driver to update its multicast diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 9c0a20e0c8ab..63ee03f454d1 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $NetBSD: nd6_rtr.c,v 1.116 2016/07/15 07:40:09 ozaki-r Exp $ */ +/* $NetBSD: nd6_rtr.c,v 1.117 2016/07/20 07:37:51 ozaki-r Exp $ */ /* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.116 2016/07/15 07:40:09 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.117 2016/07/20 07:37:51 ozaki-r Exp $"); #include #include @@ -1911,6 +1911,7 @@ in6_tmpifadd( int updateflags; u_int32_t randid[2]; u_int32_t vltime0, pltime0; + int s; memset(&ifra, 0, sizeof(ifra)); strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name)); @@ -1940,9 +1941,11 @@ in6_tmpifadd( * there may be a time lag between generation of the ID and generation * of the address. So, we'll do one more sanity check. */ + s = pserialize_read_enter(); IN6_ADDRLIST_READER_FOREACH(ia) { if (IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, &ifra.ifra_addr.sin6_addr)) { + pserialize_read_exit(s); if (trylimit-- == 0) { /* * Give up. Something strange should have @@ -1956,6 +1959,7 @@ in6_tmpifadd( goto again; } } + pserialize_read_exit(s); /* * The Valid Lifetime is the lower of the Valid Lifetime of the diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 2f50449f2bf3..01e0126c118b 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -1,4 +1,4 @@ -/* $NetBSD: key.c,v 1.100 2016/07/07 06:59:30 ozaki-r Exp $ */ +/* $NetBSD: key.c,v 1.101 2016/07/20 07:37:51 ozaki-r Exp $ */ /* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */ /* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */ @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.100 2016/07/07 06:59:30 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.101 2016/07/20 07:37:51 ozaki-r Exp $"); /* * This code is referd to RFC 2367 @@ -4117,6 +4117,7 @@ key_ismyaddr(const struct sockaddr *sa) #ifdef INET const struct sockaddr_in *sin; const struct in_ifaddr *ia; + int s; #endif /* sanity check */ @@ -4127,14 +4128,17 @@ key_ismyaddr(const struct sockaddr *sa) #ifdef INET case AF_INET: sin = (const struct sockaddr_in *)sa; + s = pserialize_read_enter(); IN_ADDRLIST_READER_FOREACH(ia) { if (sin->sin_family == ia->ia_addr.sin_family && sin->sin_len == ia->ia_addr.sin_len && sin->sin_addr.s_addr == ia->ia_addr.sin_addr.s_addr) { + pserialize_read_exit(s); return 1; } } + pserialize_read_exit(s); break; #endif #ifdef INET6 @@ -4160,11 +4164,15 @@ key_ismyaddr6(const struct sockaddr_in6 *sin6) { struct in6_ifaddr *ia; const struct in6_multi *in6m; + int s; + s = pserialize_read_enter(); IN6_ADDRLIST_READER_FOREACH(ia) { if (key_sockaddrcmp((const struct sockaddr *)&sin6, - (const struct sockaddr *)&ia->ia_addr, 0) == 0) + (const struct sockaddr *)&ia->ia_addr, 0) == 0) { + pserialize_read_exit(s); return 1; + } /* * XXX Multicast @@ -4182,9 +4190,12 @@ key_ismyaddr6(const struct sockaddr_in6 *sin6) (in6m) = in6m->in6m_entry.le_next) continue; #endif - if (in6m) + if (in6m) { + pserialize_read_exit(s); return 1; + } } + pserialize_read_exit(s); /* loopback, just for safety */ if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))