Index: net/if_arp.h
===================================================================
RCS file: /cvsroot/src/sys/net/if_arp.h,v
retrieving revision 1.38
diff -u -p -u -r1.38 if_arp.h
--- net/if_arp.h	13 Feb 2021 07:57:09 -0000	1.38
+++ net/if_arp.h	14 Feb 2021 17:45:52 -0000
@@ -72,11 +72,7 @@ struct	arphdr {
 	uint8_t  ar_tpa[];	/* target protocol address */
 #endif
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ARP_HDR_ALIGNED_P(ah)	1
-#else
-#define	ARP_HDR_ALIGNED_P(ah)	((((vaddr_t) (ah)) & 3) == 0)
-#endif
+#define	ARP_HDR_ALIGNMENT	3
 #ifdef __CTASSERT
 __CTASSERT(sizeof(struct arphdr) == 8);
 #endif
Index: net/if_bridge.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_bridge.c,v
retrieving revision 1.177
diff -u -p -u -r1.177 if_bridge.c
--- net/if_bridge.c	2 Nov 2020 12:14:59 -0000	1.177
+++ net/if_bridge.c	14 Feb 2021 17:45:52 -0000
@@ -2806,18 +2806,10 @@ bridge_ip_checkbasic(struct mbuf **mp)
 	if (*mp == NULL)
 		return -1;
 
-	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(struct ip),
-			(max_linkhdr + 3) & ~3)) == NULL) {
-			/* XXXJRT new stat, please */
-			ip_statinc(IP_STAT_TOOSMALL);
-			goto bad;
-		}
-	} else if (__predict_false(m->m_len < sizeof (struct ip))) {
-		if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
-			ip_statinc(IP_STAT_TOOSMALL);
-			goto bad;
-		}
+	if (m_get_aligned_hdr(&m, IP_HDR_ALIGNMENT, sizeof(*ip), true) != 0) {
+		/* XXXJRT new stat, please */
+		ip_statinc(IP_STAT_TOOSMALL);
+		goto bad;
 	}
 	ip = mtod(m, struct ip *);
 	if (ip == NULL) goto bad;
@@ -2908,22 +2900,12 @@ bridge_ip6_checkbasic(struct mbuf **mp)
 	 * it.  Otherwise, if it is aligned, make sure the entire base
 	 * IPv6 header is in the first mbuf of the chain.
 	 */
-	if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
+	if (m_get_aligned_hdr(&m, IP6_HDR_ALIGNMENT, sizeof(*ip6), true) != 0) {
 		struct ifnet *inifp = m_get_rcvif_NOMPSAFE(m);
-		if ((m = m_copyup(m, sizeof(struct ip6_hdr),
-		                  (max_linkhdr + 3) & ~3)) == NULL) {
-			/* XXXJRT new stat, please */
-			ip6_statinc(IP6_STAT_TOOSMALL);
-			in6_ifstat_inc(inifp, ifs6_in_hdrerr);
-			goto bad;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
-		struct ifnet *inifp = m_get_rcvif_NOMPSAFE(m);
-		if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
-			ip6_statinc(IP6_STAT_TOOSMALL);
-			in6_ifstat_inc(inifp, ifs6_in_hdrerr);
-			goto bad;
-		}
+		/* XXXJRT new stat, please */
+		ip6_statinc(IP6_STAT_TOOSMALL);
+		in6_ifstat_inc(inifp, ifs6_in_hdrerr);
+		goto bad;
 	}
 
 	ip6 = mtod(m, struct ip6_hdr *);
Index: net/if_ether.h
===================================================================
RCS file: /cvsroot/src/sys/net/if_ether.h,v
retrieving revision 1.85
diff -u -p -u -r1.85 if_ether.h
--- net/if_ether.h	13 Feb 2021 07:28:04 -0000	1.85
+++ net/if_ether.h	14 Feb 2021 17:45:52 -0000
@@ -89,11 +89,7 @@ struct ether_header {
 	uint8_t  ether_shost[ETHER_ADDR_LEN];
 	uint16_t ether_type;
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ETHER_HDR_ALIGNED_P(eh)	1
-#else
-#define	ETHER_HDR_ALIGNED_P(eh)	((((vaddr_t) (eh)) & 3) == 0)
-#endif
+#define	ETHER_HDR_ALIGNMENT	3
 #ifdef __CTASSERT
 __CTASSERT(sizeof(struct ether_addr) == 6);
 __CTASSERT(sizeof(struct ether_header) == 14);
Index: net/if_ethersubr.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_ethersubr.c,v
retrieving revision 1.291
diff -u -p -u -r1.291 if_ethersubr.c
--- net/if_ethersubr.c	13 Feb 2021 13:00:16 -0000	1.291
+++ net/if_ethersubr.c	14 Feb 2021 17:45:53 -0000
@@ -654,13 +654,8 @@ ether_input(struct ifnet *ifp, struct mb
 #endif
 
 	/* Enforce alignement */
-	if (ETHER_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		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;
-	}
+	if (m_get_aligned_hdr(&m, ETHER_HDR_ALIGNMENT, sizeof(*eh), false) != 0)
+		goto dropped;
 
 	eh = mtod(m, struct ether_header *);
 	etype = ntohs(eh->ether_type);
Index: net/if_gre.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_gre.c,v
retrieving revision 1.179
diff -u -p -u -r1.179 if_gre.c
--- net/if_gre.c	13 Feb 2021 13:00:16 -0000	1.179
+++ net/if_gre.c	14 Feb 2021 17:45:53 -0000
@@ -397,19 +397,11 @@ gre_receive(struct socket *so, void *arg
 	}
 
 	/* Enforce alignment */
-	if (GRE_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		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++;
-			return;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct gre_h))) {
-		if ((m = m_pullup(m, sizeof(struct gre_h))) == NULL) {
-			GRE_DPRINTF(sc, "m_pullup failed\n");
-			sc->sc_pullup_ev.ev_count++;
-			return;
-		}
+	if (m_get_aligned_hdr(&m, GRE_HDR_ALIGNMENT, sizeof(*gh), false) != 0) {
+		/* XXXJRT new stat, please */
+		GRE_DPRINTF(sc, "m_copyup failed\n");
+		sc->sc_pullup_ev.ev_count++;
+		return;
 	}
 	gh = mtod(m, const struct gre_h *);
 
@@ -958,7 +950,7 @@ gre_output(struct ifnet *ifp, struct mbu
 	}
 
 	gh = mtod(m, struct gre_h *);
-	KASSERT(GRE_HDR_ALIGNED_P(gh));
+	KASSERT(POINTER_ALIGNED_P(gh, GRE_HDR_ALIGNMENT));
 	gh->flags = 0;
 	gh->ptype = etype;
 	/* XXX Need to handle IP ToS.  Look at how I handle IP TTL. */
Index: net/if_gre.h
===================================================================
RCS file: /cvsroot/src/sys/net/if_gre.h,v
retrieving revision 1.48
diff -u -p -u -r1.48 if_gre.h
--- net/if_gre.h	12 Feb 2021 19:57:49 -0000	1.48
+++ net/if_gre.h	14 Feb 2021 17:45:53 -0000
@@ -131,11 +131,7 @@ struct gre_h {
 				Present if (rt_pres == 1)
  */
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	GRE_HDR_ALIGNED_P(gh)	1
-#else
-#define	GRE_HDR_ALIGNED_P(gh)	((((vaddr_t) (gh)) & 3) == 0)
-#endif
+#define GRE_HDR_ALIGNMENT	3
 #ifdef __CTASSERT
 __CTASSERT(sizeof(struct gre_h) == 4);
 #endif
Index: netinet/icmp_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/icmp_private.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 icmp_private.h
--- netinet/icmp_private.h	28 Apr 2008 20:24:09 -0000	1.3
+++ netinet/icmp_private.h	14 Feb 2021 17:45:53 -0000
@@ -44,11 +44,7 @@ extern percpu_t *icmpstat_percpu;
 
 #define	ICMP_STATINC(x)		_NET_STATINC(icmpstat_percpu, x)
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ICMP_HDR_ALIGNED_P(ic)	1
-#else
-#define	ICMP_HDR_ALIGNED_P(ic)	((((vaddr_t) (ic)) & 3) == 0)
-#endif
+#define	ICMP_HDR_ALIGNMENT	3
 #endif /* _KERNEL_ */
 
 #endif /* !_NETINET_ICMP_PRIVATE_H_ */
Index: netinet/if_arp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/if_arp.c,v
retrieving revision 1.300
diff -u -p -u -r1.300 if_arp.c
--- netinet/if_arp.c	13 Feb 2021 13:00:16 -0000	1.300
+++ netinet/if_arp.c	14 Feb 2021 17:45:53 -0000
@@ -701,13 +701,9 @@ arpintr(void)
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
 		/* Enforce alignment */
-		if (ARP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-			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)
-				goto badlen;
-		}
+		if (m_get_aligned_hdr(&m, ARP_HDR_ALIGNMENT, sizeof(*ar),
+		    false) != 0)
+			goto badlen;
 		ar = mtod(m, struct arphdr *);
 
 		rcvif = m_get_rcvif(m, &s);
@@ -744,7 +740,7 @@ arpintr(void)
 			if ((m = m_pullup(m, arplen)) == NULL)
 				goto badlen;
 			ar = mtod(m, struct arphdr *);
-			KASSERT(ARP_HDR_ALIGNED_P(ar));
+			KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
 		}
 
 		switch (ntohs(ar->ar_pro)) {
Index: netinet/igmp_var.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/igmp_var.h,v
retrieving revision 1.25
diff -u -p -u -r1.25 igmp_var.h
--- netinet/igmp_var.h	14 Sep 2018 05:09:51 -0000	1.25
+++ netinet/igmp_var.h	14 Feb 2021 17:45:53 -0000
@@ -105,11 +105,7 @@
  */
 #define	IGMP_RANDOM_DELAY(X)	(cprng_fast32() % (X) + 1)
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	IGMP_HDR_ALIGNED_P(ig)	1
-#else
-#define	IGMP_HDR_ALIGNED_P(ig)	((((vaddr_t) (ig)) & 3) == 0)
-#endif
+#define	IGMP_HDR_ALIGNMENT	3
 
 void	igmp_init(void);
 void	igmp_input(struct mbuf *, int, int);
Index: netinet/in_l2tp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/in_l2tp.c,v
retrieving revision 1.18
diff -u -p -u -r1.18 in_l2tp.c
--- netinet/in_l2tp.c	29 Jan 2020 04:37:24 -0000	1.18
+++ netinet/in_l2tp.c	14 Feb 2021 17:45:53 -0000
@@ -197,13 +197,8 @@ in_l2tp_output(struct l2tp_variant *var,
 		error = ENOBUFS;
 		goto out;
 	}
-	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		m = m_copyup(m, sizeof(struct ip), 0);
-	} else {
-		if (m->m_len < sizeof(struct ip))
-			m = m_pullup(m, sizeof(struct ip));
-	}
-	if (m == NULL) {
+	if (m_get_aligned_hdr(&m, IP_HDR_ALIGNMENT, sizeof(iphdr), false) != 0)
+	{
 		error = ENOBUFS;
 		goto out;
 	}
Index: netinet/ip_flow.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_flow.c,v
retrieving revision 1.82
diff -u -p -u -r1.82 ip_flow.c
--- netinet/ip_flow.c	11 Apr 2018 08:29:19 -0000	1.82
+++ netinet/ip_flow.c	14 Feb 2021 17:45:53 -0000
@@ -230,9 +230,8 @@ ipflow_fastforward(struct mbuf *m)
 	/*
 	 * IP header with no option and valid version and length
 	 */
-	if (IP_HDR_ALIGNED_P(mtod(m, const void *)))
-		ip = mtod(m, struct ip *);
-	else {
+	ip = mtod(m, struct ip *);
+	if (!POINTER_ALIGNED_P(ip, IP_HDR_ALIGNMENT) {
 		memcpy(&ip_store, mtod(m, const void *), sizeof(ip_store));
 		ip = &ip_store;
 	}
@@ -314,7 +313,7 @@ ipflow_fastforward(struct mbuf *m)
 	 *
 	 * XXX Use m_copyback_cow(9) here? --dyoung
 	 */
-	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0)
+	if (!POINTER_ALIGNED_P(mtod(m, void *), IP_HDR_ALIGNMENT))
 		memcpy(mtod(m, void *), &ip_store, sizeof(ip_store));
 
 	/*
Index: netinet/ip_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_input.c,v
retrieving revision 1.397
diff -u -p -u -r1.397 ip_input.c
--- netinet/ip_input.c	28 Aug 2020 06:31:42 -0000	1.397
+++ netinet/ip_input.c	14 Feb 2021 17:45:53 -0000
@@ -454,18 +454,10 @@ ip_input(struct mbuf *m, struct ifnet *i
 	 * it.  Otherwise, if it is aligned, make sure the entire
 	 * base IP header is in the first mbuf of the chain.
 	 */
-	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(struct ip),
-		    (max_linkhdr + 3) & ~3)) == NULL) {
-			/* XXXJRT new stat, please */
-			IP_STATINC(IP_STAT_TOOSMALL);
-			goto out;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct ip))) {
-		if ((m = m_pullup(m, sizeof(struct ip))) == NULL) {
-			IP_STATINC(IP_STAT_TOOSMALL);
-			goto out;
-		}
+	if (m_get_aligned_hdr(&m, IP_HDR_ALIGNMENT, sizeof(*ip), true) != 0) {
+		/* XXXJRT new stat, please */
+		IP_STATINC(IP_STAT_TOOSMALL);
+		goto out;
 	}
 	ip = mtod(m, struct ip *);
 	if (ip->ip_v != IPVERSION) {
Index: netinet/ip_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_private.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 ip_private.h
--- netinet/ip_private.h	28 Apr 2008 20:24:09 -0000	1.3
+++ netinet/ip_private.h	14 Feb 2021 17:45:53 -0000
@@ -43,11 +43,7 @@ extern	percpu_t *ipstat_percpu;
 #define	IP_STATINC(x)		_NET_STATINC(ipstat_percpu, x)
 #define	IP_STATDEC(x)		_NET_STATDEC(ipstat_percpu, x)
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	IP_HDR_ALIGNED_P(ip)	1
-#else
-#define	IP_HDR_ALIGNED_P(ip)	((((vaddr_t) (ip)) & 3) == 0)
-#endif
+#define	IP_HDR_ALIGNMENT	3
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_IP_PRIVATE_H_ */
Index: netinet/tcp_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/tcp_input.c,v
retrieving revision 1.424
diff -u -p -u -r1.424 tcp_input.c
--- netinet/tcp_input.c	29 Sep 2020 02:58:53 -0000	1.424
+++ netinet/tcp_input.c	14 Feb 2021 17:45:53 -0000
@@ -1274,7 +1274,7 @@ tcp_input(struct mbuf *m, int off, int p
 	 * Enforce alignment requirements that are violated in
 	 * some cases, see kern/50766 for details.
 	 */
-	if (TCP_HDR_ALIGNED_P(th) == 0) {
+	if (POINTER_ALIGNED_P(th, TCP_HDR_ALIGNMENT) == 0) {
 		m = m_copyup(m, off + sizeof(struct tcphdr), 0);
 		if (m == NULL) {
 			TCP_STATINC(TCP_STAT_RCVSHORT);
@@ -1282,7 +1282,7 @@ tcp_input(struct mbuf *m, int off, int p
 		}
 		th = (struct tcphdr *)(mtod(m, char *) + off);
 	}
-	KASSERT(TCP_HDR_ALIGNED_P(th));
+	KASSERT(POINTER_ALIGNED_P(th, TCP_HDR_ALIGNMENT));
 
 	/*
 	 * Get IP and TCP header.
@@ -1362,7 +1362,7 @@ tcp_input(struct mbuf *m, int off, int p
 			TCP_STATINC(TCP_STAT_RCVSHORT);
 			return;
 		}
-		KASSERT(TCP_HDR_ALIGNED_P(th));
+		KASSERT(POINTER_ALIGNED_P(th, TCP_HDR_ALIGNMENT));
 		optlen = thlen - sizeof(struct tcphdr);
 		optp = ((u_int8_t *)th) + sizeof(struct tcphdr);
 
Index: netinet/tcp_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/tcp_private.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 tcp_private.h
--- netinet/tcp_private.h	28 Apr 2008 20:24:09 -0000	1.3
+++ netinet/tcp_private.h	14 Feb 2021 17:45:53 -0000
@@ -43,11 +43,7 @@ extern	percpu_t *tcpstat_percpu;
 #define	TCP_STATINC(x)		_NET_STATINC(tcpstat_percpu, x)
 #define	TCP_STATADD(x, v)	_NET_STATADD(tcpstat_percpu, x, v)
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	TCP_HDR_ALIGNED_P(th)	1
-#else
-#define	TCP_HDR_ALIGNED_P(th)	((((vaddr_t)(th)) & 3) == 0)
-#endif /* __NO_STRICT_ALIGNMENT */
+#define	TCP_HDR_ALIGNMENT	3
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_TCP_PRIVATE_H_ */
Index: netinet/udp_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/udp_private.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 udp_private.h
--- netinet/udp_private.h	28 Apr 2008 20:24:09 -0000	1.3
+++ netinet/udp_private.h	14 Feb 2021 17:45:53 -0000
@@ -39,11 +39,7 @@ extern	percpu_t *udpstat_percpu;
 
 #define	UDP_STATINC(x)		_NET_STATINC(udpstat_percpu, x)
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	UDP_HDR_ALIGNED_P(uh)	1
-#else
-#define	UDP_HDR_ALIGNED_P(uh)	((((vaddr_t) (uh)) & 3) == 0)
-#endif
+#define	UDP_HDR_ALIGNMENT	3
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_UDP_PRIVATE_H_ */
Index: netinet/udp_usrreq.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.259
diff -u -p -u -r1.259 udp_usrreq.c
--- netinet/udp_usrreq.c	20 Aug 2020 21:21:32 -0000	1.259
+++ netinet/udp_usrreq.c	14 Feb 2021 17:45:53 -0000
@@ -335,7 +335,7 @@ udp_input(struct mbuf *m, int off, int p
 	 * Enforce alignment requirements that are violated in
 	 * some cases, see kern/50766 for details.
 	 */
-	if (UDP_HDR_ALIGNED_P(uh) == 0) {
+	if (POINTER_ALIGNED_P(uh, UDP_HDR_ALIGNMENT) == 0) {
 		m = m_copyup(m, iphlen + sizeof(struct udphdr), 0);
 		if (m == NULL) {
 			UDP_STATINC(UDP_STAT_HDROPS);
@@ -344,7 +344,7 @@ udp_input(struct mbuf *m, int off, int p
 		ip = mtod(m, struct ip *);
 		uh = (struct udphdr *)(mtod(m, char *) + iphlen);
 	}
-	KASSERT(UDP_HDR_ALIGNED_P(uh));
+	KASSERT(POINTER_ALIGNED_P(uh, UDP_HDR_ALIGNMENT));
 
 	/* destination port of 0 is illegal, based on RFC768. */
 	if (uh->uh_dport == 0)
Index: netinet6/icmp6.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/icmp6.c,v
retrieving revision 1.247
diff -u -p -u -r1.247 icmp6.c
--- netinet6/icmp6.c	11 Sep 2020 15:03:33 -0000	1.247
+++ netinet6/icmp6.c	14 Feb 2021 17:45:53 -0000
@@ -538,7 +538,7 @@ _icmp6_input(struct mbuf *m, int off, in
 	 * Enforce alignment requirements that are violated in
 	 * some cases, see kern/50766 for details.
 	 */
-	if (IP6_HDR_ALIGNED_P(icmp6) == 0) {
+	if (POINTER_ALIGNED_P(icmp6, ICMP6_HDR_ALIGNMENT) == 0) {
 		m = m_copyup(m, off + sizeof(struct icmp6_hdr), 0);
 		if (m == NULL) {
 			ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
@@ -548,7 +548,7 @@ _icmp6_input(struct mbuf *m, int off, in
 		ip6 = mtod(m, struct ip6_hdr *);
 		icmp6 = (struct icmp6_hdr *)(mtod(m, char *) + off);
 	}
-	KASSERT(IP6_HDR_ALIGNED_P(icmp6));
+	KASSERT(POINTER_ALIGNED_P(icmp6, ICMP6_HDR_ALIGNMENT));
 
 	/*
 	 * calculate the checksum
Index: netinet6/in6_l2tp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/in6_l2tp.c,v
retrieving revision 1.19
diff -u -p -u -r1.19 in6_l2tp.c
--- netinet6/in6_l2tp.c	29 Jan 2020 04:38:06 -0000	1.19
+++ netinet6/in6_l2tp.c	14 Feb 2021 17:45:53 -0000
@@ -58,6 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v
 
 #include <netinet/ip6.h>
 #include <netinet6/ip6_var.h>
+#include <netinet6/ip6_private.h>
 #include <netinet6/in6_l2tp.h>
 
 #ifdef ALTQ
@@ -192,13 +193,8 @@ in6_l2tp_output(struct l2tp_variant *var
 	M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT);
 	if (m == NULL)
 		return ENOBUFS;
-	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		m = m_copyup(m, sizeof(struct ip), 0);
-	} else {
-		if (m->m_len < sizeof(struct ip6_hdr))
-			m = m_pullup(m, sizeof(struct ip6_hdr));
-	}
-	if (m == NULL)
+	if (m_get_aligned_hdr(&m, IP6_HDR_ALIGNMENT, sizeof(ip6hdr),
+	    false) != 0)
 		return ENOBUFS;
 	memcpy(mtod(m, struct ip6_hdr *), &ip6hdr, sizeof(struct ip6_hdr));
 
Index: netinet6/ip6_flow.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6_flow.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 ip6_flow.c
--- netinet6/ip6_flow.c	6 Feb 2018 03:37:00 -0000	1.40
+++ netinet6/ip6_flow.c	14 Feb 2021 17:45:53 -0000
@@ -283,7 +283,7 @@ ip6flow_fastforward(struct mbuf **mp)
 	if ((m->m_flags & (M_BCAST|M_MCAST)) != 0)
 		goto out;
 
-	if (IP6_HDR_ALIGNED_P(mtod(m, const void *)) == 0) {
+	if (POINTER_ALIGNED_P(mtod(m, const void *), IP6_HDR_ALIGNMENT) == 0) {
 		if ((m = m_copyup(m, sizeof(struct ip6_hdr),
 		    (max_linkhdr + 3) & ~3)) == NULL) {
 			ret = 1;
Index: netinet6/ip6_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6_input.c,v
retrieving revision 1.222
diff -u -p -u -r1.222 ip6_input.c
--- netinet6/ip6_input.c	28 Aug 2020 06:32:24 -0000	1.222
+++ netinet6/ip6_input.c	14 Feb 2021 17:45:53 -0000
@@ -301,20 +301,11 @@ ip6_input(struct mbuf *m, struct ifnet *
 	 * it.  Otherwise, if it is aligned, make sure the entire base
 	 * IPv6 header is in the first mbuf of the chain.
 	 */
-	if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(struct ip6_hdr),
-		    (max_linkhdr + 3) & ~3)) == NULL) {
-			/* XXXJRT new stat, please */
-			IP6_STATINC(IP6_STAT_TOOSMALL);
-			in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
-			return;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
-		if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
-			IP6_STATINC(IP6_STAT_TOOSMALL);
-			in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
-			return;
-		}
+	if (m_get_aligned_hdr(&m, IP6_HDR_ALIGNMENT, sizeof(*ip6), true) != 0) {
+		/* XXXJRT new stat, please */
+		IP6_STATINC(IP6_STAT_TOOSMALL);
+		in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
+		return;
 	}
 
 	ip6 = mtod(m, struct ip6_hdr *);
@@ -611,7 +602,7 @@ hbhcheck:
 			rtcache_percpu_putref(ip6_forward_rt_percpu);
 			return;
 		}
-		KASSERT(IP6_HDR_ALIGNED_P(hbh));
+		KASSERT(POINTER_ALIGNED_P(hbh, IP6_HDR_ALIGNMENT));
 		nxt = hbh->ip6h_nxt;
 
 		/*
@@ -884,7 +875,7 @@ ip6_hopopts_input(u_int32_t *plenp, u_in
 		IP6_STATINC(IP6_STAT_TOOSHORT);
 		return -1;
 	}
-	KASSERT(IP6_HDR_ALIGNED_P(hbh));
+	KASSERT(POINTER_ALIGNED_P(hbh, IP6_HDR_ALIGNMENT));
 	off += hbhlen;
 	hbhlen -= sizeof(struct ip6_hbh);
 
@@ -1224,7 +1215,7 @@ ip6_savecontrol(struct in6pcb *in6p, str
 				IP6_STATINC(IP6_STAT_TOOSHORT);
 				return;
 			}
-			KASSERT(IP6_HDR_ALIGNED_P(ip6e));
+			KASSERT(POINTER_ALIGNED_P(ip6e, IP6_HDR_ALIGNMENT));
 
 			switch (nxt) {
 			case IPPROTO_DSTOPTS:
Index: netinet6/ip6_private.h
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6_private.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 ip6_private.h
--- netinet6/ip6_private.h	28 Apr 2008 20:24:10 -0000	1.3
+++ netinet6/ip6_private.h	14 Feb 2021 17:45:53 -0000
@@ -43,11 +43,7 @@ extern	percpu_t *ip6stat_percpu;
 #define	IP6_STATINC(x)		_NET_STATINC(ip6stat_percpu, x)
 #define	IP6_STATDEC(x)		_NET_STATDEC(ip6stat_percpu, x)
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	IP6_HDR_ALIGNED_P(ip)	1
-#else
-#define	IP6_HDR_ALIGNED_P(ip)	((((vaddr_t) (ip)) & 3) == 0)
-#endif
+#define	IP6_HDR_ALIGNMENT	3
 #endif /* _KERNEL */
 
 #endif /* !_NETINET_IP6_PRIVATE_H_ */
Index: netinet6/udp6_usrreq.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/udp6_usrreq.c,v
retrieving revision 1.148
diff -u -p -u -r1.148 udp6_usrreq.c
--- netinet6/udp6_usrreq.c	20 Aug 2020 21:21:32 -0000	1.148
+++ netinet6/udp6_usrreq.c	14 Feb 2021 17:45:53 -0000
@@ -665,7 +665,7 @@ udp6_input(struct mbuf **mp, int *offp, 
 	 * Enforce alignment requirements that are violated in
 	 * some cases, see kern/50766 for details.
 	 */
-	if (UDP_HDR_ALIGNED_P(uh) == 0) {
+	if (POINTER_ALIGNED_P(uh, UDP_HDR_ALIGNMENT) == 0) {
 		m = m_copyup(m, off + sizeof(struct udphdr), 0);
 		if (m == NULL) {
 			IP6_STATINC(IP6_STAT_TOOSHORT);
@@ -674,7 +674,7 @@ udp6_input(struct mbuf **mp, int *offp, 
 		ip6 = mtod(m, struct ip6_hdr *);
 		uh = (struct udphdr *)(mtod(m, char *) + off);
 	}
-	KASSERT(UDP_HDR_ALIGNED_P(uh));
+	KASSERT(POINTER_ALIGNED_P(uh, UDP_HDR_ALIGNMENT));
 	ulen = ntohs((u_short)uh->uh_ulen);
 
 	/*
Index: sys/mbuf.h
===================================================================
RCS file: /cvsroot/src/sys/sys/mbuf.h,v
retrieving revision 1.227
diff -u -p -u -r1.227 mbuf.h
--- sys/mbuf.h	6 Apr 2020 09:32:54 -0000	1.227
+++ sys/mbuf.h	14 Feb 2021 17:45:53 -0000
@@ -843,6 +843,17 @@ m_copy_rcvif(struct mbuf *m, const struc
 	m->m_pkthdr.rcvif_index = n->m_pkthdr.rcvif_index;
 }
 
+static __inline int
+m_get_aligned_hdr(struct mbuf **_m, int _align, size_t _hlen, bool _linkhdr)
+{
+	if (POINTER_ALIGNED_P(mtod(*_m, void *), _align) == 0)
+		*_m = m_copyup(*_m, _hlen, 
+		      _linkhdr ? (max_linkhdr + _align) & ~_align : 0);
+	else if (__predict_false((*_m)->m_len < _hlen))
+		*_m = m_pullup(*_m, _hlen);
+	return *_m == NULL;
+}
+
 void m_print(const struct mbuf *, const char *, void (*)(const char *, ...)
     __printflike(1, 2));
 
Index: sys/param.h
===================================================================
RCS file: /cvsroot/src/sys/sys/param.h,v
retrieving revision 1.684
diff -u -p -u -r1.684 param.h
--- sys/param.h	5 Feb 2021 17:03:35 -0000	1.684
+++ sys/param.h	14 Feb 2021 17:45:53 -0000
@@ -287,6 +287,12 @@
 #define	ALIGNED_POINTER_LOAD(q,p,t)	(*(q) = *((const t *)(p)))
 #endif
 
+#ifdef __NO_STRICT_ALIGNMENT
+#define	POINTER_ALIGNED_P(p, a)		1
+#else
+#define	POINTER_ALIGNED_P(p, a)		(((uintptr_t)(p) + (a)) & ~(a))
+#endif
+
 /*
  * Historic priority levels.  These are meaningless and remain only
  * for source compatibility.  Do not use in new code.