Do soreserve() before `rop' allocation. It doesn't require protocol
control block be attached to socket. Also we always call `pr_attach' in
thread context so we always have `curproc'. 

ok?

Index: sys/net/rtsock.c
===================================================================
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.304
diff -u -p -r1.304 rtsock.c
--- sys/net/rtsock.c    7 Nov 2020 09:51:40 -0000       1.304
+++ sys/net/rtsock.c    10 Feb 2021 19:43:52 -0000
@@ -301,6 +301,9 @@ route_attach(struct socket *so, int prot
        struct rtpcb    *rop;
        int              error;
 
+       error = soreserve(so, ROUTESNDQ, ROUTERCVQ);
+       if (error)
+               return (error);
        /*
         * use the rawcb but allocate a rtpcb, this
         * code does not care about the additional fields
@@ -311,15 +314,6 @@ route_attach(struct socket *so, int prot
        /* Init the timeout structure */
        timeout_set(&rop->rop_timeout, rtm_senddesync_timer, so);
        refcnt_init(&rop->rop_refcnt);
-
-       if (curproc == NULL)
-               error = EACCES;
-       else
-               error = soreserve(so, ROUTESNDQ, ROUTERCVQ);
-       if (error) {
-               pool_put(&rtpcb_pool, rop);
-               return (error);
-       }
 
        rop->rop_socket = so;
        rop->rop_proto = proto;

Reply via email to