diff --git a/.github/workflows/libnm_proxy_L1_test.yml b/.github/workflows/libnm_proxy_L1_test.yml index 80d945d5..d947d643 100644 --- a/.github/workflows/libnm_proxy_L1_test.yml +++ b/.github/workflows/libnm_proxy_L1_test.yml @@ -111,7 +111,7 @@ jobs: run: | sudo bash -c 'echo "ETHERNET_INTERFACE=eth0 WIFI_INTERFACE=wlan0 - DEVICE_NAME=rdk_test_device " > /etc/device.properties' + DEFAULT_HOSTNAME=rdk_test_device " > /etc/device.properties' - name: Generate IARM headers run: | diff --git a/definition/NetworkManager.json b/definition/NetworkManager.json index 8ada9b76..70cf138d 100644 --- a/definition/NetworkManager.json +++ b/definition/NetworkManager.json @@ -1351,7 +1351,7 @@ } }, "SetHostname": { - "summary": "To configure a custom DHCP hostname instead of the default (which is typically the device name).\n\nSetting host name will take effect upon reconnect; like, device reboot, wake-up from deepsleep, while connecting to new Wi-Fi connection, WiFi On/Off, or renewal of the DHCP lease.", + "summary": "To configure a custom DHCP hostname instead of the default (which is typically the default hostname).\n\nSetting host name will take effect upon reconnect; like, device reboot, wake-up from deepsleep, while connecting to new Wi-Fi connection, WiFi On/Off, or renewal of the DHCP lease.", "params": { "type": "object", "properties": { diff --git a/docs/NetworkManagerPlugin.md b/docs/NetworkManagerPlugin.md index bba3aa46..a1aac7cc 100644 --- a/docs/NetworkManagerPlugin.md +++ b/docs/NetworkManagerPlugin.md @@ -103,7 +103,7 @@ NetworkManager interface methods: | [GetWiFiSignalQuality](#method.GetWiFiSignalQuality) | Get WiFi signal quality of currently connected SSID | | [GetSupportedSecurityModes](#method.GetSupportedSecurityModes) | Returns the Wifi security modes that the device supports | | [GetWifiState](#method.GetWifiState) | Returns the current Wifi State | -| [SetHostname](#method.SetHostname) | To configure a custom DHCP hostname instead of the default (which is typically the device name) | +| [SetHostname](#method.SetHostname) | To configure a custom DHCP hostname instead of the default (which is typically the default hostname) | ## *SetLogLevel [method](#head.Methods)* @@ -1729,7 +1729,7 @@ This method takes no parameters. ## *SetHostname [method](#head.Methods)* -To configure a custom DHCP hostname instead of the default (which is typically the device name). +To configure a custom DHCP hostname instead of the default (which is typically the default hostname). Setting host name will take effect upon reconnect; like, device reboot, wake-up from deepsleep, while connecting to new Wi-Fi connection, WiFi On/Off, or renewal of the DHCP lease. diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index b2010fe9..81b57dd0 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -150,7 +150,14 @@ namespace WPEFramework // read persistent hostname if exist if(!nmUtils::readPersistentHostname(hostname)) { - hostname = nmUtils::deviceHostname(); // default hostname as device name + hostname = nmUtils::deviceHostname(); // default hostname as default hostname + } + + // Validate hostname is non-empty regardless of source (persistent or default) + if(hostname.empty()) + { + NMLOG_WARNING("Hostname is empty. No modification will be made to NM connections."); + return false; } connections = nm_client_get_connections(client); diff --git a/plugin/gnome/NetworkManagerGnomeUtils.cpp b/plugin/gnome/NetworkManagerGnomeUtils.cpp index 7d97e5e8..fa2b2869 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.cpp +++ b/plugin/gnome/NetworkManagerGnomeUtils.cpp @@ -40,7 +40,7 @@ namespace WPEFramework { static std::string m_ethifname = "eth0"; static std::string m_wlanifname = "wlan0"; - static std::string m_deviceHostname = "rdk-device"; // Device name can be empty if not set in /etc/device.properties + static std::string m_deviceHostname = "rdk-device"; // default hostname can be empty if not set in /etc/device.properties const char* nmUtils::wlanIface() {return m_wlanifname.c_str();} const char* nmUtils::ethIface() {return m_ethifname.c_str();} @@ -261,14 +261,14 @@ namespace WPEFramework } } - if (line.find("DEVICE_NAME=") != std::string::npos) { + if (line.find("DEFAULT_HOSTNAME=") != std::string::npos) { deviceHostname = line.substr(line.find('=') + 1); deviceHostname.erase(deviceHostname.find_last_not_of("\r\n\t") + 1); deviceHostname.erase(0, deviceHostname.find_first_not_of("\r\n\t")); if(deviceHostname.empty()) { - NMLOG_WARNING("DEVICE_NAME is empty in /etc/device.properties"); - deviceHostname = ""; // set empty device name + NMLOG_WARNING("DEFAULT_HOSTNAME is empty in /etc/device.properties"); + deviceHostname = ""; // set empty default hostname } } } @@ -277,7 +277,7 @@ namespace WPEFramework m_wlanifname = wifiIfname; m_ethifname = ethIfname; m_deviceHostname = deviceHostname; - NMLOG_INFO("/etc/device.properties eth: %s, wlan: %s, device name: %s", m_ethifname.c_str(), m_wlanifname.c_str(), m_deviceHostname.c_str()); + NMLOG_INFO("/etc/device.properties eth: %s, wlan: %s, default hostname: %s", m_ethifname.c_str(), m_wlanifname.c_str(), m_deviceHostname.c_str()); return true; } diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index 7fb4bb5d..4e52fc11 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -637,18 +637,27 @@ namespace WPEFramework NMLOG_DEBUG("No persistent hostname found, using device hostname"); } + if(hostname.empty()) + NMLOG_WARNING("dhcp hostname: "); + else + NMLOG_INFO("dhcp hostname: %s", hostname.c_str()); + // IPv4 settings with DHCP NMSettingIP4Config *sIpv4 = (NMSettingIP4Config *)nm_setting_ip4_config_new(); g_object_set(G_OBJECT(sIpv4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - g_object_set(G_OBJECT(sIpv4), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); - g_object_set(G_OBJECT(sIpv4), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); + if(!hostname.empty()) { + g_object_set(G_OBJECT(sIpv4), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); + g_object_set(G_OBJECT(sIpv4), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); + } nm_connection_add_setting(connection, NM_SETTING(sIpv4)); // IPv6 settings with DHCP NMSettingIP6Config *sIpv6 = (NMSettingIP6Config *)nm_setting_ip6_config_new(); g_object_set(G_OBJECT(sIpv6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - g_object_set(G_OBJECT(sIpv6), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); - g_object_set(G_OBJECT(sIpv6), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); + if(!hostname.empty()) { + g_object_set(G_OBJECT(sIpv6), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); + g_object_set(G_OBJECT(sIpv6), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); + } nm_connection_add_setting(connection, NM_SETTING(sIpv6)); NMLOG_DEBUG("Created minimal ethernet connection with autoconnect=true"); @@ -894,23 +903,30 @@ namespace WPEFramework if(!nmUtils::readPersistentHostname(hostname)) { hostname = nmUtils::deviceHostname(); - NMLOG_DEBUG("no persistent hostname found taking device name as hostname !"); + NMLOG_DEBUG("No persistent hostname found, using device hostname"); } - NMLOG_INFO("dhcp hostname: %s", hostname.c_str()); + if(hostname.empty()) + NMLOG_WARNING("dhcp hostname: "); + else + NMLOG_INFO("dhcp hostname: %s", hostname.c_str()); /* Build up the 'IPv4' Setting */ NMSettingIP4Config *sIpv4Conf = (NMSettingIP4Config *) nm_setting_ip4_config_new(); g_object_set(G_OBJECT(sIpv4Conf), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); // autoconf = true - g_object_set(G_OBJECT(sIpv4Conf), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); - g_object_set(G_OBJECT(sIpv4Conf), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); // hostname send enabled + if(!hostname.empty()) { + g_object_set(G_OBJECT(sIpv4Conf), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); + g_object_set(G_OBJECT(sIpv4Conf), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); // hostname send enabled + } nm_connection_add_setting(m_connection, NM_SETTING(sIpv4Conf)); /* Build up the 'IPv6' Setting */ NMSettingIP6Config *sIpv6Conf = (NMSettingIP6Config *) nm_setting_ip6_config_new(); g_object_set(G_OBJECT(sIpv6Conf), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); // autoconf = true - g_object_set(G_OBJECT(sIpv6Conf), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); - g_object_set(G_OBJECT(sIpv6Conf), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); // hostname send enabled + if(!hostname.empty()) { + g_object_set(G_OBJECT(sIpv6Conf), NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, hostname.c_str(), NULL); + g_object_set(G_OBJECT(sIpv6Conf), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, TRUE, NULL); // hostname send enabled + } nm_connection_add_setting(m_connection, NM_SETTING(sIpv6Conf)); return true; }