Tue 17 Feb 2015 09:33:22 PM UTC, comment #6:
This is what I did with ip_route():
diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c
index a2551d6..8223721 100644
--- a/src/core/ipv4/ip4.c
+++ b/src/core/ipv4/ip4.c
@@ -108,7 +108,7 @@
* @return the netif on which to send to reach dest
*/
struct netif *
-ip_route(ip_addr_t *dest)
+ip_route(ip_addr_t src, ip_addr_t dest)
{
struct netif *netif;
@@ -133,6 +133,19 @@
return netif;
}
}
+ }
+ if (!ip_addr_isany(src)) {
+ for (netif = netif_list; netif != NULL; netif = netif->next) {
+ /* network mask matches? */
+ if (netif_is_up(netif)) {
+ if (ip_addr_cmp(src, &(netif->ip_addr))) {
+ if (!ip_addr_isany(&(netif->gw))) {
+ /* return netif on which to forward IP packet */
+ return netif;
+ }
+ }
+ }
+ }
}
if ((netif_default == NULL) || (!netif_is_up(netif_default))) {
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
@@ -868,7 +881,7 @@
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
- if ((netif = ip_route(dest)) == NULL) {
+ if ((netif = ip_route(src, dest)) == NULL) {
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
IP_STATS_INC(ip.rterr);
diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h
index 350d51b..296de24 100644
--- a/src/include/lwip/ip.h
+++ b/src/include/lwip/ip.h
@@ -230,7 +230,7 @@
#define ipX_route(isipv6, src, dest) \
((isipv6) ? \
ip6_route(ipX_2_ip6(src), ipX_2_ip6(dest)) : \
- ip_route(ipX_2_ip(dest)))
+ ip_route(ipX_2_ip(src), ipX_2_ip(dest)))
#define ipX_netif_get_local_ipX(isipv6, netif, dest) \
((isipv6) ? \
ip6_netif_get_local_ipX(netif, ipX_2_ip6(dest)) : \
@@ -246,7 +246,7 @@
#define ipX_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
#define ipX_route(isipv6, src, dest) \
- ip_route(ipX_2_ip(dest))
+ ip_route(&ip_addr_any, ipX_2_ip(dest))
#define ipX_netif_get_local_ipX(isipv6, netif, dest) \
ip_netif_get_local_ipX(netif)
#define ipX_debug_print(is_ipv6, p) ip_debug_print(p)
diff --git a/src/include/lwip/ip4.h b/src/include/lwip/ip4.h
index c49a771..d3dedc7 100644
--- a/src/include/lwip/ip4.h
+++ b/src/include/lwip/ip4.h
@@ -112,7 +112,7 @@
#define ip_init() /* Compatibility define, no init needed. */
-struct netif ip_route(ip_addr_t dest);
+struct netif ip_route(ip_addr_t src, ip_addr_t *dest);
err_t ip_input(struct pbuf p, struct netif inp);
err_t ip_output(struct pbuf p, ip_addr_t src, ip_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto);
|
Mon 13 Aug 2012 08:04:11 PM UTC, comment #1:
> Intuitively I think we should be passing the accepted netif
For "simple" applications, I think so, too.
> but keeping a reference to inp means we can send response packets on the same netif that we received data
I think you can argue about that: from testing at work, I know that at least Windows XP sends out packets to the normal route, no matter where a packet has been received (yes, also ICMP responses).
So while the logical thing to do would be to respond on 'inp', I think that responding on the accepting netif would be just as good: if the caller delays its response, the accepting netif would be used anyway!
|