On Mon, Aug 08, 2022 at 12:47:07AM +0200, Alexander Bluhm wrote:
> On Mon, Aug 08, 2022 at 01:03:13AM +0300, Vitaliy Makkoveev wrote:
> > > I prefer the first idiom. If there is an error, do something. We
> > > should not change the style in opposite direction. This will prevent
> > > consistency.
> > >
> >
> > I???m not entirely understand you. When we have something to do in the
> > error path, I use "goto out??? and it works like the first idiom.
>
> Ah, sorry. I was speaking about the != 0. The break, return, goto
> is fine. error != 0 is just style and does not affect correctness.
>
> > >> - if (error)
> > >> + if (error != 0)
>
We use if (error != 0) or if (m == NULL) idioms in the network stack, so
I used them too in the trivial places.
But here is another version of the split diff.
guenther@ reminded me about his reverted diff. His diff introduced the
new 'pr_usrreqs' structure, which should contain pointers to user
request handlers. The diff was reverted because it had a bug in the
socreate() path.
The bug was easy to fix, we need to check "prp->pr_usrreqs == NULL"
instead of "prp->pr_attach == NULL" because `pr_attach' handler was
moved to the 'pr_usrreqs' structure. guenther@ nas no resources to
continue this work, so he proposed to me to continue.
I still like to use dedicated 'pr_usrreqs' structure instead of place
pointers to `protosw' because it allows us to avoid huge copy-paste
within in{,6}_proto.c.
The diff below uses original idea, but it moves existing `pr_attach',
`pr_detach' and `pr_usrreq' to the new 'pr_usrreqs' structure. The
original diff moved only `pr_attach' and `pr_detach' and left
`pr_usrreq' as is. The original diff also introduced the `pru_control'
handler, but I like to start split with the following diffs.
Also I like to hide ugly "(*so->so_proto->pr_usrreqs->pru_usrreq)" calls
within corresponding pru_*() wrappers.
So, for the first step, just move existing user requests handlers
pointers.
Index: sys/kern/sys_socket.c
===================================================================
RCS file: /cvs/src/sys/kern/sys_socket.c,v
retrieving revision 1.51
diff -u -p -r1.51 sys_socket.c
--- sys/kern/sys_socket.c 20 Jun 2022 01:39:44 -0000 1.51
+++ sys/kern/sys_socket.c 8 Aug 2022 12:42:41 -0000
@@ -138,8 +138,7 @@ soo_ioctl(struct file *fp, u_long cmd, c
if (IOCGROUP(cmd) == 'r')
return (EOPNOTSUPP);
KERNEL_LOCK();
- error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
- (struct mbuf *)cmd, (struct mbuf *)data, NULL, p));
+ error = pru_control(so, cmd, data, NULL, p);
KERNEL_UNLOCK();
break;
}
@@ -161,8 +160,7 @@ soo_stat(struct file *fp, struct stat *u
ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
ub->st_uid = so->so_euid;
ub->st_gid = so->so_egid;
- (void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
- (struct mbuf *)ub, NULL, NULL, p));
+ (void)pru_sense(so, ub);
sounlock(so);
return (0);
}
Index: sys/kern/uipc_proto.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_proto.c,v
retrieving revision 1.22
diff -u -p -r1.22 uipc_proto.c
--- sys/kern/uipc_proto.c 25 Feb 2022 23:51:03 -0000 1.22
+++ sys/kern/uipc_proto.c 8 Aug 2022 12:42:41 -0000
@@ -50,27 +50,21 @@ const struct protosw unixsw[] = {
.pr_domain = &unixdomain,
.pr_protocol = PF_UNIX,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
- .pr_usrreq = uipc_usrreq,
- .pr_attach = uipc_attach,
- .pr_detach = uipc_detach,
+ .pr_usrreqs = &uipc_usrreqs,
},
{
.pr_type = SOCK_SEQPACKET,
.pr_domain = &unixdomain,
.pr_protocol = PF_UNIX,
.pr_flags = PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
- .pr_usrreq = uipc_usrreq,
- .pr_attach = uipc_attach,
- .pr_detach = uipc_detach,
+ .pr_usrreqs = &uipc_usrreqs,
},
{
.pr_type = SOCK_DGRAM,
.pr_domain = &unixdomain,
.pr_protocol = PF_UNIX,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
- .pr_usrreq = uipc_usrreq,
- .pr_attach = uipc_attach,
- .pr_detach = uipc_detach,
+ .pr_usrreqs = &uipc_usrreqs,
}
};
Index: sys/kern/uipc_socket.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.280
diff -u -p -r1.280 uipc_socket.c
--- sys/kern/uipc_socket.c 25 Jul 2022 07:28:22 -0000 1.280
+++ sys/kern/uipc_socket.c 8 Aug 2022 12:42:41 -0000
@@ -172,7 +172,7 @@ socreate(int dom, struct socket **aso, i
prp = pffindproto(dom, proto, type);
else
prp = pffindtype(dom, type);
- if (prp == NULL || prp->pr_attach == NULL)
+ if (prp == NULL || prp->pr_usrreqs == NULL)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
@@ -195,7 +195,7 @@ socreate(int dom, struct socket **aso, i
so->so_rcv.sb_timeo_nsecs = INFSLP;
solock(so);
- error = (*prp->pr_attach)(so, proto);
+ error = pru_attach(prp, so, proto);
if (error) {
so->so_state |= SS_NOFDREF;
/* sofree() calls sounlock(). */
@@ -210,12 +210,8 @@ socreate(int dom, struct socket **aso, i
int
sobind(struct socket *so, struct mbuf *nam, struct proc *p)
{
- int error;
-
soassertlocked(so);
-
- error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, NULL, nam, NULL, p);
- return (error);
+ return pru_bind(so, nam, p);
}
int
@@ -231,8 +227,7 @@ solisten(struct socket *so, int backlog)
if (isspliced(so) || issplicedback(so))
return (EOPNOTSUPP);
#endif /* SOCKET_SPLICE */
- error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, NULL, NULL, NULL,
- curproc);
+ error = pru_listen(so);
if (error)
return (error);
if (TAILQ_FIRST(&so->so_q) == NULL)
@@ -392,8 +387,7 @@ soclose(struct socket *so, int flags)
drop:
if (so->so_pcb) {
int error2;
- KASSERT(so->so_proto->pr_detach);
- error2 = (*so->so_proto->pr_detach)(so);
+ error2 = pru_detach(so);
if (error == 0)
error = error2;
}
@@ -444,8 +438,7 @@ soabort(struct socket *so)
{
soassertlocked(so);
- return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, NULL, NULL, NULL,
- curproc);
+ return pru_abort(so);
}
int
@@ -460,8 +453,7 @@ soaccept(struct socket *so, struct mbuf
so->so_state &= ~SS_NOFDREF;
if ((so->so_state & SS_ISDISCONNECTED) == 0 ||
(so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0)
- error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, NULL,
- nam, NULL, curproc);
+ error = pru_accept(so, nam);
else
error = ECONNABORTED;
return (error);
@@ -487,8 +479,7 @@ soconnect(struct socket *so, struct mbuf
(error = sodisconnect(so))))
error = EISCONN;
else
- error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT,
- NULL, nam, NULL, curproc);
+ error = pru_connect(so, nam);
return (error);
}
@@ -502,8 +493,7 @@ soconnect2(struct socket *so1, struct so
else
solock(so1);
- error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, NULL,
- (struct mbuf *)so2, NULL, curproc);
+ error = pru_connect2(so1, so2);
if (persocket)
sounlock(so2);
@@ -522,8 +512,7 @@ sodisconnect(struct socket *so)
return (ENOTCONN);
if (so->so_state & SS_ISDISCONNECTING)
return (EALREADY);
- error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, NULL, NULL,
- NULL, curproc);
+ error = pru_disconnect(so);
return (error);
}
@@ -654,9 +643,10 @@ restart:
so->so_state &= ~SS_ISSENDING;
if (top && so->so_options & SO_ZEROIZE)
top->m_flags |= M_ZEROIZE;
- error = (*so->so_proto->pr_usrreq)(so,
- (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,
- top, addr, control, curproc);
+ if (flags & MSG_OOB)
+ error = pru_sendoob(so, top, addr, control);
+ else
+ error = pru_send(so, top, addr, control);
clen = 0;
control = NULL;
top = NULL;
@@ -819,8 +809,7 @@ soreceive(struct socket *so, struct mbuf
if (flags & MSG_OOB) {
m = m_get(M_WAIT, MT_DATA);
solock(so);
- error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m,
- (struct mbuf *)(long)(flags & MSG_PEEK), NULL, curproc);
+ error = pru_rcvoob(so, m, flags & MSG_PEEK);
sounlock(so);
if (error)
goto bad;
@@ -1170,8 +1159,7 @@ dontblock:
SBLASTRECORDCHK(&so->so_rcv, "soreceive 4");
SBLASTMBUFCHK(&so->so_rcv, "soreceive 4");
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
- (*pr->pr_usrreq)(so, PRU_RCVD, NULL,
- (struct mbuf *)(long)flags, NULL, curproc);
+ pru_rcvd(so, flags);
}
if (orig_resid == uio->uio_resid && orig_resid &&
(flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
@@ -1193,7 +1181,6 @@ release:
int
soshutdown(struct socket *so, int how)
{
- const struct protosw *pr = so->so_proto;
int error = 0;
solock(so);
@@ -1205,8 +1192,7 @@ soshutdown(struct socket *so, int how)
sorflush(so);
/* FALLTHROUGH */
case SHUT_WR:
- error = (*pr->pr_usrreq)(so, PRU_SHUTDOWN, NULL, NULL, NULL,
- curproc);
+ error = pru_shutdown(so);
break;
default:
error = EINVAL;
@@ -1310,7 +1296,7 @@ sosplice(struct socket *so, int fd, off_
if ((error = getsock(curproc, fd, &fp)) != 0)
return (error);
sosp = fp->f_data;
- if (sosp->so_proto->pr_usrreq != so->so_proto->pr_usrreq) {
+ if (sosp->so_proto->pr_usrreqs != so->so_proto->pr_usrreqs) {
error = EPROTONOSUPPORT;
goto frele;
}
@@ -1538,8 +1524,7 @@ somove(struct socket *so, int wait)
if (m == NULL) {
sbdroprecord(so, &so->so_rcv);
if (so->so_proto->pr_flags & PR_WANTRCVD && so->so_pcb)
- (so->so_proto->pr_usrreq)(so, PRU_RCVD, NULL,
- NULL, NULL, NULL);
+ pru_rcvd(so, 0);
goto nextpkt;
}
@@ -1645,8 +1630,7 @@ somove(struct socket *so, int wait)
/* Send window update to source peer as receive buffer has changed. */
if (so->so_proto->pr_flags & PR_WANTRCVD && so->so_pcb)
- (so->so_proto->pr_usrreq)(so, PRU_RCVD, NULL,
- NULL, NULL, NULL);
+ pru_rcvd(so, 0);
/* Receive buffer did shrink by len bytes, adjust oob. */
state = so->so_state;
@@ -1674,8 +1658,7 @@ somove(struct socket *so, int wait)
} else if (oobmark) {
o = m_split(m, oobmark, wait);
if (o) {
- error = (*sosp->so_proto->pr_usrreq)(sosp,
- PRU_SEND, m, NULL, NULL, NULL);
+ error = pru_send(sosp, m, NULL, NULL);
if (error) {
if (sosp->so_state & SS_CANTSENDMORE)
error = EPIPE;
@@ -1692,8 +1675,7 @@ somove(struct socket *so, int wait)
if (o) {
o->m_len = 1;
*mtod(o, caddr_t) = *mtod(m, caddr_t);
- error = (*sosp->so_proto->pr_usrreq)(sosp, PRU_SENDOOB,
- o, NULL, NULL, NULL);
+ error = pru_sendoob(sosp, o, NULL, NULL);
if (error) {
if (sosp->so_state & SS_CANTSENDMORE)
error = EPIPE;
@@ -1714,8 +1696,7 @@ somove(struct socket *so, int wait)
/* Append all remaining data to drain socket. */
if (so->so_rcv.sb_cc == 0 || maxreached)
sosp->so_state &= ~SS_ISSENDING;
- error = (*sosp->so_proto->pr_usrreq)(sosp, PRU_SEND, m, NULL, NULL,
- NULL);
+ error = pru_send(sosp, m, NULL, NULL);
if (error) {
if (sosp->so_state & SS_CANTSENDMORE)
error = EPIPE;
Index: sys/kern/uipc_socket2.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_socket2.c,v
retrieving revision 1.126
diff -u -p -r1.126 uipc_socket2.c
--- sys/kern/uipc_socket2.c 25 Jul 2022 07:28:22 -0000 1.126
+++ sys/kern/uipc_socket2.c 8 Aug 2022 12:42:41 -0000
@@ -238,7 +238,7 @@ sonewconn(struct socket *head, int conns
sounlock(head);
}
- error = (*so->so_proto->pr_attach)(so, 0);
+ error = pru_attach(so->so_proto, so, 0);
if (persocket) {
sounlock(so);
Index: sys/kern/uipc_syscalls.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.199
diff -u -p -r1.199 uipc_syscalls.c
--- sys/kern/uipc_syscalls.c 18 Jul 2022 04:42:37 -0000 1.199
+++ sys/kern/uipc_syscalls.c 8 Aug 2022 12:42:41 -0000
@@ -1100,7 +1100,7 @@ sys_getsockname(struct proc *p, void *v,
}
m = m_getclr(M_WAIT, MT_SONAME);
solock(so);
- error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, NULL, m, NULL, p);
+ error = pru_sockaddr(so, m);
sounlock(so);
if (error)
goto bad;
@@ -1147,7 +1147,7 @@ sys_getpeername(struct proc *p, void *v,
goto bad;
m = m_getclr(M_WAIT, MT_SONAME);
solock(so);
- error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, NULL, m, NULL, p);
+ error = pru_peeraddr(so, m);
sounlock(so);
if (error)
goto bad;
Index: sys/kern/uipc_usrreq.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
retrieving revision 1.167
diff -u -p -r1.167 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c 2 Jul 2022 11:49:23 -0000 1.167
+++ sys/kern/uipc_usrreq.c 8 Aug 2022 12:42:41 -0000
@@ -126,6 +126,12 @@ int unp_rights; /* [R] file descriptors
int unp_defer; /* [G] number of deferred fp to close by the GC task */
int unp_gcing; /* [G] GC task currently running */
+const struct pr_usrreqs uipc_usrreqs = {
+ .pru_usrreq = uipc_usrreq,
+ .pru_attach = uipc_attach,
+ .pru_detach = uipc_detach,
+};
+
void
unp_init(void)
{
Index: sys/net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.662
diff -u -p -r1.662 if.c
--- sys/net/if.c 6 Aug 2022 15:57:58 -0000 1.662
+++ sys/net/if.c 8 Aug 2022 12:42:41 -0000
@@ -2360,9 +2360,7 @@ forceup:
break;
/* FALLTHROUGH */
default:
- error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
- (struct mbuf *) cmd, (struct mbuf *) data,
- (struct mbuf *) ifp, p));
+ error = pru_control(so, cmd, data, ifp, p);
if (error != EOPNOTSUPP)
break;
switch (cmd) {
Index: sys/net/pfkeyv2.c
===================================================================
RCS file: /cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.234
diff -u -p -r1.234 pfkeyv2.c
--- sys/net/pfkeyv2.c 6 Jun 2022 14:45:41 -0000 1.234
+++ sys/net/pfkeyv2.c 8 Aug 2022 12:42:41 -0000
@@ -199,6 +199,12 @@ pfdatatopacket(void *data, int len, stru
return (0);
}
+const struct pr_usrreqs pfkeyv2_usrreqs = {
+ .pru_usrreq = pfkeyv2_usrreq,
+ .pru_attach = pfkeyv2_attach,
+ .pru_detach = pfkeyv2_detach,
+};
+
const struct protosw pfkeysw[] = {
{
.pr_type = SOCK_RAW,
@@ -206,9 +212,7 @@ const struct protosw pfkeysw[] = {
.pr_protocol = PF_KEY_V2,
.pr_flags = PR_ATOMIC | PR_ADDR,
.pr_output = pfkeyv2_output,
- .pr_usrreq = pfkeyv2_usrreq,
- .pr_attach = pfkeyv2_attach,
- .pr_detach = pfkeyv2_detach,
+ .pr_usrreqs = &pfkeyv2_usrreqs,
.pr_sysctl = pfkeyv2_sysctl,
}
};
Index: sys/net/rtsock.c
===================================================================
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.334
diff -u -p -r1.334 rtsock.c
--- sys/net/rtsock.c 28 Jun 2022 10:01:13 -0000 1.334
+++ sys/net/rtsock.c 8 Aug 2022 12:42:41 -0000
@@ -2401,6 +2401,12 @@ rt_setsource(unsigned int rtableid, stru
* Definitions of protocols supported in the ROUTE domain.
*/
+const struct pr_usrreqs route_usrreqs = {
+ .pru_usrreq = route_usrreq,
+ .pru_attach = route_attach,
+ .pru_detach = route_detach,
+};
+
const struct protosw routesw[] = {
{
.pr_type = SOCK_RAW,
@@ -2408,9 +2414,7 @@ const struct protosw routesw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR|PR_WANTRCVD,
.pr_output = route_output,
.pr_ctloutput = route_ctloutput,
- .pr_usrreq = route_usrreq,
- .pr_attach = route_attach,
- .pr_detach = route_detach,
+ .pr_usrreqs = &route_usrreqs,
.pr_init = route_prinit,
.pr_sysctl = sysctl_rtable
}
Index: sys/netinet/in_proto.c
===================================================================
RCS file: /cvs/src/sys/netinet/in_proto.c,v
retrieving revision 1.98
diff -u -p -r1.98 in_proto.c
--- sys/netinet/in_proto.c 25 Feb 2022 23:51:03 -0000 1.98
+++ sys/netinet/in_proto.c 8 Aug 2022 12:42:41 -0000
@@ -189,9 +189,7 @@ const struct protosw inetsw[] = {
.pr_input = udp_input,
.pr_ctlinput = udp_ctlinput,
.pr_ctloutput = ip_ctloutput,
- .pr_usrreq = udp_usrreq,
- .pr_attach = udp_attach,
- .pr_detach = udp_detach,
+ .pr_usrreqs = &udp_usrreqs,
.pr_init = udp_init,
.pr_sysctl = udp_sysctl
},
@@ -203,9 +201,7 @@ const struct protosw inetsw[] = {
.pr_input = tcp_input,
.pr_ctlinput = tcp_ctlinput,
.pr_ctloutput = tcp_ctloutput,
- .pr_usrreq = tcp_usrreq,
- .pr_attach = tcp_attach,
- .pr_detach = tcp_detach,
+ .pr_usrreqs = &tcp_usrreqs,
.pr_init = tcp_init,
.pr_slowtimo = tcp_slowtimo,
.pr_sysctl = tcp_sysctl
@@ -217,9 +213,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = rip_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
},
{
.pr_type = SOCK_RAW,
@@ -228,9 +222,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = icmp_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_init = icmp_init,
.pr_sysctl = icmp_sysctl
},
@@ -245,9 +237,7 @@ const struct protosw inetsw[] = {
.pr_input = ipip_input,
#endif
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = ipip_sysctl,
.pr_init = ipip_init
},
@@ -263,9 +253,7 @@ const struct protosw inetsw[] = {
.pr_input = ipip_input,
#endif
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq, /* XXX */
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs, /* XXX */
},
#endif
#if defined(MPLS) && NGIF > 0
@@ -275,9 +263,7 @@ const struct protosw inetsw[] = {
.pr_protocol = IPPROTO_MPLS,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = in_gif_input,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
},
#endif /* MPLS && GIF */
{
@@ -287,9 +273,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = igmp_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_init = igmp_init,
.pr_fasttimo = igmp_fasttimo,
.pr_slowtimo = igmp_slowtimo,
@@ -304,9 +288,7 @@ const struct protosw inetsw[] = {
.pr_input = ah46_input,
.pr_ctlinput = ah4_ctlinput,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = ah_sysctl
},
{
@@ -317,9 +299,7 @@ const struct protosw inetsw[] = {
.pr_input = esp46_input,
.pr_ctlinput = esp4_ctlinput,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = esp_sysctl
},
{
@@ -329,9 +309,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipcomp46_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = ipcomp_sysctl
},
#endif /* IPSEC */
@@ -343,9 +321,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = gre_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = gre_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &gre_usrreqs,
.pr_sysctl = gre_sysctl
},
#endif /* NGRE > 0 */
@@ -357,9 +333,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = carp_proto_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = carp_sysctl
},
#endif /* NCARP > 0 */
@@ -371,9 +345,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = pfsync_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = pfsync_sysctl
},
#endif /* NPFSYNC > 0 */
@@ -384,9 +356,7 @@ const struct protosw inetsw[] = {
.pr_protocol = IPPROTO_DIVERT,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = divert_usrreq,
- .pr_attach = divert_attach,
- .pr_detach = divert_detach,
+ .pr_usrreqs = &divert_usrreqs,
.pr_init = divert_init,
.pr_sysctl = divert_sysctl
},
@@ -399,9 +369,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ip_etherip_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_sysctl = etherip_sysctl
},
#endif /* NETHERIP */
@@ -412,9 +380,7 @@ const struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = rip_input,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq,
- .pr_attach = rip_attach,
- .pr_detach = rip_detach,
+ .pr_usrreqs = &rip_usrreqs,
.pr_init = rip_init
}
};
Index: sys/netinet/ip_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_divert.c,v
retrieving revision 1.68
diff -u -p -r1.68 ip_divert.c
--- sys/netinet/ip_divert.c 9 May 2022 19:33:46 -0000 1.68
+++ sys/netinet/ip_divert.c 8 Aug 2022 12:42:41 -0000
@@ -62,6 +62,12 @@ const struct sysctl_bounded_args divertc
{ DIVERTCTL_SENDSPACE, &divert_sendspace, 0, INT_MAX },
};
+const struct pr_usrreqs divert_usrreqs = {
+ .pru_usrreq = divert_usrreq,
+ .pru_attach = divert_attach,
+ .pru_detach = divert_detach,
+};
+
int divbhashsize = DIVERTHASHSIZE;
int divert_output(struct inpcb *, struct mbuf *, struct mbuf *,
Index: sys/netinet/ip_divert.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip_divert.h,v
retrieving revision 1.15
diff -u -p -r1.15 ip_divert.h
--- sys/netinet/ip_divert.h 5 May 2022 16:44:22 -0000 1.15
+++ sys/netinet/ip_divert.h 8 Aug 2022 12:42:41 -0000
@@ -65,6 +65,8 @@ divstat_inc(enum divstat_counters c)
extern struct inpcbtable divbtable;
+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);
Index: sys/netinet/ip_gre.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_gre.c,v
retrieving revision 1.74
diff -u -p -r1.74 ip_gre.c
--- sys/netinet/ip_gre.c 26 Jun 2022 15:50:21 -0000 1.74
+++ sys/netinet/ip_gre.c 8 Aug 2022 12:42:41 -0000
@@ -53,12 +53,19 @@
#include <netinet/in.h>
#include <netinet/ip.h>
+#include <netinet/ip_gre.h>
#include <netinet/ip_var.h>
#include <netinet/in_pcb.h>
#ifdef PIPEX
#include <net/pipex.h>
#endif
+
+const struct pr_usrreqs gre_usrreqs = {
+ .pru_usrreq = gre_usrreq,
+ .pru_attach = rip_attach,
+ .pru_detach = rip_detach,
+};
int
gre_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
Index: sys/netinet/ip_gre.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip_gre.h,v
retrieving revision 1.16
diff -u -p -r1.16 ip_gre.h
--- sys/netinet/ip_gre.h 25 Feb 2022 23:51:03 -0000 1.16
+++ sys/netinet/ip_gre.h 8 Aug 2022 12:42:41 -0000
@@ -53,6 +53,9 @@
}
#ifdef _KERNEL
+
+extern const struct pr_usrreqs gre_usrreqs;
+
int gre_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct
mbuf *, struct proc *);
#endif /* _KERNEL */
#endif /* _NETINET_IP_GRE_H_ */
Index: sys/netinet/ip_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip_var.h,v
retrieving revision 1.95
diff -u -p -r1.95 ip_var.h
--- sys/netinet/ip_var.h 4 Aug 2022 18:05:09 -0000 1.95
+++ sys/netinet/ip_var.h 8 Aug 2022 12:42:41 -0000
@@ -217,6 +217,8 @@ extern int ipmforwarding; /* enable mul
extern int ipmultipath; /* enable multipath routing */
extern int la_hold_total;
+extern const struct pr_usrreqs rip_usrreqs;
+
extern struct rttimer_queue ip_mtudisc_timeout_q;
extern struct pool ipqent_pool;
struct route;
Index: sys/netinet/raw_ip.c
===================================================================
RCS file: /cvs/src/sys/netinet/raw_ip.c,v
retrieving revision 1.129
diff -u -p -r1.129 raw_ip.c
--- sys/netinet/raw_ip.c 6 Aug 2022 15:57:59 -0000 1.129
+++ sys/netinet/raw_ip.c 8 Aug 2022 12:42:41 -0000
@@ -103,6 +103,12 @@ struct inpcbtable rawcbtable;
* Raw interface to IP protocol.
*/
+const struct pr_usrreqs rip_usrreqs = {
+ .pru_usrreq = rip_usrreq,
+ .pru_attach = rip_attach,
+ .pru_detach = rip_detach,
+};
+
/*
* Initialize raw connection block q.
*/
Index: sys/netinet/tcp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.183
diff -u -p -r1.183 tcp_usrreq.c
--- sys/netinet/tcp_usrreq.c 25 Feb 2022 23:51:03 -0000 1.183
+++ sys/netinet/tcp_usrreq.c 8 Aug 2022 12:42:41 -0000
@@ -110,6 +110,12 @@ u_int tcp_sendspace = TCP_SENDSPACE;
u_int tcp_recvspace = TCP_RECVSPACE;
u_int tcp_autorcvbuf_inc = 16 * 1024;
+const struct pr_usrreqs tcp_usrreqs = {
+ .pru_usrreq = tcp_usrreq,
+ .pru_attach = tcp_attach,
+ .pru_detach = tcp_detach,
+};
+
static int pr_slowhz = PR_SLOWHZ;
const struct sysctl_bounded_args tcpctl_vars[] = {
{ TCPCTL_SLOWHZ, &pr_slowhz, SYSCTL_INT_READONLY },
Index: sys/netinet/tcp_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_var.h,v
retrieving revision 1.139
diff -u -p -r1.139 tcp_var.h
--- sys/netinet/tcp_var.h 25 Feb 2022 23:51:03 -0000 1.139
+++ sys/netinet/tcp_var.h 8 Aug 2022 12:42:41 -0000
@@ -629,6 +629,7 @@ tcpstat_pkt(enum tcpstat_counters pcount
counters_pkt(tcpcounters, pcounter, bcounter, v);
}
+extern const struct pr_usrreqs tcp_usrreqs;
extern struct pool tcpcb_pool;
extern struct inpcbtable tcbtable; /* head of queue of active tcpcb's */
extern u_int32_t tcp_now; /* for RFC 1323 timestamps */
Index: sys/netinet/udp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.280
diff -u -p -r1.280 udp_usrreq.c
--- sys/netinet/udp_usrreq.c 6 Aug 2022 15:57:59 -0000 1.280
+++ sys/netinet/udp_usrreq.c 8 Aug 2022 12:42:41 -0000
@@ -122,6 +122,12 @@ u_int udp_sendspace = 9216; /* really m
u_int udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));
/* 40 1K datagrams */
+const struct pr_usrreqs udp_usrreqs = {
+ .pru_usrreq = udp_usrreq,
+ .pru_attach = udp_attach,
+ .pru_detach = udp_detach,
+};
+
const struct sysctl_bounded_args udpctl_vars[] = {
{ UDPCTL_CHECKSUM, &udpcksum, 0, 1 },
{ UDPCTL_RECVSPACE, &udp_recvspace, 0, INT_MAX },
Index: sys/netinet/udp_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/udp_var.h,v
retrieving revision 1.37
diff -u -p -r1.37 udp_var.h
--- sys/netinet/udp_var.h 25 Feb 2022 23:51:03 -0000 1.37
+++ sys/netinet/udp_var.h 8 Aug 2022 12:42:41 -0000
@@ -126,6 +126,8 @@ udpstat_inc(enum udpstat_counters c)
extern struct inpcbtable udbtable;
extern struct udpstat udpstat;
+extern const struct pr_usrreqs udp_usrreqs;
+
#ifdef INET6
void udp6_ctlinput(int, struct sockaddr *, u_int, void *);
#endif /* INET6 */
Index: sys/netinet6/in6_proto.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_proto.c,v
retrieving revision 1.109
diff -u -p -r1.109 in6_proto.c
--- sys/netinet6/in6_proto.c 25 Feb 2022 23:51:04 -0000 1.109
+++ sys/netinet6/in6_proto.c 8 Aug 2022 12:42:41 -0000
@@ -140,9 +140,7 @@ const struct protosw inet6sw[] = {
.pr_input = udp_input,
.pr_ctlinput = udp6_ctlinput,
.pr_ctloutput = ip6_ctloutput,
- .pr_usrreq = udp_usrreq,
- .pr_attach = udp_attach,
- .pr_detach = udp_detach,
+ .pr_usrreqs = &udp_usrreqs,
.pr_sysctl = udp_sysctl
},
{
@@ -153,9 +151,7 @@ const struct protosw inet6sw[] = {
.pr_input = tcp_input,
.pr_ctlinput = tcp6_ctlinput,
.pr_ctloutput = tcp_ctloutput,
- .pr_usrreq = tcp_usrreq,
- .pr_attach = tcp_attach,
- .pr_detach = tcp_detach,
+ .pr_usrreqs = &tcp_usrreqs,
.pr_sysctl = tcp_sysctl
},
{
@@ -166,9 +162,7 @@ const struct protosw inet6sw[] = {
.pr_input = rip6_input,
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_sysctl = rip6_sysctl
},
{
@@ -179,9 +173,7 @@ const struct protosw inet6sw[] = {
.pr_input = icmp6_input,
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_init = icmp6_init,
.pr_fasttimo = icmp6_fasttimo,
.pr_sysctl = icmp6_sysctl
@@ -215,9 +207,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ah46_input,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_sysctl = ah_sysctl
},
{
@@ -227,9 +217,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = esp46_input,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_sysctl = esp_sysctl
},
{
@@ -239,9 +227,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipcomp46_input,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_sysctl = ipcomp_sysctl
},
#endif /* IPSEC */
@@ -256,9 +242,7 @@ const struct protosw inet6sw[] = {
.pr_input = ipip_input,
#endif
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq, /* XXX */
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs, /* XXX */
},
{
.pr_type = SOCK_RAW,
@@ -271,9 +255,7 @@ const struct protosw inet6sw[] = {
.pr_input = ipip_input,
#endif
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq, /* XXX */
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs, /* XXX */
},
#if defined(MPLS) && NGIF > 0
{
@@ -287,9 +269,7 @@ const struct protosw inet6sw[] = {
.pr_input = ipip_input,
#endif
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq, /* XXX */
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs, /* XXX */
},
#endif /* MPLS */
#if NCARP > 0
@@ -300,9 +280,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = carp6_proto_input,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_sysctl = carp_sysctl
},
#endif /* NCARP */
@@ -313,9 +291,7 @@ const struct protosw inet6sw[] = {
.pr_protocol = IPPROTO_DIVERT,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = divert6_usrreq,
- .pr_attach = divert6_attach,
- .pr_detach = divert6_detach,
+ .pr_usrreqs = &divert6_usrreqs,
.pr_init = divert6_init,
.pr_sysctl = divert6_sysctl
},
@@ -328,9 +304,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ip6_etherip_input,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
},
#endif /* NETHERIP */
#if NGRE > 0
@@ -341,9 +315,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = gre_input6,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
},
#endif /* NGRE */
{
@@ -353,9 +325,7 @@ const struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = rip6_input,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq,
- .pr_attach = rip6_attach,
- .pr_detach = rip6_detach,
+ .pr_usrreqs = &rip6_usrreqs,
.pr_init = rip6_init
}
};
Index: sys/netinet6/ip6_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v
retrieving revision 1.67
diff -u -p -r1.67 ip6_divert.c
--- sys/netinet6/ip6_divert.c 9 May 2022 19:33:46 -0000 1.67
+++ sys/netinet6/ip6_divert.c 8 Aug 2022 12:42:41 -0000
@@ -63,6 +63,12 @@ const struct sysctl_bounded_args divert6
{ DIVERT6CTL_SENDSPACE, &divert6_sendspace, 0, INT_MAX },
};
+const struct pr_usrreqs divert6_usrreqs = {
+ .pru_usrreq = divert6_usrreq,
+ .pru_attach = divert6_attach,
+ .pru_detach = divert6_detach,
+};
+
int divb6hashsize = DIVERTHASHSIZE;
int divert6_output(struct inpcb *, struct mbuf *, struct mbuf *,
Index: sys/netinet6/ip6_divert.h
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_divert.h,v
retrieving revision 1.13
diff -u -p -r1.13 ip6_divert.h
--- sys/netinet6/ip6_divert.h 5 May 2022 16:44:22 -0000 1.13
+++ sys/netinet6/ip6_divert.h 8 Aug 2022 12:42:41 -0000
@@ -65,6 +65,8 @@ div6stat_inc(enum div6stat_counters c)
extern struct inpcbtable divb6table;
+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);
Index: sys/netinet6/ip6_var.h
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_var.h,v
retrieving revision 1.93
diff -u -p -r1.93 ip6_var.h
--- sys/netinet6/ip6_var.h 29 Jun 2022 22:45:24 -0000 1.93
+++ sys/netinet6/ip6_var.h 8 Aug 2022 12:42:41 -0000
@@ -297,6 +297,8 @@ extern int ip6_auto_linklocal;
#define IP6_SOIIKEY_LEN 16
extern uint8_t ip6_soiikey[IP6_SOIIKEY_LEN];
+extern const struct pr_usrreqs rip6_usrreqs;
+
struct in6pcb;
struct inpcb;
Index: sys/netinet6/raw_ip6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.148
diff -u -p -r1.148 raw_ip6.c
--- sys/netinet6/raw_ip6.c 6 Aug 2022 15:57:59 -0000 1.148
+++ sys/netinet6/raw_ip6.c 8 Aug 2022 12:42:41 -0000
@@ -105,6 +105,12 @@ struct inpcbtable rawin6pcbtable;
struct cpumem *rip6counters;
+const struct pr_usrreqs rip6_usrreqs = {
+ .pru_usrreq = rip6_usrreq,
+ .pru_attach = rip6_attach,
+ .pru_detach = rip6_detach,
+};
+
/*
* Initialize raw connection block queue.
*/
Index: sys/nfs/nfs_socket.c
===================================================================
RCS file: /cvs/src/sys/nfs/nfs_socket.c,v
retrieving revision 1.142
diff -u -p -r1.142 nfs_socket.c
--- sys/nfs/nfs_socket.c 6 Jun 2022 14:45:41 -0000 1.142
+++ sys/nfs/nfs_socket.c 8 Aug 2022 12:42:41 -0000
@@ -1177,11 +1177,9 @@ nfs_timer(void *arg)
nmp->nm_sent < nmp->nm_cwnd) &&
(m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))){
if ((nmp->nm_flag & NFSMNT_NOCONN) == 0)
- error = (*so->so_proto->pr_usrreq)(so, PRU_SEND,
- m, NULL, NULL, curproc);
+ error = pru_send(so, m, NULL, NULL);
else
- error = (*so->so_proto->pr_usrreq)(so, PRU_SEND,
- m, nmp->nm_nam, NULL, curproc);
+ error = pru_send(so, m, nmp->nm_nam, NULL);
if (error) {
if (NFSIGNORE_SOERROR(nmp->nm_soflags, error))
so->so_error = 0;
Index: sys/sys/protosw.h
===================================================================
RCS file: /cvs/src/sys/sys/protosw.h,v
retrieving revision 1.35
diff -u -p -r1.35 protosw.h
--- sys/sys/protosw.h 25 Feb 2022 23:51:04 -0000 1.35
+++ sys/sys/protosw.h 8 Aug 2022 12:42:41 -0000
@@ -59,6 +59,15 @@ struct socket;
struct domain;
struct proc;
+struct pr_usrreqs {
+ /* user request: see list below */
+ int (*pru_usrreq)(struct socket *, int, struct mbuf *,
+ struct mbuf *, struct mbuf *, struct proc *);
+
+ int (*pru_attach)(struct socket *, int);
+ int (*pru_detach)(struct socket *);
+};
+
struct protosw {
short pr_type; /* socket type used for */
const struct domain *pr_domain; /* domain protocol a member of */
@@ -76,14 +85,9 @@ struct protosw {
/* control output (from above) */
int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf *);
-/* user-protocol hook */
- /* user request: see list below */
- int (*pr_usrreq)(struct socket *, int, struct mbuf *,
- struct mbuf *, struct mbuf *, struct proc *);
-
- int (*pr_attach)(struct socket *, int);
- int (*pr_detach)(struct socket *);
-
+/* user-protocol hooks */
+ const struct pr_usrreqs *pr_usrreqs;
+
/* utility hooks */
void (*pr_init)(void); /* initialization hook */
void (*pr_fasttimo)(void); /* fast timeout (200ms) */
@@ -227,6 +231,11 @@ char *prcorequests[] = {
#endif
#ifdef _KERNEL
+
+#include <sys/socketvar.h>
+#include <sys/systm.h>
+
+struct ifnet;
struct sockaddr;
const struct protosw *pffindproto(int, int, int);
const struct protosw *pffindtype(int, int);
@@ -239,5 +248,133 @@ extern const struct protosw inetsw[];
extern u_char ip6_protox[];
extern const struct protosw inet6sw[];
#endif /* INET6 */
+
+static inline int
+pru_attach(const struct protosw *prp, struct socket *so, int proto)
+{
+ return (*prp->pr_usrreqs->pru_attach)(so, proto);
+}
+
+static inline int
+pru_detach(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreqs->pru_detach)(so);
+}
+
+static inline int
+pru_bind(struct socket *so, struct mbuf *nam, struct proc *p)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_BIND, NULL, nam, NULL, p);
+}
+
+static inline int
+pru_listen(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_LISTEN, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_connect(struct socket *so, struct mbuf *nam)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_CONNECT, NULL, nam, NULL, curproc);
+}
+
+static inline int
+pru_accept(struct socket *so, struct mbuf *nam)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_ACCEPT, NULL, nam, NULL, curproc);
+}
+
+static inline int
+pru_disconnect(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_DISCONNECT, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_shutdown(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_SHUTDOWN, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_rcvd(struct socket *so, int flags)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_RCVD, NULL, (struct mbuf *)(long)flags, NULL, curproc);
+}
+
+static inline int
+pru_send(struct socket *so, struct mbuf *top, struct mbuf *addr,
+ struct mbuf *control)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_SEND, top, addr, control, curproc);
+}
+
+static inline int
+pru_abort(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_ABORT, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_control(struct socket *so, u_long cmd, caddr_t data,
+ struct ifnet *ifp, struct proc *p)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_CONTROL, (struct mbuf *)cmd, (struct mbuf *)data,
+ (struct mbuf *)ifp, p);
+}
+
+static inline int
+pru_sense(struct socket *so, struct stat *ub)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_SENSE, (struct mbuf *)ub, NULL, NULL, curproc);
+}
+
+static inline int
+pru_rcvoob(struct socket *so, struct mbuf *m, int flags)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_RCVOOB, m, (struct mbuf *)(long)flags, NULL, curproc);
+}
+
+static inline int
+pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr,
+ struct mbuf *control)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_SENDOOB, top, addr, control, curproc);
+}
+
+static inline int
+pru_sockaddr(struct socket *so, struct mbuf *addr)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_SOCKADDR, NULL, addr, NULL, curproc);
+}
+
+static inline int
+pru_peeraddr(struct socket *so, struct mbuf *addr)
+{
+ return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
+ PRU_PEERADDR, NULL, addr, NULL, curproc);
+}
+
+static inline int
+pru_connect2(struct socket *so1, struct socket *so2)
+{
+ return (*so1->so_proto->pr_usrreqs->pru_usrreq)(so1,
+ PRU_CONNECT2, NULL, (struct mbuf *)so2, NULL, curproc);
+}
#endif
Index: sys/sys/socketvar.h
===================================================================
RCS file: /cvs/src/sys/sys/socketvar.h,v
retrieving revision 1.106
diff -u -p -r1.106 socketvar.h
--- sys/sys/socketvar.h 15 Jul 2022 17:20:24 -0000 1.106
+++ sys/sys/socketvar.h 8 Aug 2022 12:42:41 -0000
@@ -32,6 +32,9 @@
* @(#)socketvar.h 8.1 (Berkeley) 6/2/93
*/
+#ifndef _SYS_SOCKETVAR_H_
+#define _SYS_SOCKETVAR_H_
+
#include <sys/selinfo.h> /* for struct selinfo */
#include <sys/queue.h>
#include <sys/sigio.h> /* for struct sigio_ref */
@@ -370,3 +373,5 @@ void sbcheck(struct socket *, struct soc
#endif /* SOCKBUF_DEBUG */
#endif /* _KERNEL */
+
+#endif /* _SYS_SOCKETVAR_H_ */
Index: sys/sys/unpcb.h
===================================================================
RCS file: /cvs/src/sys/sys/unpcb.h,v
retrieving revision 1.26
diff -u -p -r1.26 unpcb.h
--- sys/sys/unpcb.h 1 Jul 2022 09:56:17 -0000 1.26
+++ sys/sys/unpcb.h 8 Aug 2022 12:42:41 -0000
@@ -107,6 +107,8 @@ struct fdpass {
int flags;
};
+extern const struct pr_usrreqs uipc_usrreqs;
+
int uipc_usrreq(struct socket *, int , struct mbuf *,
struct mbuf *, struct mbuf *, struct proc *);
int uipc_attach(struct socket *, int);