fixed bug #38061 (wrong multicast routing in IPv4) by adding an optional default netif for multicast routing

This commit is contained in:
sg
2015-02-25 20:58:11 +01:00
parent 3e8ac30940
commit 612e33c499
4 changed files with 43 additions and 5 deletions

View File

@@ -98,6 +98,18 @@ struct ip_globals ip_data;
/** The IP header ID of the next outgoing IP packet */
static u16_t ip_id;
#if LWIP_IGMP
/** The default netif used for multicast */
static struct netif* ip_default_multicast_netif;
/** Set a default netif for IPv4 multicast. */
void
ip_set_default_multicast_netif(struct netif* default_multicast_netif)
{
ip_default_multicast_netif = default_multicast_netif;
}
#endif /* LWIP_IGMP */
/**
* Finds the appropriate network interface for a given IP address. It
* searches the list of network interfaces linearly. A match is found
@@ -119,6 +131,13 @@ ip_route(const ip_addr_t *dest)
}
#endif
#if LWIP_IGMP
/* Use administratively selected interface for multicast by default */
if (ip_addr_ismulticast(dest) && ip_default_multicast_netif) {
return ip_default_multicast_netif;
}
#endif /* LWIP_IGMP */
/* iterate through netifs */
for (netif = netif_list; netif != NULL; netif = netif->next) {
/* network mask matches? */

View File

@@ -559,15 +559,22 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
#if LWIP_IPV6 || LWIP_IGMP
if (ipX_addr_ismulticast(PCB_ISIPV6(pcb), dst_ip_route)) {
/* For multicast, find a netif based on source address. */
#if LWIP_IPV6
if (PCB_ISIPV6(pcb)) {
/* For multicast, find a netif based on source address. */
dst_ip_route = &pcb->local_ip;
} else
#endif /* LWIP_IPV6 */
{
#if LWIP_IGMP
dst_ip_route = ip_2_ipX(&pcb->multicast_ip);
/* IPv4 does not use source-based routing by default, so we use an
administratively selected interface for multicast by default.
However, this can be overridden by setting an interface address
in pcb->multicast_ip that is used for routing. */
if (!ip_addr_isany(&pcb->multicast_ip) &&
!ip_addr_cmp(&pcb->multicast_ip, IP_ADDR_BROADCAST)) {
dst_ip_route = ip_2_ipX(&pcb->multicast_ip);
}
#endif /* LWIP_IGMP */
}
}