mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-04 21:39:49 +00:00
patch #6808: Add a utility function ip_hinted_output() (for smaller code mainly)
This commit is contained in:
parent
4f52183a39
commit
580f334274
@ -83,6 +83,10 @@ HISTORY
|
|||||||
|
|
||||||
++ Bugfixes:
|
++ Bugfixes:
|
||||||
|
|
||||||
|
2009-04-15 Simon Goldschmidt
|
||||||
|
* ip.c, ip6.c, tcp_out.c, ip.h: patch #6808: Add a utility function
|
||||||
|
ip_hinted_output() (for smaller code mainly)
|
||||||
|
|
||||||
2009-04-15 Simon Goldschmidt
|
2009-04-15 Simon Goldschmidt
|
||||||
* inet.c: patch #6765: Supporting new line characters in inet_aton()
|
* inet.c: patch #6765: Supporting new line characters in inet_aton()
|
||||||
|
|
||||||
|
@ -570,12 +570,54 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
|||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
|
|
||||||
if ((netif = ip_route(dest)) == NULL) {
|
if ((netif = ip_route(dest)) == NULL) {
|
||||||
|
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%"X32_F"\n", dest->addr));
|
||||||
|
IP_STATS_INC(ip.rterr);
|
||||||
return ERR_RTE;
|
return ERR_RTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ip_output_if(p, src, dest, ttl, tos, proto, netif);
|
return ip_output_if(p, src, dest, ttl, tos, proto, netif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
|
/** Like ip_output, but takes and addr_hint pointer that is passed on to netif->addr_hint
|
||||||
|
* before calling ip_output_if.
|
||||||
|
*
|
||||||
|
* @param p the packet to send (p->payload points to the data, e.g. next
|
||||||
|
protocol header; if dest == IP_HDRINCL, p already includes an IP
|
||||||
|
header and p->payload points to that IP header)
|
||||||
|
* @param src the source IP address to send from (if src == IP_ADDR_ANY, the
|
||||||
|
* IP address of the netif used to send is used as source address)
|
||||||
|
* @param dest the destination IP address to send the packet to
|
||||||
|
* @param ttl the TTL value to be set in the IP header
|
||||||
|
* @param tos the TOS value to be set in the IP header
|
||||||
|
* @param proto the PROTOCOL to be set in the IP header
|
||||||
|
* @param addr_hint address hint pointer set to netif->addr_hint before
|
||||||
|
* calling ip_output_if()
|
||||||
|
*
|
||||||
|
* @return ERR_RTE if no route is found
|
||||||
|
* see ip_output_if() for more return values
|
||||||
|
*/
|
||||||
|
err_t
|
||||||
|
ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||||
|
u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint)
|
||||||
|
{
|
||||||
|
struct netif *netif;
|
||||||
|
err_t err;
|
||||||
|
|
||||||
|
if ((netif = ip_route(dest)) == NULL) {
|
||||||
|
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%"X32_F"\n", dest->addr));
|
||||||
|
IP_STATS_INC(ip.rterr);
|
||||||
|
return ERR_RTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
netif->addr_hint = addr_hint;
|
||||||
|
err = ip_output_if(p, src, dest, ttl, tos, proto, netif);
|
||||||
|
netif->addr_hint = NULL;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
|
|
||||||
#if IP_DEBUG
|
#if IP_DEBUG
|
||||||
/* Print an IP header by using LWIP_DEBUGF
|
/* Print an IP header by using LWIP_DEBUGF
|
||||||
* @param p an IP packet, p->payload pointing to the IP header
|
* @param p an IP packet, p->payload pointing to the IP header
|
||||||
|
@ -327,6 +327,28 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
|||||||
return ip_output_if (p, src, dest, ttl, proto, netif);
|
return ip_output_if (p, src, dest, ttl, proto, netif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
|
err_t
|
||||||
|
ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||||
|
u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint)
|
||||||
|
{
|
||||||
|
struct netif *netif;
|
||||||
|
err_t err;
|
||||||
|
|
||||||
|
if ((netif = ip_route(dest)) == NULL) {
|
||||||
|
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%"X32_F"\n", dest->addr));
|
||||||
|
IP_STATS_INC(ip.rterr);
|
||||||
|
return ERR_RTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
netif->addr_hint = addr_hint;
|
||||||
|
err = ip_output_if(p, src, dest, ttl, tos, proto, netif);
|
||||||
|
netif->addr_hint = NULL;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
|
|
||||||
#if IP_DEBUG
|
#if IP_DEBUG
|
||||||
void
|
void
|
||||||
ip_debug_print(struct pbuf *p)
|
ip_debug_print(struct pbuf *p)
|
||||||
|
@ -501,16 +501,8 @@ tcp_output(struct tcp_pcb *pcb)
|
|||||||
IP_PROTO_TCP, p->tot_len);
|
IP_PROTO_TCP, p->tot_len);
|
||||||
#endif
|
#endif
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
{
|
ip_output_hinted(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
|
||||||
struct netif *netif;
|
IP_PROTO_TCP, &(pcb->addr_hint));
|
||||||
netif = ip_route(&pcb->remote_ip);
|
|
||||||
if(netif != NULL){
|
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
|
||||||
ip_output_if(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl,
|
|
||||||
pcb->tos, IP_PROTO_TCP, netif);
|
|
||||||
netif->addr_hint = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else /* LWIP_NETIF_HWADDRHINT*/
|
#else /* LWIP_NETIF_HWADDRHINT*/
|
||||||
ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
|
ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
|
||||||
IP_PROTO_TCP);
|
IP_PROTO_TCP);
|
||||||
@ -700,16 +692,8 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
|||||||
TCP_STATS_INC(tcp.xmit);
|
TCP_STATS_INC(tcp.xmit);
|
||||||
|
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
{
|
ip_output_hinted(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
|
||||||
struct netif *netif;
|
IP_PROTO_TCP, &(pcb->addr_hint));
|
||||||
netif = ip_route(&pcb->remote_ip);
|
|
||||||
if(netif != NULL){
|
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
|
||||||
ip_output_if(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl,
|
|
||||||
pcb->tos, IP_PROTO_TCP, netif);
|
|
||||||
netif->addr_hint = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else /* LWIP_NETIF_HWADDRHINT*/
|
#else /* LWIP_NETIF_HWADDRHINT*/
|
||||||
ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
|
ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
|
||||||
IP_PROTO_TCP);
|
IP_PROTO_TCP);
|
||||||
@ -887,16 +871,8 @@ tcp_keepalive(struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
/* Send output to IP */
|
/* Send output to IP */
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
{
|
ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP,
|
||||||
struct netif *netif;
|
&(pcb->addr_hint));
|
||||||
netif = ip_route(&pcb->remote_ip);
|
|
||||||
if(netif != NULL){
|
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
|
||||||
ip_output_if(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl,
|
|
||||||
0, IP_PROTO_TCP, netif);
|
|
||||||
netif->addr_hint = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else /* LWIP_NETIF_HWADDRHINT*/
|
#else /* LWIP_NETIF_HWADDRHINT*/
|
||||||
ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
|
ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
@ -966,16 +942,8 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
/* Send output to IP */
|
/* Send output to IP */
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
{
|
ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP,
|
||||||
struct netif *netif;
|
&(pcb->addr_hint));
|
||||||
netif = ip_route(&pcb->remote_ip);
|
|
||||||
if(netif != NULL){
|
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
|
||||||
ip_output_if(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl,
|
|
||||||
0, IP_PROTO_TCP, netif);
|
|
||||||
netif->addr_hint = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else /* LWIP_NETIF_HWADDRHINT*/
|
#else /* LWIP_NETIF_HWADDRHINT*/
|
||||||
ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
|
ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
|
@ -496,7 +496,7 @@ udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
|
|||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
netif->addr_hint = &(pcb->addr_hint);
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
|
err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
netif->addr_hint = NULL;
|
netif->addr_hint = NULL;
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
@ -519,7 +519,7 @@ udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
|
|||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
netif->addr_hint = &(pcb->addr_hint);
|
netif->addr_hint = &(pcb->addr_hint);
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
|
err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
|
||||||
#if LWIP_NETIF_HWADDRHINT
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
netif->addr_hint = NULL;
|
netif->addr_hint = NULL;
|
||||||
#endif /* LWIP_NETIF_HWADDRHINT*/
|
#endif /* LWIP_NETIF_HWADDRHINT*/
|
||||||
|
@ -47,10 +47,14 @@ extern "C" {
|
|||||||
struct netif *ip_route(struct ip_addr *dest);
|
struct netif *ip_route(struct ip_addr *dest);
|
||||||
err_t ip_input(struct pbuf *p, struct netif *inp);
|
err_t ip_input(struct pbuf *p, struct netif *inp);
|
||||||
err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||||
u8_t ttl, u8_t tos, u8_t proto);
|
u8_t ttl, u8_t tos, u8_t proto);
|
||||||
err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||||
u8_t ttl, u8_t tos, u8_t proto,
|
u8_t ttl, u8_t tos, u8_t proto,
|
||||||
struct netif *netif);
|
struct netif *netif);
|
||||||
|
#if LWIP_NETIF_HWADDRHINT
|
||||||
|
err_t ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||||
|
u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
|
||||||
|
#endif /* LWIP_NETIF_HWADDRHINT */
|
||||||
|
|
||||||
#define IP_HLEN 20
|
#define IP_HLEN 20
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user