summaryrefslogtreecommitdiff
path: root/sys/net/rtsock.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2022-10-03 16:43:53 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2022-10-03 16:43:53 +0000
commit664e716c25187e8df24c685ad24616ba16bf6205 (patch)
tree56665a3f1021af1784fe972cd6365ad9b07d458e /sys/net/rtsock.c
parent9ada79011110198e0b48f901fda0f53caae40a5b (diff)
System calls should not fail due to temporary memory shortage in
malloc(9) or pool_get(9). Pass down a wait flag to pru_attach(). During syscall socket(2) it is ok to wait, this logic was missing for internet pcb. Pfkey and route sockets were already waiting. sonewconn() must not wait when called during TCP 3-way handshake. This logic has been preserved. Unix domain stream socket connect(2) can wait until the other side has created the socket to accept. OK mvs@
Diffstat (limited to 'sys/net/rtsock.c')
-rw-r--r--sys/net/rtsock.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 8da802643e4..1abd01340c1 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.356 2022/09/13 09:05:47 mvs Exp $ */
+/* $OpenBSD: rtsock.c,v 1.357 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -111,7 +111,7 @@ void rcb_ref(void *, void *);
void rcb_unref(void *, void *);
int route_output(struct mbuf *, struct socket *);
int route_ctloutput(int, struct socket *, int, int, struct mbuf *);
-int route_attach(struct socket *, int);
+int route_attach(struct socket *, int, int);
int route_detach(struct socket *);
int route_disconnect(struct socket *);
int route_shutdown(struct socket *);
@@ -216,7 +216,7 @@ rcb_unref(void *null, void *v)
}
int
-route_attach(struct socket *so, int proto)
+route_attach(struct socket *so, int proto, int wait)
{
struct rtpcb *rop;
int error;
@@ -229,7 +229,10 @@ route_attach(struct socket *so, int proto)
* code does not care about the additional fields
* and works directly on the raw socket.
*/
- rop = pool_get(&rtpcb_pool, PR_WAITOK|PR_ZERO);
+ rop = pool_get(&rtpcb_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
+ if (rop == NULL)
+ return (ENOBUFS);
so->so_pcb = rop;
/* Init the timeout structure */
timeout_set_proc(&rop->rop_timeout, rtm_senddesync_timer, so);