From 580f33427459e2aa6df77c255d962436bb0f0b6b Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 15 Apr 2009 19:32:01 +0000 Subject: [PATCH] patch #6808: Add a utility function ip_hinted_output() (for smaller code mainly) --- CHANGELOG | 4 ++++ src/core/ipv4/ip.c | 42 +++++++++++++++++++++++++++++++++ src/core/ipv6/ip6.c | 22 +++++++++++++++++ src/core/tcp_out.c | 48 +++++++------------------------------- src/core/udp.c | 4 ++-- src/include/ipv4/lwip/ip.h | 6 ++++- 6 files changed, 83 insertions(+), 43 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 04ea9a90..09cbd513 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -83,6 +83,10 @@ HISTORY ++ 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 * inet.c: patch #6765: Supporting new line characters in inet_aton() diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index f74f423e..93258f29 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -570,12 +570,54 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, struct netif *netif; 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 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 /* Print an IP header by using LWIP_DEBUGF * @param p an IP packet, p->payload pointing to the IP header diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index ce5b501f..7e434200 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -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); } +#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 void ip_debug_print(struct pbuf *p) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 653ce4ae..a7aec309 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -501,16 +501,8 @@ tcp_output(struct tcp_pcb *pcb) IP_PROTO_TCP, p->tot_len); #endif #if LWIP_NETIF_HWADDRHINT - { - struct netif *netif; - 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; - } - } + ip_output_hinted(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, + IP_PROTO_TCP, &(pcb->addr_hint)); #else /* LWIP_NETIF_HWADDRHINT*/ ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, IP_PROTO_TCP); @@ -700,16 +692,8 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) TCP_STATS_INC(tcp.xmit); #if LWIP_NETIF_HWADDRHINT - { - struct netif *netif; - 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; - } - } + ip_output_hinted(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, + IP_PROTO_TCP, &(pcb->addr_hint)); #else /* LWIP_NETIF_HWADDRHINT*/ ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, IP_PROTO_TCP); @@ -887,16 +871,8 @@ tcp_keepalive(struct tcp_pcb *pcb) /* Send output to IP */ #if LWIP_NETIF_HWADDRHINT - { - struct netif *netif; - 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; - } - } + ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP, + &(pcb->addr_hint)); #else /* LWIP_NETIF_HWADDRHINT*/ ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP); #endif /* LWIP_NETIF_HWADDRHINT*/ @@ -966,16 +942,8 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) /* Send output to IP */ #if LWIP_NETIF_HWADDRHINT - { - struct netif *netif; - 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; - } - } + ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP, + &(pcb->addr_hint)); #else /* LWIP_NETIF_HWADDRHINT*/ ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP); #endif /* LWIP_NETIF_HWADDRHINT*/ diff --git a/src/core/udp.c b/src/core/udp.c index 0d139b53..25364625 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -496,7 +496,7 @@ udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p, #if LWIP_NETIF_HWADDRHINT netif->addr_hint = &(pcb->addr_hint); #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 netif->addr_hint = NULL; #endif /* LWIP_NETIF_HWADDRHINT*/ @@ -519,7 +519,7 @@ udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p, #if LWIP_NETIF_HWADDRHINT netif->addr_hint = &(pcb->addr_hint); #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 netif->addr_hint = NULL; #endif /* LWIP_NETIF_HWADDRHINT*/ diff --git a/src/include/ipv4/lwip/ip.h b/src/include/ipv4/lwip/ip.h index 3b760f00..36fd5c9d 100644 --- a/src/include/ipv4/lwip/ip.h +++ b/src/include/ipv4/lwip/ip.h @@ -47,10 +47,14 @@ extern "C" { struct netif *ip_route(struct ip_addr *dest); 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, - 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, u8_t ttl, u8_t tos, u8_t proto, 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