Hi,

Initialize struct inpcb pool not on demand, but during initialization.
Avoids MP problems and removes a global variable.

ok?

bluhm

Index: netinet/in_pcb.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.247
diff -u -p -r1.247 in_pcb.c
--- netinet/in_pcb.c    4 Oct 2018 17:33:41 -0000       1.247
+++ netinet/in_pcb.c    13 Jul 2019 13:08:15 -0000
@@ -114,7 +114,6 @@ int ipport_hilastauto = IPPORT_HILASTAUT
 struct baddynamicports baddynamicports;
 struct baddynamicports rootonlyports;
 struct pool inpcb_pool;
-int inpcb_pool_initialized = 0;

 int in_pcbresize (struct inpcbtable *, int);

@@ -124,6 +123,13 @@ struct inpcbhead *in_pcbhash(struct inpc
     const struct in_addr *, u_short, const struct in_addr *, u_short);
 struct inpcbhead *in_pcblhash(struct inpcbtable *, int, u_short);

+void
+in_init(void)
+{
+       pool_init(&inpcb_pool, sizeof(struct inpcb), 0,
+           IPL_SOFTNET, 0, "inpcb", NULL);
+}
+
 struct inpcbhead *
 in_pcbhash(struct inpcbtable *table, int rdom,
     const struct in_addr *faddr, u_short fport,
@@ -218,11 +224,6 @@ in_pcballoc(struct socket *so, struct in

        NET_ASSERT_LOCKED();

-       if (inpcb_pool_initialized == 0) {
-               pool_init(&inpcb_pool, sizeof(struct inpcb), 0,
-                   IPL_SOFTNET, 0, "inpcbpl", NULL);
-               inpcb_pool_initialized = 1;
-       }
        inp = pool_get(&inpcb_pool, PR_NOWAIT|PR_ZERO);
        if (inp == NULL)
                return (ENOBUFS);
Index: netinet/in_pcb.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.115
diff -u -p -r1.115 in_pcb.h
--- netinet/in_pcb.h    4 Oct 2018 17:33:41 -0000       1.115
+++ netinet/in_pcb.h    13 Jul 2019 13:05:49 -0000
@@ -256,6 +256,7 @@ extern int in_pcbnotifymiss;

 #define sotopf(so)  (so->so_proto->pr_domain->dom_family)

+void    in_init(void);
 void    in_losing(struct inpcb *);
 int     in_pcballoc(struct socket *, struct inpcbtable *);
 int     in_pcbbind(struct inpcb *, struct mbuf *, struct proc *);
Index: netinet/in_proto.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_proto.c,v
retrieving revision 1.92
diff -u -p -r1.92 in_proto.c
--- netinet/in_proto.c  13 Jun 2019 08:12:11 -0000      1.92
+++ netinet/in_proto.c  13 Jul 2019 13:05:58 -0000
@@ -441,6 +441,7 @@ const struct protosw inetsw[] = {
 struct domain inetdomain = {
   .dom_family = AF_INET,
   .dom_name = "internet",
+  .dom_init = in_init,
   .dom_protosw = inetsw,
   .dom_protoswNPROTOSW = &inetsw[nitems(inetsw)],
   .dom_sasize = sizeof(struct sockaddr_in),

Reply via email to