Skip to content

Commit

Permalink
Disable use provider IP if ip is IPv6 and IPv6 suffix is set
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 29, 2024
1 parent cfced19 commit 1a4895b
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 34 deletions.
7 changes: 4 additions & 3 deletions internal/provider/providers/allinkl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("host", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
if ip.Is6() { // ipv6
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
if ip.Is6() {
values.Set("myip6", ip.String())
} else {
values.Set("myip", ip.String())
Expand Down Expand Up @@ -178,7 +179,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}

newIP = ips[0]
if !p.useProviderIP && ip.Compare(newIP) != 0 {
if !useProviderIP && ip.Compare(newIP) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/dd24/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
values := url.Values{}
values.Set("hostname", p.BuildDomainName())
values.Set("password", p.password)
if p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if useProviderIP {
values.Set("ip", "auto")
} else {
values.Set("ip", ip.String())
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/ddnss/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
values.Set("user", p.username)
values.Set("pwd", p.password)
values.Set("host", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
ipKey := "ip"
if p.dualStack && ip.Is6() { // ipv6 update for dual stack
ipKey = "ip6"
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/desec/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/providers/dnsomatic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
User: url.UserPassword(p.username, p.password),
}
values := url.Values{}
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if useProviderIP {
values.Set("myip", ip.String())
}
values.Set("wildcard", "NOCHG")
Expand Down Expand Up @@ -179,7 +180,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}

newIP = ips[0]
if !p.useProviderIP && ip.Compare(newIP) != 0 {
if !useProviderIP && ip.Compare(newIP) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/providers/duckdns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ func New(data json.RawMessage, _, host string,
var tokenRegex = regexp.MustCompile(`^[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12}$`)

func (p *Provider) isValid() error {
if !tokenRegex.MatchString(p.token) {
switch {
case !tokenRegex.MatchString(p.token):
return fmt.Errorf("%w: token %q does not match regex %q",
errors.ErrTokenNotValid, p.token, tokenRegex)
}
switch p.host {
case "@", "*":
case p.host == "@", p.host == "*":
return fmt.Errorf("%w: %q is not valid",
errors.ErrHostOnlySubdomain, p.host)
}
Expand Down Expand Up @@ -114,7 +113,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
values.Set("verbose", "true")
values.Set("domains", p.host)
values.Set("token", p.token)
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
if ip.Is6() {
values.Set("ipv6", ip.String())
} else {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
return netip.Addr{}, fmt.Errorf("%w", errors.ErrReceivedNoIP)
}
newIP = ips[0]
if !p.useProviderIP && newIP.Compare(ip) != 0 {
if !useProviderIP && newIP.Compare(ip) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/dynu/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
values.Set("location", p.group)
hostname := utils.BuildDomainName(p.host, p.domain)
values.Set("hostname", hostname)
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
if ip.Is6() {
values.Set("myipv6", ip.String())
} else {
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/dynv6/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
values.Set("token", p.token)
values.Set("zone", utils.BuildURLQueryHostname(p.host, p.domain))
ipValue := ip.String()
if p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if useProviderIP {
ipValue = "auto"
}
if isIPv4 {
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/easydns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
if p.host == "*" {
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/providers/he/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", fqdn)
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down Expand Up @@ -154,7 +155,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}

newIP = ips[0]
if !p.useProviderIP && ip.Compare(newIP) != 0 {
if !useProviderIP && ip.Compare(newIP) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/providers/infomaniak/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down Expand Up @@ -159,7 +160,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
if err != nil {
return netip.Addr{}, fmt.Errorf("%w: for response %q: %w",
errors.ErrIPReceivedMalformed, ipString, err)
} else if !p.useProviderIP && ip.Compare(newIP) != 0 {
} else if !useProviderIP && ip.Compare(newIP) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/providers/njalla/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
values.Set("h", utils.BuildURLQueryHostname(p.host, p.domain))
values.Set("k", p.key)
updatingIP6 := ip.Is6()
if p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if useProviderIP {
values.Set("auto", "")
} else {
if updatingIP6 {
Expand Down Expand Up @@ -154,7 +155,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
newIP, err = netip.ParseAddr(ipString)
if err != nil {
return netip.Addr{}, fmt.Errorf("%w: %w", errors.ErrIPReceivedMalformed, err)
} else if !p.useProviderIP && ip.Compare(newIP) != 0 {
} else if !useProviderIP && ip.Compare(newIP) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/providers/noip/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
if ip.Is6() {
values.Set("myipv6", ip.String())
} else {
Expand Down Expand Up @@ -177,12 +178,12 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
ips = ipextract.IPv6(s)
}

if !p.useProviderIP && len(ips) == 0 {
if !useProviderIP && len(ips) == 0 {
return netip.Addr{}, fmt.Errorf("%w", errors.ErrReceivedNoIP)
}

newIP = ips[0]
if !p.useProviderIP && ip.Compare(newIP) != 0 {
if !useProviderIP && ip.Compare(newIP) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/providers/nowdns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add

values := url.Values{}
values.Set("hostname", p.domain)
if !p.useProviderIP {
if !p.useProviderIP || (ip.Is6() && p.ipv6Suffix.IsValid()) {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/providers/opendns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down Expand Up @@ -148,7 +149,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
newIP, err = netip.ParseAddr(responseIPString)
if err != nil {
return netip.Addr{}, fmt.Errorf("%w: %w", errors.ErrIPReceivedMalformed, err)
} else if !p.useProviderIP && newIP.Compare(ip) != 0 {
} else if !useProviderIP && newIP.Compare(ip) != 0 {
return netip.Addr{}, fmt.Errorf("%w: sent ip %s to update but received %s",
errors.ErrIPReceivedMismatch, ip, newIP)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/ovh/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func (p *Provider) updateWithDynHost(ctx context.Context, client *http.Client,
values := url.Values{}
values.Set("system", "dyndns")
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/selfhostde/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/strato/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
u.RawQuery = values.Encode()
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/variomedia/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func (p *Provider) HTML() models.HTMLRow {

func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Addr) (newIP netip.Addr, err error) {
host := "dyndns.variomedia.de"
if p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if useProviderIP {
if ip.Is6() {
host = "dyndns6.variomedia.de"
} else {
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/providers/zoneedit/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
values := url.Values{}
values.Set("hostname", utils.BuildURLQueryHostname(p.host, p.domain))
if !p.useProviderIP {
useProviderIP := p.useProviderIP && (ip.Is4() || !p.ipv6Suffix.IsValid())
if !useProviderIP {
values.Set("myip", ip.String())
}
if p.host == "*" {
Expand Down

0 comments on commit 1a4895b

Please sign in to comment.