Module Name: src
Committed By: roy
Date: Mon Jul 27 14:06:58 UTC 2020
Modified Files:
src/sys/netinet: ip6.h
src/sys/netinet6: ip6_input.c
Log Message:
ip6: Remove __packed attribute from ip6 structures
They should naturally align.
Add compile time assertations to ip6_input.c to prove this.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/netinet/ip6.h
cvs rdiff -u -r1.217 -r1.218 src/sys/netinet6/ip6_input.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/netinet/ip6.h
diff -u src/sys/netinet/ip6.h:1.25 src/sys/netinet/ip6.h:1.26
--- src/sys/netinet/ip6.h:1.25 Fri May 18 18:52:17 2018
+++ src/sys/netinet/ip6.h Mon Jul 27 14:06:58 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6.h,v 1.25 2018/05/18 18:52:17 maxv Exp $ */
+/* $NetBSD: ip6.h,v 1.26 2020/07/27 14:06:58 roy Exp $ */
/* $KAME: ip6.h,v 1.45 2003/06/05 04:46:38 keiichi Exp $ */
/*
@@ -81,7 +81,7 @@ struct ip6_hdr {
} ip6_ctlun;
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */
-} __packed;
+};
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
@@ -129,21 +129,21 @@ struct ip6_hdr_pseudo {
struct ip6_ext {
u_int8_t ip6e_nxt;
u_int8_t ip6e_len;
-} __packed;
+};
/* Hop-by-Hop options header */
struct ip6_hbh {
u_int8_t ip6h_nxt; /* next header */
u_int8_t ip6h_len; /* length in units of 8 octets */
/* followed by options */
-} __packed;
+};
/* Destination options header */
struct ip6_dest {
u_int8_t ip6d_nxt; /* next header */
u_int8_t ip6d_len; /* length in units of 8 octets */
/* followed by options */
-} __packed;
+};
/* Option types and related macros */
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
@@ -172,14 +172,14 @@ struct ip6_dest {
struct ip6_opt {
u_int8_t ip6o_type;
u_int8_t ip6o_len;
-} __packed;
+};
/* Jumbo Payload Option */
struct ip6_opt_jumbo {
u_int8_t ip6oj_type;
u_int8_t ip6oj_len;
u_int8_t ip6oj_jumbo_len[4];
-} __packed;
+};
#define IP6OPT_JUMBO_LEN 6
/* NSAP Address Option */
@@ -190,21 +190,21 @@ struct ip6_opt_nsap {
u_int8_t ip6on_dst_nsap_len;
/* followed by source NSAP */
/* followed by destination NSAP */
-} __packed;
+};
/* Tunnel Limit Option */
struct ip6_opt_tunnel {
u_int8_t ip6ot_type;
u_int8_t ip6ot_len;
u_int8_t ip6ot_encap_limit;
-} __packed;
+};
/* Router Alert Option */
struct ip6_opt_router {
u_int8_t ip6or_type;
u_int8_t ip6or_len;
u_int8_t ip6or_value[2];
-} __packed;
+};
/* Router alert values (in network byte order) */
#if BYTE_ORDER == BIG_ENDIAN
#define IP6_ALERT_MLD 0x0000
@@ -225,7 +225,7 @@ struct ip6_rthdr {
u_int8_t ip6r_type; /* routing type */
u_int8_t ip6r_segleft; /* segments left */
/* followed by routing type specific data */
-} __packed;
+};
/* Type 0 Routing header */
struct ip6_rthdr0 {
@@ -234,7 +234,7 @@ struct ip6_rthdr0 {
u_int8_t ip6r0_type; /* always zero */
u_int8_t ip6r0_segleft; /* segments left */
u_int32_t ip6r0_reserved; /* reserved field */
-} __packed;
+};
/* Fragment header */
struct ip6_frag {
@@ -242,7 +242,7 @@ struct ip6_frag {
u_int8_t ip6f_reserved; /* reserved field */
u_int16_t ip6f_offlg; /* offset, reserved, and flag */
u_int32_t ip6f_ident; /* identification */
-} __packed;
+};
#if BYTE_ORDER == BIG_ENDIAN
#define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.217 src/sys/netinet6/ip6_input.c:1.218
--- src/sys/netinet6/ip6_input.c:1.217 Fri Jun 19 16:08:06 2020
+++ src/sys/netinet6/ip6_input.c Mon Jul 27 14:06:58 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_input.c,v 1.217 2020/06/19 16:08:06 maxv Exp $ */
+/* $NetBSD: ip6_input.c,v 1.218 2020/07/27 14:06:58 roy 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.217 2020/06/19 16:08:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.218 2020/07/27 14:06:58 roy Exp $");
#ifdef _KERNEL_OPT
#include "opt_gateway.h"
@@ -156,6 +156,20 @@ static void sysctl_net_inet6_ip6_setup(s
#define SOFTNET_UNLOCK() KASSERT(mutex_owned(softnet_lock))
#endif
+/* Ensure that non packed structures are the desired size. */
+__CTASSERT(sizeof(struct ip6_hdr) == 40);
+__CTASSERT(sizeof(struct ip6_ext) == 2);
+__CTASSERT(sizeof(struct ip6_hbh) == 2);
+__CTASSERT(sizeof(struct ip6_dest) == 2);
+__CTASSERT(sizeof(struct ip6_opt) == 2);
+__CTASSERT(sizeof(struct ip6_opt_jumbo) == 6);
+__CTASSERT(sizeof(struct ip6_opt_nsap) == 4);
+__CTASSERT(sizeof(struct ip6_opt_tunnel) == 3);
+__CTASSERT(sizeof(struct ip6_opt_router) == 4);
+__CTASSERT(sizeof(struct ip6_rthdr) == 4);
+__CTASSERT(sizeof(struct ip6_rthdr0) == 8);
+__CTASSERT(sizeof(struct ip6_frag) == 8);
+
/*
* IP6 initialization: fill in IP6 protocol switch table.
* All protocols not implemented in kernel go to raw IP6 protocol handler.