summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2021-02-17 22:32:04 +0000
committerchristos <christos@NetBSD.org>2021-02-17 22:32:04 +0000
commit32f6d56abd9ec4fdb65ca89352f5b9775f7bc5ee (patch)
tree4f17cf36a15a537591268e2d0b3dad414ca9259a /sys
parent23754a6e6cf98a6df90b2f47af1dd0251cfbbdc8 (diff)
- pass the alignment instead of the mask (as Roy asked and to match the
other macro) - use alignof to determine that alignment and CTASSERT what we expect - remove unused macros
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_arp.h5
-rw-r--r--sys/netinet/icmp_private.h3
-rw-r--r--sys/netinet/igmp_var.h4
-rw-r--r--sys/netinet/ip_private.h5
-rw-r--r--sys/netinet/tcp_private.h5
-rw-r--r--sys/netinet/udp_private.h5
-rw-r--r--sys/netinet6/ip6_private.h5
-rw-r--r--sys/sys/mbuf.h7
-rw-r--r--sys/sys/param.h4
9 files changed, 23 insertions, 20 deletions
diff --git a/sys/net/if_arp.h b/sys/net/if_arp.h
index 9fbf9c43f55..3a9451bb53b 100644
--- a/sys/net/if_arp.h
+++ b/sys/net/if_arp.h
@@ -1,4 +1,4 @@
-/* $NetBSD: if_arp.h,v 1.41 2021/02/16 10:20:56 martin Exp $ */
+/* $NetBSD: if_arp.h,v 1.42 2021/02/17 22:32:04 christos Exp $ */
/*
* Copyright (c) 1986, 1993
@@ -72,7 +72,8 @@ struct arphdr {
uint8_t ar_tpa[]; /* target protocol address */
#endif
};
-#define ARP_HDR_ALIGNMENT 1
+#define ARP_HDR_ALIGNMENT __alignof(struct arphdr)
+__CTASSERT(ARP_HDR_ALIGNMENT == 2);
static __inline uint8_t *
ar_data(struct arphdr *ap)
diff --git a/sys/netinet/icmp_private.h b/sys/netinet/icmp_private.h
index 447e8500b6c..183c38848c0 100644
--- a/sys/netinet/icmp_private.h
+++ b/sys/netinet/icmp_private.h
@@ -1,4 +1,4 @@
-/* $NetBSD: icmp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: icmp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -44,7 +44,6 @@ extern percpu_t *icmpstat_percpu;
#define ICMP_STATINC(x) _NET_STATINC(icmpstat_percpu, x)
-#define ICMP_HDR_ALIGNMENT 3
#endif /* _KERNEL_ */
#endif /* !_NETINET_ICMP_PRIVATE_H_ */
diff --git a/sys/netinet/igmp_var.h b/sys/netinet/igmp_var.h
index f5a812100f4..fd0413b9388 100644
--- a/sys/netinet/igmp_var.h
+++ b/sys/netinet/igmp_var.h
@@ -1,4 +1,4 @@
-/* $NetBSD: igmp_var.h,v 1.26 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: igmp_var.h,v 1.27 2021/02/17 22:32:04 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -105,8 +105,6 @@
*/
#define IGMP_RANDOM_DELAY(X) (cprng_fast32() % (X) + 1)
-#define IGMP_HDR_ALIGNMENT 3
-
void igmp_init(void);
void igmp_input(struct mbuf *, int, int);
int igmp_joingroup(struct in_multi *);
diff --git a/sys/netinet/ip_private.h b/sys/netinet/ip_private.h
index 790ea188955..8fd927fd593 100644
--- a/sys/netinet/ip_private.h
+++ b/sys/netinet/ip_private.h
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: ip_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,7 +43,8 @@ extern percpu_t *ipstat_percpu;
#define IP_STATINC(x) _NET_STATINC(ipstat_percpu, x)
#define IP_STATDEC(x) _NET_STATDEC(ipstat_percpu, x)
-#define IP_HDR_ALIGNMENT 3
+#define IP_HDR_ALIGNMENT __alignof(struct ip)
+__CTASSERT(IP_HDR_ALIGNMENT == 4);
#endif /* _KERNEL */
#endif /* !_NETINET_IP_PRIVATE_H_ */
diff --git a/sys/netinet/tcp_private.h b/sys/netinet/tcp_private.h
index b4d1ebd7db5..0b85e8ed7da 100644
--- a/sys/netinet/tcp_private.h
+++ b/sys/netinet/tcp_private.h
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: tcp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,7 +43,8 @@ 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)
-#define TCP_HDR_ALIGNMENT 3
+#define TCP_HDR_ALIGNMENT __alignof(struct tcphdr)
+__CTASSERT(TCP_HDR_ALIGNMENT == 4);
#endif /* _KERNEL */
#endif /* !_NETINET_TCP_PRIVATE_H_ */
diff --git a/sys/netinet/udp_private.h b/sys/netinet/udp_private.h
index 7ab6d132db8..283ec39ba0d 100644
--- a/sys/netinet/udp_private.h
+++ b/sys/netinet/udp_private.h
@@ -1,4 +1,4 @@
-/* $NetBSD: udp_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: udp_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -39,7 +39,8 @@ extern percpu_t *udpstat_percpu;
#define UDP_STATINC(x) _NET_STATINC(udpstat_percpu, x)
-#define UDP_HDR_ALIGNMENT 3
+#define UDP_HDR_ALIGNMENT __alignof(struct udphdr)
+__CTASSERT(UDP_HDR_ALIGNMENT == 2);
#endif /* _KERNEL */
#endif /* !_NETINET_UDP_PRIVATE_H_ */
diff --git a/sys/netinet6/ip6_private.h b/sys/netinet6/ip6_private.h
index 4edceebd29d..7ea19b01db1 100644
--- a/sys/netinet6/ip6_private.h
+++ b/sys/netinet6/ip6_private.h
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_private.h,v 1.4 2021/02/14 20:58:35 christos Exp $ */
+/* $NetBSD: ip6_private.h,v 1.5 2021/02/17 22:32:04 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -43,7 +43,8 @@ extern percpu_t *ip6stat_percpu;
#define IP6_STATINC(x) _NET_STATINC(ip6stat_percpu, x)
#define IP6_STATDEC(x) _NET_STATDEC(ip6stat_percpu, x)
-#define IP6_HDR_ALIGNMENT 3
+#define IP6_HDR_ALIGNMENT __alignof(struct ip6_hdr)
+__CTASSERT(IP6_HDR_ALIGNMENT == 4);
#endif /* _KERNEL */
#endif /* !_NETINET_IP6_PRIVATE_H_ */
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index cf0c3040933..15c931dbefd 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.230 2021/02/15 09:29:56 kre Exp $ */
+/* $NetBSD: mbuf.h,v 1.231 2021/02/17 22:32:04 christos Exp $ */
/*
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -846,10 +846,11 @@ m_copy_rcvif(struct mbuf *m, const struct mbuf *n)
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)
+ if (POINTER_ALIGNED_P(mtod(*m, void *), align) == 0) {
+ --align; // Turn into mask
*m = m_copyup(*m, hlen,
linkhdr ? (max_linkhdr + align) & ~align : 0);
- else if (__predict_false((size_t)(*m)->m_len < hlen))
+ } else if (__predict_false((size_t)(*m)->m_len < hlen))
*m = m_pullup(*m, hlen);
return *m == NULL;
}
diff --git a/sys/sys/param.h b/sys/sys/param.h
index ad9358090c7..22e4bd4cd81 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.688 2021/02/15 19:46:53 christos Exp $ */
+/* $NetBSD: param.h,v 1.689 2021/02/17 22:32:04 christos Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -290,7 +290,7 @@
#ifdef __NO_STRICT_ALIGNMENT
#define POINTER_ALIGNED_P(p, a) 1
#else
-#define POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & (a)) == 0)
+#define POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & ((a) - 1)) == 0)
#endif
/*