use of org.eclipse.kura.net.dhcp.DhcpServerConfig4 in project kura by eclipse.
the class WifiMonitorServiceImpl method enableInterface.
private void enableInterface(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig) throws KuraException {
s_logger.debug("enableInterface: {}", netInterfaceConfig);
WifiInterfaceConfigImpl wifiInterfaceConfig = null;
if (netInterfaceConfig instanceof WifiInterfaceConfigImpl) {
wifiInterfaceConfig = (WifiInterfaceConfigImpl) netInterfaceConfig;
} else {
return;
}
String interfaceName = wifiInterfaceConfig.getName();
WifiMode wifiMode = WifiMode.UNKNOWN;
NetInterfaceStatus status = NetInterfaceStatus.netIPv4StatusUnknown;
boolean isDhcpClient = false;
boolean enableDhcpServer = false;
if (wifiInterfaceConfig != null) {
for (WifiInterfaceAddressConfig wifiInterfaceAddressConfig : wifiInterfaceConfig.getNetInterfaceAddresses()) {
wifiMode = wifiInterfaceAddressConfig.getMode();
for (NetConfig netConfig : wifiInterfaceAddressConfig.getConfigs()) {
if (netConfig instanceof NetConfigIP4) {
status = ((NetConfigIP4) netConfig).getStatus();
isDhcpClient = ((NetConfigIP4) netConfig).isDhcp();
} else if (netConfig instanceof DhcpServerConfig4) {
enableDhcpServer = ((DhcpServerConfig4) netConfig).isEnabled();
}
}
}
}
if (status.equals(NetInterfaceStatus.netIPv4StatusEnabledLAN) || status.equals(NetInterfaceStatus.netIPv4StatusEnabledWAN)) {
if (wifiMode.equals(WifiMode.INFRA) || wifiMode.equals(WifiMode.MASTER)) {
this.m_netAdminService.enableInterface(interfaceName, isDhcpClient);
if (enableDhcpServer) {
this.m_netAdminService.manageDhcpServer(interfaceName, true);
}
}
}
}
use of org.eclipse.kura.net.dhcp.DhcpServerConfig4 in project kura by eclipse.
the class DhcpConfigReader method getConfig.
private void getConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig, Properties kuraExtendedProps) throws KuraException {
String interfaceName = netInterfaceConfig.getName();
s_logger.debug("Getting DHCP server config for {}", interfaceName);
NetInterfaceType type = netInterfaceConfig.getType();
if (type == NetInterfaceType.ETHERNET || type == NetInterfaceType.WIFI) {
// StringBuffer configFilename = new
// StringBuffer(FILE_DIR).append("dhcpd-").append(interfaceName).append(".conf");
String configFilename = DhcpServerManager.getConfigFilename(interfaceName);
File dhcpConfigFile = new File(configFilename);
if (dhcpConfigFile.exists()) {
DhcpServerConfig4 dhcpServerConfig4 = populateConfig(interfaceName, dhcpConfigFile, kuraExtendedProps);
if (dhcpServerConfig4 != null) {
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
if (netInterfaceAddressConfigs == null) {
throw KuraException.internalError("NetInterfaceAddress list is null for interface " + interfaceName);
} else if (netInterfaceAddressConfigs.size() == 0) {
throw KuraException.internalError("NetInterfaceAddress list is empty for interface " + interfaceName);
}
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
if (netConfigs == null) {
netConfigs = new ArrayList<NetConfig>();
if (netInterfaceAddressConfig instanceof NetInterfaceAddressConfigImpl) {
((NetInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(netConfigs);
} else if (netInterfaceAddressConfig instanceof WifiInterfaceAddressConfigImpl) {
((WifiInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(netConfigs);
}
}
netConfigs.add(dhcpServerConfig4);
}
}
} else {
s_logger.debug("There is no current DHCP server configuration for {}", interfaceName);
}
}
}
use of org.eclipse.kura.net.dhcp.DhcpServerConfig4 in project kura by eclipse.
the class DhcpConfigReader method populateConfig.
private DhcpServerConfig4 populateConfig(String interfaceName, File dhcpConfigFile, Properties kuraExtendedProps) throws KuraException {
DhcpServerConfig4 dhcpServerConfig4 = null;
DhcpServerTool dhcpServerTool = DhcpServerManager.getTool();
if (dhcpServerTool == DhcpServerTool.DHCPD) {
dhcpServerConfig4 = populateDhcpdConfig(interfaceName, dhcpConfigFile, kuraExtendedProps);
} else if (dhcpServerTool == DhcpServerTool.UDHCPD) {
dhcpServerConfig4 = populateUdhcpdConfig(interfaceName, dhcpConfigFile, kuraExtendedProps);
}
return dhcpServerConfig4;
}
use of org.eclipse.kura.net.dhcp.DhcpServerConfig4 in project kura by eclipse.
the class DhcpConfigWriter method writeKuraExtendedConfig.
private void writeKuraExtendedConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig, Properties kuraExtendedProps) throws KuraException {
boolean enabled = false;
boolean passDns = false;
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = null;
if (netInterfaceConfig instanceof EthernetInterfaceConfigImpl) {
netInterfaceAddressConfigs = ((EthernetInterfaceConfigImpl) netInterfaceConfig).getNetInterfaceAddresses();
} else if (netInterfaceConfig instanceof WifiInterfaceConfigImpl) {
netInterfaceAddressConfigs = ((WifiInterfaceConfigImpl) netInterfaceConfig).getNetInterfaceAddresses();
} else {
s_logger.error("not adding config for " + netInterfaceConfig.getName());
}
if (netInterfaceAddressConfigs != null && netInterfaceAddressConfigs.size() > 0) {
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
if (netConfigs != null && netConfigs.size() > 0) {
for (int i = 0; i < netConfigs.size(); i++) {
NetConfig netConfig = netConfigs.get(i);
if (netConfig instanceof DhcpServerConfig4) {
enabled = ((DhcpServerConfig4) netConfig).isEnabled();
passDns = ((DhcpServerConfig4) netConfig).isPassDns();
}
}
}
}
}
// set it all
if (kuraExtendedProps == null) {
s_logger.debug("kuraExtendedProps was null");
kuraExtendedProps = new Properties();
}
StringBuilder sb = new StringBuilder().append("net.interface.").append(netInterfaceConfig.getName()).append(".config.dhcpServer4.enabled");
kuraExtendedProps.put(sb.toString(), Boolean.toString(enabled));
sb = new StringBuilder().append("net.interface.").append(netInterfaceConfig.getName()).append(".config.dhcpServer4.passDns");
kuraExtendedProps.put(sb.toString(), Boolean.toString(passDns));
// write it
if (kuraExtendedProps != null && !kuraExtendedProps.isEmpty()) {
try {
KuranetConfig.storeProperties(kuraExtendedProps);
} catch (Exception e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
}
use of org.eclipse.kura.net.dhcp.DhcpServerConfig4 in project kura by eclipse.
the class DhcpConfigWriter method writeConfig.
/*
* private void writeConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig) throws
* KuraException {
* DhcpServerTool dhcpServerTool = DhcpServerManager.getTool();
* if (dhcpServerTool == DhcpServerTool.DHCPD) {
* writeDhcpdConfig(netInterfaceConfig);
* } else if (dhcpServerTool == DhcpServerTool.DHCPD) {
* writeUdhcpdConfig(netInterfaceConfig);
* }
* }
*/
private void writeConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig) throws KuraException {
String interfaceName = netInterfaceConfig.getName();
/*
* String dhcpConfigFileName = new
* StringBuffer().append(FILE_DIR).append("dhcpd-").append(interfaceName).append(".conf").toString();
* String tmpDhcpConfigFileName = new
* StringBuffer().append(FILE_DIR).append("dhcpd-").append(interfaceName).append(".conf").append(".tmp").
* toString();
*/
String dhcpConfigFileName = DhcpServerManager.getConfigFilename(interfaceName);
String tmpDhcpConfigFileName = new StringBuilder(dhcpConfigFileName).append(".tmp").toString();
s_logger.debug("Writing DHCP config for {}", interfaceName);
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
if (netInterfaceAddressConfigs != null && netInterfaceAddressConfigs.size() > 0) {
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
if (netConfigs != null) {
for (NetConfig netConfig : netConfigs) {
if (netConfig instanceof DhcpServerConfig4) {
DhcpServerConfig4 dhcpServerConfig = (DhcpServerConfig4) netConfig;
writeConfigFile(tmpDhcpConfigFileName, interfaceName, dhcpServerConfig);
// move the file if we made it this far and they are different
File tmpDhcpConfigFile = new File(tmpDhcpConfigFileName);
File dhcpConfigFile = new File(dhcpConfigFileName);
try {
if (!FileUtils.contentEquals(tmpDhcpConfigFile, dhcpConfigFile)) {
if (tmpDhcpConfigFile.renameTo(dhcpConfigFile)) {
s_logger.trace("Successfully wrote DHCP config file");
} else {
s_logger.error("Failed to write DHCP config file for " + interfaceName);
throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, "error while building up new configuration files for dhcp server: " + interfaceName);
}
} else {
s_logger.info("Not rewriting DHCP config file for " + interfaceName + " because it is the same");
}
} catch (IOException e) {
throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, "error while building up new configuration files for dhcp servers", e);
}
}
}
}
}
}
}
Aggregations