engine/main_loop.c File Reference

#include "main_loop.h"
#include "hlbrlib.h"
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include "../packets/packet.h"
#include "../decoders/decode.h"
#include "../routes/route.h"
#include "../actions/action.h"
#include "bits.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define DEBUGPATH   ;

Functions

void IdleFunc ()
int RouteAndSend (int PacketSlot)
int HandleTimers (int Now)
int ProcessPacket (int PacketSlot)
void * ProcessPacketThread (void *v)
int MainLoopPoll ()
int MainLoopThreaded ()
int MainLoop ()

Variables

GlobalVars Globals
int TCPDecoderID
int UDPDecoderID


Define Documentation

#define DEBUGPATH   ;

Definition at line 20 of file main_loop.c.


Function Documentation

int HandleTimers ( int  Now  ) 

Definition at line 110 of file main_loop.c.

References DEBUGPATH, Globals, timer_rec::Interval, timer_rec::InUse, timer_rec::LastTime, MAX_TIMERS, timer_rec::TimerFunc, global_vars::Timers, TRUE, and timer_rec::User.

Referenced by ProcessPacket().

void IdleFunc (  ) 

Idle function. Called whenever hlbr is idle

Definition at line 32 of file main_loop.c.

References global_vars::AllocatedCount, DEBUGPATH, Globals, global_vars::IdleCount, global_vars::PendingCount, PRINTERROR, PRINTERROR1, global_vars::ProcessingCount, and global_vars::SavedCount.

Referenced by MainLoopPoll(), and ProcessPacketThread().

int MainLoop (  ) 

Main loop, start handling packets. Calls one of the two other functions: MainLoopThreaded() if HLBR is running in multi-thread mode, or MainLoopPolling(), if in single-thread mode.

Returns:
Always FALSE?

Definition at line 350 of file main_loop.c.

References DEBUGPATH, FALSE, Globals, global_vars::Interfaces, interface_rec::IsPollable, MainLoopPoll(), global_vars::NumInterfaces, PRINTERROR, and global_vars::UseThreads.

Referenced by main().

int MainLoopPoll (  ) 

Definition at line 259 of file main_loop.c.

References DEBUG, DEBUGPATH, global_vars::Done, FALSE, interface_rec::FD, Globals, IDLE_TIMEOUT, IdleFunc(), global_vars::Interfaces, interface_rec::Name, NULL, global_vars::NumInterfaces, PopFromPending(), ProcessPacket(), and ReadPacket().

Referenced by MainLoop().

int MainLoopThreaded (  ) 

Spawn a thread for each interface.

Definition at line 317 of file main_loop.c.

References DEBUGPATH, global_vars::Done, FALSE, Globals, NULL, global_vars::NumInterfaces, ProcessPacketThread(), and StartInterfaceThread().

Referenced by main().

int ProcessPacket ( int  PacketSlot  ) 

Check the packet for rules matches. This is one of the main functions responsible for everything HLBR does; the other is Decode(), called here. Decode() is called with the 'root' packet decoder, so all registered decoders (TCP, UDP, etc.) will be called, with all their respective registered tests (according to the rules defined by the user). After this, the RuleBits field of the packet structure is tested to see if any rule matched, and the necessary actions performed. Then finally the packet is 'routed' and sent.

Returns:
Always TRUE?
Remarks:
Basically this is what ProcessPacket does:

Definition at line 163 of file main_loop.c.

References BitFieldIsEmpty(), DBG, DEBUGPATH, Decode(), global_vars::DecoderRoot, global_vars::Done, FALSE, GetDataByID(), Globals, HandleTimers(), global_vars::NumRules, PACKET_STATUS_BLOCKED, global_vars::PacketLimit, packet_rec::PacketNum, global_vars::Packets, global_vars::PacketsPerSec, PerformActions(), PRINTERROR, PRINTERROR1, ReturnEmptyPacket(), RouteAndSend(), packet_rec::RuleBits, packet_rec::Status, TCPDecoderID, global_vars::TCPPerSec, TCPRemount_unblock(), TRUE, packet_rec::tv, UDPDecoderID, and global_vars::UDPPerSec.

Referenced by MainLoopPoll(), and ProcessPacketThread().

void* ProcessPacketThread ( void *  v  ) 

Thread to process packets from the queue. There may be more than one of these (but not currently in HLBR).

Definition at line 237 of file main_loop.c.

References DEBUGPATH, global_vars::Done, Globals, IdleFunc(), NULL, PACKET_NONE, PopFromPending(), and ProcessPacket().

Referenced by MainLoopThreaded().

int RouteAndSend ( int  PacketSlot  ) 

Apply the routing and send out the packet.

Definition at line 55 of file main_loop.c.

References DBG, DEBUGPATH, FALSE, Globals, packet_rec::InterfaceNum, global_vars::Interfaces, interface_rec::Name, global_vars::NumRoutes, global_vars::Packets, packet_rec::PassRawPacket, PRINTERROR, packet_rec::RawPacket, Route(), packet_rec::TargetInterface, TRUE, and WritePacket().

Referenced by ProcessPacket().


Variable Documentation

GlobalVars Globals

Definition at line 41 of file hlbr.c.

int TCPDecoderID

Definition at line 13 of file decode_tcp_stream.c.

int UDPDecoderID

Definition at line 12 of file decode_dns.c.


Generated on Sat Jul 7 23:33:10 2007 for HLBR by  doxygen 1.5.2