From: guenther Date: Fri, 25 Feb 2022 08:36:01 +0000 (+0000) Subject: Move pr_attach and pr_detach to a new structure pr_usrreqs that can X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=80ceac1983da55420b0737450ea0ed47b8271479;p=openbsd Move pr_attach and pr_detach to a new structure pr_usrreqs that can then be shared among protosw structures, following the same basic direction as NetBSD and FreeBSD for this. Split PRU_CONTROL out of pr_usrreq into pru_control, giving it the proper prototype to eliminate the previously necessary casts. ok mvs@ bluhm@ --- diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index 103ee79ca6a..e6cae385d4b 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_socket.c,v 1.47 2021/10/24 00:02:25 jsg Exp $ */ +/* $OpenBSD: sys_socket.c,v 1.48 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */ /* @@ -139,9 +139,11 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) } if (IOCGROUP(cmd) == 'r') return (EOPNOTSUPP); + if (so->so_proto->pr_usrreqs->pru_control == NULL) + return (EOPNOTSUPP); KERNEL_LOCK(); - error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, - (struct mbuf *)cmd, (struct mbuf *)data, NULL, p)); + error = ((*so->so_proto->pr_usrreqs->pru_control)(so, cmd, + data, NULL)); KERNEL_UNLOCK(); break; } diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c index 8ec85a32169..c0d9d6f989e 100644 --- a/sys/kern/uipc_proto.c +++ b/sys/kern/uipc_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_proto.c,v 1.20 2021/05/30 21:01:27 bluhm Exp $ */ +/* $OpenBSD: uipc_proto.c,v 1.21 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */ /*- @@ -51,8 +51,7 @@ const struct protosw unixsw[] = { .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, @@ -60,8 +59,7 @@ const struct protosw unixsw[] = { .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, @@ -69,8 +67,7 @@ const struct protosw unixsw[] = { .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, } }; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index d294b4df857..084f9c44edc 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.273 2022/02/16 13:16:10 visa Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.274 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -169,7 +169,7 @@ socreate(int dom, struct socket **aso, int type, int proto) prp = pffindproto(dom, proto, type); else prp = pffindtype(dom, type); - if (prp == NULL || prp->pr_attach == NULL) + if (prp == NULL || prp->pr_usrreqs->pru_attach == NULL) return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); @@ -192,7 +192,7 @@ socreate(int dom, struct socket **aso, int type, int proto) so->so_rcv.sb_timeo_nsecs = INFSLP; s = solock(so); - error = (*prp->pr_attach)(so, proto); + error = (*prp->pr_usrreqs->pru_attach)(so, proto); if (error) { so->so_state |= SS_NOFDREF; /* sofree() calls sounlock(). */ @@ -347,8 +347,8 @@ 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); + KASSERT(so->so_proto->pr_usrreqs->pru_detach != NULL); + error2 = (*so->so_proto->pr_usrreqs->pru_detach)(so); if (error == 0) error = error2; } diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index df28d6f10e8..df506fd5ada 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.118 2022/02/21 12:09:15 jsg Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.119 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -150,7 +150,7 @@ sonewconn(struct socket *head, int connstatus) /* * XXXSMP as long as `so' and `head' share the same lock, we - * can call soreserve() and pr_attach() below w/o explicitly + * can call soreserve() and pru_attach() below w/o explicitly * locking `so'. */ soassertlocked(head); @@ -194,7 +194,7 @@ sonewconn(struct socket *head, int connstatus) sigio_copy(&so->so_sigio, &head->so_sigio); soqinsque(head, so, soqueue); - if ((*so->so_proto->pr_attach)(so, 0)) { + if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0)) { (void) soqremque(so, soqueue); sigio_free(&so->so_sigio); klist_free(&so->so_rcv.sb_sel.si_note); diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index dbb1845358f..a25bda5a765 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.161 2021/12/29 07:15:13 anton Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.162 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -150,8 +150,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct socket *so2; int error = 0; - if (req == PRU_CONTROL) - return (EOPNOTSUPP); if (req != PRU_SEND && control && control->m_len) { error = EOPNOTSUPP; goto release; @@ -472,6 +470,11 @@ uipc_detach(struct socket *so) return (0); } +const struct pr_usrreqs uipc_usrreqs = { + .pru_attach = uipc_attach, + .pru_detach = uipc_detach, +}; + int uipc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) diff --git a/sys/net/if.c b/sys/net/if.c index 0bda92609c6..c7a3f6b1924 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.647 2022/01/07 16:39:18 deraadt Exp $ */ +/* $OpenBSD: if.c,v 1.648 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2258,11 +2258,12 @@ forceup: break; /* FALLTHROUGH */ default: - error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, - (struct mbuf *) cmd, (struct mbuf *) data, - (struct mbuf *) ifp, p)); - if (error != EOPNOTSUPP) - break; + if (so->so_proto->pr_usrreqs->pru_control != NULL) { + error = ((*so->so_proto->pr_usrreqs->pru_control)(so, + cmd, data, ifp)); + if (error != EOPNOTSUPP) + break; + } switch (cmd) { case SIOCAIFADDR: case SIOCDIFADDR: diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index b848dab990a..fc08630cfb6 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.229 2021/12/19 23:30:08 bluhm Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.230 2022/02/25 08:36:01 guenther Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -199,6 +199,11 @@ pfdatatopacket(void *data, int len, struct mbuf **packet) return (0); } +const struct pr_usrreqs pfkeyv2_usrreqs = { + .pru_attach = pfkeyv2_attach, + .pru_detach = pfkeyv2_detach, +}; + const struct protosw pfkeysw[] = { { .pr_type = SOCK_RAW, @@ -207,8 +212,7 @@ const struct protosw pfkeysw[] = { .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, } }; @@ -335,9 +339,6 @@ pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, struct pkpcb *kp; int error = 0; - if (req == PRU_CONTROL) - return (EOPNOTSUPP); - soassertlocked(so); if (control && control->m_len) { diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 0ff8dd87531..9a9d6f40c4b 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.324 2022/01/20 11:06:57 bluhm Exp $ */ +/* $OpenBSD: rtsock.c,v 1.325 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -214,9 +214,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct rtpcb *rop; int error = 0; - if (req == PRU_CONTROL) - return (EOPNOTSUPP); - soassertlocked(so); if (control && control->m_len) { @@ -2389,6 +2386,11 @@ rt_setsource(unsigned int rtableid, struct sockaddr *src) * Definitions of protocols supported in the ROUTE domain. */ +const struct pr_usrreqs route_usrreqs = { + .pru_attach = route_attach, + .pru_detach = route_detach, +}; + const struct protosw routesw[] = { { .pr_type = SOCK_RAW, @@ -2397,8 +2399,7 @@ const struct protosw routesw[] = { .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 } diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 8e55ded3c7b..15d63ac295f 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.96 2021/10/24 22:59:47 bluhm Exp $ */ +/* $OpenBSD: in_proto.c,v 1.97 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -190,8 +190,7 @@ const struct protosw inetsw[] = { .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 }, @@ -204,8 +203,7 @@ const struct protosw inetsw[] = { .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 @@ -218,8 +216,7 @@ const struct protosw inetsw[] = { .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, @@ -229,8 +226,7 @@ const struct protosw inetsw[] = { .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 }, @@ -246,8 +242,7 @@ const struct protosw inetsw[] = { #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 }, @@ -264,8 +259,7 @@ const struct protosw inetsw[] = { #endif .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, /* XXX */ - .pr_attach = rip_attach, - .pr_detach = rip_detach, + .pr_usrreqs = &rip_usrreqs, }, #endif #if defined(MPLS) && NGIF > 0 @@ -276,8 +270,7 @@ const struct protosw inetsw[] = { .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 */ { @@ -288,8 +281,7 @@ const struct protosw inetsw[] = { .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, @@ -305,8 +297,7 @@ const struct protosw inetsw[] = { .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 }, { @@ -318,8 +309,7 @@ const struct protosw inetsw[] = { .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 }, { @@ -330,8 +320,7 @@ const struct protosw inetsw[] = { .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 */ @@ -344,8 +333,7 @@ const struct protosw inetsw[] = { .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 */ @@ -358,8 +346,7 @@ const struct protosw inetsw[] = { .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 */ @@ -372,8 +359,7 @@ const struct protosw inetsw[] = { .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 */ @@ -385,8 +371,7 @@ const struct protosw inetsw[] = { .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 }, @@ -400,8 +385,7 @@ const struct protosw inetsw[] = { .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 */ @@ -413,8 +397,7 @@ const struct protosw inetsw[] = { .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 } }; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index dea2b6d4d1f..d99c6dde5be 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.64 2020/11/16 06:38:20 gnezdo Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.65 2022/02/25 08:36:01 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -41,6 +41,9 @@ #include +int divert_attach(struct socket *, int); +int divert_detach(struct socket *); + struct inpcbtable divbtable; struct cpumem *divcounters; @@ -243,11 +246,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp = sotoinpcb(so); int error = 0; - if (req == PRU_CONTROL) { - return (in_control(so, (u_long)m, (caddr_t)addr, - (struct ifnet *)control)); - } - soassertlocked(so); if (inp == NULL) { @@ -346,6 +344,12 @@ divert_detach(struct socket *so) return (0); } +const struct pr_usrreqs divert_usrreqs = { + .pru_attach = divert_attach, + .pru_detach = divert_detach, + .pru_control = in_control, +}; + int divert_sysctl_divstat(void *oldp, size_t *oldlenp, void *newp) { diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h index 8a6924e7147..3062c7eb72e 100644 --- a/sys/netinet/ip_divert.h +++ b/sys/netinet/ip_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.h,v 1.12 2020/08/24 16:00:31 gnezdo Exp $ */ +/* $OpenBSD: ip_divert.h,v 1.13 2022/02/25 08:36:01 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,7 +70,7 @@ int divert_packet(struct mbuf *, int, u_int16_t); int divert_sysctl(int *, u_int, void *, size_t *, void *, size_t); int divert_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -int divert_attach(struct socket *, int); -int divert_detach(struct socket *); + +extern const struct pr_usrreqs divert_usrreqs; #endif /* _KERNEL */ #endif /* _IP_DIVERT_H_ */ diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 147ab23ccea..0e7e2643931 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.71 2018/02/07 22:30:59 dlg Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.72 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -92,4 +92,9 @@ gre_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, #endif return rip_usrreq(so, req, m, nam, control, p); } + +const struct pr_usrreqs gre_usrreqs = { + .pru_attach = rip_attach, + .pru_detach = rip_detach, +}; #endif /* if NGRE > 0 */ diff --git a/sys/netinet/ip_gre.h b/sys/netinet/ip_gre.h index 8c5f742d145..033ca8684e7 100644 --- a/sys/netinet/ip_gre.h +++ b/sys/netinet/ip_gre.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.h,v 1.14 2019/11/04 23:52:28 dlg Exp $ */ +/* $OpenBSD: ip_gre.h,v 1.15 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: ip_gre.h,v 1.3 1998/10/07 23:33:02 thorpej Exp $ */ /* @@ -54,5 +54,7 @@ #ifdef _KERNEL int gre_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); + +extern const struct pr_usrreqs gre_usrreqs; #endif /* _KERNEL */ #endif /* _NETINET_IP_GRE_H_ */ diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index e2269e4892d..fb621024127 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.88 2021/03/30 08:37:11 sashan Exp $ */ +/* $OpenBSD: ip_var.h,v 1.89 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -261,6 +261,9 @@ int rip_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int rip_attach(struct socket *, int); int rip_detach(struct socket *); + +extern const struct pr_usrreqs rip_usrreqs; + #ifdef MROUTING extern struct socket *ip_mrouter[]; /* multicast routing daemon */ #endif diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 9e1c0d1df37..46724bb97cd 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.119 2019/02/04 21:40:52 bluhm Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.120 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -432,10 +432,6 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct inpcb *inp; int error = 0; - if (req == PRU_CONTROL) - return (in_control(so, (u_long)m, (caddr_t)nam, - (struct ifnet *)control)); - soassertlocked(so); inp = sotoinpcb(so); @@ -617,3 +613,9 @@ rip_detach(struct socket *so) return (0); } + +const struct pr_usrreqs rip_usrreqs = { + .pru_attach = rip_attach, + .pru_detach = rip_detach, + .pru_control = in_control, +}; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 98d2270d8f4..945b4299edb 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.181 2021/04/30 13:52:48 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.182 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -100,6 +100,9 @@ #include #endif +int tcp_attach(struct socket *, int); +int tcp_detach(struct socket *); + #ifndef TCP_SENDSPACE #define TCP_SENDSPACE 1024*16 #endif @@ -149,17 +152,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, int error = 0; short ostate; - if (req == PRU_CONTROL) { -#ifdef INET6 - if (sotopf(so) == PF_INET6) - return in6_control(so, (u_long)m, (caddr_t)nam, - (struct ifnet *)control); - else -#endif /* INET6 */ - return (in_control(so, (u_long)m, (caddr_t)nam, - (struct ifnet *)control)); - } - soassertlocked(so); if (control && control->m_len) { @@ -669,6 +661,19 @@ tcp_detach(struct socket *so) return (error); } +const struct pr_usrreqs tcp_usrreqs = { + .pru_attach = tcp_attach, + .pru_detach = tcp_detach, + .pru_control = in_control, +}; +#ifdef INET6 +const struct pr_usrreqs tcp6_usrreqs = { + .pru_attach = tcp_attach, + .pru_detach = tcp_detach, + .pru_control = in6_control, +}; +#endif + /* * Initiate (or continue) disconnect. * If embryonic state, just send reset (once). diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 22288cbe679..927ad2b3fcf 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.137 2022/01/23 21:44:31 bluhm Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.138 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -703,8 +703,6 @@ struct tcpcb * int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t); int tcp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -int tcp_attach(struct socket *, int); -int tcp_detach(struct socket *); void tcp_xmit_timer(struct tcpcb *, int); void tcpdropoldhalfopen(struct tcpcb *, u_int16_t); void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int); @@ -738,5 +736,10 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp, } #endif +extern const struct pr_usrreqs tcp_usrreqs; +#ifdef INET6 +extern const struct pr_usrreqs tcp6_usrreqs; +#endif + #endif /* _KERNEL */ #endif /* _NETINET_TCP_VAR_H_ */ diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 2b2bf9acbfb..3e2f2a1a34a 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.269 2022/02/16 01:25:45 dlg Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.270 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -112,6 +112,9 @@ #include #endif +int udp_attach(struct socket *, int); +int udp_detach(struct socket *); + /* * UDP protocol implementation. * Per RFC 768, August, 1980. @@ -1027,17 +1030,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp; int error = 0; - if (req == PRU_CONTROL) { -#ifdef INET6 - if (sotopf(so) == PF_INET6) - return (in6_control(so, (u_long)m, (caddr_t)addr, - (struct ifnet *)control)); - else -#endif /* INET6 */ - return (in_control(so, (u_long)m, (caddr_t)addr, - (struct ifnet *)control)); - } - soassertlocked(so); inp = sotoinpcb(so); @@ -1250,6 +1242,19 @@ udp_detach(struct socket *so) return (0); } +const struct pr_usrreqs udp_usrreqs = { + .pru_attach = udp_attach, + .pru_detach = udp_detach, + .pru_control = in_control, +}; +#ifdef INET6 +const struct pr_usrreqs udp6_usrreqs = { + .pru_attach = udp_attach, + .pru_detach = udp_detach, + .pru_control = in6_control, +}; +#endif + /* * Sysctl for udp variables. */ diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 337542a3f10..aa1eeba09c4 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.35 2020/08/22 17:54:57 gnezdo Exp $ */ +/* $OpenBSD: udp_var.h,v 1.36 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -139,7 +139,10 @@ int udp6_output(struct inpcb *, struct mbuf *, struct mbuf *, int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t); int udp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -int udp_attach(struct socket *, int); -int udp_detach(struct socket *); + +extern const struct pr_usrreqs udp_usrreqs; +#ifdef INET6 +extern const struct pr_usrreqs udp6_usrreqs; +#endif #endif /* _KERNEL */ #endif /* _NETINET_UDP_VAR_H_ */ diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 7945b95a4b9..8e523d13404 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.107 2022/02/22 01:35:41 guenther Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.108 2022/02/25 08:36:01 guenther Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -141,8 +141,7 @@ const struct protosw inet6sw[] = { .pr_ctlinput = udp6_ctlinput, .pr_ctloutput = ip6_ctloutput, .pr_usrreq = udp_usrreq, - .pr_attach = udp_attach, - .pr_detach = udp_detach, + .pr_usrreqs = &udp6_usrreqs, .pr_sysctl = udp_sysctl }, { @@ -154,8 +153,7 @@ const struct protosw inet6sw[] = { .pr_ctlinput = tcp6_ctlinput, .pr_ctloutput = tcp_ctloutput, .pr_usrreq = tcp_usrreq, - .pr_attach = tcp_attach, - .pr_detach = tcp_detach, + .pr_usrreqs = &tcp6_usrreqs, .pr_sysctl = tcp_sysctl }, { @@ -167,8 +165,7 @@ const struct protosw inet6sw[] = { .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 }, { @@ -180,8 +177,7 @@ const struct protosw inet6sw[] = { .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 @@ -216,8 +212,7 @@ const struct protosw inet6sw[] = { .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 }, { @@ -228,8 +223,7 @@ const struct protosw inet6sw[] = { .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 }, { @@ -240,8 +234,7 @@ const struct protosw inet6sw[] = { .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 */ @@ -257,8 +250,7 @@ const struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_attach = rip6_attach, - .pr_detach = rip6_detach, + .pr_usrreqs = &rip6_usrreqs, }, { .pr_type = SOCK_RAW, @@ -272,8 +264,7 @@ const struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_attach = rip6_attach, - .pr_detach = rip6_detach, + .pr_usrreqs = &rip6_usrreqs, }, #if defined(MPLS) && NGIF > 0 { @@ -288,8 +279,7 @@ const struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_attach = rip6_attach, - .pr_detach = rip6_detach, + .pr_usrreqs = &rip6_usrreqs, }, #endif /* MPLS */ #if NCARP > 0 @@ -301,8 +291,7 @@ const struct protosw inet6sw[] = { .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 */ @@ -314,8 +303,7 @@ const struct protosw inet6sw[] = { .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 }, @@ -329,8 +317,7 @@ const struct protosw inet6sw[] = { .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 @@ -342,8 +329,7 @@ const struct protosw inet6sw[] = { .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 */ { @@ -354,8 +340,7 @@ const struct protosw inet6sw[] = { .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 } }; diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 7a92eb2b928..fc83232dde1 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.63 2020/11/16 06:38:20 gnezdo Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.64 2022/02/25 08:36:01 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -42,6 +42,9 @@ #include +int divert6_attach(struct socket *, int); +int divert6_detach(struct socket *); + struct inpcbtable divb6table; struct cpumem *div6counters; @@ -248,11 +251,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp = sotoinpcb(so); int error = 0; - if (req == PRU_CONTROL) { - return (in6_control(so, (u_long)m, (caddr_t)addr, - (struct ifnet *)control)); - } - soassertlocked(so); if (inp == NULL) { @@ -352,6 +350,12 @@ divert6_detach(struct socket *so) return (0); } +const struct pr_usrreqs divert6_usrreqs = { + .pru_attach = divert6_attach, + .pru_detach = divert6_detach, + .pru_control = in6_control, +}; + int divert6_sysctl_div6stat(void *oldp, size_t *oldlenp, void *newp) { diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h index 8a463970485..51b524069b5 100644 --- a/sys/netinet6/ip6_divert.h +++ b/sys/netinet6/ip6_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.h,v 1.10 2020/08/24 16:00:31 gnezdo Exp $ */ +/* $OpenBSD: ip6_divert.h,v 1.11 2022/02/25 08:36:01 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,8 +70,8 @@ int divert6_packet(struct mbuf *, int, u_int16_t); int divert6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int divert6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -int divert6_attach(struct socket *, int); -int divert6_detach(struct socket *); + +extern const struct pr_usrreqs divert6_usrreqs; #endif /* _KERNEL */ #endif /* _IP6_DIVERT_H_ */ diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index 4b99f9e9f10..a3c86ef4519 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.89 2021/12/01 12:51:09 bluhm Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.90 2022/02/25 08:36:01 guenther Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -348,8 +348,6 @@ int rip6_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); int rip6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -int rip6_attach(struct socket *, int); -int rip6_detach(struct socket *); int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int dest6_input(struct mbuf **, int *, int, int); @@ -371,6 +369,8 @@ int ip6_output_ipsec_send(struct tdb *, struct mbuf *, struct route_in6 *, int, int); #endif /* IPSEC */ +extern const struct pr_usrreqs rip6_usrreqs; + #endif /* _KERNEL */ #endif /* !_NETINET6_IP6_VAR_H_ */ diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 193c575c4aa..5f31d59c8ca 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.139 2022/02/21 11:43:02 jsg Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.140 2022/02/25 08:36:01 guenther Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -97,6 +97,9 @@ #include +int rip6_attach(struct socket *, int); +int rip6_detach(struct socket *); + /* * Raw interface to IP6 protocol. */ @@ -559,10 +562,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct inpcb *in6p; int error = 0; - if (req == PRU_CONTROL) - return (in6_control(so, (u_long)m, (caddr_t)nam, - (struct ifnet *)control)); - soassertlocked(so); in6p = sotoinpcb(so); @@ -766,6 +765,12 @@ rip6_detach(struct socket *so) return (0); } +const struct pr_usrreqs rip6_usrreqs = { + .pru_attach = rip6_attach, + .pru_detach = rip6_detach, + .pru_control = in6_control, +}; + int rip6_sysctl_rip6stat(void *oldp, size_t *oldplen, void *newp) { diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index f578f6ae0ff..c7feca678e8 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.33 2022/02/22 01:02:57 guenther Exp $ */ +/* $OpenBSD: protosw.h,v 1.34 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -58,6 +58,7 @@ struct sockaddr; struct socket; struct domain; struct proc; +struct pr_usrreqs; struct protosw { short pr_type; /* socket type used for */ @@ -80,9 +81,7 @@ struct protosw { /* 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 *); + const struct pr_usrreqs *pr_usrreqs; /* utility hooks */ void (*pr_init)(void); /* initialization hook */ @@ -227,7 +226,15 @@ char *prcorequests[] = { #endif #ifdef _KERNEL -struct sockaddr; +struct ifnet; + +struct pr_usrreqs { + int (*pru_attach)(struct socket *, int _proto); + int (*pru_detach)(struct socket *); + int (*pru_control)(struct socket *, u_long _cmd, caddr_t _data, + struct ifnet *_ifp); +}; + const struct protosw *pffindproto(int, int, int); const struct protosw *pffindtype(int, int); void pfctlinput(int, struct sockaddr *); diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index b8afbb47514..156aa3c538c 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.23 2022/01/11 23:59:55 jsg Exp $ */ +/* $OpenBSD: unpcb.h,v 1.24 2022/02/25 08:36:01 guenther Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -120,4 +120,6 @@ void unp_shutdown(struct unpcb *); int unp_externalize(struct mbuf *, socklen_t, int); int unp_internalize(struct mbuf *, struct proc *); void unp_dispose(struct mbuf *); + +extern const struct pr_usrreqs uipc_usrreqs; #endif /* _KERNEL */