Merge branch 'feature/ip_route_base_on_source_ip_v2.1' into 'release/v2.1'

Broadcast IP route based on source IP address.

See merge request !1218
This commit is contained in:
Jiang Jiang Jian 2017-09-30 16:04:03 +08:00
commit 90aafbd25b
2 changed files with 29 additions and 1 deletions

View file

@ -115,9 +115,36 @@ 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 hook function. This function works only
* when destination IP is broadcast IP.
*/
struct netif *
ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src)
{
struct netif *netif = NULL;
/* destination IP is broadcast IP? */
if ((src != NULL) && (dest->addr == IPADDR_BROADCAST)) {
/* iterate through netifs */
for (netif = netif_list; netif != NULL; netif = netif->next) {
/* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
/* source IP matches? */
if (ip4_addr_cmp(src, netif_ip4_addr(netif))) {
/* return netif on which to forward IP packet */
return netif;
}
}
}
}
return netif;
}
/**
* Source based IPv4 routing must be fully implemented in
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides he parameters.
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides the parameters.
*/
struct netif *
ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)

View file

@ -574,6 +574,7 @@
---------- Hook options ---------------
---------------------------------------
*/
#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook
/*
---------------------------------------