mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Rule Class Referenceabstract

#include <Rule.hpp>

Inheritance diagram for Rule:
Inheritance graph
Collaboration diagram for Rule:
Collaboration graph

Public Member Functions

 Rule (std::optional< If > condition={})
 
virtual ~Rule ()
 
virtual Action action (const Packet &packet, const MAVAddress &address) const =0
 
virtual std::unique_ptr< Ruleclone () const =0
 
virtual bool operator== (const Rule &other) const =0
 
virtual bool operator!= (const Rule &other) const =0
 

Protected Member Functions

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

Protected Attributes

std::optional< Ifcondition_
 

Friends

std::ostream & operator<< (std::ostream &os, const Rule &action)
 

Detailed Description

Base class of all rules, used in filter Chain's.

Rule's are used to determine an Action to take with a packet based on its type, source address, and destination address. They are very much like the rules found in a typical software defined firewalls.

Definition at line 38 of file Rule.hpp.

Constructor & Destructor Documentation

◆ Rule()

Rule::Rule ( std::optional< If condition = {})

Base constructor for Rule classes.

Parameters
conditionThe condition used to determine if 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.
See also
action

Definition at line 33 of file Rule.cpp.

◆ ~Rule()

Rule::~Rule ( )
virtual

Definition at line 42 of file Rule.cpp.

Member Function Documentation

◆ action()

virtual Action Rule::action ( const Packet packet,
const MAVAddress address 
) const
pure 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.

Implemented in GoTo, Call, Accept, and Reject.

Here is the caller graph for this function:

◆ clone()

virtual std::unique_ptr<Rule> Rule::clone ( ) const
pure 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.

Implemented in GoTo, Call, Accept, and Reject.

Here is the caller graph for this function:

◆ operator!=()

virtual bool Rule::operator!= ( const Rule other) const
pure 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.

Implemented in GoTo, Call, Accept, and Reject.

◆ operator==()

virtual bool Rule::operator== ( const Rule other) const
pure 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.

Implemented in GoTo, Call, Accept, and Reject.

◆ print_()

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

Print the rule to the given output stream.

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

Implemented in GoTo, Call, Accept, and Reject.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Rule rule 
)
friend

Print the given rule to the given output stream.

Note
This is a polymorphic print, it will work on any child of Rule even if the pointer/reference is to the base class Rule.

Some examples are:

  • accept
  • accept with priority 3
  • reject if ENCAPSULATED_DATA
  • call gcs_in if from 192.168
  • goto autopilot_out
Parameters
osThe output stream to print to.
ruleThe rule (or any child of Rule) to print.
Returns
The output stream.

Definition at line 65 of file Rule.cpp.

Member Data Documentation

◆ condition_

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

Definition at line 91 of file Rule.hpp.


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