Module Name:    src
Committed By:   roy
Date:           Mon Jul 27 14:52:55 UTC 2020

Modified Files:
        src/sys/netinet: icmp6.h
        src/sys/netinet6: icmp6.c

Log Message:
icmp6: Remove __packed attribute from icmp6 structures

They should naturally align.
Add compile time assertations to icmp6.c to prove this.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/netinet/icmp6.h
cvs rdiff -u -r1.245 -r1.246 src/sys/netinet6/icmp6.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/icmp6.h
diff -u src/sys/netinet/icmp6.h:1.56 src/sys/netinet/icmp6.h:1.57
--- src/sys/netinet/icmp6.h:1.56	Mon Jun 15 23:41:35 2020
+++ src/sys/netinet/icmp6.h	Mon Jul 27 14:52:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.h,v 1.56 2020/06/15 23:41:35 roy Exp $	*/
+/*	$NetBSD: icmp6.h,v 1.57 2020/07/27 14:52:55 roy Exp $	*/
 /*	$KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $	*/
 
 
@@ -77,7 +77,7 @@ struct icmp6_hdr {
 		u_int16_t	icmp6_un_data16[2]; /* type-specific field */
 		u_int8_t	icmp6_un_data8[4];  /* type-specific field */
 	} icmp6_dataun;
-} __packed;
+};
 
 #define icmp6_data32	icmp6_dataun.icmp6_un_data32
 #define icmp6_data16	icmp6_dataun.icmp6_un_data16
@@ -182,7 +182,7 @@ struct icmp6_hdr {
 struct mld_hdr {
 	struct icmp6_hdr	mld_icmp6_hdr;
 	struct in6_addr		mld_addr; /* multicast address */
-} __packed;
+};
 
 /* definitions to provide backward compatibility to old KAME applications */
 #ifndef _KERNEL
@@ -211,7 +211,7 @@ struct mld_hdr {
 struct nd_router_solicit {	/* router solicitation */
 	struct icmp6_hdr 	nd_rs_hdr;
 	/* could be followed by options */
-} __packed;
+};
 
 #define nd_rs_type	nd_rs_hdr.icmp6_type
 #define nd_rs_code	nd_rs_hdr.icmp6_code
@@ -223,7 +223,7 @@ struct nd_router_advert {	/* router adve
 	u_int32_t		nd_ra_reachable;	/* reachable time */
 	u_int32_t		nd_ra_retransmit;	/* retransmit timer */
 	/* could be followed by options */
-} __packed;
+};
 
 #define nd_ra_type		nd_ra_hdr.icmp6_type
 #define nd_ra_code		nd_ra_hdr.icmp6_code
@@ -251,7 +251,7 @@ struct nd_neighbor_solicit {	/* neighbor
 	struct icmp6_hdr	nd_ns_hdr;
 	struct in6_addr		nd_ns_target;	/*target address */
 	/* could be followed by options */
-} __packed;
+};
 
 #define nd_ns_type		nd_ns_hdr.icmp6_type
 #define nd_ns_code		nd_ns_hdr.icmp6_code
@@ -262,7 +262,7 @@ struct nd_neighbor_advert {	/* neighbor 
 	struct icmp6_hdr	nd_na_hdr;
 	struct in6_addr		nd_na_target;	/* target address */
 	/* could be followed by options */
-} __packed;
+};
 
 #define nd_na_type		nd_na_hdr.icmp6_type
 #define nd_na_code		nd_na_hdr.icmp6_code
@@ -285,7 +285,7 @@ struct nd_redirect {		/* redirect */
 	struct in6_addr		nd_rd_target;	/* target address */
 	struct in6_addr		nd_rd_dst;	/* destination address */
 	/* could be followed by options */
-} __packed;
+};
 
 #define nd_rd_type		nd_rd_hdr.icmp6_type
 #define nd_rd_code		nd_rd_hdr.icmp6_code
@@ -296,7 +296,7 @@ struct nd_opt_hdr {		/* Neighbor discove
 	u_int8_t	nd_opt_type;
 	u_int8_t	nd_opt_len;
 	/* followed by option specific data*/
-} __packed;
+};
 
 #define ND_OPT_SOURCE_LINKADDR		1
 #define ND_OPT_TARGET_LINKADDR		2
@@ -332,7 +332,7 @@ struct nd_opt_prefix_info {	/* prefix in
 	u_int32_t	nd_opt_pi_preferred_time;
 	u_int32_t	nd_opt_pi_reserved2;
 	struct in6_addr	nd_opt_pi_prefix;
-} __packed;
+};
 
 #define ND_OPT_PI_FLAG_ONLINK		0x80
 #define ND_OPT_PI_FLAG_AUTO		0x40
@@ -344,14 +344,14 @@ struct nd_opt_rd_hdr {		/* redirected he
 	u_int16_t	nd_opt_rh_reserved1;
 	u_int32_t	nd_opt_rh_reserved2;
 	/* followed by IP header and data */
-} __packed;
+};
 
 struct nd_opt_mtu {		/* MTU option */
 	u_int8_t	nd_opt_mtu_type;
 	u_int8_t	nd_opt_mtu_len;
 	u_int16_t	nd_opt_mtu_reserved;
 	u_int32_t	nd_opt_mtu_mtu;
-} __packed;
+};
 
 #define	ND_OPT_NONCE_LEN	((1 * 8) - 2)
 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0
@@ -361,7 +361,7 @@ struct nd_opt_nonce {
 	u_int8_t	nd_opt_nonce_type;
 	u_int8_t	nd_opt_nonce_len;
 	u_int8_t	nd_opt_nonce[ND_OPT_NONCE_LEN];
-} __packed;
+};
 
 struct nd_opt_rdnss {		/* RDNSS option RFC 6106 */
 	u_int8_t	nd_opt_rdnss_type;
@@ -369,7 +369,7 @@ struct nd_opt_rdnss {		/* RDNSS option R
 	u_int16_t	nd_opt_rdnss_reserved;
 	u_int32_t	nd_opt_rdnss_lifetime;
 	/* followed by list of IP prefixes */
-} __packed;
+};
 
 struct nd_opt_dnssl {		/* DNSSL option RFC 6106 */
 	u_int8_t	nd_opt_dnssl_type;
@@ -377,7 +377,7 @@ struct nd_opt_dnssl {		/* DNSSL option R
 	u_int16_t	nd_opt_dnssl_reserved;
 	u_int32_t	nd_opt_dnssl_lifetime;
 	/* followed by list of IP prefixes */
-} __packed;
+};
 
 /*
  * icmp6 namelookup
@@ -392,7 +392,7 @@ struct icmp6_namelookup {
 	u_int8_t	icmp6_nl_name[3];
 #endif
 	/* could be followed by options */
-} __packed;
+};
 
 /*
  * icmp6 node information
@@ -401,7 +401,7 @@ struct icmp6_nodeinfo {
 	struct icmp6_hdr icmp6_ni_hdr;
 	u_int8_t icmp6_ni_nonce[8];
 	/* could be followed by reply data */
-} __packed;
+};
 
 #define ni_type		icmp6_ni_hdr.icmp6_type
 #define ni_code		icmp6_ni_hdr.icmp6_code
@@ -464,7 +464,7 @@ struct ni_reply_fqdn {
 	u_int32_t ni_fqdn_ttl;	/* TTL */
 	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
 	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
-} __packed;
+};
 
 /*
  * Router Renumbering. as router-renum-08.txt
@@ -475,7 +475,7 @@ struct icmp6_router_renum {	/* router re
 	u_int8_t	rr_flags;
 	u_int16_t	rr_maxdelay;
 	u_int32_t	rr_reserved;
-} __packed;
+};
 
 #define ICMP6_RR_FLAGS_TEST		0x80
 #define ICMP6_RR_FLAGS_REQRESULT	0x40
@@ -497,7 +497,7 @@ struct rr_pco_match {		/* match prefix p
 	u_int8_t	rpm_maxlen;
 	u_int16_t	rpm_reserved;
 	struct	in6_addr	rpm_prefix;
-} __packed;
+};
 
 #define RPM_PCO_ADD		1
 #define RPM_PCO_CHANGE		2
@@ -513,7 +513,7 @@ struct rr_pco_use {		/* use prefix part 
 	u_int32_t	rpu_pltime;
 	u_int32_t	rpu_flags;
 	struct	in6_addr rpu_prefix;
-} __packed;
+};
 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
 
@@ -531,7 +531,7 @@ struct rr_result {		/* router renumberin
 	u_int8_t	rrr_matchedlen;
 	u_int32_t	rrr_ifid;
 	struct	in6_addr rrr_prefix;
-} __packed;
+};
 #if BYTE_ORDER == BIG_ENDIAN
 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001

Index: src/sys/netinet6/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.245 src/sys/netinet6/icmp6.c:1.246
--- src/sys/netinet6/icmp6.c:1.245	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/icmp6.c	Mon Jul 27 14:52:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.245 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.246 2020/07/27 14:52:55 roy 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.245 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.246 2020/07/27 14:52:55 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -114,6 +114,32 @@ __KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.
 #include <net/if_faith.h>
 #endif
 
+/* Ensure that non packed structures are the desired size. */
+__CTASSERT(sizeof(struct icmp6_hdr) == 8);
+__CTASSERT(sizeof(struct icmp6_nodeinfo) == 16);
+__CTASSERT(sizeof(struct icmp6_namelookup) == 20);
+__CTASSERT(sizeof(struct icmp6_router_renum) == 16);
+
+__CTASSERT(sizeof(struct nd_router_solicit) == 8);
+__CTASSERT(sizeof(struct nd_router_advert) == 16);
+__CTASSERT(sizeof(struct nd_neighbor_solicit) == 24);
+__CTASSERT(sizeof(struct nd_neighbor_advert) == 24);
+__CTASSERT(sizeof(struct nd_redirect) == 40);
+__CTASSERT(sizeof(struct nd_opt_hdr) == 2);
+__CTASSERT(sizeof(struct nd_opt_route_info) == 8);
+__CTASSERT(sizeof(struct nd_opt_prefix_info) == 32);
+__CTASSERT(sizeof(struct nd_opt_rd_hdr) == 8);
+__CTASSERT(sizeof(struct nd_opt_mtu) == 8);
+__CTASSERT(sizeof(struct nd_opt_nonce) == 2 + ND_OPT_NONCE_LEN);
+__CTASSERT(sizeof(struct nd_opt_rdnss) == 8);
+__CTASSERT(sizeof(struct nd_opt_dnssl) == 8);
+
+__CTASSERT(sizeof(struct mld_hdr) == 24);
+__CTASSERT(sizeof(struct ni_reply_fqdn) == 8);
+__CTASSERT(sizeof(struct rr_pco_match) == 24);
+__CTASSERT(sizeof(struct rr_pco_use) == 32);
+__CTASSERT(sizeof(struct rr_result) == 24);
+
 extern struct domain inet6domain;
 
 percpu_t *icmp6stat_percpu;

Reply via email to