- centralize header align and pullup into a single inline function
- use a single macro to align pointers and expose the alignment, instead of hard-coding 3 in 1/2 the macros. - fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling for ipv6.
This commit is contained in:
parent
aa7e1ebfd6
commit
9183889817
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_arp.h,v 1.39 2021/02/14 19:47:16 roy Exp $ */
|
||||
/* $NetBSD: if_arp.h,v 1.40 2021/02/14 20:58:34 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1986, 1993
|
||||
|
@ -72,6 +72,7 @@ struct arphdr {
|
|||
uint8_t ar_tpa[]; /* target protocol address */
|
||||
#endif
|
||||
};
|
||||
#define ARP_HDR_ALIGNMENT 3
|
||||
|
||||
static __inline uint8_t *
|
||||
ar_data(struct arphdr *ap)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_bridge.c,v 1.177 2020/11/02 12:14:59 roy Exp $ */
|
||||
/* $NetBSD: if_bridge.c,v 1.178 2021/02/14 20:58:34 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
|
@ -80,7 +80,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.177 2020/11/02 12:14:59 roy Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.178 2021/02/14 20:58:34 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_inet.h"
|
||||
|
@ -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 *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: icmp_private.h,v 1.3 2008/04/28 20:24:09 martin Exp $ */
|
||||
/* $NetBSD: icmp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -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_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_arp.c,v 1.301 2021/02/14 19:47:17 roy Exp $ */
|
||||
/* $NetBSD: if_arp.c,v 1.302 2021/02/14 20:58:35 christos 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.301 2021/02/14 19:47:17 roy Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.302 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_ddb.h"
|
||||
|
@ -712,7 +712,7 @@ arpintr(void)
|
|||
goto badlen;
|
||||
}
|
||||
ar = mtod(m, struct arphdr *);
|
||||
KASSERT(ARP_HDR_ALIGNED_P(ar));
|
||||
KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
|
||||
|
||||
rcvif = m_get_rcvif(m, &s);
|
||||
if (__predict_false(rcvif == NULL)) {
|
||||
|
@ -741,7 +741,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)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: igmp_var.h,v 1.25 2018/09/14 05:09:51 maxv Exp $ */
|
||||
/* $NetBSD: igmp_var.h,v 1.26 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: in_l2tp.c,v 1.18 2020/01/29 04:37:24 thorpej Exp $ */
|
||||
/* $NetBSD: in_l2tp.c,v 1.19 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Internet Initiative Japan Inc.
|
||||
|
@ -27,7 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.18 2020/01/29 04:37:24 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.19 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_l2tp.h"
|
||||
|
@ -197,13 +197,8 @@ in_l2tp_output(struct l2tp_variant *var, struct mbuf *m)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ip_flow.c,v 1.82 2018/04/11 08:29:19 maxv Exp $ */
|
||||
/* $NetBSD: ip_flow.c,v 1.83 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.82 2018/04/11 08:29:19 maxv Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.83 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_net_mpsafe.h"
|
||||
|
@ -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));
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ip_input.c,v 1.397 2020/08/28 06:31:42 ozaki-r Exp $ */
|
||||
/* $NetBSD: ip_input.c,v 1.398 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
|
@ -91,7 +91,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.397 2020/08/28 06:31:42 ozaki-r Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.398 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_inet.h"
|
||||
|
@ -454,18 +454,10 @@ ip_input(struct mbuf *m, struct ifnet *ifp)
|
|||
* 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) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ip_private.h,v 1.3 2008/04/28 20:24:09 martin Exp $ */
|
||||
/* $NetBSD: ip_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -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_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tcp_input.c,v 1.424 2020/09/29 02:58:53 msaitoh Exp $ */
|
||||
/* $NetBSD: tcp_input.c,v 1.425 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
|
@ -148,7 +148,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.424 2020/09/29 02:58:53 msaitoh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.425 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_inet.h"
|
||||
|
@ -1274,7 +1274,7 @@ tcp_input(struct mbuf *m, int off, int proto)
|
|||
* 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 proto)
|
|||
}
|
||||
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 proto)
|
|||
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);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tcp_private.h,v 1.3 2008/04/28 20:24:09 martin Exp $ */
|
||||
/* $NetBSD: tcp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -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_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: udp_private.h,v 1.3 2008/04/28 20:24:09 martin Exp $ */
|
||||
/* $NetBSD: udp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -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_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: udp_usrreq.c,v 1.259 2020/08/20 21:21:32 riastradh Exp $ */
|
||||
/* $NetBSD: udp_usrreq.c,v 1.260 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
|
@ -66,7 +66,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.259 2020/08/20 21:21:32 riastradh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.260 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_inet.h"
|
||||
|
@ -335,7 +335,7 @@ udp_input(struct mbuf *m, int off, int proto)
|
|||
* 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 proto)
|
|||
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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: icmp6.c,v 1.247 2020/09/11 15:03:33 roy Exp $ */
|
||||
/* $NetBSD: icmp6.c,v 1.248 2021/02/14 20:58:35 christos Exp $ */
|
||||
/* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -62,7 +62,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.247 2020/09/11 15:03:33 roy Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.248 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -538,7 +538,7 @@ _icmp6_input(struct mbuf *m, int off, int proto)
|
|||
* 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, int proto)
|
|||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: in6_l2tp.c,v 1.19 2020/01/29 04:38:06 thorpej Exp $ */
|
||||
/* $NetBSD: in6_l2tp.c,v 1.20 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Internet Initiative Japan Inc.
|
||||
|
@ -27,7 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.19 2020/01/29 04:38:06 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.20 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_l2tp.h"
|
||||
|
@ -58,6 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.19 2020/01/29 04:38:06 thorpej Exp $"
|
|||
|
||||
#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, struct mbuf *m)
|
|||
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));
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ip6_flow.c,v 1.40 2018/02/06 03:37:00 ozaki-r Exp $ */
|
||||
/* $NetBSD: ip6_flow.c,v 1.41 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.40 2018/02/06 03:37:00 ozaki-r Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.41 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_net_mpsafe.h"
|
||||
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ip6_input.c,v 1.222 2020/08/28 06:32:24 ozaki-r Exp $ */
|
||||
/* $NetBSD: ip6_input.c,v 1.223 2021/02/14 20:58:35 christos Exp $ */
|
||||
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -62,7 +62,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.222 2020/08/28 06:32:24 ozaki-r Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.223 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_gateway.h"
|
||||
|
@ -301,20 +301,11 @@ ip6_input(struct mbuf *m, struct ifnet *rcvif)
|
|||
* 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_int32_t *rtalertp,
|
|||
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, struct mbuf **mp,
|
|||
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:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ip6_private.h,v 1.3 2008/04/28 20:24:10 martin Exp $ */
|
||||
/* $NetBSD: ip6_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -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_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: udp6_usrreq.c,v 1.148 2020/08/20 21:21:32 riastradh Exp $ */
|
||||
/* $NetBSD: udp6_usrreq.c,v 1.149 2021/02/14 20:58:35 christos Exp $ */
|
||||
/* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
|
||||
/* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
|
||||
|
||||
|
@ -63,7 +63,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.148 2020/08/20 21:21:32 riastradh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.149 2021/02/14 20:58:35 christos Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_inet.h"
|
||||
|
@ -665,7 +665,7 @@ udp6_input(struct mbuf **mp, int *offp, int proto)
|
|||
* 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, int proto)
|
|||
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);
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mbuf.h,v 1.227 2020/04/06 09:32:54 jdolecek Exp $ */
|
||||
/* $NetBSD: mbuf.h,v 1.228 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -843,6 +843,17 @@ m_copy_rcvif(struct mbuf *m, const struct mbuf *n)
|
|||
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));
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: param.h,v 1.684 2021/02/05 17:03:35 thorpej Exp $ */
|
||||
/* $NetBSD: param.h,v 1.685 2021/02/14 20:58:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue