Source-Changes-HG archive

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

[src/trunk]: src/sys Switch the IPv4 address list to pslist(9)



details:   https://anonhg.NetBSD.org/src/rev/8114c8b31bcd
branches:  trunk
changeset: 816443:8114c8b31bcd
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Jul 06 08:42:34 2016 +0000

description:
Switch the IPv4 address list to pslist(9)

Note that we leave the old list just in case; it seems there are some
kvm(3) users accessing the list. We can remove it later if we confirmed
nobody does actually.

diffstat:

 sys/net/if_stf.c       |   7 ++---
 sys/netinet/in.c       |  30 ++++++++++++++++++---------
 sys/netinet/in_gif.c   |   6 ++--
 sys/netinet/in_pcb.c   |  13 ++++++-----
 sys/netinet/in_var.h   |  53 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/netinet/ip_carp.c  |   8 ++----
 sys/netinet/ip_icmp.c  |   6 ++--
 sys/netinet/ip_input.c |   7 ++---
 sys/netipsec/key.c     |  10 +++-----
 9 files changed, 98 insertions(+), 42 deletions(-)

diffs (truncated from 441 to 300 lines):

diff -r 17322755145f -r 8114c8b31bcd sys/net/if_stf.c
--- a/sys/net/if_stf.c  Wed Jul 06 08:01:30 2016 +0000
+++ b/sys/net/if_stf.c  Wed Jul 06 08:42:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_stf.c,v 1.93 2016/07/04 04:35:09 knakahara Exp $    */
+/*     $NetBSD: if_stf.c,v 1.94 2016/07/06 08:42:34 ozaki-r Exp $      */
 /*     $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
 
 /*
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.93 2016/07/04 04:35:09 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.94 2016/07/06 08:42:34 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -488,8 +488,7 @@
        /*
         * reject packets with broadcast
         */
-       TAILQ_FOREACH(ia4, &in_ifaddrhead, ia_list)
-       {
+       IN_ADDRLIST_READER_FOREACH(ia4) {
                if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
                        continue;
                if (in->s_addr == ia4->ia_broadaddr.sin_addr.s_addr)
diff -r 17322755145f -r 8114c8b31bcd sys/netinet/in.c
--- a/sys/netinet/in.c  Wed Jul 06 08:01:30 2016 +0000
+++ b/sys/netinet/in.c  Wed Jul 06 08:42:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.c,v 1.170 2016/07/06 05:27:52 ozaki-r Exp $ */
+/*     $NetBSD: in.c,v 1.171 2016/07/06 08:42:34 ozaki-r Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.170 2016/07/06 05:27:52 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.171 2016/07/06 08:42:34 ozaki-r Exp $");
 
 #include "arp.h"
 
@@ -185,13 +185,14 @@
 #define IN_MULTI_HASH(x, ifp) \
     (in_multihashtbl[(u_long)((x) ^ (ifp->if_index)) % IN_MULTI_HASH_SIZE])
 
-/* XXX DEPRECATED. Keep it to avoid breaking kvm(3) users. */
+/* XXX DEPRECATED. Keep them to avoid breaking kvm(3) users. */
 struct in_ifaddrhashhead *     in_ifaddrhashtbl;
 u_long                         in_ifaddrhash;
 struct in_ifaddrhead           in_ifaddrhead;
 
 struct pslist_head *           in_ifaddrhashtbl_pslist;
 u_long                         in_ifaddrhash_pslist;
+struct pslist_head             in_ifaddrhead_pslist;
 
 void
 in_init(void)
@@ -199,6 +200,7 @@
        pool_init(&inmulti_pool, sizeof(struct in_multi), 0, 0, 0, "inmltpl",
            NULL, IPL_SOFTNET);
        TAILQ_INIT(&in_ifaddrhead);
+       PSLIST_INIT(&in_ifaddrhead_pslist);
 
        in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true,
            &in_ifaddrhash);
@@ -223,13 +225,15 @@
        struct in_ifaddr *ia;
 
        if (subnetsarelocal) {
-               TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list)
+               IN_ADDRLIST_READER_FOREACH(ia) {
                        if ((in.s_addr & ia->ia_netmask) == ia->ia_net)
                                return (1);
+               }
        } else {
-               TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list)
+               IN_ADDRLIST_READER_FOREACH(ia) {
                        if ((in.s_addr & ia->ia_subnetmask) == ia->ia_subnet)
                                return (1);
+               }
        }
        return (0);
 }
@@ -304,7 +308,7 @@
        struct ifnet *ifp;
        unsigned long maxmtu = 0;
 
-       TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
+       IN_ADDRLIST_READER_FOREACH(ia) {
                if ((ifp = ia->ia_ifp) == 0)
                        continue;
                if ((ifp->if_flags & (IFF_UP|IFF_LOOPBACK)) != IFF_UP)
@@ -466,6 +470,7 @@
                        ia->ia_idsalt = cprng_fast32() % 65535;
                        LIST_INIT(&ia->ia_multiaddrs);
                        IN_ADDRHASH_ENTRY_INIT(ia);
+                       IN_ADDRLIST_ENTRY_INIT(ia);
 
                        newifaddr = 1;
                }
@@ -640,6 +645,8 @@
                TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_list);
                ifaref(&ia->ia_ifa);
                ifa_insert(ifp, &ia->ia_ifa);
+               TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_list);
+               IN_ADDRLIST_WRITER_INSERT_TAIL(ia);
                LIST_INSERT_HEAD(&IN_IFADDR_HASH(ia->ia_addr.sin_addr.s_addr),
                    ia, ia_hash);
                IN_ADDRHASH_WRITER_INSERT_HEAD(ia);
@@ -690,7 +697,7 @@
        ia = (struct in_ifaddr *)ifa;
        /* Delete the entry if exactly one ifaddr matches the
         * address, ifa->ifa_addr. */
-       TAILQ_FOREACH(p, &in_ifaddrhead, ia_list) {
+       IN_ADDRLIST_READER_FOREACH(p) {
                if (!in_hosteq(p->ia_addr.sin_addr, ia->ia_addr.sin_addr))
                        continue;
                if (p->ia_ifp != ia->ia_ifp)
@@ -722,6 +729,9 @@
        IN_ADDRHASH_ENTRY_DESTROY(ia);
        ifa_remove(ifp, &ia->ia_ifa);
        TAILQ_REMOVE(&in_ifaddrhead, ia, ia_list);
+       IN_ADDRLIST_WRITER_REMOVE(ia);
+       IN_ADDRLIST_ENTRY_DESTROY(ia);
+
        if (ia->ia_allhosts != NULL)
                in_delmulti(ia->ia_allhosts);
        ifafree(&ia->ia_ifa);
@@ -1066,7 +1076,7 @@
                prefix.s_addr &= mask.s_addr;
        }
 
-       TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
+       IN_ADDRLIST_READER_FOREACH(ia) {
                if (rtinitflags(ia))
                        p = ia->ia_dstaddr.sin_addr;
                else {
@@ -1126,7 +1136,7 @@
                prefix.s_addr &= mask.s_addr;
        }
 
-       TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
+       IN_ADDRLIST_READER_FOREACH(ia) {
                if (rtinitflags(ia))
                        p = ia->ia_dstaddr.sin_addr;
                else {
@@ -1524,7 +1534,7 @@
                sin->sin_port = fport;
                if (ia == NULL) {
                        /* Find 1st non-loopback AF_INET address */
-                       TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
+                       IN_ADDRLIST_READER_FOREACH(ia) {
                                if (!(ia->ia_ifp->if_flags & IFF_LOOPBACK))
                                        break;
                        }
diff -r 17322755145f -r 8114c8b31bcd sys/netinet/in_gif.c
--- a/sys/netinet/in_gif.c      Wed Jul 06 08:01:30 2016 +0000
+++ b/sys/netinet/in_gif.c      Wed Jul 06 08:42:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_gif.c,v 1.80 2016/07/06 01:10:07 knakahara Exp $    */
+/*     $NetBSD: in_gif.c,v 1.81 2016/07/06 08:42:34 ozaki-r Exp $      */
 /*     $KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $ */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.80 2016/07/06 01:10:07 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.81 2016/07/06 08:42:34 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -306,7 +306,7 @@
                return 0;
        }
        /* reject packets with broadcast on source */
-       TAILQ_FOREACH(ia4, &in_ifaddrhead, ia_list) {
+       IN_ADDRLIST_READER_FOREACH(ia4) {
                if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
                        continue;
                if (ip->ip_src.s_addr == ia4->ia_broadaddr.sin_addr.s_addr)
diff -r 17322755145f -r 8114c8b31bcd sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c      Wed Jul 06 08:01:30 2016 +0000
+++ b/sys/netinet/in_pcb.c      Wed Jul 06 08:42:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_pcb.c,v 1.164 2016/06/21 03:28:27 ozaki-r Exp $     */
+/*     $NetBSD: in_pcb.c,v 1.165 2016/07/06 08:42:34 ozaki-r Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.164 2016/06/21 03:28:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.165 2016/07/06 08:42:34 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -411,7 +411,7 @@
        if (inp->inp_af != AF_INET)
                return (EINVAL);
 
-       if (TAILQ_FIRST(&in_ifaddrhead) == 0)
+       if (IN_ADDRLIST_READER_EMPTY())
                return (EADDRNOTAVAIL);
        if (inp->inp_lport || !in_nullhost(inp->inp_laddr))
                return (EINVAL);
@@ -470,7 +470,7 @@
            inp->inp_socket->so_type == SOCK_STREAM)
                return EADDRNOTAVAIL;
 
-       if (TAILQ_FIRST(&in_ifaddrhead) != 0) {
+       if (!IN_ADDRLIST_READER_EMPTY()) {
                /*
                 * If the destination address is INADDR_ANY,
                 * use any local address (likely loopback).
@@ -480,10 +480,11 @@
                 */
 
                if (in_nullhost(sin->sin_addr)) {
+                       /* XXX racy */
                        sin->sin_addr =
-                           TAILQ_FIRST(&in_ifaddrhead)->ia_addr.sin_addr;
+                           IN_ADDRLIST_READER_FIRST()->ia_addr.sin_addr;
                } else if (sin->sin_addr.s_addr == INADDR_BROADCAST) {
-                       TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
+                       IN_ADDRLIST_READER_FOREACH(ia) {
                                if (ia->ia_ifp->if_flags & IFF_BROADCAST) {
                                        sin->sin_addr =
                                            ia->ia_broadaddr.sin_addr;
diff -r 17322755145f -r 8114c8b31bcd sys/netinet/in_var.h
--- a/sys/netinet/in_var.h      Wed Jul 06 08:01:30 2016 +0000
+++ b/sys/netinet/in_var.h      Wed Jul 06 08:42:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_var.h,v 1.75 2016/07/06 05:27:52 ozaki-r Exp $      */
+/*     $NetBSD: in_var.h,v 1.76 2016/07/06 08:42:34 ozaki-r Exp $      */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -107,6 +107,7 @@
 
 #ifdef _KERNEL
        struct pslist_entry     ia_hash_pslist_entry;
+       struct pslist_entry     ia_pslist_entry;
 #endif
 };
 
@@ -148,6 +149,7 @@
 
 extern struct pslist_head *in_ifaddrhashtbl_pslist;
 extern u_long in_ifaddrhash_pslist;
+extern struct pslist_head in_ifaddrhead_pslist;
 
 #define IN_IFADDR_HASH_PSLIST(x)                                       \
        in_ifaddrhashtbl_pslist[(u_long)(x) % IN_IFADDR_HASH_SIZE]
@@ -166,6 +168,55 @@
 #define IN_ADDRHASH_ENTRY_DESTROY(__ia)                                        \
        PSLIST_ENTRY_DESTROY((__ia), ia_hash_pslist_entry);
 
+#define IN_ADDRLIST_ENTRY_INIT(__ia)                                   \
+       PSLIST_ENTRY_INIT((__ia), ia_pslist_entry)
+#define IN_ADDRLIST_ENTRY_DESTROY(__ia)                                        \
+       PSLIST_ENTRY_DESTROY((__ia), ia_pslist_entry);
+#define IN_ADDRLIST_READER_EMPTY()                                     \
+       (PSLIST_READER_FIRST(&in_ifaddrhead_pslist, struct in_ifaddr,   \
+                            ia_pslist_entry) == NULL)
+#define IN_ADDRLIST_READER_FIRST()                                     \
+       PSLIST_READER_FIRST(&in_ifaddrhead_pslist, struct in_ifaddr,    \
+                           ia_pslist_entry)
+#define IN_ADDRLIST_READER_NEXT(__ia)                                  \
+       PSLIST_READER_NEXT((__ia), struct in_ifaddr, ia_pslist_entry)
+#define IN_ADDRLIST_READER_FOREACH(__ia)                               \
+       PSLIST_READER_FOREACH((__ia), &in_ifaddrhead_pslist,            \
+                             struct in_ifaddr, ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_INSERT_HEAD(__ia)                           \
+       PSLIST_WRITER_INSERT_HEAD(&in_ifaddrhead_pslist, (__ia),        \
+           ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_REMOVE(__ia)                                        \
+       PSLIST_WRITER_REMOVE((__ia), ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_FOREACH(__ia)                               \
+       PSLIST_WRITER_FOREACH((__ia), &in_ifaddrhead_pslist,            \
+                             struct in_ifaddr, ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_FIRST()                                     \
+       PSLIST_WRITER_FIRST(&in_ifaddrhead_pslist, struct in_ifaddr,    \
+                           ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_NEXT(__ia)                                  \
+       PSLIST_WRITER_NEXT((__ia), struct in_ifaddr, ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_INSERT_AFTER(__ia, __new)                   \
+       PSLIST_WRITER_INSERT_AFTER((__ia), (__new), ia_pslist_entry)
+#define IN_ADDRLIST_WRITER_EMPTY()                                     \
+       (PSLIST_WRITER_FIRST(&in_ifaddrhead_pslist, struct in_ifaddr,   \
+           ia_pslist_entry) == NULL)
+#define IN_ADDRLIST_WRITER_INSERT_TAIL(__new)                          \



Home | Main Index | Thread Index | Old Index