Cleanup hton*/ntoh* function handling and platform abstraction

Let lwip use functions/macros prefixed by lwip_ internally to avoid naming clashes with external #includes.
Remove over-complicated #define handling in def.h
Make functions easier to override in cc.h. The following is sufficient now (no more LWIP_PLATFORM_BYTESWAP):
#define lwip_htons(x) <your_htons>
#define lwip_htonl(x) <your_htonl>
This commit is contained in:
Dirk Ziegelmeier
2016-10-06 12:55:57 +02:00
parent 0c06073819
commit 13fb616bb2
44 changed files with 370 additions and 426 deletions

View File

@@ -152,7 +152,7 @@ ip6addr_aton(const char *cp, ip6_addr_t *addr)
/* convert to network byte order. */
if (addr) {
for (addr_index = 0; addr_index < 4; addr_index++) {
addr->addr[addr_index] = htonl(addr->addr[addr_index]);
addr->addr[addr_index] = lwip_htonl(addr->addr[addr_index]);
}
}
@@ -199,7 +199,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
for (current_block_index = 0; current_block_index < 8; current_block_index++) {
/* get the current 16-bit block */
current_block_value = htonl(addr->addr[current_block_index >> 1]);
current_block_value = lwip_htonl(addr->addr[current_block_index >> 1]);
if ((current_block_index & 0x1) == 0) {
current_block_value = current_block_value >> 16;
}
@@ -218,7 +218,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
if (empty_block_flag == 0) {
/* generate empty block "::", but only if more than one contiguous zero block,
* according to current formatting suggestions RFC 5952. */
next_block_value = htonl(addr->addr[(current_block_index + 1) >> 1]);
next_block_value = lwip_htonl(addr->addr[(current_block_index + 1) >> 1]);
if ((current_block_index & 0x1) == 0x01) {
next_block_value = next_block_value >> 16;
}

View File

@@ -279,12 +279,12 @@ ip6_reass(struct pbuf *p)
clen = pbuf_clen(p);
offset = ntohs(frag_hdr->_fragment_offset);
offset = lwip_ntohs(frag_hdr->_fragment_offset);
/* Calculate fragment length from IPv6 payload length.
* Adjust for headers before Fragment Header.
* And finally adjust by Fragment Header length. */
len = ntohs(ip6_current_header()->_plen);
len = lwip_ntohs(ip6_current_header()->_plen);
len -= (u16_t)(((u8_t*)p->payload - (const u8_t*)ip6_current_header()) - IP6_HLEN);
len -= IP6_FRAG_HLEN;
@@ -560,7 +560,7 @@ ip6_reass(struct pbuf *p)
- IP6_HLEN);
/* Set payload length in ip header. */
iphdr_ptr->_plen = htons(ipr->datagram_len);
iphdr_ptr->_plen = lwip_htons(ipr->datagram_len);
/* Get the first pbuf. */
p = ipr->p;
@@ -748,8 +748,8 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest)
/* Set headers */
frag_hdr->_nexth = original_ip6hdr->_nexth;
frag_hdr->reserved = 0;
frag_hdr->_fragment_offset = htons((fragment_offset & IP6_FRAG_OFFSET_MASK) | (last ? 0 : IP6_FRAG_MORE_FLAG));
frag_hdr->_identification = htonl(identification);
frag_hdr->_fragment_offset = lwip_htons((fragment_offset & IP6_FRAG_OFFSET_MASK) | (last ? 0 : IP6_FRAG_MORE_FLAG));
frag_hdr->_identification = lwip_htonl(identification);
IP6H_NEXTH_SET(ip6hdr, IP6_NEXTH_FRAGMENT);
IP6H_PLEN_SET(ip6hdr, cop + IP6_FRAG_HLEN);

View File

@@ -420,15 +420,15 @@ nd6_input(struct pbuf *p, struct netif *inp)
}
/* Re-set invalidation timer. */
default_router_list[i].invalidation_timer = htons(ra_hdr->router_lifetime);
default_router_list[i].invalidation_timer = lwip_htons(ra_hdr->router_lifetime);
/* Re-set default timer values. */
#if LWIP_ND6_ALLOW_RA_UPDATES
if (ra_hdr->retrans_timer > 0) {
retrans_timer = htonl(ra_hdr->retrans_timer);
retrans_timer = lwip_htonl(ra_hdr->retrans_timer);
}
if (ra_hdr->reachable_time > 0) {
reachable_time = htonl(ra_hdr->reachable_time);
reachable_time = lwip_htonl(ra_hdr->reachable_time);
}
#endif /* LWIP_ND6_ALLOW_RA_UPDATES */
@@ -479,9 +479,9 @@ nd6_input(struct pbuf *p, struct netif *inp)
{
struct mtu_option *mtu_opt;
mtu_opt = (struct mtu_option *)buffer;
if (htonl(mtu_opt->mtu) >= 1280) {
if (lwip_htonl(mtu_opt->mtu) >= 1280) {
#if LWIP_ND6_ALLOW_RA_UPDATES
inp->mtu = (u16_t)htonl(mtu_opt->mtu);
inp->mtu = (u16_t)lwip_htonl(mtu_opt->mtu);
#endif /* LWIP_ND6_ALLOW_RA_UPDATES */
}
break;
@@ -507,7 +507,7 @@ nd6_input(struct pbuf *p, struct netif *inp)
prefix = nd6_new_onlink_prefix(ip6_current_dest_addr(), inp);
}
if (prefix >= 0) {
prefix_list[prefix].invalidation_timer = htonl(prefix_opt->valid_lifetime);
prefix_list[prefix].invalidation_timer = lwip_htonl(prefix_opt->valid_lifetime);
#if LWIP_IPV6_AUTOCONFIG
if (prefix_opt->flags & ND6_PREFIX_FLAG_AUTONOMOUS) {
@@ -640,7 +640,7 @@ nd6_input(struct pbuf *p, struct netif *inp)
}
/* Change the Path MTU. */
pmtu = htonl(icmp6hdr->data);
pmtu = lwip_htonl(icmp6hdr->data);
destination_cache[i].pmtu = (u16_t)LWIP_MIN(pmtu, 0xFFFF);
break; /* ICMP6_TYPE_PTB */