My_nat.free_udp_port: avoid looping forever, use last_resort_port earlier

This commit is contained in:
Hannes Mehnert 2022-11-08 18:57:09 +01:00
parent d094b20950
commit e8e03fe6a6

View File

@ -44,7 +44,10 @@ let pick_free_port t proto =
go 10
let free_udp_port t ~src ~dst ~dst_port =
let rec go () =
let rec go retries =
if retries = 0 then
t.last_resort_port, Fun.id
else
let src_port =
Option.value ~default:t.last_resort_port (pick_free_port t `Udp)
in
@ -57,9 +60,9 @@ let free_udp_port t ~src ~dst ~dst_port =
in
src_port, remove
end else
go ()
go (retries - 1)
in
go ()
go 10
let dns_port t port = S.mem port t.udp_dns || port = t.last_resort_port