Skip to content

Commit

Permalink
Merge pull request #346 from FedeParola/nat-fixes
Browse files Browse the repository at this point in the history
Fix NAT bugs
  • Loading branch information
frisso committed Oct 27, 2020
2 parents 7988930 + 0422d14 commit d2f64b6
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Documentation/services/pcn-nat/nat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ To delete a single rule (an SNAT rule in the example):

::

polycubectl nat1 rule snat del RULE_ID
polycubectl nat1 rule snat entry del RULE_ID

Deleting a rule does not affect ongoing natting sessions: to prevent a deleted rule from being applied, `flush the natting table <Natting-table>`_.

Expand Down
2 changes: 1 addition & 1 deletion src/services/pcn-nat/src/IpAddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct IpAddr {
throw std::runtime_error("Netmask can't be bigger than 32");

ip_ = ipnetmask.substr(0, found);
ip = utils::ip_string_to_nbo_uint(ip_);
ip = utils::ip_string_to_nbo_uint(ip_) & ntohl(0xffffffff << (32 - netmask_));
netmask = netmask_;
}
bool operator<(const IpAddr &that) const {
Expand Down
13 changes: 4 additions & 9 deletions src/services/pcn-nat/src/Rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ Rule::Rule(Nat &parent, const RuleJsonObject &conf) : parent_(parent) {
update(conf);
}

Rule::~Rule() {
delSnat();
delDnat();
delPortForwarding();
delMasquerade();
}
Rule::~Rule() {}

void Rule::update(const RuleJsonObject &conf) {
// This method updates all the object/parameter in Rule object specified in
Expand Down Expand Up @@ -87,7 +82,7 @@ void Rule::replaceSnat(const RuleSnatJsonObject &conf) {
}

void Rule::delSnat() {
snat_ = nullptr;
snat_->delEntryList();
}

std::shared_ptr<RuleMasquerade> Rule::getMasquerade() {
Expand Down Expand Up @@ -122,7 +117,7 @@ void Rule::replaceDnat(const RuleDnatJsonObject &conf) {
}

void Rule::delDnat() {
dnat_ = nullptr;
dnat_->delEntryList();
}

std::shared_ptr<RulePortForwarding> Rule::getPortForwarding() {
Expand All @@ -139,5 +134,5 @@ void Rule::replacePortForwarding(const RulePortForwardingJsonObject &conf) {
}

void Rule::delPortForwarding() {
portforwarding_ = nullptr;
portforwarding_->delEntryList();
}
3 changes: 2 additions & 1 deletion src/services/pcn-nat/src/RuleDnat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ RuleDnat::RuleDnat(Rule &parent, const RuleDnatJsonObject &conf)

RuleDnat::~RuleDnat() {
delEntryList();
logger()->info("Removed all DNAT rules");
}

void RuleDnat::update(const RuleDnatJsonObject &conf) {
Expand Down Expand Up @@ -151,4 +150,6 @@ void RuleDnat::delEntryList() {
}

rules_.clear();

logger()->info("Removed all DNAT rules");
}
3 changes: 2 additions & 1 deletion src/services/pcn-nat/src/RulePortForwarding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ RulePortForwarding::RulePortForwarding(Rule &parent,

RulePortForwarding::~RulePortForwarding() {
delEntryList();
logger()->info("Removed all PortForwarding rules");
}

void RulePortForwarding::update(const RulePortForwardingJsonObject &conf) {
Expand Down Expand Up @@ -157,4 +156,6 @@ void RulePortForwarding::delEntryList() {
}

rules_.clear();

logger()->info("Removed all PortForwarding rules");
}
3 changes: 2 additions & 1 deletion src/services/pcn-nat/src/RuleSnat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ RuleSnat::RuleSnat(Rule &parent, const RuleSnatJsonObject &conf)

RuleSnat::~RuleSnat() {
delEntryList();
logger()->info("Removed all SNAT rules");
}

void RuleSnat::update(const RuleSnatJsonObject &conf) {
Expand Down Expand Up @@ -145,4 +144,6 @@ void RuleSnat::delEntryList() {
}

rules_.clear();

logger()->info("Removed all SNAT rules");
}

0 comments on commit d2f64b6

Please sign in to comment.