Search in sources :

Example 1 with NetInterfaceAddressConfigImpl

use of org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl 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);
        }
    }
}
Also used : NetInterfaceAddressConfigImpl(org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) NetConfig(org.eclipse.kura.net.NetConfig) DhcpServerConfig4(org.eclipse.kura.net.dhcp.DhcpServerConfig4) File(java.io.File) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) WifiInterfaceAddressConfigImpl(org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl)

Example 2 with NetInterfaceAddressConfigImpl

use of org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl in project kura by eclipse.

the class FirewallAutoNatConfigReader method getConfig.

private void getConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig, Properties kuraProps) throws KuraException {
    String interfaceName = netInterfaceConfig.getName();
    NetInterfaceType type = netInterfaceConfig.getType();
    if (type == NetInterfaceType.ETHERNET || type == NetInterfaceType.WIFI) {
        s_logger.debug("Getting NAT config for {}", interfaceName);
        if (kuraProps != null) {
            s_logger.debug("Getting NAT config from kuraProps");
            boolean natEnabled = false;
            boolean useMasquerade = false;
            String prop = null;
            String srcIface = null;
            String dstIface = null;
            StringBuilder sb = new StringBuilder().append("net.interface.").append(interfaceName).append(".config.nat.enabled");
            if ((prop = kuraProps.getProperty(sb.toString())) != null) {
                natEnabled = Boolean.parseBoolean(prop);
            }
            sb = new StringBuilder().append("net.interface.").append(interfaceName).append(".config.nat.masquerade");
            if ((prop = kuraProps.getProperty(sb.toString())) != null) {
                useMasquerade = Boolean.parseBoolean(prop);
            }
            sb = new StringBuilder().append("net.interface.").append(interfaceName).append(".config.nat.src.interface");
            if ((prop = kuraProps.getProperty(sb.toString())) != null) {
                srcIface = prop;
            }
            sb = new StringBuilder().append("net.interface.").append(interfaceName).append(".config.nat.dst.interface");
            if ((prop = kuraProps.getProperty(sb.toString())) != null) {
                dstIface = prop;
            }
            if (natEnabled) {
                FirewallAutoNatConfig natConfig = new FirewallAutoNatConfig(srcIface, dstIface, useMasquerade);
                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(natConfig);
                }
            }
        } else {
            // get it from the firewall file if possible
            LinuxFirewall firewall = LinuxFirewall.getInstance();
            Set<NATRule> natRules = firewall.getAutoNatRules();
            if (natRules != null && !natRules.isEmpty()) {
                Iterator<NATRule> it = natRules.iterator();
                while (it.hasNext()) {
                    NATRule rule = it.next();
                    if (rule.getSourceInterface().equals(interfaceName)) {
                        s_logger.debug("found NAT rule: {}", rule);
                        // this is the one we care about
                        FirewallAutoNatConfig natConfig = new FirewallAutoNatConfig(rule.getSourceInterface(), rule.getDestinationInterface(), rule.isMasquerade());
                        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(natConfig);
                        }
                    }
                }
            }
        }
    }
}
Also used : NetInterfaceAddressConfigImpl(org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl) FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) LinuxFirewall(org.eclipse.kura.linux.net.iptables.LinuxFirewall) NATRule(org.eclipse.kura.linux.net.iptables.NATRule) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) NetConfig(org.eclipse.kura.net.NetConfig) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) WifiInterfaceAddressConfigImpl(org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl)

Example 3 with NetInterfaceAddressConfigImpl

use of org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl in project kura by eclipse.

the class GenericNetworkInterface method getCurrentConfig.

protected static NetInterfaceConfig<?> getCurrentConfig(String interfaceName, NetInterfaceType type, NetInterfaceStatus status, boolean dhcpServerEnabled, boolean passDns, Properties kuraProps) throws KuraException {
    try {
        NetInterfaceConfig<?> netInterfaceConfig = null;
        boolean autoConnect = false;
        int mtu = -1;
        boolean dhcp = false;
        IP4Address address = null;
        String ipAddress = null;
        String prefixString = null;
        String netmask = null;
        String gateway = null;
        boolean interfaceEnabled = false;
        if (kuraProps != null) {
            String onBoot = kuraProps.getProperty("ONBOOT");
            if ("yes".equals(onBoot)) {
                autoConnect = true;
                // we are enabled - just not sure if for LAN or WAN
                if (status == NetInterfaceStatus.netIPv4StatusUnknown) {
                    interfaceEnabled = true;
                }
            } else {
                autoConnect = false;
            }
            // override MTU with what is in config if it is present
            String stringMtu = kuraProps.getProperty("MTU");
            if (stringMtu == null) {
                try {
                    mtu = LinuxNetworkUtil.getCurrentMtu(interfaceName);
                } catch (KuraException e) {
                    // just assume ???
                    if (interfaceName.equals("lo")) {
                        mtu = 16436;
                    } else {
                        mtu = 1500;
                    }
                }
            } else {
                mtu = Short.parseShort(stringMtu);
            }
            // get the bootproto
            String bootproto = kuraProps.getProperty("BOOTPROTO");
            if (bootproto == null) {
                bootproto = "static";
            }
            // get the defroute
            String defroute = kuraProps.getProperty("DEFROUTE");
            if (defroute == null) {
                defroute = "no";
            }
            if (interfaceEnabled) {
                if (defroute.equals("yes")) {
                    status = NetInterfaceStatus.netIPv4StatusEnabledWAN;
                } else {
                    status = NetInterfaceStatus.netIPv4StatusEnabledLAN;
                }
            }
            // check for dhcp or static configuration
            try {
                ipAddress = kuraProps.getProperty("IPADDR");
                prefixString = kuraProps.getProperty("PREFIX");
                netmask = kuraProps.getProperty("NETMASK");
                kuraProps.getProperty("BROADCAST");
                try {
                    gateway = kuraProps.getProperty("GATEWAY");
                    s_logger.debug("got gateway for {}: {}", interfaceName, gateway);
                } catch (Exception e) {
                    s_logger.warn("missing gateway stanza for " + interfaceName);
                }
                if (bootproto.equals("dhcp")) {
                    s_logger.debug("currently set for DHCP");
                    dhcp = true;
                    ipAddress = null;
                    netmask = null;
                } else {
                    s_logger.debug("currently set for static address");
                    dhcp = false;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "malformatted config file: " + NET_CONFIGURATION_DIRECTORY + "ifcfg-" + interfaceName);
            }
            if (ipAddress != null && !ipAddress.isEmpty()) {
                address = (IP4Address) IPAddress.parseHostAddress(ipAddress);
            }
            // make sure at least prefix or netmask is present if static
            if (!dhcp && prefixString == null && netmask == null) {
                throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "malformatted config file: " + NET_CONFIGURATION_DIRECTORY + "ifcfg-" + interfaceName + " must contain NETMASK and/or PREFIX");
            }
        }
        ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
        LinuxDns dnsService = LinuxDns.getInstance();
        // note - we only add the fields we need/care about from a configuration standpoint
        if (type == NetInterfaceType.LOOPBACK) {
            s_logger.debug("Adding a Loopback interface");
            netInterfaceConfig = new LoopbackInterfaceConfigImpl(interfaceName);
            ((LoopbackInterfaceImpl<?>) netInterfaceConfig).setMTU(mtu);
            // loopback autoConnect
            ((LoopbackInterfaceImpl<?>) netInterfaceConfig).setAutoConnect(true);
            // should always be true?
            ((LoopbackInterfaceImpl<?>) netInterfaceConfig).setLoopback(true);
            List<NetInterfaceAddressConfig> netInterfaceAddressConfigs = new ArrayList<NetInterfaceAddressConfig>();
            List<NetInterfaceAddress> netInterfaceAddresses = new ArrayList<NetInterfaceAddress>();
            NetInterfaceAddressConfigImpl netInterfaceAddressConfig = new NetInterfaceAddressConfigImpl();
            netInterfaceAddressConfigs.add(netInterfaceAddressConfig);
            netInterfaceAddresses.add(netInterfaceAddressConfig);
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null && ifconfig.isUp()) {
                netInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                netInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                netInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(ifconfig.getInetMask()));
                netInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(ifconfig.getInetMask()));
                netInterfaceAddressConfig.setGateway(conInfo.getGateway());
                if (dhcp) {
                    netInterfaceAddressConfig.setDnsServers(dnsService.getDhcpDnsServers(interfaceName, netInterfaceAddressConfig.getAddress()));
                } else {
                    netInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
                }
            }
            ((LoopbackInterfaceConfigImpl) netInterfaceConfig).setNetInterfaceAddresses(netInterfaceAddressConfigs);
            List<NetConfig> netConfigs = new ArrayList<NetConfig>();
            netInterfaceAddressConfig.setNetConfigs(netConfigs);
            // FIXME - hardcoded
            NetConfig netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusEnabledLAN, true);
            ((NetConfigIP4) netConfig).setAddress(address);
            ((NetConfigIP4) netConfig).setDhcp(dhcp);
            ((NetConfigIP4) netConfig).setDnsServers(null);
            ((NetConfigIP4) netConfig).setDomains(null);
            ((NetConfigIP4) netConfig).setGateway(null);
            ((NetConfigIP4) netConfig).setNetworkPrefixLength((short) 8);
            ((NetConfigIP4) netConfig).setSubnetMask((IP4Address) IPAddress.parseHostAddress("255.0.0.0"));
            ((NetConfigIP4) netConfig).setWinsServers(null);
            netConfigs.add(netConfig);
        } else if (type == NetInterfaceType.ETHERNET) {
            s_logger.debug("Adding an Ethernet interface - {}", interfaceName);
            netInterfaceConfig = new EthernetInterfaceConfigImpl(interfaceName);
            ((EthernetInterfaceImpl<?>) netInterfaceConfig).setMTU(mtu);
            ((EthernetInterfaceImpl<?>) netInterfaceConfig).setAutoConnect(autoConnect);
            ((EthernetInterfaceImpl<?>) netInterfaceConfig).setLoopback(false);
            List<NetInterfaceAddressConfig> netInterfaceAddressConfigs = new ArrayList<NetInterfaceAddressConfig>();
            List<NetInterfaceAddress> netInterfaceAddresses = new ArrayList<NetInterfaceAddress>();
            NetInterfaceAddressConfigImpl netInterfaceAddressConfig = new NetInterfaceAddressConfigImpl();
            netInterfaceAddressConfigs.add(netInterfaceAddressConfig);
            netInterfaceAddresses.add(netInterfaceAddressConfig);
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                ((EthernetInterfaceImpl<?>) netInterfaceConfig).setHardwareAddress(ifconfig.getMacAddressBytes());
                if (ifconfig.isUp()) {
                    try {
                        netInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                        netInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                        netInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(ifconfig.getInetMask()));
                        netInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(ifconfig.getInetMask()));
                        netInterfaceAddressConfig.setGateway(conInfo.getGateway());
                        if (dhcp) {
                            netInterfaceAddressConfig.setDnsServers(dnsService.getDhcpDnsServers(interfaceName, netInterfaceAddressConfig.getAddress()));
                        } else {
                            netInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
                        }
                    } catch (KuraException e) {
                        s_logger.warn("The interface went down " + interfaceName + " not including current state in status because it is not up");
                        netInterfaceAddressConfig.setAddress(null);
                        netInterfaceAddressConfig.setBroadcast(null);
                        netInterfaceAddressConfig.setNetmask(null);
                        netInterfaceAddressConfig.setNetworkPrefixLength((short) -1);
                        netInterfaceAddressConfig.setGateway(null);
                        netInterfaceAddressConfig.setDnsServers(null);
                    }
                }
            }
            ((EthernetInterfaceConfigImpl) netInterfaceConfig).setNetInterfaceAddresses(netInterfaceAddressConfigs);
            // add the config
            List<NetConfig> netConfigs = new ArrayList<NetConfig>();
            netInterfaceAddressConfig.setNetConfigs(netConfigs);
            NetConfigIP4 netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusDisabled, autoConnect);
            setNetConfigIP4(netConfig, status, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
            netConfigs.add(netConfig);
            if (dhcpServerEnabled) {
                // add DHCP server configuration to the list
                DhcpServerImpl dhcpServer = DhcpServerFactory.getInstance(interfaceName, dhcpServerEnabled, passDns);
                DhcpServerConfig4 dhcpServerConfig = dhcpServer.getDhcpServerConfig(dhcpServerEnabled, passDns);
                if (dhcpServerConfig != null) {
                    netConfigs.add(dhcpServerConfig);
                }
            }
        } else if (type == NetInterfaceType.WIFI) {
            s_logger.debug("Adding a Wireless interface - {}", interfaceName);
            WifiInterfaceConfigImpl wifiInterfaceConfig = new WifiInterfaceConfigImpl(interfaceName);
            netInterfaceConfig = wifiInterfaceConfig;
            wifiInterfaceConfig.setMTU(mtu);
            wifiInterfaceConfig.setAutoConnect(autoConnect);
            wifiInterfaceConfig.setLoopback(false);
            List<WifiInterfaceAddressConfig> wifiInterfaceAddressConfigs = new ArrayList<WifiInterfaceAddressConfig>();
            List<WifiInterfaceAddress> wifiInterfaceAddresses = new ArrayList<WifiInterfaceAddress>();
            WifiInterfaceAddressConfigImpl wifiInterfaceAddressConfig = new WifiInterfaceAddressConfigImpl();
            wifiInterfaceAddressConfigs.add(wifiInterfaceAddressConfig);
            wifiInterfaceAddresses.add(wifiInterfaceAddressConfig);
            String currentSSID = LinuxNetworkUtil.getSSID(interfaceName);
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                wifiInterfaceConfig.setHardwareAddress(ifconfig.getMacAddressBytes());
                if (ifconfig.isUp()) {
                    wifiInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                    wifiInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                    String currentNetmask = ifconfig.getInetMask();
                    if (currentNetmask != null) {
                        wifiInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(currentNetmask));
                        wifiInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
                    }
                    wifiInterfaceAddressConfig.setBitrate(LinuxNetworkUtil.getWifiBitrate(interfaceName));
                    wifiInterfaceAddressConfig.setGateway(conInfo.getGateway());
                    if (dhcp) {
                        wifiInterfaceAddressConfig.setDnsServers(dnsService.getDhcpDnsServers(interfaceName, wifiInterfaceAddressConfig.getAddress()));
                    } else {
                        wifiInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
                    }
                    WifiAccessPointImpl ap = null;
                    if (currentSSID != null) {
                        s_logger.debug("Adding access point SSID: {}", currentSSID);
                        ap = new WifiAccessPointImpl(currentSSID);
                        // TODO: fill in other info
                        ap.setMode(WifiMode.INFRA);
                        List<Long> bitrate = new ArrayList<Long>();
                        bitrate.add(54000000L);
                        ap.setBitrate(bitrate);
                        ap.setFrequency(12345);
                        ap.setHardwareAddress("20AA4B8A6442".getBytes());
                        ap.setRsnSecurity(EnumSet.allOf(WifiSecurity.class));
                        ap.setStrength(1234);
                        ap.setWpaSecurity(EnumSet.allOf(WifiSecurity.class));
                    }
                    wifiInterfaceAddressConfig.setWifiAccessPoint(ap);
                }
            }
            // mode
            WifiMode wifiMode = WifiMode.UNKNOWN;
            s_logger.debug("Get WifiMode...");
            try {
                // get from config file
                String mode = kuraProps.getProperty("MODE");
                if (mode != null) {
                    s_logger.debug("Getting wifi mode from {}", kuraFile.getAbsolutePath());
                    if (mode.equalsIgnoreCase("Managed")) {
                        wifiMode = WifiMode.INFRA;
                    } else if (mode.equalsIgnoreCase("Master")) {
                        wifiMode = WifiMode.MASTER;
                    } else if (mode.equalsIgnoreCase("Ad-Hoc")) {
                        wifiMode = WifiMode.ADHOC;
                    } else {
                        wifiMode = WifiMode.valueOf(mode);
                    }
                } else {
                    // get current setting using iwconfig
                    s_logger.debug("Getting wifi mode from iwconfig");
                    wifiMode = LinuxNetworkUtil.getWifiMode(interfaceName);
                }
            } catch (Exception e) {
            // leave as unknown
            }
            s_logger.debug("Current WifiMode: {}", wifiMode);
            wifiInterfaceAddressConfig.setMode(wifiMode);
            wifiInterfaceConfig.setNetInterfaceAddresses(wifiInterfaceAddressConfigs);
            // TODO: fix
            wifiInterfaceConfig.setCapabilities(EnumSet.allOf(Capability.class));
            // add the configs - one for client (managed) mode, one for access point (master) mode
            List<NetConfig> netConfigs = new ArrayList<NetConfig>();
            wifiInterfaceAddressConfig.setNetConfigs(netConfigs);
            // get the NetConfig
            NetConfigIP4 netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusDisabled, autoConnect);
            setNetConfigIP4(netConfig, status, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
            netConfigs.add(netConfig);
            // get the wpa_supplicant configuration
            WifiConfig wifiClientConfig = new WifiConfig();
            setWifiClientConfig(interfaceName, wifiClientConfig, wifiMode);
            // get the hostapd configuration
            WifiConfig wifiAPConfig = new WifiConfig();
            setWifiAccessPointConfig(wifiAPConfig);
            // add WiFi configurations to the list
            netConfigs.add(wifiClientConfig);
            netConfigs.add(wifiAPConfig);
            if (dhcpServerEnabled) {
                // add DHCP server configuration to the list
                DhcpServerImpl dhcpServer = DhcpServerFactory.getInstance(interfaceName, dhcpServerEnabled, passDns);
                DhcpServerConfig4 dhcpServerConfig = dhcpServer.getDhcpServerConfig(dhcpServerEnabled, passDns);
                if (dhcpServerConfig != null) {
                    netConfigs.add(dhcpServerConfig);
                }
            }
        } else if (type == NetInterfaceType.MODEM) {
            s_logger.debug("Adding a Modem interface");
            netInterfaceConfig = new ModemInterfaceConfigImpl(interfaceName);
            ((ModemInterfaceConfigImpl) netInterfaceConfig).setMTU(mtu);
            ((ModemInterfaceConfigImpl) netInterfaceConfig).setAutoConnect(autoConnect);
            ((ModemInterfaceConfigImpl) netInterfaceConfig).setLoopback(false);
            ((ModemInterfaceConfigImpl) netInterfaceConfig).setPointToPoint(true);
            List<ModemInterfaceAddressConfig> modemInterfaceAddressConfigs = new ArrayList<ModemInterfaceAddressConfig>();
            List<ModemInterfaceAddress> netInterfaceAddresses = new ArrayList<ModemInterfaceAddress>();
            ModemInterfaceAddressConfigImpl netInterfaceAddressConfig = new ModemInterfaceAddressConfigImpl();
            modemInterfaceAddressConfigs.add(netInterfaceAddressConfig);
            netInterfaceAddresses.add(netInterfaceAddressConfig);
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                ((ModemInterfaceConfigImpl) netInterfaceConfig).setHardwareAddress(ifconfig.getMacAddressBytes());
                if (ifconfig.isUp()) {
                    netInterfaceAddressConfig.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                    netInterfaceAddressConfig.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                    netInterfaceAddressConfig.setNetmask(IPAddress.parseHostAddress(ifconfig.getInetMask()));
                    netInterfaceAddressConfig.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(ifconfig.getInetMask()));
                    netInterfaceAddressConfig.setGateway(conInfo.getGateway());
                    netInterfaceAddressConfig.setDnsServers(conInfo.getDnsServers());
                }
            }
            ((ModemInterfaceConfigImpl) netInterfaceConfig).setNetInterfaceAddresses(modemInterfaceAddressConfigs);
            // add the config
            List<NetConfig> netConfigs = new ArrayList<NetConfig>();
            netInterfaceAddressConfig.setNetConfigs(netConfigs);
            NetConfigIP4 netConfig = new NetConfigIP4(NetInterfaceStatus.netIPv4StatusDisabled, autoConnect);
            setNetConfigIP4(netConfig, status, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
            netConfigs.add(netConfig);
        } else {
            s_logger.warn("Unsupported Type: " + type);
        }
        return netInterfaceConfig;
    } catch (UnknownHostException e) {
        throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : ModemInterfaceAddressConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceAddressConfigImpl) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) ArrayList(java.util.ArrayList) WifiInterfaceAddressConfig(org.eclipse.kura.net.wifi.WifiInterfaceAddressConfig) LinuxDns(org.eclipse.kura.linux.net.dns.LinuxDns) KuraException(org.eclipse.kura.KuraException) WifiMode(org.eclipse.kura.net.wifi.WifiMode) ModemInterfaceAddressConfig(org.eclipse.kura.net.modem.ModemInterfaceAddressConfig) ArrayList(java.util.ArrayList) List(java.util.List) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) WifiInterfaceAddressConfigImpl(org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl) Capability(org.eclipse.kura.net.wifi.WifiInterface.Capability) IP4Address(org.eclipse.kura.net.IP4Address) DhcpServerImpl(org.eclipse.kura.linux.net.dhcp.DhcpServerImpl) EthernetInterfaceConfigImpl(org.eclipse.kura.core.net.EthernetInterfaceConfigImpl) WifiAccessPointImpl(org.eclipse.kura.core.net.WifiAccessPointImpl) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) NetConfig(org.eclipse.kura.net.NetConfig) ConnectionInfo(org.eclipse.kura.net.ConnectionInfo) WifiInterfaceAddress(org.eclipse.kura.net.wifi.WifiInterfaceAddress) NetInterfaceAddressConfigImpl(org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) LoopbackInterfaceConfigImpl(org.eclipse.kura.core.net.LoopbackInterfaceConfigImpl) UnknownHostException(java.net.UnknownHostException) DhcpServerConfig4(org.eclipse.kura.net.dhcp.DhcpServerConfig4) KuraException(org.eclipse.kura.KuraException) UnknownHostException(java.net.UnknownHostException) WifiInterfaceConfigImpl(org.eclipse.kura.core.net.WifiInterfaceConfigImpl) LoopbackInterfaceImpl(org.eclipse.kura.core.net.LoopbackInterfaceImpl) ModemInterfaceConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceConfigImpl) WifiSecurity(org.eclipse.kura.net.wifi.WifiSecurity) ModemInterfaceAddress(org.eclipse.kura.net.modem.ModemInterfaceAddress) ConnectionInfoImpl(org.eclipse.kura.linux.net.ConnectionInfoImpl)

Example 4 with NetInterfaceAddressConfigImpl

use of org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl in project kura by eclipse.

the class IfcfgConfigReader method getConfig.

private void getConfig(NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig, Properties kuraExtendedProps) throws KuraException {
    String interfaceName = netInterfaceConfig.getName();
    s_logger.debug("Getting config for {}", interfaceName);
    NetInterfaceType type = netInterfaceConfig.getType();
    if (type == NetInterfaceType.ETHERNET || type == NetInterfaceType.WIFI || type == NetInterfaceType.LOOPBACK) {
        NetInterfaceStatus netInterfaceStatus = null;
        StringBuilder sb = new StringBuilder().append("net.interface.").append(netInterfaceConfig.getName()).append(".config.ip4.status");
        if (kuraExtendedProps != null && kuraExtendedProps.getProperty(sb.toString()) != null) {
            netInterfaceStatus = NetInterfaceStatus.valueOf(kuraExtendedProps.getProperty(sb.toString()));
        } else {
            netInterfaceStatus = NetInterfaceStatus.netIPv4StatusDisabled;
        }
        s_logger.debug("Setting NetInterfaceStatus to " + netInterfaceStatus + " for " + netInterfaceConfig.getName());
        boolean autoConnect = false;
        // int mtu = -1; // MTU is not currently used
        boolean dhcp = false;
        IP4Address address = null;
        String ipAddress = null;
        String prefixString = null;
        String netmask = null;
        String gateway = null;
        File ifcfgFile = null;
        if (OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion()) || OS_VERSION.equals(KuraConstants.Raspberry_Pi.getImageName()) || OS_VERSION.equals(KuraConstants.BeagleBone.getImageName()) || OS_VERSION.equals(KuraConstants.Intel_Edison.getImageName() + "_" + KuraConstants.Intel_Edison.getImageVersion() + "_" + KuraConstants.Intel_Edison.getTargetName()) || OS_VERSION.equals(KuraConstants.ReliaGATE_50_21_Ubuntu.getImageName() + "_" + KuraConstants.ReliaGATE_50_21_Ubuntu.getImageVersion())) {
            ifcfgFile = new File(DEBIAN_NET_CONFIGURATION_DIRECTORY + "interfaces");
        } else {
            ifcfgFile = new File(REDHAT_NET_CONFIGURATION_DIRECTORY + "ifcfg-" + interfaceName);
        }
        if (ifcfgFile.exists()) {
            Properties kuraProps;
            // found our match so load the properties
            if (OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion()) || OS_VERSION.equals(KuraConstants.Raspberry_Pi.getImageName()) || OS_VERSION.equals(KuraConstants.BeagleBone.getImageName()) || OS_VERSION.equals(KuraConstants.Intel_Edison.getImageName() + "_" + KuraConstants.Intel_Edison.getImageVersion() + "_" + KuraConstants.Intel_Edison.getTargetName()) || OS_VERSION.equals(KuraConstants.ReliaGATE_50_21_Ubuntu.getImageName() + "_" + KuraConstants.ReliaGATE_50_21_Ubuntu.getImageVersion())) {
                kuraProps = parseDebianConfigFile(ifcfgFile, interfaceName);
            } else {
                kuraProps = parseRedhatConfigFile(ifcfgFile, interfaceName);
            }
            if (kuraProps != null) {
                String onBoot = kuraProps.getProperty("ONBOOT");
                if ("yes".equals(onBoot)) {
                    s_logger.debug("Setting autoConnect to true");
                    autoConnect = true;
                } else {
                    s_logger.debug("Setting autoConnect to false");
                    autoConnect = false;
                }
                // override MTU with what is in config if it is present
                /*
                     * IAB: MTU is not currently used
                     * String stringMtu = kuraProps.getProperty("MTU");
                     * if (stringMtu == null) {
                     * try {
                     * mtu = LinuxNetworkUtil.getCurrentMtu(interfaceName);
                     * } catch (KuraException e) {
                     * // just assume ???
                     * if (interfaceName.equals("lo")) {
                     * mtu = 16436;
                     * } else {
                     * mtu = 1500;
                     * }
                     * }
                     * } else {
                     * mtu = Short.parseShort(stringMtu);
                     * }
                     */
                // get the bootproto
                String bootproto = kuraProps.getProperty("BOOTPROTO");
                if (bootproto == null) {
                    bootproto = "static";
                }
                // get the defroute
                String defroute = kuraProps.getProperty("DEFROUTE");
                if (defroute == null) {
                    defroute = "no";
                }
                // actual properties
                if (netInterfaceStatus == NetInterfaceStatus.netIPv4StatusDisabled) {
                    if (autoConnect) {
                        if (defroute.equals("no")) {
                            netInterfaceStatus = NetInterfaceStatus.netIPv4StatusEnabledLAN;
                        } else {
                            netInterfaceStatus = NetInterfaceStatus.netIPv4StatusEnabledWAN;
                        }
                    }
                }
                // check for dhcp or static configuration
                try {
                    ipAddress = kuraProps.getProperty("IPADDR");
                    prefixString = kuraProps.getProperty("PREFIX");
                    netmask = kuraProps.getProperty("NETMASK");
                    kuraProps.getProperty("BROADCAST");
                    try {
                        gateway = kuraProps.getProperty("GATEWAY");
                        s_logger.debug("got gateway for " + interfaceName + ": " + gateway);
                    } catch (Exception e) {
                        s_logger.warn("missing gateway stanza for " + interfaceName);
                    }
                    if (bootproto.equals("dhcp")) {
                        s_logger.debug("currently set for DHCP");
                        dhcp = true;
                        ipAddress = null;
                        netmask = null;
                    } else {
                        s_logger.debug("currently set for static address");
                        dhcp = false;
                    }
                } catch (Exception e) {
                    throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "malformatted config file: " + ifcfgFile.toString(), e);
                }
                if (ipAddress != null && !ipAddress.isEmpty()) {
                    try {
                        address = (IP4Address) IPAddress.parseHostAddress(ipAddress);
                    } catch (UnknownHostException e) {
                        s_logger.warn("Error parsing address: " + ipAddress, e);
                    }
                }
                // make sure at least prefix or netmask is present if static
                if (autoConnect && !dhcp && prefixString == null && netmask == null) {
                    throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "malformatted config file: " + ifcfgFile.toString() + " must contain NETMASK and/or PREFIX");
                }
            }
            List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
            if (netInterfaceAddressConfigs == null) {
                throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "InterfaceAddressConfig list is null");
            } else if (netInterfaceAddressConfigs.size() == 0) {
                throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "InterfaceAddressConfig list has no entries");
            }
            for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
                List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
                if (netConfigs == null) {
                    netConfigs = new ArrayList<NetConfig>();
                    if (netInterfaceAddressConfig instanceof NetInterfaceAddressConfigImpl) {
                        ((NetInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(netConfigs);
                        if (dhcp) {
                            // Replace with DNS provided by DHCP server
                            // (displayed as read-only in Denali)
                            List<? extends IPAddress> dhcpDnsServers = getDhcpDnsServers(interfaceName, netInterfaceAddressConfig.getAddress());
                            if (dhcpDnsServers != null) {
                                ((NetInterfaceAddressConfigImpl) netInterfaceAddressConfig).setDnsServers(dhcpDnsServers);
                            }
                        }
                    } else if (netInterfaceAddressConfig instanceof WifiInterfaceAddressConfigImpl) {
                        ((WifiInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(netConfigs);
                        if (dhcp) {
                            // Replace with DNS provided by DHCP server
                            // (displayed as read-only in Denali)
                            List<? extends IPAddress> dhcpDnsServers = getDhcpDnsServers(interfaceName, netInterfaceAddressConfig.getAddress());
                            if (dhcpDnsServers != null) {
                                ((WifiInterfaceAddressConfigImpl) netInterfaceAddressConfig).setDnsServers(dhcpDnsServers);
                            }
                        }
                    }
                }
                NetConfigIP4 netConfig = new NetConfigIP4(netInterfaceStatus, autoConnect);
                setNetConfigIP4(netConfig, autoConnect, dhcp, address, gateway, prefixString, netmask, kuraProps);
                s_logger.debug("NetConfig: {}", netConfig);
                netConfigs.add(netConfig);
            }
        }
    }
}
Also used : NetInterfaceAddressConfigImpl(org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl) UnknownHostException(java.net.UnknownHostException) NetInterfaceStatus(org.eclipse.kura.net.NetInterfaceStatus) IP4Address(org.eclipse.kura.net.IP4Address) Properties(java.util.Properties) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) KuraException(org.eclipse.kura.KuraException) NetConfig(org.eclipse.kura.net.NetConfig) ArrayList(java.util.ArrayList) List(java.util.List) IPAddress(org.eclipse.kura.net.IPAddress) File(java.io.File) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) WifiInterfaceAddressConfigImpl(org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl)

Example 5 with NetInterfaceAddressConfigImpl

use of org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl in project kura by eclipse.

the class NetworkAdminServiceImpl method updateEthernetInterfaceConfig.

@Override
public void updateEthernetInterfaceConfig(String interfaceName, boolean autoConnect, int mtu, List<NetConfig> netConfigs) throws KuraException {
    NetConfigIP4 netConfig4 = null;
    NetConfigIP6 netConfig6 = null;
    DhcpServerConfigIP4 dhcpServerConfigIP4 = null;
    FirewallAutoNatConfig natConfig = null;
    boolean hadNetConfig4 = false;
    boolean hadNetConfig6 = false;
    boolean hadDhcpServerConfigIP4 = false;
    boolean hadNatConfig = false;
    if (netConfigs != null && !netConfigs.isEmpty()) {
        for (NetConfig netConfig : netConfigs) {
            if (!netConfig.isValid()) {
                throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, "NetConfig Configuration is invalid: " + netConfig.toString());
            }
            if (netConfig instanceof NetConfigIP4) {
                netConfig4 = (NetConfigIP4) netConfig;
            } else if (netConfig instanceof NetConfigIP6) {
                netConfig6 = (NetConfigIP6) netConfig;
            } else if (netConfig instanceof DhcpServerConfigIP4) {
                dhcpServerConfigIP4 = (DhcpServerConfigIP4) netConfig;
            } else if (netConfig instanceof FirewallAutoNatConfig) {
                natConfig = (FirewallAutoNatConfig) netConfig;
            }
        }
    }
    // validation
    if (netConfig4 == null && netConfig6 == null) {
        throw new KuraException(KuraErrorCode.CONFIGURATION_REQUIRED_ATTRIBUTE_MISSING, "Either IPv4 or IPv6 configuration must be defined");
    }
    List<String> modifiedInterfaceNames = new ArrayList<String>();
    boolean configurationChanged = false;
    ComponentConfiguration originalNetworkComponentConfiguration = ((SelfConfiguringComponent) this.m_networkConfigurationService).getConfiguration();
    if (originalNetworkComponentConfiguration == null) {
        s_logger.debug("Returning for some unknown reason - no existing config???");
        return;
    }
    try {
        NetworkConfiguration newNetworkConfiguration = new NetworkConfiguration(originalNetworkComponentConfiguration.getConfigurationProperties());
        List<NetInterfaceConfig<? extends NetInterfaceAddressConfig>> netInterfaceConfigs = newNetworkConfiguration.getNetInterfaceConfigs();
        for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig : netInterfaceConfigs) {
            if (netInterfaceConfig.getName().equals(interfaceName)) {
                // handle MTU
                if (mtu != netInterfaceConfig.getMTU()) {
                    AbstractNetInterface<?> absNetInterfaceConfig = (AbstractNetInterface<?>) netInterfaceConfig;
                    s_logger.debug("updating MTU for {}", interfaceName);
                    absNetInterfaceConfig.setMTU(mtu);
                    configurationChanged = true;
                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                        modifiedInterfaceNames.add(interfaceName);
                    }
                }
                // handle autoconnect
                if (autoConnect != netInterfaceConfig.isAutoConnect()) {
                    AbstractNetInterface<?> absNetInterfaceConfig = (AbstractNetInterface<?>) netInterfaceConfig;
                    s_logger.debug("updating autoConnect for {} to be {}", interfaceName, autoConnect);
                    absNetInterfaceConfig.setAutoConnect(autoConnect);
                    configurationChanged = true;
                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                        modifiedInterfaceNames.add(interfaceName);
                    }
                }
                // replace existing configs
                List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
                if (netInterfaceAddressConfigs != null && !netInterfaceAddressConfigs.isEmpty()) {
                    for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
                        List<NetConfig> existingNetConfigs = netInterfaceAddressConfig.getConfigs();
                        List<NetConfig> newNetConfigs = new ArrayList<NetConfig>();
                        for (NetConfig netConfig : existingNetConfigs) {
                            s_logger.debug("looking at existing NetConfig for {} with value: {}", interfaceName, netConfig);
                            if (netConfig instanceof NetConfigIP4) {
                                if (netConfig4 == null) {
                                    s_logger.debug("removing NetConfig4 for {}", interfaceName);
                                } else {
                                    hadNetConfig4 = true;
                                    newNetConfigs.add(netConfig4);
                                    if (!netConfig.equals(netConfig4)) {
                                        s_logger.debug("updating NetConfig4 for {}", interfaceName);
                                        s_logger.debug("Is new State DHCP? {}", netConfig4.isDhcp());
                                        configurationChanged = true;
                                        if (!modifiedInterfaceNames.contains(interfaceName)) {
                                            modifiedInterfaceNames.add(interfaceName);
                                        }
                                    } else {
                                        s_logger.debug("not updating NetConfig4 for {} because it is unchanged", interfaceName);
                                    }
                                }
                            } else if (netConfig instanceof NetConfig6) {
                                if (netConfig6 == null) {
                                    s_logger.debug("removing NetConfig6 for {}", interfaceName);
                                } else {
                                    hadNetConfig6 = true;
                                    newNetConfigs.add(netConfig6);
                                    if (!netConfig.equals(netConfig6)) {
                                        s_logger.debug("updating NetConfig6 for {}", interfaceName);
                                        configurationChanged = true;
                                        if (!modifiedInterfaceNames.contains(interfaceName)) {
                                            modifiedInterfaceNames.add(interfaceName);
                                        }
                                    } else {
                                        s_logger.debug("not updating NetConfig6 for {} because it is unchanged", interfaceName);
                                    }
                                }
                            } else if (netConfig instanceof DhcpServerConfigIP4) {
                                if (dhcpServerConfigIP4 == null) {
                                    s_logger.debug("removing DhcpServerConfigIP4 for {}", interfaceName);
                                    configurationChanged = true;
                                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                                        modifiedInterfaceNames.add(interfaceName);
                                    }
                                } else {
                                    hadDhcpServerConfigIP4 = true;
                                    newNetConfigs.add(dhcpServerConfigIP4);
                                    if (!netConfig.equals(dhcpServerConfigIP4)) {
                                        s_logger.debug("updating DhcpServerConfigIP4 for {}", interfaceName);
                                        configurationChanged = true;
                                        if (!modifiedInterfaceNames.contains(interfaceName)) {
                                            modifiedInterfaceNames.add(interfaceName);
                                        }
                                    } else {
                                        s_logger.debug("not updating DhcpServerConfigIP4 for {} because it is unchanged", interfaceName);
                                    }
                                }
                            } else if (netConfig instanceof FirewallAutoNatConfig) {
                                if (natConfig == null) {
                                    s_logger.debug("removing FirewallAutoNatConfig for {}", interfaceName);
                                    configurationChanged = true;
                                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                                        modifiedInterfaceNames.add(interfaceName);
                                    }
                                } else {
                                    hadNatConfig = true;
                                    newNetConfigs.add(natConfig);
                                    if (!netConfig.equals(natConfig)) {
                                        s_logger.debug("updating FirewallAutoNatConfig for {}", interfaceName);
                                        configurationChanged = true;
                                        if (!modifiedInterfaceNames.contains(interfaceName)) {
                                            modifiedInterfaceNames.add(interfaceName);
                                        }
                                    } else {
                                        s_logger.debug("not updating FirewallAutoNatConfig for {} because it is unchanged", interfaceName);
                                    }
                                }
                            } else {
                                s_logger.debug("Found unsupported configuration: {}", netConfig.toString());
                            }
                        }
                        // add configs that did not match any in the current configuration
                        if (netConfigs != null && !netConfigs.isEmpty()) {
                            for (NetConfig netConfig : netConfigs) {
                                if (netConfig instanceof NetConfigIP4 && !hadNetConfig4) {
                                    s_logger.debug("adding new NetConfig4 to existing config for {}", interfaceName);
                                    newNetConfigs.add(netConfig);
                                    configurationChanged = true;
                                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                                        modifiedInterfaceNames.add(interfaceName);
                                    }
                                }
                                if (netConfig instanceof NetConfigIP6 && !hadNetConfig6) {
                                    s_logger.debug("adding new NetConfig6 to existing config for {}", interfaceName);
                                    newNetConfigs.add(netConfig);
                                    configurationChanged = true;
                                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                                        modifiedInterfaceNames.add(interfaceName);
                                    }
                                }
                                if (netConfig instanceof DhcpServerConfigIP4 && !hadDhcpServerConfigIP4) {
                                    s_logger.debug("adding new DhcpServerConfigIP4 to existing config for {}", interfaceName);
                                    newNetConfigs.add(netConfig);
                                    configurationChanged = true;
                                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                                        modifiedInterfaceNames.add(interfaceName);
                                    }
                                }
                                if (netConfig instanceof FirewallAutoNatConfig && !hadNatConfig) {
                                    s_logger.debug("adding new FirewallAutoNatConfig to existing config for {}", interfaceName);
                                    newNetConfigs.add(netConfig);
                                    configurationChanged = true;
                                    if (!modifiedInterfaceNames.contains(interfaceName)) {
                                        modifiedInterfaceNames.add(interfaceName);
                                    }
                                }
                            }
                        }
                        for (NetConfig netConfig : newNetConfigs) {
                            s_logger.debug("New NetConfig: {} :: {}", netConfig.getClass().toString(), netConfig.toString());
                        }
                        // replace with new list
                        ((NetInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(newNetConfigs);
                    }
                }
            }
        }
        if (configurationChanged) {
            submitNetworkConfiguration(modifiedInterfaceNames, newNetworkConfiguration);
        }
    } catch (UnknownHostException e) {
        s_logger.warn("Exception while updating EthernetInterfaceConfig", e);
    }
}
Also used : NetInterfaceAddressConfigImpl(org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl) DhcpServerConfigIP4(org.eclipse.kura.net.dhcp.DhcpServerConfigIP4) FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) NetInterfaceConfig(org.eclipse.kura.net.NetInterfaceConfig) UnknownHostException(java.net.UnknownHostException) NetConfig6(org.eclipse.kura.net.NetConfig6) ArrayList(java.util.ArrayList) AbstractNetInterface(org.eclipse.kura.core.net.AbstractNetInterface) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) SelfConfiguringComponent(org.eclipse.kura.configuration.SelfConfiguringComponent) ComponentConfiguration(org.eclipse.kura.configuration.ComponentConfiguration) NetConfigIP6(org.eclipse.kura.net.NetConfigIP6) KuraException(org.eclipse.kura.KuraException) NetConfig(org.eclipse.kura.net.NetConfig) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig)

Aggregations

NetInterfaceAddressConfigImpl (org.eclipse.kura.core.net.NetInterfaceAddressConfigImpl)5 NetConfig (org.eclipse.kura.net.NetConfig)5 NetInterfaceAddressConfig (org.eclipse.kura.net.NetInterfaceAddressConfig)5 WifiInterfaceAddressConfigImpl (org.eclipse.kura.core.net.WifiInterfaceAddressConfigImpl)4 UnknownHostException (java.net.UnknownHostException)3 ArrayList (java.util.ArrayList)3 KuraException (org.eclipse.kura.KuraException)3 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)3 NetInterfaceType (org.eclipse.kura.net.NetInterfaceType)3 File (java.io.File)2 List (java.util.List)2 IP4Address (org.eclipse.kura.net.IP4Address)2 DhcpServerConfig4 (org.eclipse.kura.net.dhcp.DhcpServerConfig4)2 FirewallAutoNatConfig (org.eclipse.kura.net.firewall.FirewallAutoNatConfig)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ComponentConfiguration (org.eclipse.kura.configuration.ComponentConfiguration)1 SelfConfiguringComponent (org.eclipse.kura.configuration.SelfConfiguringComponent)1 AbstractNetInterface (org.eclipse.kura.core.net.AbstractNetInterface)1