From: mvs Date: Mon, 15 Aug 2022 09:11:38 +0000 (+0000) Subject: Introduce 'pr_usrreqs' structure and move existing user-protocol X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7985bfd0a068dc874e13da550e9053a23be063a0;p=openbsd Introduce 'pr_usrreqs' structure and move existing user-protocol handlers into it. We want to split existing (*pr_usrreq)() to multiple short handlers for each PRU_ request as it was already done for PRU_ATTACH and PRU_DETACH. This is the preparation step, (*pr_usrreq)() split will be done with the following diffs. Based on reverted diff from guenther@. ok bluhm@ --- diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c index 01e07364c93..d6447bf9958 100644 --- a/sys/kern/uipc_proto.c +++ b/sys/kern/uipc_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_proto.c,v 1.23 2022/08/14 01:58:28 jsg Exp $ */ +/* $OpenBSD: uipc_proto.c,v 1.24 2022/08/15 09:11:38 mvs Exp $ */ /* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */ /*- @@ -48,27 +48,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, } }; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 1e6fac656a4..ae9ed7b9f23 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.282 2022/08/14 01:58:28 jsg Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.283 2022/08/15 09:11:38 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -170,7 +170,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 == NULL) return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); @@ -1294,7 +1294,7 @@ sosplice(struct socket *so, int fd, off_t max, struct timeval *tv) 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; } diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 0fb95eea8d3..55a2fc64bac 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.167 2022/07/02 11:49:23 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.168 2022/08/15 09:11:38 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -126,6 +126,12 @@ int unp_rights; /* [R] file descriptors in flight */ 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) { diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index c918b2f8fbc..ab2571e0acb 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.234 2022/06/06 14:45:41 claudio Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.235 2022/08/15 09:11:38 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -199,6 +199,12 @@ pfdatatopacket(void *data, int len, struct mbuf **packet) 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, } }; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index fde6ec78565..abc76b7d069 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.334 2022/06/28 10:01:13 bluhm Exp $ */ +/* $OpenBSD: rtsock.c,v 1.335 2022/08/15 09:11:38 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -2401,6 +2401,12 @@ rt_setsource(unsigned int rtableid, struct sockaddr *src) * 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 } diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 9a81ad184c7..c4087a7a993 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.98 2022/02/25 23:51:03 guenther Exp $ */ +/* $OpenBSD: in_proto.c,v 1.99 2022/08/15 09:11:38 mvs Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -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 } }; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index aae4ed62bea..f5825f554c3 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.68 2022/05/09 19:33:46 bluhm Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.69 2022/08/15 09:11:39 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -62,6 +62,12 @@ const struct sysctl_bounded_args divertctl_vars[] = { { 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 *, diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h index c9021274e96..f76dd4d1e23 100644 --- a/sys/netinet/ip_divert.h +++ b/sys/netinet/ip_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.h,v 1.15 2022/05/05 16:44:22 bluhm Exp $ */ +/* $OpenBSD: ip_divert.h,v 1.16 2022/08/15 09:11:39 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -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); diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 3e630221a18..ea73003f68d 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.74 2022/06/26 15:50:21 mvs Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.75 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -53,6 +53,7 @@ #include #include +#include #include #include @@ -60,6 +61,12 @@ #include #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, struct mbuf *control, struct proc *p) diff --git a/sys/netinet/ip_gre.h b/sys/netinet/ip_gre.h index 7645ae15cc2..7bef90b3b75 100644 --- a/sys/netinet/ip_gre.h +++ b/sys/netinet/ip_gre.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.h,v 1.16 2022/02/25 23:51:03 guenther Exp $ */ +/* $OpenBSD: ip_gre.h,v 1.17 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: ip_gre.h,v 1.3 1998/10/07 23:33:02 thorpej Exp $ */ /* @@ -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_ */ diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 43e0799bae3..68adea349d0 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.96 2022/08/12 14:49:15 bluhm Exp $ */ +/* $OpenBSD: ip_var.h,v 1.97 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -219,6 +219,8 @@ extern int ipmforwarding; /* enable multicast forwarding */ 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; diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index d5846ef0451..8758f3fa466 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.129 2022/08/06 15:57:59 bluhm Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.130 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -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. */ diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index d03efeb8bbf..8a4a8cbb02e 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.186 2022/08/13 19:13:45 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.187 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -111,6 +111,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 }, diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 29dcff81e0e..97213c6e0c7 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.140 2022/08/11 09:13:21 claudio Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.141 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -637,6 +637,7 @@ tcpstat_pkt(enum tcpstat_counters pcounter, enum tcpstat_counters bcounter, 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 */ diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index bf10be68923..0f7dcac974a 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.281 2022/08/08 12:06:30 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.282 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -122,6 +122,12 @@ u_int udp_sendspace = 9216; /* really max datagram size */ 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 }, diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 8042f407103..939068eb3bd 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.37 2022/02/25 23:51:03 guenther Exp $ */ +/* $OpenBSD: udp_var.h,v 1.38 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -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 */ diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 3e2675d8a1c..01da0ec2219 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.109 2022/02/25 23:51:04 guenther Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.110 2022/08/15 09:11:39 mvs Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -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 } }; diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index eb88105ea9a..6a02695e1ff 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.67 2022/05/09 19:33:46 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.68 2022/08/15 09:11:39 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -63,6 +63,12 @@ const struct sysctl_bounded_args divert6ctl_vars[] = { { 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 *, diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h index 709cc2aa315..cc8ea696813 100644 --- a/sys/netinet6/ip6_divert.h +++ b/sys/netinet6/ip6_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.h,v 1.13 2022/05/05 16:44:22 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.h,v 1.14 2022/08/15 09:11:39 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -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); diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index 021f7f04610..0fc60efe413 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.94 2022/08/12 14:49:15 bluhm Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.95 2022/08/15 09:11:39 mvs Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -300,6 +300,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; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 33bc726bc3f..93752793884 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.149 2022/08/08 12:06:31 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.150 2022/08/15 09:11:39 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -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. */ diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index af12315caaf..9fb80269c26 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.36 2022/08/13 21:01:46 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.37 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -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) */ @@ -248,61 +252,61 @@ extern const struct protosw inet6sw[]; static inline int pru_attach(struct socket *so, int proto) { - return (*so->so_proto->pr_attach)(so, proto); + return (*so->so_proto->pr_usrreqs->pru_attach)(so, proto); } static inline int pru_detach(struct socket *so) { - return (*so->so_proto->pr_detach)(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_usrreq)(so, + 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_usrreq)(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_usrreq)(so, + 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_usrreq)(so, + 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_usrreq)(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_usrreq)(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_usrreq)(so, + return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, PRU_RCVD, NULL, (struct mbuf *)(long)flags, NULL, curproc); } @@ -310,14 +314,14 @@ static inline int pru_send(struct socket *so, struct mbuf *top, struct mbuf *addr, struct mbuf *control) { - return (*so->so_proto->pr_usrreq)(so, + 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_usrreq)(so, + return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, PRU_ABORT, NULL, NULL, NULL, curproc); } @@ -325,7 +329,7 @@ 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_usrreq)(so, + return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, PRU_CONTROL, (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)ifp, p); } @@ -333,14 +337,14 @@ pru_control(struct socket *so, u_long cmd, caddr_t data, static inline int pru_sense(struct socket *so, struct stat *ub) { - return (*so->so_proto->pr_usrreq)(so, + 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_usrreq)(so, + return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, PRU_RCVOOB, m, (struct mbuf *)(long)flags, NULL, curproc); } @@ -348,28 +352,28 @@ static inline int pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr, struct mbuf *control) { - return (*so->so_proto->pr_usrreq)(so, + 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_usrreq)(so, + 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_usrreq)(so, + 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_usrreq)(so1, + return (*so1->so_proto->pr_usrreqs->pru_usrreq)(so1, PRU_CONNECT2, NULL, (struct mbuf *)so2, NULL, curproc); } diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index 54d083b6103..f16d236da19 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.26 2022/07/01 09:56:17 mvs Exp $ */ +/* $OpenBSD: unpcb.h,v 1.27 2022/08/15 09:11:39 mvs Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -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);