@@ -21,7 +21,7 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"math"
24
- "net"
24
+ "net/netip "
25
25
"reflect"
26
26
"strconv"
27
27
"strings"
@@ -255,11 +255,12 @@ func getTargetsFromTargetAnnotation(annotations map[string]string) endpoint.Targ
255
255
}
256
256
257
257
// suitableType returns the DNS resource record type suitable for the target.
258
- // In this case type A for IPs and type CNAME for everything else.
258
+ // In this case type A/AAAA for IPs and type CNAME for everything else.
259
259
func suitableType (target string ) string {
260
- if net .ParseIP (target ) != nil && net .ParseIP (target ).To4 () != nil {
260
+ netIP , err := netip .ParseAddr (target )
261
+ if err == nil && netIP .Is4 () {
261
262
return endpoint .RecordTypeA
262
- } else if net . ParseIP ( target ) != nil && net . ParseIP ( target ). To16 () != nil {
263
+ } else if err == nil && netIP . Is6 () {
263
264
return endpoint .RecordTypeAAAA
264
265
}
265
266
return endpoint .RecordTypeCNAME
@@ -276,14 +277,8 @@ func endpointsForHostname(hostname string, targets endpoint.Targets, ttl endpoin
276
277
for _ , t := range targets {
277
278
switch suitableType (t ) {
278
279
case endpoint .RecordTypeA :
279
- if isIPv6String (t ) {
280
- continue
281
- }
282
280
aTargets = append (aTargets , t )
283
281
case endpoint .RecordTypeAAAA :
284
- if ! isIPv6String (t ) {
285
- continue
286
- }
287
282
aaaaTargets = append (aaaaTargets , t )
288
283
default :
289
284
cnameTargets = append (cnameTargets , t )
@@ -387,9 +382,3 @@ func waitForDynamicCacheSync(ctx context.Context, factory dynamicInformerFactory
387
382
}
388
383
return nil
389
384
}
390
-
391
- // isIPv6String returns if ip is IPv6.
392
- func isIPv6String (ip string ) bool {
393
- netIP := net .ParseIP (ip )
394
- return netIP != nil && netIP .To4 () == nil
395
- }
0 commit comments