Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys ip6: Remove __packed attribute from ip6 structures



details:   https://anonhg.NetBSD.org/src/rev/17ef602e03c1
branches:  trunk
changeset: 936455:17ef602e03c1
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Jul 27 14:06:58 2020 +0000

description:
ip6: Remove __packed attribute from ip6 structures

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

diffstat:

 sys/netinet/ip6.h        |  26 +++++++++++++-------------
 sys/netinet6/ip6_input.c |  18 ++++++++++++++++--
 2 files changed, 29 insertions(+), 15 deletions(-)

diffs (151 lines):

diff -r 7c5accbbc892 -r 17ef602e03c1 sys/netinet/ip6.h
--- a/sys/netinet/ip6.h Mon Jul 27 12:32:54 2020 +0000
+++ b/sys/netinet/ip6.h Mon Jul 27 14:06:58 2020 +0000
@@ -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 @@
        } 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_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_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 @@
        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 @@
        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 @@
        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 @@
        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 */
diff -r 7c5accbbc892 -r 17ef602e03c1 sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c  Mon Jul 27 12:32:54 2020 +0000
+++ b/sys/netinet6/ip6_input.c  Mon Jul 27 14:06:58 2020 +0000
@@ -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 @@
 #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.



Home | Main Index | Thread Index | Old Index