Seen in ptpd v2.3.0
Problem:
netShutdownMulticastIPv4() does not check whether multicastAddr is 0x0 or not. Hence, setsockopt(IP_DROP_MEMBERSHIP) is called with this invalid address:
static Boolean
netShutdownMulticastIPv4(NetPath * netPath, Integer32 multicastAddr)
{
struct ip_mreq imr;
/* Close General Multicast */
imr.imr_multiaddr.s_addr = multicastAddr;
imr.imr_interface.s_addr = netPath->interfaceAddr.s_addr;
setsockopt(netPath->eventSock, IPPROTO_IP, IP_DROP_MEMBERSHIP,
&imr, sizeof(struct ip_mreq));
setsockopt(netPath->generalSock, IPPROTO_IP, IP_DROP_MEMBERSHIP,
&imr, sizeof(struct ip_mreq));
return TRUE;
}
When using the LWIP TCP/IP stack, an assertion is triggered for this condition (unless assertions are disabled).
Proposal:
When entering netShutdownMulticastIPv4(), check if multicastAddr is 0x0. In that case, return immediately.
Fredrik,
A zero value should not get there in the first place. NetInitMulticast always calls ChooseMcastGroup before netInitMulticastIPv4. After a quick analysis, the only reason I can think of where a zero would get there, is if there was an error while initialising the network.
Under what conditions does this get triggered? We can add the check you suggest, but I'd like to find out why this is happening at all.
I'm quite interested in having this working with LWIP - some FPGA based offload cards use it that are of my interest.
We are planning a major rewrite of the network subsystem in the next version of ptpd anyway, but any bug identified is a help.
Regards
Wojciech
OK, are you running unicast?
It looks like netShutdownMulticast is called in netShutdown even if we're running unicast - this is one place where this could happen.
Regards
Wojciech
No, I'm not running unicast. It's normal IPv4 multicast.
It is old problem of PTPd design. PTPd calls netShutdown prior to any netInit. Sockets and all netPath variables are uninitialised. It is silently ignored on Linux and FreeBSD but it may cause problems on other platforms: LwIP based, InterrvalZero RTX RTTCP/IP stack, MS Windows, ...
Regards,
Jan
Wojciech and Jan,
Thanks for looking at this.
The root cause of the problem is the problem described in [#63], i.e. that netPath.interfaceAddr no longer is the same as the interface IP address. The sequence of events leading to the problem described in the ticket description goes like this:
Regards,
Fredrik
Related
Bugs:
#63Finally fixed this, svn 594