From 3f68dcd30ab7a3790e8f7af54ae2336112945c26 Mon Sep 17 00:00:00 2001 From: mvs Date: Fri, 2 Sep 2022 13:12:31 +0000 Subject: [PATCH] Move PRU_CONTROL request to (*pru_control)(). The 'proc *' arg is not used for PRU_CONTROL request, so remove it from pru_control() wrapper. Split out {tcp,udp}6_usrreqs from {tcp,udp}_usrreqs and use them for inet6 case. ok guenther@ bluhm@ --- sys/kern/sys_socket.c | 4 ++-- sys/kern/uipc_usrreq.c | 4 +--- sys/net/if.c | 4 ++-- sys/net/pfkeyv2.c | 5 +---- sys/net/rtsock.c | 5 +---- sys/netinet/ip_divert.c | 8 ++------ sys/netinet/ip_gre.c | 5 ++++- sys/netinet/raw_ip.c | 7 ++----- sys/netinet/tcp_usrreq.c | 35 +++++++++++++++++++++++------------ sys/netinet/tcp_var.h | 7 ++++++- sys/netinet/udp_usrreq.c | 29 +++++++++++++++++------------ sys/netinet/udp_var.h | 6 +++++- sys/netinet6/in6_proto.c | 6 +++--- sys/netinet6/ip6_divert.c | 8 ++------ sys/netinet6/raw_ip6.c | 7 ++----- sys/sys/protosw.h | 15 +++++++++------ 16 files changed, 82 insertions(+), 73 deletions(-) diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index 20b9913670f..e49f2910b6e 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_socket.c,v 1.53 2022/08/14 01:58:28 jsg Exp $ */ +/* $OpenBSD: sys_socket.c,v 1.54 2022/09/02 13:12:31 mvs Exp $ */ /* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */ /* @@ -137,7 +137,7 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) if (IOCGROUP(cmd) == 'r') return (EOPNOTSUPP); KERNEL_LOCK(); - error = pru_control(so, cmd, data, NULL, p); + error = pru_control(so, cmd, data, NULL); KERNEL_UNLOCK(); break; } diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index a85c60ff7a8..74d93f015df 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.182 2022/09/01 18:21:22 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.183 2022/09/02 13:12:31 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -219,8 +219,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; diff --git a/sys/net/if.c b/sys/net/if.c index c7045347c12..dc053ae24c3 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.663 2022/08/13 21:01:46 mvs Exp $ */ +/* $OpenBSD: if.c,v 1.664 2022/09/02 13:12:31 mvs Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2360,7 +2360,7 @@ forceup: break; /* FALLTHROUGH */ default: - error = pru_control(so, cmd, data, ifp, p); + error = pru_control(so, cmd, data, ifp); if (error != EOPNOTSUPP) break; switch (cmd) { diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index a384076d728..c03087fe459 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.249 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.250 2022/09/02 13:12:32 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -395,9 +395,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 ce8e46be628..867fc3e1a8f 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.350 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.351 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -220,9 +220,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) { diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index b5d6195df67..b03aa692ae3 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.83 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.84 2022/09/02 13:12:32 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,6 +70,7 @@ const struct pr_usrreqs divert_usrreqs = { .pru_shutdown = divert_shutdown, .pru_send = divert_send, .pru_abort = divert_abort, + .pru_control = in_control, }; int divbhashsize = DIVERTHASHSIZE; @@ -258,11 +259,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) { diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 588a51ff8cf..7407369d3c7 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.81 2022/08/28 18:44:16 mvs Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.82 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -56,6 +57,7 @@ #include #include #include +#include #ifdef PIPEX #include @@ -71,6 +73,7 @@ const struct pr_usrreqs gre_usrreqs = { .pru_shutdown = rip_shutdown, .pru_send = gre_send, .pru_abort = rip_abort, + .pru_control = in_control, }; int diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 58c3325d69c..bdc62075bf5 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.144 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.145 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -113,6 +113,7 @@ const struct pr_usrreqs rip_usrreqs = { .pru_shutdown = rip_shutdown, .pru_send = rip_send, .pru_abort = rip_abort, + .pru_control = in_control, }; /* @@ -464,10 +465,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); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 350eb598fd7..03c3b8e7b72 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.203 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.204 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -127,8 +127,30 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_sense = tcp_sense, .pru_rcvoob = tcp_rcvoob, .pru_sendoob = tcp_sendoob, + .pru_control = in_control, }; +#ifdef INET6 +const struct pr_usrreqs tcp6_usrreqs = { + .pru_usrreq = tcp_usrreq, + .pru_attach = tcp_attach, + .pru_detach = tcp_detach, + .pru_bind = tcp_bind, + .pru_listen = tcp_listen, + .pru_connect = tcp_connect, + .pru_accept = tcp_accept, + .pru_disconnect = tcp_disconnect, + .pru_shutdown = tcp_shutdown, + .pru_rcvd = tcp_rcvd, + .pru_send = tcp_send, + .pru_abort = tcp_abort, + .pru_sense = tcp_sense, + .pru_rcvoob = tcp_rcvoob, + .pru_sendoob = tcp_sendoob, + .pru_control = in6_control, +}; +#endif + static int pr_slowhz = PR_SLOWHZ; const struct sysctl_bounded_args tcpctl_vars[] = { { TCPCTL_SLOWHZ, &pr_slowhz, SYSCTL_INT_READONLY }, @@ -195,17 +217,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) { diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 4d10f7900b6..fa92c7d4066 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.153 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.154 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -639,6 +639,11 @@ tcpstat_pkt(enum tcpstat_counters pcounter, enum tcpstat_counters bcounter, } extern const struct pr_usrreqs tcp_usrreqs; + +#ifdef INET6 +extern const struct pr_usrreqs tcp6_usrreqs; +#endif + 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 02b74513a86..1864d0286c2 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.298 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.299 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -132,8 +132,24 @@ const struct pr_usrreqs udp_usrreqs = { .pru_shutdown = udp_shutdown, .pru_send = udp_send, .pru_abort = udp_abort, + .pru_control = in_control, }; +#ifdef INET6 +const struct pr_usrreqs udp6_usrreqs = { + .pru_usrreq = udp_usrreq, + .pru_attach = udp_attach, + .pru_detach = udp_detach, + .pru_bind = udp_bind, + .pru_connect = udp_connect, + .pru_disconnect = udp_disconnect, + .pru_shutdown = udp_shutdown, + .pru_send = udp_send, + .pru_abort = udp_abort, + .pru_control = in6_control, +}; +#endif + const struct sysctl_bounded_args udpctl_vars[] = { { UDPCTL_CHECKSUM, &udpcksum, 0, 1 }, { UDPCTL_RECVSPACE, &udp_recvspace, 0, INT_MAX }, @@ -1064,17 +1080,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); diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index a564b799fc0..fd7ce924b52 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.44 2022/08/28 18:44:16 mvs Exp $ */ +/* $OpenBSD: udp_var.h,v 1.45 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -128,6 +128,10 @@ extern struct udpstat udpstat; extern const struct pr_usrreqs udp_usrreqs; +#ifdef INET6 +extern const struct pr_usrreqs udp6_usrreqs; +#endif + #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 01da0ec2219..808422f6eab 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.110 2022/08/15 09:11:39 mvs Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.111 2022/09/02 13:12:32 mvs Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -140,7 +140,7 @@ const struct protosw inet6sw[] = { .pr_input = udp_input, .pr_ctlinput = udp6_ctlinput, .pr_ctloutput = ip6_ctloutput, - .pr_usrreqs = &udp_usrreqs, + .pr_usrreqs = &udp6_usrreqs, .pr_sysctl = udp_sysctl }, { @@ -151,7 +151,7 @@ const struct protosw inet6sw[] = { .pr_input = tcp_input, .pr_ctlinput = tcp6_ctlinput, .pr_ctloutput = tcp_ctloutput, - .pr_usrreqs = &tcp_usrreqs, + .pr_usrreqs = &tcp6_usrreqs, .pr_sysctl = tcp_sysctl }, { diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 8f1c4763f58..d1800b14c39 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.82 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.83 2022/09/02 13:12:32 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -71,6 +71,7 @@ const struct pr_usrreqs divert6_usrreqs = { .pru_shutdown = divert6_shutdown, .pru_send = divert6_send, .pru_abort = divert6_abort, + .pru_control = in6_control, }; int divb6hashsize = DIVERTHASHSIZE; @@ -264,11 +265,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) { diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 20b4032cc6c..0bae4da3a35 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.165 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.166 2022/09/02 13:12:32 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -115,6 +115,7 @@ const struct pr_usrreqs rip6_usrreqs = { .pru_shutdown = rip6_shutdown, .pru_send = rip6_send, .pru_abort = rip6_abort, + .pru_control = in6_control, }; /* @@ -580,10 +581,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); diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index c9e8bd43d08..7b7d54c371c 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.51 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.52 2022/09/02 13:12:32 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -59,6 +59,7 @@ struct socket; struct domain; struct proc; struct stat; +struct ifnet; struct pr_usrreqs { /* user request: see list below */ @@ -77,6 +78,8 @@ struct pr_usrreqs { int (*pru_send)(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int (*pru_abort)(struct socket *); + int (*pru_control)(struct socket *, u_long, caddr_t, + struct ifnet *); int (*pru_sense)(struct socket *, struct stat *); int (*pru_rcvoob)(struct socket *, struct mbuf *, int); int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, @@ -343,12 +346,12 @@ pru_abort(struct socket *so) } static inline int -pru_control(struct socket *so, u_long cmd, caddr_t data, - struct ifnet *ifp, struct proc *p) +pru_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_CONTROL, (struct mbuf *)cmd, (struct mbuf *)data, - (struct mbuf *)ifp, p); + if (so->so_proto->pr_usrreqs->pru_control) + return (*so->so_proto->pr_usrreqs->pru_control)(so, + cmd, data, ifp); + return (EOPNOTSUPP); } static inline int -- 2.20.1