From 1bd9ac781b8e869b5862348583148eb7efaba5a0 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 09:42:24 +0200 Subject: [PATCH] Define ICMP, UDP, and TCP buffer pointers globally in uip.h --- os/net/ipv6/multicast/esmrf.c | 6 ------ os/net/ipv6/multicast/roll-tm.c | 3 --- os/net/ipv6/resolv.c | 4 +--- os/net/ipv6/sicslowpan.c | 16 +++++++--------- os/net/ipv6/tcpip.c | 3 --- os/net/ipv6/uip-icmp6.c | 1 - os/net/ipv6/uip-nd6.c | 1 - os/net/ipv6/uip.h | 10 +++++++++- os/net/ipv6/uip6.c | 3 --- os/net/routing/rpl-classic/rpl-icmp6.c | 2 -- os/net/routing/rpl-lite/rpl-icmp6.c | 3 --- tools/sky/uip6-bridge/sicslow_ethernet.c | 1 - 12 files changed, 17 insertions(+), 36 deletions(-) diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index edbc32b16..d72d99fad 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -103,12 +103,6 @@ static struct uip_udp_conn *c; static uip_ipaddr_t src_ip; static uip_ipaddr_t des_ip; /*---------------------------------------------------------------------------*/ -/* uIPv6 Pointers */ -/*---------------------------------------------------------------------------*/ -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -/*---------------------------------------------------------------------------*/ /* Local function prototypes */ /*---------------------------------------------------------------------------*/ static void icmp_input(void); diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 20a681fc5..a8dee46a6 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -457,12 +457,9 @@ static uint16_t last_seq; /* uIPv6 Pointers */ /*---------------------------------------------------------------------------*/ #define UIP_DATA_BUF ((uint8_t *)&uip_buf[uip_l2_l3_hdr_len + UIP_UDPH_LEN]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) #define UIP_EXT_BUF_NEXT ((uint8_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + HBHO_TOTAL_LEN]) #define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + 2]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) extern uint16_t uip_slen; /*---------------------------------------------------------------------------*/ /* Local function prototypes */ diff --git a/os/net/ipv6/resolv.c b/os/net/ipv6/resolv.c index 2bcd3983b..29af2b4cf 100644 --- a/os/net/ipv6/resolv.c +++ b/os/net/ipv6/resolv.c @@ -116,8 +116,6 @@ int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t n); #endif /* __SDCC */ -#define UIP_UDP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) - /* If RESOLV_CONF_SUPPORTS_MDNS is set, then queries * for domain names in the local TLD will use mDNS as * described by draft-cheshire-dnsext-multicastdns. @@ -837,7 +835,7 @@ newdata(void) } else { uip_udp_packet_sendto(resolv_conn, uip_appdata, mdns_prep_host_announce_packet(), - &UIP_UDP_BUF->srcipaddr, + &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport); } return; diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index b5c23a3be..2a1a9f34f 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -121,10 +121,8 @@ #define SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN]) #define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_IPH_LEN]) -#define UIP_UDP_BUF(p) ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN + p]) -#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLIPH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN]) -#define UIP_IPPAYLOAD_BUF(pos) (&uip_buf[UIP_LLIPH_LEN + pos]) +#define UIP_IPPAYLOAD_BUF_POS(pos) (&uip_buf[UIP_LLIPH_LEN + (pos)]) +#define UIP_UDP_BUF_POS(pos) ((struct uip_udp_hdr *)UIP_IPPAYLOAD_BUF_POS(pos)) /** @} */ @@ -464,9 +462,9 @@ set_packet_attrs(void) /* assign values to the channel attribute (port or type + code) */ if(UIP_IP_BUF->proto == UIP_PROTO_UDP) { - c = UIP_UDP_BUF(0)->srcport; - if(UIP_UDP_BUF(0)->destport < c) { - c = UIP_UDP_BUF(0)->destport; + c = UIP_UDP_BUF_POS(0)->srcport; + if(UIP_UDP_BUF_POS(0)->destport < c) { + c = UIP_UDP_BUF_POS(0)->destport; } } else if(UIP_IP_BUF->proto == UIP_PROTO_TCP) { c = UIP_TCP_BUF->srcport; @@ -917,7 +915,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* Handle the header here! */ { struct uip_ext_hdr *ext_hdr = - (struct uip_ext_hdr *) UIP_IPPAYLOAD_BUF(ext_hdr_len); + (struct uip_ext_hdr *) UIP_IPPAYLOAD_BUF_POS(ext_hdr_len); int len; proto = proto == -1 ? SICSLOWPAN_NHC_ETX_HDR_DESTO : proto; /* Len is defined to be in octets from the length byte */ @@ -956,7 +954,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) case UIP_PROTO_UDP: /* allocate a byte for the next header posision as UDP has no next */ hc06_ptr++; - udp_buf = UIP_UDP_BUF(ext_hdr_len); + udp_buf = UIP_UDP_BUF_POS(ext_hdr_len); LOG_DBG("compression: inlined UDP ports on send side: %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); /* Mask out the last 4 bits can be used as a mask */ diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 740054010..b7a10de9a 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -55,9 +55,6 @@ #define LOG_MODULE "TCP/IP" #define LOG_LEVEL LOG_LEVEL_TCPIP -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len]) -#define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) - #ifdef UIP_FALLBACK_INTERFACE extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE; #endif diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 13d03a859..193c02aa4 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -53,7 +53,6 @@ #define LOG_MODULE "ICMPv6" #define LOG_LEVEL LOG_LEVEL_IPV6 -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len]) #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN]) diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index d3e50bdcf..b2a17ff1d 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -94,7 +94,6 @@ * value of these length variables */ -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) /**< Pointer to ICMP header*/ /**@{ Pointers to messages just after icmp header */ #define UIP_ND6_RS_BUF ((uip_nd6_rs *)&uip_buf[uip_l2_l3_icmp_hdr_len]) #define UIP_ND6_RA_BUF ((uip_nd6_ra *)&uip_buf[uip_l2_l3_icmp_hdr_len]) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index fa3bdbd98..556a3e4be 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -79,7 +79,15 @@ /** * Direct access to IPv6 header */ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) + +/** + * Direct access to ICMP, UDP, and TCP headers and payload + */ +#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) +#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) +#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) +#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 5b86de266..0a6153a2a 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -142,9 +142,6 @@ uint8_t uip_ext_opt_offset = 0; * @{ */ #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_ROUTING_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #define UIP_FRAG_BUF ((struct uip_frag_hdr *)&uip_buf[uip_l2_l3_hdr_len]) diff --git a/os/net/routing/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c index ed0bde02a..5230ab4e4 100644 --- a/os/net/routing/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -70,8 +70,6 @@ #define RPL_DIO_MOP_MASK 0x38 #define RPL_DIO_PREFERENCE_MASK 0x07 -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) /*---------------------------------------------------------------------------*/ static void dis_input(void); static void dio_input(void); diff --git a/os/net/routing/rpl-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c index f369b34c7..260f9b168 100644 --- a/os/net/routing/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -62,9 +62,6 @@ #define RPL_DIO_MOP_MASK 0x38 #define RPL_DIO_PREFERENCE_MASK 0x07 -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) - /*---------------------------------------------------------------------------*/ static void dis_input(void); static void dio_input(void); diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 317c7abe8..0b241d71b 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -379,7 +379,6 @@ typedef struct { uint8_t data[16]; } icmp_opts_t; -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) #define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x]) void slide(uint8_t * data, uint8_t length, int16_t slide);