Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Eliminate struct protosw::pr_output.



details:   https://anonhg.NetBSD.org/src/rev/70a63c59fcb6
branches:  trunk
changeset: 343052:70a63c59fcb6
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jan 20 21:43:59 2016 +0000

description:
Eliminate struct protosw::pr_output.

You can't use this unless you know what it is a priori: the formal
prototype is variadic, and the different instances (e.g., ip_output,
route_output) have different real prototypes.

Convert the only user of it, raw_send in net/raw_cb.c, to take an
explicit callback argument.  Convert the only instances of it,
route_output and key_output, to such explicit callbacks for raw_send.
Use assertions to make sure the conversion to explicit callbacks is
warranted.

Discussed on tech-net with no objections:
https://mail-index.netbsd.org/tech-net/2016/01/16/msg005484.html

diffstat:

 sys/net/if_stf.c          |   5 ++---
 sys/net/raw_cb.h          |   5 +++--
 sys/net/raw_usrreq.c      |   9 +++++----
 sys/net/rtsock.c          |  20 ++++++++------------
 sys/netatalk/at_proto.c   |   5 ++---
 sys/netinet/if_arp.c      |   5 ++---
 sys/netinet/in_gif.c      |   5 ++---
 sys/netinet/in_proto.c    |  15 ++-------------
 sys/netinet/ip_mroute.c   |   5 ++---
 sys/netinet6/in6_gif.c    |   5 ++---
 sys/netinet6/in6_proto.c  |  12 ++----------
 sys/netinet6/ip6protosw.h |   5 +----
 sys/netipsec/keysock.c    |  25 +++++++++----------------
 sys/netipsec/keysock.h    |   3 +--
 sys/netipsec/xform_ipip.c |   6 ++----
 sys/netnatm/natm_proto.c  |   7 ++-----
 sys/sys/protosw.h         |   4 +---
 17 files changed, 48 insertions(+), 93 deletions(-)

diffs (truncated from 702 to 300 lines):

diff -r 2d0a86253772 -r 70a63c59fcb6 sys/net/if_stf.c
--- a/sys/net/if_stf.c  Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/net/if_stf.c  Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_stf.c,v 1.82 2015/08/24 22:21:26 pooka Exp $        */
+/*     $NetBSD: if_stf.c,v 1.83 2016/01/20 21:43:59 riastradh Exp $    */
 /*     $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
 
 /*
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.82 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.83 2016/01/20 21:43:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -165,7 +165,6 @@
        .pr_protocol    = IPPROTO_IPV6,
        .pr_flags       = PR_ATOMIC|PR_ADDR,
        .pr_input       = in_stf_input,
-       .pr_output      = rip_output,
        .pr_ctlinput    = NULL,
        .pr_ctloutput   = rip_ctloutput,
        .pr_usrreqs     = &rip_usrreqs,
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/net/raw_cb.h
--- a/sys/net/raw_cb.h  Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/net/raw_cb.h  Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: raw_cb.h,v 1.25 2015/05/02 17:18:03 rtr Exp $  */
+/*     $NetBSD: raw_cb.h,v 1.26 2016/01/20 21:43:59 riastradh Exp $    */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -71,7 +71,8 @@
 void   raw_setsockaddr(struct rawcb *, struct sockaddr *);
 void   raw_setpeeraddr(struct rawcb *, struct sockaddr *);
 int    raw_send(struct socket *,
-           struct mbuf *, struct sockaddr *, struct mbuf *, struct lwp *);
+           struct mbuf *, struct sockaddr *, struct mbuf *, struct lwp *,
+           int (*)(struct mbuf *, struct socket *));
 
 #endif /* _KERNEL */
 
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/net/raw_usrreq.c
--- a/sys/net/raw_usrreq.c      Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/net/raw_usrreq.c      Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: raw_usrreq.c,v 1.54 2015/05/02 17:18:03 rtr Exp $      */
+/*     $NetBSD: raw_usrreq.c,v 1.55 2016/01/20 21:43:59 riastradh Exp $        */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.54 2015/05/02 17:18:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.55 2016/01/20 21:43:59 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -153,7 +153,8 @@
 
 int
 raw_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
-    struct mbuf *control, struct lwp *l)
+    struct mbuf *control, struct lwp *l,
+    int (*output)(struct mbuf *, struct socket *))
 {
        struct rawcb *rp = sotorawcb(so);
        int error = 0;
@@ -186,7 +187,7 @@
                        goto die;
                }
        }
-       error = (*so->so_proto->pr_output)(m, so);
+       error = (*output)(m, so);
        if (nam)
                raw_disconnect(rp);
 
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/net/rtsock.c
--- a/sys/net/rtsock.c  Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/net/rtsock.c  Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.174 2015/10/13 21:28:34 rjs Exp $ */
+/*     $NetBSD: rtsock.c,v 1.175 2016/01/20 21:43:59 riastradh Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.174 2015/10/13 21:28:34 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.175 2016/01/20 21:43:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -151,7 +151,7 @@
 #define        PRESERVED_RTF   (RTF_UP | RTF_GATEWAY | RTF_HOST | RTF_DONE | RTF_MASK)
 
 static void COMPATNAME(route_init)(void);
-static int COMPATNAME(route_output)(struct mbuf *, ...);
+static int COMPATNAME(route_output)(struct mbuf *, struct socket *);
 
 static int rt_msg2(int, struct rt_addrinfo *, void *, struct rt_walkarg *, int *);
 static int rt_xaddrs(u_char, const char *, const char *, struct rt_addrinfo *);
@@ -165,6 +165,8 @@
 static int sysctl_rtable(SYSCTLFN_PROTO);
 static void rt_adjustcount(int, int);
 
+static const struct protosw COMPATNAME(route_protosw)[];
+
 static void
 rt_adjustcount(int af, int cnt)
 {
@@ -390,9 +392,10 @@
        int s;
 
        KASSERT(solocked(so));
+       KASSERT(so->so_proto == &COMPATNAME(route_protosw)[0]);
 
        s = splsoftnet();
-       error = raw_send(so, m, nam, control, l);
+       error = raw_send(so, m, nam, control, l, &COMPATNAME(route_output));
        splx(s);
 
        return error;
@@ -420,7 +423,7 @@
 
 /*ARGSUSED*/
 int
-COMPATNAME(route_output)(struct mbuf *m, ...)
+COMPATNAME(route_output)(struct mbuf *m, struct socket *so)
 {
        struct sockproto proto = { .sp_family = PF_XROUTE, };
        struct rt_xmsghdr *rtm = NULL;
@@ -431,14 +434,8 @@
        int len, error = 0;
        struct ifnet *ifp = NULL;
        struct ifaddr *ifa = NULL;
-       struct socket *so;
-       va_list ap;
        sa_family_t family;
 
-       va_start(ap, m);
-       so = va_arg(ap, struct socket *);
-       va_end(ap);
-
 #define senderr(e) do { error = e; goto flush;} while (/*CONSTCOND*/ 0)
        if (m == NULL || ((m->m_len < sizeof(int32_t)) &&
           (m = m_pullup(m, sizeof(int32_t))) == NULL))
@@ -1541,7 +1538,6 @@
                .pr_domain = &COMPATNAME(routedomain),
                .pr_flags = PR_ATOMIC|PR_ADDR,
                .pr_input = raw_input,
-               .pr_output = COMPATNAME(route_output),
                .pr_ctlinput = raw_ctlinput,
                .pr_usrreqs = &route_usrreqs,
                .pr_init = raw_init,
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/netatalk/at_proto.c
--- a/sys/netatalk/at_proto.c   Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/netatalk/at_proto.c   Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: at_proto.c,v 1.18 2014/05/18 14:46:16 rmind Exp $      */
+/*     $NetBSD: at_proto.c,v 1.19 2016/01/20 21:43:59 riastradh Exp $  */
 
 /*
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.18 2014/05/18 14:46:16 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.19 2016/01/20 21:43:59 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -55,7 +55,6 @@
        .pr_domain = &atalkdomain,
        .pr_protocol = ATPROTO_DDP,
        .pr_flags = PR_ATOMIC|PR_ADDR,
-       .pr_output = ddp_output,
        .pr_usrreqs = &ddp_usrreqs,
        .pr_init = ddp_init,
     },
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/netinet/if_arp.c      Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.199 2016/01/05 05:37:06 ozaki-r Exp $     */
+/*     $NetBSD: if_arp.c,v 1.200 2016/01/20 21:43:59 riastradh Exp $   */
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.199 2016/01/05 05:37:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.200 2016/01/20 21:43:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -270,7 +270,6 @@
          .pr_protocol = 0,
          .pr_flags = 0,
          .pr_input = 0,
-         .pr_output = 0,
          .pr_ctlinput = 0,
          .pr_ctloutput = 0,
          .pr_usrreqs = 0,
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/netinet/in_gif.c
--- a/sys/netinet/in_gif.c      Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/netinet/in_gif.c      Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_gif.c,v 1.68 2016/01/18 06:08:26 knakahara Exp $    */
+/*     $NetBSD: in_gif.c,v 1.69 2016/01/20 21:43:59 riastradh Exp $    */
 /*     $KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $ */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.68 2016/01/18 06:08:26 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.69 2016/01/20 21:43:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -85,7 +85,6 @@
        .pr_protocol    = 0 /* IPPROTO_IPV[46] */,
        .pr_flags       = PR_ATOMIC|PR_ADDR,
        .pr_input       = in_gif_input,
-       .pr_output      = rip_output,
        .pr_ctlinput    = NULL,
        .pr_ctloutput   = rip_ctloutput,
        .pr_usrreqs     = &rip_usrreqs,
diff -r 2d0a86253772 -r 70a63c59fcb6 sys/netinet/in_proto.c
--- a/sys/netinet/in_proto.c    Wed Jan 20 20:47:41 2016 +0000
+++ b/sys/netinet/in_proto.c    Wed Jan 20 21:43:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_proto.c,v 1.115 2015/10/13 21:28:35 rjs Exp $       */
+/*     $NetBSD: in_proto.c,v 1.116 2016/01/20 21:43:59 riastradh Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.115 2015/10/13 21:28:35 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.116 2016/01/20 21:43:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -199,7 +199,6 @@
 const struct protosw inetsw[] = {
 {      .pr_domain = &inetdomain,
        .pr_init = ip_init,
-       .pr_output = ip_output,
        .pr_fasttimo = ip_fasttimo,
        .pr_slowtimo = ip_slowtimo,
        .pr_drain = ip_drainstub,
@@ -276,7 +275,6 @@
        .pr_protocol = IPPROTO_RAW,
        .pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
        .pr_input = rip_input,
-       .pr_output = rip_output,
        .pr_ctlinput = rip_ctlinput,
        .pr_ctloutput = rip_ctloutput,
        .pr_usrreqs = &rip_usrreqs,
@@ -286,7 +284,6 @@
        .pr_protocol = IPPROTO_ICMP,
        .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
        .pr_input = icmp_input,
-       .pr_output = rip_output,
        .pr_ctlinput = rip_ctlinput,
        .pr_ctloutput = rip_ctloutput,
        .pr_usrreqs = &rip_usrreqs,
@@ -326,7 +323,6 @@
        .pr_protocol = IPPROTO_IPV4,
        .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
        .pr_input = encap4_input,
-       .pr_output = rip_output,
        .pr_ctlinput = rip_ctlinput,
        .pr_ctloutput = rip_ctloutput,
        .pr_usrreqs = &rip_usrreqs,
@@ -338,7 +334,6 @@
        .pr_protocol = IPPROTO_IPV6,
        .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
        .pr_input = encap4_input,
-       .pr_output = rip_output,
        .pr_ctlinput = rip_ctlinput,
        .pr_ctloutput = rip_ctloutput,
        .pr_usrreqs = &rip_usrreqs,
@@ -351,7 +346,6 @@
        .pr_protocol = IPPROTO_ETHERIP,



Home | Main Index | Thread Index | Old Index