NetBSD Problem Report #56263
From www@netbsd.org Sun Jun 20 13:38:22 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id DF1411A921F
for <gnats-bugs@gnats.NetBSD.org>; Sun, 20 Jun 2021 13:38:22 +0000 (UTC)
Message-Id: <20210620133821.BCE871A923D@mollari.NetBSD.org>
Date: Sun, 20 Jun 2021 13:38:21 +0000 (UTC)
From: andrew@ugh.net.au
Reply-To: andrew@ugh.net.au
To: gnats-bugs@NetBSD.org
Subject: mdnsd advertises link-local addresses in non-standard KAME format
X-Send-Pr-Version: www-1.0
>Number: 56263
>Category: bin
>Synopsis: mdnsd advertises link-local addresses in non-standard KAME format
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jun 20 13:40:00 +0000 2021
>Originator: Andrew Stevenson
>Release: 9.99.83
>Organization:
>Environment:
NetBSD 3dp 9.99.83 NetBSD 9.99.83 (RPI) #0: Sun Jun 6 18:37:20 UTC 2021 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/evbarm/compile/RPI evbarm
>Description:
mdnsd advertises the link local address obtained from getifaddrs() however this is in the non-standard KAME format where the scope ID is embedded in bytes 3 & 4.
I'm not sure getifaddrs() should be returning it in that format but as it does it is important that mdnsd regularises it (i.e. sets these bytes to 0) before putting it on the wire. In my limited testing BSD based systems seem to handle it (zeroing the bytes themselves) but Linux machines using systems-resolved do not. They are therefore unable to contact NetBSD machines using the IPv6 link local address.
mdnsd is contributed code from Apple but IIUC the fix needs to be in mDNSBSD.c which I don't see in the upstream distribution.
>How-To-Repeat:
Run mdnsd on NetBSD.
Look at the mdns packets on the wire and see the AAAA address advertised does not match that you see with ifconfig.
OR
From a linux machine using systems-resolved try ping -6 "netbsd.local". The address used will have bits set in the 4th byte and won't match what you see with ifconfig on the NetBSD machine. The ping will timeout.
>Fix:
--- external/apache2/mDNSResponder/dist/mDNSPosix/mDNSBSD.c.orig 2021-06-20 13:32:59.522315787 +0000
+++ external/apache2/mDNSResponder/dist/mDNSPosix/mDNSBSD.c 2021-06-20 13:33:37.814346492 +0000
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
+#include <netinet6/in6.h>
#include <net/if_dl.h>
static int
@@ -112,6 +113,17 @@
if (!copyaddr(&ifi->ifi_netmask, ifa->ifa_netmask, sa->sa_len))
goto gotError;
+ if (sa->sa_family == AF_INET6) {
+ struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)(ifi->ifi_addr);
+ if (IN6_IS_ADDR_LINKLOCAL(&(sa6->sin6_addr))) {
+ // KAME encodes the zone ID in the 3rd and 4th byte of a link
+ // local address but we musn't leak that to the outside world.
+ // BSD derived systems will cope but e.g. systemd systems will
+ // not
+ sa6->sin6_addr.__u6_addr.__u6_addr16[1] = 0;
+ }
+ }
+
if ((flags & IFF_BROADCAST) && !copyaddr(&ifi->ifi_brdaddr,
ifa->ifa_broadaddr, sa->sa_len))
goto gotError;
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.