Source-Changes-HG archive

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

[src/trunk]: src/sys Pass inpcb/in6pcb instead of socket to ip_output/ip6_output



details:   https://anonhg.NetBSD.org/src/rev/ca4f036b345c
branches:  trunk
changeset: 351882:ca4f036b345c
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Mar 03 07:13:06 2017 +0000

description:
Pass inpcb/in6pcb instead of socket to ip_output/ip6_output

- Passing a socket to Layer 3 is layer violation and even unnecessary
- The change makes codes of callers and IPsec a bit simple

diffstat:

 sys/netinet/dccp_usrreq.c  |   6 +++---
 sys/netinet/ip_output.c    |  15 ++++++---------
 sys/netinet/ip_var.h       |   4 ++--
 sys/netinet/raw_ip.c       |   6 +++---
 sys/netinet/sctp_output.c  |   8 ++++----
 sys/netinet/tcp_input.c    |  22 ++++++----------------
 sys/netinet/tcp_output.c   |   8 ++++----
 sys/netinet/tcp_subr.c     |  20 ++++++--------------
 sys/netinet/udp_usrreq.c   |   6 +++---
 sys/netinet6/ip6_output.c  |   8 ++++----
 sys/netinet6/ip6_var.h     |   8 +++-----
 sys/netinet6/raw_ip6.c     |   6 +++---
 sys/netinet6/udp6_output.c |   8 ++++----
 sys/netipsec/ipsec.c       |  16 ++++------------
 sys/netipsec/ipsec.h       |   4 ++--
 sys/netipsec/ipsec6.h      |   4 ++--
 16 files changed, 59 insertions(+), 90 deletions(-)

diffs (truncated from 567 to 300 lines):

diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/dccp_usrreq.c
--- a/sys/netinet/dccp_usrreq.c Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/dccp_usrreq.c Fri Mar 03 07:13:06 2017 +0000
@@ -1,5 +1,5 @@
 /*     $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $   */
-/*     $NetBSD: dccp_usrreq.c,v 1.12 2017/01/16 15:44:47 christos Exp $ */
+/*     $NetBSD: dccp_usrreq.c,v 1.13 2017/03/03 07:13:06 ozaki-r Exp $ */
 
 /*
  * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson 
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.12 2017/01/16 15:44:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.13 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1620,7 +1620,7 @@
                DCCP_DEBUG((LOG_INFO, "Calling ip_output, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len));
                error = ip_output(m, inp->inp_options, &inp->inp_route,
                    (inp->inp_socket->so_options & SO_DONTROUTE), 0, 
-                                 inp->inp_socket);
+                                 inp);
        }
 
        if (error) {
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/ip_output.c   Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_output.c,v 1.274 2017/03/02 05:29:31 ozaki-r Exp $  */
+/*     $NetBSD: ip_output.c,v 1.275 2017/03/03 07:13:06 ozaki-r Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.274 2017/03/02 05:29:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.275 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -225,7 +225,7 @@
  */
 int
 ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, int flags,
-    struct ip_moptions *imo, struct socket *so)
+    struct ip_moptions *imo, struct inpcb *inp)
 {
        struct rtentry *rt;
        struct ip *ip;
@@ -588,7 +588,7 @@
                bool ipsec_done = false;
 
                /* Perform IPsec processing, if any. */
-               error = ipsec4_output(m, so, flags, &sp, &mtu, &natt_frag,
+               error = ipsec4_output(m, inp, flags, &sp, &mtu, &natt_frag,
                    &ipsec_done);
                if (error || ipsec_done)
                        goto done;
@@ -713,10 +713,7 @@
         */
        if (ntohs(ip->ip_off) & IP_DF) {
                if (flags & IP_RETURNMTU) {
-                       struct inpcb *inp;
-
-                       KASSERT(so && solocked(so));
-                       inp = sotoinpcb(so);
+                       KASSERT(inp != NULL);
                        inp->inp_errormtu = mtu;
                }
                error = EMSGSIZE;
@@ -750,7 +747,7 @@
                if (natt_frag) {
                        error = ip_output(m, opt, ro,
                            flags | IP_RAWOUTPUT | IP_NOIPNEWID,
-                           imo, so);
+                           imo, inp);
                } else {
                        KASSERT((m->m_pkthdr.csum_flags &
                            (M_CSUM_UDPv4 | M_CSUM_TCPv4)) == 0);
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/ip_var.h
--- a/sys/netinet/ip_var.h      Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/ip_var.h      Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_var.h,v 1.117 2017/02/16 08:12:44 knakahara Exp $   */
+/*     $NetBSD: ip_var.h,v 1.118 2017/03/03 07:13:06 ozaki-r Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -213,7 +213,7 @@
 int     ip_optcopy(struct ip *, struct ip *);
 u_int   ip_optlen(struct inpcb *);
 int     ip_output(struct mbuf *, struct mbuf *, struct route *, int,
-           struct ip_moptions *, struct socket *);
+           struct ip_moptions *, struct inpcb *);
 int     ip_fragment(struct mbuf *, struct ifnet *, u_long);
 
 void    ip_reass_init(void);
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/raw_ip.c
--- a/sys/netinet/raw_ip.c      Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/raw_ip.c      Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: raw_ip.c,v 1.162 2017/01/24 07:09:24 ozaki-r Exp $     */
+/*     $NetBSD: raw_ip.c,v 1.163 2017/03/03 07:13:06 ozaki-r Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.162 2017/01/24 07:09:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.163 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -383,7 +383,7 @@
         * will be stored in inp_errormtu.
         */
        return ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
-            inp->inp_socket);
+            inp);
 }
 
 /*
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/sctp_output.c
--- a/sys/netinet/sctp_output.c Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/sctp_output.c Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sctp_output.c,v 1.9 2016/12/23 11:11:28 maya Exp $ */
+/*     $NetBSD: sctp_output.c,v 1.10 2017/03/03 07:13:06 ozaki-r Exp $ */
 /*     $KAME: sctp_output.c,v 1.48 2005/06/16 18:29:24 jinmei Exp $    */
 
 /*
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.9 2016/12/23 11:11:28 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.10 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -2251,7 +2251,7 @@
                }
                ret = ip_output(m, inp->ip_inp.inp.inp_options,
                                ro, o_flgs, inp->ip_inp.inp.inp_moptions,
-                                (struct socket *)inp->sctp_socket);
+                                &inp->ip_inp.inp);
                if ((rt) && (have_mtu) && (net) && (have_mtu > net->mtu)) {
                        rt->rt_ifp->if_mtu = have_mtu;
                }
@@ -2449,7 +2449,7 @@
                                 ro,
                                 o_flgs,
                                 ((struct in6pcb *)inp)->in6p_moptions,
-                                (struct socket *)inp->sctp_socket,
+                                (struct in6pcb *)inp,
                                 &ifp);
                if (net) {
                        /* for link local this must be done */
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/tcp_input.c   Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.354 2017/02/07 02:38:08 ozaki-r Exp $  */
+/*     $NetBSD: tcp_input.c,v 1.355 2017/03/03 07:13:06 ozaki-r Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.354 2017/02/07 02:38:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.355 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -4535,7 +4535,6 @@
        struct tcpcb *tp = NULL;
        struct tcphdr *th;
        u_int hlen;
-       struct socket *so;
 #ifdef TCP_SIGNATURE
        struct secasvar *sav = NULL;
        u_int8_t *sigp = NULL;
@@ -4584,18 +4583,8 @@
 
        /* Fixup the mbuf. */
        m->m_data += max_linkhdr;
-       if (sc->sc_tp) {
+       if (sc->sc_tp)
                tp = sc->sc_tp;
-               if (tp->t_inpcb)
-                       so = tp->t_inpcb->inp_socket;
-#ifdef INET6
-               else if (tp->t_in6pcb)
-                       so = tp->t_in6pcb->in6p_socket;
-#endif
-               else
-                       so = NULL;
-       } else
-               so = NULL;
        m_reset_rcvif(m);
        memset(mtod(m, u_char *), 0, tlen);
 
@@ -4818,7 +4807,7 @@
        case AF_INET:
                error = ip_output(m, sc->sc_ipopts, ro,
                    (ip_mtudisc ? IP_MTUDISC : 0),
-                   NULL, so);
+                   NULL, tp ? tp->t_inpcb : NULL);
                break;
 #endif
 #ifdef INET6
@@ -4827,7 +4816,8 @@
                    (rt = rtcache_validate(ro)) != NULL ? rt->rt_ifp : NULL);
                rtcache_unref(rt, ro);
 
-               error = ip6_output(m, NULL /*XXX*/, ro, 0, NULL, so, NULL);
+               error = ip6_output(m, NULL /*XXX*/, ro, 0, NULL,
+                   tp ? tp->t_in6pcb : NULL, NULL);
                break;
 #endif
        default:
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/tcp_output.c
--- a/sys/netinet/tcp_output.c  Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/tcp_output.c  Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_output.c,v 1.194 2017/01/04 15:09:37 martin Exp $  */
+/*     $NetBSD: tcp_output.c,v 1.195 2017/03/03 07:13:06 ozaki-r Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.194 2017/01/04 15:09:37 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.195 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1680,7 +1680,7 @@
                        opts = NULL;
                error = ip_output(m, opts, ro,
                        (tp->t_mtudisc ? IP_MTUDISC : 0) |
-                       (so->so_options & SO_DONTROUTE), NULL, so);
+                       (so->so_options & SO_DONTROUTE), NULL, tp->t_inpcb);
                break;
            }
 #endif
@@ -1694,7 +1694,7 @@
                else
                        opts = NULL;
                error = ip6_output(m, opts, ro, so->so_options & SO_DONTROUTE,
-                       NULL, so, NULL);
+                       NULL, tp->t_in6pcb, NULL);
                break;
            }
 #endif
diff -r cbc8da51af3e -r ca4f036b345c sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c    Fri Mar 03 07:11:49 2017 +0000
+++ b/sys/netinet/tcp_subr.c    Fri Mar 03 07:13:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_subr.c,v 1.269 2017/01/02 01:18:42 christos Exp $  */
+/*     $NetBSD: tcp_subr.c,v 1.270 2017/03/03 07:13:06 ozaki-r Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.269 2017/01/02 01:18:42 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.270 2017/03/03 07:13:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -649,7 +649,6 @@
 #endif
        int family;     /* family on packet, not inpcb/in6pcb! */
        struct tcphdr *th;
-       struct socket *so;
 
        if (tp != NULL && (flags & TH_RST) == 0) {
 #ifdef DIAGNOSTIC
@@ -892,15 +891,6 @@
 #endif
        }
 
-       if (tp && tp->t_inpcb)
-               so = tp->t_inpcb->inp_socket;
-#ifdef INET6



Home | Main Index | Thread Index | Old Index