Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys A few fixes:
details: https://anonhg.NetBSD.org/src/rev/e9f35afbcaff
branches: trunk
changeset: 359042:e9f35afbcaff
user: maxv <maxv%NetBSD.org@localhost>
date: Fri Jan 26 14:47:41 2018 +0000
description:
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 | 25 +++++++++++++++----------
sys/netinet/ip_etherip.c | 23 +++++++++++++----------
sys/netinet6/ip6_etherip.c | 23 ++++++++++++-----------
3 files changed, 40 insertions(+), 31 deletions(-)
diffs (236 lines):
diff -r 9a6f72c41464 -r e9f35afbcaff sys/net/if_etherip.c
--- a/sys/net/if_etherip.c Fri Jan 26 14:41:22 2018 +0000
+++ b/sys/net/if_etherip.c Fri Jan 26 14:47:41 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_etherip.c,v 1.41 2018/01/26 11:06:32 maxv Exp $ */
+/* $NetBSD: if_etherip.c,v 1.42 2018/01/26 14:47:41 maxv 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.41 2018/01/26 11:06:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.42 2018/01/26 14:47:41 maxv 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.
@@ -363,7 +364,7 @@
{
struct etherip_softc *sc = ifp->if_softc;
- if(sc->sc_si)
+ if (sc->sc_si)
softint_schedule(sc->sc_si);
}
@@ -400,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 9a6f72c41464 -r e9f35afbcaff sys/netinet/ip_etherip.c
--- a/sys/netinet/ip_etherip.c Fri Jan 26 14:41:22 2018 +0000
+++ b/sys/netinet/ip_etherip.c Fri Jan 26 14:47:41 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.21 2018/01/26 14:47:41 maxv 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.21 2018/01/26 14:47:41 maxv 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, ðerip_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 9a6f72c41464 -r e9f35afbcaff sys/netinet6/ip6_etherip.c
--- a/sys/netinet6/ip6_etherip.c Fri Jan 26 14:41:22 2018 +0000
+++ b/sys/netinet6/ip6_etherip.c Fri Jan 26 14:47:41 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.22 2018/01/26 14:47:41 maxv 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.22 2018/01/26 14:47:41 maxv 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, ð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)
Home |
Main Index |
Thread Index |
Old Index