Simplify uip.h definitions

This commit is contained in:
Simon Duquennoy 2018-10-18 17:54:34 +02:00
parent 9b66b6931d
commit 8456c544d8
11 changed files with 36 additions and 47 deletions

View File

@ -201,11 +201,11 @@ icmp_input()
VERBOSE_PRINTF("ESMRF: ICMPv6 In, parse from %p to %p\n",
UIP_ICMP_PAYLOAD,
(uint8_t *)UIP_ICMP_PAYLOAD + uip_len -
uip_l2_l3_icmp_hdr_len);
uip_l3_icmp_hdr_len);
locmobptr = (struct multicast_on_behalf *) UIP_ICMP_PAYLOAD;
loclen = uip_len - (uip_l2_l3_icmp_hdr_len + UIP_ICMP_MOB);
loclen = uip_len - (uip_l3_icmp_hdr_len + UIP_ICMP_MOB);
uip_ipaddr_copy(&src_ip, &UIP_IP_BUF->srcipaddr);
uip_ipaddr_copy(&des_ip, &UIP_IP_BUF->destipaddr);

View File

@ -1146,10 +1146,10 @@ icmp_input()
VERBOSE_PRINTF("ROLL TM: ICMPv6 In, parse from %p to %p\n",
UIP_ICMP_PAYLOAD,
(uint8_t *)UIP_ICMP_PAYLOAD + uip_len -
uip_l2_l3_icmp_hdr_len);
uip_l3_icmp_hdr_len);
while(locslhptr <
(struct sequence_list_header *)((uint8_t *)UIP_ICMP_PAYLOAD +
uip_len - uip_l2_l3_icmp_hdr_len)) {
uip_len - uip_l3_icmp_hdr_len)) {
VERBOSE_PRINTF("ROLL TM: ICMPv6 In, seq hdr @ %p\n", locslhptr);
if((locslhptr->flags & SEQUENCE_LIST_RES) != 0) {

View File

@ -121,7 +121,7 @@
#define SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN])
#define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_IPH_LEN])
#define UIP_IPPAYLOAD_BUF_POS(pos) (&uip_buf[UIP_LLIPH_LEN + (pos)])
#define UIP_IPPAYLOAD_BUF_POS(pos) (&uip_buf[UIP_IPH_LEN + (pos)])
#define UIP_UDP_BUF_POS(pos) ((struct uip_udp_hdr *)UIP_IPPAYLOAD_BUF_POS(pos))
/** @} */

View File

@ -201,7 +201,7 @@ ns_input(void)
#endif /* UIP_CONF_IPV6_CHECKS */
switch (ND6_OPT_HDR_BUF(nd6_opt_offset)->type) {
case UIP_ND6_OPT_SLLAO:
nd6_opt_llao = &uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset];
nd6_opt_llao = &uip_buf[uip_l3_icmp_hdr_len + nd6_opt_offset];
#if UIP_CONF_IPV6_CHECKS
/* There must be NO option in a DAD NS */
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
@ -328,7 +328,7 @@ create_na:
UIP_ND6_NA_BUF->flagsreserved = flags;
memcpy(&UIP_ND6_NA_BUF->tgtipaddr, &addr->ipaddr, sizeof(uip_ipaddr_t));
create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NA_LEN],
create_llao(&uip_buf[uip_l3_icmp_hdr_len + UIP_ND6_NA_LEN],
UIP_ND6_OPT_TLLAO);
UIP_ICMP_BUF->icmpchksum = 0;
@ -391,7 +391,7 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
}
uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN);
create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NS_LEN],
create_llao(&uip_buf[uip_l3_icmp_hdr_len + UIP_ND6_NS_LEN],
UIP_ND6_OPT_SLLAO);
uip_len =
@ -823,7 +823,7 @@ uip_nd6_rs_output(void)
uip_len = uip_l3_icmp_hdr_len + UIP_ND6_RS_LEN + UIP_ND6_OPT_LLAO_LEN;
uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + UIP_ND6_RS_LEN + UIP_ND6_OPT_LLAO_LEN);
create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_RS_LEN],
create_llao(&uip_buf[uip_l3_icmp_hdr_len + UIP_ND6_RS_LEN],
UIP_ND6_OPT_SLLAO);
}

View File

@ -62,18 +62,7 @@
#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + UDP header */
#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + TCP header */
#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* Size of ICMP + IP header */
#define UIP_LLIPH_LEN (UIP_IPH_LEN) /* Size of L2 + IP header */
/**
* The sums below are quite used in ND. When used for uip_buf, we
* include link layer length when used for uip_len, we do not, hence
* we need values with and without LLH_LEN we do not use capital
* letters as these values are variable
*/
#define uip_l2_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
#define uip_l2_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
/**
@ -1779,7 +1768,7 @@ struct uip_udp_hdr {
*
* \hideinitializer
*/
#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_TCPIP_HLEN)
#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_IPTCPH_LEN)
#define UIP_PROTO_ICMP 1
#define UIP_PROTO_TCP 6

View File

@ -1728,7 +1728,7 @@ uip_process(uint8_t flag)
/* Parse the TCP MSS option, if present. */
if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
opt = uip_buf[UIP_TCPIP_HLEN + c];
opt = uip_buf[UIP_IPTCPH_LEN + c];
if(opt == TCP_OPT_END) {
/* End of options. */
break;
@ -1736,9 +1736,9 @@ uip_process(uint8_t flag)
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + 1 + c] == TCP_OPT_MSS_LEN) {
uip_buf[UIP_IPTCPH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = ((uint16_t)uip_buf[UIP_TCPIP_HLEN + 2 + c] << 8) |
tmp16 = ((uint16_t)uip_buf[UIP_IPTCPH_LEN + 2 + c] << 8) |
(uint16_t)uip_buf[UIP_IPTCPH_LEN + 3 + c];
uip_connr->initialmss = uip_connr->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
@ -1748,12 +1748,12 @@ uip_process(uint8_t flag)
} else {
/* All other options have a length field, so that we easily
can skip past them. */
if(uip_buf[UIP_TCPIP_HLEN + 1 + c] == 0) {
if(uip_buf[UIP_IPTCPH_LEN + 1 + c] == 0) {
/* If the length field is zero, the options are malformed
and we don't process them further. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + 1 + c];
c += uip_buf[UIP_IPTCPH_LEN + 1 + c];
}
}
}
@ -1923,10 +1923,10 @@ uip_process(uint8_t flag)
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + 1 + c] == TCP_OPT_MSS_LEN) {
uip_buf[UIP_IPTCPH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = (uip_buf[UIP_TCPIP_HLEN + 2 + c] << 8) |
uip_buf[UIP_TCPIP_HLEN + 3 + c];
tmp16 = (uip_buf[UIP_IPTCPH_LEN + 2 + c] << 8) |
uip_buf[UIP_IPTCPH_LEN + 3 + c];
uip_connr->initialmss =
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
@ -1935,12 +1935,12 @@ uip_process(uint8_t flag)
} else {
/* All other options have a length field, so that we easily
can skip past them. */
if(uip_buf[UIP_TCPIP_HLEN + 1 + c] == 0) {
if(uip_buf[UIP_IPTCPH_LEN + 1 + c] == 0) {
/* If the length field is zero, the options are malformed
and we don't process them further. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + 1 + c];
c += uip_buf[UIP_IPTCPH_LEN + 1 + c];
}
}
}
@ -2123,7 +2123,7 @@ uip_process(uint8_t flag)
packet had new data in it, we must send out a packet. */
if(uip_slen > 0 && uip_connr->len > 0) {
/* Add the length of the IP and TCP headers. */
uip_len = uip_connr->len + UIP_TCPIP_HLEN;
uip_len = uip_connr->len + UIP_IPTCPH_LEN;
/* We always set the ACK flag in response packets. */
UIP_TCP_BUF->flags = TCP_ACK | TCP_PSH;
/* Send the packet. */
@ -2132,7 +2132,7 @@ uip_process(uint8_t flag)
/* If there is no data to send, just send out a pure ACK if
there is newdata. */
if(uip_flags & UIP_NEWDATA) {
uip_len = UIP_TCPIP_HLEN;
uip_len = UIP_IPTCPH_LEN;
UIP_TCP_BUF->flags = TCP_ACK;
goto tcp_send_noopts;
}
@ -2307,10 +2307,10 @@ uip_send(const void *data, int len)
int copylen;
if(uip_sappdata != NULL) {
copylen = MIN(len, UIP_BUFSIZE - UIP_TCPIP_HLEN -
copylen = MIN(len, UIP_BUFSIZE - UIP_IPTCPH_LEN -
(int)((char *)uip_sappdata - (char *)UIP_TCP_PAYLOAD));
} else {
copylen = MIN(len, UIP_BUFSIZE - UIP_TCPIP_HLEN);
copylen = MIN(len, UIP_BUFSIZE - UIP_IPTCPH_LEN);
}
if(copylen > 0) {
uip_slen = copylen;

View File

@ -414,15 +414,15 @@ void uip_log(char *msg);
* The TCP maximum segment size.
*
* This is should not be to set to more than
* UIP_BUFSIZE - UIP_TCPIP_HLEN.
* UIP_BUFSIZE - UIP_IPTCPH_LEN.
*/
#ifdef UIP_CONF_TCP_MSS
#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_TCPIP_HLEN)
#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_IPTCPH_LEN)
#error UIP_CONF_TCP_MSS is too large for the current UIP_BUFSIZE
#endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_TCPIP_HLEN) */
#endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_IPTCPH_LEN) */
#define UIP_TCP_MSS (UIP_CONF_TCP_MSS)
#else /* UIP_CONF_TCP_MSS */
#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_TCPIP_HLEN)
#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_IPTCPH_LEN)
#endif /* UIP_CONF_TCP_MSS */
/**

View File

@ -367,9 +367,9 @@ insert_srh_header(void)
}
/* Move existing ext headers and payload ext_len further */
memmove(uip_buf + uip_l2_l3_hdr_len + ext_len,
uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN);
memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len);
memmove(uip_buf + UIP_IPH_LEN + uip_ext_len + ext_len,
uip_buf + UIP_IPH_LEN + uip_ext_len, uip_len - UIP_IPH_LEN);
memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len);
/* Insert source routing header (as first ext header) */
UIP_RH_BUF(0)->next = UIP_IP_BUF->proto;

View File

@ -256,9 +256,9 @@ insert_srh_header(void)
}
/* Move existing ext headers and payload ext_len further */
memmove(uip_buf + uip_l2_l3_hdr_len + ext_len,
uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN);
memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len);
memmove(uip_buf + UIP_IPH_LEN + uip_ext_len + ext_len,
uip_buf + UIP_IPH_LEN + uip_ext_len, uip_len - UIP_IPH_LEN);
memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len);
/* Insert source routing header (as first ext header) */
UIP_RH_BUF(0)->next = UIP_IP_BUF->proto;

View File

@ -409,7 +409,7 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr)
arp_hdr->protolen = 4;
arp_hdr->ethhdr.type = UIP_HTONS(IP64_ETH_TYPE_ARP);
uip_appdata = &uip_buf[UIP_TCPIP_HLEN];
uip_appdata = &uip_buf[UIP_IPTCPH_LEN];
return sizeof(struct arp_hdr);
}

View File

@ -451,7 +451,7 @@ arp_out(struct ethip_hdr *iphdr, int len)
arphdr->protolen = 4;
arphdr->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
/* uip_appdata = &uip_buf[UIP_TCPIP_HLEN];*/
/* uip_appdata = &uip_buf[UIP_IPTCPH_LEN];*/
return sizeof(struct arp_hdr);
}