Skip to content

Commit

Permalink
fix: allow ipv4-mapped ipv6 addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Kreitzer <[email protected]>
  • Loading branch information
buroa committed Dec 11, 2024
1 parent fe2924b commit 7092b9d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"fmt"
"math"
"net"
"net/netip"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -257,9 +257,10 @@ func getTargetsFromTargetAnnotation(annotations map[string]string) endpoint.Targ
// suitableType returns the DNS resource record type suitable for the target.
// In this case type A for IPs and type CNAME for everything else.
func suitableType(target string) string {
if net.ParseIP(target) != nil && net.ParseIP(target).To4() != nil {
netIP, err := netip.ParseAddr(target)
if err == nil && netIP.Is4() {
return endpoint.RecordTypeA
} else if net.ParseIP(target) != nil && net.ParseIP(target).To16() != nil {
} else if err == nil && netIP.Is6() {
return endpoint.RecordTypeAAAA
}
return endpoint.RecordTypeCNAME
Expand Down Expand Up @@ -390,6 +391,6 @@ func waitForDynamicCacheSync(ctx context.Context, factory dynamicInformerFactory

// isIPv6String returns if ip is IPv6.
func isIPv6String(ip string) bool {
netIP := net.ParseIP(ip)
return netIP != nil && netIP.To4() == nil
netIP, err := netip.ParseAddr(ip)
return err == nil && netIP.Is6()
}

0 comments on commit 7092b9d

Please sign in to comment.