Mon 23 Mar 2015 03:54:08 PM UTC, original submission:
In udp_input (udp.c) the dst address is not being checked vs. the pcb when the pcb is connectionless. Arriving UDP is only checked for matching port number.
If two Multicast UDP sockets are open using different addresses but the same port number then the frame will arrive on both.
My application requires that the UDP frame is only copied to the PCB with the matching multicast address.
May I propose an enhancement to include an option to check for a match vs. pcb.multicast_ip when current_iphdr_dest is multicast? I've implemented the following in udp.c and it works for me:
//FROM LINE 239
/* compare PCB local addr+port to UDP destination addr+port */
if (pcb->local_port == dest) {
#if MC_MATCH_DSTADDRESS
bool mc_match_dstaddress = true;
if (ip_addr_ismulticast(¤t_iphdr_dest))
{
if (!ip_addr_cmp(&(pcb->multicast_ip), ¤t_iphdr_dest))
{
mc_match_dstaddress = false;
}
}
if (mc_match_dstaddress)
{
#endif
if (
(!broadcast && ip_addr_isany(&pcb->local_ip)) ||
ip_addr_cmp(&(pcb->local_ip), ¤t_iphdr_dest) ||
#if LWIP_IGMP
ip_addr_ismulticast(¤t_iphdr_dest) ||
#endif /* LWIP_IGMP */
#if IP_SOF_BROADCAST_RECV
(broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
(ip_addr_isany(&pcb->local_ip) ||
ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))) {
#else /* IP_SOF_BROADCAST_RECV */
(broadcast &&
(ip_addr_isany(&pcb->local_ip) ||
ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))) {
#endif /* IP_SOF_BROADCAST_RECV */
local_match = 1;
if ((uncon_pcb == NULL) &&
((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
/* the first unconnected matching PCB */
uncon_pcb = pcb;
}
}
#if MC_MATCH_DSTADDRESS
}
#endif
I also added "#define MC_MATCH_DSTADDRESS 1" to opt.h. multicast_ip is set using setsockopt with the IP_MULTICAST_IF option.
|