mavtables  0.2.1
MAVLink router and firewall.
MAVSubnet.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2017-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 MAVSUBNET_HPP_
19 #define MAVSUBNET_HPP_
20 
21 
22 #include <ostream>
23 #include <string>
24 
25 #include "MAVAddress.hpp"
26 
27 
28 /** A MAVLink subnet.
29  *
30  * Mavlink subnets work the same as IP subnets and allow the definition of a
31  * range of addresses. This is used to allow a single firewall rule to match
32  * multiple addresses.
33  *
34  * \sa MAVAddress
35  */
36 class MAVSubnet
37 {
38  public:
39  /** Copy constructor.
40  *
41  * \param other MAVLink subnet to copy from.
42  */
43  MAVSubnet(const MAVSubnet &other) = default;
44  /** Move constructor.
45  *
46  * \param other MAVLink subnet to move from.
47  */
48  MAVSubnet(MAVSubnet &&other) = default;
49  MAVSubnet(const MAVAddress &address, unsigned int mask = 0xFFFF);
50  MAVSubnet(const MAVAddress &address, unsigned int system_mask,
51  unsigned int component_mask);
52  MAVSubnet(std::string address);
53  bool contains(const MAVAddress &address) const;
54  /** Assignment operator.
55  *
56  * \param other MAVLink subnet to copy from.
57  */
58  MAVSubnet &operator=(const MAVSubnet &other) = default;
59  /** Assignment operator (by move semantics).
60  *
61  * \param other MAVLink subnet to move from.
62  */
63  MAVSubnet &operator=(MAVSubnet &&other) = default;
64 
65  friend bool operator==(const MAVSubnet &lhs, const MAVSubnet &rhs);
66  friend bool operator!=(const MAVSubnet &lhs, const MAVSubnet &rhs);
67  friend std::ostream &operator<<(std::ostream &os,
68  const MAVSubnet &mavsubnet);
69 
70  private:
71  MAVAddress address_;
72  unsigned int mask_;
73 };
74 
75 
76 bool operator==(const MAVSubnet &lhs, const MAVSubnet &rhs);
77 bool operator!=(const MAVSubnet &lhs, const MAVSubnet &rhs);
78 std::ostream &operator<<(std::ostream &os, const MAVSubnet &mavsubnet);
79 
80 
81 #endif // MAVSUBNET_HPP_
MAVSubnet(const MAVSubnet &other)=default
friend bool operator==(const MAVSubnet &lhs, const MAVSubnet &rhs)
Definition: MAVSubnet.cpp:266
MAVSubnet & operator=(const MAVSubnet &other)=default
friend bool operator!=(const MAVSubnet &lhs, const MAVSubnet &rhs)
Definition: MAVSubnet.cpp:282
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 contains(const MAVAddress &address) const
Definition: MAVSubnet.cpp:250
friend std::ostream & operator<<(std::ostream &os, const MAVSubnet &mavsubnet)
Definition: MAVSubnet.cpp:311