mavtables  0.2.1
MAVLink router and firewall.
Chain.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef CHAIN_HPP_
19 #define CHAIN_HPP_
20 
21 
22 #include <memory>
23 #include <ostream>
24 #include <string>
25 #include <vector>
26 
27 #include "Action.hpp"
28 #include "config.hpp"
29 #include "MAVAddress.hpp"
30 #include "Packet.hpp"
31 #include "RecursionGuard.hpp"
32 #include "Rule.hpp"
33 
34 
35 /** A filter chain, containing a list of rules to check packets against.
36  */
37 class Chain
38 {
39  public:
40  Chain(const Chain &other);
41  /** Move constructor.
42  *
43  * \param other Chain to move from.
44  */
45  Chain(Chain &&other) = default;
46  Chain(std::string name_,
47  std::vector<std::unique_ptr<Rule>> &&rules = {});
48  TEST_VIRTUAL ~Chain() = default;
49  TEST_VIRTUAL Action action(
50  const Packet &packet, const MAVAddress &address);
51  void append(std::unique_ptr<Rule> rule);
52  const std::string &name() const;
53  Chain &operator=(const Chain &other);
54  /** Assignment operator (by move semantics).
55  *
56  * \param other Chain to move from.
57  */
58  Chain &operator=(Chain &&other) = default;
59 
60  friend bool operator==(const Chain &lhs, const Chain &rhs);
61  friend bool operator!=(const Chain &lhs, const Chain &rhs);
62  friend std::ostream &operator<<(std::ostream &os, const Chain &chain);
63 
64  private:
65  std::string name_;
66  std::vector<std::unique_ptr<Rule>> rules_;
67  RecursionData recursion_data_;
68 };
69 
70 
71 bool operator==(const Chain &lhs, const Chain &rhs);
72 bool operator!=(const Chain &lhs, const Chain &rhs);
73 std::ostream &operator<<(std::ostream &os, const Chain &chain);
74 
75 
76 #endif // CHAIN_HPP_
const std::string & name() const
Definition: Chain.cpp:128
TEST_VIRTUAL ~Chain()=default
friend std::ostream & operator<<(std::ostream &os, const Chain &chain)
Definition: Chain.cpp:225
Chain & operator=(const Chain &other)
Definition: Chain.cpp:138
friend bool operator==(const Chain &lhs, const Chain &rhs)
Definition: Chain.cpp:163
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
TEST_VIRTUAL Action action(const Packet &packet, const MAVAddress &address)
Definition: Chain.cpp:90
bool operator==(const Action &lhs, const Action &rhs)
Definition: Action.cpp:154
bool operator!=(const Action &lhs, const Action &rhs)
Definition: Action.cpp:168
friend bool operator!=(const Chain &lhs, const Chain &rhs)
Definition: Chain.cpp:200
Definition: Chain.hpp:37
void append(std::unique_ptr< Rule > rule)
Definition: Chain.cpp:116
Chain(const Chain &other)
Definition: Chain.cpp:38
Rule & rule
Definition: test_Call.cpp:231