From c3a3d6092d41859cf047929fddba8fb54e316416 Mon Sep 17 00:00:00 2001 From: mvs Date: Sat, 3 Sep 2022 22:43:38 +0000 Subject: [PATCH] Move PRU_PEERADDR request to (*pru_peeraddr)(). Introduce in{,6}_peeraddr() and use them for inet and inet6 sockets, except tcp(4) case. Also remove *_usrreq() handlers. ok bluhm@ --- sys/kern/uipc_usrreq.c | 57 +++++++------------------ sys/net/pfkeyv2.c | 45 ++++---------------- sys/net/rtsock.c | 55 ++++++------------------- sys/netinet/in_pcb.c | 13 +++++- sys/netinet/in_pcb.h | 4 +- sys/netinet/ip_divert.c | 43 +------------------ sys/netinet/ip_divert.h | 4 +- sys/netinet/ip_gre.c | 11 +---- sys/netinet/ip_var.h | 4 +- sys/netinet/raw_ip.c | 37 +---------------- sys/netinet/tcp_usrreq.c | 87 +++++++++++++-------------------------- sys/netinet/tcp_var.h | 5 +-- sys/netinet/udp_usrreq.c | 55 ++----------------------- sys/netinet/udp_var.h | 4 +- sys/netinet6/in6_pcb.c | 13 +++++- sys/netinet6/ip6_divert.c | 43 +------------------ sys/netinet6/ip6_divert.h | 4 +- sys/netinet6/ip6_var.h | 4 +- sys/netinet6/raw_ip6.c | 35 +--------------- sys/sys/protosw.h | 12 ++---- sys/sys/unpcb.h | 5 +-- 21 files changed, 115 insertions(+), 425 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 659b5f6d639..296d8500bf3 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.184 2022/09/03 18:48:49 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.185 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -127,7 +127,6 @@ 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, .pru_bind = uipc_bind, @@ -141,6 +140,7 @@ const struct pr_usrreqs uipc_usrreqs = { .pru_abort = uipc_abort, .pru_sense = uipc_sense, .pru_sockaddr = uipc_sockaddr, + .pru_peeraddr = uipc_peeraddr, .pru_connect2 = uipc_connect2, }; @@ -212,46 +212,6 @@ uipc_setaddr(const struct unpcb *unp, struct mbuf *nam) } } -int -uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control, struct proc *p) -{ - struct unpcb *unp = sotounpcb(so); - struct socket *so2; - int error = 0; - - if (req != PRU_SEND && control && control->m_len) { - error = EOPNOTSUPP; - goto release; - } - if (unp == NULL) { - error = EINVAL; - goto release; - } - - switch (req) { - - case PRU_PEERADDR: - so2 = unp_solock_peer(so); - uipc_setaddr(unp->unp_conn, nam); - if (so2 != NULL && so2 != so) - sounlock(so2); - break; - - case PRU_SLOWTIMO: - break; - - default: - panic("uipc_usrreq"); - } -release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - /* * Both send and receive buffers are allocated PIPSIZ bytes of buffering * for stream sockets, although the total for sender and receiver is @@ -585,6 +545,19 @@ uipc_sockaddr(struct socket *so, struct mbuf *nam) return (0); } +int +uipc_peeraddr(struct socket *so, struct mbuf *nam) +{ + struct unpcb *unp = sotounpcb(so); + struct socket *so2; + + so2 = unp_solock_peer(so); + uipc_setaddr(unp->unp_conn, nam); + if (so2 != NULL && so2 != so) + sounlock(so2); + return (0); +} + int uipc_connect2(struct socket *so, struct socket *so2) { diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index 93572667d86..b8f123a0802 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.251 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.252 2022/09/03 22:43:38 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -177,8 +177,7 @@ int pfkeyv2_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int pfkeyv2_abort(struct socket *); int pfkeyv2_sockaddr(struct socket *, struct mbuf *); -int pfkeyv2_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, - struct mbuf *, struct proc *); +int pfkeyv2_peeraddr(struct socket *, struct mbuf *); int pfkeyv2_output(struct mbuf *, struct socket *); int pfkey_sendup(struct pkpcb *, struct mbuf *, int); int pfkeyv2_sa_flush(struct tdb *, void *, int); @@ -205,7 +204,6 @@ pfdatatopacket(void *data, int len, struct mbuf **packet) } const struct pr_usrreqs pfkeyv2_usrreqs = { - .pru_usrreq = pfkeyv2_usrreq, .pru_attach = pfkeyv2_attach, .pru_detach = pfkeyv2_detach, .pru_disconnect = pfkeyv2_disconnect, @@ -213,6 +211,7 @@ const struct pr_usrreqs pfkeyv2_usrreqs = { .pru_send = pfkeyv2_send, .pru_abort = pfkeyv2_abort, .pru_sockaddr = pfkeyv2_sockaddr, + .pru_peeraddr = pfkeyv2_peeraddr, }; const struct protosw pfkeysw[] = { @@ -397,42 +396,12 @@ pfkeyv2_sockaddr(struct socket *so, struct mbuf *nam) } int -pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, - struct mbuf *nam, struct mbuf *control, struct proc *p) +pfkeyv2_peeraddr(struct socket *so, struct mbuf *nam) { - struct pkpcb *kp; - int error = 0; - - soassertlocked(so); - - if (control && control->m_len) { - error = EOPNOTSUPP; - goto release; - } - - kp = sotokeycb(so); - if (kp == NULL) { - error = EINVAL; - goto release; - } - - switch (req) { /* minimal support, just implement a fake peer address */ - case PRU_PEERADDR: - bcopy(&pfkey_addr, mtod(nam, caddr_t), pfkey_addr.sa_len); - nam->m_len = pfkey_addr.sa_len; - break; - - default: - panic("pfkeyv2_usrreq"); - } - - release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); + bcopy(&pfkey_addr, mtod(nam, caddr_t), pfkey_addr.sa_len); + nam->m_len = pfkey_addr.sa_len; + return (0); } int diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index c64efb5a815..2e31020c5c6 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.352 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.353 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -111,8 +111,6 @@ void rcb_ref(void *, void *); void rcb_unref(void *, void *); int route_output(struct mbuf *, struct socket *); int route_ctloutput(int, struct socket *, int, int, struct mbuf *); -int route_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, - struct mbuf *, struct proc *); int route_disconnect(struct socket *); int route_shutdown(struct socket *); int route_rcvd(struct socket *); @@ -120,6 +118,7 @@ int route_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int route_abort(struct socket *); int route_sockaddr(struct socket *, struct mbuf *); +int route_peeraddr(struct socket *, struct mbuf *); void route_input(struct mbuf *m0, struct socket *, sa_family_t); int route_arp_conflict(struct rtentry *, struct rt_addrinfo *); int route_cleargateway(struct rtentry *, void *, unsigned int); @@ -214,45 +213,6 @@ rcb_unref(void *null, void *v) refcnt_rele_wake(&rop->rop_refcnt); } -int -route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control, struct proc *p) -{ - struct rtpcb *rop; - int error = 0; - - soassertlocked(so); - - if (control && control->m_len) { - error = EOPNOTSUPP; - goto release; - } - - rop = sotortpcb(so); - if (rop == NULL) { - error = EINVAL; - goto release; - } - - switch (req) { - /* minimal support, just implement a fake peer address */ - case PRU_PEERADDR: - bcopy(&route_src, mtod(nam, caddr_t), route_src.sa_len); - nam->m_len = route_src.sa_len; - break; - - default: - panic("route_usrreq"); - } - - release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - int route_attach(struct socket *so, int proto) { @@ -397,6 +357,15 @@ route_sockaddr(struct socket *so, struct mbuf *nam) return (EINVAL); } +int +route_peeraddr(struct socket *so, struct mbuf *nam) +{ + /* minimal support, just implement a fake peer address */ + bcopy(&route_src, mtod(nam, caddr_t), route_src.sa_len); + nam->m_len = route_src.sa_len; + return (0); +} + int route_ctloutput(int op, struct socket *so, int level, int optname, struct mbuf *m) @@ -2431,7 +2400,6 @@ rt_setsource(unsigned int rtableid, struct sockaddr *src) */ const struct pr_usrreqs route_usrreqs = { - .pru_usrreq = route_usrreq, .pru_attach = route_attach, .pru_detach = route_detach, .pru_disconnect = route_disconnect, @@ -2440,6 +2408,7 @@ const struct pr_usrreqs route_usrreqs = { .pru_send = route_send, .pru_abort = route_abort, .pru_sockaddr = route_sockaddr, + .pru_peeraddr = route_peeraddr, }; const struct protosw routesw[] = { diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 49b19ebc03f..e7d59873e7e 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.274 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.275 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -676,6 +676,17 @@ in_sockaddr(struct socket *so, struct mbuf *nam) return (0); } +int +in_peeraddr(struct socket *so, struct mbuf *nam) +{ + struct inpcb *inp; + + inp = sotoinpcb(so); + in_setpeeraddr(inp, nam); + + return (0); +} + /* * Pass some notification to all connections of a protocol * associated with address dst. The "usual action" will be diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 9139c8b7e81..a89a963ff8b 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.133 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.134 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -309,6 +309,7 @@ int in6_pcbconnect(struct inpcb *, struct mbuf *); void in6_setsockaddr(struct inpcb *, struct mbuf *); void in6_setpeeraddr(struct inpcb *, struct mbuf *); int in6_sockaddr(struct socket *, struct mbuf *); +int in6_peeraddr(struct socket *, struct mbuf *); #endif /* INET6 */ void in_pcbinit(struct inpcbtable *, int); struct inpcb * @@ -320,6 +321,7 @@ void in_rtchange(struct inpcb *, int); void in_setpeeraddr(struct inpcb *, struct mbuf *); void in_setsockaddr(struct inpcb *, struct mbuf *); int in_sockaddr(struct socket *, struct mbuf *); +int in_peeraddr(struct socket *, struct mbuf *); int in_baddynamic(u_int16_t, u_int16_t); int in_rootonly(u_int16_t, u_int16_t); int in_pcbselsrc(struct in_addr *, struct sockaddr_in *, struct inpcb *); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 263175597e1..361d00c4ea4 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.85 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.86 2022/09/03 22:43:38 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -63,7 +63,6 @@ const struct sysctl_bounded_args divertctl_vars[] = { }; const struct pr_usrreqs divert_usrreqs = { - .pru_usrreq = divert_usrreq, .pru_attach = divert_attach, .pru_detach = divert_detach, .pru_bind = divert_bind, @@ -72,6 +71,7 @@ const struct pr_usrreqs divert_usrreqs = { .pru_abort = divert_abort, .pru_control = in_control, .pru_sockaddr = in_sockaddr, + .pru_peeraddr = in_peeraddr, }; int divbhashsize = DIVERTHASHSIZE; @@ -252,45 +252,6 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port) m_freem(m); } -/*ARGSUSED*/ -int -divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, - struct mbuf *control, struct proc *p) -{ - struct inpcb *inp = sotoinpcb(so); - int error = 0; - - soassertlocked(so); - - if (inp == NULL) { - error = EINVAL; - goto release; - } - switch (req) { - - case PRU_PEERADDR: - in_setpeeraddr(inp, addr); - break; - - case PRU_FASTTIMO: - case PRU_SLOWTIMO: - case PRU_PROTORCV: - case PRU_PROTOSEND: - error = EOPNOTSUPP; - break; - - default: - panic("divert_usrreq"); - } - -release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - int divert_attach(struct socket *so, int proto) { diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h index 004047b9403..d5e4dabf631 100644 --- a/sys/netinet/ip_divert.h +++ b/sys/netinet/ip_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.h,v 1.20 2022/08/28 18:44:16 mvs Exp $ */ +/* $OpenBSD: ip_divert.h,v 1.21 2022/09/03 22:43:38 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,8 +70,6 @@ extern const struct pr_usrreqs divert_usrreqs; void divert_init(void); void divert_packet(struct mbuf *, int, u_int16_t); int divert_sysctl(int *, u_int, void *, size_t *, void *, size_t); -int divert_usrreq(struct socket *, - int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int divert_attach(struct socket *, int); int divert_detach(struct socket *); int divert_bind(struct socket *, struct mbuf *, struct proc *); diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 7a9db85f35e..eb89d8b7cb1 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.83 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.84 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -64,7 +64,6 @@ #endif const struct pr_usrreqs gre_usrreqs = { - .pru_usrreq = gre_usrreq, .pru_attach = rip_attach, .pru_detach = rip_detach, .pru_bind = rip_bind, @@ -75,15 +74,9 @@ const struct pr_usrreqs gre_usrreqs = { .pru_abort = rip_abort, .pru_control = in_control, .pru_sockaddr = in_sockaddr, + .pru_peeraddr = in_peeraddr, }; -int -gre_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control, struct proc *p) -{ - return rip_usrreq(so, req, m, nam, control, p); -} - int gre_send(struct socket *so, struct mbuf *m, struct mbuf *nam, struct mbuf *control) diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 89a53ccd43e..0e9402139be 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.103 2022/08/28 18:44:16 mvs Exp $ */ +/* $OpenBSD: ip_var.h,v 1.104 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -256,8 +256,6 @@ void rip_init(void); int rip_input(struct mbuf **, int *, int, int); int rip_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); -int rip_usrreq(struct socket *, - int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int rip_attach(struct socket *, int); int rip_detach(struct socket *); int rip_bind(struct socket *so, struct mbuf *, struct proc *); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 162e16ec47e..cc449212770 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.146 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.147 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -104,7 +104,6 @@ struct inpcbtable rawcbtable; */ const struct pr_usrreqs rip_usrreqs = { - .pru_usrreq = rip_usrreq, .pru_attach = rip_attach, .pru_detach = rip_detach, .pru_bind = rip_bind, @@ -115,6 +114,7 @@ const struct pr_usrreqs rip_usrreqs = { .pru_abort = rip_abort, .pru_control = in_control, .pru_sockaddr = in_sockaddr, + .pru_peeraddr = in_peeraddr, }; /* @@ -458,39 +458,6 @@ rip_ctloutput(int op, struct socket *so, int level, int optname, u_long rip_sendspace = RIPSNDQ; u_long rip_recvspace = RIPRCVQ; -/*ARGSUSED*/ -int -rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control, struct proc *p) -{ - struct inpcb *inp; - int error = 0; - - soassertlocked(so); - - inp = sotoinpcb(so); - if (inp == NULL) { - error = EINVAL; - goto release; - } - - switch (req) { - - case PRU_PEERADDR: - in_setpeeraddr(inp, nam); - break; - - default: - panic("rip_usrreq"); - } -release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - int rip_attach(struct socket *so, int proto) { diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 5630404e576..0edab7d6a7f 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.206 2022/09/03 19:22:19 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.207 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -112,7 +112,6 @@ 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, .pru_bind = tcp_bind, @@ -129,11 +128,11 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_sendoob = tcp_sendoob, .pru_control = in_control, .pru_sockaddr = tcp_sockaddr, + .pru_peeraddr = tcp_peeraddr, }; #ifdef INET6 const struct pr_usrreqs tcp6_usrreqs = { - .pru_usrreq = tcp_usrreq, .pru_attach = tcp_attach, .pru_detach = tcp_detach, .pru_bind = tcp_bind, @@ -150,6 +149,7 @@ const struct pr_usrreqs tcp6_usrreqs = { .pru_sendoob = tcp_sendoob, .pru_control = in6_control, .pru_sockaddr = tcp_sockaddr, + .pru_peeraddr = tcp_peeraddr, }; #endif @@ -204,62 +204,6 @@ tcp_sogetpcb(struct socket *so, struct inpcb **rinp, struct tcpcb **rtp) return 0; } -/* - * Process a TCP user request for TCP tb. If this is a send request - * then m is the mbuf chain of send data. If this is a timer expiration - * (called from the software clock routine), then timertype tells which timer. - */ -/*ARGSUSED*/ -int -tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control, struct proc *p) -{ - struct inpcb *inp; - struct tcpcb *otp = NULL, *tp; - int error = 0; - short ostate; - - soassertlocked(so); - - if (control && control->m_len) { - error = EINVAL; - goto release; - } - - if ((error = tcp_sogetpcb(so, &inp, &tp))) - goto release; - - if (so->so_options & SO_DEBUG) { - otp = tp; - ostate = tp->t_state; - } - - switch (req) { - - case PRU_PEERADDR: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setpeeraddr(inp, nam); - else -#endif - in_setpeeraddr(inp, nam); - break; - - default: - panic("tcp_usrreq"); - } - if (otp) - tcp_trace(TA_USER, ostate, tp, otp, NULL, req, 0); - return (error); - - release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - /* * Export internal TCP state information via a struct tcp_info without * leaking any sensitive information. Sequence numbers are reported @@ -1078,6 +1022,31 @@ tcp_sockaddr(struct socket *so, struct mbuf *nam) return (0); } +int +tcp_peeraddr(struct socket *so, struct mbuf *nam) +{ + struct inpcb *inp; + struct tcpcb *tp; + int error; + + soassertlocked(so); + + if ((error = tcp_sogetpcb(so, &inp, &tp))) + return (error); + +#ifdef INET6 + if (inp->inp_flags & INP_IPV6) + in6_setpeeraddr(inp, nam); + else +#endif + in_setpeeraddr(inp, nam); + + if (so->so_options & SO_DEBUG) + tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, + PRU_PEERADDR, 0); + return (0); +} + /* * 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 d7d643b9aa9..cd6bb75fc5c 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.156 2022/09/03 19:22:19 bluhm Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.157 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -717,8 +717,6 @@ void tcp_trace(short, short, struct tcpcb *, struct tcpcb *, caddr_t, struct tcpcb * tcp_usrclosed(struct tcpcb *); int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t); -int tcp_usrreq(struct socket *, - int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int tcp_attach(struct socket *, int); int tcp_detach(struct socket *); int tcp_bind(struct socket *, struct mbuf *, struct proc *); @@ -732,6 +730,7 @@ int tcp_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int tcp_abort(struct socket *); int tcp_sockaddr(struct socket *, struct mbuf *); +int tcp_peeraddr(struct socket *, struct mbuf *); int tcp_sense(struct socket *, struct stat *); int tcp_rcvoob(struct socket *, struct mbuf *, int); int tcp_sendoob(struct socket *, struct mbuf *, struct mbuf *, diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 44591b2c6ba..21440ab3a2c 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.300 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.301 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -123,7 +123,6 @@ 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, .pru_bind = udp_bind, @@ -134,11 +133,11 @@ const struct pr_usrreqs udp_usrreqs = { .pru_abort = udp_abort, .pru_control = in_control, .pru_sockaddr = in_sockaddr, + .pru_peeraddr = in_peeraddr, }; #ifdef INET6 const struct pr_usrreqs udp6_usrreqs = { - .pru_usrreq = udp_usrreq, .pru_attach = udp_attach, .pru_detach = udp_detach, .pru_bind = udp_bind, @@ -149,6 +148,7 @@ const struct pr_usrreqs udp6_usrreqs = { .pru_abort = udp_abort, .pru_control = in6_control, .pru_sockaddr = in6_sockaddr, + .pru_peeraddr = in6_peeraddr, }; #endif @@ -1074,55 +1074,6 @@ release: goto bail; } -/*ARGSUSED*/ -int -udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, - struct mbuf *control, struct proc *p) -{ - struct inpcb *inp; - int error = 0; - - soassertlocked(so); - - inp = sotoinpcb(so); - if (inp == NULL) { - error = EINVAL; - goto release; - } - - /* - * Note: need to block udp_input while changing - * the udp pcb queue and/or pcb addresses. - */ - switch (req) { - - case PRU_PEERADDR: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setpeeraddr(inp, addr); - else -#endif /* INET6 */ - in_setpeeraddr(inp, addr); - break; - - case PRU_FASTTIMO: - case PRU_SLOWTIMO: - case PRU_PROTORCV: - case PRU_PROTOSEND: - error = EOPNOTSUPP; - break; - - default: - panic("udp_usrreq"); - } -release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - int udp_attach(struct socket *so, int proto) { diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index fd7ce924b52..79fdfeed540 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.45 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: udp_var.h,v 1.46 2022/09/03 22:43:38 mvs Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -143,8 +143,6 @@ int udp6_output(struct inpcb *, struct mbuf *, struct mbuf *, struct mbuf *); #endif /* INET6 */ int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t); -int udp_usrreq(struct socket *, - int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int udp_attach(struct socket *, int); int udp_detach(struct socket *); int udp_bind(struct socket *, struct mbuf *, struct proc *); diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 5410149d4ab..1e17ada3257 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.122 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.123 2022/09/03 22:43:38 mvs Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -376,6 +376,17 @@ in6_sockaddr(struct socket *so, struct mbuf *nam) return (0); } +int +in6_peeraddr(struct socket *so, struct mbuf *nam) +{ + struct inpcb *in6p; + + in6p = sotoinpcb(so); + in6_setpeeraddr(in6p, nam); + + return (0); +} + /* * Pass some notification to all connections of a protocol * associated with address dst. The local address and/or port numbers diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 892f7fd033d..706d5b9f3b9 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.84 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.85 2022/09/03 22:43:38 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -64,7 +64,6 @@ const struct sysctl_bounded_args divert6ctl_vars[] = { }; const struct pr_usrreqs divert6_usrreqs = { - .pru_usrreq = divert6_usrreq, .pru_attach = divert6_attach, .pru_detach = divert6_detach, .pru_bind = divert6_bind, @@ -73,6 +72,7 @@ const struct pr_usrreqs divert6_usrreqs = { .pru_abort = divert6_abort, .pru_control = in6_control, .pru_sockaddr = in6_sockaddr, + .pru_peeraddr = in6_peeraddr, }; int divb6hashsize = DIVERTHASHSIZE; @@ -258,45 +258,6 @@ divert6_packet(struct mbuf *m, int dir, u_int16_t divert_port) m_freem(m); } -/*ARGSUSED*/ -int -divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, - struct mbuf *control, struct proc *p) -{ - struct inpcb *inp = sotoinpcb(so); - int error = 0; - - soassertlocked(so); - - if (inp == NULL) { - error = EINVAL; - goto release; - } - switch (req) { - - case PRU_PEERADDR: - in6_setpeeraddr(inp, addr); - break; - - case PRU_FASTTIMO: - case PRU_SLOWTIMO: - case PRU_PROTORCV: - case PRU_PROTOSEND: - error = EOPNOTSUPP; - break; - - default: - panic("%s", __func__); - } - -release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - int divert6_attach(struct socket *so, int proto) { diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h index 21884ac948e..d76c123e15c 100644 --- a/sys/netinet6/ip6_divert.h +++ b/sys/netinet6/ip6_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.h,v 1.18 2022/08/28 18:44:17 mvs Exp $ */ +/* $OpenBSD: ip6_divert.h,v 1.19 2022/09/03 22:43:38 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,8 +70,6 @@ extern const struct pr_usrreqs divert6_usrreqs; void divert6_init(void); void divert6_packet(struct mbuf *, int, u_int16_t); int divert6_sysctl(int *, u_int, void *, size_t *, void *, size_t); -int divert6_usrreq(struct socket *, - int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int divert6_attach(struct socket *, int); int divert6_detach(struct socket *); int divert6_bind(struct socket *, struct mbuf *, struct proc *); diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index ee560a02273..f501eb023c8 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.101 2022/08/28 18:44:17 mvs Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.102 2022/09/03 22:43:38 mvs Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -351,8 +351,6 @@ void rip6_ctlinput(int, struct sockaddr *, u_int, void *); int rip6_ctloutput(int, struct socket *, int, int, struct mbuf *); int rip6_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); -int rip6_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_bind(struct socket *, struct mbuf *, struct proc *); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 2e080474206..1d8c2709839 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.167 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.168 2022/09/03 22:43:38 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -106,7 +106,6 @@ struct inpcbtable rawin6pcbtable; struct cpumem *rip6counters; const struct pr_usrreqs rip6_usrreqs = { - .pru_usrreq = rip6_usrreq, .pru_attach = rip6_attach, .pru_detach = rip6_detach, .pru_bind = rip6_bind, @@ -117,6 +116,7 @@ const struct pr_usrreqs rip6_usrreqs = { .pru_abort = rip6_abort, .pru_control = in6_control, .pru_sockaddr = in6_sockaddr, + .pru_peeraddr = in6_peeraddr, }; /* @@ -575,37 +575,6 @@ rip6_ctloutput(int op, struct socket *so, int level, int optname, extern u_long rip6_sendspace; extern u_long rip6_recvspace; -int -rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, - struct mbuf *control, struct proc *p) -{ - struct inpcb *in6p; - int error = 0; - - soassertlocked(so); - - in6p = sotoinpcb(so); - if (in6p == NULL) { - error = EINVAL; - goto release; - } - - switch (req) { - case PRU_PEERADDR: - in6_setpeeraddr(in6p, nam); - break; - - default: - panic("%s", __func__); - } -release: - if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) { - m_freem(control); - m_freem(m); - } - return (error); -} - int rip6_attach(struct socket *so, int proto) { diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index f22568b7450..eb7f67e7cb1 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.53 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.54 2022/09/03 22:43:39 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -62,10 +62,6 @@ struct stat; struct ifnet; 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 *); int (*pru_bind)(struct socket *, struct mbuf *, struct proc *); @@ -84,8 +80,9 @@ struct pr_usrreqs { int (*pru_rcvoob)(struct socket *, struct mbuf *, int); int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); - int (*pru_connect2)(struct socket *, struct socket *); int (*pru_sockaddr)(struct socket *, struct mbuf *); + int (*pru_peeraddr)(struct socket *, struct mbuf *); + int (*pru_connect2)(struct socket *, struct socket *); }; struct protosw { @@ -392,8 +389,7 @@ pru_sockaddr(struct socket *so, struct mbuf *addr) 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); + return (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, addr); } static inline int diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index e9f600eda4b..ec5a5fd4217 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.39 2022/09/03 18:48:50 mvs Exp $ */ +/* $OpenBSD: unpcb.h,v 1.40 2022/09/03 22:43:39 mvs Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -112,8 +112,6 @@ struct fdpass { 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); int uipc_detach(struct socket *); int uipc_bind(struct socket *, struct mbuf *, struct proc *); @@ -128,6 +126,7 @@ int uipc_send(struct socket *, struct mbuf *, struct mbuf *, int uipc_abort(struct socket *); int uipc_sense(struct socket *, struct stat *); int uipc_sockaddr(struct socket *, struct mbuf *); +int uipc_peeraddr(struct socket *, struct mbuf *); int uipc_connect2(struct socket *, struct socket *); void unp_init(void); -- 2.20.1