mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Friends | List of all members
Chain Class Reference

#include <Chain.hpp>

Collaboration diagram for Chain:
Collaboration graph

Public Member Functions

 Chain (const Chain &other)
 
 Chain (Chain &&other)=default
 
 Chain (std::string name_, std::vector< std::unique_ptr< Rule >> &&rules={})
 
TEST_VIRTUAL ~Chain ()=default
 
TEST_VIRTUAL Action action (const Packet &packet, const MAVAddress &address)
 
void append (std::unique_ptr< Rule > rule)
 
const std::string & name () const
 
Chainoperator= (const Chain &other)
 
Chainoperator= (Chain &&other)=default
 

Friends

bool operator== (const Chain &lhs, const Chain &rhs)
 
bool operator!= (const Chain &lhs, const Chain &rhs)
 
std::ostream & operator<< (std::ostream &os, const Chain &chain)
 

Detailed Description

A filter chain, containing a list of rules to check packets against.

Definition at line 37 of file Chain.hpp.

Constructor & Destructor Documentation

◆ Chain() [1/3]

Chain::Chain ( const Chain other)

Copy constructor.

Parameters
otherChain to copy from.

Definition at line 38 of file Chain.cpp.

References Rule::clone(), and rule.

Here is the call graph for this function:

◆ Chain() [2/3]

Chain::Chain ( Chain &&  other)
default

Move constructor.

Parameters
otherChain to move from.

◆ Chain() [3/3]

Chain::Chain ( std::string  name,
std::vector< std::unique_ptr< Rule >> &&  rules = {} 
)

Construct a new filter chain.

Note
No rule in the chain may contain a GoTo or Call that would directly or indirectly result in returning to this chain.
Parameters
nameThe name of the filter chain. This is only used when printing the chain. The name cannot contain whitespace.
rulesA vector of the rules used in the filter chain. This must be moved from since the vector is made up of std::unique_ptr's.
Exceptions
std::invalid_argumentif the name contains whitespace.

Definition at line 59 of file Chain.cpp.

◆ ~Chain()

TEST_VIRTUAL Chain::~Chain ( )
default

Member Function Documentation

◆ action()

Action Chain::action ( const Packet packet,
const MAVAddress address 
)

Decide what to do with a Packet.

Determine what action to take with the given packet sent to the given address. The possible actions are documented in the Action class.

The filter chain will loop through all the rules and the first one that matches and returns something other than the continue Action will be taken as the result.

Note
An error will be thrown if any Call or GoTo rule matches that directly or indirectly loops back to this chain.
Parameters
packetThe packet to determine whether to allow or not.
addressThe address the packet will be sent out on if the action allows it.
Returns
The action to take with the packet. If this is the accept Action object, it may also contain a priority for the packet.
Exceptions
RecursionErrorif a rule loops back to this chain.

Definition at line 90 of file Chain.cpp.

References Rule::action(), Action::CONTINUE, Action::make_continue(), and rule.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append()

void Chain::append ( std::unique_ptr< Rule rule)

Append a new rule to the filter chain.

Parameters
ruleA new filter rule to append to the chain.

Definition at line 116 of file Chain.cpp.

References rule.

Here is the caller graph for this function:

◆ name()

const std::string & Chain::name ( ) const

Return the name of the chain.

Note
This is only used when printing the chain.
Returns
The chain's name.

Definition at line 128 of file Chain.cpp.

◆ operator=() [1/2]

Chain & Chain::operator= ( const Chain other)

Assignment operator.

Parameters
otherChain to copy from.

Definition at line 138 of file Chain.cpp.

References Rule::clone(), and rule.

Here is the call graph for this function:

◆ operator=() [2/2]

Chain& Chain::operator= ( Chain &&  other)
default

Assignment operator (by move semantics).

Parameters
otherChain to move from.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Chain lhs,
const Chain rhs 
)
friend

Inequality comparison.

Compares the chain name and each Rule in the chain.

Parameters
lhsThe left hand side action.
rhsThe right hand side action.
Return values
trueif lhs is not the same as rhs.
falseif lhs is the same as rhs.

Definition at line 200 of file Chain.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Chain chain 
)
friend

Print the given filter chain to to the given output stream.

An example is:

chain default {
reject if HEARTBEAT from 10.10;
accept with priority -3 if GPS_STATUS to 172.0/8;
accept if GLOBAL_POSITION_INT to 172.0/8;
goto ap-in with priority 3 if from 192.168;
call ap-out if to 192.168;
}
Parameters
osThe output stream to print to.
chainThe filter chain to print.
Returns
The output stream.

Definition at line 225 of file Chain.cpp.

◆ operator==

bool operator== ( const Chain lhs,
const Chain rhs 
)
friend

Equality comparison.

Compares the chain name and each Rule in the chain.

Parameters
lhsThe left hand side filter chain.
rhsThe right hand side filter chain.
Return values
trueif lhs is the same as rhs.
falseif lhs is not the same as rhs.

Definition at line 163 of file Chain.cpp.


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