Skip to contentSkip to conversation

mdns: improve numerous aspects of Posix backend

PATCH New Matt Hoosier 1 participant 1 message Feb 5, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mdns: improve numerous aspects of Posix backend

Apple's default implementation of the Posix backend for mDNSResponder has a number of weaknesses. Address several of them, most notably:

* Improve interface tracking, preventing confusion to mdns's state machine. Prevents spurious removal/republication cycles whenever network interfaces are added or removed.

* Support network interfaces whose indeces are great than 31. Indices grow past that range surprisingly quickly, especially with multi- homed, mobile, wifi, Bluetooth, VPN, VLANs, or other interfaces present.

* Correctly handle edge cases during removal of a network interface.

The fixes are kept as a patch series for clarity.

---
 ...utine-for-cleaning-recent-interfaces.patch |  60 +++++
 ...outine-for-tearing-down-an-interface.patch |  58 +++++
 .../0003-Track-interface-socket-family.patch  |  50 +++++
 ...0004-Use-list-for-changed-interfaces.patch | 177 +++++++++++++++
 .../0005-Handle-noisy-netlink-sockets.patch   | 212 ++++++++++++++++++
 .../files/0006-Remove-unneeded-function.patch |  51 +++++
 ...cate-loopback-interface-to-mDNS-core.patch | 129 +++++++++++
 ...-deleted-interfaces-as-being-changed.patch |  39 ++++
 .../0009-Fix-possible-NULL-dereference.patch  |  45 ++++
 ...0010-Handle-errors-from-socket-calls.patch |  62 +++++
 ...ic-allocation-to-file-scope-variable.patch |  51 +++++
 .../recipes-protocols/mdns/mdns_878.260.1.bb  |  11 +
 12 files changed, 945 insertions(+)
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0001-Create-subroutine-for-cleaning-recent-interfaces.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0002-Create-subroutine-for-tearing-down-an-interface.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0003-Track-interface-socket-family.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0004-Use-list-for-changed-interfaces.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0005-Handle-noisy-netlink-sockets.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0006-Remove-unneeded-function.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0007-Indicate-loopback-interface-to-mDNS-core.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0008-Mark-deleted-interfaces-as-being-changed.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0009-Fix-possible-NULL-dereference.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0010-Handle-errors-from-socket-calls.patch
 create mode 100644 meta-networking/recipes-protocols/mdns/files/0011-Change-a-dynamic-allocation-to-file-scope-variable.patch
meta-networking/recipes-protocols/mdns/files/0001-Create-subroutine-for-cleaning-recent-interfaces.patch new file +60 -0
new file mode 100644
index 000000000..692c344db
@@ -0,0 +1,60 @@
+From 89ea6ac4a8840e8c2be0140a9805c6522c6c5280 Mon Sep 17 00:00:00 2001
+From: Nate Karstens <[email protected]>
+Date: Wed, 28 Jun 2017 17:30:00 -0500
+Subject: [PATCH 01/11] Create subroutine for cleaning recent interfaces
+
+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]>
+---
+ mDNSPosix/mDNSPosix.c | 24 ++++++++++++++----------
+ 1 file changed, 14 insertions(+), 10 deletions(-)
+
+diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
+index 0e10bd5..ffc9696 100644
+--- a/mDNSPosix/mDNSPosix.c
++++ b/mDNSPosix/mDNSPosix.c
+@@ -856,6 +856,19 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
+     return err;
+ }
+ 
++// Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
++mDNSlocal void CleanRecentInterfaces(void)
++{
++    PosixNetworkInterface **ri = &gRecentInterfaces;
++    const mDNSs32 utc = mDNSPlatformUTC();
++    while (*ri)
++    {
++        PosixNetworkInterface *pi = *ri;
++        if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
++        else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); }
++    }
++}
++
+ // Creates a PosixNetworkInterface for the interface whose IP address is
+ // intfAddr and whose name is intfName and registers it with mDNS core.
+ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex)
+@@ -1010,16 +1023,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m)
+ 
+     // Clean up.
+     if (intfList != NULL) free_ifi_info(intfList);
+-
+-    // Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
+-    PosixNetworkInterface **ri = &gRecentInterfaces;
+-    const mDNSs32 utc = mDNSPlatformUTC();
+-    while (*ri)
+-    {
+-        PosixNetworkInterface *pi = *ri;
+-        if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
+-        else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); }
+-    }
++    CleanRecentInterfaces();
+ 
+     return err;
+ }
+-- 
+2.17.1
+
meta-networking/recipes-protocols/mdns/files/0002-Create-subroutine-for-tearing-down-an-interface.patch new file +58 -0

58 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0003-Track-interface-socket-family.patch new file +50 -0

50 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0004-Use-list-for-changed-interfaces.patch new file +177 -0

177 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0005-Handle-noisy-netlink-sockets.patch new file +212 -0

212 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0006-Remove-unneeded-function.patch new file +51 -0

51 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0007-Indicate-loopback-interface-to-mDNS-core.patch new file +129 -0

129 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0008-Mark-deleted-interfaces-as-being-changed.patch new file +39 -0
new file mode 100644
index 000000000..fdc5105cb
@@ -0,0 +1,39 @@
+From 0fcc0f210f3a9310a1963de640b384ce866410fd Mon Sep 17 00:00:00 2001
+From: Nate Karstens <[email protected]>
+Date: Wed, 9 Aug 2017 09:16:58 -0500
+Subject: [PATCH 08/11] Mark deleted interfaces as being changed
+
+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]>
+---
+ mDNSPosix/mDNSPosix.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
+index 798ab10..a8a57df 100644
+--- a/mDNSPosix/mDNSPosix.c
++++ b/mDNSPosix/mDNSPosix.c
+@@ -1163,7 +1163,7 @@ mDNSlocal void          ProcessRoutingNotification(int sd, GenLinkedList *change
+ #endif
+ 
+         // Process the NetLink message
+-        if (pNLMsg->nlmsg_type == RTM_GETLINK || pNLMsg->nlmsg_type == RTM_NEWLINK)
++        if (pNLMsg->nlmsg_type == RTM_DELLINK || pNLMsg->nlmsg_type == RTM_NEWLINK)
+             AddInterfaceIndexToList(changedInterfaces, ((struct ifinfomsg*) NLMSG_DATA(pNLMsg))->ifi_index);
+         else if (pNLMsg->nlmsg_type == RTM_DELADDR || pNLMsg->nlmsg_type == RTM_NEWADDR)
+             AddInterfaceIndexToList(changedInterfaces, ((struct ifaddrmsg*) NLMSG_DATA(pNLMsg))->ifa_index);
+-- 
+2.17.1
+
meta-networking/recipes-protocols/mdns/files/0009-Fix-possible-NULL-dereference.patch new file +45 -0

45 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0010-Handle-errors-from-socket-calls.patch new file +62 -0

62 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/files/0011-Change-a-dynamic-allocation-to-file-scope-variable.patch new file +51 -0

51 lines not on this page · raw message

meta-networking/recipes-protocols/mdns/mdns_878.260.1.bb +11 -0
index 017894531..a5991bf73 100644
@@ -11,6 +11,17 @@ RPROVIDES_${PN} += "libdns_sd.so"
 SRC_URI = "https://opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-${PV}.tar.gz \
            file://build.patch;patchdir=.. \
            file://mdns.service \
+           file://0001-Create-subroutine-for-cleaning-recent-interfaces.patch;patchdir=.. \
+           file://0002-Create-subroutine-for-tearing-down-an-interface.patch;patchdir=.. \
+           file://0003-Track-interface-socket-family.patch;patchdir=.. \
+           file://0004-Use-list-for-changed-interfaces.patch;patchdir=.. \
+           file://0005-Handle-noisy-netlink-sockets.patch;patchdir=.. \
+           file://0006-Remove-unneeded-function.patch;patchdir=.. \
+           file://0007-Indicate-loopback-interface-to-mDNS-core.patch;patchdir=.. \
+           file://0008-Mark-deleted-interfaces-as-being-changed.patch;patchdir=.. \
+           file://0009-Fix-possible-NULL-dereference.patch;patchdir=.. \
+           file://0010-Handle-errors-from-socket-calls.patch;patchdir=.. \
+           file://0011-Change-a-dynamic-allocation-to-file-scope-variable.patch;patchdir=.. \
            "
 SRC_URI[md5sum] = "aeb92d838a4aa2402ef128ed501484eb"
 SRC_URI[sha256sum] = "3cc71582e8eee469c2de8ecae1d769e7f32b3468dfb7f2ca77f1dee1f30a7d1e"
Signature · 1 line
2.21.0