Dear Mr. Luca Deri,

As I said you before, I think that your "ntop" package is a wonderful
and useful tool. I being using the version 1.2a12 for several months
and experimented very successful results.

I downloaded and tried now version 1.3.2, all the following comments
are referred to this version. However, the cvs snapshot from
00-12-08 was checked and almost all these comments still remain valid.

A large number of problems were observed with this version. The most
noticeable one is the presence of a large amount of inaccurate information
in the report pages (for instance: some machine are showed as serving
services they don't serve; the netbios name are miss, even 
for remote machines; multiple routers are found in the local net; etc.)
Other notorious problem is a marked tendency to die with a core dump when
you are requesting reports via the web or when you try to add or delete a
user or an URL. It seems now that many of these problems are the
consequence of a unique bug, which is described below, although other
-less important- bugs were found.

I do some code modifications as an attempt to correct the bugs I found.
Some code rewriting were done to improve code readability (a couple of
new functions were defined for this purpose) and some enhancements were
introduced, specially in the web data presentation section.

I tried to be particularly careful when doing these changes, I hope no
new bugs were introduced in the process...

--------------------------------------------------------
General comments:

Some modifications I do are required to enable the debug mode.
Particularly, although I don't interested in intop now, I must add
the "libntopreport" library among the linked libraries in the intop
Makefile, otherwise an "unsolved reference" is got as the result of
the make process. By the way, I fail to disable the "intop" generation
using the "--disable-intop" configure option. I need to suppress a
couple of references to "plugins/pep" directory, which is lost in
version 1.3.2. It seems that is include in the recent cvs snapshots.

The addition of the possibility to simultaneously monitoring multiple
interfaces it's a great idea and it deserves an special comment,
there is a number of unsolved problems associated with this feature.
In the first place, there are some inconsistencies with the use of the
device table index, specially when the macro "checkSessionIdx" is used
(this macro assumes that the table is pointed by actualDeviceId, which
is not ever true).
Another serious problem relies on the use of the global arrays
"processes[]", "tcpSession[]" and "udpSession[]". These arrays hold hash
table indexes with no indication of which device they are referred to.
In particular, invalid data could be obtained as the result of the index
reassignment done in "resizeHostHash()", since each device has it's own
host hash table. A possible solution could be the introduction of an
extra element in the "IPSession" and "ProcessInfo" structures to hold
the device index for which the stored info are referred to.
Another point to take into account is the way the traffic is accounted
when multiple interfaces are merged. For instance, in a router almost
all the packets entering one interface are leaving the box via another,
should they be piled up and counted twice?
I do not made no attempt to solve these problems because -perhaps- it
implies a general discussion of the problems and a code redesign.

--------------------------------------------------------
Comments referred to "pbuf.c":

In "getHostInfo()" there is a bug by which an invalid pointer could be
returned when a new item is added to the table. In line #323 an item is
added to the slot pointed by "firstEmptySlot" but "idx" (which may be
different) is returned.
This bug is the originator of almost all the invalid data I saw in the
reports.

In the same function, the loop to determine a candidate to purge, which
begins at line #422, do some references to "idx" instead to the loop
index "i". Moreover, the loop could start from 1 (instead of 0) since the
first slot (0, the broadcast entry) must not be purged.

In line #225 (in "getHostInfo()"):
        "if(el->hostIpAddresses[i].s_addr == 0x0) {"
  the "else" section makes no sense, I believe it not be there...

In line #586 (in "updateHostSessionsList()"):
        "scanner->peersIdx[scanner->lastPeer] = remotePeerIdx;"
  perhaps should say "...->peersIdx[i] =..." instead or should
  set "scanner->lastPeer = i" before ?

In line #2213 (in "processIpPkt()"):
        "FD_SET(NAME_SERVER_HOST_FLAG, &srcHost->flags);"
  this statement should be delayed after the DNS packet is analyzed
  and the flag should be set only for response packets. Otherwise,
  a host may be erroneously assigned as a DNS server.

In lines #2264 and #2270 (in "processIpPkt()"):
  It seems that there is a mistake between ...ReqMade and ...ReqServed

In the same function "processIpPkt()" the section that handle Netbios
packets were modified to include a more general code to retrieve the
netbios name and domain (the modified code was taken from a recent version
of tcpdump). The trimming of trailing whitespace were moved to function
"name_interpret()". The setting of netbios name and host type is done only
for the source host and the name type is checked before assigning it.
Setting those items for the destination host is not a good idea, sometimes
invalid data may be assigned.

--------------------------------------------------------
Comments referred to "initialize.c":

In line #475:
        "device[actualDeviceId].droppedPackets = 0;"
  should be a loop over devices

In line #689:
        "getLocalHostAddress(&device[i].network, device[i].name);"
  makes no sense. The setting of device[i].network is actually done in
  "initLibpcap()"

In line #718:
        "void initLibpcap(char* rulesFile, int numDevices) {"
  numDevices should be the global instance. This function
  set it to 1 when packet capture is done from a file dump

--------------------------------------------------------
Comments referred to "main.c":

In line #404:
        "strncat(ifStr, tmpBuf, sizeof(ifStr)-strlen(ifStr)-1)[..."
  the second use of strlen() could lead to an error since "tmpBuf"
  could be not NULL-terminated at this point.

--------------------------------------------------------
Comments referred to "hash.c":

I believe that the initial hint computed in "computeInitialHashIdx()"
is wrong when isBroadcastAddress(hostIpAddress) is true. The test in
line #93 is never executed because "isLocalAddress(hostIpAddress)" is
executed before and includes it. I modified the tests order to take
this case into account.
In "resizeHostHash()" the call to "purgeIdleHosts()" acts upon
actualDeviceId instead of deviceToExtend. In "freeHostInfo()" the macro
"checkSessionIdx()" acts upon actualDeviceId instead of theDevice.

--------------------------------------------------------
Comments referred to "http.c":

There is a problem with the utilization of the browser cache, this is
particularly noticeable for hosts statistics pages with a lot of flags.
The data for the "Expires:" header field in "returnHTTPPage()" is computed
using actTime -which is measured in UTC- and formated with "localtime_r()".
As a consequence, the result is doubly shifted from the real value with
the amount of the time offset for the local time zone. Using an expiration
of 1 hour, if you live west of Greenwich more than one zone (this is,
your offset is less than -01:00, like mine, which is -03:00), all the
pages arrives pre-expired to the browser!
I modified the code so all the pages taken entirely from files are now
included among the set of browser-cacheable hints. This makes a performance
improvement and -I believe- has no contraindications. Of course, dynamically
generated pages are still sent pre-expired.

The same problem with time affects "logHTTPaccess()", which was modified
to correctly record the time and time zone of the access.

A note about the function "strftime()":
At least in Linux, strftime() does not guarantees the end-of-string mark
if the size of the buffer is exceeded. When the format includes fields
displayed in the current locale (like "%a"), the size can grow without
controlled limit. The defined size should be enough for most situations,
but just in case, I set the end-of-string mark explicitly.

I try to unified  almost all the HTTP protocol handling in the
"sendHTTPHeader()" function. It replaces both "sendHTTPProtoHeader()",
"sendHTTPHeaderType()" and "sendGIFHeaderType()". This function has a
number of options to allow the handling of the most usual cases and a
hook to handle any special case.
I rearrange the order in which the header fields are sent to be fully
compliant with RFC 2068 recommendations.
I also defined a new function "returnHTTPspecialStatusCode()". Using it
I was able to do a more accurate handling of possible HTTP errors and
singular situations. The functions "returnHTTPaccessDenied()",
"returnHTTPaccessForbidden()" and "returnHTTPnotImplemented()" are
defined now in terms of it.

Some modifications were done in "readHTTPheader()". In the first
place, all the incoming header data is received until a response is
sent, otherwise, an error may occur. Additionally, the setting of
the timeout parameter was moved just before the call to select().
Accordingly to the Linux select man page:
   "On Linux, timeout is modified to reflect the amount of time
    not slept; most other implementations do not do this."
As a consequence, if the value isn't reseted before each call, it
could approach to zero after successive reads. This behavior could
affect other systems too. For instance, the Solaris man page says:
   "On successful completion, the object pointed to by the
    timeout argument may be modified."
The call to select() in other sections of the code could be affected
by this behavior (look at "getHostOS()", in "util.c").
The HTTP version in the request is checked and an error is reported for
malformed or unsupported version indication. Additionally, this information
is stripped from the returned "theRequestedURL" string. Of course, the
global string "httpRequestedURL" still contains the whole request line.
Incoming "<CR>" characters are now ignored, as recommended in section
19.3 of RFC 2068, so the variable "preLastChar" is not used anymore.

In "returnHTTPPage()" I modified the way the pages with the PLUGINS_HEADER
prefix are handled. If the "handlePluginHTTPRequest()" function fails a
"Page not found" error is returned. I believe that it's an error to
fallback these pages across the following comparisons.

--------------------------------------------------------
Comments referred to "ntop.h":

I added a number of "#define" for names used in the modified versions of
"sendHTTPHeader()" and "printHTMLheader()". I moved the definition of
INVALID_HTTP_REQUEST to http.c since this is local to this program section.

--------------------------------------------------------
Comments referred to both "http.c", "report.c", "reportUtils.c", "admin.c"
and "plugins/*.c":

There are a lot of malformed HTML constructions, like <TITLE>
outside <HEADER>, opening tags (i.e. <ADDRESS>) without the matching
closing tag and vice-versa (</CENTER>). Some browser have an erratic
behavior in such situations. Extending sectioning directives (like
<CENTER>) across several logical program sections is not a good idea,
this practice seems to be prone to error. 
In an attempt to fix many of these problems I modified the functions
"printHTTPheader()" and "printHTTPtrailer()" (renamed as "printHTMLheader()"
and "printHTTPtrailer()" since there is no HTTP involved here) and defined
two new ones: "printSectionTitle()" and "printFlagedWarning()" (both in
"reportUtils.c").
Using these functions and with the rearrangement of some code section I
tried to made the code more readable and correct the HTML errors. Matching
pairs of opening and closing tags are put together as close as possible.

The title for the reports produced by the functions "printHostsTraffic()"
and "printHostsInfo()" is printed from these functions instead of from
"printHeader()". This last one is not called anymore from inside
"printHostsInfo()" or from "printHostsTraffic()" when "sortSendMode" is
equal to 2.
The title for the various reports created by "printIpAccounting()",
"printIpTrafficMatrix()", "printIpProtocolUsage()", "printActiveTCPSessions()"
and "shutdownNtop()" are now printed from inside the involved function
instead of from "returnHTTPPage()" in "http.c".
These changes render the huge "if-then-else-if" block in "returnHTTPPage()"
in a more readable form.

Some pages should not include the "Refresh" meta-directive. That is the
case for "shutdown.html" and "resetStats.html". If one of these pages
remain visible in the browser you have some trouble when the refresh period
expires. For "shutdown.html" you get an error (because the server is not
here anymore!) and for "resetStats.html" you get the statistics automatically
reseted. Additionally, for the "shutdown.html" page I added an explicit
"closeNwSocket()" in the function "shutdownNtop()". Since that function
calls "cleanup()" -whichever calls "exit()"- it never returns and the
conecction with the browser remains open producing a "Network Timeout Error".

In "reportUtils.c" a minor bug in "cmpHostsFctn()", which produces an
incorrect ordering in the "IP Remote to Local" report, was corrected.

--------------------------------------------------------
Comments referred to "util.c":

A bug in "getHostOS()", which prevents to correctly retrieve the nmap
returned OS information, was corrected. It seems that this bug is corrected
in the recent cvs snapshot.
The function "name_interpret()" was modified so now include code to trim
the trailing whitespace. A bug was corrected by which the end-of-string
mark was incorrectly set after the "name Type" code.
In "readNepedInfo()" the use of global variable "device" seems to be
incorrect ("device" is an array of "ntopInterface_t" objects not a pointer
to a character string).

--------------------------------------------------------
Comments referred to "webInterface.c":

In "handleSingleWebConnection()" a pair of braces was added to disambiguate
the nested "if-else" blocks. In "shutdownNtop()" a call to "printHTMLheader()"
was moved from "returnHTTPPage()" (in "http.c"), a call to "closeNwSocket()"
was added so the interaction with the browser is terminated and the statements
were rearragend so "cleanup()" is called in the last term.

--------------------------------------------------------
Comments referred to "plugin.c":

I modified the function "handlePluginHTTPRequest()" so now a warning
messages is sent if the requested plugin is currently inactive. I also
corrected a mistake with the name of the rmonPlugin entry function and
added an explicit end-of-string mark for safety when handling "bpfFilter".

--------------------------------------------------------
Comments referred to "admin.c":

This code seems to have some problems, I got a core dump every time an 
attempt to add or delete a user is made. I do some extensive code rewriting
and it seems to work now. I defined some new functions: "sendMenuFooter()"
handle the footer menu in each page. "readHTTPpostData()" reads the data
received as a result of the HTTP POST and is called from "doAddUser()" and
"doAddURL()". "decodeWebFormURL()" and "encodeWebFormURL()" are used to
interpret data in "x-www-form-urlencoded" form used by HTTP POST, all the
related link anchors are now encoded this way.
Perhaps "readHTTPpostData()" and possibly "decodeWebFormURL()" and
"encodeWebFormURL()" should pertain to "http.c" instead of here.
Some checks were added as an attempt to reduce the impact of a malicious
client. Particularly, the posted form data is parsed and verified for
invalid characters: only alphanumeric are allowed in usernames, some
additional characters ("/", "-", "_", etc.) are allowed in URLs and
anything is admitted in passwords.
In "addURL()" the list of authorized users associated with a particular URL
is parsed and correctly checked now so "foo" doesn't match "foobar". It
seems that the same problem could affect the function "checkHTTPpassword()"
in "http.c". A couple of memory leaks were fixed.
The string returned by "crypt()" is copied into a private buffer since
this is a static buffer which is overwritten in every call to "crypt()".
The function "redirectURL()" was renamed as "returnHTTPredirect()" and
moved to "http.c" so is builded upon some "http.c" private structures.

------------------------------------------------------------

Below is enclosed as an attachment a gzipped "diff -c" patch against
the original version 1.3.2 files. Let me know if you find interesting
this kind of contributions. With best regards, Roberto.
-- 

------------------------------------------------------------------
 Roberto F. De Luca :
         E-mail: mailto:[EMAIL PROTECTED]
          PHONE: +54 11 4754 7167
                 +54 11 4754 7007 ext. 7680
            FAX: +54 11 4754 7121
------------------------------------------------------------------
  Laboratorio TANDAR - Comision Nacional de Energia Atomica
             URL: http://www.tandar.cnea.gov.ar/
       Avda. Gral. Paz  Nro. 1499 (1650) SAN MARTIN
             Pcia. de Buenos Aires - ARGENTINA
------------------------------------------------------------------

gzip compressed data - deflate method , original file name

Reply via email to