The Pedigree Project  0.1
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
NetworkFilter Class Reference

#include <Filter.h>

+ Collaboration diagram for NetworkFilter:

Public Member Functions

 NetworkFilter ()
 Default constructor, boring.
 
virtual ~NetworkFilter ()
 Destructor, also boring.
 
bool filter (size_t level, uintptr_t packet, size_t sz)
 
size_t installCallback (size_t level, bool(*callback)(uintptr_t, size_t))
 
void removeCallback (size_t level, size_t id)
 

Static Public Member Functions

static NetworkFilterinstance ()
 

Private Attributes

Tree< size_t, List< void * > * > m_Callbacks
 Level -> Callback list mapping.
 

Static Private Attributes

static NetworkFilter m_Instance
 

Detailed Description

Provides an interface for filtering network packets as they come in to the system.

Definition at line 30 of file Filter.h.

Member Function Documentation

bool NetworkFilter::filter ( size_t  level,
uintptr_t  packet,
size_t  sz 
)

Passes a Level n packet to filter callbacks. Level 1 is the lowest level, handling for example Ethernet frames. Level 2 handles the Level 1 payload. ARP, IP, and other low-level protocols are handled here. Level 3 handles the Level 2 payload. TCP, UDP, ICMP, etc... Level 4 handles the Level 3 payload. Specific application protocols such as FTP, DNS.

Todo:
Callbacks should be able to return a code which requests a specific response, such as ICMP Unreachable or something, rather than just dropping the packet.
Parameters
levelLevel of callback to call
packetPacket buffer, can be modified by callbacks
sizeSize of the packet. Can NOT be modified by callbacks
Returns
False if the packet has been rejected, true otherwise.

Definition at line 35 of file Filter.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), Tree< K, E >::lookup(), and m_Callbacks.

size_t NetworkFilter::installCallback ( size_t  level,
bool(*)(uintptr_t, size_t)  callback 
)

Installs a callback for a specific level.

Returns
An identifier which can be passed to removeCallback to uninstall the callback, or ((size_t) -1) if unable to install.
Todo:
UnlikelyLock here

Definition at line 63 of file Filter.cc.

References List< T, nodePoolSize >::count(), Dec, ERROR, Hex, Tree< K, E >::insert(), Tree< K, E >::lookup(), m_Callbacks, and List< T, nodePoolSize >::pushBack().

static NetworkFilter& NetworkFilter::instance ( )
inlinestatic

The design pattern everyone loves to hate!

Definition at line 40 of file Filter.h.

Referenced by NetworkStack::receive().

+ Here is the caller graph for this function:

void NetworkFilter::removeCallback ( size_t  level,
size_t  id 
)

Removes a callback for a specific level.

Todo:
Implement me!

Definition at line 106 of file Filter.cc.


The documentation for this class was generated from the following files: