fix type conversion errors introduced with last commit

This commit is contained in:
Simon Goldschmidt 2018-05-17 22:35:12 +02:00
parent 0c2fdfcf42
commit 11c294e973
3 changed files with 32 additions and 24 deletions

View File

@ -819,7 +819,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
dest = &mcastaddr; dest = &mcastaddr;
/* unicast destination IP address? */ /* unicast destination IP address? */
} else { } else {
u16_t i; netif_addr_idx_t i;
/* outside local network? if so, this can neither be a global broadcast nor /* outside local network? if so, this can neither be a global broadcast nor
a subnet broadcast. */ a subnet broadcast. */
if (!ip4_addr_netcmp(ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif)) && if (!ip4_addr_netcmp(ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif)) &&
@ -936,7 +936,7 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
err_t result = ERR_MEM; err_t result = ERR_MEM;
int is_new_entry = 0; int is_new_entry = 0;
s16_t i_err; s16_t i_err;
u16_t i; netif_addr_idx_t i;
/* non-unicast address? */ /* non-unicast address? */
if (ip4_addr_isbroadcast(ipaddr, netif) || if (ip4_addr_isbroadcast(ipaddr, netif) ||
@ -958,7 +958,8 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
} }
return (err_t)i_err; return (err_t)i_err;
} }
i = (u16_t)i_err; LWIP_ASSERT("type overflow", (size_t)i_err < NETIF_ADDR_IDX_MAX);
i = (netif_addr_idx_t)i_err;
/* mark a fresh entry as pending (we just sent a request) */ /* mark a fresh entry as pending (we just sent a request) */
if (arp_table[i].state == ETHARP_STATE_EMPTY) { if (arp_table[i].state == ETHARP_STATE_EMPTY) {

View File

@ -286,6 +286,7 @@ nd6_input(struct pbuf *p, struct netif *inp)
{ {
u8_t msg_type; u8_t msg_type;
s8_t i; s8_t i;
s16_t dest_idx;
ND6_STATS_INC(nd6.recv); ND6_STATS_INC(nd6.recv);
@ -836,8 +837,8 @@ nd6_input(struct pbuf *p, struct netif *inp)
} }
/* Find dest address in cache */ /* Find dest address in cache */
i = nd6_find_destination_cache_entry(&destination_address); dest_idx = nd6_find_destination_cache_entry(&destination_address);
if (i < 0) { if (dest_idx < 0) {
/* Destination not in cache, drop packet. */ /* Destination not in cache, drop packet. */
pbuf_free(p); pbuf_free(p);
return; return;
@ -848,7 +849,7 @@ nd6_input(struct pbuf *p, struct netif *inp)
ip6_addr_assign_zone(&target_address, IP6_UNICAST, inp); ip6_addr_assign_zone(&target_address, IP6_UNICAST, inp);
/* Set the new target address. */ /* Set the new target address. */
ip6_addr_copy(destination_cache[i].next_hop_addr, target_address); ip6_addr_copy(destination_cache[dest_idx].next_hop_addr, target_address);
/* If Link-layer address of other router is given, try to add to neighbor cache. */ /* If Link-layer address of other router is given, try to add to neighbor cache. */
if (lladdr_opt != NULL) { if (lladdr_opt != NULL) {
@ -904,8 +905,8 @@ nd6_input(struct pbuf *p, struct netif *inp)
ip6_addr_assign_zone(&destination_address, IP6_UNKNOWN, inp); ip6_addr_assign_zone(&destination_address, IP6_UNKNOWN, inp);
/* Look for entry in destination cache. */ /* Look for entry in destination cache. */
i = nd6_find_destination_cache_entry(&destination_address); dest_idx = nd6_find_destination_cache_entry(&destination_address);
if (i < 0) { if (dest_idx < 0) {
/* Destination not in cache, drop packet. */ /* Destination not in cache, drop packet. */
pbuf_free(p); pbuf_free(p);
return; return;
@ -913,7 +914,7 @@ nd6_input(struct pbuf *p, struct netif *inp)
/* Change the Path MTU. */ /* Change the Path MTU. */
pmtu = lwip_htonl(icmp6hdr->data); pmtu = lwip_htonl(icmp6hdr->data);
destination_cache[i].pmtu = (u16_t)LWIP_MIN(pmtu, 0xFFFF); destination_cache[dest_idx].pmtu = (u16_t)LWIP_MIN(pmtu, 0xFFFF);
break; /* ICMP6_TYPE_PTB */ break; /* ICMP6_TYPE_PTB */
} }
@ -1539,10 +1540,10 @@ nd6_free_neighbor_cache_entry(s8_t i)
* @return The destination cache entry index that matched, -1 if no * @return The destination cache entry index that matched, -1 if no
* entry is found * entry is found
*/ */
static s8_t static s16_t
nd6_find_destination_cache_entry(const ip6_addr_t *ip6addr) nd6_find_destination_cache_entry(const ip6_addr_t *ip6addr)
{ {
s8_t i; s16_t i;
IP6_ADDR_ZONECHECK(ip6addr); IP6_ADDR_ZONECHECK(ip6addr);
@ -1564,7 +1565,7 @@ nd6_find_destination_cache_entry(const ip6_addr_t *ip6addr)
static s16_t static s16_t
nd6_new_destination_cache_entry(void) nd6_new_destination_cache_entry(void)
{ {
s8_t i, j; s16_t i, j;
u32_t age; u32_t age;
/* Find an empty entry. */ /* Find an empty entry. */
@ -1910,6 +1911,7 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif)
const ip6_addr_t *next_hop_addr; const ip6_addr_t *next_hop_addr;
#endif /* LWIP_HOOK_ND6_GET_GW */ #endif /* LWIP_HOOK_ND6_GET_GW */
s8_t i; s8_t i;
s16_t dst_idx;
IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif); IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif);
@ -1930,16 +1932,18 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif)
ND6_STATS_INC(nd6.cachehit); ND6_STATS_INC(nd6.cachehit);
} else { } else {
/* Search destination cache. */ /* Search destination cache. */
i = nd6_find_destination_cache_entry(ip6addr); dst_idx = nd6_find_destination_cache_entry(ip6addr);
if (i >= 0) { if (dst_idx >= 0) {
/* found destination entry. make it our new cached index. */ /* found destination entry. make it our new cached index. */
nd6_cached_destination_index = i; LWIP_ASSERT("type overflow", (size_t)dst_idx < NETIF_ADDR_IDX_MAX);
nd6_cached_destination_index = (netif_addr_idx_t)dst_idx;
} else { } else {
/* Not found. Create a new destination entry. */ /* Not found. Create a new destination entry. */
i = nd6_new_destination_cache_entry(); dst_idx = nd6_new_destination_cache_entry();
if (i >= 0) { if (dst_idx >= 0) {
/* got new destination entry. make it our new cached index. */ /* got new destination entry. make it our new cached index. */
nd6_cached_destination_index = i; LWIP_ASSERT("type overflow", (size_t)dst_idx < NETIF_ADDR_IDX_MAX);
nd6_cached_destination_index = (netif_addr_idx_t)dst_idx;
} else { } else {
/* Could not create a destination cache entry. */ /* Could not create a destination cache entry. */
return ERR_MEM; return ERR_MEM;
@ -2267,7 +2271,7 @@ nd6_get_next_hop_addr_or_queue(struct netif *netif, struct pbuf *q, const ip6_ad
u16_t u16_t
nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif) nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif)
{ {
s8_t i; s16_t i;
i = nd6_find_destination_cache_entry(ip6addr); i = nd6_find_destination_cache_entry(ip6addr);
if (i >= 0) { if (i >= 0) {
@ -2298,24 +2302,25 @@ void
nd6_reachability_hint(const ip6_addr_t *ip6addr) nd6_reachability_hint(const ip6_addr_t *ip6addr)
{ {
s8_t i; s8_t i;
s16_t dst_idx;
/* Find destination in cache. */ /* Find destination in cache. */
if (ip6_addr_cmp(ip6addr, &(destination_cache[nd6_cached_destination_index].destination_addr))) { if (ip6_addr_cmp(ip6addr, &(destination_cache[nd6_cached_destination_index].destination_addr))) {
i = nd6_cached_destination_index; dst_idx = nd6_cached_destination_index;
ND6_STATS_INC(nd6.cachehit); ND6_STATS_INC(nd6.cachehit);
} else { } else {
i = nd6_find_destination_cache_entry(ip6addr); dst_idx = nd6_find_destination_cache_entry(ip6addr);
} }
if (i < 0) { if (dst_idx < 0) {
return; return;
} }
/* Find next hop neighbor in cache. */ /* Find next hop neighbor in cache. */
if (ip6_addr_cmp(&(destination_cache[i].next_hop_addr), &(neighbor_cache[nd6_cached_neighbor_index].next_hop_address))) { if (ip6_addr_cmp(&(destination_cache[dst_idx].next_hop_addr), &(neighbor_cache[nd6_cached_neighbor_index].next_hop_address))) {
i = nd6_cached_neighbor_index; i = nd6_cached_neighbor_index;
ND6_STATS_INC(nd6.cachehit); ND6_STATS_INC(nd6.cachehit);
} else { } else {
i = nd6_find_neighbor_cache_entry(&(destination_cache[i].next_hop_addr)); i = nd6_find_neighbor_cache_entry(&(destination_cache[dst_idx].next_hop_addr));
} }
if (i < 0) { if (i < 0) {
return; return;

View File

@ -239,8 +239,10 @@ u8_t netif_alloc_client_data_id(void);
#if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f)) #if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f))
typedef u16_t netif_addr_idx_t; typedef u16_t netif_addr_idx_t;
#define NETIF_ADDR_IDX_MAX 0x7FFF
#else #else
typedef u8_t netif_addr_idx_t; typedef u8_t netif_addr_idx_t;
#define NETIF_ADDR_IDX_MAX 0x7F
#endif #endif
#if LWIP_NETIF_HWADDRHINT #if LWIP_NETIF_HWADDRHINT