portmaster: github.com/safing/portmaster/network/packet Index | Files

package packet

import "github.com/safing/portmaster/network/packet"

Index

Package Files

const.go packet.go packetinfo.go parse.go

Constants

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

var (
    ErrFailedToLoadPayload = errors.New("could not load packet payload")
)

func Parse Uses

func Parse(packetData []byte, packet *Base) error

Parse parses an IP packet and saves the information in the given packet object.

type Base Uses

type Base struct {
    Payload []byte
    // contains filtered or unexported fields
}

Base is a base structure for satisfying the Packet interface.

func (*Base) Ctx Uses

func (pkt *Base) Ctx() context.Context

Ctx returns the packet context.

func (*Base) FmtPacket Uses

func (pkt *Base) FmtPacket() string

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

func (*Base) FmtProtocol Uses

func (pkt *Base) FmtProtocol() string

FmtProtocol returns the protocol as a string

func (*Base) FmtRemoteAddress Uses

func (pkt *Base) FmtRemoteAddress() string

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

func (*Base) FmtRemoteIP Uses

func (pkt *Base) FmtRemoteIP() string

FmtRemoteIP returns the remote IP address as a string

func (*Base) FmtRemotePort Uses

func (pkt *Base) FmtRemotePort() string

FmtRemotePort returns the remote port as a string

func (*Base) GetLinkID Uses

func (pkt *Base) GetLinkID() string

GetLinkID returns the link ID for this packet.

func (*Base) GetPayload Uses

func (pkt *Base) GetPayload() ([]byte, error)

GetPayload returns the packet payload. In some cases, this will fetch the payload from the os integration system.

func (*Base) HasPorts Uses

func (pkt *Base) HasPorts() bool

HasPorts checks if the packet has a protocol that uses ports.

func (*Base) Info Uses

func (pkt *Base) Info() *Info

Info returns the packet Info.

func (*Base) IsInbound Uses

func (pkt *Base) IsInbound() bool

IsInbound checks if the packet is inbound.

func (*Base) IsOutbound Uses

func (pkt *Base) IsOutbound() bool

IsOutbound checks if the packet is outbound.

func (*Base) MatchesAddress Uses

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

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

Comparison matrix:

IN   OUT

Local Dst Src Remote Src Dst

func (*Base) MatchesIP Uses

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

MatchesIP checks if a the packet matches a given endpoint (remote or local) IP.

Comparison matrix:

IN   OUT

Local Dst Src Remote Src Dst

func (*Base) SetCtx Uses

func (pkt *Base) SetCtx(ctx context.Context)

SetCtx sets the packet context.

func (*Base) SetInbound Uses

func (pkt *Base) SetInbound()

SetInbound sets a the packet direction to inbound. This must only used when initializing the packet structure.

func (*Base) SetOutbound Uses

func (pkt *Base) SetOutbound()

SetOutbound sets a the packet direction to outbound. This must only used when initializing the packet structure.

func (*Base) SetPacketInfo Uses

func (pkt *Base) SetPacketInfo(packetInfo Info)

SetPacketInfo sets a new packet Info. This must only used when initializing the packet structure.

func (*Base) String Uses

func (pkt *Base) String() string

type Endpoint Uses

type Endpoint bool

type IPProtocol Uses

type IPProtocol uint8

func (IPProtocol) String Uses

func (p IPProtocol) String() string

type IPVersion Uses

type IPVersion uint8

func (IPVersion) ByteSize Uses

func (v IPVersion) ByteSize() int

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

func (IPVersion) String Uses

func (v IPVersion) String() string

type Info Uses

type Info struct {
    Direction bool
    InTunnel  bool

    Version          IPVersion
    Src, Dst         net.IP
    Protocol         IPProtocol
    SrcPort, DstPort uint16
}

Info holds IP and TCP/UDP header information

func (*Info) LocalIP Uses

func (pi *Info) LocalIP() net.IP

LocalIP returns the local IP of the packet.

func (*Info) LocalPort Uses

func (pi *Info) LocalPort() uint16

LocalPort returns the local port of the packet.

func (*Info) RemoteIP Uses

func (pi *Info) RemoteIP() net.IP

RemoteIP returns the remote IP of the packet.

func (*Info) RemotePort Uses

func (pi *Info) RemotePort() uint16

RemotePort returns the remote port of the packet.

type Packet Uses

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

    // INFO
    SetCtx(context.Context)
    Ctx() context.Context
    Info() *Info
    SetPacketInfo(Info)
    IsInbound() bool
    IsOutbound() bool
    SetInbound()
    SetOutbound()
    HasPorts() bool
    GetPayload() ([]byte, error)
    GetLinkID() string

    // 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 Verdict Uses

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

func (Verdict) String Uses

func (v Verdict) String() string

Package packet imports 6 packages (graph) and is imported by 4 packages. Updated 2019-06-20. Refresh now. Tools for package owners.