Module Name: src
Committed By: roy
Date: Sat Feb 13 13:00:16 UTC 2021
Modified Files:
src/sys/net: if_ethersubr.c if_gre.c
src/sys/netinet: if_arp.c
Log Message:
Prior alignment fixes should not use an offset
To generate a diff of this commit:
cvs rdiff -u -r1.290 -r1.291 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.178 -r1.179 src/sys/net/if_gre.c
cvs rdiff -u -r1.299 -r1.300 src/sys/netinet/if_arp.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_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.290 src/sys/net/if_ethersubr.c:1.291
--- src/sys/net/if_ethersubr.c:1.290 Sat Feb 13 07:28:04 2021
+++ src/sys/net/if_ethersubr.c Sat Feb 13 13:00:16 2021
@@ -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 @@ ether_input(struct ifnet *ifp, struct mb
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);
Index: src/sys/net/if_gre.c
diff -u src/sys/net/if_gre.c:1.178 src/sys/net/if_gre.c:1.179
--- src/sys/net/if_gre.c:1.178 Fri Feb 12 19:57:49 2021
+++ src/sys/net/if_gre.c Sat Feb 13 13:00:16 2021
@@ -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 @@ gre_receive(struct socket *so, void *arg
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++;
Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.299 src/sys/netinet/if_arp.c:1.300
--- src/sys/netinet/if_arp.c:1.299 Sat Feb 13 07:57:09 2021
+++ src/sys/netinet/if_arp.c Sat Feb 13 13:00:16 2021
@@ -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 @@ arpintr(void)
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 @@ arpintr(void)
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 @@ arpintr(void)
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: