Skip to content

net: dns-sd: use hostname instead of instance name #89341

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

toonst
Copy link
Contributor

@toonst toonst commented Apr 30, 2025

As described in https://www.rfc-editor.org/rfc/rfc2782, the target field of an SRV record should be the domain name of the target host.

Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are compliance issues and CI issues that needs to be fixed.

@@ -575,6 +575,7 @@ int add_srv_record(const struct dns_sd_rec *inst, uint32_t ttl,
size_t label_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message talks about domain name, was that suppose to say host name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the terminology in the RFC is a bit confusing. Updated the commit message to be consistent

@@ -593,9 +594,9 @@ int add_srv_record(const struct dns_sd_rec *inst, uint32_t ttl,
/* pointer to .<Instance>.<Service>.<Protocol>.local. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is now wrong in this line if we replace Instance by Hostname

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acutally it is still correct, the full service name is still in the resource record.

As described in https://www.rfc-editor.org/rfc/rfc2782, the target field
of an SRV record should be the host name of the machine providing the
service.

Signed-off-by: Toon Stegen <toon@toostsolutions.be>
@toonst toonst force-pushed the dns_sd_hostname branch from beda08f to 88e44db Compare May 14, 2025 12:08
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3 Security Hotspots

See analysis details on SonarQube Cloud

@toonst toonst force-pushed the dns_sd_hostname branch from 88e44db to 0e1551d Compare May 14, 2025 17:03
this fixes the tests to check the hostname is filles in the SRV record's
target field.

Signed-off-by: Toon Stegen <toon@toostsolutions.be>
@toonst toonst force-pushed the dns_sd_hostname branch from 0e1551d to 619dbaf Compare May 14, 2025 17:21
@@ -382,56 +382,90 @@ ZTEST(dns_sd, test_add_txt_record)
ZTEST(dns_sd, test_add_srv_record)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo on test commit msg
s/filles/filled/

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pass in hostname as a parameter to add_srv_record().

The signature of the function will need to be changed in the library as well as in the testsuite to accommodate, but overall doing so will ensure that it can be tested efficiently as a unit by parametrizing inputs.

@@ -575,6 +575,7 @@ int add_srv_record(const struct dns_sd_rec *inst, uint32_t ttl,
size_t label_size;
uint16_t inst_offs;
uint16_t offset = buf_offset;
const char *hostname = net_hostname_get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is already pretty testable as a unit. Is there any reason not to add hostname as a function parameter?

This change effectively hard-codes the host name, in that it is not easily manipulated by the test harness that tests add_srv_record() as a unit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants