Feat: WIREGUARD_PORT for Mullvad
This commit is contained in:
@@ -40,7 +40,12 @@ func (settings *Provider) readMullvad(r reader) (err error) {
|
|||||||
return fmt.Errorf("environment variable OWNED: %w", err)
|
return fmt.Errorf("environment variable OWNED: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings.ServerSelection.OpenVPN.readMullvad(r.env)
|
err = settings.ServerSelection.OpenVPN.readMullvad(r.env)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings.ServerSelection.Wireguard.readMullvad(r.env)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (settings *OpenVPNSelection) readMullvad(env params.Interface) (err error) {
|
func (settings *OpenVPNSelection) readMullvad(env params.Interface) (err error) {
|
||||||
@@ -57,3 +62,12 @@ func (settings *OpenVPNSelection) readMullvad(env params.Interface) (err error)
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (settings *WireguardSelection) readMullvad(env params.Interface) (err error) {
|
||||||
|
settings.CustomPort, err = readWireguardCustomPort(env, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ func readOpenVPNCustomPort(env params.Interface, tcp bool,
|
|||||||
ErrInvalidPort, port, portsToString(allowedUDP))
|
ErrInvalidPort, port, portsToString(allowedUDP))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// note: set allowed to an empty slice to allow all valid ports
|
||||||
func readWireguardCustomPort(env params.Interface, allowed []uint16) (port uint16, err error) {
|
func readWireguardCustomPort(env params.Interface, allowed []uint16) (port uint16, err error) {
|
||||||
port, err = readPortOrZero(env, "WIREGUARD_PORT")
|
port, err = readPortOrZero(env, "WIREGUARD_PORT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -175,11 +176,16 @@ func readWireguardCustomPort(env params.Interface, allowed []uint16) (port uint1
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(allowed) == 0 {
|
||||||
|
return port, nil
|
||||||
|
}
|
||||||
|
|
||||||
for i := range allowed {
|
for i := range allowed {
|
||||||
if allowed[i] == port {
|
if allowed[i] == port {
|
||||||
return port, nil
|
return port, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, fmt.Errorf(
|
return 0, fmt.Errorf(
|
||||||
"environment variable WIREGUARD_PORT: %w: port %d, can only be one of %s",
|
"environment variable WIREGUARD_PORT: %w: port %d, can only be one of %s",
|
||||||
ErrInvalidPort, port, portsToString(allowed))
|
ErrInvalidPort, port, portsToString(allowed))
|
||||||
|
|||||||
Reference in New Issue
Block a user