|
From: <wow...@us...> - 2015-10-15 04:11:02
|
Revision: 594
http://sourceforge.net/p/ptpd/code/594
Author: wowczarek
Date: 2015-10-15 04:11:00 +0000 (Thu, 15 Oct 2015)
Log Message:
-----------
- prevent from leaving multicast group zero
- only join necessary multicast group,
tested when switching between e2e and p2p
while reloading ptpd
Modified Paths:
--------------
trunk/src/dep/datatypes_dep.h
trunk/src/dep/net.c
Modified: trunk/src/dep/datatypes_dep.h
===================================================================
--- trunk/src/dep/datatypes_dep.h 2015-10-14 19:46:42 UTC (rev 593)
+++ trunk/src/dep/datatypes_dep.h 2015-10-15 04:11:00 UTC (rev 594)
@@ -112,7 +112,8 @@
/* used for tracking the last TTL set */
int ttlGeneral;
int ttlEvent;
- Boolean joinedMulticast;
+ Boolean joinedPeer;
+ Boolean joinedGeneral;
struct ether_addr etherDest;
struct ether_addr peerEtherDest;
Boolean txTimestampFailure;
Modified: trunk/src/dep/net.c
===================================================================
--- trunk/src/dep/net.c 2015-10-14 19:46:42 UTC (rev 593)
+++ trunk/src/dep/net.c 2015-10-15 04:11:00 UTC (rev 594)
@@ -98,6 +98,10 @@
{
struct ip_mreq imr;
+ if(!multicastAddr || !netPath->interfaceAddr.s_addr) {
+ return TRUE;
+ }
+
/* Close General Multicast */
imr.imr_multiaddr.s_addr = multicastAddr;
imr.imr_interface.s_addr = netPath->interfaceAddr.s_addr;
@@ -106,7 +110,7 @@
&imr, sizeof(struct ip_mreq));
setsockopt(netPath->generalSock, IPPROTO_IP, IP_DROP_MEMBERSHIP,
&imr, sizeof(struct ip_mreq));
-
+
return TRUE;
}
@@ -133,7 +137,7 @@
/*
* For future use: Check if IPv4 address is multiast -
- * If last 4 bits of an address are 0xE (1110), it's multicast
+ * If first 4 bits of an address are 0xE (1110), it's multicast
*/
/*
static Boolean
@@ -560,7 +564,7 @@
}
/* this allows for leaving groups only if joined */
- netPath->joinedMulticast = TRUE;
+ netPath->joinedGeneral = TRUE;
netPath->multicastAddr = netAddr.s_addr;
if(!netInitMulticastIPv4(netPath, netPath->multicastAddr)) {
@@ -569,6 +573,9 @@
/* End of General multicast Ip address init */
+ if(rtOpts->delayMechanism != P2P) {
+ return TRUE;
+ }
/* Init Peer multicast IP address */
strncpy(addrStr, PEER_PTP_DOMAIN_ADDRESS, NET_ADDRESS_LENGTH);
@@ -576,6 +583,10 @@
ERROR("failed to encode multicast address: %s\n", addrStr);
return FALSE;
}
+
+ /* track if we have joined the p2p mcast group */
+ netPath->joinedPeer = TRUE;
+
netPath->peerMulticastAddr = netAddr.s_addr;
if(!netInitMulticastIPv4(netPath, netPath->peerMulticastAddr)) {
return FALSE;
@@ -2211,15 +2222,23 @@
netRefreshIGMP(NetPath * netPath, const RunTimeOpts * rtOpts, PtpClock * ptpClock)
{
DBG("netRefreshIGMP\n");
-
- if(netPath->joinedMulticast)
- netShutdownMulticast(netPath);
-
+
+ if(netPath->joinedGeneral) {
+ netShutdownMulticastIPv4(netPath, netPath->multicastAddr);
+ netPath->multicastAddr = 0;
+ }
+
+ if(netPath->joinedPeer) {
+ netShutdownMulticastIPv4(netPath, netPath->peerMulticastAddr);
+ netPath->peerMulticastAddr = 0;
+ }
+
/* suspend process 100 milliseconds, to make sure the kernel sends the IGMP_leave properly */
usleep(100*1000);
if (!netInitMulticast(netPath, rtOpts)) {
return FALSE;
}
+
return TRUE;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|