mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-04 05:39:53 +00:00
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
This commit is contained in:
parent
44068e3109
commit
c01096097c
@ -465,11 +465,11 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
|
|||||||
struct eth_addr netifaddr;
|
struct eth_addr netifaddr;
|
||||||
ETHADDR16_COPY(netifaddr.addr, netif->hwaddr);
|
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).
|
* structure packing (not using structure copy which breaks strict-aliasing rules).
|
||||||
*/
|
*/
|
||||||
IPADDR2_COPY(&sipaddr, &hdr->sipaddr);
|
IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&sipaddr, &hdr->sipaddr);
|
||||||
IPADDR2_COPY(&dipaddr, &hdr->dipaddr);
|
IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&dipaddr, &hdr->dipaddr);
|
||||||
|
|
||||||
if (autoip->state == AUTOIP_STATE_PROBING) {
|
if (autoip->state == AUTOIP_STATE_PROBING) {
|
||||||
/* RFC 3927 Section 2.2.1:
|
/* RFC 3927 Section 2.2.1:
|
||||||
|
@ -671,10 +671,10 @@ etharp_input(struct pbuf *p, struct netif *netif)
|
|||||||
autoip_arp_reply(netif, hdr);
|
autoip_arp_reply(netif, hdr);
|
||||||
#endif /* LWIP_AUTOIP */
|
#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). */
|
* structure packing (not using structure copy which breaks strict-aliasing rules). */
|
||||||
IPADDR2_COPY(&sipaddr, &hdr->sipaddr);
|
IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&sipaddr, &hdr->sipaddr);
|
||||||
IPADDR2_COPY(&dipaddr, &hdr->dipaddr);
|
IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&dipaddr, &hdr->dipaddr);
|
||||||
|
|
||||||
/* this interface is not configured? */
|
/* this interface is not configured? */
|
||||||
if (ip4_addr_isany_val(*netif_ip4_addr(netif))) {
|
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 */
|
/* Write the ARP MAC-Addresses */
|
||||||
ETHADDR16_COPY(&hdr->shwaddr, hwsrc_addr);
|
ETHADDR16_COPY(&hdr->shwaddr, hwsrc_addr);
|
||||||
ETHADDR16_COPY(&hdr->dhwaddr, hwdst_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. */
|
* structure packing. */
|
||||||
IPADDR2_COPY(&hdr->sipaddr, ipsrc_addr);
|
IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->sipaddr, ipsrc_addr);
|
||||||
IPADDR2_COPY(&hdr->dipaddr, ipdst_addr);
|
IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->dipaddr, ipdst_addr);
|
||||||
|
|
||||||
hdr->hwtype = PP_HTONS(HWTYPE_ETHERNET);
|
hdr->hwtype = PP_HTONS(HWTYPE_ETHERNET);
|
||||||
hdr->proto = PP_HTONS(ETHTYPE_IP);
|
hdr->proto = PP_HTONS(ETHTYPE_IP);
|
||||||
|
@ -56,22 +56,6 @@ struct ip4_addr {
|
|||||||
* operate both on ip4_addr_t as well as on ip4_addr_p_t. */
|
* operate both on ip4_addr_t as well as on ip4_addr_p_t. */
|
||||||
typedef struct ip4_addr ip4_addr_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 */
|
/* Forward declaration to not include netif.h */
|
||||||
struct netif;
|
struct netif;
|
||||||
|
|
||||||
@ -119,13 +103,6 @@ struct netif;
|
|||||||
/** Set an IP address given by the four byte-parts */
|
/** 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))
|
#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 */
|
/** Copy IP address - faster than ip4_addr_set: no NULL check */
|
||||||
#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
|
#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
|
||||||
/** Safely copy one IP address to another (src may be NULL) */
|
/** Safely copy one IP address to another (src may be NULL) */
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
#include "lwip/arch.h"
|
#include "lwip/arch.h"
|
||||||
#include "lwip/prot/ethernet.h"
|
#include "lwip/prot/ethernet.h"
|
||||||
#include "lwip/ip4_addr.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -49,6 +48,36 @@ extern "C" {
|
|||||||
#define ETHARP_HWADDR_LEN ETH_HWADDR_LEN
|
#define ETHARP_HWADDR_LEN ETH_HWADDR_LEN
|
||||||
#endif
|
#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
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
# include "arch/bpstruct.h"
|
# include "arch/bpstruct.h"
|
||||||
#endif
|
#endif
|
||||||
@ -61,9 +90,9 @@ struct etharp_hdr {
|
|||||||
PACK_STRUCT_FLD_8(u8_t protolen);
|
PACK_STRUCT_FLD_8(u8_t protolen);
|
||||||
PACK_STRUCT_FIELD(u16_t opcode);
|
PACK_STRUCT_FIELD(u16_t opcode);
|
||||||
PACK_STRUCT_FLD_S(struct eth_addr shwaddr);
|
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 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_STRUCT;
|
||||||
PACK_STRUCT_END
|
PACK_STRUCT_END
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
|
Loading…
Reference in New Issue
Block a user