Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Firewall IPV6 support in UI #4805

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public interface FirewallPortForwardConfig extends NetConfig {
*/
public IPAddress getIPAddress();

/**
* The netmask of the LAN IP address to forward connections to
*
* @return The netmask of the LAN IPAddress to forward connections to
* @since 2.6
*/
public short getIPAddressNetmask();

/**
* Gets the type of network protocol (TCP or UDP) that is used for this configuration
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public static FirewallPortForwardConfigIP4Builder builder() {
return new FirewallPortForwardConfigIP4Builder();
}

/**
* @since 2.6
*/
@Override
public short getIPAddressNetmask() {
return (short) 32;
}

/**
* The builder class for the IPv4 firewall port forward configuration
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public static FirewallPortForwardConfigIP6Builder builder() {
return new FirewallPortForwardConfigIP6Builder();
}

/**
* @since 2.6
*/
@Override
public short getIPAddressNetmask() {
return (short) 128;
}

/**
* The builder class for the IPv6 firewall port forward configuration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private String formPortForwardConfigPropValue() {
}
sb.append(',');
if (portForwardConfig.getIPAddress() != null) {
sb.append(portForwardConfig.getIPAddress());
sb.append(portForwardConfig.getIPAddress().getHostAddress());
}
sb.append(',');
if (portForwardConfig.getProtocol() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ protected void setExecutorService(CommandExecutorService executorService) {

protected abstract String getIpForwardFileName();

/*
* Add a Local rule to the firewall.
*
* @deprecated since 1.2. Use {@link addLocalRules(List<LocalRule>
* newLocalRules)}
*/
@Deprecated
@SuppressWarnings("checkstyle:parameterNumber")
public void addLocalRule(int port, String protocol, String permittedNetwork, String permittedNetworkPrefix,
String permittedInterfaceName, String unpermittedInterfaceName, String permittedMAC, String sourcePortRange)
Expand Down Expand Up @@ -117,6 +124,13 @@ public void addLocalRules(List<LocalRule> newLocalRules) throws KuraException {
}
}

/*
* Add a Port Forward rule to the firewall.
*
* @deprecated since 1.2. Use {@link addPortForwardRules(List<PortForwardRule>
* newPortForwardRules)}
*/
@Deprecated
@SuppressWarnings("checkstyle:parameterNumber")
public void addPortForwardRule(String inboundIface, String outboundIface, String address, String protocol,
int inPort, int outPort, boolean masquerade, String permittedNetwork, String permittedNetworkPrefix,
Expand Down Expand Up @@ -157,15 +171,12 @@ public void addPortForwardRules(List<PortForwardRule> newPortForwardRules) throw
}
}

/**
* Adds automatic NAT rule
*
* @param sourceInterface
* @param destinationInterface
* @param masquerade
* @param type
* @throws KuraException
/*
* Add a Nat rule to the firewall.
*
* @deprecated since 1.2. Use {@link addNatRules(List<NATRule> newNatRules))}
*/
@Deprecated
public void addNatRule(String sourceInterface, String destinationInterface, boolean masquerade, RuleType type)
throws KuraException {
if (sourceInterface == null || sourceInterface.isEmpty()) {
Expand All @@ -182,18 +193,12 @@ public void addNatRule(String sourceInterface, String destinationInterface, bool
addAutoNatRules(natRuleList);
}

/**
* Adds NAT Rule
*
* @param sourceInterface
* @param destinationInterface
* @param protocol
* @param source
* @param destination
* @param masquerade
* @param type
* @throws KuraException
/*
* Add a Nat Forward rule to the firewall.
*
* @deprecated since 1.2. Use {@link addNatRules(List<NATRule> newNatRules)}
*/
@Deprecated
public void addNatRule(String sourceInterface, String destinationInterface, String protocol, String source,
String destination, boolean masquerade, RuleType type) throws KuraException {

Expand Down Expand Up @@ -282,6 +287,14 @@ public void deleteAutoNatRule(NATRule rule) throws KuraException {
update();
}

public void deleteNatRule(NATRule rule) throws KuraException {
if (this.natRules == null) {
return;
}
this.natRules.remove(rule);
update();
}

public void deleteAllLocalRules() throws KuraException {
this.localRules.clear();
update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,10 @@ public List<String> toStrings() {
List<String> ret = new ArrayList<>();
StringBuilder sb = new StringBuilder("-A " + chain);
if (this.srcNetwork != null) {
sb.append(" -s ") //
.append(this.srcNetwork) //
.append('/') //
.append(this.srcMask);
sb.append(" -s ").append(this.srcNetwork).append('/').append(this.srcMask);
}
if (this.dstNetwork != null) {
sb.append(" -d ") //
.append(this.dstNetwork) //
.append('/') //
.append(this.dstMask);
sb.append(" -d ").append(this.dstNetwork).append('/').append(this.dstMask);
}
sb.append(" -i ").append(this.inputInterface);
sb.append(" -o ").append(this.outputInterface);
Expand All @@ -168,10 +162,7 @@ public List<String> toStrings() {
sb.append(" -m mac --mac-source ").append(this.permittedMacAddress);
}
if (this.srcPortFirst > 0 && this.srcPortLast >= this.srcPortFirst) {
sb.append(" --sport ") //
.append(this.srcPortFirst) //
.append(':') //
.append(this.srcPortLast);
sb.append(" --sport ").append(this.srcPortFirst).append(':').append(this.srcPortLast);
}
if (this.dstPort > 0) {
sb.append(" --dport ").append(this.dstPort);
Expand All @@ -180,10 +171,7 @@ public List<String> toStrings() {
ret.add(sb.toString());
sb = new StringBuilder("-A " + chain);
if (this.dstNetwork != null) {
sb.append(" -s ") //
.append(this.dstNetwork) //
.append('/') //
.append(this.dstMask);
sb.append(" -s ").append(this.dstNetwork).append('/').append(this.dstMask);
}
sb.append(" -i ").append(this.outputInterface);
sb.append(" -o ").append(this.inputInterface);
Expand Down
Loading