Removed all structure packing directives. Protocol header fields are naturally aligned by design.

(Earlier, the 14-byte ethernet header screwed this up, this had already been fixed by adding two pad bytes.)
Assumption is that compilers do not align with larger-than-sizeof(type) boundaries.
Pre-tag PRE_PACK_REMOVE. Post-tag POST_TAG_REMOVE.
This commit is contained in:
likewise 2004-05-05 19:16:51 +00:00
parent 9dd10e46ab
commit 79110ba469
10 changed files with 78 additions and 173 deletions

View File

@ -154,12 +154,6 @@ cc.h - Architecture environment, some compiler specific, some
Typedefs for the types used by lwip - Typedefs for the types used by lwip -
u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t
Compiler hints for packing lwip's structures -
PACK_STRUCT_FIELD(x)
PACK_STRUCT_STRUCT
PACK_STRUCT_BEGIN
PACK_STRUCT_END
Platform specific diagnostic output - Platform specific diagnostic output -
LWIP_PLATFORM_DIAG(x) - non-fatal, print a message. LWIP_PLATFORM_DIAG(x) - non-fatal, print a message.
LWIP_PLATFORM_ASSERT(x) - fatal, print message and abandon execution. LWIP_PLATFORM_ASSERT(x) - fatal, print message and abandon execution.

View File

@ -71,36 +71,24 @@ void icmp_input(struct pbuf *p, struct netif *inp);
void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct icmp_echo_hdr { struct icmp_echo_hdr {
PACK_STRUCT_FIELD(u16_t _type_code); u16_t _type_code;
PACK_STRUCT_FIELD(u16_t chksum); u16_t chksum;
PACK_STRUCT_FIELD(u16_t id); u16_t id;
PACK_STRUCT_FIELD(u16_t seqno); u16_t seqno;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
PACK_STRUCT_BEGIN
struct icmp_dur_hdr { struct icmp_dur_hdr {
PACK_STRUCT_FIELD(u16_t _type_code); u16_t _type_code;
PACK_STRUCT_FIELD(u16_t chksum); u16_t chksum;
PACK_STRUCT_FIELD(u32_t unused); u32_t unused;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
PACK_STRUCT_BEGIN
struct icmp_te_hdr { struct icmp_te_hdr {
PACK_STRUCT_FIELD(u16_t _type_code); u16_t _type_code;
PACK_STRUCT_FIELD(u16_t chksum); u16_t chksum;
PACK_STRUCT_FIELD(u32_t unused); u32_t unused;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#define ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8) #define ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8)
#define ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff) #define ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff)

View File

@ -94,37 +94,27 @@ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
#define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */ #define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */
#define SOF_REUSEPORT (u16_t)0x0200U /* allow local address & port reuse */ #define SOF_REUSEPORT (u16_t)0x0200U /* allow local address & port reuse */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct ip_hdr { struct ip_hdr {
/* version / header length / type of service */ /* version / header length / type of service */
PACK_STRUCT_FIELD(u16_t _v_hl_tos); u16_t _v_hl_tos;
/* total length */ /* total length */
PACK_STRUCT_FIELD(u16_t _len); u16_t _len;
/* identification */ /* identification */
PACK_STRUCT_FIELD(u16_t _id); u16_t _id;
/* fragment offset field */ /* fragment offset field */
PACK_STRUCT_FIELD(u16_t _offset); u16_t _offset;
#define IP_RF 0x8000 /* reserved fragment flag */ #define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */ #define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
/* time to live / protocol*/ /* time to live / protocol*/
PACK_STRUCT_FIELD(u16_t _ttl_proto); u16_t _ttl_proto;
/* checksum */ /* checksum */
PACK_STRUCT_FIELD(u16_t _chksum); u16_t _chksum;
/* source and destination IP addresses */ /* source and destination IP addresses */
PACK_STRUCT_FIELD(struct ip_addr src); struct ip_addr src;
PACK_STRUCT_FIELD(struct ip_addr dest); struct ip_addr dest;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12) #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
#define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f) #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)

View File

@ -34,29 +34,13 @@
#include "lwip/arch.h" #include "lwip/arch.h"
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct ip_addr { struct ip_addr {
PACK_STRUCT_FIELD(u32_t addr); u32_t addr;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct ip_addr2 { struct ip_addr2 {
PACK_STRUCT_FIELD(u16_t addrw[2]); u16_t addrw[2];
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
/* For compatibility with BSD code */ /* For compatibility with BSD code */
struct in_addr { struct in_addr {

View File

@ -42,20 +42,6 @@
#include "arch/cc.h" #include "arch/cc.h"
#ifndef PACK_STRUCT_BEGIN
#define PACK_STRUCT_BEGIN
#endif /* PACK_STRUCT_BEGIN */
#ifndef PACK_STRUCT_END
#define PACK_STRUCT_END
#endif /* PACK_STRUCT_END */
#ifndef PACK_STRUCT_FIELD
#define PACK_STRUCT_FIELD(x) x
#endif /* PACK_STRUCT_FIELD */
#ifdef LWIP_PROVIDE_ERRNO #ifdef LWIP_PROVIDE_ERRNO
#define EPERM 1 /* Operation not permitted */ #define EPERM 1 /* Operation not permitted */

View File

@ -55,44 +55,35 @@ struct dhcp
#endif #endif
}; };
/* MUST be compiled with "pack structs" or equivalent! */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
/** minimum set of fields of any DHCP message */ /** minimum set of fields of any DHCP message */
struct dhcp_msg struct dhcp_msg
{ {
PACK_STRUCT_FIELD(u8_t op); u8_t op;
PACK_STRUCT_FIELD(u8_t htype); u8_t htype;
PACK_STRUCT_FIELD(u8_t hlen); u8_t hlen;
PACK_STRUCT_FIELD(u8_t hops); u8_t hops;
PACK_STRUCT_FIELD(u32_t xid); u32_t xid;
PACK_STRUCT_FIELD(u16_t secs); u16_t secs;
PACK_STRUCT_FIELD(u16_t flags); u16_t flags;
PACK_STRUCT_FIELD(struct ip_addr ciaddr); struct ip_addr ciaddr;
PACK_STRUCT_FIELD(struct ip_addr yiaddr); struct ip_addr yiaddr;
PACK_STRUCT_FIELD(struct ip_addr siaddr); struct ip_addr siaddr;
PACK_STRUCT_FIELD(struct ip_addr giaddr); struct ip_addr giaddr;
#define DHCP_CHADDR_LEN 16U #define DHCP_CHADDR_LEN 16U
PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]); u8_t chaddr[DHCP_CHADDR_LEN];
#define DHCP_SNAME_LEN 64U #define DHCP_SNAME_LEN 64U
PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]); u8_t sname[DHCP_SNAME_LEN];
#define DHCP_FILE_LEN 128U #define DHCP_FILE_LEN 128U
PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]); u8_t file[DHCP_FILE_LEN];
PACK_STRUCT_FIELD(u32_t cookie); u32_t cookie;
#define DHCP_MIN_OPTIONS_LEN 68U #define DHCP_MIN_OPTIONS_LEN 68U
/** allow this to be configured in lwipopts.h, but not too small */ /** allow this to be configured in lwipopts.h, but not too small */
#if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) #if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
/** set this to be sufficient for your options in outgoing DHCP msgs */ /** set this to be sufficient for your options in outgoing DHCP msgs */
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
#endif #endif
PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]); u8_t options[DHCP_OPTIONS_LEN];
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
/** start DHCP configuration */ /** start DHCP configuration */
err_t dhcp_start(struct netif *netif); err_t dhcp_start(struct netif *netif);

View File

@ -161,25 +161,16 @@ void tcp_rexmit (struct tcp_pcb *pcb);
#define TCP_KEEPCNT 9 /* Counter for KEEPALIVE probes */ #define TCP_KEEPCNT 9 /* Counter for KEEPALIVE probes */
#define TCP_MAXIDLE TCP_KEEPCNT * TCP_KEEPINTVL /* Maximum KEEPALIVE probe time */ #define TCP_MAXIDLE TCP_KEEPCNT * TCP_KEEPINTVL /* Maximum KEEPALIVE probe time */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct tcp_hdr { struct tcp_hdr {
PACK_STRUCT_FIELD(u16_t src); u16_t src;
PACK_STRUCT_FIELD(u16_t dest); u16_t dest;
PACK_STRUCT_FIELD(u32_t seqno); u32_t seqno;
PACK_STRUCT_FIELD(u32_t ackno); u32_t ackno;
PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags); u16_t _hdrlen_rsvd_flags;
PACK_STRUCT_FIELD(u16_t wnd); u16_t wnd;
PACK_STRUCT_FIELD(u16_t chksum); u16_t chksum;
PACK_STRUCT_FIELD(u16_t urgp); u16_t urgp;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8) #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
#define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12) #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)

View File

@ -41,11 +41,11 @@
#define UDP_HLEN 8 #define UDP_HLEN 8
struct udp_hdr { struct udp_hdr {
PACK_STRUCT_FIELD(u16_t src); u16_t src;
PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ u16_t dest; /* src/dest UDP ports */
PACK_STRUCT_FIELD(u16_t len); u16_t len;
PACK_STRUCT_FIELD(u16_t chksum); u16_t chksum;
} PACK_STRUCT_STRUCT; };
#define UDP_FLAGS_NOCHKSUM 0x01U #define UDP_FLAGS_NOCHKSUM 0x01U
#define UDP_FLAGS_UDPLITE 0x02U #define UDP_FLAGS_UDPLITE 0x02U

View File

@ -44,49 +44,36 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct eth_addr { struct eth_addr {
PACK_STRUCT_FIELD(u8_t addr[6]); u8_t addr[6];
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
PACK_STRUCT_BEGIN
struct eth_hdr { struct eth_hdr {
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]); u8_t padding[ETH_PAD_SIZE];
#endif #endif
PACK_STRUCT_FIELD(struct eth_addr dest); struct eth_addr dest;
PACK_STRUCT_FIELD(struct eth_addr src); struct eth_addr src;
PACK_STRUCT_FIELD(u16_t type); u16_t type;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
PACK_STRUCT_BEGIN
/** the ARP message */ /** the ARP message */
struct etharp_hdr { struct etharp_hdr {
PACK_STRUCT_FIELD(struct eth_hdr ethhdr); struct eth_hdr ethhdr;
PACK_STRUCT_FIELD(u16_t hwtype); u16_t hwtype;
PACK_STRUCT_FIELD(u16_t proto); u16_t proto;
PACK_STRUCT_FIELD(u16_t _hwlen_protolen); u16_t _hwlen_protolen;
PACK_STRUCT_FIELD(u16_t opcode); u16_t opcode;
PACK_STRUCT_FIELD(struct eth_addr shwaddr); struct eth_addr shwaddr;
PACK_STRUCT_FIELD(struct ip_addr2 sipaddr); struct ip_addr2 sipaddr;
PACK_STRUCT_FIELD(struct eth_addr dhwaddr); struct eth_addr dhwaddr;
PACK_STRUCT_FIELD(struct ip_addr2 dipaddr); struct ip_addr2 dipaddr;
} PACK_STRUCT_STRUCT; };
PACK_STRUCT_END
struct ethip_hdr {
PACK_STRUCT_BEGIN struct eth_hdr eth);
struct ethip_hdr { struct ip_hdr ip;
PACK_STRUCT_FIELD(struct eth_hdr eth);
PACK_STRUCT_FIELD(struct ip_hdr ip);
}; };
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
#define ARP_TMR_INTERVAL 10000 #define ARP_TMR_INTERVAL 10000
@ -102,6 +89,4 @@ err_t etharp_output(struct netif *netif, struct ip_addr *ipaddr,
struct pbuf *q); struct pbuf *q);
err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q); err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q);
#endif /* __NETIF_ARP_H__ */ #endif /* __NETIF_ARP_H__ */

View File

@ -11,7 +11,6 @@
* pragmatically since otherwise unsigned comparisons can result * pragmatically since otherwise unsigned comparisons can result
* against negative integers quite easily, and fail in subtle ways. * against negative integers quite easily, and fail in subtle ways.
*/ */
PACK_STRUCT_BEGIN
struct ip struct ip
{ {
#if defined(NO_CHAR_BITFIELDS) #if defined(NO_CHAR_BITFIELDS)
@ -39,7 +38,6 @@ struct ip
u_short ip_sum; /* checksum */ u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */ struct in_addr ip_src,ip_dst; /* source and dest address */
}; };
PACK_STRUCT_END
typedef u32_t tcp_seq; typedef u32_t tcp_seq;
@ -47,7 +45,6 @@ typedef u32_t tcp_seq;
* TCP header. * TCP header.
* Per RFC 793, September, 1981. * Per RFC 793, September, 1981.
*/ */
PACK_STRUCT_BEGIN
struct tcphdr struct tcphdr
{ {
u_short th_sport; /* source port */ u_short th_sport; /* source port */
@ -71,6 +68,5 @@ struct tcphdr
u_short th_sum; /* checksum */ u_short th_sum; /* checksum */
u_short th_urp; /* urgent pointer */ u_short th_urp; /* urgent pointer */
}; };
PACK_STRUCT_END
#endif /* VJBSDHDR_H */ #endif /* VJBSDHDR_H */