OK, here is a combined patch that cleans up the use of the address resolution
mutex by hiding it in a macro.
Incidentally, my ntop machine is a 400Mhz Pentium with 768MB RAM and 120GB
drive. It is attached to a switch that funnels all traffic from a 1000+ node
network to it.
rtg
On Thursday 02 January 2003 14:21, Burton M. Strauss III wrote:
> Good find ...
>
> For form's sake, might want to use
>
> #if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
>
> in the plugin, so it's the same test as in address.c, report.c,
> reportUtils.c and webInterface.c
>
>
> actually, there are a couple of OTHER places which need their tests
> adjusted... grepping the code gives:
>
> address.c OK
> initialize.c needs correx
> ntop.c OK
> plugins/icmpPlugin.c your fix
> plugins/nfsPlugin.c needs correx
> report.c OK
> reportUtils.c OK
> util.c needs correx
> webInterface.c OK
>
> Would you like to try fixing the other three and sending a combined patch?
>
> FWIW, patches (once you're ready to have them applied) should be sent to
> the special address, [EMAIL PROTECTED] -- Luca usually won't look at
> attachments sent to any other address.
>
> -----Burton
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf
> Of Tim Gardner
> Sent: Thursday, January 02, 2003 1:23 PM
> To: NTOP Developers List
> Subject: [Ntop-dev] icmpPlugin.c patch to fix addressResolutionMutex
> access bug.
>
>
> The ICMP plugin was incorrectly using addressResolutionMutex if it was not
> initialized. See attached.
--
Tim Gardner - [EMAIL PROTECTED] 406-443-5357
TriplePoint, Inc. - http://www.tpi.com
PGP: http://www.tpi.com/PGP/Tim.txt
--- ntop.cvs/ntop/./globals-core.h 2003-01-02 11:28:35.000000000 -0700
+++ ntop/ntop/./globals-core.h 2003-01-02 18:02:19.000000000 -0700
@@ -24,6 +24,14 @@
extern NtopGlobals myGlobals;
+#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
+#define accessAddrResMutex(a) if(myGlobals.numericFlag == 0) accessMutex(&myGlobals.addressResolutionMutex,a)
+#define releaseAddrResMutex() if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex)
+#else
+#define accessAddrResMutex(a)
+#define releaseAddrResMutex()
+#endif
+
#ifdef HAVE_LIBWRAP
extern int allow_severity, deny_severity;
#endif
--- ntop.cvs/ntop/./report.c 2003-01-02 11:29:43.000000000 -0700
+++ ntop/ntop/./report.c 2003-01-02 18:05:20.000000000 -0700
@@ -3776,13 +3776,9 @@
*/
return(strcasecmp(a->domainHost->fullDomainName, b->domainHost->fullDomainName));
} else {
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) accessMutex(&myGlobals.addressResolutionMutex, "fillDomainName");
-#endif
+ accessAddrResMutex("fillDomainName");
rc = strcasecmp(a->domainHost->hostSymIpAddress, b->domainHost->hostSymIpAddress);
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
}
return(rc);
@@ -4111,18 +4107,14 @@
char tmpBuf[64], *hostLink;
int blankId;
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) accessMutex(&myGlobals.addressResolutionMutex, "getHostIcon");
-#endif
+ accessAddrResMutex("getHostIcon");
blankId = strlen(statsEntry->domainHost->hostSymIpAddress)-
strlen(statsEntry->domainHost->fullDomainName)-1;
strncpy(tmpBuf, statsEntry->domainHost->hostSymIpAddress, sizeof(tmpBuf));
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
if((blankId > 0)
&& (strcmp(&tmpBuf[blankId+1], domainName) == 0))
--- ntop.cvs/ntop/./address.c 2003-01-02 11:26:33.000000000 -0700
+++ ntop/ntop/./address.c 2003-01-02 18:03:17.000000000 -0700
@@ -59,10 +59,7 @@
/* Search the instance and update its name */
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "updateHostNameInfo");
-#endif
+ accessAddrResMutex("updateHostNameInfo");
idx = findHostIdxByNumIP(addr, actualDeviceId);
@@ -75,10 +72,7 @@
}
}
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
}
/* ************************************ */
--- ntop.cvs/ntop/./main.c 2003-01-02 11:29:10.000000000 -0700
+++ ntop/ntop/./main.c 2003-01-02 17:12:13.000000000 -0700
@@ -696,7 +698,7 @@
bufLen=0;
for (i=0; i<argc; i++) {
- bufLen += 1 + strlen(argv[i]);
+ bufLen += (2 + strlen(argv[i]));
}
startedAs = (char*)malloc(bufLen);
--- ntop.cvs/ntop/./util.c 2003-01-02 11:29:58.000000000 -0700
+++ ntop/ntop/./util.c 2003-01-02 18:02:32.000000000 -0700
@@ -2457,10 +2457,7 @@
|| (el->hostSymIpAddress[0] == '\0'))
return;
-#ifdef MULTITHREADED
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "fillDomainName");
-#endif
+ accessAddrResMutex("fillDomainName");
if((el->hostSymIpAddress[0] == '*')
|| (el->hostNumIpAddress[0] == '\0')
@@ -2468,10 +2465,7 @@
isdigit(el->hostSymIpAddress[0]))) {
/* NOTE: theDomainHasBeenComputed(el) = 0 */
el->fullDomainName = el->dotDomainName = "";
-#ifdef MULTITHREADED
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return;
}
@@ -2514,10 +2508,7 @@
el->fullDomainName = el->dotDomainName = "";
}
-#ifdef MULTITHREADED
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return;
}
@@ -2537,10 +2528,7 @@
/* traceEvent(TRACE_INFO, "'%s'\n", el->domainName); */
-#ifdef MULTITHREADED
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
}
/* ********************************* */
--- ntop.cvs/ntop/./webInterface.c 2003-01-02 11:30:14.000000000 -0700
+++ ntop/ntop/./webInterface.c 2003-01-02 18:02:16.000000000 -0700
@@ -348,10 +348,7 @@
bufIdx = (bufIdx+1)%5;
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "makeHostLink");
-#endif
+ accessAddrResMutex("makeHostLink");
if((el == myGlobals.otherHostEntry)
|| (el->hostSerial == myGlobals.otherHostEntryIdx)) {
@@ -365,10 +362,7 @@
if(snprintf(buf[bufIdx], BUF_SIZE, fmt, el->hostSymIpAddress) < 0)
BufferTooShort();
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(buf[bufIdx]);
}
@@ -402,10 +396,7 @@
usedEthAddress = 1;
}
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
if(specialMacAddress) {
tmpStr = el->ethAddressString;
@@ -531,10 +522,7 @@
bufIdx = (bufIdx+1)%5;
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "getHostName");
-#endif
+ accessAddrResMutex("getHostName");
tmpStr = el->hostSymIpAddress;
@@ -561,10 +549,7 @@
} else
strncpy(buf[bufIdx], el->ethAddressString, 80);
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(buf[bufIdx]);
}
--- ntop.cvs/ntop/./reportUtils.c 2003-01-02 11:29:48.000000000 -0700
+++ ntop/ntop/./reportUtils.c 2003-01-02 18:02:31.000000000 -0700
@@ -752,16 +752,10 @@
switch(myGlobals.columnSort) {
case 1:
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "sortHostFctn");
-#endif
+ accessAddrResMutex( "sortHostFctn");
rc = strcasecmp((*a)->hostSymIpAddress[0] != '\0' ? (*a)->hostSymIpAddress : (*a)->ethAddressString,
(*b)->hostSymIpAddress[0] != '\0' ? (*b)->hostSymIpAddress : (*b)->ethAddressString);
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(rc);
break;
case 2:
@@ -947,10 +941,7 @@
int rc;
/* Host name */
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "cmpFctn");
-#endif
+ accessAddrResMutex("cmpFctn");
if((*a)->hostSymIpAddress[0] != '\0') {
char *name1, *name2;
@@ -962,10 +953,7 @@
} else
rc = strcasecmp((*a)->ethAddressString, (*b)->ethAddressString);
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(rc);
} else if(myGlobals.columnSort == DOMAIN_DUMMY_IDX_VALUE) {
int rc;
@@ -1432,17 +1420,11 @@
break; /* NOTREACHED */
default:
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "cmpMulticastFctn");
-#endif
+ accessAddrResMutex("cmpMulticastFctn");
rc = strcmp((*a)->hostSymIpAddress, /* Host name */
(*b)->hostSymIpAddress);
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(rc);
}
}
@@ -1566,9 +1548,7 @@
break;
default: /* Host Name */
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) accessMutex(&myGlobals.addressResolutionMutex, "cmpHostsFctn");
-#endif
+ accessAddrResMutex("cmpHostsFctn");
name_a = (*a)->hostSymIpAddress;
@@ -1590,9 +1570,7 @@
name_b = (*b)->ethAddressString;
}
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
rc = strcasecmp(name_a, name_b); /* case insensitive */
@@ -2972,9 +2950,7 @@
int printedHeader, i;
char *dynIp, *multihomed;
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) accessMutex(&myGlobals.addressResolutionMutex, "printAllSessionsHTML");
-#endif
+ accessAddrResMutex("printAllSessionsHTML");
buf1[0]=0;
if(getSniffedDNSName(el->hostNumIpAddress, sniffedName, sizeof(sniffedName))) {
@@ -2999,9 +2975,7 @@
BufferTooShort();
}
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
printHTMLheader(buf, 0);
sendString("<CENTER>\n");
@@ -3010,20 +2984,14 @@
if(el->hostNumIpAddress[0] != '\0') {
char *countryIcon, *hostType;
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) accessMutex(&myGlobals.addressResolutionMutex, "printAllSessions-2");
-#endif
+ accessAddrResMutex("printAllSessions-2");
/* Courtesy of Roberto De Luca <[EMAIL PROTECTED]> */
if(strcmp(el->hostNumIpAddress, el->hostSymIpAddress) != 0) {
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
countryIcon = getHostCountryIconURL(el);
} else {
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
countryIcon = "";
}
@@ -3890,10 +3858,7 @@
static char buf[BUF_SIZE];
int idx = i*myGlobals.device[myGlobals.actualReportDeviceId].numHosts + j;
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0)
- accessMutex(&myGlobals.addressResolutionMutex, "buildHTMLBrowserWindowsLabel");
-#endif
+ accessAddrResMutex("buildHTMLBrowserWindowsLabel");
if((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx] == NULL)
|| ((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value == 0)
@@ -3928,9 +3893,7 @@
BufferTooShort();
}
-#if defined(MULTITHREADED) && defined(ASYNC_ADDRESS_RESOLUTION)
- if(myGlobals.numericFlag == 0) releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(buf);
}
--- ntop.cvs/ntop/intop/top.c 2002-11-12 06:53:29.000000000 -0700
+++ ntop/ntop/intop/top.c 2003-01-02 18:02:23.000000000 -0700
@@ -283,9 +283,7 @@
|| (el->hostSymIpAddress == NULL))
return;
-#ifdef MULTITHREADED
- accessMutex (&myGlobals.addressResolutionMutex, "yafillDomainName");
-#endif
+ accessAddrResMutex("yafillDomainName");
if ((el->hostSymIpAddress[0] == '*')
|| (el->hostNumIpAddress[0] == '\0')
@@ -293,9 +291,7 @@
isdigit(el->hostSymIpAddress[0]))) {
/* NOTE: theDomainHasBeenComputed(el) = 0 */
el->fullDomainName = el->dotDomainName = "";
-#ifdef MULTITHREADED
- releaseMutex (&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return;
}
@@ -335,9 +331,7 @@
el->fullDomainName = el->dotDomainName = "";
}
-#ifdef MULTITHREADED
- releaseMutex (&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return;
}
@@ -356,9 +350,7 @@
el->fullDomainName = &el->hostSymIpAddress[i+1];
-#ifdef MULTITHREADED
- releaseMutex (&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
}
@@ -393,17 +385,13 @@
int rc;
/* Host name */
-#ifdef MULTITHREADED
- accessMutex (&myGlobals.addressResolutionMutex, "yacmpFctn");
-#endif
+ accessAddrResMutex("yacmpFctn");
if ((*a)->hostSymIpAddress[0] != '\0')
rc = strcasecmp ((*a)->hostSymIpAddress, (*b)->hostSymIpAddress);
else
rc = strcasecmp ((*a)->ethAddressString, (*b)->ethAddressString);
-#ifdef MULTITHREADED
- releaseMutex (&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(rc);
}
else if (columnSort == DOMAIN_DUMMY_IDX_VALUE)
@@ -1029,7 +1017,7 @@
bufIdx = (bufIdx + 1) % 5;
#ifdef MULTITHREADED
- accessMutex (&myGlobals.addressResolutionMutex, "cgetHostName");
+ accessAddrResMutex("cgetHostName");
#endif
switch (myGlobals.numericFlag)
@@ -1088,9 +1076,7 @@
break;
}
-#ifdef MULTITHREADED
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return (buf[bufIdx]);
}
--- ntop.cvs/ntop/plugins/icmpPlugin.c 2002-11-17 10:37:07.000000000 -0700
+++ ntop/ntop/plugins/icmpPlugin.c 2003-01-02 18:02:28.000000000 -0700
@@ -138,15 +138,11 @@
break;
default:
-#ifdef MULTITHREADED
- accessMutex(&myGlobals.addressResolutionMutex, "addressResolution");
-#endif
+ accessAddrResMutex("addressResolution");
rc = strcasecmp((*a)->hostSymIpAddress, (*b)->hostSymIpAddress);
-#ifdef MULTITHREADED
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(rc);
break;
}
--- ntop.cvs/ntop/plugins/nfsPlugin.c 2002-11-17 07:22:34.000000000 -0700
+++ ntop/ntop/plugins/nfsPlugin.c 2003-01-02 18:02:29.000000000 -0700
@@ -173,13 +173,9 @@
switch(nfsColumnSort) {
default:
case 1:
-#ifdef MULTITHREADED
- accessMutex(&myGlobals.addressResolutionMutex, "sortNFShosts");
-#endif
+ accessAddrResMutex("sortNFShosts");
rc = strcasecmp((*a)->host->hostSymIpAddress, (*b)->host->hostSymIpAddress);
-#ifdef MULTITHREADED
- releaseMutex(&myGlobals.addressResolutionMutex);
-#endif
+ releaseAddrResMutex();
return(rc);
break;