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

mDNSPosix Fixes #2

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

Conversation

nkarstens
Copy link

@nkarstens nkarstens commented Mar 23, 2023

The attached patches fix some issues we noticed with the POSIX implementation:

  1. Linux builds currently fail.
  2. The record cache is cleared when a netlink message indicates that there has been a change, even if the change is for a different interface or would not affect the status of the interface. This causes applications to think all of the services they have been tracking have been removed and increases network load because the client must re-query for all records it is interested in.
  3. Changes to interface indices larger than 31 are currently ignored.
  4. Some socket API errors are not being handled.

Most of these changes have been available on OpenEmbedded for a while.

The __block qualifier is not used in Linux builds.

Signed-off-by: Nate Karstens <[email protected]>
Moves functionality for cleaning the list of recent
interfaces into its own subroutine.

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Creates a subroutine for tearing down an interface.

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Tracks the socket family associated with the interface.

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Tells the mDNS core if an interface is a loopback interface,
similar to AddInterfaceToList() in the MacOS implementation.

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Uses a linked list to store the index of changed network interfaces
instead of a bitfield. This allows for network interfaces with an
index greater than 31 (an index of 36 was seen on Android).

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Change-Id: Ibeab0ec68ca0d21da8384d4362e59afd2951f138
The POSIX implementation currently clears all network interfaces
when netlink indicates that there has been a change. This causes
the following problems:

  1) Applications are informed that all of the services they are
     tracking have been removed.
  2) Increases network load because the client must re-query for
     all records it is interested in.

This changes netlink notification handling by:

  1) Always comparing with the latest interface list returned
     by the OS.
  2) Confirming that the interface has been changed in a way
     that we care about.

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Netlink notification handling ignores messages for deleted links,
RTM_DELLINK. It does handle RTM_GETLINK. According to libnl docu-
mentation (http://www.infradead.org/~tgr/libnl/doc/route.html)
RTM_DELLINK can be sent by the kernel, but RTM_GETLINK cannot.
There was likely a mixup in the original implementation, so this
change replaces handling for RTM_GETLINK with RTM_DELLINK.

Testing and Verification Instructions:
  1. Use ip-link to add and remove a VLAN interface and verify
     that mDNSResponder handles the deleted link.

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
Adds handling for socket() or read() returning a
negative value (indicating an error has occurred).

Upstream-Status: Submitted [[email protected]]

Signed-off-by: Nate Karstens <[email protected]>
Signed-off-by: Alex Kiernan <[email protected]>
@Goldindollar
Copy link

Nice fix

@agners agners mentioned this pull request Jun 23, 2023
@agners
Copy link

agners commented Jun 23, 2023

With this patchset applied, I get a SIGSEGV when there is a wpan0 interface on the same host.

Program received signal SIGSEGV, Segmentation fault.
InterfaceChangeCallback (fd=19, context=0x555555629e70) at mDNSPosix.c:1898
1898                ((*ifi)->ifa_addr->sa_family == AF_INET) &&
(gdb) bt
#0  InterfaceChangeCallback (fd=19, context=0x555555629e70) at mDNSPosix.c:1898
#1  0x000055555555c461 in mDNSPosixProcessFDSet (m=0x555555617d40 <mDNSStorage>, readfds=0x7fffffffde70, writefds=0x7fffffffdef0) at mDNSPosix.c:2499
#2  0x000055555555cbe2 in mDNSPosixRunEventLoopOnce (m=0x555555617d40 <mDNSStorage>, pTimeout=0x7fffffffdfc0, pSignalsReceived=0x7fffffffdfd0, pDataDispatched=0x7fffffffdfb7 "") at mDNSPosix.c:2700
#3  0x0000555555556b23 in MainLoop (m=0x555555617d40 <mDNSStorage>) at PosixDaemon.c:170
#4  0x0000555555556da5 in main (argc=2, argv=0x7fffffffe1a8) at PosixDaemon.c:220
(gdb) print (*ifi)->ifa_addr
$1 = (struct sockaddr *) 0x0

I've made a fix and created a separate PR with the fix included (see #6).

@Goldindollar
Copy link

Goldindollar commented Jun 23, 2023 via email

It seems that certain interface types may have `ifa_addr` set to null.
Handle this case gracefully.

Signed-off-by: Stefan Agner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants