Skip to content
Draft
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 @@ -406,44 +406,37 @@ private synchronized void doApply(Map<String, Object> networkConfiguration) thro
private synchronized void doApply(String deviceIdToBeConfigured, Map<String, Object> networkConfiguration)
throws DBusException {
NetworkProperties properties = new NetworkProperties(networkConfiguration);
List<String> configuredInterfaceIds = properties.getStringList("net.interfaces");

Optional<Device> device = getNetworkManagerDeviceByInterfaceId(deviceIdToBeConfigured);
if (device.isPresent()) {
if (configuredInterfaceIds.contains(deviceIdToBeConfigured)) {
manageConfiguredInterface(device, deviceIdToBeConfigured, properties);
} else {
manageNonConfiguredInterface(device, deviceIdToBeConfigured);
}
manageInterface(device, deviceIdToBeConfigured, properties);
} else {
NMDeviceType propertyDeviceType = NMDeviceType.fromPropertiesString(
properties.get(String.class, "net.interface.%s.type", deviceIdToBeConfigured));
if (CONFIGURATION_SUPPORTED_VIRTUAL_DEVICE_TYPES.contains(propertyDeviceType)) {
manageConfiguredInterface(Optional.empty(), deviceIdToBeConfigured, properties);
manageInterface(Optional.empty(), deviceIdToBeConfigured, properties);
} else {
logger.warn("Can't apply configuration to disconnected or unsupported virtual device "
+ "\"{}\" of type \"{}\"", deviceIdToBeConfigured, propertyDeviceType);
}
}
}

private synchronized void manageConfiguredInterface(Optional<Device> device, String deviceId,
NetworkProperties properties) throws DBusException {
NMDeviceType deviceType;
if (device.isPresent()) {
deviceType = this.networkManager.getDeviceType(device.get().getObjectPath());
} else {
deviceType = NMDeviceType
.fromPropertiesString(properties.get(String.class, "net.interface.%s.type", deviceId));
}
private synchronized void manageInterface(Optional<Device> device, String deviceId, NetworkProperties properties)
throws DBusException {
NMDeviceType deviceType = getDeviceType(device, deviceId, properties);

KuraIpStatus ip4Status = KuraIpStatus
.fromString(properties.get(String.class, "net.interface.%s.config.ip4.status", deviceId));
Optional<KuraIpStatus> ip4OptStatus = KuraIpStatus
.fromString(properties.getOpt(String.class, "net.interface.%s.config.ip4.status", deviceId));
KuraIpStatus ip4Status = KuraIpStatus.DISABLED;
if (ip4OptStatus.isPresent()) {
ip4Status = ip4OptStatus.get();
}

Optional<KuraIpStatus> ip6OptStatus = KuraIpStatus
.fromString(properties.getOpt(String.class, "net.interface.%s.config.ip6.status", deviceId));
KuraIpStatus ip6Status;

KuraIpStatus ip6Status;
if (!ip6OptStatus.isPresent()) {
ip6Status = ip4Status == KuraIpStatus.UNMANAGED ? KuraIpStatus.UNMANAGED : KuraIpStatus.DISABLED;
} else {
Expand Down Expand Up @@ -482,6 +475,15 @@ private synchronized void manageConfiguredInterface(Optional<Device> device, Str

}

private NMDeviceType getDeviceType(Optional<Device> device, String deviceId, NetworkProperties properties)
throws DBusException {
if (device.isPresent()) {
return this.networkManager.getDeviceType(device.get().getObjectPath());
} else {
return NMDeviceType.fromPropertiesString(properties.get(String.class, "net.interface.%s.type", deviceId));
}
}

private void enableInterface(String deviceId, NetworkProperties properties, Optional<Device> device,
NMDeviceType deviceType) throws DBusException {
if (device.isPresent()) {
Expand Down Expand Up @@ -569,34 +571,6 @@ private void createVirtualInterface(String deviceId, NetworkProperties propertie
}
}

private void manageNonConfiguredInterface(Optional<Device> optDevice, String deviceId) throws DBusException {
if (!optDevice.isPresent()) {
logger.warn("Ignoring missing, non configured device \"{}\"", deviceId);
return;
}
Device device = optDevice.get();

NMDeviceType deviceType = this.networkManager.getDeviceType(device.getObjectPath());

if (!CONFIGURATION_SUPPORTED_DEVICE_TYPES.contains(deviceType)) {
logger.warn("Device \"{}\" of type \"{}\" currently not supported", deviceId, deviceType);
return;
}

if (Boolean.FALSE.equals(this.networkManager.isDeviceManaged(device))) {
this.networkManager.setDeviceManaged(device, true);
}

logger.warn("Device \"{}\" of type \"{}\" not configured. Disabling...", deviceId, deviceType);

disable(optDevice, deviceId);

if (deviceType == NMDeviceType.NM_DEVICE_TYPE_MODEM) {
Optional<String> mmDbusPath = this.networkManager.getModemManagerDbusPath(device.getObjectPath());
this.modemManager.setGPS(mmDbusPath, Optional.of(false), Optional.empty());
}
}

private void disable(Optional<Device> optDevice, String deviceId) throws DBusException {
if (!optDevice.isPresent()) {
logger.warn("Can't disable missing device {}", deviceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,32 @@ public static Map<String, Variant<?>> build8021xSettings(NetworkProperties props
Map<String, Variant<?>> settings = new HashMap<>();

switch (Kura8021xEAP.fromString(eap)) {
case KURA_8021X_EAP_TTLS:
create8021xTunneledTls(props, deviceId, settings);
break;
case KURA_8021X_EAP_PEAP:
create8021xProtectedEap(props, deviceId, settings);
break;
case KURA_8021X_EAP_TLS:
create8021xTls(props, deviceId, settings);
break;
default:
throw new IllegalArgumentException(
String.format("Security type 802-1x EAP \"%s\" is not supported.", eap));
case KURA_8021X_EAP_TTLS:
create8021xTunneledTls(props, deviceId, settings);
break;
case KURA_8021X_EAP_PEAP:
create8021xProtectedEap(props, deviceId, settings);
break;
case KURA_8021X_EAP_TLS:
create8021xTls(props, deviceId, settings);
break;
default:
throw new IllegalArgumentException(String.format("Security type 802-1x EAP \"%s\" is not supported.", eap));
}

if (!phase2.isPresent()) {
return settings;
}

switch (Kura8021xInnerAuth.fromString(phase2.get())) {
case KURA_8021X_INNER_AUTH_NONE:
break;
case KURA_8021X_INNER_AUTH_MSCHAPV2:
create8021xMschapV2(props, deviceId, settings);
break;
default:
throw new IllegalArgumentException(
String.format("Security type 802-1x InnerAuth (Phase2) \"%s\" is not supported.", phase2));
case KURA_8021X_INNER_AUTH_NONE:
break;
case KURA_8021X_INNER_AUTH_MSCHAPV2:
create8021xMschapV2(props, deviceId, settings);
break;
default:
throw new IllegalArgumentException(
String.format("Security type 802-1x InnerAuth (Phase2) \"%s\" is not supported.", phase2));
}

return settings;
Expand Down Expand Up @@ -386,8 +385,7 @@ private static void configureIp6Mtu(NetworkProperties props, String deviceId, Se
}

private static void configureIp6Wan(NetworkProperties props, String deviceId, Map<String, Variant<?>> settings) {
Optional<List<String>> dnsServers = props.getOptStringList("net.interface.%s.config.ip6.dnsServers",
deviceId);
Optional<List<String>> dnsServers = props.getOptStringList("net.interface.%s.config.ip6.dnsServers", deviceId);

dnsServers.ifPresent(value -> {
settings.put("dns", new Variant<>(convertIp6(value), "aay"));
Expand Down Expand Up @@ -429,14 +427,14 @@ private static void configureIp6MethodAuto(NetworkProperties props, String devic
Map<String, Variant<?>> settings) {
settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("auto"));

Optional<String> addressGenerationMode = props.getOpt(String.class,
"net.interface.%s.config.ip6.addr.gen.mode", deviceId);
Optional<String> addressGenerationMode = props.getOpt(String.class, "net.interface.%s.config.ip6.addr.gen.mode",
deviceId);

addressGenerationMode.ifPresent(value -> {
KuraIp6AddressGenerationMode ipv6AddressGenerationMode = KuraIp6AddressGenerationMode
.fromString(addressGenerationMode.get());
settings.put("addr-gen-mode", new Variant<>(KuraIp6AddressGenerationMode
.toNMSettingIP6ConfigAddrGenMode(ipv6AddressGenerationMode).toInt32()));
settings.put("addr-gen-mode", new Variant<>(
KuraIp6AddressGenerationMode.toNMSettingIP6ConfigAddrGenMode(ipv6AddressGenerationMode).toInt32()));
});

Optional<String> privacy = props.getOpt(String.class, "net.interface.%s.config.ip6.privacy", deviceId);
Expand All @@ -454,8 +452,7 @@ private static KuraIp6ConfigurationMethod getIp6ConfigMethod(NetworkProperties p
ip6ConfigMethod = KuraIp6ConfigurationMethod
.fromString(props.get(String.class, "net.interface.%s.config.ip6.address.method", deviceId));
} catch (NoSuchElementException e) {
logger.warn("IPv6 address method property not found. Using default value: {}",
ip6ConfigMethod);
logger.warn("IPv6 address method property not found. Using default value: {}", ip6ConfigMethod);
}
return ip6ConfigMethod;
}
Expand All @@ -471,8 +468,12 @@ public static Map<String, Variant<?>> build80211WirelessSettings(NetworkProperti
String ssid = props.get(String.class, "net.interface.%s.config.wifi.%s.ssid", deviceId, propMode.toLowerCase());
settings.put("ssid", new Variant<>(ssid.getBytes(StandardCharsets.UTF_8)));

short channel = Short.parseShort(
props.get(String.class, "net.interface.%s.config.wifi.%s.channel", deviceId, propMode.toLowerCase()));
short channel = 0;
Optional<String> optionalChannel = props.getOpt(String.class, "net.interface.%s.config.wifi.%s.channel",
deviceId, propMode.toLowerCase());
if (optionalChannel.isPresent()) {
channel = Short.parseShort(optionalChannel.get());
}
settings.put("channel", new Variant<>(new UInt32(channel)));

Optional<String> band = wifiBandConvert(
Expand All @@ -496,17 +497,16 @@ public static Map<String, Variant<?>> build80211WirelessSecuritySettings(Network
props.get(String.class, KURA_PROPS_KEY_WIFI_SECURITY_TYPE, deviceId, propMode.toLowerCase()));

switch (securityType) {
case SECURITY_WEP:
return createWEPSettings(props, deviceId, propMode);
case SECURITY_WPA:
case SECURITY_WPA2:
case SECURITY_WPA_WPA2:
return createWPAWPA2Settings(props, deviceId, propMode);
case SECURITY_WPA2_WPA3_ENTERPRISE:
return createWPA2WPA3EnterpriseSettings();
default:
throw new IllegalArgumentException(
String.format("Security type \"%s\" is not supported.", securityType));
case SECURITY_WEP:
return createWEPSettings(props, deviceId, propMode);
case SECURITY_WPA:
case SECURITY_WPA2:
case SECURITY_WPA_WPA2:
return createWPAWPA2Settings(props, deviceId, propMode);
case SECURITY_WPA2_WPA3_ENTERPRISE:
return createWPA2WPA3EnterpriseSettings();
default:
throw new IllegalArgumentException(String.format("Security type \"%s\" is not supported.", securityType));
}
}

Expand Down Expand Up @@ -753,12 +753,12 @@ private static List<Byte> convertIp6(String ipAddrString) throws UnknownHostExce

private static String wifiModeConvert(String kuraMode) {
switch (kuraMode) {
case "INFRA":
return "infrastructure";
case "MASTER":
return "ap";
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi mode \"%s\"", kuraMode));
case "INFRA":
return "infrastructure";
case "MASTER":
return "ap";
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi mode \"%s\"", kuraMode));
}
}

Expand All @@ -779,58 +779,57 @@ private static Optional<String> wifiBandConvert(String kuraBand, short channel)
}

switch (kuraBand) {
case "RADIO_MODE_80211a":
case "RADIO_MODE_80211_AC":
return Optional.of("a");
case "RADIO_MODE_80211b":
case "RADIO_MODE_80211g":
return Optional.of("bg");
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi band \"%s\"", kuraBand));
case "RADIO_MODE_80211a":
case "RADIO_MODE_80211_AC":
return Optional.of("a");
case "RADIO_MODE_80211b":
case "RADIO_MODE_80211g":
return Optional.of("bg");
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi band \"%s\"", kuraBand));
}
}

private static List<String> wifiCipherConvert(String kuraCipher) {
switch (kuraCipher) {
case "CCMP":
return Arrays.asList("ccmp");
case "TKIP":
return Arrays.asList("tkip");
case "CCMP_TKIP":
return Arrays.asList("tkip", "ccmp");
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi cipher \"%s\"", kuraCipher));
case "CCMP":
return Arrays.asList("ccmp");
case "TKIP":
return Arrays.asList("tkip");
case "CCMP_TKIP":
return Arrays.asList("tkip", "ccmp");
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi cipher \"%s\"", kuraCipher));
}
}

private static List<String> wifiProtoConvert(KuraWifiSecurityType securityType) {
switch (securityType) {
case SECURITY_WPA:
return Arrays.asList("wpa");
case SECURITY_WPA2:
return Arrays.asList("rsn");
case SECURITY_WPA_WPA2:
return Arrays.asList();
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi proto \"%s\"", securityType));
case SECURITY_WPA:
return Arrays.asList("wpa");
case SECURITY_WPA2:
return Arrays.asList("rsn");
case SECURITY_WPA_WPA2:
return Arrays.asList();
default:
throw new IllegalArgumentException(String.format("Unsupported WiFi proto \"%s\"", securityType));
}
}

private static String connectionTypeConvert(NMDeviceType deviceType) {
switch (deviceType) {
case NM_DEVICE_TYPE_ETHERNET:
return "802-3-ethernet";
case NM_DEVICE_TYPE_WIFI:
return "802-11-wireless";
case NM_DEVICE_TYPE_MODEM:
return "gsm";
case NM_DEVICE_TYPE_VLAN:
return "vlan";
// ... WIP
default:
throw new IllegalArgumentException(String
.format("Unsupported connection type conversion from NMDeviceType \"%s\"",
deviceType.toString()));
case NM_DEVICE_TYPE_ETHERNET:
return "802-3-ethernet";
case NM_DEVICE_TYPE_WIFI:
return "802-11-wireless";
case NM_DEVICE_TYPE_MODEM:
return "gsm";
case NM_DEVICE_TYPE_VLAN:
return "vlan";
// ... WIP
default:
throw new IllegalArgumentException(String
.format("Unsupported connection type conversion from NMDeviceType \"%s\"", deviceType.toString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,5 @@ private boolean isNetworkConfigurationPid(String pid) {
}
return result;
}

}
Loading