Introduce in{,6}_sockaddr() and in{,6}_peeraddr() functions, and use
them for all except tcp(4) sockets. Use tcp_sockaddr() and
tcp_peeraddr() functions 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.

Within the old *_usrreq() only default panic case left. They are not
called anymore, so just invoke panic() within. The *_usrreq() will be
removed with the next diff.

Index: sys/kern/uipc_usrreq.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
retrieving revision 1.183
diff -u -p -r1.183 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c      2 Sep 2022 13:12:31 -0000       1.183
+++ sys/kern/uipc_usrreq.c      2 Sep 2022 14:44:46 -0000
@@ -140,6 +140,8 @@ const struct pr_usrreqs uipc_usrreqs = {
        .pru_send       = uipc_send,
        .pru_abort      = uipc_abort,
        .pru_sense      = uipc_sense,
+       .pru_sockaddr   = uipc_sockaddr,
+       .pru_peeraddr   = uipc_peeraddr,
        .pru_connect2   = uipc_connect2,
 };
 
@@ -215,44 +217,8 @@ 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_SOCKADDR:
-               uipc_setaddr(unp, nam);
-               break;
-
-       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);
+       panic("uipc_usrreq");
+       return (EOPNOTSUPP);
 }
 
 /*
@@ -576,6 +542,28 @@ uipc_sense(struct socket *so, struct sta
            sb->st_ctim.tv_nsec = unp->unp_ctime.tv_nsec;
        sb->st_ino = unp->unp_ino;
 
+       return (0);
+}
+
+int
+uipc_sockaddr(struct socket *so, struct mbuf *nam)
+{
+       struct unpcb *unp = sotounpcb(so);
+
+       uipc_setaddr(unp, 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);
 }
 
Index: sys/net/pfkeyv2.c
===================================================================
RCS file: /cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.250
diff -u -p -r1.250 pfkeyv2.c
--- sys/net/pfkeyv2.c   2 Sep 2022 13:12:32 -0000       1.250
+++ sys/net/pfkeyv2.c   2 Sep 2022 14:44:46 -0000
@@ -176,6 +176,8 @@ 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_peeraddr(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 +213,8 @@ const struct pr_usrreqs pfkeyv2_usrreqs 
        .pru_shutdown   = pfkeyv2_shutdown,
        .pru_send       = pfkeyv2_send,
        .pru_abort      = pfkeyv2_abort,
+       .pru_sockaddr   = pfkeyv2_sockaddr,
+       .pru_peeraddr   = pfkeyv2_peeraddr,
 };
 
 const struct protosw pfkeysw[] = {
@@ -389,45 +393,26 @@ pfkeyv2_abort(struct socket *so)
 }
 
 int
-pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m,
-    struct mbuf *nam, struct mbuf *control, struct proc *p)
+pfkeyv2_sockaddr(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_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;
-               break;
+       /* Keep existing behaviour for a while. */
+       return (EINVAL);
+}
 
-       default:
-               panic("pfkeyv2_usrreq");
-       }
+int
+pfkeyv2_peeraddr(struct socket *so, struct mbuf *nam)
+{
+       bcopy(&pfkey_addr, mtod(nam, caddr_t), pfkey_addr.sa_len);
+       nam->m_len = pfkey_addr.sa_len;
+       return (0);
+}
 
- release:
-       if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) {
-               m_freem(control);
-               m_freem(m);
-       }
-       return (error);
+int
+pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m,
+    struct mbuf *nam, struct mbuf *control, struct proc *p)
+{
+       panic("pfkeyv2_usrreq");
+       return (EOPNOTSUPP);
 }
 
 int
Index: sys/net/rtsock.c
===================================================================
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.351
diff -u -p -r1.351 rtsock.c
--- sys/net/rtsock.c    2 Sep 2022 13:12:32 -0000       1.351
+++ sys/net/rtsock.c    2 Sep 2022 14:44:46 -0000
@@ -119,6 +119,8 @@ 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 *);
+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);
@@ -217,42 +219,8 @@ 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_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;
-               break;
-
-       default:
-               panic("route_usrreq");
-       }
-
- release:
-       if (req != PRU_RCVD && req != PRU_RCVOOB && req != PRU_SENSE) {
-               m_freem(control);
-               m_freem(m);
-       }
-       return (error);
+       panic("route_usrreq");
+       return (EOPNOTSUPP);
 }
 
 int
@@ -394,6 +362,21 @@ route_abort(struct socket *so)
 }
 
 int
+route_sockaddr(struct socket *so, struct mbuf *nam)
+{
+       /* Keep existing behaviour for a while. */
+       return (EINVAL);
+}
+
+int
+route_peeraddr(struct socket *so, struct mbuf *nam)
+{
+       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)
 {
@@ -2435,6 +2418,8 @@ const struct pr_usrreqs route_usrreqs = 
        .pru_rcvd       = route_rcvd,
        .pru_send       = route_send,
        .pru_abort      = route_abort,
+       .pru_sockaddr   = route_sockaddr,
+       .pru_peeraddr   = route_peeraddr,
 };
 
 const struct protosw routesw[] = {
Index: sys/netinet/in_pcb.c
===================================================================
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.273
diff -u -p -r1.273 in_pcb.c
--- sys/netinet/in_pcb.c        30 Aug 2022 11:53:04 -0000      1.273
+++ sys/netinet/in_pcb.c        2 Sep 2022 14:44:46 -0000
@@ -665,6 +665,28 @@ in_setpeeraddr(struct inpcb *inp, struct
        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);
+}
+
+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
Index: sys/netinet/in_pcb.h
===================================================================
RCS file: /cvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.132
diff -u -p -r1.132 in_pcb.h
--- sys/netinet/in_pcb.h        30 Aug 2022 11:53:04 -0000      1.132
+++ sys/netinet/in_pcb.h        2 Sep 2022 14:44:46 -0000
@@ -308,6 +308,8 @@ int  in6_pcbaddrisavail(struct inpcb *, 
 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 *
@@ -318,6 +320,8 @@ 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_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 *);
Index: sys/netinet/in_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/in_var.h,v
retrieving revision 1.41
diff -u -p -r1.41 in_var.h
--- sys/netinet/in_var.h        18 Oct 2018 15:23:04 -0000      1.41
+++ sys/netinet/in_var.h        2 Sep 2022 14:44:46 -0000
@@ -159,6 +159,8 @@ void        in_delmulti(struct in_multi *);
 int    in_hasmulti(struct in_addr *, struct ifnet *);
 void   in_ifscrub(struct ifnet *, struct in_ifaddr *);
 int    in_control(struct socket *, u_long, caddr_t, struct ifnet *);
+int    in_sockaddr(struct socket *, struct mbuf *);
+int    in_peeraddr(struct socket *, struct mbuf *);
 int    in_ioctl(u_long, caddr_t, struct ifnet *, int);
 void   in_prefixlen2mask(struct in_addr *, int);
 #endif
Index: sys/netinet/ip_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_divert.c,v
retrieving revision 1.84
diff -u -p -r1.84 ip_divert.c
--- sys/netinet/ip_divert.c     2 Sep 2022 13:12:32 -0000       1.84
+++ sys/netinet/ip_divert.c     2 Sep 2022 14:44:46 -0000
@@ -71,6 +71,8 @@ const struct pr_usrreqs divert_usrreqs =
        .pru_send       = divert_send,
        .pru_abort      = divert_abort,
        .pru_control    = in_control,
+       .pru_sockaddr   = in_sockaddr,
+       .pru_peeraddr   = in_peeraddr,
 };
 
 int divbhashsize = DIVERTHASHSIZE;
@@ -256,42 +258,8 @@ 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_SOCKADDR:
-               in_setsockaddr(inp, addr);
-               break;
-
-       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);
+       panic("divert_usrreq");
+       return (EOPNOTSUPP);
 }
 
 int
Index: sys/netinet/ip_gre.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_gre.c,v
retrieving revision 1.82
diff -u -p -r1.82 ip_gre.c
--- sys/netinet/ip_gre.c        2 Sep 2022 13:12:32 -0000       1.82
+++ sys/netinet/ip_gre.c        2 Sep 2022 14:44:46 -0000
@@ -74,6 +74,8 @@ const struct pr_usrreqs gre_usrreqs = {
        .pru_send       = gre_send,
        .pru_abort      = rip_abort,
        .pru_control    = in_control,
+       .pru_sockaddr   = in_sockaddr,
+       .pru_peeraddr   = in_peeraddr,
 };
 
 int
Index: sys/netinet/raw_ip.c
===================================================================
RCS file: /cvs/src/sys/netinet/raw_ip.c,v
retrieving revision 1.145
diff -u -p -r1.145 raw_ip.c
--- sys/netinet/raw_ip.c        2 Sep 2022 13:12:32 -0000       1.145
+++ sys/netinet/raw_ip.c        2 Sep 2022 14:44:46 -0000
@@ -114,6 +114,8 @@ const struct pr_usrreqs rip_usrreqs = {
        .pru_send       = rip_send,
        .pru_abort      = rip_abort,
        .pru_control    = in_control,
+       .pru_sockaddr   = in_sockaddr,
+       .pru_peeraddr   = in_peeraddr,
 };
 
 /*
@@ -462,36 +464,8 @@ 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_SOCKADDR:
-               in_setsockaddr(inp, nam);
-               break;
-
-       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);
+       panic("rip_usrreq");
+       return (EOPNOTSUPP);
 }
 
 int
Index: sys/netinet/tcp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.204
diff -u -p -r1.204 tcp_usrreq.c
--- sys/netinet/tcp_usrreq.c    2 Sep 2022 13:12:32 -0000       1.204
+++ sys/netinet/tcp_usrreq.c    2 Sep 2022 14:44:46 -0000
@@ -128,6 +128,8 @@ const struct pr_usrreqs tcp_usrreqs = {
        .pru_rcvoob     = tcp_rcvoob,
        .pru_sendoob    = tcp_sendoob,
        .pru_control    = in_control,
+       .pru_sockaddr   = tcp_sockaddr,
+       .pru_peeraddr   = tcp_peeraddr,
 };
 
 #ifdef INET6
@@ -148,6 +150,8 @@ const struct pr_usrreqs tcp6_usrreqs = {
        .pru_rcvoob     = tcp_rcvoob,
        .pru_sendoob    = tcp_sendoob,
        .pru_control    = in6_control,
+       .pru_sockaddr   = tcp_sockaddr,
+       .pru_peeraddr   = tcp_peeraddr,
 };
 #endif
 
@@ -212,59 +216,8 @@ 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_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)
-                       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);
+       panic("tcp_usrreq");
+       return (EOPNOTSUPP);
 }
 
 /*
@@ -1058,6 +1011,54 @@ 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);
+}
+
+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.
Index: sys/netinet/tcp_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_var.h,v
retrieving revision 1.154
diff -u -p -r1.154 tcp_var.h
--- sys/netinet/tcp_var.h       2 Sep 2022 13:12:32 -0000       1.154
+++ sys/netinet/tcp_var.h       2 Sep 2022 14:44:46 -0000
@@ -730,6 +730,8 @@ 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_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 *,
Index: sys/netinet/udp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.299
diff -u -p -r1.299 udp_usrreq.c
--- sys/netinet/udp_usrreq.c    2 Sep 2022 13:12:32 -0000       1.299
+++ sys/netinet/udp_usrreq.c    2 Sep 2022 14:44:46 -0000
@@ -133,6 +133,8 @@ const struct pr_usrreqs udp_usrreqs = {
        .pru_send       = udp_send,
        .pru_abort      = udp_abort,
        .pru_control    = in_control,
+       .pru_sockaddr   = in_sockaddr,
+       .pru_peeraddr   = in_peeraddr,
 };
 
 #ifdef INET6
@@ -147,6 +149,8 @@ const struct pr_usrreqs udp6_usrreqs = {
        .pru_send       = udp_send,
        .pru_abort      = udp_abort,
        .pru_control    = in6_control,
+       .pru_sockaddr   = in6_sockaddr,
+       .pru_peeraddr   = in6_peeraddr,
 };
 #endif
 
@@ -1077,57 +1081,8 @@ 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_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)
-                       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);
+       panic("udp_usrreq");
+       return (EOPNOTSUPP);
 }
 
 int
Index: sys/netinet6/in6_pcb.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_pcb.c,v
retrieving revision 1.121
diff -u -p -r1.121 in6_pcb.c
--- sys/netinet6/in6_pcb.c      30 Aug 2022 11:53:04 -0000      1.121
+++ sys/netinet6/in6_pcb.c      2 Sep 2022 14:44:46 -0000
@@ -365,6 +365,28 @@ in6_setpeeraddr(struct inpcb *inp, struc
        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);
+}
+
+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
Index: sys/netinet6/ip6_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v
retrieving revision 1.83
diff -u -p -r1.83 ip6_divert.c
--- sys/netinet6/ip6_divert.c   2 Sep 2022 13:12:32 -0000       1.83
+++ sys/netinet6/ip6_divert.c   2 Sep 2022 14:44:46 -0000
@@ -72,6 +72,8 @@ const struct pr_usrreqs divert6_usrreqs 
        .pru_send       = divert6_send,
        .pru_abort      = divert6_abort,
        .pru_control    = in6_control,
+       .pru_sockaddr   = in6_sockaddr,
+       .pru_peeraddr   = in6_peeraddr,
 };
 
 int divb6hashsize = DIVERTHASHSIZE;
@@ -262,42 +264,8 @@ 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_SOCKADDR:
-               in6_setsockaddr(inp, addr);
-               break;
-
-       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);
+       panic("%s", __func__);
+       return (EOPNOTSUPP);
 }
 
 int
Index: sys/netinet6/raw_ip6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.166
diff -u -p -r1.166 raw_ip6.c
--- sys/netinet6/raw_ip6.c      2 Sep 2022 13:12:32 -0000       1.166
+++ sys/netinet6/raw_ip6.c      2 Sep 2022 14:44:46 -0000
@@ -116,6 +116,8 @@ const struct pr_usrreqs rip6_usrreqs = {
        .pru_send       = rip6_send,
        .pru_abort      = rip6_abort,
        .pru_control    = in6_control,
+       .pru_sockaddr   = in6_sockaddr,
+       .pru_peeraddr   = in6_peeraddr,
 };
 
 /*
@@ -578,35 +580,8 @@ 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_SOCKADDR:
-               in6_setsockaddr(in6p, nam);
-               break;
-
-       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);
+       panic("%s", __func__);
+       return (EOPNOTSUPP);
 }
 
 int
Index: sys/sys/protosw.h
===================================================================
RCS file: /cvs/src/sys/sys/protosw.h,v
retrieving revision 1.52
diff -u -p -r1.52 protosw.h
--- sys/sys/protosw.h   2 Sep 2022 13:12:32 -0000       1.52
+++ sys/sys/protosw.h   2 Sep 2022 14:44:46 -0000
@@ -85,6 +85,8 @@ 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 *);
+       int     (*pru_peeraddr)(struct socket *, struct mbuf *);
 };
 
 struct protosw {
@@ -385,15 +387,13 @@ pru_sendoob(struct socket *so, struct mb
 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
 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
Index: sys/sys/unpcb.h
===================================================================
RCS file: /cvs/src/sys/sys/unpcb.h,v
retrieving revision 1.38
diff -u -p -r1.38 unpcb.h
--- sys/sys/unpcb.h     1 Sep 2022 18:21:23 -0000       1.38
+++ sys/sys/unpcb.h     2 Sep 2022 14:44:46 -0000
@@ -127,6 +127,8 @@ int uipc_send(struct socket *, struct mb
            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);

Reply via email to