weizhouapache commented on code in PR #8530:
URL: https://github.com/apache/cloudstack/pull/8530#discussion_r1459367595
##########
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java:
##########
@@ -2287,28 +2287,39 @@ public synchronized String
allowOutgoingOnPrivate(String destCidr) {
if (!_inSystemVM) {
return null;
}
- Script command = new Script("/bin/bash", s_logger);
String intf = "eth1";
- command.add("-c");
- command.add("iptables -D OUTPUT -o " + intf + " -d " + destCidr + " -p
tcp -m state --state NEW -m tcp -j ACCEPT");
+ String rule = String.format("OUTPUT -o %s -d %s -p tcp -m state
--state NEW -m tcp -j ACCEPT", intf, destCidr);
- /* ignore the String result =*/ command.execute();
-
- command = new Script("/bin/bash", s_logger);
- command.add("-c");
- command.add("iptables -I OUTPUT -o " + intf + " -d " + destCidr + " -p
tcp -m state --state NEW -m tcp -j ACCEPT");
+ if (ruleNeedsAdding(rule)) {
+ Script command = new Script("/bin/bash", s_logger);
+ command.add("-c");
+ command.add("iptables -I");
+ command.add(rule);
- String result = command.execute();
- if (result != null) {
- s_logger.warn("Error in allowing outgoing to " + destCidr + ",
err=" + result);
- return "Error in allowing outgoing to " + destCidr + ", err=" +
result;
+ String result = command.execute();
+ if (result != null) {
+ s_logger.warn("Error in allowing outgoing to " + destCidr + ",
err=" + result);
+ return "Error in allowing outgoing to " + destCidr + ", err="
+ result;
+ }
+ } else {
+ s_logger.warn("Rule already defined in SVM: Error in allowing
outgoing to " + destCidr);
}
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, destCidr);
return null;
}
+ private boolean ruleNeedsAdding(String rule) {
+ Script command = new Script("/bin/bash", s_logger);
+ command.add("-c");
+ command.add("iptables -C");
+ command.add("rule");
Review Comment:
```suggestion
command.add(rule);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]