mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-12 22:14:25 +00:00
Reduce usage of PCB IP version flag in raw and tcp code. Maybe we can figure out a good way for dual-stack UDP when we manage to remove the flag (nearly) entirely from the code.
This commit is contained in:
parent
f104d68569
commit
5809b01388
@ -248,7 +248,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
|||||||
|
|
||||||
header_size = (
|
header_size = (
|
||||||
#if LWIP_IPV4 && LWIP_IPV6
|
#if LWIP_IPV4 && LWIP_IPV6
|
||||||
PCB_ISIPV6(pcb) ? IP6_HLEN : IP_HLEN);
|
IP_IS_V6(ipaddr) ? IP6_HLEN : IP_HLEN);
|
||||||
#elif LWIP_IPV4
|
#elif LWIP_IPV4
|
||||||
IP_HLEN);
|
IP_HLEN);
|
||||||
#else
|
#else
|
||||||
@ -279,7 +279,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip);
|
netif = ip_route(IP_IS_V6(dst_ip), &pcb->local_ip, dst_ip);
|
||||||
if (netif == NULL) {
|
if (netif == NULL) {
|
||||||
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to "));
|
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to "));
|
||||||
ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, dst_ip);
|
ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, dst_ip);
|
||||||
@ -291,7 +291,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if IP_SOF_BROADCAST
|
#if IP_SOF_BROADCAST
|
||||||
if (!PCB_ISIPV6(pcb))
|
if (!IP_IS_V6(ipaddr))
|
||||||
{
|
{
|
||||||
/* broadcast filter? */
|
/* broadcast filter? */
|
||||||
if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(ipaddr, netif)) {
|
if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(ipaddr, netif)) {
|
||||||
@ -307,7 +307,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
|||||||
|
|
||||||
if (ip_addr_isany(&pcb->local_ip)) {
|
if (ip_addr_isany(&pcb->local_ip)) {
|
||||||
/* use outgoing network interface IP address as source address */
|
/* use outgoing network interface IP address as source address */
|
||||||
src_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, dst_ip);
|
src_ip = ip_netif_get_local_ip(IP_IS_V6(dst_ip), netif, dst_ip);
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
if (src_ip == NULL) {
|
if (src_ip == NULL) {
|
||||||
if (q != p) {
|
if (q != p) {
|
||||||
@ -324,7 +324,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
|||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
/* If requested, based on the IPV6_CHECKSUM socket option per RFC3542,
|
/* If requested, based on the IPV6_CHECKSUM socket option per RFC3542,
|
||||||
compute the checksum and update the checksum in the payload. */
|
compute the checksum and update the checksum in the payload. */
|
||||||
if (PCB_ISIPV6(pcb) && pcb->chksum_reqd) {
|
if (IP_IS_V6(dst_ip) && pcb->chksum_reqd) {
|
||||||
u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(dst_ip));
|
u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(dst_ip));
|
||||||
LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2));
|
LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2));
|
||||||
SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t));
|
SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t));
|
||||||
@ -332,7 +332,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
|
NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
|
||||||
err = ip_output_if(PCB_ISIPV6(pcb), q, src_ip, dst_ip, pcb->ttl, pcb->tos, pcb->protocol, netif);
|
err = ip_output_if(IP_IS_V6(dst_ip), q, src_ip, dst_ip, pcb->ttl, pcb->tos, pcb->protocol, netif);
|
||||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||||
|
|
||||||
/* did we chain a header earlier? */
|
/* did we chain a header earlier? */
|
||||||
|
@ -769,7 +769,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
|||||||
/* no local IP address set, yet. */
|
/* no local IP address set, yet. */
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
const ip_addr_t *local_ip;
|
const ip_addr_t *local_ip;
|
||||||
ip_route_get_local_ip(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip);
|
ip_route_get_local_ip(IP_IS_V6(ipaddr), &pcb->local_ip, &pcb->remote_ip, netif, local_ip);
|
||||||
if ((netif == NULL) || (local_ip == NULL)) {
|
if ((netif == NULL) || (local_ip == NULL)) {
|
||||||
/* Don't even try to send a SYN packet if we have no route
|
/* Don't even try to send a SYN packet if we have no route
|
||||||
since that will fail. */
|
since that will fail. */
|
||||||
@ -823,7 +823,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
|||||||
The send MSS is updated when an MSS option is received. */
|
The send MSS is updated when an MSS option is received. */
|
||||||
pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
|
pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
|
||||||
#if TCP_CALCULATE_EFF_SEND_MSS
|
#if TCP_CALCULATE_EFF_SEND_MSS
|
||||||
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip, PCB_ISIPV6(pcb));
|
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip, IP_IS_V6_VAL(pcb->remote_ip));
|
||||||
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
||||||
pcb->cwnd = 1;
|
pcb->cwnd = 1;
|
||||||
pcb->ssthresh = TCP_WND;
|
pcb->ssthresh = TCP_WND;
|
||||||
|
@ -740,7 +740,7 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
#if TCP_CALCULATE_EFF_SEND_MSS
|
#if TCP_CALCULATE_EFF_SEND_MSS
|
||||||
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip,
|
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip,
|
||||||
PCB_ISIPV6(pcb));
|
IP_IS_V6_VAL(pcb->remote_ip));
|
||||||
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
||||||
|
|
||||||
/* Set ssthresh again after changing 'mss' and 'snd_wnd' */
|
/* Set ssthresh again after changing 'mss' and 'snd_wnd' */
|
||||||
|
@ -930,7 +930,7 @@ tcp_send_empty_ack(struct tcp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip);
|
netif = ip_route(IP_IS_V6_VAL(pcb->remote_ip), &pcb->local_ip, &pcb->remote_ip);
|
||||||
if (netif == NULL) {
|
if (netif == NULL) {
|
||||||
err = ERR_RTE;
|
err = ERR_RTE;
|
||||||
} else {
|
} else {
|
||||||
@ -941,7 +941,7 @@ tcp_send_empty_ack(struct tcp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
||||||
err = ip_output_if(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip,
|
err = ip_output_if(IP_IS_V6_VAL(pcb->remote_ip), p, &pcb->local_ip, &pcb->remote_ip,
|
||||||
pcb->ttl, pcb->tos, IP_PROTO_TCP, netif);
|
pcb->ttl, pcb->tos, IP_PROTO_TCP, netif);
|
||||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||||
}
|
}
|
||||||
@ -1161,7 +1161,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
|||||||
if (seg->flags & TF_SEG_OPTS_MSS) {
|
if (seg->flags & TF_SEG_OPTS_MSS) {
|
||||||
u16_t mss;
|
u16_t mss;
|
||||||
#if TCP_CALCULATE_EFF_SEND_MSS
|
#if TCP_CALCULATE_EFF_SEND_MSS
|
||||||
mss = tcp_eff_send_mss(TCP_MSS, &pcb->local_ip, &pcb->remote_ip, PCB_ISIPV6(pcb));
|
mss = tcp_eff_send_mss(TCP_MSS, &pcb->local_ip, &pcb->remote_ip, IP_IS_V6_VAL(pcb->remote_ip));
|
||||||
#else /* TCP_CALCULATE_EFF_SEND_MSS */
|
#else /* TCP_CALCULATE_EFF_SEND_MSS */
|
||||||
mss = TCP_MSS;
|
mss = TCP_MSS;
|
||||||
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
|
||||||
@ -1189,14 +1189,14 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
|||||||
pcb->rtime = 0;
|
pcb->rtime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip);
|
netif = ip_route(IP_IS_V6_VAL(pcb->remote_ip), &pcb->local_ip, &pcb->remote_ip);
|
||||||
if (netif == NULL) {
|
if (netif == NULL) {
|
||||||
return ERR_RTE;
|
return ERR_RTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we don't have a local IP address, we get one from netif */
|
/* If we don't have a local IP address, we get one from netif */
|
||||||
if (ip_addr_isany(&pcb->local_ip)) {
|
if (ip_addr_isany(&pcb->local_ip)) {
|
||||||
const ip_addr_t *local_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif,
|
const ip_addr_t *local_ip = ip_netif_get_local_ip(IP_IS_V6_VAL(pcb->remote_ip), netif,
|
||||||
&pcb->remote_ip);
|
&pcb->remote_ip);
|
||||||
if (local_ip == NULL) {
|
if (local_ip == NULL) {
|
||||||
return ERR_RTE;
|
return ERR_RTE;
|
||||||
@ -1262,7 +1262,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
|||||||
TCP_STATS_INC(tcp.xmit);
|
TCP_STATS_INC(tcp.xmit);
|
||||||
|
|
||||||
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
||||||
err = ip_output_if(PCB_ISIPV6(pcb), seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
|
err = ip_output_if(IP_IS_V6_VAL(pcb->remote_ip), seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
|
||||||
pcb->tos, IP_PROTO_TCP, netif);
|
pcb->tos, IP_PROTO_TCP, netif);
|
||||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||||
return err;
|
return err;
|
||||||
@ -1493,7 +1493,7 @@ tcp_keepalive(struct tcp_pcb *pcb)
|
|||||||
("tcp_keepalive: could not allocate memory for pbuf\n"));
|
("tcp_keepalive: could not allocate memory for pbuf\n"));
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip);
|
netif = ip_route(IP_IS_V6_VAL(pcb->remote_ip), &pcb->local_ip, &pcb->remote_ip);
|
||||||
if (netif == NULL) {
|
if (netif == NULL) {
|
||||||
err = ERR_RTE;
|
err = ERR_RTE;
|
||||||
} else {
|
} else {
|
||||||
@ -1508,7 +1508,7 @@ tcp_keepalive(struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
/* Send output to IP */
|
/* Send output to IP */
|
||||||
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
||||||
err = ip_output_if(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
|
err = ip_output_if(IP_IS_V6_VAL(pcb->remote_ip), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
|
||||||
0, IP_PROTO_TCP, netif);
|
0, IP_PROTO_TCP, netif);
|
||||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||||
}
|
}
|
||||||
@ -1581,7 +1581,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
|
|||||||
pbuf_copy_partial(seg->p, d, 1, seg->p->tot_len - seg->len);
|
pbuf_copy_partial(seg->p, d, 1, seg->p->tot_len - seg->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip);
|
netif = ip_route(IP_IS_V6_VAL(pcb->remote_ip), &pcb->local_ip, &pcb->remote_ip);
|
||||||
if (netif == NULL) {
|
if (netif == NULL) {
|
||||||
err = ERR_RTE;
|
err = ERR_RTE;
|
||||||
} else {
|
} else {
|
||||||
@ -1595,7 +1595,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
/* Send output to IP */
|
/* Send output to IP */
|
||||||
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
|
||||||
err = ip_output_if(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
|
err = ip_output_if(IP_IS_V6_VAL(pcb->remote_ip), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
|
||||||
0, IP_PROTO_TCP, netif);
|
0, IP_PROTO_TCP, netif);
|
||||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user