net/dns: work around old systemd-resolved setLinkDomain length limit

Don't set all the *.arpa. reverse DNS lookup domains if systemd-resolved
is old and can't handle them.

Fixes #3188

Change-Id: I283f8ce174daa8f0a972ac7bfafb6ff393dde41d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/3328/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 9fa6cdf7bf
commit 400ed799e6

@ -12,6 +12,7 @@ import (
"errors"
"fmt"
"net"
"strings"
"github.com/godbus/dbus/v5"
"golang.org/x/sys/unix"
@ -171,6 +172,14 @@ func (m *resolvedManager) SetDNS(config OSConfig) error {
ctx, "org.freedesktop.resolve1.Manager.SetLinkDomains", 0,
m.ifidx, linkDomains,
).Store()
if err != nil && err.Error() == "Argument list too long" { // TODO: better error match
// Issue 3188: older systemd-resolved had argument length limits.
// Trim out the *.arpa. entries and try again.
err = m.resolved.CallWithContext(
ctx, "org.freedesktop.resolve1.Manager.SetLinkDomains", 0,
m.ifidx, linkDomainsWithoutReverseDNS(linkDomains),
).Store()
}
if err != nil {
return fmt.Errorf("setLinkDomains: %w", err)
}
@ -234,3 +243,16 @@ func (m *resolvedManager) Close() error {
return nil
}
// linkDomainsWithoutReverseDNS returns a copy of v without
// *.arpa. entries.
func linkDomainsWithoutReverseDNS(v []resolvedLinkDomain) (ret []resolvedLinkDomain) {
for _, d := range v {
if strings.HasSuffix(d.Domain, ".arpa.") {
// Oh well. At least the rest will work.
continue
}
ret = append(ret, d)
}
return ret
}

Loading…
Cancel
Save