netstack

package module
v0.0.0-...-6781d13 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2016 License: GPL-3.0 Imports: 14 Imported by: 1

README

netstack

Custom network stack in Go

This networkstack implements (very) basic and rudimentary support for connecting tcp streams. There needs to be a lot to be implemented and optimised.

Projects

Currently netstack is being used by the following projects:

Configuration

Linux will send RST packets for unknown tcp packets, so this needs to be disabled using iptables.

iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP
iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP

Samples

See samples folder.

References

Documentation

Index

Constants

View Source
const (
	MaxEpollEvents    = 64
	DefaultBufferSize = 65535
)

Variables

View Source
var ErrNoState = errors.New("No state for packet.")

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Connected chan bool

	Src, Dst                    net.IP
	SourcePort, DestinationPort uint16

	Recv  chan []byte
	Stack *Stack
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Connection) Open

func (c *Connection) Open(src net.IP, dst net.IP, port int) error

func (*Connection) Read

func (conn *Connection) Read(b []byte) (n int, err error)

Read reads data from the connection. Read can be made to time out and return a Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*Connection) Receive

func (c *Connection) Receive() chan []byte

func (*Connection) RemoteAddr

func (c *Connection) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*Connection) SetDeadline

func (c *Connection) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future I/O, not just the immediately following call to Read or Write.

An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.

A zero value for t means I/O operations will not time out.

func (*Connection) SetReadDeadline

func (c *Connection) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls. A zero value for t means Read will not time out.

func (*Connection) SetWriteDeadline

func (c *Connection) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

func (*Connection) Write

func (c *Connection) Write(b []byte) (n int, err error)

Write writes data to the connection. Write can be made to time out and return a Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline.

type SocketState

type SocketState int
const (
	SocketClosed SocketState = iota
	SocketListen
	SocketSynReceived
	SocketSynSent
	SocketEstablished
	SocketFinWait1
	SocketFinWait2
	SocketClosing
	SocketTimeWait
	SocketCloseWait
	SocketLastAck
)

func (SocketState) String

func (ss SocketState) String() string

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

func New

func New(intf string) (*Stack, error)

func (*Stack) Close

func (s *Stack) Close()

func (*Stack) Connect

func (s *Stack) Connect(dest net.IP, port int) (*Connection, error)

func (Stack) Listen

func (s Stack) Listen() (*listener, error)

func (*Stack) Start

func (s *Stack) Start() error

type State

type State struct {
	sync.Mutex

	SrcIP    net.IP
	SrcPort  uint16
	DestIP   net.IP
	DestPort uint16

	Last time.Time

	RecvNext           uint32
	SendNext           uint32
	SendUnAcknowledged uint32
	LastAcked          uint32

	SocketState SocketState

	ID int

	Conn *Connection
}

type StateTable

type StateTable []*State

func (*StateTable) Add

func (st *StateTable) Add(state *State)

func (*StateTable) Get

func (st *StateTable) Get(SrcIP, DestIP net.IP, SrcPort, DestPort uint16) *State

GetState will return the state for the ip, port combination

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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