Skip to content

Add a mechanism to forward outgoing TCP via a Unix domain socket#590

Merged
djs55 merged 9 commits intomoby:masterfrom
djs55:forward3
Aug 22, 2022
Merged

Add a mechanism to forward outgoing TCP via a Unix domain socket#590
djs55 merged 9 commits intomoby:masterfrom
djs55:forward3

Conversation

@djs55
Copy link
Copy Markdown
Collaborator

@djs55 djs55 commented Jul 27, 2022

This is based on the existing "gateway forwards" mechanism which allowed traffic sent to the gateway to be forwarded.

A forwards.json can be dynamically updated with IP network matches and Unix domain socket / Windows named pipe paths. When a SYN arrives, a request is sent on the Unix domain socket, allowing the server to reject or accept the request. Assuming the connection is accepted, the handshake is completed and traffic flows.

@djs55 djs55 changed the title WIP: Add a mechanism to forward outgoing TCP via a Unix domain socket Add a mechanism to forward outgoing TCP via a Unix domain socket Aug 22, 2022
| `Eof -> Fmt.string ppf "EOF while reading handshake"

let read flow =
FLOW.read_some flow 2 >>= function
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but I think you could replace this >>= with >!= and lose all the Lwt.returns below.

let src_ip =
match Ipaddr.of_string @@ get_string @@ find j [ "src_ip" ] with
| Error (`Msg m) ->
raise (Parse_error (j, "src_ip should be an IPv4 address: " ^ m))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Ipaddr.of_string also parse V6 addresses? Dont you need Ipaddr.V4.of_string here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think in this case the accompanying error message is wrong -- I've been trying to use Ipaddr.t more throughout in preparation for supporting IPv6

src/fs9p/dune Outdated
(name fs9p)
(wrapped false)
(libraries protocol-9p mirage-flow))
(libraries protocol-9p mirage-flow result))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this result package if you use a modern OCaml. 4.08+ (as the lower bound currently is) should be sufficient as Result has been present since then.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes indeed!

Copy link
Copy Markdown
Collaborator

@avsm avsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm just minor comments

djs55 added 9 commits August 22, 2022 14:30
Previously we had
- Endpoint.input_tcp: which handled RST and then called
  intercept_tcp_syn with a default forwarding option (connect to (ip,
  port))
- Endpoint.intercept_tcp_syn: also used by services like the HTTP proxy

The RST handling wasn't clear for the HTTP proxy etc, so rename
intercept_tcp_syn to intercept_tcp and ensure it handles RST packets
too.

Signed-off-by: David Scott <dave@recoil.org>
This is modelled on the existing "Gateway_forwards"

Signed-off-by: David Scott <dave@recoil.org>
This reads and watches the <json path> for configuration updates,
modelled on the existing `--gateway-forwards`

Signed-off-by: David Scott <dave@recoil.org>
We will have a future function which forwards to a Unix socket.

Signed-off-by: David Scott <dave@recoil.org>
Define a simple handshake with a .json-formatted request and response.

Forwards.Stream.connect will take care of making a direct connection
or indirecting via a Unix proxy internally.

Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
It only needs `connect` + usual suspects `read`, `write`, `close` etc

Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
@djs55 djs55 merged commit eda2298 into moby:master Aug 22, 2022
@djs55 djs55 deleted the forward3 branch August 22, 2022 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants