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
"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
+}
