Browse Source

plutosdr: resolve ambiguous mDNS URIs using discovered endpoint

Fix mDNS discovery ambiguity where multiple devices across
different network segments/subnets can advertise the same hostname (e.g.
"ip:pluto.local"), resulting in non-unique or misleading URIs.

Replace unresolved mDNS hostnames with the actual discovered endpoint
reported in the scan description.
- Detect ".local" URIs on IP backend and substitute hostname with
  resolved endpoint from libiio scan results.
- Preserve URI semantics:
  - Keep backend prefix ("ip:")
  - Preserve optional port suffix
  - Correctly format IPv6 literals with RFC2732 bracket notation when
    required
- Add replaceHostnameWithIP() to perform URI normalization during scan:
  - Only applies to IP backend URIs
  - Only triggers for mDNS-based ".local" hostnames
  - Uses scan-provided endpoint (from description string) as authoritative
    address instead of advertised hostname
- Extend scan() to emit both original and resolved URIs for debugging
  and verification during device discovery.

This resolves inconsistent device addressing when multiple PlutoSDRs
are accessible via mDNS across different subnets or network segments.

No change to backend enumeration or device identity logic; this only
normalizes .local IP URI resolution at scan time.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
chirpmodem-v8.0.0
Robin Getz 5 months ago
parent
commit
9632d6d9c7
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 84
      devices/plutosdr/deviceplutosdrscan.cpp
  2. 3
      devices/plutosdr/deviceplutosdrscan.h

84
devices/plutosdr/deviceplutosdrscan.cpp

@ -65,7 +65,10 @@ void DevicePlutoSDRScan::scan() @@ -65,7 +65,10 @@ void DevicePlutoSDRScan::scan()
continue;
}
qDebug("PlutoSDRScan::scan: %d: %s [%s]", i, description, uri);
// For uri which are ip:*.local replace with the ip address
std::string fixedUri = replaceHostnameWithIP(uri, description);
qDebug("PlutoSDRScan::scan: %d: %s [%s] [%s]", i, description, uri, fixedUri.c_str());
const std::string_view descriptionView = description ? std::string_view{description} : std::string_view{};
const bool isPlutoDescription =
(descriptionView.find("PlutoSDR") != std::string_view::npos) ||
@ -79,7 +82,7 @@ void DevicePlutoSDRScan::scan() @@ -79,7 +82,7 @@ void DevicePlutoSDRScan::scan()
DeviceScan({
std::string(description),
std::string("TBD"),
std::string(uri)
fixedUri
}));
m_scans.push_back(dev_scan);
m_urilMap[m_scans.back()->m_uri] = m_scans.back();
@ -198,6 +201,83 @@ void DevicePlutoSDRScan::enumOriginDevices(const QString& hardwareId, PluginInte @@ -198,6 +201,83 @@ void DevicePlutoSDRScan::enumOriginDevices(const QString& hardwareId, PluginInte
}
/**
* @brief Replaces an mDNS hostname with the discovered endpoint.
*
* Older libiio versions may return the advertised mDNS hostname (for example
* "ip:pluto.local") rather than the endpoint that was actually discovered.
* This becomes ambiguous when identical mDNS hostnames exist on different
* network segments, since multiple devices can legitimately advertise the
* same ".local" hostname.
*
* Since the scan description begins with the discovered endpoint (IPv4 or IPv6),
* followed by " (". For ".local" URIs, substitute the endpoint while
* preserving the backend and optional port number.
*
* Examples:
* URI: ip:pluto.local
* Description: 192.168.2.1 (...)
* Result: ip:192.168.2.1
*
* URI: ip:pluto.local:30431
* Description: fe80::205:f7ff:fe75:9c4f%eth1 (...)
* Result: ip:[fe80::205:f7ff:fe75:9c4f%eth1]:30431
*/
std::string DevicePlutoSDRScan::replaceHostnameWithIP(
const std::string& uri,
const char *description) const
{
if (!description) {
return uri;
}
// Only applies to IP backends.
if (uri.rfind("ip:", 0) != 0) {
return uri;
}
// Only rewrite mDNS hostnames.
if (uri.find(".local") == std::string::npos) {
return uri;
}
// Description starts with "<endpoint> (".
const std::string desc(description);
const size_t endpointEnd = desc.find(" (");
if (endpointEnd == std::string::npos) {
return uri;
}
const std::string endpoint = desc.substr(0, endpointEnd);
// Preserve any optional port.
std::string port;
const size_t localPos = uri.find(".local");
if (localPos != std::string::npos)
{
const size_t afterLocal = localPos + 6; // strlen(".local")
if (afterLocal < uri.size() && uri[afterLocal] == ':') {
port = uri.substr(afterLocal);
}
}
std::string newUri = "ip:";
// RFC2732 requires brackets around IPv6 literals when a port is present.
if (!port.empty() && endpoint.find(':') != std::string::npos) {
newUri += "[" + endpoint + "]";
} else {
newUri += endpoint;
}
newUri += port;
return newUri;
}
/**
* @brief Creates a backend prefix from a libiio URI.
*

3
devices/plutosdr/deviceplutosdrscan.h

@ -52,6 +52,9 @@ public: @@ -52,6 +52,9 @@ public:
private:
static constexpr char BACKEND_SEPARATOR = '_';
std::string replaceHostnameWithIP(
const std::string& uri,
const char *description) const;
std::string createBackendSuffix(const char *uri) const;
QString getBackendLabel(const std::string& serial) const;
std::string getPhysicalSerial(const std::string& serial) const;

Loading…
Cancel
Save