support IPv4 source based routing: define LWIP_HOOK_IP4_ROUTE_SRC to point to a routing function

This commit is contained in:
sg
2015-08-30 21:54:39 +02:00
parent 3121b34d17
commit a01a1b4556
7 changed files with 59 additions and 15 deletions

View File

@@ -113,6 +113,24 @@ ip4_set_default_multicast_netif(struct netif* default_multicast_netif)
}
#endif /* LWIP_MULTICAST_TX_OPTIONS */
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
/**
* Source based IPv4 routing must be fully implemented in
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides he parameters.
*/
struct netif *
ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
{
if (src != NULL) {
struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, src);
if (netif != NULL) {
return netif;
}
}
return ip4_route(dest);
}
#endif /* LWIP_HOOK_IP4_ROUTE_SRC */
/**
* Finds the appropriate network interface for a given IP address. It
* searches the list of network interfaces linearly. A match is found
@@ -127,7 +145,12 @@ ip4_route(const ip4_addr_t *dest)
{
struct netif *netif;
#ifdef LWIP_HOOK_IP4_ROUTE
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, NULL);
if (netif != NULL) {
return netif;
}
#elif defined(LWIP_HOOK_IP4_ROUTE)
netif = LWIP_HOOK_IP4_ROUTE(dest);
if (netif != NULL) {
return netif;
@@ -253,7 +276,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
}
/* Find network interface where to forward this IP packet to. */
netif = ip4_route(ip4_current_dest_addr());
netif = ip4_route_src(ip4_current_dest_addr(), ip4_current_src_addr());
if (netif == NULL) {
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for %"U16_F".%"U16_F".%"U16_F".%"U16_F" found\n",
ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
@@ -937,7 +960,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
if ((netif = ip4_route(dest)) == NULL) {
if ((netif = ip4_route_src(dest, src)) == 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);
@@ -975,7 +998,7 @@ ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
if ((netif = ip4_route(dest)) == NULL) {
if ((netif = ip4_route_src(dest, src)) == 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);