mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-10 17:43:39 +08:00
eliminate temporary storage when using netif addresses for ip_addr_t* now that they have the correct type (ATTENTION: ip6_select_source_address() and ip4_netif_get_local_ip() now return ip_addr_t*!)
This commit is contained in:
@@ -163,7 +163,7 @@ icmp6_input(struct pbuf *p, struct netif *inp)
|
||||
/* Determine reply source IPv6 address. */
|
||||
#if LWIP_MULTICAST_PING
|
||||
if (ip6_addr_ismulticast(ip6_current_dest_addr())) {
|
||||
reply_src = ip6_select_source_address(inp, ip6_current_src_addr());
|
||||
reply_src = ip_2_ip6_c(ip6_select_source_address(inp, ip6_current_src_addr()));
|
||||
if (reply_src == NULL) {
|
||||
/* drop */
|
||||
pbuf_free(p);
|
||||
@@ -323,7 +323,7 @@ icmp6_send_response(struct pbuf *p, u8_t code, u32_t data, u8_t type)
|
||||
reply_dest = ip6_current_src_addr();
|
||||
|
||||
/* Select an address to use as source. */
|
||||
reply_src = ip6_select_source_address(netif, reply_dest);
|
||||
reply_src = ip_2_ip6_c(ip6_select_source_address(netif, reply_dest));
|
||||
if (reply_src == NULL) {
|
||||
/* drop */
|
||||
pbuf_free(q);
|
||||
|
||||
@@ -206,10 +206,10 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
|
||||
* @return the most suitable source address to use, or NULL if no suitable
|
||||
* source address is found
|
||||
*/
|
||||
const ip6_addr_t *
|
||||
const ip_addr_t *
|
||||
ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest)
|
||||
{
|
||||
const ip6_addr_t *src = NULL;
|
||||
const ip_addr_t *src = NULL;
|
||||
u8_t i;
|
||||
|
||||
/* If dest is link-local, choose a link-local source. */
|
||||
@@ -217,7 +217,7 @@ ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest)
|
||||
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
|
||||
ip6_addr_islinklocal(netif_ip6_addr(netif, i))) {
|
||||
return netif_ip6_addr(netif, i);
|
||||
return netif_ip_addr6(netif, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest)
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
|
||||
ip6_addr_issitelocal(netif_ip6_addr(netif, i)) &&
|
||||
ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
|
||||
return netif_ip6_addr(netif, i);
|
||||
return netif_ip_addr6(netif, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest)
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
|
||||
ip6_addr_isuniquelocal(netif_ip6_addr(netif, i)) &&
|
||||
ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
|
||||
return netif_ip6_addr(netif, i);
|
||||
return netif_ip_addr6(netif, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,14 +250,14 @@ ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest)
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
|
||||
ip6_addr_isglobal(netif_ip6_addr(netif, i))) {
|
||||
if (src == NULL) {
|
||||
src = netif_ip6_addr(netif, i);
|
||||
src = netif_ip_addr6(netif, i);
|
||||
}
|
||||
else {
|
||||
/* Replace src only if we find a prefix match. */
|
||||
/* TODO find longest matching prefix. */
|
||||
if ((!(ip6_addr_netcmp(src, dest))) &&
|
||||
if ((!(ip6_addr_netcmp(ip_2_ip6_c(src), dest))) &&
|
||||
ip6_addr_netcmp(netif_ip6_addr(netif, i), dest)) {
|
||||
src = netif_ip6_addr(netif, i);
|
||||
src = netif_ip_addr6(netif, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,7 @@ ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest)
|
||||
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
|
||||
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
|
||||
ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
|
||||
return netif_ip6_addr(netif, i);
|
||||
return netif_ip_addr6(netif, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
|
||||
const ip6_addr_t *src_used = src;
|
||||
if (dest != IP_HDRINCL) {
|
||||
if (src != NULL && ip6_addr_isany(src)) {
|
||||
src = ip6_select_source_address(netif, dest);
|
||||
src = ip_2_ip6_c(ip6_select_source_address(netif, dest));
|
||||
if ((src == NULL) || ip6_addr_isany(src)) {
|
||||
/* No appropriate source address was found for this packet. */
|
||||
LWIP_DEBUGF(IP6_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip6_output: No suitable source address for packet.\n"));
|
||||
|
||||
@@ -276,20 +276,6 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
|
||||
}
|
||||
|
||||
#if LWIP_IPV4
|
||||
/** Convert IPv6 address to generic IP address.
|
||||
* Since source types do not contain the type field, a target storage needs to be supplied.
|
||||
*/
|
||||
ip_addr_t*
|
||||
ip6_2_ip(const ip6_addr_t *ip6addr, ip_addr_t* storage)
|
||||
{
|
||||
if ((ip6addr == NULL) || (storage == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
ip6_addr_copy(storage->u_addr.ip6, *ip6addr);
|
||||
IP_SET_TYPE_VAL(*storage, IPADDR_TYPE_V6);
|
||||
return storage;
|
||||
}
|
||||
|
||||
/** Convert IP address string (both versions) to numeric.
|
||||
* The version is auto-detected from the string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user