diff options
author | Vitaliy Makkoveev <mvs@cvs.openbsd.org> | 2022-09-03 18:48:51 +0000 |
---|---|---|
committer | Vitaliy Makkoveev <mvs@cvs.openbsd.org> | 2022-09-03 18:48:51 +0000 |
commit | b74deec071b622bf75e369b894f29a81d2d7329c (patch) | |
tree | 5c977f410a8599b1bfcc7de57478fbb7018ab689 | |
parent | a06d57e8bc374eb2babce93aba9a7b90ac53fa3f (diff) |
Move PRU_SOCKADDR request to (*pru_sockaddr)()
Introduce in{,6}_sockaddr() functions, and use them for all except tcp(4)
inet sockets. For tcp(4) sockets use tcp_sockaddr() to keep debug ability.
The key management and route domain sockets returns EINVAL error for
PRU_SOCKADDR request, so keep this behaviour for a while instead of make
pru_sockaddr handler optional and return EOPNOTSUPP.
ok bluhm@
-rw-r--r-- | sys/kern/uipc_usrreq.c | 16 | ||||
-rw-r--r-- | sys/net/pfkeyv2.c | 13 | ||||
-rw-r--r-- | sys/net/rtsock.c | 13 | ||||
-rw-r--r-- | sys/netinet/in_pcb.c | 13 | ||||
-rw-r--r-- | sys/netinet/in_pcb.h | 4 | ||||
-rw-r--r-- | sys/netinet/ip_divert.c | 7 | ||||
-rw-r--r-- | sys/netinet/ip_gre.c | 3 | ||||
-rw-r--r-- | sys/netinet/raw_ip.c | 7 | ||||
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 37 | ||||
-rw-r--r-- | sys/netinet/tcp_var.h | 3 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 13 | ||||
-rw-r--r-- | sys/netinet6/in6_pcb.c | 13 | ||||
-rw-r--r-- | sys/netinet6/ip6_divert.c | 7 | ||||
-rw-r--r-- | sys/netinet6/raw_ip6.c | 7 | ||||
-rw-r--r-- | sys/sys/protosw.h | 6 | ||||
-rw-r--r-- | sys/sys/unpcb.h | 3 |
16 files changed, 103 insertions, 62 deletions
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 74d93f015df..659b5f6d639 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.183 2022/09/02 13:12:31 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.184 2022/09/03 18:48:49 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -140,6 +140,7 @@ const struct pr_usrreqs uipc_usrreqs = { .pru_send = uipc_send, .pru_abort = uipc_abort, .pru_sense = uipc_sense, + .pru_sockaddr = uipc_sockaddr, .pru_connect2 = uipc_connect2, }; @@ -230,10 +231,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_SOCKADDR: - uipc_setaddr(unp, nam); - break; - case PRU_PEERADDR: so2 = unp_solock_peer(so); uipc_setaddr(unp->unp_conn, nam); @@ -580,6 +577,15 @@ uipc_sense(struct socket *so, struct stat *sb) } int +uipc_sockaddr(struct socket *so, struct mbuf *nam) +{ + struct unpcb *unp = sotounpcb(so); + + uipc_setaddr(unp, nam); + return (0); +} + +int uipc_connect2(struct socket *so, struct socket *so2) { struct unpcb *unp = sotounpcb(so), *unp2; diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index c03087fe459..93572667d86 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.250 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.251 2022/09/03 18:48:50 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -176,6 +176,7 @@ int pfkeyv2_shutdown(struct socket *); 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_output(struct mbuf *, struct socket *); @@ -211,6 +212,7 @@ const struct pr_usrreqs pfkeyv2_usrreqs = { .pru_shutdown = pfkeyv2_shutdown, .pru_send = pfkeyv2_send, .pru_abort = pfkeyv2_abort, + .pru_sockaddr = pfkeyv2_sockaddr, }; const struct protosw pfkeysw[] = { @@ -389,6 +391,12 @@ pfkeyv2_abort(struct socket *so) } int +pfkeyv2_sockaddr(struct socket *so, struct mbuf *nam) +{ + return (EINVAL); +} + +int pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct proc *p) { @@ -410,9 +418,6 @@ pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, switch (req) { /* minimal support, just implement a fake peer address */ - case PRU_SOCKADDR: - error = EINVAL; - break; case PRU_PEERADDR: bcopy(&pfkey_addr, mtod(nam, caddr_t), pfkey_addr.sa_len); nam->m_len = pfkey_addr.sa_len; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 867fc3e1a8f..c64efb5a815 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.351 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.352 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -119,6 +119,7 @@ int route_rcvd(struct socket *); int route_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int route_abort(struct socket *); +int route_sockaddr(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); @@ -235,9 +236,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { /* minimal support, just implement a fake peer address */ - case PRU_SOCKADDR: - error = EINVAL; - break; case PRU_PEERADDR: bcopy(&route_src, mtod(nam, caddr_t), route_src.sa_len); nam->m_len = route_src.sa_len; @@ -394,6 +392,12 @@ route_abort(struct socket *so) } int +route_sockaddr(struct socket *so, struct mbuf *nam) +{ + return (EINVAL); +} + +int route_ctloutput(int op, struct socket *so, int level, int optname, struct mbuf *m) { @@ -2435,6 +2439,7 @@ const struct pr_usrreqs route_usrreqs = { .pru_rcvd = route_rcvd, .pru_send = route_send, .pru_abort = route_abort, + .pru_sockaddr = route_sockaddr, }; const struct protosw routesw[] = { diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index b326f3f14df..49b19ebc03f 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.273 2022/08/30 11:53:04 bluhm Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.274 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -665,6 +665,17 @@ in_setpeeraddr(struct inpcb *inp, struct mbuf *nam) sin->sin_addr = inp->inp_faddr; } +int +in_sockaddr(struct socket *so, struct mbuf *nam) +{ + struct inpcb *inp; + + inp = sotoinpcb(so); + in_setsockaddr(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 4726009ac25..9139c8b7e81 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.132 2022/08/30 11:53:04 bluhm Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.133 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -308,6 +308,7 @@ int in6_pcbaddrisavail(struct inpcb *, struct sockaddr_in6 *, int, 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 *); #endif /* INET6 */ void in_pcbinit(struct inpcbtable *, int); struct inpcb * @@ -318,6 +319,7 @@ void in_pcbrehash(struct inpcb *); 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_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 b03aa692ae3..263175597e1 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.84 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.85 2022/09/03 18:48:50 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -71,6 +71,7 @@ const struct pr_usrreqs divert_usrreqs = { .pru_send = divert_send, .pru_abort = divert_abort, .pru_control = in_control, + .pru_sockaddr = in_sockaddr, }; int divbhashsize = DIVERTHASHSIZE; @@ -267,10 +268,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, } switch (req) { - case PRU_SOCKADDR: - in_setsockaddr(inp, addr); - break; - case PRU_PEERADDR: in_setpeeraddr(inp, addr); break; diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 7407369d3c7..7a9db85f35e 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.82 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.83 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -74,6 +74,7 @@ const struct pr_usrreqs gre_usrreqs = { .pru_send = gre_send, .pru_abort = rip_abort, .pru_control = in_control, + .pru_sockaddr = in_sockaddr, }; int diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index bdc62075bf5..162e16ec47e 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.145 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.146 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -114,6 +114,7 @@ const struct pr_usrreqs rip_usrreqs = { .pru_send = rip_send, .pru_abort = rip_abort, .pru_control = in_control, + .pru_sockaddr = in_sockaddr, }; /* @@ -475,10 +476,6 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_SOCKADDR: - in_setsockaddr(inp, nam); - break; - case PRU_PEERADDR: in_setpeeraddr(inp, nam); break; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 03c3b8e7b72..7f64090f83d 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.204 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.205 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -128,6 +128,7 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_rcvoob = tcp_rcvoob, .pru_sendoob = tcp_sendoob, .pru_control = in_control, + .pru_sockaddr = tcp_sockaddr, }; #ifdef INET6 @@ -148,6 +149,7 @@ const struct pr_usrreqs tcp6_usrreqs = { .pru_rcvoob = tcp_rcvoob, .pru_sendoob = tcp_sendoob, .pru_control = in6_control, + .pru_sockaddr = tcp_sockaddr, }; #endif @@ -234,15 +236,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_SOCKADDR: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setsockaddr(inp, nam); - else -#endif - in_setsockaddr(inp, nam); - break; - case PRU_PEERADDR: #ifdef INET6 if (inp->inp_flags & INP_IPV6) @@ -1058,6 +1051,30 @@ release: return (error); } +int +tcp_sockaddr(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_setsockaddr(inp, nam); + else +#endif + in_setsockaddr(inp, nam); + + if (so->so_options & SO_DEBUG) + tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, + PRU_SOCKADDR, 0); + return (0); +} /* * Initiate (or continue) disconnect. diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index fa92c7d4066..f72e4d37b6e 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.154 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.155 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -730,6 +730,7 @@ int tcp_rcvd(struct socket *); 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_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 1864d0286c2..44591b2c6ba 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.299 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.300 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -133,6 +133,7 @@ const struct pr_usrreqs udp_usrreqs = { .pru_send = udp_send, .pru_abort = udp_abort, .pru_control = in_control, + .pru_sockaddr = in_sockaddr, }; #ifdef INET6 @@ -147,6 +148,7 @@ const struct pr_usrreqs udp6_usrreqs = { .pru_send = udp_send, .pru_abort = udp_abort, .pru_control = in6_control, + .pru_sockaddr = in6_sockaddr, }; #endif @@ -1094,15 +1096,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, */ switch (req) { - case PRU_SOCKADDR: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setsockaddr(inp, addr); - else -#endif /* INET6 */ - in_setsockaddr(inp, addr); - break; - case PRU_PEERADDR: #ifdef INET6 if (inp->inp_flags & INP_IPV6) diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 8825c7ffa5b..5410149d4ab 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.121 2022/08/30 11:53:04 bluhm Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.122 2022/09/03 18:48:50 mvs Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -365,6 +365,17 @@ in6_setpeeraddr(struct inpcb *inp, struct mbuf *nam) in6_recoverscope(sin6, &inp->inp_faddr6); } +int +in6_sockaddr(struct socket *so, struct mbuf *nam) +{ + struct inpcb *in6p; + + in6p = sotoinpcb(so); + in6_setsockaddr(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 d1800b14c39..892f7fd033d 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.83 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.84 2022/09/03 18:48:50 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -72,6 +72,7 @@ const struct pr_usrreqs divert6_usrreqs = { .pru_send = divert6_send, .pru_abort = divert6_abort, .pru_control = in6_control, + .pru_sockaddr = in6_sockaddr, }; int divb6hashsize = DIVERTHASHSIZE; @@ -273,10 +274,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, } switch (req) { - case PRU_SOCKADDR: - in6_setsockaddr(inp, addr); - break; - case PRU_PEERADDR: in6_setpeeraddr(inp, addr); break; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 0bae4da3a35..2e080474206 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.166 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.167 2022/09/03 18:48:50 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -116,6 +116,7 @@ const struct pr_usrreqs rip6_usrreqs = { .pru_send = rip6_send, .pru_abort = rip6_abort, .pru_control = in6_control, + .pru_sockaddr = in6_sockaddr, }; /* @@ -590,10 +591,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, } switch (req) { - case PRU_SOCKADDR: - in6_setsockaddr(in6p, nam); - break; - case PRU_PEERADDR: in6_setpeeraddr(in6p, nam); break; diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 7b7d54c371c..f22568b7450 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.52 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.53 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -85,6 +85,7 @@ struct pr_usrreqs { 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 *); }; struct protosw { @@ -385,8 +386,7 @@ pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr, static inline int pru_sockaddr(struct socket *so, struct mbuf *addr) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_SOCKADDR, NULL, addr, NULL, curproc); + return (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, addr); } static inline int diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index 0275d511ca4..e9f600eda4b 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.38 2022/09/01 18:21:23 mvs Exp $ */ +/* $OpenBSD: unpcb.h,v 1.39 2022/09/03 18:48:50 mvs Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -127,6 +127,7 @@ int uipc_send(struct socket *, struct mbuf *, 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_connect2(struct socket *, struct socket *); void unp_init(void); |