mavtables  0.2.1
MAVLink router and firewall.
If.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 IF_HPP_
19 #define IF_HPP_
20 
21 
22 #include <optional>
23 #include <string>
24 
25 #include "MAVAddress.hpp"
26 #include "MAVSubnet.hpp"
27 #include "Packet.hpp"
28 
29 
30 /** An if statement used to determine if a packet matches a rule.
31  *
32  * This uses the type, source, and destination of a packet to determine if it
33  * matches.
34  */
35 class If
36 {
37  public:
38  If(std::optional<unsigned long> id = {},
39  std::optional<MAVSubnet> source = {},
40  std::optional<MAVSubnet> dest = {});
41  /** Copy constructor.
42  *
43  * \param other If to copy from.
44  */
45  If(const If &other) = default;
46  /** Move constructor.
47  *
48  * \param other If to move from.
49  */
50  If(If &&other) = default;
51  If &type(unsigned long id);
52  If &type(const std::string &name);
53  If &from(MAVSubnet subnet);
54  If &from(const std::string &subnet);
55  If &to(MAVSubnet subnet);
56  If &to(const std::string &subnet);
57  bool check(const Packet &packet, const MAVAddress &address) const;
58  /** Assignment operator.
59  *
60  * \param other If to copy from.
61  */
62  If &operator=(const If &other) = default;
63  /** Assignment operator (by move semantics).
64  *
65  * \param other If to move from.
66  */
67  If &operator=(If &&other) = default;
68 
69  friend bool operator==(const If &lhs, const If &rhs);
70  friend bool operator!=(const If &lhs, const If &rhs);
71  friend std::ostream &operator<<(
72  std::ostream &os, const If &if_);
73 
74  private:
75  std::optional<unsigned long> id_;
76  std::optional<MAVSubnet> source_;
77  std::optional<MAVSubnet> dest_;
78 };
79 
80 
81 bool operator==(const If &lhs, const If &rhs);
82 bool operator!=(const If &lhs, const If &rhs);
83 std::ostream &operator<<(std::ostream &os, const If &if_);
84 
85 
86 #endif // IF_HPP_
If & from(MAVSubnet subnet)
Definition: If.cpp:98
If & type(unsigned long id)
Definition: If.cpp:69
If(std::optional< unsigned long > id={}, std::optional< MAVSubnet > source={}, std::optional< MAVSubnet > dest={})
Definition: If.cpp:49
Definition: If.hpp:35
If & to(MAVSubnet subnet)
Definition: If.cpp:127
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
bool operator==(const Action &lhs, const Action &rhs)
Definition: Action.cpp:154
bool operator!=(const Action &lhs, const Action &rhs)
Definition: Action.cpp:168
bool check(const Packet &packet, const MAVAddress &address) const
Definition: If.cpp:160
friend bool operator==(const If &lhs, const If &rhs)
Definition: If.cpp:194
If & operator=(const If &other)=default
friend bool operator!=(const If &lhs, const If &rhs)
Definition: If.cpp:209
friend std::ostream & operator<<(std::ostream &os, const If &if_)
Definition: If.cpp:224