diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-09 18:45:12 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-09 18:45:12 +0100 |
commit | 30b96ba083e4ef61051f125770b50bd278712539 (patch) | |
tree | 285947e5f050849dcbb26d5ee2489e26b4946be3 /conn/conn_linux.go | |
parent | 78ebce69324e241d462d624cae389396db9dbd94 (diff) | |
download | wireguard-go-30b96ba083e4ef61051f125770b50bd278712539.tar.gz wireguard-go-30b96ba083e4ef61051f125770b50bd278712539.zip |
conn: try harder to have v4 and v6 ports agree
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | conn/conn_linux.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/conn/conn_linux.go b/conn/conn_linux.go index f6638dd..716028f 100644 --- a/conn/conn_linux.go +++ b/conn/conn_linux.go @@ -104,7 +104,11 @@ func createBind(port uint16) (Bind, uint16, error) { var err error var bind nativeBind var newPort uint16 + var tries int + originalPort := port +again: + port = originalPort // Attempt ipv6 bind, update port if successful. bind.sock6, newPort, err = create6(port) if err != nil { @@ -118,6 +122,10 @@ func createBind(port uint16) (Bind, uint16, error) { // Attempt ipv4 bind, update port if successful. bind.sock4, newPort, err = create4(port) if err != nil { + if originalPort == 0 && err == syscall.EADDRINUSE && tries < 100 { + tries++ + goto again + } if err != syscall.EAFNOSUPPORT { unix.Close(bind.sock6) return nil, 0, err |