ip6: Remove __packed attribute from ip6 structures

They should naturally align.
Add compile time assertations to ip6_input.c to prove this.
This commit is contained in:
roy 2020-07-27 14:06:58 +00:00
parent 0b6773556a
commit 6ef1c3277f
2 changed files with 29 additions and 15 deletions

View File

@ -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 $ */ /* $KAME: ip6.h,v 1.45 2003/06/05 04:46:38 keiichi Exp $ */
/* /*
@ -81,7 +81,7 @@ struct ip6_hdr {
} ip6_ctlun; } ip6_ctlun;
struct in6_addr ip6_src; /* source address */ struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */ struct in6_addr ip6_dst; /* destination address */
} __packed; };
#define ip6_vfc ip6_ctlun.ip6_un2_vfc #define ip6_vfc ip6_ctlun.ip6_un2_vfc
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
@ -129,21 +129,21 @@ struct ip6_hdr_pseudo {
struct ip6_ext { struct ip6_ext {
u_int8_t ip6e_nxt; u_int8_t ip6e_nxt;
u_int8_t ip6e_len; u_int8_t ip6e_len;
} __packed; };
/* Hop-by-Hop options header */ /* Hop-by-Hop options header */
struct ip6_hbh { struct ip6_hbh {
u_int8_t ip6h_nxt; /* next header */ u_int8_t ip6h_nxt; /* next header */
u_int8_t ip6h_len; /* length in units of 8 octets */ u_int8_t ip6h_len; /* length in units of 8 octets */
/* followed by options */ /* followed by options */
} __packed; };
/* Destination options header */ /* Destination options header */
struct ip6_dest { struct ip6_dest {
u_int8_t ip6d_nxt; /* next header */ u_int8_t ip6d_nxt; /* next header */
u_int8_t ip6d_len; /* length in units of 8 octets */ u_int8_t ip6d_len; /* length in units of 8 octets */
/* followed by options */ /* followed by options */
} __packed; };
/* Option types and related macros */ /* Option types and related macros */
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */ #define IP6OPT_PAD1 0x00 /* 00 0 00000 */
@ -172,14 +172,14 @@ struct ip6_dest {
struct ip6_opt { struct ip6_opt {
u_int8_t ip6o_type; u_int8_t ip6o_type;
u_int8_t ip6o_len; u_int8_t ip6o_len;
} __packed; };
/* Jumbo Payload Option */ /* Jumbo Payload Option */
struct ip6_opt_jumbo { struct ip6_opt_jumbo {
u_int8_t ip6oj_type; u_int8_t ip6oj_type;
u_int8_t ip6oj_len; u_int8_t ip6oj_len;
u_int8_t ip6oj_jumbo_len[4]; u_int8_t ip6oj_jumbo_len[4];
} __packed; };
#define IP6OPT_JUMBO_LEN 6 #define IP6OPT_JUMBO_LEN 6
/* NSAP Address Option */ /* NSAP Address Option */
@ -190,21 +190,21 @@ struct ip6_opt_nsap {
u_int8_t ip6on_dst_nsap_len; u_int8_t ip6on_dst_nsap_len;
/* followed by source NSAP */ /* followed by source NSAP */
/* followed by destination NSAP */ /* followed by destination NSAP */
} __packed; };
/* Tunnel Limit Option */ /* Tunnel Limit Option */
struct ip6_opt_tunnel { struct ip6_opt_tunnel {
u_int8_t ip6ot_type; u_int8_t ip6ot_type;
u_int8_t ip6ot_len; u_int8_t ip6ot_len;
u_int8_t ip6ot_encap_limit; u_int8_t ip6ot_encap_limit;
} __packed; };
/* Router Alert Option */ /* Router Alert Option */
struct ip6_opt_router { struct ip6_opt_router {
u_int8_t ip6or_type; u_int8_t ip6or_type;
u_int8_t ip6or_len; u_int8_t ip6or_len;
u_int8_t ip6or_value[2]; u_int8_t ip6or_value[2];
} __packed; };
/* Router alert values (in network byte order) */ /* Router alert values (in network byte order) */
#if BYTE_ORDER == BIG_ENDIAN #if BYTE_ORDER == BIG_ENDIAN
#define IP6_ALERT_MLD 0x0000 #define IP6_ALERT_MLD 0x0000
@ -225,7 +225,7 @@ struct ip6_rthdr {
u_int8_t ip6r_type; /* routing type */ u_int8_t ip6r_type; /* routing type */
u_int8_t ip6r_segleft; /* segments left */ u_int8_t ip6r_segleft; /* segments left */
/* followed by routing type specific data */ /* followed by routing type specific data */
} __packed; };
/* Type 0 Routing header */ /* Type 0 Routing header */
struct ip6_rthdr0 { struct ip6_rthdr0 {
@ -234,7 +234,7 @@ struct ip6_rthdr0 {
u_int8_t ip6r0_type; /* always zero */ u_int8_t ip6r0_type; /* always zero */
u_int8_t ip6r0_segleft; /* segments left */ u_int8_t ip6r0_segleft; /* segments left */
u_int32_t ip6r0_reserved; /* reserved field */ u_int32_t ip6r0_reserved; /* reserved field */
} __packed; };
/* Fragment header */ /* Fragment header */
struct ip6_frag { struct ip6_frag {
@ -242,7 +242,7 @@ struct ip6_frag {
u_int8_t ip6f_reserved; /* reserved field */ u_int8_t ip6f_reserved; /* reserved field */
u_int16_t ip6f_offlg; /* offset, reserved, and flag */ u_int16_t ip6f_offlg; /* offset, reserved, and flag */
u_int32_t ip6f_ident; /* identification */ u_int32_t ip6f_ident; /* identification */
} __packed; };
#if BYTE_ORDER == BIG_ENDIAN #if BYTE_ORDER == BIG_ENDIAN
#define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */ #define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */

View File

@ -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 $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/* /*
@ -62,7 +62,7 @@
*/ */
#include <sys/cdefs.h> #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 #ifdef _KERNEL_OPT
#include "opt_gateway.h" #include "opt_gateway.h"
@ -156,6 +156,20 @@ static void sysctl_net_inet6_ip6_setup(struct sysctllog **);
#define SOFTNET_UNLOCK() KASSERT(mutex_owned(softnet_lock)) #define SOFTNET_UNLOCK() KASSERT(mutex_owned(softnet_lock))
#endif #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. * IP6 initialization: fill in IP6 protocol switch table.
* All protocols not implemented in kernel go to raw IP6 protocol handler. * All protocols not implemented in kernel go to raw IP6 protocol handler.