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

network/ovn: LXD does not create records for reverse DNS. #14812

Open
fnordahl opened this issue Jan 17, 2025 · 3 comments
Open

network/ovn: LXD does not create records for reverse DNS. #14812

fnordahl opened this issue Jan 17, 2025 · 3 comments
Assignees
Milestone

Comments

@fnordahl
Copy link
Member

The OVN DNS interception supports providing answers for both forward and reverse DNS lookups on instance names.

However, LXD does currently not populate the database with reverse DNS records.

This causes issues for software that rely on correct reverse DNS lookups to determine FQDN.

Something like this could potentially fix it:

diff --git a/lxd/network/openvswitch/ovn.go b/lxd/network/openvswitch/ovn.go
index d15d508253..ff9879d8ae 100644
--- a/lxd/network/openvswitch/ovn.go
+++ b/lxd/network/openvswitch/ovn.go
@@ -4,6 +4,7 @@ import (
        "context"
        "fmt"
        "net"
+       "netip"
        "os"
        "strconv"
        "strings"
@@ -1377,6 +1378,7 @@ func (o *OVN) LogicalSwitchPortSetDNS(switchName OVNSwitch, portName OVNSwitchPo
 
        // Only include DNS name record if IPs supplied.
        if len(dnsIPs) > 0 {
+               lowerDnsName := strings.ToLower(dnsName)
                var dnsIPsStr strings.Builder
                for i, dnsIP := range dnsIPs {
                        if i > 0 {
@@ -1386,7 +1388,17 @@ func (o *OVN) LogicalSwitchPortSetDNS(switchName OVNSwitch, portName OVNSwitchPo
                        dnsIPsStr.WriteString(dnsIP.String())
                }
 
-               cmdArgs = append(cmdArgs, fmt.Sprintf(`records={"%s"="%s"}`, strings.ToLower(dnsName), dnsIPsStr.String()))
+               cmdArgs = append(cmdArgs, fmt.Sprintf(`records={"%s"="%s"`, lowerDnsName, dnsIPsStr.String()))
+
+               for i, dnsIP = range dnsIPs {
+                       addr, ok := netip.AddrFromSlice(dnsIP)
+                       if addr.Is6() {
+                               cmdArgs = append(cmdArgs, fmt.Sprintf(`,"%s"="%s"`, reverse6(dnsIP.String(), lowerDnsName)))
+                       } else {
+                               cmdArgs = append(cmdArgs, fmt.Sprintf(`,"%s"="%s"`, reverse(dnsIP.String(), lowerDnsName)))
+                       }
+               }
+               cmdArgs = append(cmdArgs, "}")
        }
 
        dnsUUID = strings.TrimSpace(dnsUUID)
@tomponline
Copy link
Member

Thanks @fnordahl indeed I have tested this with a manually patched OVN dns record entry and it works.

We just need to come up with an implementation (or use an external one) for reverse and reverse6 functions.

@tomponline tomponline added this to the lxd-6.3 milestone Jan 17, 2025
@fnordahl
Copy link
Member Author

They are already in https://github.com/canonical/lxd/blob/main/shared/dnsutil/dnsutil.go :)

@tomponline
Copy link
Member

They are already in https://github.com/canonical/lxd/blob/main/shared/dnsutil/dnsutil.go :)

Excellent, and its my own function from 6 years ago :)

@tomponline tomponline self-assigned this Jan 17, 2025
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

No branches or pull requests

2 participants