From c01096097ce51bed88b00c85abbdb04b35162c71 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 13 Feb 2017 12:34:38 +0100 Subject: [PATCH] Move struct ip4_addr2 and corresponding copy macros from ip4_addr.h to prot/etharp.h where they belong Also rename struct not to clash with IP4_ADDR2 macro definition, and rework copy macros to contain a source/dest direction --- src/core/ipv4/autoip.c | 6 +++--- src/core/ipv4/etharp.c | 12 ++++++------ src/include/lwip/ip4_addr.h | 23 ---------------------- src/include/lwip/prot/etharp.h | 35 +++++++++++++++++++++++++++++++--- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 10db8a34..68e12628 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -465,11 +465,11 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) struct eth_addr netifaddr; ETHADDR16_COPY(netifaddr.addr, netif->hwaddr); - /* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without + /* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without * structure packing (not using structure copy which breaks strict-aliasing rules). */ - IPADDR2_COPY(&sipaddr, &hdr->sipaddr); - IPADDR2_COPY(&dipaddr, &hdr->dipaddr); + IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&sipaddr, &hdr->sipaddr); + IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&dipaddr, &hdr->dipaddr); if (autoip->state == AUTOIP_STATE_PROBING) { /* RFC 3927 Section 2.2.1: diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 7e70f1e6..efafcea2 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -671,10 +671,10 @@ etharp_input(struct pbuf *p, struct netif *netif) autoip_arp_reply(netif, hdr); #endif /* LWIP_AUTOIP */ - /* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without + /* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without * structure packing (not using structure copy which breaks strict-aliasing rules). */ - IPADDR2_COPY(&sipaddr, &hdr->sipaddr); - IPADDR2_COPY(&dipaddr, &hdr->dipaddr); + IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&sipaddr, &hdr->sipaddr); + IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&dipaddr, &hdr->dipaddr); /* this interface is not configured? */ if (ip4_addr_isany_val(*netif_ip4_addr(netif))) { @@ -1133,10 +1133,10 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, /* Write the ARP MAC-Addresses */ ETHADDR16_COPY(&hdr->shwaddr, hwsrc_addr); ETHADDR16_COPY(&hdr->dhwaddr, hwdst_addr); - /* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without + /* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without * structure packing. */ - IPADDR2_COPY(&hdr->sipaddr, ipsrc_addr); - IPADDR2_COPY(&hdr->dipaddr, ipdst_addr); + IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->sipaddr, ipsrc_addr); + IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->dipaddr, ipdst_addr); hdr->hwtype = PP_HTONS(HWTYPE_ETHERNET); hdr->proto = PP_HTONS(ETHTYPE_IP); diff --git a/src/include/lwip/ip4_addr.h b/src/include/lwip/ip4_addr.h index 51b46b8d..e0c32c78 100644 --- a/src/include/lwip/ip4_addr.h +++ b/src/include/lwip/ip4_addr.h @@ -56,22 +56,6 @@ struct ip4_addr { * operate both on ip4_addr_t as well as on ip4_addr_p_t. */ typedef struct ip4_addr ip4_addr_t; -/** - * struct ipaddr2 is used in the definition of the ARP packet format in - * order to support compilers that don't have structure packing. - */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip4_addr2 { - PACK_STRUCT_FIELD(u16_t addrw[2]); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - /* Forward declaration to not include netif.h */ struct netif; @@ -119,13 +103,6 @@ struct netif; /** Set an IP address given by the four byte-parts */ #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d)) -/** MEMCPY-like copying of IP addresses where addresses are known to be - * 16-bit-aligned if the port is correctly configured (so a port could define - * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ -#ifndef IPADDR2_COPY -#define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t)) -#endif - /** Copy IP address - faster than ip4_addr_set: no NULL check */ #define ip4_addr_copy(dest, src) ((dest).addr = (src).addr) /** Safely copy one IP address to another (src may be NULL) */ diff --git a/src/include/lwip/prot/etharp.h b/src/include/lwip/prot/etharp.h index ec78305b..b18d50fd 100644 --- a/src/include/lwip/prot/etharp.h +++ b/src/include/lwip/prot/etharp.h @@ -39,7 +39,6 @@ #include "lwip/arch.h" #include "lwip/prot/ethernet.h" -#include "lwip/ip4_addr.h" #ifdef __cplusplus extern "C" { @@ -49,6 +48,36 @@ extern "C" { #define ETHARP_HWADDR_LEN ETH_HWADDR_LEN #endif +/** + * struct ipaddr2 is used in the definition of the ARP packet format in + * order to support compilers that don't have structure packing. + */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip4_addr_wordaligned { + PACK_STRUCT_FIELD(u16_t addrw[2]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** MEMCPY-like copying of IP addresses where addresses are known to be + * 16-bit-aligned if the port is correctly configured (so a port could define + * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ +#ifndef IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T +#define IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t)) +#endif + + /** MEMCPY-like copying of IP addresses where addresses are known to be + * 16-bit-aligned if the port is correctly configured (so a port could define + * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ +#ifndef IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T +#define IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t)) +#endif + #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/bpstruct.h" #endif @@ -61,9 +90,9 @@ struct etharp_hdr { PACK_STRUCT_FLD_8(u8_t protolen); PACK_STRUCT_FIELD(u16_t opcode); PACK_STRUCT_FLD_S(struct eth_addr shwaddr); - PACK_STRUCT_FLD_S(struct ip4_addr2 sipaddr); + PACK_STRUCT_FLD_S(struct ip4_addr_wordaligned sipaddr); PACK_STRUCT_FLD_S(struct eth_addr dhwaddr); - PACK_STRUCT_FLD_S(struct ip4_addr2 dipaddr); + PACK_STRUCT_FLD_S(struct ip4_addr_wordaligned dipaddr); } PACK_STRUCT_STRUCT; PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES