Module Name: src Committed By: maxv Date: Fri Jan 26 14:47:41 UTC 2018
Modified Files: src/sys/net: if_etherip.c src/sys/netinet: ip_etherip.c src/sys/netinet6: ip6_etherip.c Log Message: 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.41 -r1.42 src/sys/net/if_etherip.c cvs rdiff -u -r1.20 -r1.21 src/sys/netinet/ip_etherip.c cvs rdiff -u -r1.21 -r1.22 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.41 src/sys/net/if_etherip.c:1.42 --- src/sys/net/if_etherip.c:1.41 Fri Jan 26 11:06:32 2018 +++ src/sys/net/if_etherip.c Fri Jan 26 14:47:41 2018 @@ -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 <rosenf...@grumpf.hope-2000.org> @@ -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 @@ 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. @@ -363,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); } @@ -400,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.21 --- src/sys/netinet/ip_etherip.c:1.20 Wed Jan 11 13:08:29 2017 +++ src/sys/netinet/ip_etherip.c Fri Jan 26 14:47:41 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.21 2018/01/26 14:47:41 maxv Exp $ */ /* * Copyright (c) 2006, Hans Rosenfeld <rosenf...@grumpf.hope-2000.org> @@ -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 @@ 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.22 --- src/sys/netinet6/ip6_etherip.c:1.21 Wed Jan 11 13:08:29 2017 +++ src/sys/netinet6/ip6_etherip.c Fri Jan 26 14:47:41 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.22 2018/01/26 14:47:41 maxv Exp $ */ /* * Copyright (c) 2006, Hans Rosenfeld <rosenf...@grumpf.hope-2000.org> @@ -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 @@ 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)