Skip to content

Commit 6ccc0d2

Browse files
committed
Exec also ip6tables startup rules
1 parent 0ccd44d commit 6ccc0d2

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

hb/src/main.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,14 +740,29 @@ int main(int argc, char *argv[])
740740
running = true;
741741

742742
// iptables commands for execution during daemon startup
743-
if (!config.iptablesStartupCheck.empty() && iptables.command(config.iptablesStartupCheck + ">/dev/null 2>/dev/null") != 0) {
744-
log.info("Executing iptables startup commands...");
745-
int response = 0;
746-
for (std::vector<std::string>::iterator it = config.iptablesStartupAdd.begin(); it != config.iptablesStartupAdd.end(); ++it) {
747-
log.debug("iptables " + *it);
748-
response = iptables.command(*it);
749-
if (response != 0) {
750-
log.error("Failed to execute iptables command '" + *it + "', return code: " + std::to_string(response));
743+
if (!config.iptablesStartupCheck.empty()) {
744+
// IPv4
745+
if (iptables.command(config.iptablesStartupCheck + ">/dev/null 2>/dev/null") != 0) {
746+
log.info("Executing iptables startup commands...");
747+
int response = 0;
748+
for (std::vector<std::string>::iterator it = config.iptablesStartupAdd.begin(); it != config.iptablesStartupAdd.end(); ++it) {
749+
log.debug("iptables " + *it);
750+
response = iptables.command(*it);
751+
if (response != 0) {
752+
log.error("Failed to execute iptables command '" + *it + "', return code: " + std::to_string(response));
753+
}
754+
}
755+
}
756+
// IPv6
757+
if (iptables.command(config.iptablesStartupCheck + ">/dev/null 2>/dev/null", 6) != 0) {
758+
log.info("Executing ip6tables startup commands...");
759+
int response = 0;
760+
for (std::vector<std::string>::iterator it = config.iptablesStartupAdd.begin(); it != config.iptablesStartupAdd.end(); ++it) {
761+
log.debug("ip6tables " + *it);
762+
response = iptables.command(*it, 6);
763+
if (response != 0) {
764+
log.error("Failed to execute ip6tables command '" + *it + "', return code: " + std::to_string(response));
765+
}
751766
}
752767
}
753768
}

0 commit comments

Comments
 (0)