softwarecontainer  0.18.0-739e8d7 2017-05-04
iptableentry.h
1 /*
2  * Copyright (C) 2016-2017 Pelagicore AB
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11  * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15  * SOFTWARE.
16  *
17  * For further information see LICENSE
18  */
19 
20 #pragma once
21 
22 #include "softwarecontainer-common.h"
23 
24 namespace softwarecontainer {
25 
30 {
31  LOG_DECLARE_CLASS_CONTEXT("IPTE", "IPTable Entry");
32 public:
33  IPTableEntry() : m_type{""}, m_defaultTarget{DROP} {};
37  struct portFilter {
38  portFilter(bool _any=0, bool _multiport=0, std::string _ports="") :
39  any(_any),
40  multiport(_multiport),
41  ports(_ports)
42  {};
43  bool any;
44  bool multiport;
45  std::string ports;
46  };
47 
51  enum Target
52  {
53  INVALID_TARGET,
54  ACCEPT,
55  DROP,
56  REJECT
57  };
58 
62  struct Rule
63  {
64  std::string host;
65  std::vector<std::string> protocols;
66  portFilter ports;
67  Target target;
68  };
69 
75  bool applyRules();
76 
81  std::string interpretRule(Rule rule);
82 
87  std::string interpretRuleWithProtocol(Rule rule, const std::string &protocol);
88 
98  std::string interpretPolicy(void);
99 
100 
104  std::string toString();
105 
106  std::string m_type;
107  std::vector<Rule> m_rules;
108  Target m_defaultTarget;
109 private:
114  std::string convertTarget (Target& t);
115 
121  bool insertCommand(std::string command);
122 };
123 
124 } // namespace softwarecontainer
Definition of a &#39;Rule&#39; used to handle network traffic.
Definition: iptableentry.h:62
Target
Targets for Rules.
Definition: iptableentry.h:51
std::string interpretRuleWithProtocol(Rule rule, const std::string &protocol)
Interprets a rule with protocol information to iptables applicable string.
std::string interpretRule(Rule rule)
Interprets a rule to iptables applicable string.
bool applyRules()
Applies all rules to iptables.
std::string interpretPolicy(void)
This function Interprets defaultTarget rule to iptables applicable policy string. ...
std::string toString()
Creates a string with information about the entry.
container for port filtering options.
Definition: iptableentry.h:37
Developers guide to adding a config item:
A rules entry for the treatment of packets.
Definition: iptableentry.h:29