packetforward

package module
v0.0.0-...-c68a447 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

README

packetforward GoDoc Build Status Coverage Status

A library for forwarding packets.

Dependencies

This library uses Go modules. When running commands like go test in this repository, make sure the GO111MODULE environment variable is set to 'on'. See the go command documentation for more details. If you are running Go 1.13 or later, this should not be necessary as the Go tool will support modules by default.

Testing

Tests in this package require root access. The easiest way to test is to compile the tests with go test -c and run the output binary using the sudo command.

Be careful if you choose to run the Go tool with the sudo command (e.g. sudo go test). This can cause issues if the tool attempts to download missing dependencies. Namely, the Go tool may not be able to download anything as Git will likely be using a different SSH keypair (or no keypair at all). Worse, the Go tool may create folders in $GOPATH/pkg/mod/cache owned by the root user. This can disrupt future use of the Go tool, even outside of this repository.

Demo

This repository includes a demo client and server in demo/client and demo/server.

The server forwards TCP and UDP packets to hardcoded IP addresses configured with the -tcpdest and -udpdest flags.

The client opens a TUN device.

For example:

sudo iptables -d OUTPUT -p tcp -m conntrack --ctstate ESTABLISHED --ctdir ORIGINAL --tcp-flags RST RST -j DROP
cd demo/server
go build && sudo ./server
cd demo/client
go build && sudo ./client
curl http://10.0.0.1/1GB.zip > /dev/null

Documentation

Overview

packetforward provides a mechanism for forwarding IP packets from a client to a NAT server, which in turn proxies them to their final destination.

- Clients are uniquely identified by a random UUID. - Clients connect to the server using a configurable dial function. - In the event of a disconnect, clients can reconnect with the same client ID - Interrupted and resumed client connections do not disconnect the clients' TCP connections to the origin - Currently, packetforward supports only TCP and UDP

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(downstream io.Writer, idleTimeout time.Duration, dialServer DialFunc) io.WriteCloser

Client creates a new packetforward client and returns a WriteCloser. Consumers of packetforward should write whole IP packets to this WriteCloser. The packetforward client will write response packets to the specified downstream Writer. idleTimeout specifies a timeout for idle clients. When the client to server connection remains idle for longer than idleTimeout, it is automatically closed. dialServer configures how to connect to the packetforward server. When packetforwarding is no longer needed, consumers should Close the returned WriteCloser to clean up any outstanding resources.

Types

type DialFunc

type DialFunc func(ctx context.Context) (net.Conn, error)

DialFunc is a function that dials a server, preferrably respecting any timeout in the provided Context.

Directories

Path Synopsis
demo
server provides the server end of packetforward functionality.
server provides the server end of packetforward functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL