Skip to content

Commit

Permalink
api/server: fix non-compilable rule
Browse files Browse the repository at this point in the history
"( )" rule does not seem to compile with NPF, this commit avoid having
empty rules like this.
closes outscale#83

Signed-off-by: Jerome Jutteau <jerome.jutteau@outscale.com>
  • Loading branch information
jerome-jutteau committed Jul 13, 2016
1 parent 857f715 commit 43786b4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions api/server/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,17 @@ std::string Graph::fw_build_rule(const app::Rule &rule) {
std::string Graph::fw_build_sg(const app::Sg &sg) {
std::string r;
for (auto it = sg.rules.begin(); it != sg.rules.end();) {
r += "(" + fw_build_rule(it->second) + ")";
auto fw_rule = fw_build_rule(it->second);
if (fw_rule.length() == 0)
continue;
r += "(" + fw_rule + ")";
if (++it != sg.rules.end())
r += " || ";
r += "||";
}
// Special case when last rule is empty
if (r.back() == '|') {
r.pop_back();
r.pop_back();
}
return r;
}
Expand Down Expand Up @@ -639,9 +647,17 @@ void Graph::fw_update(const app::Nic &nic) {
it++;
continue;
}
in_rules += "( " + fw_build_sg(sit->second) + " )";
auto sg_rules = fw_build_sg(sit->second);
if (sg_rules.length() == 0)
continue;
in_rules += "(" + fw_build_sg(sit->second) + ")";
if (++it != nic.security_groups.end())
in_rules += " || ";
in_rules += "||";
// Special case when last rule is empty
if (in_rules.back() == '|') {
in_rules.pop_back();
in_rules.pop_back();
}
}

// Set rules for the outgoing traffic: allow NIC's IPs
Expand Down

0 comments on commit 43786b4

Please sign in to comment.