in reply to Should I use threads? Perl/DHCP/Radius
I've moved this back from the deeply-nested sub-thread and quote your /msgs below for clarity.
The API response determines if the MAC is a "known" MAC. We then allow it to RADUIS auth. After RADIUS auth, the MAC is allowed into a network .
Another http service reports idle MACs based on n/w packets. I delete them from %clients forcing them to do API / RAdius Auth again.
Basically we continously allow MACs to come into the n/w , auth them in hte background and drop when no activity is seen
If I read that correctly, you retain the %client hash of MACs so that you can avoid re-authing them if they are already authed.
And you need to query another server that tracks MAC activity by inspecting packets.
And when that other server replies:"this MAC has been inactive for a while"
You delete that MAC from the %clients hash so the next time it turns up in the logs, it has to re-authorise.
If the above is a true reflection of the process, then I would suggest the following modification to the process to avoid having to constantly poll the Auth server with every known MAC.
The file reading loop remains the same:
while( <LOG> ) { next unless m[ACK (...)]i; async( \&checkMAC, $1 )->detach; }
But the logic in checkMAC() gets modified:
sub checkMAC{ my $mac = shift; ## If this is a known MAC & it has previously authorised successfu +lly if( exists $clients{ $mac } and $clients{ $mac } ) { ## Check with the activity monitor to see if it has fallen ina +ctive my $active = get "http://activityServer/check.pl?mac=$mac"; ## If is has never fallen inactive, it is known, authorised, a +nd active ## and there is nothing to do return if $active; ## Not sure that this is really necessary, ## but it might save a little resource. lock %clients; delete $clients{ $mac }; } ## Otherwise, check http & Auth and modify status (or add) in %cli +ents my $httpRes = get ...; my $authRes = get ...; lock %clients; $clients{ $mac } = $httpRes && $authRes ? 1 : 0; return. }
This way, you'd only contact the activity server each time a MAC appears in the log, rather than constant having to poll it for every known MAC.
|
|---|