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

#include <Filter.h>

+ Collaboration diagram for NetworkFilter:

Classes

struct  ActiveInvocation
 
struct  CallbackItem
 

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))
 
bool removeCallback (size_t level, size_t id)
 

Static Public Member Functions

static NetworkFilter & instance ()
 

Private Member Functions

void drainCallback (size_t level, CallbackItem *item)
 
bool isCallbackInvocation (Thread *thread) const
 

Private Attributes

List< CallbackItem * > m_Callbacks [4]
 
Spinlock m_Lock
 
size_t m_NextCallbackId
 
ActiveInvocation * m_pActiveInvocations
 

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 34 of file Filter.h.

Constructor & Destructor Documentation

◆ NetworkFilter()

NetworkFilter::NetworkFilter ( )

Default constructor, boring.

Definition at line 32 of file Filter.cc.

◆ ~NetworkFilter()

NetworkFilter::~NetworkFilter ( )
virtual

Destructor, also boring.

Definition at line 35 of file Filter.cc.

References Spinlock::acquire(), ProcessorBase::information(), Spinlock::release(), and removeCallback().

Member Function Documentation

◆ drainCallback()

void NetworkFilter::drainCallback ( size_t  level,
CallbackItem *  item 
)
private

Definition at line 212 of file Filter.cc.

◆ filter()

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 60 of file Filter.cc.

References Spinlock::acquire(), ProcessorBase::information(), and Spinlock::release().

◆ installCallback()

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.

Definition at line 141 of file Filter.cc.

References Spinlock::acquire(), and Spinlock::release().

◆ instance()

static NetworkFilter & NetworkFilter::instance ( )
inlinestatic

The design pattern everyone loves to hate!

Definition at line 43 of file Filter.h.

Referenced by NetworkStack::receive().

+ Here is the caller graph for this function:

◆ isCallbackInvocation()

bool NetworkFilter::isCallbackInvocation ( Thread *  thread) const
private

Definition at line 257 of file Filter.cc.

◆ removeCallback()

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

Closes admission and removes a callback for a specific level.

Outside filter dispatch this waits for admitted calls and returns true once callback-owned state may be destroyed. During dispatch, an active target is disabled but retained and false is returned; the caller must preserve the identifier and callback-owned state, then retry from outside callback context. An already absent valid identifier is complete.

Definition at line 165 of file Filter.cc.

References Spinlock::acquire(), ProcessorBase::information(), and Spinlock::release().

Referenced by ~NetworkFilter().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_Callbacks

List<CallbackItem*> NetworkFilter::m_Callbacks[4]
private

Definition at line 108 of file Filter.h.

◆ m_Instance

NetworkFilter NetworkFilter::m_Instance
staticprivate

Definition at line 106 of file Filter.h.

◆ m_Lock

Spinlock NetworkFilter::m_Lock
private

Definition at line 109 of file Filter.h.

◆ m_NextCallbackId

size_t NetworkFilter::m_NextCallbackId
private

Definition at line 110 of file Filter.h.

◆ m_pActiveInvocations

ActiveInvocation* NetworkFilter::m_pActiveInvocations
private

Definition at line 111 of file Filter.h.


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