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

@@ -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))