-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from hannesm/next
Next release: 0.8.3
- Loading branch information
Showing
10 changed files
with
104 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
(* Copyright (C) 2015, Thomas Leonard <[email protected]> | ||
See the README file for details. *) | ||
|
||
open Lwt.Infix | ||
|
||
let src = Logs.Src.create "my-nat" ~doc:"NAT shim" | ||
module Log = (val Logs.src_log src : Logs.LOG) | ||
|
||
|
@@ -46,22 +44,25 @@ let pick_free_port t proto = | |
go 10 | ||
|
||
let free_udp_port t ~src ~dst ~dst_port = | ||
let rec go () = | ||
let src_port = | ||
Option.value ~default:t.last_resort_port (pick_free_port t `Udp) | ||
in | ||
if Nat.is_port_free t.table `Udp ~src ~dst ~src_port ~dst_port then begin | ||
let remove = | ||
if src_port <> t.last_resort_port then begin | ||
t.udp_dns <- S.add src_port t.udp_dns; | ||
(fun () -> t.udp_dns <- S.remove src_port t.udp_dns) | ||
end else Fun.id | ||
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 | ||
src_port, remove | ||
end else | ||
go () | ||
if Nat.is_port_free t.table `Udp ~src ~dst ~src_port ~dst_port then begin | ||
let remove = | ||
if src_port <> t.last_resort_port then begin | ||
t.udp_dns <- S.add src_port t.udp_dns; | ||
(fun () -> t.udp_dns <- S.remove src_port t.udp_dns) | ||
end else Fun.id | ||
in | ||
src_port, remove | ||
end else | ||
go (retries - 1) | ||
in | ||
go () | ||
go 10 | ||
|
||
let dns_port t port = S.mem port t.udp_dns || port = t.last_resort_port | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters