summaryrefslogtreecommitdiff
path: root/sys
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
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')
-rw-r--r--sys/kern/uipc_socket.c11
-rw-r--r--sys/kern/uipc_socket2.c8
-rw-r--r--sys/kern/uipc_usrreq.c9
-rw-r--r--sys/net/pfkeyv2.c11
-rw-r--r--sys/net/rtsock.c11
-rw-r--r--sys/netinet/in_pcb.c7
-rw-r--r--sys/netinet/in_pcb.h4
-rw-r--r--sys/netinet/ip_divert.c6
-rw-r--r--sys/netinet/ip_divert.h4
-rw-r--r--sys/netinet/ip_var.h4
-rw-r--r--sys/netinet/raw_ip.c6
-rw-r--r--sys/netinet/tcp_input.c4
-rw-r--r--sys/netinet/tcp_subr.c7
-rw-r--r--sys/netinet/tcp_usrreq.c8
-rw-r--r--sys/netinet/tcp_var.h6
-rw-r--r--sys/netinet/udp_usrreq.c6
-rw-r--r--sys/netinet/udp_var.h4
-rw-r--r--sys/netinet6/ip6_divert.c6
-rw-r--r--sys/netinet6/ip6_divert.h4
-rw-r--r--sys/netinet6/ip6_var.h4
-rw-r--r--sys/netinet6/raw_ip6.c10
-rw-r--r--sys/sys/protosw.h8
-rw-r--r--sys/sys/socketvar.h4
-rw-r--r--sys/sys/unpcb.h4
24 files changed, 83 insertions, 73 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 05e6eb58249..478763592b4 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.289 2022/09/05 14:56:08 bluhm Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.290 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -138,11 +138,12 @@ soinit(void)
}
struct socket *
-soalloc(int prflags)
+soalloc(int wait)
{
struct socket *so;
- so = pool_get(&socket_pool, prflags);
+ so = pool_get(&socket_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
if (so == NULL)
return (NULL);
rw_init_flags(&so->so_lock, "solock", RWL_DUPOK);
@@ -174,7 +175,7 @@ socreate(int dom, struct socket **aso, int type, int proto)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
- so = soalloc(PR_WAITOK | PR_ZERO);
+ so = soalloc(M_WAIT);
klist_init(&so->so_rcv.sb_sel.si_note, &socket_klistops, so);
klist_init(&so->so_snd.sb_sel.si_note, &socket_klistops, so);
sigio_init(&so->so_sigio);
@@ -193,7 +194,7 @@ socreate(int dom, struct socket **aso, int type, int proto)
so->so_rcv.sb_timeo_nsecs = INFSLP;
solock(so);
- error = pru_attach(so, proto);
+ error = pru_attach(so, proto, M_WAIT);
if (error) {
so->so_state |= SS_NOFDREF;
/* sofree() calls sounlock(). */
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index 3658537a02d..d8b39e44c69 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.128 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.129 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -168,7 +168,7 @@ soisdisconnected(struct socket *so)
* Connstatus may be 0 or SS_ISCONNECTED.
*/
struct socket *
-sonewconn(struct socket *head, int connstatus)
+sonewconn(struct socket *head, int connstatus, int wait)
{
struct socket *so;
int persocket = solock_persocket(head);
@@ -185,7 +185,7 @@ sonewconn(struct socket *head, int connstatus)
return (NULL);
if (head->so_qlen + head->so_q0len > head->so_qlimit * 3)
return (NULL);
- so = soalloc(PR_NOWAIT | PR_ZERO);
+ so = soalloc(wait);
if (so == NULL)
return (NULL);
so->so_type = head->so_type;
@@ -238,7 +238,7 @@ sonewconn(struct socket *head, int connstatus)
sounlock(head);
}
- error = pru_attach(so, 0);
+ error = pru_attach(so, 0, wait);
if (persocket) {
sounlock(so);
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index ddd8479cf45..bf5d83bb828 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.189 2022/09/20 10:10:11 mvs Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.190 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -242,7 +242,7 @@ const struct sysctl_bounded_args unpdgctl_vars[] = {
};
int
-uipc_attach(struct socket *so, int proto)
+uipc_attach(struct socket *so, int proto, int wait)
{
struct unpcb *unp;
int error;
@@ -270,7 +270,8 @@ uipc_attach(struct socket *so, int proto)
if (error)
return (error);
}
- unp = pool_get(&unpcb_pool, PR_NOWAIT|PR_ZERO);
+ unp = pool_get(&unpcb_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
if (unp == NULL)
return (ENOBUFS);
refcnt_init(&unp->unp_refcnt);
@@ -839,7 +840,7 @@ unp_connect(struct socket *so, struct mbuf *nam, struct proc *p)
solock(so2);
if ((so2->so_options & SO_ACCEPTCONN) == 0 ||
- (so3 = sonewconn(so2, 0)) == NULL) {
+ (so3 = sonewconn(so2, 0, M_WAIT)) == NULL) {
error = ECONNREFUSED;
}
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c
index b8f123a0802..022bd5ae025 100644
--- a/sys/net/pfkeyv2.c
+++ b/sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.252 2022/09/03 22:43:38 mvs Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.253 2022/10/03 16:43:52 bluhm Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -169,7 +169,7 @@ static int npromisc = 0;
void pfkey_init(void);
-int pfkeyv2_attach(struct socket *, int);
+int pfkeyv2_attach(struct socket *, int, int);
int pfkeyv2_detach(struct socket *);
int pfkeyv2_disconnect(struct socket *);
int pfkeyv2_shutdown(struct socket *);
@@ -269,7 +269,7 @@ pfkey_init(void)
* Attach a new PF_KEYv2 socket.
*/
int
-pfkeyv2_attach(struct socket *so, int proto)
+pfkeyv2_attach(struct socket *so, int proto, int wait)
{
struct pkpcb *kp;
int error;
@@ -281,7 +281,10 @@ pfkeyv2_attach(struct socket *so, int proto)
if (error)
return (error);
- kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO);
+ kp = pool_get(&pkpcb_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
+ if (kp == NULL)
+ return (ENOBUFS);
so->so_pcb = kp;
refcnt_init(&kp->kcb_refcnt);
kp->kcb_socket = so;
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);
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index e7d59873e7e..acc9a06a619 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_pcb.c,v 1.275 2022/09/03 22:43:38 mvs Exp $ */
+/* $OpenBSD: in_pcb.c,v 1.276 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
@@ -226,11 +226,12 @@ in_rootonly(u_int16_t port, u_int16_t proto)
}
int
-in_pcballoc(struct socket *so, struct inpcbtable *table)
+in_pcballoc(struct socket *so, struct inpcbtable *table, int wait)
{
struct inpcb *inp;
- inp = pool_get(&inpcb_pool, PR_NOWAIT|PR_ZERO);
+ inp = pool_get(&inpcb_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
if (inp == NULL)
return (ENOBUFS);
inp->inp_table = table;
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index a89a963ff8b..fd887789462 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_pcb.h,v 1.134 2022/09/03 22:43:38 mvs Exp $ */
+/* $OpenBSD: in_pcb.h,v 1.135 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */
/*
@@ -277,7 +277,7 @@ extern int in_pcbnotifymiss;
void in_init(void);
void in_losing(struct inpcb *);
-int in_pcballoc(struct socket *, struct inpcbtable *);
+int in_pcballoc(struct socket *, struct inpcbtable *, int);
int in_pcbbind(struct inpcb *, struct mbuf *, struct proc *);
int in_pcbaddrisavail(struct inpcb *, struct sockaddr_in *, int,
struct proc *);
diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c
index 1cdad66c298..9d4867776cf 100644
--- a/sys/netinet/ip_divert.c
+++ b/sys/netinet/ip_divert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_divert.c,v 1.87 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: ip_divert.c,v 1.88 2022/10/03 16:43:52 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -255,7 +255,7 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port)
}
int
-divert_attach(struct socket *so, int proto)
+divert_attach(struct socket *so, int proto, int wait)
{
int error;
@@ -264,7 +264,7 @@ divert_attach(struct socket *so, int proto)
if ((so->so_state & SS_PRIV) == 0)
return EACCES;
- error = in_pcballoc(so, &divbtable);
+ error = in_pcballoc(so, &divbtable, wait);
if (error)
return error;
diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h
index 5055a8f0a89..098e424b0f3 100644
--- a/sys/netinet/ip_divert.h
+++ b/sys/netinet/ip_divert.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_divert.h,v 1.22 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: ip_divert.h,v 1.23 2022/10/03 16:43:52 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -70,7 +70,7 @@ extern const struct pr_usrreqs divert_usrreqs;
void divert_init(void);
void divert_packet(struct mbuf *, int, u_int16_t);
int divert_sysctl(int *, u_int, void *, size_t *, void *, size_t);
-int divert_attach(struct socket *, int);
+int divert_attach(struct socket *, int, int);
int divert_detach(struct socket *);
void divert_lock(struct socket *);
void divert_unlock(struct socket *);
diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h
index 49b2f67fdb2..3f90bbc60d9 100644
--- a/sys/netinet/ip_var.h
+++ b/sys/netinet/ip_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_var.h,v 1.105 2022/09/13 09:05:02 mvs Exp $ */
+/* $OpenBSD: ip_var.h,v 1.106 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */
/*
@@ -256,7 +256,7 @@ void rip_init(void);
int rip_input(struct mbuf **, int *, int, int);
int rip_output(struct mbuf *, struct socket *, struct sockaddr *,
struct mbuf *);
-int rip_attach(struct socket *, int);
+int rip_attach(struct socket *, int, int);
int rip_detach(struct socket *);
void rip_lock(struct socket *);
void rip_unlock(struct socket *);
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index a00d922e37a..68e5a443ff7 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip.c,v 1.148 2022/09/13 09:05:02 mvs Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.149 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
@@ -468,7 +468,7 @@ u_long rip_sendspace = RIPSNDQ;
u_long rip_recvspace = RIPRCVQ;
int
-rip_attach(struct socket *so, int proto)
+rip_attach(struct socket *so, int proto, int wait)
{
struct inpcb *inp;
int error;
@@ -483,7 +483,7 @@ rip_attach(struct socket *so, int proto)
if ((error = soreserve(so, rip_sendspace, rip_recvspace)))
return error;
NET_ASSERT_LOCKED();
- if ((error = in_pcballoc(so, &rawcbtable)))
+ if ((error = in_pcballoc(so, &rawcbtable, wait)))
return error;
inp = sotoinpcb(so);
inp->inp_ip.ip_p = proto;
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index a37da1dfd99..3ec2bfc7060 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_input.c,v 1.380 2022/09/03 19:22:19 bluhm Exp $ */
+/* $OpenBSD: tcp_input.c,v 1.381 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
/*
@@ -3505,7 +3505,7 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, struct tcphdr *th,
* the connection, abort it.
*/
oso = so;
- so = sonewconn(so, SS_ISCONNECTED);
+ so = sonewconn(so, SS_ISCONNECTED, M_DONTWAIT);
if (so == NULL)
goto resetandabort;
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index e79aa0ff2f2..3a0d0cd7ab3 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_subr.c,v 1.188 2022/09/03 22:11:09 bluhm Exp $ */
+/* $OpenBSD: tcp_subr.c,v 1.189 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */
/*
@@ -420,12 +420,13 @@ tcp_respond(struct tcpcb *tp, caddr_t template, struct tcphdr *th0,
* protocol control block.
*/
struct tcpcb *
-tcp_newtcpcb(struct inpcb *inp)
+tcp_newtcpcb(struct inpcb *inp, int wait)
{
struct tcpcb *tp;
int i;
- tp = pool_get(&tcpcb_pool, PR_NOWAIT|PR_ZERO);
+ tp = pool_get(&tcpcb_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
+ PR_ZERO);
if (tp == NULL)
return (NULL);
TAILQ_INIT(&tp->t_segq);
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 7968aacbe3a..85083ee1fe0 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_usrreq.c,v 1.208 2022/09/13 09:05:47 mvs Exp $ */
+/* $OpenBSD: tcp_usrreq.c,v 1.209 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */
/*
@@ -460,7 +460,7 @@ tcp_ctloutput(int op, struct socket *so, int level, int optname,
* buffer space, and entering LISTEN state to accept connections.
*/
int
-tcp_attach(struct socket *so, int proto)
+tcp_attach(struct socket *so, int proto, int wait)
{
struct tcpcb *tp;
struct inpcb *inp;
@@ -477,11 +477,11 @@ tcp_attach(struct socket *so, int proto)
}
NET_ASSERT_LOCKED();
- error = in_pcballoc(so, &tcbtable);
+ error = in_pcballoc(so, &tcbtable, wait);
if (error)
return (error);
inp = sotoinpcb(so);
- tp = tcp_newtcpcb(inp);
+ tp = tcp_newtcpcb(inp, wait);
if (tp == NULL) {
unsigned int nofd = so->so_state & SS_NOFDREF; /* XXX */
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 7939cb3f7e1..430bc561f5b 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_var.h,v 1.158 2022/09/13 09:05:47 mvs Exp $ */
+/* $OpenBSD: tcp_var.h,v 1.159 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */
/*
@@ -696,7 +696,7 @@ void tcp6_mtudisc(struct inpcb *, int);
void tcp6_mtudisc_callback(struct sockaddr_in6 *, u_int);
#endif
struct tcpcb *
- tcp_newtcpcb(struct inpcb *);
+ tcp_newtcpcb(struct inpcb *, int);
void tcp_notify(struct inpcb *, int);
int tcp_output(struct tcpcb *);
void tcp_pulloutofband(struct socket *, u_int, struct mbuf *, int);
@@ -717,7 +717,7 @@ void tcp_trace(short, short, struct tcpcb *, struct tcpcb *, caddr_t,
struct tcpcb *
tcp_usrclosed(struct tcpcb *);
int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
-int tcp_attach(struct socket *, int);
+int tcp_attach(struct socket *, int, int);
int tcp_detach(struct socket *);
int tcp_bind(struct socket *, struct mbuf *, struct proc *);
int tcp_listen(struct socket *);
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index a019b2c236d..1b7aa8210b9 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_usrreq.c,v 1.302 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.303 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
/*
@@ -1079,7 +1079,7 @@ release:
}
int
-udp_attach(struct socket *so, int proto)
+udp_attach(struct socket *so, int proto, int wait)
{
int error;
@@ -1090,7 +1090,7 @@ udp_attach(struct socket *so, int proto)
return error;
NET_ASSERT_LOCKED();
- if ((error = in_pcballoc(so, &udbtable)))
+ if ((error = in_pcballoc(so, &udbtable, wait)))
return error;
#ifdef INET6
if (sotoinpcb(so)->inp_flags & INP_IPV6)
diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h
index c086640cf6d..bfe0723f115 100644
--- a/sys/netinet/udp_var.h
+++ b/sys/netinet/udp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_var.h,v 1.47 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: udp_var.h,v 1.48 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */
/*
@@ -143,7 +143,7 @@ int udp6_output(struct inpcb *, struct mbuf *, struct mbuf *,
struct mbuf *);
#endif /* INET6 */
int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
-int udp_attach(struct socket *, int);
+int udp_attach(struct socket *, int, int);
int udp_detach(struct socket *);
void udp_lock(struct socket *);
void udp_unlock(struct socket *);
diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c
index 29b3afb4642..daea9b981ca 100644
--- a/sys/netinet6/ip6_divert.c
+++ b/sys/netinet6/ip6_divert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_divert.c,v 1.86 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: ip6_divert.c,v 1.87 2022/10/03 16:43:52 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -261,7 +261,7 @@ divert6_packet(struct mbuf *m, int dir, u_int16_t divert_port)
}
int
-divert6_attach(struct socket *so, int proto)
+divert6_attach(struct socket *so, int proto, int wait)
{
int error;
@@ -271,7 +271,7 @@ divert6_attach(struct socket *so, int proto)
if ((so->so_state & SS_PRIV) == 0)
return EACCES;
- error = in_pcballoc(so, &divb6table);
+ error = in_pcballoc(so, &divb6table, wait);
if (error)
return (error);
diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h
index df0fbcf7677..d19db2141e5 100644
--- a/sys/netinet6/ip6_divert.h
+++ b/sys/netinet6/ip6_divert.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_divert.h,v 1.20 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: ip6_divert.h,v 1.21 2022/10/03 16:43:52 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -70,7 +70,7 @@ extern const struct pr_usrreqs divert6_usrreqs;
void divert6_init(void);
void divert6_packet(struct mbuf *, int, u_int16_t);
int divert6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
-int divert6_attach(struct socket *, int);
+int divert6_attach(struct socket *, int, int);
int divert6_detach(struct socket *);
void divert6_lock(struct socket *);
void divert6_unlock(struct socket *);
diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h
index c3c1d13824d..7aad9019955 100644
--- a/sys/netinet6/ip6_var.h
+++ b/sys/netinet6/ip6_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_var.h,v 1.103 2022/09/13 09:05:02 mvs Exp $ */
+/* $OpenBSD: ip6_var.h,v 1.104 2022/10/03 16:43:52 bluhm Exp $ */
/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
/*
@@ -351,7 +351,7 @@ void rip6_ctlinput(int, struct sockaddr *, u_int, void *);
int rip6_ctloutput(int, struct socket *, int, int, struct mbuf *);
int rip6_output(struct mbuf *, struct socket *, struct sockaddr *,
struct mbuf *);
-int rip6_attach(struct socket *, int);
+int rip6_attach(struct socket *, int, int);
int rip6_detach(struct socket *);
void rip6_lock(struct socket *);
void rip6_unlock(struct socket *);
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c
index b87f83df98c..cfa24451874 100644
--- a/sys/netinet6/raw_ip6.c
+++ b/sys/netinet6/raw_ip6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip6.c,v 1.169 2022/09/13 09:05:02 mvs Exp $ */
+/* $OpenBSD: raw_ip6.c,v 1.170 2022/10/03 16:43:52 bluhm Exp $ */
/* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */
/*
@@ -585,7 +585,7 @@ extern u_long rip6_sendspace;
extern u_long rip6_recvspace;
int
-rip6_attach(struct socket *so, int proto)
+rip6_attach(struct socket *so, int proto, int wait)
{
struct inpcb *in6p;
int error;
@@ -600,15 +600,15 @@ rip6_attach(struct socket *so, int proto)
if ((error = soreserve(so, rip6_sendspace, rip6_recvspace)))
return error;
NET_ASSERT_LOCKED();
- if ((error = in_pcballoc(so, &rawin6pcbtable)))
+ if ((error = in_pcballoc(so, &rawin6pcbtable, wait)))
return error;
in6p = sotoinpcb(so);
in6p->inp_ipv6.ip6_nxt = proto;
in6p->inp_cksum6 = -1;
- in6p->inp_icmp6filt = malloc(sizeof(struct icmp6_filter),
- M_PCB, M_NOWAIT);
+ in6p->inp_icmp6filt = malloc(sizeof(struct icmp6_filter), M_PCB,
+ wait == M_WAIT ? M_WAITOK : M_NOWAIT);
if (in6p->inp_icmp6filt == NULL) {
in_pcbdetach(in6p);
return ENOMEM;
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
index 00a6c754a4f..38304171186 100644
--- a/sys/sys/protosw.h
+++ b/sys/sys/protosw.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: protosw.h,v 1.56 2022/09/13 09:05:47 mvs Exp $ */
+/* $OpenBSD: protosw.h,v 1.57 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */
/*-
@@ -62,7 +62,7 @@ struct stat;
struct ifnet;
struct pr_usrreqs {
- int (*pru_attach)(struct socket *, int);
+ int (*pru_attach)(struct socket *, int, int);
int (*pru_detach)(struct socket *);
void (*pru_lock)(struct socket *);
void (*pru_unlock)(struct socket *);
@@ -267,9 +267,9 @@ extern const struct protosw inet6sw[];
#endif /* INET6 */
static inline int
-pru_attach(struct socket *so, int proto)
+pru_attach(struct socket *so, int proto, int wait)
{
- return (*so->so_proto->pr_usrreqs->pru_attach)(so, proto);
+ return (*so->so_proto->pr_usrreqs->pru_attach)(so, proto, wait);
}
static inline int
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
index 16f586b19e0..0e9030059c1 100644
--- a/sys/sys/socketvar.h
+++ b/sys/sys/socketvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socketvar.h,v 1.110 2022/09/05 14:56:09 bluhm Exp $ */
+/* $OpenBSD: socketvar.h,v 1.111 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
/*-
@@ -331,7 +331,7 @@ void soisconnecting(struct socket *);
void soisdisconnected(struct socket *);
void soisdisconnecting(struct socket *);
int solisten(struct socket *, int);
-struct socket *sonewconn(struct socket *, int);
+struct socket *sonewconn(struct socket *, int, int);
void soqinsque(struct socket *, struct socket *, int);
int soqremque(struct socket *, int);
int soreceive(struct socket *, struct mbuf **, struct uio *,
diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h
index b4f2681bacd..b0a02c41856 100644
--- a/sys/sys/unpcb.h
+++ b/sys/sys/unpcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unpcb.h,v 1.41 2022/09/13 09:05:47 mvs Exp $ */
+/* $OpenBSD: unpcb.h,v 1.42 2022/10/03 16:43:52 bluhm Exp $ */
/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
/*
@@ -112,7 +112,7 @@ struct fdpass {
extern const struct pr_usrreqs uipc_usrreqs;
-int uipc_attach(struct socket *, int);
+int uipc_attach(struct socket *, int, int);
int uipc_detach(struct socket *);
int uipc_bind(struct socket *, struct mbuf *, struct proc *);
int uipc_listen(struct socket *);