mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-11 10:03:47 +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:
@@ -315,20 +315,4 @@ ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen)
|
||||
return buf;
|
||||
}
|
||||
|
||||
#if LWIP_IPV6
|
||||
/** Convert IPv4 address to generic IP address.
|
||||
* Since source types do not contain the type field, a target storage need to be supplied.
|
||||
*/
|
||||
ip_addr_t*
|
||||
ip4_2_ip(const ip4_addr_t *ip4addr, ip_addr_t* storage)
|
||||
{
|
||||
if ((ip4addr == NULL) || (storage == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
ip4_addr_copy(storage->u_addr.ip4, *ip4addr);
|
||||
IP_SET_TYPE_VAL(*storage, IPADDR_TYPE_V4);
|
||||
return storage;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -241,9 +241,6 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
||||
struct pbuf *q; /* q will be sent down the stack */
|
||||
s16_t header_size;
|
||||
const ip_addr_t *dst_ip = ipaddr;
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
ip_addr_t src_ip_tmp;
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
|
||||
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
|
||||
return ERR_VAL;
|
||||
@@ -314,7 +311,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
||||
|
||||
if (ip_addr_isany(&pcb->local_ip)) {
|
||||
/* use outgoing network interface IP address as source address */
|
||||
src_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, dst_ip, &src_ip_tmp);
|
||||
src_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, dst_ip);
|
||||
#if LWIP_IPV6
|
||||
if (src_ip == NULL) {
|
||||
if (q != p) {
|
||||
|
||||
@@ -228,9 +228,6 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
|
||||
{
|
||||
struct snmp_trap_dst *td;
|
||||
struct netif *dst_if;
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
ip_addr_t dst_ip_storage;
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
const ip_addr_t* dst_ip;
|
||||
struct pbuf *p;
|
||||
u16_t i,tot_len;
|
||||
@@ -244,7 +241,7 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
|
||||
ip_addr_copy(trap_msg.dip, td->dip);
|
||||
/* lookup current source address for this dst */
|
||||
ip_route_get_local_ip(PCB_ISIPV6(trap_msg.pcb), &trap_msg.pcb->local_ip,
|
||||
&td->dip, dst_if, dst_ip, &dst_ip_storage);
|
||||
&td->dip, dst_if, dst_ip);
|
||||
if ((dst_if != NULL) && (dst_ip != NULL)) {
|
||||
trap_msg.sip_raw_len = (IP_IS_V6_VAL(*dst_ip) ? 16 : 4);
|
||||
memcpy(trap_msg.sip_raw, dst_ip, trap_msg.sip_raw_len);
|
||||
|
||||
@@ -755,9 +755,6 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
||||
err_t ret;
|
||||
u32_t iss;
|
||||
u16_t old_local_port;
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
ip_addr_t local_ip_tmp;
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
|
||||
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
|
||||
return ERR_VAL;
|
||||
@@ -778,7 +775,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
||||
/* no local IP address set, yet. */
|
||||
struct netif *netif;
|
||||
const ip_addr_t *local_ip;
|
||||
ip_route_get_local_ip(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip, &local_ip_tmp);
|
||||
ip_route_get_local_ip(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip);
|
||||
if ((netif == NULL) || (local_ip == NULL)) {
|
||||
/* Don't even try to send a SYN packet if we have no route
|
||||
since that will fail. */
|
||||
|
||||
@@ -1198,13 +1198,11 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
||||
/* If we don't have a local IP address, we get one from netif */
|
||||
if (ip_addr_isany(&pcb->local_ip)) {
|
||||
const ip_addr_t *local_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif,
|
||||
&pcb->remote_ip, &pcb->local_ip);
|
||||
&pcb->remote_ip);
|
||||
if (local_ip == NULL) {
|
||||
return ERR_RTE;
|
||||
}
|
||||
#if !LWIP_IPV4 || !LWIP_IPV6
|
||||
ip_addr_copy(pcb->local_ip, *local_ip);
|
||||
#endif /* !LWIP_IPV4 || !LWIP_IPV6 */
|
||||
}
|
||||
|
||||
if (pcb->rttest == 0) {
|
||||
|
||||
@@ -596,7 +596,8 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
||||
in pcb->multicast_ip that is used for routing. */
|
||||
if (!ip4_addr_isany(&pcb->multicast_ip) &&
|
||||
!ip4_addr_cmp(&pcb->multicast_ip, IP4_ADDR_BROADCAST)) {
|
||||
dst_ip_route = ip4_2_ip(&pcb->multicast_ip, &dst_ip_tmp);
|
||||
ip_addr_copy_from_ip4(dst_ip_tmp, pcb->multicast_ip);
|
||||
dst_ip_route = &dst_ip_tmp;
|
||||
}
|
||||
#endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS */
|
||||
}
|
||||
@@ -656,9 +657,6 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i
|
||||
{
|
||||
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
|
||||
const ip_addr_t *src_ip;
|
||||
#if LWIP_IPV6 && LWIP_IPV4
|
||||
ip_addr_t src_ip_tmp;
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV4 */
|
||||
|
||||
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
|
||||
return ERR_VAL;
|
||||
@@ -668,7 +666,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i
|
||||
#if LWIP_IPV6
|
||||
if (PCB_ISIPV6(pcb)) {
|
||||
if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip))) {
|
||||
src_ip = ip6_2_ip(ip6_select_source_address(netif, ip_2_ip6_c(dst_ip)), &src_ip_tmp);
|
||||
src_ip = ip6_select_source_address(netif, ip_2_ip6_c(dst_ip));
|
||||
if (src_ip == NULL) {
|
||||
/* No suitable source address was found. */
|
||||
return ERR_RTE;
|
||||
@@ -1056,7 +1054,7 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
|
||||
/** TODO: this will bind the udp pcb locally, to the interface which
|
||||
is used to route output packets to the remote address. However, we
|
||||
might want to accept incoming packets on any interface! */
|
||||
ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, &pcb->remote_ip, &pcb->local_ip);
|
||||
ip_addr_set(&pcb->local_ip, ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, &pcb->remote_ip));
|
||||
} else if (ip_addr_isany(&pcb->remote_ip)) {
|
||||
ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->local_ip);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user