Skip to content

Commit

Permalink
feat(web2): ipv6 status information display (#4809)
Browse files Browse the repository at this point in the history
* feat(web2): populate ipv6 status informations (WIP)

* refactor: better name for method

* fix(web2): check for auto config

* fix: correct setting of subnet mask

* fix(web2): wrong field overwrite

* fix(web2): correctly populate dns fields

* fix(web2): correct way to populate dns servers

* revert(web2): original prettyPrintDnsServers method implementation

* style(web2): fix formatting

* fix(web2): Show read-only dns field when DHCP is selected and there are no custom DNS entries

* fix(web2): Show read-only dns field when there are no custom DNS entrie

* refactor(web2): moved DNS read-only visibility change in dedicated method

* fix(web2): unable to restore emtpy custom DNS

* fix(web2): fix on wrong assumption about config content
  • Loading branch information
mattdibi authored Aug 18, 2023
1 parent 0a9ceb6 commit 6be683f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,13 @@ private void initDnsField() {

this.dns.addValueChangeHandler(event -> {
setDirty(true);

if (this.dns.getText().trim().length() == 0) {
this.groupDns.setValidationState(ValidationState.NONE);
this.wrongInputDns.setText("");
return;
}

String[] addresses = this.dns.getText().trim().split(DNS_REGEX);
boolean isValid = addresses.length > 0;

Expand Down Expand Up @@ -474,30 +474,30 @@ private void refreshForm() {

private void refreshFieldsBasedOnInterface(GwtNetInterfaceConfig config) {
switch (config.getHwTypeEnum()) {
case ETHERNET:
break;
case LOOPBACK:
this.status.setEnabled(false);
this.priority.setEnabled(false);
this.configure.setEnabled(false);
this.autoconfiguration.setEnabled(false);
this.ip.setEnabled(false);
this.subnet.setEnabled(false);
this.gateway.setEnabled(false);
this.dns.setEnabled(false);
this.privacy.setEnabled(false);
break;
case MODEM:
this.configure.setEnabled(false);
this.configure.setSelectedIndex(0);
this.ip.setEnabled(false);
this.subnet.setEnabled(false);
this.gateway.setEnabled(false);
break;
case WIFI:
break;
default:
break;
case ETHERNET:
break;
case LOOPBACK:
this.status.setEnabled(false);
this.priority.setEnabled(false);
this.configure.setEnabled(false);
this.autoconfiguration.setEnabled(false);
this.ip.setEnabled(false);
this.subnet.setEnabled(false);
this.gateway.setEnabled(false);
this.dns.setEnabled(false);
this.privacy.setEnabled(false);
break;
case MODEM:
this.configure.setEnabled(false);
this.configure.setSelectedIndex(0);
this.ip.setEnabled(false);
this.subnet.setEnabled(false);
this.gateway.setEnabled(false);
break;
case WIFI:
break;
default:
break;

}
}
Expand Down Expand Up @@ -534,18 +534,18 @@ private void refreshFieldsBasedOnSelectedValues() {
if (this.configure.getSelectedValue().equals(CONFIGURE_AUTO)
|| this.configure.getSelectedValue().equals(CONFIGURE_DHCP)) {
this.ip.setEnabled(false);
this.ip.setText("");
this.subnet.setEnabled(false);
this.subnet.setText("");
this.gateway.setEnabled(false);
this.gateway.setText("");
}

if (this.configure.getSelectedValue().equals(CONFIGURE_MANUAL)
|| this.configure.getSelectedValue().equals(CONFIGURE_DHCP)) {
this.autoconfiguration.setEnabled(false);
this.privacy.setEnabled(false);
}

// Show read-only dns field when there are no custom DNS entries
this.dnsRead.setVisible(this.dns.getValue() == null || this.dns.getValue().isEmpty());
}

@Override
Expand Down Expand Up @@ -590,15 +590,23 @@ private void updateConfigWithSelectedValues(GwtNetInterfaceConfig updatedNetIf)

if (notNullOrEmpty(this.ip.getValue())) {
updatedNetIf.setIpv6Address(this.ip.getValue().trim());
} else {
updatedNetIf.setIpv6Address("");
}
if (this.subnet.getValue() != null) {
updatedNetIf.setIpv6SubnetMask(this.subnet.getValue());
} else {
updatedNetIf.setIpv6SubnetMask(0);
}
if (notNullOrEmpty(this.gateway.getValue())) {
updatedNetIf.setIpv6Gateway(this.gateway.getValue().trim());
} else {
updatedNetIf.setIpv6Gateway("");
}
if (notNullOrEmpty(this.dns.getValue())) {
updatedNetIf.setIpv6DnsServers(this.dns.getValue().trim());
} else {
updatedNetIf.setIpv6DnsServers("");
}

updatedNetIf.setIpv6Privacy(this.privacy.getSelectedValue());
Expand Down Expand Up @@ -642,10 +650,10 @@ public void refresh() {
setDirty(false);
resetValidations();

if (this.selectedNetIfConfig.isEmpty()) {
reset();
} else {
if (this.selectedNetIfConfig.isPresent()) {
fillFormWithCachedConfig();
} else {
reset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private void setIpv6Properties() {
}

this.gwtConfig.setIpv6Gateway(this.properties.getIp6Gateway(this.ifName));
this.gwtConfig.setIpv6DnsServers(this.properties.getIp6DnsServers(this.ifName));

Optional<String> privacy = this.properties.getIp6Privacy(this.ifName);
if (privacy.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.kura.core.net.util.NetworkUtil;
import org.eclipse.kura.core.util.NetUtil;
import org.eclipse.kura.net.IP4Address;
import org.eclipse.kura.net.IP6Address;
import org.eclipse.kura.net.IPAddress;
import org.eclipse.kura.net.status.NetworkInterfaceIpAddress;
import org.eclipse.kura.net.status.NetworkInterfaceStatus;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void fillWithStatusProperties(String ifName, GwtNetInterfaceConfig gwtCon
if (networkInterfaceInfo.isPresent()) {
setCommonStateProperties(gwtConfigToUpdate, networkInterfaceInfo.get());
setIpv4DhcpClientProperties(gwtConfigToUpdate, networkInterfaceInfo.get());
setIpv6StatusProperties(gwtConfigToUpdate, networkInterfaceInfo.get());
setWifiStateProperties(gwtConfigToUpdate, networkInterfaceInfo.get());
setModemStateProperties(gwtConfigToUpdate, networkInterfaceInfo.get());
}
Expand Down Expand Up @@ -220,6 +222,33 @@ private boolean isDhcpClient(String ipConfigMode) {
return ipConfigMode != null && ipConfigMode.equals(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
}

private void setIpv6StatusProperties(GwtNetInterfaceConfig gwtConfig, NetworkInterfaceStatus networkInterfaceInfo) {

String ipConfigMode = gwtConfig.getIpv6ConfigMode();
if (isIpv6AutoConfig(ipConfigMode)) {
/*
* An interface can have multiple active addresses, we select just the first
* one. This is a limit of the current GWT UI.
*/
networkInterfaceInfo.getInterfaceIp6Addresses().ifPresent(address -> {
if (!address.getAddresses().isEmpty()) {
NetworkInterfaceIpAddress<IP6Address> firstAddress = address.getAddresses().get(0);
gwtConfig.setIpv6Address(firstAddress.getAddress().getHostAddress());
gwtConfig.setIpv6SubnetMask((int) firstAddress.getPrefix());
}
if (address.getGateway().isPresent()) {
gwtConfig.setIpv6Gateway(address.getGateway().get().getHostAddress());
}
gwtConfig.setIpv6ReadOnlyDnsServers(prettyPrintDnsServers(address.getDnsServerAddresses()));
});
}
}

private boolean isIpv6AutoConfig(String ipConfigMode) {
return ipConfigMode != null
&& (ipConfigMode.equals("netIPv6MethodAuto") || ipConfigMode.equals("netIPv6MethodDhcp"));
}

private <T extends IPAddress> String prettyPrintDnsServers(List<T> dnsAddresses) {
StringBuilder result = new StringBuilder();
for (T dnsAddress : dnsAddresses) {
Expand Down

0 comments on commit 6be683f

Please sign in to comment.