Source-Changes-HG archive

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

[src/netbsd-8]: src/sys Pull up following revision(s) (requested by maxv in t...



details:   https://anonhg.NetBSD.org/src/rev/b0c33f7be308
branches:  netbsd-8
changeset: 434827:b0c33f7be308
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Apr 05 14:31:19 2018 +0000

description:
Pull up following revision(s) (requested by maxv in ticket #694):

        sys/netinet6/ip6_etherip.c: revision 1.22
        sys/net/if_etherip.c: revision 1.41
        sys/net/if_etherip.c: revision 1.42
        sys/netinet/ip_etherip.c: revision 1.21

Don't call if_attach, do if_initialize+if_register, otherwise when an
EtherIP packet is received the first KASSERT in if_input() fires.

A few fixes:
 * Style.
 * Don't add M_PKTHDR manually, that's absolutely forbidden. Add a
   KASSERT to make sure it's already there.
 * Add a missing NULL check after m_pullup.

diffstat:

 sys/net/if_etherip.c       |  30 ++++++++++++++++++------------
 sys/netinet/ip_etherip.c   |  23 +++++++++++++----------
 sys/netinet6/ip6_etherip.c |  23 ++++++++++++-----------
 3 files changed, 43 insertions(+), 33 deletions(-)

diffs (254 lines):

diff -r dd2f45d53587 -r b0c33f7be308 sys/net/if_etherip.c
--- a/sys/net/if_etherip.c      Wed Apr 04 16:42:03 2018 +0000
+++ b/sys/net/if_etherip.c      Thu Apr 05 14:31:19 2018 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_etherip.c,v 1.38.10.2 2018/01/02 10:20:33 snj Exp $        */
+/*      $NetBSD: if_etherip.c,v 1.38.10.3 2018/04/05 14:31:19 martin Exp $        */
 
 /*
  *  Copyright (c) 2006, Hans Rosenfeld <rosenfeld%grumpf.hope-2000.org@localhost>
@@ -27,8 +27,9 @@
  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  *  SUCH DAMAGE.
- *
- *
+ */
+
+/*
  *  Copyright (c) 2003, 2004, 2008 The NetBSD Foundation.
  *  All rights reserved.
  *
@@ -55,9 +56,9 @@
  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  *  POSSIBILITY OF SUCH DAMAGE.
- *
- *
- * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ */
+
+/* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -86,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.38.10.2 2018/01/02 10:20:33 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.38.10.3 2018/04/05 14:31:19 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -227,7 +228,7 @@
        memcpy(enaddr+3, (uint8_t *)&ui, 3);
 
        aprint_verbose_dev(self, "Ethernet address %s\n",
-                      ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr));
+           ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr));
 
        /*
         * Why 1000baseT? Why not? You can add more.
@@ -266,14 +267,15 @@
         * Those steps are mandatory for an Ethernet driver, the first call
         * being common to all network interface drivers.
         */
-       error = if_attach(ifp);
+       error = if_initialize(ifp);
        if (error != 0) {
-               aprint_error_dev(self, "if_attach failed(%d)\n", error);
+               aprint_error_dev(self, "if_initialize failed(%d)\n", error);
                ifmedia_delete_instance(&sc->sc_im, IFM_INST_ANY);
                pmf_device_deregister(self);
                return;
        }
        ether_ifattach(ifp, enaddr);
+       if_register(ifp);
 
        /*
         * Add a sysctl node for that interface.
@@ -362,7 +364,7 @@
 {
        struct etherip_softc *sc = ifp->if_softc;
 
-       if(sc->sc_si)
+       if (sc->sc_si)
                softint_schedule(sc->sc_si);
 }
 
@@ -399,10 +401,14 @@
                                break;
 #endif
                        default:
+                               /* impossible */
+                               m_freem(m);
                                error = ENETDOWN;
                        }
                        ifp->if_flags &= ~IFF_OACTIVE;
-               } else  m_freem(m);
+               } else {
+                       m_freem(m);
+               }
        }
        mutex_exit(softnet_lock);
        __USE(error);
diff -r dd2f45d53587 -r b0c33f7be308 sys/netinet/ip_etherip.c
--- a/sys/netinet/ip_etherip.c  Wed Apr 04 16:42:03 2018 +0000
+++ b/sys/netinet/ip_etherip.c  Thu Apr 05 14:31:19 2018 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ip_etherip.c,v 1.20 2017/01/11 13:08:29 ozaki-r Exp $        */
+/*      $NetBSD: ip_etherip.c,v 1.20.8.1 2018/04/05 14:31:19 martin Exp $        */
 
 /*
  *  Copyright (c) 2006, Hans Rosenfeld <rosenfeld%grumpf.hope-2000.org@localhost>
@@ -27,8 +27,9 @@
  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  *  SUCH DAMAGE.
- *
- *
+ */
+
+/*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * All rights reserved.
  *
@@ -58,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_etherip.c,v 1.20 2017/01/11 13:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_etherip.c,v 1.20.8.1 2018/04/05 14:31:19 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -107,7 +108,7 @@
        sin_src = (struct sockaddr_in *)sc->sc_src;
        sin_dst = (struct sockaddr_in *)sc->sc_dst;
 
-       if (sin_src == NULL || 
+       if (sin_src == NULL ||
            sin_dst == NULL ||
            sin_src->sin_family != AF_INET ||
            sin_dst->sin_family != AF_INET) {
@@ -118,7 +119,7 @@
        /* reset broadcast/multicast flags */
        m->m_flags &= ~(M_BCAST|M_MCAST);
 
-       m->m_flags |= M_PKTHDR;
+       KASSERT((m->m_flags & M_PKTHDR) != 0);
        proto = IPPROTO_ETHERIP;
 
        /* fill and prepend Ethernet-in-IP header */
@@ -132,8 +133,8 @@
                if (m == NULL)
                        return ENOBUFS;
        }
-       memcpy(mtod(m, struct etherip_header *), &eiphdr, 
-              sizeof(struct etherip_header));
+       memcpy(mtod(m, struct etherip_header *), &eiphdr,
+           sizeof(struct etherip_header));
 
        /* fill new IP header */
        memset(&iphdr, 0, sizeof(struct ip));
@@ -156,6 +157,8 @@
                return ENOBUFS;
        if (M_UNWRITABLE(m, sizeof(struct ip)))
                m = m_pullup(m, sizeof(struct ip));
+       if (m == NULL)
+               return ENOBUFS;
        memcpy(mtod(m, struct ip *), &iphdr, sizeof(struct ip));
 
        sockaddr_in_init(&u.dst4, &sin_dst->sin_addr, 0);
@@ -201,7 +204,7 @@
 
        ip = mtod(m, const struct ip *);
 
-       /* find device configured for this packets src and dst */
+       /* find device configured for this packet's src and dst */
        LIST_FOREACH(sc, &etherip_softc_list, etherip_list) {
                if (!sc->sc_src || !sc->sc_dst)
                        continue;
@@ -216,7 +219,7 @@
                if (src->sin_addr.s_addr != ip->ip_dst.s_addr ||
                    dst->sin_addr.s_addr != ip->ip_src.s_addr)
                        continue;
-               
+
                ifp = &sc->sc_ec.ec_if;
                break;
        }
diff -r dd2f45d53587 -r b0c33f7be308 sys/netinet6/ip6_etherip.c
--- a/sys/netinet6/ip6_etherip.c        Wed Apr 04 16:42:03 2018 +0000
+++ b/sys/netinet6/ip6_etherip.c        Thu Apr 05 14:31:19 2018 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ip6_etherip.c,v 1.21 2017/01/11 13:08:29 ozaki-r Exp $        */
+/*      $NetBSD: ip6_etherip.c,v 1.21.8.1 2018/04/05 14:31:19 martin Exp $        */
 
 /*
  *  Copyright (c) 2006, Hans Rosenfeld <rosenfeld%grumpf.hope-2000.org@localhost>
@@ -27,8 +27,9 @@
  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  *  SUCH DAMAGE.
- *
- *
+ */
+
+/*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * All rights reserved.
  *
@@ -58,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_etherip.c,v 1.21 2017/01/11 13:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_etherip.c,v 1.21.8.1 2018/04/05 14:31:19 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -113,7 +114,7 @@
        sin6_src = (struct sockaddr_in6 *)sc->sc_src;
        sin6_dst = (struct sockaddr_in6 *)sc->sc_dst;
 
-       if (sin6_src == NULL || 
+       if (sin6_src == NULL ||
            sin6_dst == NULL ||
            sin6_src->sin6_family != AF_INET6 ||
            sin6_dst->sin6_family != AF_INET6) {
@@ -124,7 +125,7 @@
        /* reset broadcast/multicast flags */
        m->m_flags &= ~(M_BCAST|M_MCAST);
 
-       m->m_flags |= M_PKTHDR;
+       KASSERT((m->m_flags & M_PKTHDR) != 0);
        proto = IPPROTO_ETHERIP;
 
        /* fill and prepend Ethernet-in-IP header */
@@ -138,9 +139,9 @@
                if (m == NULL)
                        return ENOBUFS;
        }
-       memcpy(mtod(m, struct etherip_header *), &eiphdr, 
-              sizeof(struct etherip_header));
-       
+       memcpy(mtod(m, struct etherip_header *), &eiphdr,
+           sizeof(struct etherip_header));
+
        /* prepend new IP header */
        M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT);
        if (m && m->m_len < sizeof(struct ip6_hdr))
@@ -207,9 +208,9 @@
 
        ip6 = mtod(m, const struct ip6_hdr *);
 
-       /* find device configured for this packets src and dst */
+       /* find device configured for this packet's src and dst */
        LIST_FOREACH(sc, &etherip_softc_list, etherip_list) {
-               if( !sc->sc_src || !sc->sc_dst)
+               if (!sc->sc_src || !sc->sc_dst)
                        continue;
                if (sc->sc_src->sa_family != AF_INET6 ||
                    sc->sc_dst->sa_family != AF_INET6)



Home | Main Index | Thread Index | Old Index