Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Use pslist(9) for the global in6_ifaddr list



details:   https://anonhg.NetBSD.org/src/rev/4b8cfd03f00a
branches:  trunk
changeset: 346269:4b8cfd03f00a
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Jul 04 06:48:14 2016 +0000

description:
Use pslist(9) for the global in6_ifaddr list

psz and psref will be applied in another commit.

No functional change intended.

diffstat:

 sys/netinet/ip_carp.c       |   6 ++--
 sys/netinet6/in6.c          |  58 ++++++++++++++++----------------------------
 sys/netinet6/in6_ifattach.c |   6 ++--
 sys/netinet6/in6_src.c      |   6 ++--
 sys/netinet6/in6_var.h      |  58 +++++++++++++++++++++++++++++++++++++++++---
 sys/netinet6/ip6_input.c    |   8 +++--
 sys/netinet6/mld6.c         |   6 ++--
 sys/netinet6/nd6.c          |  13 +++++----
 sys/netinet6/nd6_rtr.c      |  12 ++++----
 sys/netipsec/key.c          |   8 +++---
 10 files changed, 109 insertions(+), 72 deletions(-)

diffs (truncated from 539 to 300 lines):

diff -r e2275ad1f338 -r 4b8cfd03f00a sys/netinet/ip_carp.c
--- a/sys/netinet/ip_carp.c     Mon Jul 04 04:43:46 2016 +0000
+++ b/sys/netinet/ip_carp.c     Mon Jul 04 06:48:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_carp.c,v 1.71 2016/06/21 03:28:27 ozaki-r Exp $     */
+/*     $NetBSD: ip_carp.c,v 1.72 2016/07/04 06:48:14 ozaki-r Exp $     */
 /*     $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $   */
 
 /*
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.71 2016/06/21 03:28:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.72 2016/07/04 06:48:14 ozaki-r Exp $");
 
 /*
  * TODO:
@@ -1827,7 +1827,7 @@
 
        /* we have to do this by hand to ensure we don't match on ourselves */
        ia_if = NULL;
-       for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+       IN6_ADDRLIST_READER_FOREACH(ia) {
                int i;
 
                for (i = 0; i < 4; i++) {
diff -r e2275ad1f338 -r 4b8cfd03f00a sys/netinet6/in6.c
--- a/sys/netinet6/in6.c        Mon Jul 04 04:43:46 2016 +0000
+++ b/sys/netinet6/in6.c        Mon Jul 04 06:48:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6.c,v 1.203 2016/07/04 02:41:18 ozaki-r Exp $        */
+/*     $NetBSD: in6.c,v 1.204 2016/07/04 06:48:14 ozaki-r Exp $        */
 /*     $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $   */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.203 2016/07/04 02:41:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.204 2016/07/04 06:48:14 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -209,7 +209,7 @@
         * XXX agree, especially now that I have fixed the dangling
         * XXX ifp-pointers bug.
         */
-       for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+       IN6_ADDRLIST_READER_FOREACH(ia) {
                if (!IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa), &ia->ia_addr.sin6_addr))
                        continue;
                if (ia->ia_ifp != ifa->ifa_ifp)
@@ -758,7 +758,6 @@
     struct in6_ifaddr *ia, int flags)
 {
        int error = 0, hostIsNew = 0, plen = -1;
-       struct in6_ifaddr *oia;
        struct sockaddr_in6 dst6;
        struct in6_addrlifetime *lt;
        struct in6_multi_mship *imm;
@@ -921,6 +920,7 @@
                    (struct sockaddr *)&ia->ia_prefixmask;
 
                ia->ia_ifp = ifp;
+               IN6_ADDRLIST_ENTRY_INIT(ia);
        }
 
        /* update timestamp */
@@ -1027,12 +1027,8 @@
        /*
         * Insert ia to the global list and ifa to the interface's list.
         */
-       if ((oia = in6_ifaddr) != NULL) {
-               for ( ; oia->ia_next; oia = oia->ia_next)
-                       continue;
-               oia->ia_next = ia;
-       } else
-               in6_ifaddr = ia;
+       IN6_ADDRLIST_WRITER_INSERT_TAIL(ia);
+
        /* gain a refcnt for the link from in6_ifaddr */
        ifaref(&ia->ia_ifa);
        ifa_insert(ifp, &ia->ia_ifa);
@@ -1352,52 +1348,39 @@
 static void
 in6_unlink_ifa(struct in6_ifaddr *ia, struct ifnet *ifp)
 {
-       struct in6_ifaddr *oia;
        int     s = splnet();
 
        ifa_remove(ifp, &ia->ia_ifa);
 
-       oia = ia;
-       if (oia == (ia = in6_ifaddr))
-               in6_ifaddr = ia->ia_next;
-       else {
-               while (ia->ia_next && (ia->ia_next != oia))
-                       ia = ia->ia_next;
-               if (ia->ia_next)
-                       ia->ia_next = oia->ia_next;
-               else {
-                       /* search failed */
-                       printf("Couldn't unlink in6_ifaddr from in6_ifaddr\n");
-               }
-       }
+       IN6_ADDRLIST_WRITER_REMOVE(ia);
 
        /*
         * XXX thorpej%NetBSD.org@localhost -- if the interface is going
         * XXX away, don't save the multicast entries, delete them!
         */
-       if (LIST_EMPTY(&oia->ia6_multiaddrs))
+       if (LIST_EMPTY(&ia->ia6_multiaddrs))
                ;
-       else if (if_is_deactivated(oia->ia_ifa.ifa_ifp)) {
+       else if (if_is_deactivated(ia->ia_ifa.ifa_ifp)) {
                struct in6_multi *in6m, *next;
 
-               for (in6m = LIST_FIRST(&oia->ia6_multiaddrs); in6m != NULL;
+               for (in6m = LIST_FIRST(&ia->ia6_multiaddrs); in6m != NULL;
                     in6m = next) {
                        next = LIST_NEXT(in6m, in6m_entry);
                        in6_delmulti(in6m);
                }
        } else
-               in6_savemkludge(oia);
+               in6_savemkludge(ia);
 
        /*
         * Release the reference to the base prefix.  There should be a
         * positive reference.
         */
-       if (oia->ia6_ndpr == NULL) {
+       if (ia->ia6_ndpr == NULL) {
                nd6log(LOG_NOTICE, "autoconf'ed address %p has no prefix\n",
-                   oia);
+                   ia);
        } else {
-               oia->ia6_ndpr->ndpr_refcnt--;
-               oia->ia6_ndpr = NULL;
+               ia->ia6_ndpr->ndpr_refcnt--;
+               ia->ia6_ndpr = NULL;
        }
 
        /*
@@ -1405,14 +1388,14 @@
         * pfxlist_onlink_check() since the release might affect the status of
         * other (detached) addresses.
         */
-       if ((oia->ia6_flags & IN6_IFF_AUTOCONF) != 0)
+       if ((ia->ia6_flags & IN6_IFF_AUTOCONF) != 0)
                pfxlist_onlink_check();
 
        /*
         * release another refcnt for the link from in6_ifaddr.
         * Note that we should decrement the refcnt at least once for all *BSD.
         */
-       ifafree(&oia->ia_ifa);
+       ifafree(&ia->ia_ifa);
 
        splx(s);
 }
@@ -1789,7 +1772,7 @@
        IN6_IFADDR_RLOCK();
        LIST_FOREACH(ia, IN6ADDR_HASH(addr), ia6_hash) {
 #else
-       for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+       IN6_ADDRLIST_READER_FOREACH(ia) {
 #endif
                if (IN6_ARE_ADDR_EQUAL(IA6_IN6(ia), addr)) {
                        if (zoneid != 0 &&
@@ -1858,10 +1841,11 @@
        if (IN6_IS_ADDR_LOOPBACK(in6) || IN6_IS_ADDR_LINKLOCAL(in6))
                return 1;
 
-       for (ia = in6_ifaddr; ia; ia = ia->ia_next)
+       IN6_ADDRLIST_READER_FOREACH(ia) {
                if (IN6_ARE_MASKED_ADDR_EQUAL(in6, &ia->ia_addr.sin6_addr,
                                              &ia->ia_prefixmask.sin6_addr))
                        return 1;
+       }
 
        return 0;
 }
@@ -1871,7 +1855,7 @@
 {
        struct in6_ifaddr *ia;
 
-       for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+       IN6_ADDRLIST_READER_FOREACH(ia) {
                if (IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr,
                    &sa6->sin6_addr) &&
 #ifdef SCOPEDROUTING
diff -r e2275ad1f338 -r 4b8cfd03f00a sys/netinet6/in6_ifattach.c
--- a/sys/netinet6/in6_ifattach.c       Mon Jul 04 04:43:46 2016 +0000
+++ b/sys/netinet6/in6_ifattach.c       Mon Jul 04 06:48:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_ifattach.c,v 1.99 2016/07/04 02:41:18 ozaki-r Exp $        */
+/*     $NetBSD: in6_ifattach.c,v 1.100 2016/07/04 06:48:14 ozaki-r Exp $       */
 /*     $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $  */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.99 2016/07/04 02:41:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.100 2016/07/04 06:48:14 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -245,7 +245,7 @@
        else {
                struct in6_ifaddr *ia;
 
-               for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+               IN6_ADDRLIST_READER_FOREACH(ia) {
                        if (!memcmp(&ia->ia_addr.sin6_addr.s6_addr[8], 
                            ret, 8)) {
                                badid = 1;
diff -r e2275ad1f338 -r 4b8cfd03f00a sys/netinet6/in6_src.c
--- a/sys/netinet6/in6_src.c    Mon Jul 04 04:43:46 2016 +0000
+++ b/sys/netinet6/in6_src.c    Mon Jul 04 06:48:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_src.c,v 1.62 2016/06/21 10:25:27 ozaki-r Exp $     */
+/*     $NetBSD: in6_src.c,v 1.63 2016/07/04 06:48:14 ozaki-r Exp $     */
 /*     $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $     */
 
 /*
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.62 2016/06/21 10:25:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.63 2016/07/04 06:48:14 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -293,7 +293,7 @@
        if (*errorp != 0)
                goto exit;
 
-       for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+       IN6_ADDRLIST_READER_FOREACH(ia) {
                int new_scope = -1, new_matchlen = -1;
                struct in6_addrpolicy *new_policy = NULL;
                u_int32_t srczone, osrczone, dstzone;
diff -r e2275ad1f338 -r 4b8cfd03f00a sys/netinet6/in6_var.h
--- a/sys/netinet6/in6_var.h    Mon Jul 04 04:43:46 2016 +0000
+++ b/sys/netinet6/in6_var.h    Mon Jul 04 06:48:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_var.h,v 1.77 2016/06/22 07:48:17 ozaki-r Exp $     */
+/*     $NetBSD: in6_var.h,v 1.78 2016/07/04 06:48:14 ozaki-r Exp $     */
 /*     $KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $        */
 
 /*
@@ -111,6 +111,7 @@
        struct  sockaddr_in6 ia_dstaddr; /* space for destination addr */
        struct  sockaddr_in6 ia_prefixmask; /* prefix mask */
        u_int32_t ia_plen;              /* prefix length */
+       /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
        struct  in6_ifaddr *ia_next;    /* next in6 list of IP6 addresses */
        struct  in6_multihead ia6_multiaddrs;
                                        /* list of multicast addresses */
@@ -127,6 +128,8 @@
 
        /* multicast addresses joined from the kernel */
        LIST_HEAD(, in6_multi_mship) ia6_memberships;
+
+       struct pslist_entry     ia6_pslist_entry;
 };
 
 /* control structure to manage address selection policy */
@@ -490,7 +493,53 @@
 
 MALLOC_DECLARE(M_IP6OPT);
 
-extern struct in6_ifaddr *in6_ifaddr;
+extern struct pslist_head in6_ifaddr_list;
+
+#define IN6_ADDRLIST_ENTRY_INIT(__ia) \
+       PSLIST_ENTRY_INIT((__ia), ia6_pslist_entry)
+#define IN6_ADDRLIST_READER_EMPTY() \
+       (PSLIST_READER_FIRST(&in6_ifaddr_list, struct in6_ifaddr, \
+                            ia6_pslist_entry) == NULL)
+#define IN6_ADDRLIST_READER_FIRST() \
+       PSLIST_READER_FIRST(&in6_ifaddr_list, struct in6_ifaddr, \
+                           ia6_pslist_entry)
+#define IN6_ADDRLIST_READER_NEXT(__ia) \
+       PSLIST_READER_NEXT((__ia), struct in6_ifaddr, ia6_pslist_entry)
+#define IN6_ADDRLIST_READER_FOREACH(__ia) \
+       PSLIST_READER_FOREACH((__ia), &in6_ifaddr_list, \
+                             struct in6_ifaddr, ia6_pslist_entry)
+#define IN6_ADDRLIST_WRITER_INSERT_HEAD(__ia) \
+       PSLIST_WRITER_INSERT_HEAD(&in6_ifaddr_list, (__ia), ia6_pslist_entry)
+#define IN6_ADDRLIST_WRITER_REMOVE(__ia) \
+       PSLIST_WRITER_REMOVE((__ia), ia6_pslist_entry)
+#define IN6_ADDRLIST_WRITER_FOREACH(__ia) \



Home | Main Index | Thread Index | Old Index