51 enum class TableType { Invalid, Raw, Nat, Mangle, Filter, Security };
52 typedef std::map<TableType, std::list<std::string>> RuleSet;
54 RuleSet
rules(
const int ipVersion)
const;
55 bool setRules(
const RuleSet &ruleSet,
const int ipVersion);
57 enum class Operation { Append, Insert, Delete, Unchanged };
59 bool addRules(RuleSet &ruleSet,
const int ipVersion, Operation operation);
67 bool forkExec(
const std::string &file,
68 const std::list<std::string> &args,
69 int stdinFd,
int stdoutFd,
int stderrFd)
const;
71 bool writeString(
int fd,
const std::string &str)
const;
76 const std::list<std::string> &rulesList)
const;
80 RuleSet appendRuleSet;
81 RuleSet insertRuleSet;
82 RuleSet deleteRuleSet;
83 RuleSet unchangedRuleSet;
90 Operation operation)
const;
93 void dump(
const RuleSet &ruleSet,
const char *title =
nullptr)
const;
105 mutable std::mutex mLock;
Class that can read / write iptables rule sets.
Definition: Netfilter.h:45
bool writeString(int fd, const std::string &str) const
Writes the string into the supplied file descriptor.
Definition: Netfilter.cpp:681
bool ruleInList(const std::string &rule, const std::list< std::string > &rulesList) const
Returns true if the rule is in the rulesList.
Definition: Netfilter.cpp:728
bool addRules(RuleSet &ruleSet, const int ipVersion, Operation operation)
Adds rules to the internal rule caches.
Definition: Netfilter.cpp:763
bool forkExec(const std::string &file, const std::list< std::string > &args, int stdinFd, int stdoutFd, int stderrFd) const
Performs a fork/exec operation and waits for the child to terminate.
Definition: Netfilter.cpp:105
RuleSet getRuleSet(const int ipVersion) const
Uses the iptables-save tool to get the current rules.
Definition: Netfilter.cpp:240
bool createNewChain(TableType table, const std::string &name, const int ipVersion)
Creates a new IPTables chain with the given name and put it in the rule cache to write later.
Definition: Netfilter.cpp:828
bool checkDuplicates(RuleSets ruleCache, const int ipVersion) const
Checks all rulesets in a rule cache for duplicates to check which rules need to be applied.
Definition: Netfilter.cpp:434
bool applyRules(const int ipVersion)
Uses the iptables-restore tool to apply the rules stored in mRulesets.
Definition: Netfilter.cpp:484
void dump(const RuleSet &ruleSet, const char *title=nullptr) const
Debugging function to print out the supplied ruleset.
Definition: Netfilter.cpp:863
void trimDuplicates(RuleSet &existing, RuleSet &newRuleSet, Operation operation) const
Trims duplicates from mRuleSets based on the operation.
Definition: Netfilter.cpp:381
IptablesVersion getIptablesVersion() const
Definition: Netfilter.cpp:892
RuleSet rules(const int ipVersion) const
Returns the current iptables ruleset.
Definition: Netfilter.cpp:714
Definition: Netfilter.h:96
Definition: Netfilter.h:79