[prev in list] [next in list] [prev in thread] [next in thread]
List: ntop-dev
Subject: [Ntop-dev] ntop-dev How do I add/split an option? (was [Ntop] Sticky Locals - Non Sticky Remotes)
From: "Burton M. Strauss III" <Burton () ntopsupport ! com>
Date: 2004-04-04 13:12:37
Message-ID: JIEPJGFPFMFIGBNCPKGGGECNFGAA.Burton () ntopsupport ! com
[Download RAW message or body]
Go for it. Something like that is a relatively simple change... and IMHO a
reasonable one.
Where do you start - especially for a function which is derivative of
something that's already there?
First off, look in main.c for the case 'c': -- that's the code that handles
the option, so you can see what variable is set:
case 'c': /* Sticky hosts = hosts that are not purged when idle */
myGlobals.stickyHosts = 1;
break;
grep for that constant - that gives you clues about the work effort.
$ grep -c myGlobals.stickyHosts *.[ch] plugins/*.[ch] -c | grep -v :0
globals-core.c:1
hash.c:1
main.c:2
ntop.c:1
webInterface.c:1
Five files, six cases - that sounds reasonable, right???
If you're not sure about the design of a change like this, switch over to
ntop-dev and ask. If you want to announce that you're doing something like
this and ask for a volunteer to help test, that's GREAT.
So what's the 'design'??
I would probably add a (long only) option, --sticky-local-hosts so you have
-c | --sticky-hosts just like they are today and a new, less sticky
option, --sticky-local-hosts.
So:
1) I would make the int myGlobals.stickyHosts an enum -- noSticky,
localStick, allSticky and add that in globals-structures.h with the other
enums. Then change the definition in struct ntopGlobals to the new type.
2) main.c, add the new option to the long_options table, to usage() and to
the big opt loop - there are long-only options you can use as a model. Just
pick something you know is also a long only option and look at where in the
main.c code it's referenced.
2a) For this option, there's - unusually - a second case (but it's found in
the grep, that's why the count is 2 for main.c. It's this:
case 147:
myGlobals.printFcOnly = TRUE;
myGlobals.stickyHosts = TRUE;
break;
Looking for 147, it's --fc-only. You might have to ask or think about it.
In this case you probably want to make that setting to --sticky-local-hosts,
given that there isn't a lot of WAN FibreChannel traffic that I know of...
3) globals-core.c has the initialization. You want to make sure that the
value (here it's a constant) is one of the enum values. Constants are
defined in globals-defines.h.
4) You'll find hash.c has the actual host purge routine, purgeIdleHosts() -
that needs to be made local/remote sensitive, based on the enum. Come back
to this in a second...
5) ntop.c calls purgeIdleHosts():
if(!myGlobals.stickyHosts) purgeIdleHosts(i);
You'll want to make that
if(myGlobals.stickyHosts != noSticky) purgeIdleHosts(i);
6) webInterface.c has the code that reports the setting:
printParameterConfigInfo(textPrintFlag, "-c | --sticky-hosts",
myGlobals.stickyHosts == 1 ? "Yes" : "No",
DEFAULT_NTOP_STICKY_HOSTS == 1 ? "Yes" : "No");
You'll want to make that enum based...
printParameterConfigInfo(textPrintFlag, "-c | --sticky-hosts",
myGlobals.stickyHosts == noSticky ? "No" :
myGlobals.stickyHosts == localSticky ? "Local
only" :
"Yes",
DEFAULT_NTOP_STICKY_HOSTS == noSticky ? "No" :
myGlobals.stickyHosts == localSticky ? "Local
only" :
"Yes");
(back to 4) So all that's left is the stuff in hash.c ... making it
sensitive to the enum. It turns out that's just one if:
if((el->refCount == 0)
&& ( ((el->numHostSessions == 0) && (el->lastSeen <
noSessionPurgeTime))
|| ((el->numHostSessions > 0) && (el->lastSeen <
withSessionPurgeTime)))
&& (!broadcastHost(el))
&& ((!myGlobals.stickyHosts)
|| ((el->l2Family == FLAG_HOST_TRAFFIC_AF_ETH) &&
((el->hostNumIpAddress[0] == '\0') /* Purge MAC addresses
too */
|| (!subnetPseudoLocalHost(el)))) /* Purge remote
* hosts only */
|| ((el->l2Family == FLAG_HOST_TRAFFIC_AF_FC) &&
(el->hostNumFcAddress[0] == '\0')))
) {
/* Host selected for deletion */
which you'll need to fix up (exercise left for the reader).
Then test your code for a few days, and prepare a patch file...
diff -U3 xxxx.old xxxx.new
for everything you've changed, roll that into a single .patch file and send
it to me or Luca (he prefers to receive patches at patch@ntop.org) for
inclusion!
Want my opinion? It's a reasonable change and a good 1st project for
someone new to developing ntop.
-----Burton
> -----Original Message-----
> From: ntop-admin@unipi.it [mailto:ntop-admin@unipi.it]On Behalf Of Mark
> Gibbons
> Sent: Saturday, April 03, 2004 2:46 PM
> To: Ntop (E-mail)
> Subject: [Ntop] Sticky Locals - Non Sticky Remotes
>
>
> Hi
>
> We currently run Sticky/Local Hosts only.
>
> It would be nice to run Sticky/Local but merged with Non-Sticky/Remote.
>
> I.E we want to keep local host info but are only interested in
> remotes whilst in contact and for a short time afterwards.
>
> Is this possible? How hard would it be to accomplish if not?
>
> Mark
_______________________________________________
Ntop-dev mailing list
Ntop-dev@unipi.it
http://listgateway.unipi.it/mailman/listinfo/ntop-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic