The 'proc *' is not used for PRU_CONTROL request, so remove it from
pru_control() wrapper.

I want to use existing in{6,}_control for tcp(4) and udp(4) sockets, so
for inet6 case I introduced `tcp6_usrreqs' and `udp6_usrreqs'
structures. I also want to use them for the following PRU_SOCKADDR and
PRU_PEERADDR.

Since the PRU_SOCKADDR and PRU_PEERADDR are the last ones, I want to
move the corresponding (*pru_)() handlers and kill (*pru_usrreq)() with
single diff. Is it ok to review?

Index: sys/sys/protosw.h
===================================================================
RCS file: /cvs/src/sys/sys/protosw.h,v
retrieving revision 1.51
diff -u -p -r1.51 protosw.h
--- sys/sys/protosw.h   1 Sep 2022 18:21:23 -0000       1.51
+++ sys/sys/protosw.h   1 Sep 2022 19:35:08 -0000
@@ -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
Index: sys/kern/sys_socket.c
===================================================================
RCS file: /cvs/src/sys/kern/sys_socket.c,v
retrieving revision 1.53
diff -u -p -r1.53 sys_socket.c
--- sys/kern/sys_socket.c       14 Aug 2022 01:58:28 -0000      1.53
+++ sys/kern/sys_socket.c       1 Sep 2022 19:35:07 -0000
@@ -137,7 +137,7 @@ soo_ioctl(struct file *fp, u_long cmd, c
                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;
        }
Index: sys/kern/uipc_usrreq.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
retrieving revision 1.182
diff -u -p -r1.182 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c      1 Sep 2022 18:21:22 -0000       1.182
+++ sys/kern/uipc_usrreq.c      1 Sep 2022 19:35:07 -0000
@@ -219,8 +219,6 @@ uipc_usrreq(struct socket *so, int req, 
        struct socket *so2;
        int error = 0;
 
-       if (req == PRU_CONTROL)
-               return (EOPNOTSUPP);
        if (req != PRU_SEND && control && control->m_len) {
                error = EOPNOTSUPP;
                goto release;
Index: sys/net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.663
diff -u -p -r1.663 if.c
--- sys/net/if.c        13 Aug 2022 21:01:46 -0000      1.663
+++ sys/net/if.c        1 Sep 2022 19:35:07 -0000
@@ -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) {
Index: sys/net/pfkeyv2.c
===================================================================
RCS file: /cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.249
diff -u -p -r1.249 pfkeyv2.c
--- sys/net/pfkeyv2.c   1 Sep 2022 18:21:23 -0000       1.249
+++ sys/net/pfkeyv2.c   1 Sep 2022 19:35:07 -0000
@@ -395,9 +395,6 @@ pfkeyv2_usrreq(struct socket *so, int re
        struct pkpcb *kp;
        int error = 0;
 
-       if (req == PRU_CONTROL)
-               return (EOPNOTSUPP);
-
        soassertlocked(so);
 
        if (control && control->m_len) {
Index: sys/net/rtsock.c
===================================================================
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.350
diff -u -p -r1.350 rtsock.c
--- sys/net/rtsock.c    1 Sep 2022 18:21:23 -0000       1.350
+++ sys/net/rtsock.c    1 Sep 2022 19:35:07 -0000
@@ -220,9 +220,6 @@ route_usrreq(struct socket *so, int req,
        struct rtpcb    *rop;
        int              error = 0;
 
-       if (req == PRU_CONTROL)
-               return (EOPNOTSUPP);
-
        soassertlocked(so);
 
        if (control && control->m_len) {
Index: sys/netinet/ip_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_divert.c,v
retrieving revision 1.83
diff -u -p -r1.83 ip_divert.c
--- sys/netinet/ip_divert.c     1 Sep 2022 18:21:23 -0000       1.83
+++ sys/netinet/ip_divert.c     1 Sep 2022 19:35:08 -0000
@@ -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;
@@ -257,11 +258,6 @@ divert_usrreq(struct socket *so, int req
 {
        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);
 
Index: sys/netinet/ip_gre.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_gre.c,v
retrieving revision 1.81
diff -u -p -r1.81 ip_gre.c
--- sys/netinet/ip_gre.c        28 Aug 2022 18:44:16 -0000      1.81
+++ sys/netinet/ip_gre.c        1 Sep 2022 19:35:08 -0000
@@ -49,6 +49,7 @@
 #include <sys/sysctl.h>
 
 #include <net/if.h>
+#include <net/if_var.h>
 #include <net/route.h>
 
 #include <netinet/in.h>
@@ -56,6 +57,7 @@
 #include <netinet/ip_gre.h>
 #include <netinet/ip_var.h>
 #include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
 
 #ifdef PIPEX
 #include <net/pipex.h>
@@ -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
Index: sys/netinet/raw_ip.c
===================================================================
RCS file: /cvs/src/sys/netinet/raw_ip.c,v
retrieving revision 1.144
diff -u -p -r1.144 raw_ip.c
--- sys/netinet/raw_ip.c        1 Sep 2022 18:21:23 -0000       1.144
+++ sys/netinet/raw_ip.c        1 Sep 2022 19:35:08 -0000
@@ -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,
 };
 
 /*
@@ -463,10 +464,6 @@ rip_usrreq(struct socket *so, int req, s
 {
        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);
 
Index: sys/netinet/tcp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.203
diff -u -p -r1.203 tcp_usrreq.c
--- sys/netinet/tcp_usrreq.c    1 Sep 2022 18:21:23 -0000       1.203
+++ sys/netinet/tcp_usrreq.c    1 Sep 2022 19:35:08 -0000
@@ -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 },
@@ -194,17 +216,6 @@ tcp_usrreq(struct socket *so, int req, s
        struct tcpcb *otp = NULL, *tp;
        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);
 
Index: sys/netinet/tcp_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_var.h,v
retrieving revision 1.153
diff -u -p -r1.153 tcp_var.h
--- sys/netinet/tcp_var.h       31 Aug 2022 21:23:02 -0000      1.153
+++ sys/netinet/tcp_var.h       1 Sep 2022 19:35:08 -0000
@@ -639,6 +639,11 @@ tcpstat_pkt(enum tcpstat_counters pcount
 }
 
 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 */
Index: sys/netinet/udp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.298
diff -u -p -r1.298 udp_usrreq.c
--- sys/netinet/udp_usrreq.c    1 Sep 2022 18:21:23 -0000       1.298
+++ sys/netinet/udp_usrreq.c    1 Sep 2022 19:35:08 -0000
@@ -132,7 +132,23 @@ 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 },
Index: sys/netinet/udp_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/udp_var.h,v
retrieving revision 1.44
diff -u -p -r1.44 udp_var.h
--- sys/netinet/udp_var.h       28 Aug 2022 18:44:16 -0000      1.44
+++ sys/netinet/udp_var.h       1 Sep 2022 19:35:08 -0000
@@ -129,6 +129,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 */
 void    udp_ctlinput(int, struct sockaddr *, u_int, void *);
Index: sys/netinet6/in6_proto.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_proto.c,v
retrieving revision 1.110
diff -u -p -r1.110 in6_proto.c
--- sys/netinet6/in6_proto.c    15 Aug 2022 09:11:39 -0000      1.110
+++ sys/netinet6/in6_proto.c    1 Sep 2022 19:35:08 -0000
@@ -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
 },
 {
Index: sys/netinet6/ip6_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v
retrieving revision 1.82
diff -u -p -r1.82 ip6_divert.c
--- sys/netinet6/ip6_divert.c   1 Sep 2022 18:21:23 -0000       1.82
+++ sys/netinet6/ip6_divert.c   1 Sep 2022 19:35:08 -0000
@@ -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;
@@ -263,11 +264,6 @@ divert6_usrreq(struct socket *so, int re
 {
        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);
 
Index: sys/netinet6/raw_ip6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.165
diff -u -p -r1.165 raw_ip6.c
--- sys/netinet6/raw_ip6.c      1 Sep 2022 18:21:23 -0000       1.165
+++ sys/netinet6/raw_ip6.c      1 Sep 2022 19:35:08 -0000
@@ -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,
 };
 
 /*
@@ -579,10 +580,6 @@ rip6_usrreq(struct socket *so, int req, 
 {
        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);
 

Reply via email to