Module Name: src
Committed By: martin
Date: Thu Apr 5 14:31:19 UTC 2018
Modified Files:
src/sys/net [netbsd-8]: if_etherip.c
src/sys/netinet [netbsd-8]: ip_etherip.c
src/sys/netinet6 [netbsd-8]: ip6_etherip.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.38.10.2 -r1.38.10.3 src/sys/net/if_etherip.c
cvs rdiff -u -r1.20 -r1.20.8.1 src/sys/netinet/ip_etherip.c
cvs rdiff -u -r1.21 -r1.21.8.1 src/sys/netinet6/ip6_etherip.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if_etherip.c
diff -u src/sys/net/if_etherip.c:1.38.10.2 src/sys/net/if_etherip.c:1.38.10.3
--- src/sys/net/if_etherip.c:1.38.10.2 Tue Jan 2 10:20:33 2018
+++ src/sys/net/if_etherip.c Thu Apr 5 14:31:19 2018
@@ -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 <[email protected]>
@@ -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 @@ etherip_attach(device_t parent, device_t
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 @@ etherip_attach(device_t parent, device_t
* 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 @@ etherip_start(struct ifnet *ifp)
{
struct etherip_softc *sc = ifp->if_softc;
- if(sc->sc_si)
+ if (sc->sc_si)
softint_schedule(sc->sc_si);
}
@@ -399,10 +401,14 @@ etheripintr(void *arg)
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);
Index: src/sys/netinet/ip_etherip.c
diff -u src/sys/netinet/ip_etherip.c:1.20 src/sys/netinet/ip_etherip.c:1.20.8.1
--- src/sys/netinet/ip_etherip.c:1.20 Wed Jan 11 13:08:29 2017
+++ src/sys/netinet/ip_etherip.c Thu Apr 5 14:31:19 2018
@@ -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 <[email protected]>
@@ -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 @@ ip_etherip_output(struct ifnet *ifp, str
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 @@ ip_etherip_output(struct ifnet *ifp, str
/* 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 @@ ip_etherip_output(struct ifnet *ifp, str
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 @@ ip_etherip_output(struct ifnet *ifp, str
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_etherip_input(struct mbuf *m, ...)
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, ðerip_softc_list, etherip_list) {
if (!sc->sc_src || !sc->sc_dst)
continue;
@@ -216,7 +219,7 @@ ip_etherip_input(struct mbuf *m, ...)
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;
}
Index: src/sys/netinet6/ip6_etherip.c
diff -u src/sys/netinet6/ip6_etherip.c:1.21 src/sys/netinet6/ip6_etherip.c:1.21.8.1
--- src/sys/netinet6/ip6_etherip.c:1.21 Wed Jan 11 13:08:29 2017
+++ src/sys/netinet6/ip6_etherip.c Thu Apr 5 14:31:19 2018
@@ -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 <[email protected]>
@@ -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 @@ ip6_etherip_output(struct ifnet *ifp, st
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 @@ ip6_etherip_output(struct ifnet *ifp, st
/* 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 @@ ip6_etherip_output(struct ifnet *ifp, st
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_etherip_input(struct mbuf **mp, int
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, ðerip_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)