Feat: WIREGUARD_PORT for Mullvad

This commit is contained in:
Quentin McGaw (desktop)
2021-08-23 16:00:40 +00:00
parent f41fec57ed
commit eb6238ee52
2 changed files with 21 additions and 1 deletions

View File

@@ -40,7 +40,12 @@ func (settings *Provider) readMullvad(r reader) (err error) {
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) {
@@ -57,3 +62,12 @@ func (settings *OpenVPNSelection) readMullvad(env params.Interface) (err error)
return nil
}
func (settings *WireguardSelection) readMullvad(env params.Interface) (err error) {
settings.CustomPort, err = readWireguardCustomPort(env, nil)
if err != nil {
return err
}
return nil
}

View File

@@ -167,6 +167,7 @@ func readOpenVPNCustomPort(env params.Interface, tcp bool,
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) {
port, err = readPortOrZero(env, "WIREGUARD_PORT")
if err != nil {
@@ -175,11 +176,16 @@ func readWireguardCustomPort(env params.Interface, allowed []uint16) (port uint1
return 0, nil
}
if len(allowed) == 0 {
return port, nil
}
for i := range allowed {
if allowed[i] == port {
return port, nil
}
}
return 0, fmt.Errorf(
"environment variable WIREGUARD_PORT: %w: port %d, can only be one of %s",
ErrInvalidPort, port, portsToString(allowed))