Skip to content

Commit

Permalink
ipn/warp: m impl & use ipok fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Nov 28, 2024
1 parent 3863b61 commit 370269d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions intra/ipn/warp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func WarpEndpoints() (v4 netip.AddrPort, v6 netip.AddrPort, err error) {
err = core.JoinErr(err4, err6)
return
}
v4ok, v6ok := ip4.IsValid(), ip6.IsValid()
v4ok, v6ok := ipok(ip4), ipok(ip6)
if !v4ok && !v6ok {
err = errZeroRandomEp
return
Expand All @@ -149,13 +149,14 @@ func WarpEndpoints() (v4 netip.AddrPort, v6 netip.AddrPort, err error) {
func AmzEndpoints() (v4 []netip.AddrPort, v6 []netip.AddrPort, err error) {
var v4ok, v6ok bool
for _, ip := range dialers.For(agwProdUrl) {
if ip.IsValid() && ip.Is4() && !ip.IsUnspecified() {
v4 = append(v4, netip.AddrPortFrom(ip, uint16(80)))
v4ok = true
}
if ip.IsValid() && ip.Is6() && !ip.IsUnspecified() {
v6 = append(v6, netip.AddrPortFrom(ip, uint16(80)))
v6ok = true
if ipok(ip) {
if ip.Is4() {
v4 = append(v4, netip.AddrPortFrom(ip, uint16(80)))
v4ok = true
} else if ip.Is6() {
v6 = append(v6, netip.AddrPortFrom(ip, uint16(80)))
v6ok = true
}
}
}
if !v4ok && !v6ok {
Expand All @@ -167,7 +168,7 @@ func AmzEndpoints() (v4 []netip.AddrPort, v6 []netip.AddrPort, err error) {
func Exit64Endpoints() (v6 []netip.Addr, errs error) {
for _, cidr6 := range Net6to4 {
if ip6, err := core.RandomIPFromPrefix(cidr6); err == nil {
if ip6.IsValid() && !ip6.IsUnspecified() {
if ipok(ip6) {
v6 = append(v6, ip6)
} // else: discard
} else {
Expand All @@ -179,3 +180,7 @@ func Exit64Endpoints() (v6 []netip.Addr, errs error) {
}
return v6, nil
}

func ipok(ip netip.Addr) bool {
return ip.IsValid() && !ip.IsUnspecified()
}

0 comments on commit 370269d

Please sign in to comment.