mavtables  0.2.1
MAVLink router and firewall.
Filter.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 FILTER_HPP_
19 #define FILTER_HPP_
20 
21 
22 #include <memory>
23 #include <utility>
24 
25 #include "Action.hpp"
26 #include "Chain.hpp"
27 #include "config.hpp"
28 #include "MAVAddress.hpp"
29 #include "Packet.hpp"
30 
31 
32 /** The filter used to determine whether to accept or reject a packet.
33  *
34  * \sa Chain
35  * \sa Rule
36  * \sa If
37  */
38 class Filter
39 {
40  public:
41  /** Copy constructor.
42  *
43  * \param other Filter to copy from.
44  */
45  Filter(const Filter &other) = default;
46  /** Move constructor.
47  *
48  * \param other Filter to move from.
49  */
50  Filter(Filter &&other) = default;
51  Filter(Chain default_chain, bool accept_by_default = false);
52  // LCOV_EXCL_START
53  TEST_VIRTUAL ~Filter() = default;
54  // LCOV_EXCL_STOP
55  TEST_VIRTUAL std::pair<bool, int> will_accept(
56  const Packet &packet, const MAVAddress &address);
57  /** Assignment operator.
58  *
59  * \param other Filter to copy from.
60  */
61  Filter &operator=(const Filter &other) = default;
62  /** Assignment operator (by move semantics).
63  *
64  * \param other Filter to move from.
65  */
66  Filter &operator=(Filter &&other) = default;
67 
68  friend bool operator==(const Filter &lhs, const Filter &rhs);
69  friend bool operator!=(const Filter &lhs, const Filter &rhs);
70 
71  private:
72  Chain default_chain_;
73  bool accept_by_default_;
74 };
75 
76 
77 bool operator==(const Filter &lhs, const Filter &rhs);
78 bool operator!=(const Filter &lhs, const Filter &rhs);
79 
80 
81 #endif // FILTER_HPP_
Filter(const Filter &other)=default
friend bool operator!=(const Filter &lhs, const Filter &rhs)
Definition: Filter.cpp:102
Filter & operator=(const Filter &other)=default
TEST_VIRTUAL std::pair< bool, int > will_accept(const Packet &packet, const MAVAddress &address)
Definition: Filter.cpp:53
bool operator==(const Action &lhs, const Action &rhs)
Definition: Action.cpp:154
bool operator!=(const Action &lhs, const Action &rhs)
Definition: Action.cpp:168
TEST_VIRTUAL ~Filter()=default
Definition: Chain.hpp:37
friend bool operator==(const Filter &lhs, const Filter &rhs)
Definition: Filter.cpp:85