]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Get rid of ND_UNALIGNED.
authorGuy Harris <[email protected]>
Wed, 14 Feb 2018 22:03:41 +0000 (14:03 -0800)
committerGuy Harris <[email protected]>
Wed, 14 Feb 2018 22:03:41 +0000 (14:03 -0800)
Structures that describe packet formats now all use nd_ types, none of
which require more than 1-byte alignment, so compilers shouldn't assume
that anything in those structures is aligned on any particular boundary,
even without a "this is unaligned" hint.

ip6.h
netdissect.h
print-bootp.c
print-dccp.c
tcp.h

diff --git a/ip6.h b/ip6.h
index a821cd2345e32cb8d15c2255a1c7fdc3da26a8d8..b5058a48e8df4ea92d0dc40ca75eab406d55931f 100644 (file)
--- a/ip6.h
+++ b/ip6.h
@@ -85,7 +85,7 @@ struct ip6_hdr {
        } ip6_ctlun;
        nd_ipv6 ip6_src;        /* source address */
        nd_ipv6 ip6_dst;        /* destination address */
        } ip6_ctlun;
        nd_ipv6 ip6_src;        /* source address */
        nd_ipv6 ip6_dst;        /* destination address */
-} ND_UNALIGNED;
+};
 
 #define ip6_vfc                ip6_ctlun.ip6_un2_vfc
 #define IP6_VERSION(ip6_hdr)   ((EXTRACT_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4)
 
 #define ip6_vfc                ip6_ctlun.ip6_un2_vfc
 #define IP6_VERSION(ip6_hdr)   ((EXTRACT_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4)
@@ -111,21 +111,21 @@ struct ip6_hdr {
 struct ip6_ext {
        nd_uint8_t ip6e_nxt;
        nd_uint8_t ip6e_len;
 struct ip6_ext {
        nd_uint8_t ip6e_nxt;
        nd_uint8_t ip6e_len;
-} ND_UNALIGNED;
+};
 
 /* Hop-by-Hop options header */
 struct ip6_hbh {
        nd_uint8_t ip6h_nxt;    /* next header */
        nd_uint8_t ip6h_len;    /* length in units of 8 octets */
        /* followed by options */
 
 /* Hop-by-Hop options header */
 struct ip6_hbh {
        nd_uint8_t ip6h_nxt;    /* next header */
        nd_uint8_t ip6h_len;    /* length in units of 8 octets */
        /* followed by options */
-} ND_UNALIGNED;
+};
 
 /* Destination options header */
 struct ip6_dest {
        nd_uint8_t ip6d_nxt;    /* next header */
        nd_uint8_t ip6d_len;    /* length in units of 8 octets */
        /* followed by options */
 
 /* Destination options header */
 struct ip6_dest {
        nd_uint8_t ip6d_nxt;    /* next header */
        nd_uint8_t ip6d_len;    /* length in units of 8 octets */
        /* followed by options */
-} ND_UNALIGNED;
+};
 
 /* http://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */
 
 
 /* http://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */
 
@@ -170,7 +170,7 @@ struct ip6_rthdr {
        nd_uint8_t  ip6r_type;          /* routing type */
        nd_uint8_t  ip6r_segleft;       /* segments left */
        /* followed by routing type specific data */
        nd_uint8_t  ip6r_type;          /* routing type */
        nd_uint8_t  ip6r_segleft;       /* segments left */
        /* followed by routing type specific data */
-} ND_UNALIGNED;
+};
 
 #define IPV6_RTHDR_TYPE_0 0
 #define IPV6_RTHDR_TYPE_2 2
 
 #define IPV6_RTHDR_TYPE_0 0
 #define IPV6_RTHDR_TYPE_2 2
@@ -208,7 +208,7 @@ struct ip6_frag {
        nd_uint8_t  ip6f_reserved;      /* reserved field */
        nd_uint16_t ip6f_offlg;         /* offset, reserved, and flag */
        nd_uint32_t ip6f_ident;         /* identification */
        nd_uint8_t  ip6f_reserved;      /* reserved field */
        nd_uint16_t ip6f_offlg;         /* offset, reserved, and flag */
        nd_uint32_t ip6f_ident;         /* identification */
-} ND_UNALIGNED;
+};
 
 #define IP6F_OFF_MASK          0xfff8  /* mask out offset from ip6f_offlg */
 #define IP6F_RESERVED_MASK     0x0006  /* reserved bits in ip6f_offlg */
 
 #define IP6F_OFF_MASK          0xfff8  /* mask out offset from ip6f_offlg */
 #define IP6F_RESERVED_MASK     0x0006  /* reserved bits in ip6f_offlg */
index 4c09bfe29290fb039c32cf55769c553b3be6f6b2..fad9330ab7a2bb6c0c7e78da22daa2adad0806ae 100644 (file)
 #endif
 #include <sys/types.h>
 
 #endif
 #include <sys/types.h>
 
-/*
- * Used to declare a structure unaligned, so that the C compiler,
- * if necessary, generates code that doesn't assume alignment.
- * This is required because there is no guarantee that the packet
- * data we get from libpcap/WinPcap is properly aligned.
- *
- * This assumes that, for all compilers that support __attribute__((packed)),
- * for all instruction set architectures requiring strict alignment, declaring
- * a structure with that attribute causes the compiler to generate code that
- * handles misaligned 2-byte, 4-byte, and 8-byte integral quantities.
- *
- * It does not (yet) handle compilers where you can get the compiler
- * to generate code of that sort by some other means.
- *
- * This is required in order to, for example, keep the compiler from
- * generating, for
- *
- *     if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
- *
- * in print-bootp.c, code that loads the first 4-byte word of a
- * "struct bootp", masking out the bp_hops field, and comparing the result
- * against 0x01010600.
- *
- * Note: this also requires that padding be put into the structure,
- * at least for compilers where it's implemented as __attribute__((packed)).
- *
- * XXX - now that we're using nd_ types that are just arrays of bytes, is
- * this still necessary?  Are there any compilers that align structures,
- * none of whose members require more than byte alignment, on more than
- * one-byte boundaries, and assume a structure is aligned on such a
- * boundary?  (I have vague memories of either m68k or ARM compilers
- * aligning on at least 2-byte boundaries.)
- */
-#if ND_IS_AT_LEAST_GNUC_VERSION(2,0) || \
-    ND_IS_AT_LEAST_XL_C_VERSION(6,0)
-  /*
-   * GCC 2.0 or later, or a compiler that claims to be GCC 2.0 or later,
-   * or IBM XL C 6.0 or later.
-   *
-   * Use __attribute__((packed)).
-   */
-  #define ND_UNALIGNED __attribute__((packed))
-#else
-  /*
-   * Nothing.
-   */
-  #define ND_UNALIGNED
-#endif
-
 /*
  * Data types corresponding to multi-byte integral values within data
  * structures.  These are defined as arrays of octets, so that they're
 /*
  * Data types corresponding to multi-byte integral values within data
  * structures.  These are defined as arrays of octets, so that they're
index 2b315d5c2ea152749b19c4e8432dd2f1ecfa9e8a..bddd5f9b685407f2ae84ea9ebfe54dcab9e2a7d2 100644 (file)
@@ -72,7 +72,7 @@ struct bootp {
        nd_byte         bp_sname[64];   /* server host name */
        nd_byte         bp_file[128];   /* boot file name */
        nd_byte         bp_vend[64];    /* vendor-specific area */
        nd_byte         bp_sname[64];   /* server host name */
        nd_byte         bp_file[128];   /* boot file name */
        nd_byte         bp_vend[64];    /* vendor-specific area */
-} ND_UNALIGNED;
+};
 
 #define BOOTPREPLY     2
 #define BOOTPREQUEST   1
 
 #define BOOTPREPLY     2
 #define BOOTPREQUEST   1
@@ -247,7 +247,7 @@ struct cmu_vend {
        nd_ipv4         v_ins1, v_ins2; /* IEN-116 name servers */
        nd_ipv4         v_ts1, v_ts2;   /* Time servers */
        nd_byte         v_unused[24];   /* currently unused */
        nd_ipv4         v_ins1, v_ins2; /* IEN-116 name servers */
        nd_ipv4         v_ts1, v_ts2;   /* Time servers */
        nd_byte         v_unused[24];   /* currently unused */
-} ND_UNALIGNED;
+};
 
 
 /* v_flags values */
 
 
 /* v_flags values */
index 88fbeb10d25ae20f792abedab01222ab42e811b3..5937d53aa4ac73cc25cd9a795f301b5a506b56bd 100644 (file)
@@ -51,7 +51,7 @@ struct dccp_hdr {
        nd_uint16_t     dccph_checksum;
        nd_uint8_t      dccph_xtr;
        nd_uint24_t     dccph_seq;
        nd_uint16_t     dccph_checksum;
        nd_uint8_t      dccph_xtr;
        nd_uint24_t     dccph_seq;
-} ND_UNALIGNED;
+};
 
 /**
  * struct dccp_hdr_ext - generic part of DCCP packet header, with a 48-bit
 
 /**
  * struct dccp_hdr_ext - generic part of DCCP packet header, with a 48-bit
@@ -76,7 +76,7 @@ struct dccp_hdr_ext {
        nd_uint8_t      dccph_xtr;
        nd_uint8_t      reserved;
        nd_uint48_t     dccph_seq;
        nd_uint8_t      dccph_xtr;
        nd_uint8_t      reserved;
        nd_uint48_t     dccph_seq;
-} ND_UNALIGNED;
+};
 
 #define DCCPH_CCVAL(dh)        ((EXTRACT_U_1((dh)->dccph_ccval_cscov) >> 4) & 0xF)
 #define DCCPH_CSCOV(dh)        (EXTRACT_U_1((dh)->dccph_ccval_cscov) & 0xF)
 
 #define DCCPH_CCVAL(dh)        ((EXTRACT_U_1((dh)->dccph_ccval_cscov) >> 4) & 0xF)
 #define DCCPH_CSCOV(dh)        (EXTRACT_U_1((dh)->dccph_ccval_cscov) & 0xF)
@@ -91,7 +91,7 @@ struct dccp_hdr_ext {
  */
 struct dccp_hdr_request {
        nd_uint32_t     dccph_req_service;
  */
 struct dccp_hdr_request {
        nd_uint32_t     dccph_req_service;
-} ND_UNALIGNED;
+};
 
 /**
  * struct dccp_hdr_response - Conection initiation response header
 
 /**
  * struct dccp_hdr_response - Conection initiation response header
@@ -102,7 +102,7 @@ struct dccp_hdr_request {
 struct dccp_hdr_response {
        nd_uint64_t     dccph_resp_ack; /* always 8 bytes, first 2 reserved */
        nd_uint32_t     dccph_resp_service;
 struct dccp_hdr_response {
        nd_uint64_t     dccph_resp_ack; /* always 8 bytes, first 2 reserved */
        nd_uint32_t     dccph_resp_service;
-} ND_UNALIGNED;
+};
 
 /**
  * struct dccp_hdr_reset - Unconditionally shut down a connection
 
 /**
  * struct dccp_hdr_reset - Unconditionally shut down a connection
@@ -116,7 +116,7 @@ struct dccp_hdr_reset {
        nd_uint8_t      dccph_reset_data1;
        nd_uint8_t      dccph_reset_data2;
        nd_uint8_t      dccph_reset_data3;
        nd_uint8_t      dccph_reset_data1;
        nd_uint8_t      dccph_reset_data2;
        nd_uint8_t      dccph_reset_data3;
-} ND_UNALIGNED;
+};
 
 enum dccp_pkt_type {
        DCCP_PKT_REQUEST = 0,
 
 enum dccp_pkt_type {
        DCCP_PKT_REQUEST = 0,
diff --git a/tcp.h b/tcp.h
index 33452043345abfdec942220fe023bbc6a81edc96..701c23f847be1f0f0525c3edc5d6e97526f10c9b 100644 (file)
--- a/tcp.h
+++ b/tcp.h
@@ -47,7 +47,7 @@ struct tcphdr {
        nd_uint16_t     th_win;                 /* window */
        nd_uint16_t     th_sum;                 /* checksum */
        nd_uint16_t     th_urp;                 /* urgent pointer */
        nd_uint16_t     th_win;                 /* window */
        nd_uint16_t     th_sum;                 /* checksum */
        nd_uint16_t     th_urp;                 /* urgent pointer */
-} ND_UNALIGNED;
+};
 
 #define TH_OFF(th)     ((EXTRACT_U_1((th)->th_offx2) & 0xf0) >> 4)
 
 
 #define TH_OFF(th)     ((EXTRACT_U_1((th)->th_offx2) & 0xf0) >> 4)