Source-Changes-HG archive

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

[src/trunk]: src/sys Prior alignment fixes should not use an offset



details:   https://anonhg.NetBSD.org/src/rev/ad65255517c3
branches:  trunk
changeset: 959421:ad65255517c3
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Feb 13 13:00:16 2021 +0000

description:
Prior alignment fixes should not use an offset

diffstat:

 sys/net/if_ethersubr.c |  20 ++++++++------------
 sys/net/if_gre.c       |  13 ++++---------
 sys/netinet/if_arp.c   |  29 +++++++++++------------------
 3 files changed, 23 insertions(+), 39 deletions(-)

diffs (153 lines):

diff -r ea3b065c0d18 -r ad65255517c3 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Sat Feb 13 10:37:00 2021 +0000
+++ b/sys/net/if_ethersubr.c    Sat Feb 13 13:00:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.290 2021/02/13 07:28:04 roy Exp $   */
+/*     $NetBSD: if_ethersubr.c,v 1.291 2021/02/13 13:00:16 roy Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.290 2021/02/13 07:28:04 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.291 2021/02/13 13:00:16 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -649,23 +649,19 @@
        if ((ifp->if_flags & IFF_UP) == 0)
                goto drop;
 
-       /* If the Ethernet header is not aligned, slurp it up into a new
-        * mbuf with space for link headers, in the event we forward
-        * it.  Otherwise, if it is aligned, make sure the entire
-        * base Ethernet header is in the first mbuf of the chain.
-        */
+#ifdef MBUFTRACE
+       m_claimm(m, &ec->ec_rx_mowner);
+#endif
+
+       /* Enforce alignement */
        if (ETHER_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-               if ((m = m_copyup(m, sizeof(*eh),
-                   (max_linkhdr + 3) & ~3)) == NULL)
+               if ((m = m_copyup(m, sizeof(*eh), 0)) == NULL)
                        goto dropped;
        } else if (__predict_false(m->m_len < sizeof(*eh))) {
                if ((m = m_pullup(m, sizeof(*eh))) == NULL)
                        goto dropped;
        }
 
-#ifdef MBUFTRACE
-       m_claimm(m, &ec->ec_rx_mowner);
-#endif
        eh = mtod(m, struct ether_header *);
        etype = ntohs(eh->ether_type);
        ehlen = sizeof(*eh);
diff -r ea3b065c0d18 -r ad65255517c3 sys/net/if_gre.c
--- a/sys/net/if_gre.c  Sat Feb 13 10:37:00 2021 +0000
+++ b/sys/net/if_gre.c  Sat Feb 13 13:00:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gre.c,v 1.178 2021/02/12 19:57:49 roy Exp $ */
+/*     $NetBSD: if_gre.c,v 1.179 2021/02/13 13:00:16 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.178 2021/02/12 19:57:49 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.179 2021/02/13 13:00:16 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -396,14 +396,9 @@
                return;
        }
 
-       /* If the GRE header is not aligned, slurp it up into a new
-        * mbuf with space for link headers, in the event we forward
-        * it.  Otherwise, if it is aligned, make sure the entire
-        * base GRE header is in the first mbuf of the chain.
-        */
+       /* Enforce alignment */
        if (GRE_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-               if ((m = m_copyup(m, sizeof(struct gre_h),
-                   (max_linkhdr + 3) & ~3)) == NULL) {
+               if ((m = m_copyup(m, sizeof(struct gre_h), 0)) == NULL) {
                        /* XXXJRT new stat, please */
                        GRE_DPRINTF(sc, "m_copyup failed\n");
                        sc->sc_pullup_ev.ev_count++;
diff -r ea3b065c0d18 -r ad65255517c3 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Sat Feb 13 10:37:00 2021 +0000
+++ b/sys/netinet/if_arp.c      Sat Feb 13 13:00:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.299 2021/02/13 07:57:09 roy Exp $ */
+/*     $NetBSD: if_arp.c,v 1.300 2021/02/13 13:00:16 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.299 2021/02/13 07:57:09 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.300 2021/02/13 13:00:16 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -700,14 +700,9 @@
                MCLAIM(m, &arpdomain.dom_mowner);
                ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-               /* If the ARP header is not aligned, slurp it up into a new
-                * mbuf with space for link headers, in the event we forward
-                * it.  Otherwise, if it is aligned, make sure the entire
-                * base ARP header is in the first mbuf of the chain.
-                */
+               /* Enforce alignment */
                if (ARP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-                       if ((m = m_copyup(m, sizeof(*ar),
-                           (max_linkhdr + 3) & ~3)) == NULL)
+                       if ((m = m_copyup(m, sizeof(*ar), 0)) == NULL)
                                goto badlen;
                } else if (__predict_false(m->m_len < sizeof(*ar))) {
                        if ((m = m_pullup(m, sizeof(*ar))) == NULL)
@@ -732,9 +727,6 @@
                                ARP_STATINC(ARP_STAT_RCVBADPROTO);
                                goto free;
                        }
-
-                       arplen = sizeof(struct arphdr) +
-                           ar->ar_hln + 2 * ar->ar_pln;
                        break;
                default:
                        if (ntohs(ar->ar_hrd) == ARPHRD_IEEE1394) {
@@ -742,17 +734,18 @@
                                ARP_STATINC(ARP_STAT_RCVBADPROTO);
                                goto free;
                        }
-
-                       arplen = sizeof(struct arphdr) +
-                           2 * ar->ar_hln + 2 * ar->ar_pln;
                        break;
                }
 
                m_put_rcvif(rcvif, &s);
 
-               if (m->m_len < arplen && (m = m_pullup(m, arplen)) == NULL)
-                       goto badlen;
-               ar = mtod(m, struct arphdr *);
+               arplen = sizeof(*ar) + 2 * ar->ar_hln + 2 * ar->ar_pln;
+               if (m->m_len < arplen) {
+                       if ((m = m_pullup(m, arplen)) == NULL)
+                               goto badlen;
+                       ar = mtod(m, struct arphdr *);
+                       KASSERT(ARP_HDR_ALIGNED_P(ar));
+               }
 
                switch (ntohs(ar->ar_pro)) {
                case ETHERTYPE_IP:



Home | Main Index | Thread Index | Old Index