mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GoTo Class Reference

#include <GoTo.hpp>

Inheritance diagram for GoTo:
Inheritance graph
Collaboration diagram for GoTo:
Collaboration graph

Public Member Functions

 GoTo (std::shared_ptr< Chain > chain, std::optional< If > condition={})
 
 GoTo (std::shared_ptr< Chain > chain, int priority, std::optional< If > condition={})
 
virtual Action action (const Packet &packet, const MAVAddress &address) const
 
virtual std::unique_ptr< Ruleclone () const
 
virtual bool operator== (const Rule &other) const
 
virtual bool operator!= (const Rule &other) const
 

Protected Member Functions

virtual std::ostream & print_ (std::ostream &os) const
 

Protected Attributes

std::optional< Ifcondition_
 

Detailed Description

Delegate decision on a packet to another Chain.

Rule to delegate the decision on what to do with a packet to a filter Chain. In particular, final decision is given to this Chain. If the Chain cannot decide what to do with the Packet the global default action should be taken.

Definition at line 44 of file GoTo.hpp.

Constructor & Destructor Documentation

◆ GoTo() [1/2]

GoTo::GoTo ( std::shared_ptr< Chain chain,
std::optional< If condition = {} 
)

Construct a goto rule given a chain to delegate to, without a priority.

A goto rule is used to delegate the decision on whether to accept or reject a packet/address combination to another filter Chain. If this called chain does not make a decision then the default action should be taken.

Parameters
chainThe chain to delegate decisions of whether to accept or reject a packet/address combination to. nullptr is not valid.
conditionThe condition used to determine the rule matches a particular packet/address combination given to the action method. The default is {} which indicates the rule matches any packet/address combination.
Exceptions
std::invalid_argumentif the given pointer is null.
See also
action

Definition at line 47 of file GoTo.cpp.

◆ GoTo() [2/2]

GoTo::GoTo ( std::shared_ptr< Chain chain,
int  priority,
std::optional< If condition = {} 
)

Construct a goto rule given a chain to delegate to, with a priority.

A goto rule is used to delegate the decision on whether to accept or reject a packet/address combination to another filter Chain. If this called chain does not make a decision then the default action should be taken.

Parameters
chainThe chain to delegate decisions of whether to accept or reject a packet/address combination to. nullptr is not valid.
priorityThe priority to accept packets with. A higher number is more important and will be routed first.
conditionThe condition used to determine the rule matches a particular packet/address combination given to the action method. The default is {} which indicates the rule matches any packet/address combination.
Exceptions
std::invalid_argumentif the given pointer is null.
See also
action

Definition at line 75 of file GoTo.cpp.

Member Function Documentation

◆ action()

Action GoTo::action ( const Packet packet,
const MAVAddress address 
) const
virtual

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 continue object is always returned if the condition was set and does not match the packet/address combination.

Parameters
packetThe packet to determine whether to allow or not.
addressThe address the packet will be sent out on if the action dictates it.
Returns
The action to take with the packet. If this is the accept object, it may also contain a priority for the packet.

The GoTo class delegates the action choice to the contained Chain. If the Chain decides on the continue action this method will return the default instead since final decision for a GoTo should be with the contained Chain or with the default action. In other words, once a GoTo rule matches, no further rule in the chain should ever be ran, regardless of the contained chain.

Implements Rule.

Definition at line 120 of file GoTo.cpp.

References Rule::condition_, Action::CONTINUE, Action::make_continue(), and Action::make_default().

Here is the call graph for this function:

◆ clone()

std::unique_ptr< Rule > GoTo::clone ( ) const
virtual

Return a copy of the Rule polymorphically.

This allows Rule's to be copied without knowing the derived type.

Returns
A pointer to a new object with base type Rule which is an exact copy of this one.

Implements Rule.

Definition at line 147 of file GoTo.cpp.

References Rule::condition_.

◆ operator!=()

bool GoTo::operator!= ( const Rule other) const
virtual

Inequality comparison.

Compares the type of the Rule and the condition (If) if set.

Parameters
otherThe other rule to compare this to.
Return values
trueif this rule is not the same as other.
falseif this rule is the same as other.

Compares the chain and priority (if set) associated with the rule as well.

Implements Rule.

Definition at line 175 of file GoTo.cpp.

References Rule::condition_.

◆ operator==()

bool GoTo::operator== ( const Rule other) const
virtual

Equality comparison.

Compares the type of the Rule and the condition (If) if set.

Parameters
otherThe other rule to compare this to.
Return values
trueif this rule is the same as other.
falseif this rule is not the same as other.

Compares the chain and priority (if set) associated with the rule as well.

Implements Rule.

Definition at line 162 of file GoTo.cpp.

References Rule::condition_.

◆ print_()

std::ostream & GoTo::print_ ( std::ostream &  os) const
protectedvirtual

Print the rule to the given output stream.

Parameters
osThe output stream to print to.
Returns
The output stream.

Prints "goto <Chain Name> <If Statement>" or "goto <Chain Name> with priority <If Statement> with priority <priority>" if the priority is given.

Implements Rule.

Definition at line 93 of file GoTo.cpp.

References Rule::condition_.

Member Data Documentation

◆ condition_

std::optional<If> Rule::condition_
protectedinherited

Definition at line 91 of file Rule.hpp.


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