Documentation
¶
Index ¶
- Constants
- func RunTest(t *testing.T, tunDeviceName, tunAddr, tunGW, tunMask string, mtu int, ...)
- func TUNDevice(name, addr, netmask string, mtu int) (io.ReadWriteCloser, error)
- type Addr
- type FiveTuple
- type IPPacket
- type Opts
- type ReadWriter
- type ReadWriterAdapter
- type Server
- type StatsTracker
- func (s *StatsTracker) AcceptedPackets() int
- func (s *StatsTracker) Close() error
- func (s *StatsTracker) DroppedPackets() int
- func (s *StatsTracker) InvalidPackets() int
- func (s *StatsTracker) NumServers() int
- func (s *StatsTracker) NumServersClosed() int
- func (s *StatsTracker) NumServersClosing() int
- func (s *StatsTracker) NumTCPConns() int
- func (s *StatsTracker) NumTCPConnsClosed() int
- func (s *StatsTracker) NumUDPConns() int
- func (s *StatsTracker) NumUDPConnsClosed() int
Constants ¶
const ( // DefaultBufferPoolSize is 10 MB DefaultBufferPoolSize = 10000000 // DefaultBufferDepth is 250 packets DefaultBufferDepth = 250 // DefaultIdleTimeout is 65 seconds DefaultIdleTimeout = 65 * time.Second // DefaultStatsInterval is 15 seconds DefaultStatsInterval = 15 * time.Second // MinConntrackTimeout sets a lower bound on how long we'll let conntrack entries persist MinConntrackTimeout = 1 * time.Minute // MaximumIPPacketSize is 65535 bytes MaximumIPPacketSize = 65535 )
const (
TCPFlagRST = 0x04
)
TCPFlags are the different flags supported in the TCP header
Variables ¶
This section is empty.
Functions ¶
func RunTest ¶
func RunTest(t *testing.T, tunDeviceName, tunAddr, tunGW, tunMask string, mtu int, doTest func(ifAddr string, dev io.ReadWriter, origEchoAddr Addr, finishedCh chan interface{}) (func() error, error))
Note - this test has to be run with root permissions to allow setting up the TUN device.
Types ¶
type IPPacket ¶
type IPPacket struct { Raw bpool.ByteSlice IPVersion uint8 IPProto uint8 SrcAddr *net.IPAddr DstAddr *net.IPAddr Header []byte Payload []byte }
func (*IPPacket) HasTCPFlag ¶
HasTCPFlag returns true if the packet is a TCP packet that has the given flag set.
type Opts ¶
type Opts struct { // IFName is the name of the interface to use for connecting upstream. // If not specified, this will use the default interface for reaching the // Internet. IFName string // IFAddr is the address to use for outbound packets. Overrides the IFName // when specified. IFAddr string // BufferPool is a pool for buffers. If not provided, default to a 10MB pool. // Each []byte in the buffer pool should be <MaximumIPPacketSize> bytes. BufferPool bpool.ByteSlicePool // BufferDepth specifies the number of outbound packets to buffer between // stages in the send/receive pipeline. The default is <DefaultBufferDepth>. BufferDepth int // IdleTimeout specifies the amount of time before idle connections are // automatically closed. The default is <DefaultIdleTimeout>. IdleTimeout time.Duration // StatsTracker allows specifying an existing StatsTracker to use for tracking // stats. If not specified, one will be created using the configured StatsInterval. // Note - the StatsTracker has to be manually closed using its Close() method, otherwise // it will keep logging stats. StatsTracker *StatsTracker // StatsInterval controls how frequently to display stats. Defaults to // <DefaultStatsInterval>. StatsInterval time.Duration // OnOutbound allows modifying outbound ip packets. OnOutbound func(pkt *IPPacket) // OnInbound allows modifying inbound ip packets. ft is the 5 tuple to // which the current connection/UDP port mapping is keyed. OnInbound func(pkt *IPPacket, downFT FiveTuple) }
func (*Opts) ApplyDefaults ¶
ApplyDefaults applies the default values to the given Opts, including making a new Opts if opts is nil.
type ReadWriter ¶
type ReadWriter interface { // Read reads data into a ByteSlice Read(bpool.ByteSlice) (int, error) // Write writes data from a ByteSlice Write(bpool.ByteSlice) (int, error) }
ReadWriter is like io.ReadWriter but using bpool.ByteSlice.
type ReadWriterAdapter ¶
type ReadWriterAdapter struct {
io.ReadWriter
}
ReadWriterAdapter adapts io.ReadWriter to ReadWriter
type Server ¶
type StatsTracker ¶
type StatsTracker struct {
// contains filtered or unexported fields
}
StatsTracker tracks statistics for one or more gonat servers.
func NewStatsTracker ¶
func NewStatsTracker(statsInterval time.Duration) *StatsTracker
NewStatsTracker creates a new StatsTracker that will log stats at the given statsInterval. Logging only begins once a Server using this StatsTracker is started, and continues until Stop is called
func (*StatsTracker) AcceptedPackets ¶
func (s *StatsTracker) AcceptedPackets() int
AcceptedPackets gives a count of accepted packets
func (*StatsTracker) DroppedPackets ¶
func (s *StatsTracker) DroppedPackets() int
DroppedPackets gives a count of packets dropped due to being stalled writing down or upstream, being unable to assign a port open a connection, etc.
func (*StatsTracker) InvalidPackets ¶
func (s *StatsTracker) InvalidPackets() int
InvalidPackets gives a count of invalid packets (unknown destination, wrong IP version, etc.)
func (*StatsTracker) NumServers ¶
func (s *StatsTracker) NumServers() int
NumServers gives a count of the number of gonat servers currently running
func (*StatsTracker) NumServersClosed ¶
func (s *StatsTracker) NumServersClosed() int
NumServersClosed gives a count of the number of gonat servers closed
func (*StatsTracker) NumServersClosing ¶
func (s *StatsTracker) NumServersClosing() int
NumServersClosing gives a count of the number of gonat servers currently closing
func (*StatsTracker) NumTCPConns ¶
func (s *StatsTracker) NumTCPConns() int
NumTCPConns gives a count of the number of TCP connections being tracked
func (*StatsTracker) NumTCPConnsClosed ¶
func (s *StatsTracker) NumTCPConnsClosed() int
NumTCPConnsClosed gives a count of the number of TCP connections that have been closed
func (*StatsTracker) NumUDPConns ¶
func (s *StatsTracker) NumUDPConns() int
NumUDPConns gives a count of the number of UDP connections being tracked
func (*StatsTracker) NumUDPConnsClosed ¶
func (s *StatsTracker) NumUDPConnsClosed() int
NumUDPConnsClosed gives a count of the number of UDP connections that have been closed