gophertun

package module
v0.0.0-...-62ca0bc Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMRU                   = 65536
	DefaultMTU                   = 1500
	DefaultTTL                   = 64
	DefaultPostProcessBufferSize = 16
	EthernetHeaderSize           = 14
)

Variables

View Source
var (
	ErrUnsupportedFeature  = errors.New("gophertun: feature unsupported on this platform")
	ErrUnsupportedProtocol = errors.New("gophertun: protocol unsupported")
)

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Decode(buf []byte) error
	Encode() ([]byte, error)
	NextLayer() Codec
}

type CodecARP

type CodecARP struct {
	HardwareType       uint16
	ProtocolType       EtherType
	HardwareSize       uint8
	ProtocolSize       uint8
	Opcode             uint16
	SenderHardwareAddr net.HardwareAddr
	SenderProtocolAddr net.IP
	TargetHardwareAddr net.HardwareAddr
	TargetProtocolAddr net.IP
	Extra              []byte
}

func (*CodecARP) Decode

func (c *CodecARP) Decode(buf []byte) error

func (*CodecARP) Encode

func (c *CodecARP) Encode() ([]byte, error)

func (*CodecARP) NextLayer

func (c *CodecARP) NextLayer() Codec

func (*CodecARP) String

func (c *CodecARP) String() string

type CodecEthernet

type CodecEthernet struct {
	Destination net.HardwareAddr
	Source      net.HardwareAddr
	Type        EtherType
	Payload     Codec
}

func (*CodecEthernet) Decode

func (c *CodecEthernet) Decode(buf []byte) error

func (*CodecEthernet) Encode

func (c *CodecEthernet) Encode() ([]byte, error)

func (*CodecEthernet) NextLayer

func (c *CodecEthernet) NextLayer() Codec

func (*CodecEthernet) String

func (c *CodecEthernet) String() string

type CodecICMP

type CodecICMP struct {
	Type     uint8
	Code     uint8
	Checksum uint16
	Omni     uint32
	Payload  Codec
}

func (*CodecICMP) Decode

func (c *CodecICMP) Decode(buf []byte) error

func (*CodecICMP) Encode

func (c *CodecICMP) Encode() ([]byte, error)

func (*CodecICMP) NextLayer

func (c *CodecICMP) NextLayer() Codec

func (*CodecICMP) String

func (c *CodecICMP) String() string

type CodecICMPv6

type CodecICMPv6 struct {
	Type     uint8
	Code     uint8
	Checksum uint16
	Omni     uint32
	Payload  Codec
	// contains filtered or unexported fields
}

func (*CodecICMPv6) Decode

func (c *CodecICMPv6) Decode(buf []byte) error

func (*CodecICMPv6) Encode

func (c *CodecICMPv6) Encode() ([]byte, error)

func (*CodecICMPv6) NextLayer

func (c *CodecICMPv6) NextLayer() Codec

func (*CodecICMPv6) String

func (c *CodecICMPv6) String() string

type CodecIPv4

type CodecIPv4 struct {
	Version        uint8
	HeaderLength   uint8 // raw * 4
	DSCP           uint8
	ECN            uint8
	TotalLength    uint16
	Identification uint16
	Flags          uint8
	FragmentOffset uint16 // raw * 8
	TTL            uint8
	Protocol       uint8
	HeaderChecksum uint16
	Source         net.IP
	Destination    net.IP
	Extra1         []byte
	Payload        Codec
	Extra2         []byte
}

func (*CodecIPv4) Decode

func (c *CodecIPv4) Decode(buf []byte) error

func (*CodecIPv4) Encode

func (c *CodecIPv4) Encode() ([]byte, error)

func (*CodecIPv4) NextLayer

func (c *CodecIPv4) NextLayer() Codec

func (*CodecIPv4) String

func (c *CodecIPv4) String() string

type CodecIPv6

type CodecIPv6 struct {
	Version       uint8
	DSCP          uint8
	ECN           uint8
	Flowlabel     uint32
	PayloadLength uint16
	NextHeader    uint8
	HopLimit      uint8
	Source        net.IP
	Destination   net.IP
	Payload       Codec
	Extra         []byte
}

func (*CodecIPv6) Decode

func (c *CodecIPv6) Decode(buf []byte) error

func (*CodecIPv6) Encode

func (c *CodecIPv6) Encode() ([]byte, error)

func (*CodecIPv6) NextLayer

func (c *CodecIPv6) NextLayer() Codec

func (*CodecIPv6) String

func (c *CodecIPv6) String() string

type CodecIPv6Fragment

type CodecIPv6Fragment struct {
	NextHeader     uint8
	Reserved1      uint8
	FragmentOffset uint16 // raw * 8
	Reserved2      uint8
	MoreFragment   bool
	Identification uint32
	Payload        Codec
	// contains filtered or unexported fields
}

func (*CodecIPv6Fragment) Decode

func (c *CodecIPv6Fragment) Decode(buf []byte) error

func (*CodecIPv6Fragment) Encode

func (c *CodecIPv6Fragment) Encode() ([]byte, error)

func (*CodecIPv6Fragment) NextLayer

func (c *CodecIPv6Fragment) NextLayer() Codec

func (*CodecIPv6Fragment) String

func (c *CodecIPv6Fragment) String() string

type CodecIPv6HopByHop

type CodecIPv6HopByHop struct {
	NextHeader   uint8
	HeaderLength uint16 // raw * 8 + 8
	FirstOption  *CodecIPv6HopByHopOption
	Payload      Codec
	// contains filtered or unexported fields
}

func (*CodecIPv6HopByHop) Decode

func (c *CodecIPv6HopByHop) Decode(buf []byte) error

func (*CodecIPv6HopByHop) Encode

func (c *CodecIPv6HopByHop) Encode() ([]byte, error)

func (*CodecIPv6HopByHop) NextLayer

func (c *CodecIPv6HopByHop) NextLayer() Codec

func (*CodecIPv6HopByHop) String

func (c *CodecIPv6HopByHop) String() string

type CodecIPv6HopByHopOption

type CodecIPv6HopByHopOption struct {
	Type       uint8
	DataLength uint8
	Data       Codec
	NextOption *CodecIPv6HopByHopOption
}

func (*CodecIPv6HopByHopOption) Decode

func (c *CodecIPv6HopByHopOption) Decode(buf []byte) error

func (*CodecIPv6HopByHopOption) Encode

func (c *CodecIPv6HopByHopOption) Encode() ([]byte, error)

func (*CodecIPv6HopByHopOption) NextLayer

func (c *CodecIPv6HopByHopOption) NextLayer() Codec

func (*CodecIPv6HopByHopOption) String

func (c *CodecIPv6HopByHopOption) String() string

type CodecRaw

type CodecRaw struct {
	Payload []byte
	Err     error
}

func (*CodecRaw) Decode

func (c *CodecRaw) Decode(buf []byte) error

func (*CodecRaw) Encode

func (c *CodecRaw) Encode() ([]byte, error)

func (*CodecRaw) NextLayer

func (c *CodecRaw) NextLayer() Codec

func (*CodecRaw) String

func (c *CodecRaw) String() string

type EtherType

type EtherType uint16
const (
	EtherTypeIPv4 EtherType = 0x0800
	EtherTypeARP  EtherType = 0x0806
	EtherTypeIPv6 EtherType = 0x86dd
)

type IPAddress

type IPAddress struct {
	Net  *net.IPNet
	Peer *net.IPNet
}

type Packet

type Packet struct {
	Format    PayloadFormat
	EtherType EtherType
	Payload   []byte
	Extra     []byte
}

func (*Packet) ConvertTo

func (p *Packet) ConvertTo(outputFormat PayloadFormat, hwAddr net.HardwareAddr) (*Packet, error)

type PayloadFormat

type PayloadFormat int
const (
	FormatUnknown PayloadFormat = iota
	FormatIP
	FormatEthernet
)

type TunTapConfig

type TunTapConfig struct {
	NameHint              string
	AllowNameSuffix       bool
	PreferredNativeFormat PayloadFormat
	ExtraFlags            uint32
}

func (*TunTapConfig) Create

func (c *TunTapConfig) Create() (Tunnel, error)

type TunTapImpl

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

func (*TunTapImpl) AddIPAddresses

func (t *TunTapImpl) AddIPAddresses(addresses []*IPAddress) (int, error)

func (*TunTapImpl) Close

func (t *TunTapImpl) Close() error

func (*TunTapImpl) MTU

func (t *TunTapImpl) MTU() (int, error)

func (*TunTapImpl) Name

func (t *TunTapImpl) Name() (string, error)

func (*TunTapImpl) NativeFormat

func (t *TunTapImpl) NativeFormat() PayloadFormat

func (*TunTapImpl) Open

func (t *TunTapImpl) Open(outputFormat PayloadFormat) error

func (*TunTapImpl) OutputFormat

func (t *TunTapImpl) OutputFormat() PayloadFormat

func (*TunTapImpl) RawFile

func (t *TunTapImpl) RawFile() (*os.File, error)

func (*TunTapImpl) Read

func (t *TunTapImpl) Read() (*Packet, error)

func (*TunTapImpl) SetMTU

func (t *TunTapImpl) SetMTU(mtu int) error

func (*TunTapImpl) Write

func (t *TunTapImpl) Write(packet *Packet, pmtud bool) error

type Tunnel

type Tunnel interface {
	AddIPAddresses(addresses []*IPAddress) (int, error)
	Close() error
	MTU() (int, error)
	Name() (string, error)
	NativeFormat() PayloadFormat
	Open(outputFormat PayloadFormat) error
	OutputFormat() PayloadFormat
	RawFile() (*os.File, error)
	Read() (*Packet, error)
	SetMTU(mtu int) error
	Write(packet *Packet, pmtud bool) error
}

type TunnelConfig

type TunnelConfig interface {
	Create() (Tunnel, error)
}

type VxlanConfig

type VxlanConfig struct {
	VxlanConn           net.PacketConn
	VxlanNetworkID      uint32
	VxlanTunnelEndpoint net.Addr
}

func (*VxlanConfig) Create

func (c *VxlanConfig) Create() (Tunnel, error)

type VxlanImpl

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

func (*VxlanImpl) AddIPAddresses

func (t *VxlanImpl) AddIPAddresses(addresses []*IPAddress) (int, error)

func (*VxlanImpl) Close

func (t *VxlanImpl) Close() error

func (*VxlanImpl) MTU

func (t *VxlanImpl) MTU() (int, error)

func (*VxlanImpl) Name

func (t *VxlanImpl) Name() (string, error)

func (*VxlanImpl) NativeFormat

func (t *VxlanImpl) NativeFormat() PayloadFormat

func (*VxlanImpl) Open

func (t *VxlanImpl) Open(outputFormat PayloadFormat) error

func (*VxlanImpl) OutputFormat

func (t *VxlanImpl) OutputFormat() PayloadFormat

func (*VxlanImpl) RawFile

func (t *VxlanImpl) RawFile() (*os.File, error)

func (*VxlanImpl) Read

func (t *VxlanImpl) Read() (*Packet, error)

func (*VxlanImpl) SetMTU

func (t *VxlanImpl) SetMTU(mtu int) error

func (*VxlanImpl) Write

func (t *VxlanImpl) Write(packet *Packet, pmtud bool) error

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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