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

Do a mDNS advertisement on minmdns server startup #4884

Merged
merged 22 commits into from
Feb 19, 2021

Conversation

andy31415
Copy link
Contributor

@andy31415 andy31415 commented Feb 16, 2021

Problem

Devices should advertise that they exist at boot time, so that passive listeners can see such devices.

This is especially useful on commisioning devices (new devices appear) as well as in case IP address changes.

Summary of Changes

  • IPv4 listen on all inteerfaces (instead of NULL interface id)
  • at ::Start, do a mdns advertise of all PTR entries (which will recursively send SRV and A/AAAA records)

Note that this is not fully RFC compliant (RFC requires a re-advertisement after 10s). It just makes things more functional.

Fixes #4853

@pullapprove pullapprove bot requested a review from rwalker-apple February 17, 2021 14:07
@andy31415 andy31415 requested a review from msandstedt February 17, 2021 14:11
@andy31415
Copy link
Contributor Author

Copy link
Contributor

@woody-apple woody-apple left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

src/lib/mdns/Advertiser_ImplMinimalMdns.cpp Outdated Show resolved Hide resolved
src/lib/mdns/Advertiser_ImplMinimalMdns.cpp Outdated Show resolved Hide resolved
src/lib/mdns/Advertiser_ImplMinimalMdns.cpp Outdated Show resolved Hide resolved
@andy31415 andy31415 force-pushed the 01_mdns_advertise_at_boot branch from f3fd002 to 9fecbf9 Compare February 18, 2021 23:00
@github-actions
Copy link

Size increase report for "nrfconnect-example-build" from 0e9c5b8

File Section File VM
chip-lighting.elf text 476 476
chip-lighting.elf bss 0 51
chip-lighting.elf shell_root_cmds_sections 4 4
chip-lighting.elf [LOAD #3 [RW]] 0 -19
chip-lighting.elf rodata -32 -32
chip-lock.elf text 472 472
chip-lock.elf bss 0 55
chip-lock.elf shell_root_cmds_sections 8 8
chip-lock.elf [LOAD #3 [RW]] 0 -23
chip-lock.elf rodata -32 -36
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-lighting.elf and ./pull_artifact/chip-lighting.elf:

sections,vmsize,filesize
.debug_info,0,4206
.debug_str,0,1147
.debug_line,0,648
text,476,476
.debug_loc,0,441
.debug_ranges,0,440
.strtab,0,315
.symtab,0,192
.debug_frame,0,76
bss,51,0
.debug_aranges,0,16
.debug_abbrev,0,10
shell_root_cmds_sections,4,4
.shstrtab,0,-3
[LOAD #3 [RW]],-19,0
rodata,-32,-32

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize
.debug_info,0,20
.debug_str,0,17
.debug_loc,0,-5

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_info,0,4206
.debug_str,0,1147
.debug_line,0,652
text,472,472
.debug_loc,0,445
.debug_ranges,0,440
.strtab,0,315
.symtab,0,192
.debug_frame,0,76
bss,55,0
.debug_aranges,0,16
.debug_abbrev,0,10
shell_root_cmds_sections,8,8
.shstrtab,0,-3
[LOAD #3 [RW]],-23,0
rodata,-36,-32


@github-actions
Copy link

Size increase report for "gn_qpg6100-example-build" from 0e9c5b8

File Section File VM
chip-qpg6100-lock-example.out .text 476 476
chip-qpg6100-lock-example.out .bss 0 40
chip-qpg6100-lock-example.out .heap 0 -40
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-qpg6100-lock-example.out and ./pull_artifact/chip-qpg6100-lock-example.out:

sections,vmsize,filesize
.debug_info,0,4372
.debug_str,0,1153
.debug_loc,0,877
.debug_line,0,871
.strtab,0,573
.text,476,476
.symtab,0,320
.debug_frame,0,156
.debug_ranges,0,88
.bss,40,0
.debug_aranges,0,40
.shstrtab,0,-1
.heap,-40,0
.debug_abbrev,0,-57
[Unmapped],0,-476


@github-actions
Copy link

Size increase report for "esp32-example-build" from 0e9c5b8

File Section File VM
chip-all-clusters-app.elf .flash.text 504 504
chip-all-clusters-app.elf .dram0.bss 0 40
chip-all-clusters-app.elf .flash.rodata -32 -32
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-pigweed-app.elf and ./pull_artifact/chip-pigweed-app.elf:

sections,vmsize,filesize
.debug_str,0,663
.debug_info,0,374
.debug_loc,0,2
.xt.prop._ZSt9__find_ifIPKSt4byteN9__gnu_cxx5__ops10_Iter_predIPFbS0_EEEET_S9_S9_T0_St26random_access_iterator_tag,0,1

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,4185
.debug_line,0,1345
.debug_str,0,1147
.debug_loc,0,648
.debug_ranges,0,592
.flash.text,504,504
.strtab,0,139
.dram0.bss,40,0
.symtab,0,32
[Unmapped],0,32
.debug_frame,0,24
.debug_aranges,0,8
.xt.prop._ZN4mdns7Minimal16QueryReplyFilter6AcceptENS0_5QTypeENS0_6QClassENS0_9FullQNameE,0,4
.shstrtab,0,1
.debug_abbrev,0,-9
.flash.rodata,-32,-32
.xt.prop._ZN4mdns7Minimal16QueryReplyFilterD2Ev,0,-40


src/lib/mdns/minimal/Server.h Outdated Show resolved Hide resolved
src/lib/mdns/minimal/responders/QueryResponder.h Outdated Show resolved Hide resolved
private:
bool AcceptableQueryType(QType qType)
{
if (mSendingAdditionalItems && mQueryData.IsBootAdvertising())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check needed (isn't the 2nd condition true already?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IsBootAdvertising is only set during initial boot, not during normal query replies, where as 'sending additional items' is set for any reply processing. I believe they are both needed.


bool AcceptablePath(FullQName qname)
{
if (mIgnoreNameMatch || mQueryData.IsBootAdvertising())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need IsBootAdvertising instead of just using IgnoreNameMatch ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed to make the intent cleaner by having behaviour depend on query.

The boot-time broadcaster builds a fake query (so that the sender sends replies to such a query) however it does not have access to the underlying filtering used by the mDNS sender.

Alternative would be to propagate flags into the mdns sending and that seeemed to be a bit uglier.

return false;
}

if (strncmp(name, "lo", 2) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a new issue, but doesn't seem right that if I rename my interface to "lollipop" it will be skipped.

Probably the name is the wrong thing to look at altogether, and we should just inspect the address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could find no better way.

For devices this may not be an issue (since they control their wifi name and it is likely LWIP anyway). Would people rename interfaces on android/iOS?

Added a TODO to auto-create an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just get the address and see if it's ::1 or inside 127.0.0.0/8 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InterfaceIterator does not provide the address only InterfaceAddressIterator does.

Absolutely possible to use AddressIterator instead and do some dedup, but I find it more bothersome than what I would be generally add as a 'fix if you are already touching this'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Real fix would probably to fix the interface iterator to be able to return an address iterator for that specified interface. Having 2 types of iterators that both iterate over all interfaces is strange.

@todo
Copy link

todo bot commented Feb 19, 2021

need a better way to ignore local loopback interfaces/addresses

// TODO: need a better way to ignore local loopback interfaces/addresses
// We do not want to listen on local loopback even though they are up and
// support multicast
//
// Some way to detect 'is local looback' that is smarter (e.g. at least
// strict string compare on linux instead of substring) would be better.
//
// This would reject likely valid interfaces like 'lollipop' or 'lostinspace'
if (strncmp(name, "lo", 2) == 0)
{
/// local loopback interface is not usable by MDNS


This comment was generated by todo based on a TODO comment in d285703 in #4884. cc @andy31415.

@andy31415 andy31415 merged commit 2b58bdf into project-chip:master Feb 19, 2021
@andy31415 andy31415 deleted the 01_mdns_advertise_at_boot branch October 28, 2021 14:03
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.

mDNS appears broken on ESP32 after #4132
5 participants