Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darwin dns-sd advertising needs to use the right hostname #16849

Closed
bzbarsky-apple opened this issue Mar 30, 2022 · 2 comments · Fixed by #21985 or #22010
Closed

Darwin dns-sd advertising needs to use the right hostname #16849

bzbarsky-apple opened this issue Mar 30, 2022 · 2 comments · Fixed by #21985 or #22010
Assignees
Labels
darwin spec Mismatch between spec and implementation V1.0

Comments

@bzbarsky-apple
Copy link
Contributor

Problem

Right now operational and commissionable DNS-SD advertising on Darwin uses the default hostname of the device involved, because we are passing NULL for the host argument when calling DNSServiceRegister.

Per spec, the hostname is supposed to be the MAC (or whatever randomized thing we are pretending is the MAC).

I tried implemeting this as follows:

  1. Modify Register in src/platform/Darwin/DnssdImpl.cpp to take a hostname argument.
  2. Pass service->mHostName to Register from ChipDnssdPublishService in that file.
  3. Do some munging on the hostname in Register:
    // Treat empty hostname as null.
    if (hostname != nullptr && strcmp(hostname, "") == 0) {
        hostname = nullptr;
    }
    
    std::string hostnameStr;
    if (hostname != nullptr) {
        hostnameStr = std::string(hostname) + '.' + kLocalDot;
        hostname = hostnameStr.c_str();
    }
    
  4. Pass hostname to DNSServiceRegister.

That fixes the advertisements to have the right hostname, afaict, but address resolution then fails because there is no IP associated with that hostname. The documentation at https://developer.apple.com/documentation/dnssd/1804733-dnsserviceregister?language=objc says to call DNSServiceRegisterRecord to handle that, but I could not figure out the right arguments to pass it, even when hard-coding the relevant IPs, to get past "invalid argument" errors it was giving me.

Proposed Solution

  • Figure out whether the combination of passing a hostname to DNSServiceRegister and calling DNSServiceRegisterRecord is actually what we want to be doing here.
  • If so, sort out how to actually call DNSServiceRegisterRecord properly.
@bzbarsky-apple bzbarsky-apple added darwin V1.0 spec Mismatch between spec and implementation labels Mar 30, 2022
@andy31415
Copy link
Contributor

andy31415 commented Jun 15, 2022

Would it be easier to update the spec to only recommend using the mac as hostname?
Or does that potentially cause issues because macs (or other devices) may have overly long hostnames that devices then fail to work with due to embedded constrains?

@bzbarsky-apple
Copy link
Contributor Author

bzbarsky-apple commented Jun 16, 2022

Or does that potentially cause issues because macs (or other devices) may have overly long hostnames that devices then fail to work with due to embedded constrains?

Exactly. We ran into this because minmdns was using a buffer sized to the spec thing and failing out if the hostname did not
fit in there, iirc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
darwin spec Mismatch between spec and implementation V1.0
Projects
None yet
6 participants