chore(all): replace net.IP with netip.Addr
This commit is contained in:
14
internal/configuration/sources/env/dns.go
vendored
14
internal/configuration/sources/env/dns.go
vendored
@@ -2,7 +2,7 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
@@ -26,19 +26,19 @@ func (s *Source) readDNS() (dns settings.DNS, err error) {
|
||||
return dns, nil
|
||||
}
|
||||
|
||||
func (s *Source) readDNSServerAddress() (address net.IP, err error) {
|
||||
func (s *Source) readDNSServerAddress() (address netip.Addr, err error) {
|
||||
key, value := s.getEnvWithRetro("DNS_ADDRESS", "DNS_PLAINTEXT_ADDRESS")
|
||||
if value == "" {
|
||||
return nil, nil
|
||||
return address, nil
|
||||
}
|
||||
|
||||
address = net.ParseIP(value)
|
||||
if address == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s", key, ErrIPAddressParse, value)
|
||||
address, err = netip.ParseAddr(value)
|
||||
if err != nil {
|
||||
return address, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
}
|
||||
|
||||
// TODO remove in v4
|
||||
if !address.Equal(net.IPv4(127, 0, 0, 1)) { //nolint:gomnd
|
||||
if address.Unmap().Compare(netip.AddrFrom4([4]byte{127, 0, 0, 1})) != 0 {
|
||||
s.warner.Warn(key + " is set to " + value +
|
||||
" so the DNS over TLS (DoT) server will not be used." +
|
||||
" The default value changed to 127.0.0.1 so it uses the internal DoT serves." +
|
||||
|
||||
@@ -3,7 +3,7 @@ package env
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -113,16 +113,15 @@ var (
|
||||
ErrInvalidIP = errors.New("invalid IP address")
|
||||
)
|
||||
|
||||
func (s *Source) readOpenVPNTargetIP() (ip net.IP, err error) {
|
||||
func (s *Source) readOpenVPNTargetIP() (ip netip.Addr, err error) {
|
||||
envKey, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", "OPENVPN_TARGET_IP")
|
||||
if value == "" {
|
||||
return nil, nil
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
ip = net.ParseIP(value)
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s",
|
||||
envKey, ErrInvalidIP, value)
|
||||
ip, err = netip.ParseAddr(value)
|
||||
if err != nil {
|
||||
return ip, fmt.Errorf("environment variable %s: %w", envKey, err)
|
||||
}
|
||||
|
||||
return ip, nil
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/port"
|
||||
@@ -26,18 +25,15 @@ func (s *Source) readWireguardSelection() (
|
||||
return selection, nil
|
||||
}
|
||||
|
||||
var ErrIPAddressParse = errors.New("cannot parse IP address")
|
||||
|
||||
func (s *Source) readWireguardEndpointIP() (endpointIP net.IP, err error) {
|
||||
func (s *Source) readWireguardEndpointIP() (endpointIP netip.Addr, err error) {
|
||||
key, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", "WIREGUARD_ENDPOINT_IP")
|
||||
if value == "" {
|
||||
return nil, nil
|
||||
return endpointIP, nil
|
||||
}
|
||||
|
||||
endpointIP = net.ParseIP(value)
|
||||
if endpointIP == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s",
|
||||
key, ErrIPAddressParse, value)
|
||||
endpointIP, err = netip.ParseAddr(value)
|
||||
if err != nil {
|
||||
return endpointIP, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
}
|
||||
|
||||
return endpointIP, nil
|
||||
|
||||
Reference in New Issue
Block a user