Skip to content

Commit

Permalink
RDKEMW-516 : GetPublicIP Method is not taking ipversion & interface c…
Browse files Browse the repository at this point in the history
…orrectly

Reason for change: GetPublicIP Method is not taking ipversion & interface correctly
Test Procedure: As per RDKEMW-516
Risks: Low
Signed-off-by: kamirt573_comcast <[email protected]>
  • Loading branch information
karuna2git committed Jan 3, 2025
1 parent a196415 commit b16b802
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion INetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace WPEFramework
virtual uint32_t StopConnectivityMonitoring(void) const = 0;

/* @brief Get the Public IP used for external world communication */
virtual uint32_t GetPublicIP (string &ipversion /* @inout */, string& ipaddress /* @out */) = 0;
virtual uint32_t GetPublicIP (string& interface /* @inout */, string &ipversion /* @inout */, string& ipaddress /* @out */) = 0;

/* @brief Request for ping and get the response in as event. The GUID used in the request will be returned in the event. */
virtual uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t count /* @in */, const uint16_t timeout /* @in */, const string guid /* @in */, string& response /* @out */) = 0;
Expand Down
13 changes: 10 additions & 3 deletions LegacyPlugin_NetworkAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,20 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
uint32_t rc = Core::ERROR_GENERAL;
string ipAddress{};
string ipversion = "IPv4";
if (parameters.HasLabel("ipversion"))
ipversion = parameters["ipversion"].String();
if (parameters.HasLabel("ipv6") && parameters["ipv6"].Boolean())
ipversion = "IPv6";

string interface = "";
if (parameters.HasLabel("iface"))
{
string givenInterface = parameters["iface"].String();
interface = getInterfaceTypeToName(givenInterface);
}

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
{
rc = _nwmgr->GetPublicIP(ipversion, ipAddress);
rc = _nwmgr->GetPublicIP(interface, ipversion, ipAddress);
_nwmgr->Release();
}
else
Expand Down
23 changes: 21 additions & 2 deletions NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,30 @@ namespace WPEFramework
}

/* @brief Get the Public IP used for external world communication */
uint32_t NetworkManagerImplementation::GetPublicIP (string &ipversion /* @inout */, string& ipaddress /* @out */)
uint32_t NetworkManagerImplementation::GetPublicIP (string& interface /* @inout */, string &ipversion /* @inout */, string& ipaddress /* @out */)
{
LOG_ENTRY_FUNCTION();
stun::bind_result result;
bool isIPv6 = (ipversion == "IPv6");

// Either Interface must be connected to get the public IP
if (!(m_ethConnected | m_wlanConnected))
{
NMLOG_WARNING("No interface Connected");
return Core::ERROR_GENERAL;
}

stun::protocol proto (isIPv6 ? stun::protocol::af_inet6 : stun::protocol::af_inet);
if(stunClient.bind(m_stunEndpoint, m_stunPort, m_defaultInterface, proto, m_stunBindTimeout, m_stunCacheTimeout, result))
if(stunClient.bind(m_stunEndpoint, m_stunPort, interface, proto, m_stunBindTimeout, m_stunCacheTimeout, result))
{
if (isIPv6)
ipversion = "IPv6";
else
ipversion = "IPv4";

if (interface.empty())
interface = m_defaultInterface;

ipaddress = result.public_ip;
return Core::ERROR_NONE;
}
Expand Down Expand Up @@ -630,6 +640,9 @@ namespace WPEFramework
else if (currentActiveinterface == "wlan0")
m_wlanConnected = true;

// FIXME : This could be the place to define `m_defaultInterface` to incoming `currentActiveinterface`.
// m_defaultInterface = currentActiveinterface;

for (const auto callback : _notificationCallbacks) {
callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface);
}
Expand All @@ -646,6 +659,12 @@ namespace WPEFramework
else if(interface == "wlan0")
m_wlanConnected = true;

// FIXME : Availability of ip address for a given interface does not mean that its the default interface. This hardcoding will work for RDKProxy but not for Gnome.
if (m_ethConnected && m_wlanConnected)
m_defaultInterface = "eth0";
else
m_defaultInterface = interface;

// Start the connectivity monitor with 'true' to indicate the interface is up.
// The monitor will conntinoue even after no internet retry completed, Exit when fully connectd.
connectivityMonitor.startConnectivityMonitor();
Expand Down
2 changes: 1 addition & 1 deletion NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace WPEFramework
uint32_t StopConnectivityMonitoring(void) const override;

/* @brief Get the Public IP used for external world communication */
uint32_t GetPublicIP (string &ipversion /* @inout */, string& ipaddress /* @out */) override;
uint32_t GetPublicIP (string& interface /* @inout */, string &ipversion /* @inout */, string& ipaddress /* @out */) override;

/* @brief Request for ping and get the response in as event. The GUID used in the request will be returned in the event. */
uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const uint16_t timeOutInSeconds /* @in */, const string guid /* @in */, string& response /* @out */) override;
Expand Down
32 changes: 11 additions & 21 deletions NetworkManagerJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,30 +535,27 @@ namespace WPEFramework
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
string ipAddress{};
string interface{};
string ipaddress{};
string ipversion = "IPv4";
if (parameters.HasLabel("ipversion"))
ipversion = parameters["ipversion"].String();

if ((!m_publicIPAddress.empty()) && (m_publicIPAddressType == ipversion))
{
rc = Core::ERROR_NONE;
ipAddress = m_publicIPAddress;
}
if (parameters.HasLabel("interface"))
interface = parameters["interface"].String();

if (_networkManager)
rc = _networkManager->GetPublicIP(interface, ipversion, ipaddress);
else
{
if (_networkManager)
rc = _networkManager->GetPublicIP(ipversion, ipAddress);
else
rc = Core::ERROR_UNAVAILABLE;
}
rc = Core::ERROR_UNAVAILABLE;

if (Core::ERROR_NONE == rc)
{
response["ipaddress"] = ipAddress;
response["interface"] = interface;
response["ipaddress"] = ipaddress;
response["ipversion"] = ipversion;

m_publicIPAddress = ipAddress;
m_publicIPAddress = ipaddress;
m_publicIPAddressType = ipversion;
PublishToThunderAboutInternet();
}
Expand All @@ -567,15 +564,8 @@ namespace WPEFramework

void NetworkManager::PublishToThunderAboutInternet()
{
if (m_publicIPAddress.empty())
{
JsonObject input, output;
GetPublicIP(input, output);
}

if (!m_publicIPAddress.empty())
{
NMLOG_DEBUG("No public IP persisted yet; Update the data");
PluginHost::ISubSystem* subSystem = _service->SubSystems();

if (subSystem != nullptr)
Expand Down

0 comments on commit b16b802

Please sign in to comment.