packet

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2019 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4 = IPVersion(4)
	IPv6 = IPVersion(6)

	InBound  = true
	OutBound = false

	Local  = true
	Remote = false

	// convenience
	IGMP   = IPProtocol(2)
	RAW    = IPProtocol(255)
	TCP    = IPProtocol(6)
	UDP    = IPProtocol(17)
	ICMP   = IPProtocol(1)
	ICMPv6 = IPProtocol(58)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint bool

type IPHeader

type IPHeader struct {
	Version IPVersion

	Tos, TTL uint8
	Protocol IPProtocol
	Src, Dst net.IP
}

type IPProtocol

type IPProtocol uint8

func (IPProtocol) String

func (p IPProtocol) String() string

type IPVersion

type IPVersion uint8

func (IPVersion) ByteSize

func (v IPVersion) ByteSize() int

Returns the byte size of the ip, IPv4 = 4 bytes, IPv6 = 16

func (IPVersion) String

func (v IPVersion) String() string

type Packet

type Packet interface {
	// VERDICTS
	Accept() error
	Block() error
	Drop() error
	PermanentAccept() error
	PermanentBlock() error
	PermanentDrop() error
	RerouteToNameserver() error
	RerouteToTunnel() error

	// INFO
	GetIPHeader() *IPHeader
	GetTCPUDPHeader() *TCPUDPHeader
	GetPayload() []byte
	IsInbound() bool
	IsOutbound() bool
	SetInbound()
	SetOutbound()
	GetLinkID() string
	IPVersion() IPVersion

	// MATCHING
	MatchesAddress(bool, IPProtocol, *net.IPNet, uint16) bool
	MatchesIP(bool, *net.IPNet) bool

	// FORMATTING
	String() string
	FmtPacket() string
	FmtProtocol() string
	FmtRemoteIP() string
	FmtRemotePort() string
	FmtRemoteAddress() string
}

Packet is an interface to a network packet to provide object behaviour the same across all systems

type PacketBase

type PacketBase struct {
	Direction bool
	InTunnel  bool
	Payload   []byte
	*IPHeader
	*TCPUDPHeader
	// contains filtered or unexported fields
}

func (*PacketBase) FmtPacket

func (pkt *PacketBase) FmtPacket() string

FmtPacket returns the most important information about the packet as a string

func (*PacketBase) FmtProtocol

func (pkt *PacketBase) FmtProtocol() string

FmtProtocol returns the protocol as a string

func (*PacketBase) FmtRemoteAddress

func (pkt *PacketBase) FmtRemoteAddress() string

FmtRemoteAddress returns the full remote address (protocol, IP, port) as a string

func (*PacketBase) FmtRemoteIP

func (pkt *PacketBase) FmtRemoteIP() string

FmtRemoteIP returns the remote IP address as a string

func (*PacketBase) FmtRemotePort

func (pkt *PacketBase) FmtRemotePort() string

FmtRemotePort returns the remote port as a string

func (*PacketBase) GetIPHeader

func (pkt *PacketBase) GetIPHeader() *IPHeader

func (*PacketBase) GetLinkID

func (pkt *PacketBase) GetLinkID() string

func (*PacketBase) GetPayload

func (pkt *PacketBase) GetPayload() []byte

func (*PacketBase) GetTCPUDPHeader

func (pkt *PacketBase) GetTCPUDPHeader() *TCPUDPHeader

func (*PacketBase) IPVersion

func (pkt *PacketBase) IPVersion() IPVersion

func (*PacketBase) IsInbound

func (pkt *PacketBase) IsInbound() bool

func (*PacketBase) IsOutbound

func (pkt *PacketBase) IsOutbound() bool

func (*PacketBase) MatchesAddress

func (pkt *PacketBase) MatchesAddress(endpoint bool, protocol IPProtocol, network *net.IPNet, port uint16) bool

Matches checks if a the packet matches a given endpoint (remote or local) in protocol, network and port.

IN   OUT

Local Dst Src Remote Src Dst

func (*PacketBase) MatchesIP

func (pkt *PacketBase) MatchesIP(endpoint bool, network *net.IPNet) bool

func (*PacketBase) SetInbound

func (pkt *PacketBase) SetInbound()

func (*PacketBase) SetOutbound

func (pkt *PacketBase) SetOutbound()

func (*PacketBase) String

func (pkt *PacketBase) String() string

type TCPUDPHeader

type TCPUDPHeader struct {
	SrcPort, DstPort uint16
	Checksum         uint16 //not implemented
}

type Verdict

type Verdict uint8
const (
	DROP Verdict = iota
	BLOCK
	ACCEPT
	STOLEN
	QUEUE
	REPEAT
	STOP
)

func (Verdict) String

func (v Verdict) String() string

Jump to

Keyboard shortcuts

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