Documentation ¶
Index ¶
- Constants
- Variables
- func CreateConnectionID(protocol IPProtocol, src net.IP, srcPort uint16, dst net.IP, dstPort uint16, ...) string
- func Parse(packetData []byte, pktBase *Base) (err error)
- type BandwidthUpdate
- type BandwidthUpdateMethod
- type Base
- func (pkt *Base) Ctx() context.Context
- func (pkt *Base) ExpectInfo() bool
- func (pkt *Base) FastTrackedByIntegration() bool
- func (pkt *Base) FmtPacket() string
- func (pkt *Base) FmtProtocol() string
- func (pkt *Base) FmtRemoteAddress() string
- func (pkt *Base) FmtRemoteIP() string
- func (pkt *Base) FmtRemotePort() string
- func (pkt *Base) GetConnectionID() string
- func (pkt *Base) HasPorts() bool
- func (pkt *Base) Info() *Info
- func (pkt *Base) InfoOnly() bool
- func (pkt *Base) IsInbound() bool
- func (pkt *Base) IsOutbound() bool
- func (pkt *Base) Layers() gopacket.Packet
- func (pkt *Base) LoadPacketData() error
- func (pkt *Base) MatchesAddress(remote bool, protocol IPProtocol, network *net.IPNet, port uint16) bool
- func (pkt *Base) MatchesIP(endpoint bool, network *net.IPNet) bool
- func (pkt *Base) Payload() []byte
- func (pkt *Base) Raw() []byte
- func (pkt *Base) SetCtx(ctx context.Context)
- func (pkt *Base) SetInbound()
- func (pkt *Base) SetOutbound()
- func (pkt *Base) SetPacketInfo(packetInfo Info)
- func (pkt *Base) String() string
- type IPProtocol
- type IPVersion
- type Info
- type InfoPacket
- func (pkt *InfoPacket) Accept() error
- func (pkt *InfoPacket) Block() error
- func (pkt *InfoPacket) Drop() error
- func (pkt *InfoPacket) InfoOnly() bool
- func (pkt *InfoPacket) LoadPacketData() error
- func (pkt *InfoPacket) PermanentAccept() error
- func (pkt *InfoPacket) PermanentBlock() error
- func (pkt *InfoPacket) PermanentDrop() error
- func (pkt *InfoPacket) RerouteToNameserver() error
- func (pkt *InfoPacket) RerouteToTunnel() error
- type Packet
- type Verdict
Constants ¶
const ( IPv4 = IPVersion(4) IPv6 = IPVersion(6) InBound = true OutBound = false ICMP = IPProtocol(1) IGMP = IPProtocol(2) TCP = IPProtocol(6) UDP = IPProtocol(17) ICMPv6 = IPProtocol(58) UDPLite = IPProtocol(136) RAW = IPProtocol(255) AnyHostInternalProtocol61 = IPProtocol(61) )
Basic Constants.
Variables ¶
var ErrFailedToLoadPayload = errors.New("could not load packet payload")
ErrFailedToLoadPayload is returned by GetPayload if it failed for an unspecified reason, or is not implemented on the current system.
var ErrInfoOnlyPacket = errors.New("info-only packet")
ErrInfoOnlyPacket is returned for unsupported operations on an info-only packet.
Functions ¶
Types ¶
type BandwidthUpdate ¶ added in v1.2.0
type BandwidthUpdate struct { ConnID string BytesReceived uint64 BytesSent uint64 Method BandwidthUpdateMethod }
BandwidthUpdate holds an update to the seen bandwidth of a connection.
func (*BandwidthUpdate) String ¶ added in v1.2.0
func (bu *BandwidthUpdate) String() string
type BandwidthUpdateMethod ¶ added in v1.2.0
type BandwidthUpdateMethod uint8
BandwidthUpdateMethod defines how the bandwidth data of a bandwidth update should be interpreted.
const ( Absolute BandwidthUpdateMethod = iota Additive )
Bandwidth Update Methods.
func (BandwidthUpdateMethod) String ¶ added in v1.2.0
func (bum BandwidthUpdateMethod) String() string
type Base ¶ added in v0.2.5
type Base struct {
// contains filtered or unexported fields
}
Base is a base structure for satisfying the Packet interface.
func (*Base) ExpectInfo ¶ added in v1.2.0
ExpectInfo returns whether the next packet is expected to be informational only.
func (*Base) FastTrackedByIntegration ¶ added in v0.6.12
FastTrackedByIntegration returns whether the packet has been fast-track accepted by the OS integration.
func (*Base) FmtPacket ¶ added in v0.2.5
FmtPacket returns the most important information about the packet as a string.
func (*Base) FmtProtocol ¶ added in v0.2.5
FmtProtocol returns the protocol as a string.
func (*Base) FmtRemoteAddress ¶ added in v0.2.5
FmtRemoteAddress returns the full remote address (protocol, IP, port) as a string.
func (*Base) FmtRemoteIP ¶ added in v0.2.5
FmtRemoteIP returns the remote IP address as a string.
func (*Base) FmtRemotePort ¶ added in v0.2.5
FmtRemotePort returns the remote port as a string.
func (*Base) GetConnectionID ¶ added in v0.4.0
GetConnectionID returns the link ID for this packet.
func (*Base) HasPorts ¶ added in v0.2.5
HasPorts checks if the packet has a protocol that uses ports.
func (*Base) InfoOnly ¶ added in v1.2.0
InfoOnly returns whether the packet is informational only and does not represent an actual packet.
func (*Base) IsOutbound ¶ added in v0.2.5
IsOutbound checks if the packet is outbound.
func (*Base) LoadPacketData ¶ added in v0.6.9
LoadPacketData loads packet data from the integration, if not yet done.
func (*Base) MatchesAddress ¶ added in v0.2.5
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 ¶ added in v0.2.5
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) SetInbound ¶ added in v0.2.5
func (pkt *Base) SetInbound()
SetInbound sets a the packet direction to inbound. This must only used when initializing the packet structure.
func (*Base) SetOutbound ¶ added in v0.2.5
func (pkt *Base) SetOutbound()
SetOutbound sets a the packet direction to outbound. This must only used when initializing the packet structure.
func (*Base) SetPacketInfo ¶ added in v0.2.5
SetPacketInfo sets a new packet Info. This must only used when initializing the packet structure.
type IPProtocol ¶
type IPProtocol uint8
IPProtocol represents an IP protocol.
func (IPProtocol) String ¶
func (p IPProtocol) String() string
String returns the string representation (abbreviation) of the protocol.
type IPVersion ¶
type IPVersion uint8
IPVersion represents an IP version.
type Info ¶ added in v0.2.5
type Info struct { Inbound bool InTunnel bool Version IPVersion Protocol IPProtocol SrcPort, DstPort uint16 Src, Dst net.IP PID int SeenAt time.Time }
Info holds IP and TCP/UDP header information.
func (*Info) CreateConnectionID ¶ added in v1.2.0
CreateConnectionID creates a connection ID. In most circumstances, this method should not be used directly, but packet.GetConnectionID() should be called instead.
func (*Info) RemotePort ¶ added in v0.2.5
RemotePort returns the remote port of the packet.
type InfoPacket ¶ added in v1.2.0
type InfoPacket struct {
Base
}
InfoPacket does not represent an actual packet, but only holds metadata. Implements the packet.Packet interface.
func NewInfoPacket ¶ added in v1.2.0
func NewInfoPacket(info Info) *InfoPacket
NewInfoPacket returns a new InfoPacket with the given info.
func (*InfoPacket) Accept ¶ added in v1.2.0
func (pkt *InfoPacket) Accept() error
Accept does nothing on an info-only packet.
func (*InfoPacket) Block ¶ added in v1.2.0
func (pkt *InfoPacket) Block() error
Block does nothing on an info-only packet.
func (*InfoPacket) Drop ¶ added in v1.2.0
func (pkt *InfoPacket) Drop() error
Drop does nothing on an info-only packet.
func (*InfoPacket) InfoOnly ¶ added in v1.2.0
func (pkt *InfoPacket) InfoOnly() bool
InfoOnly returns whether the packet is informational only and does not represent an actual packet.
func (*InfoPacket) LoadPacketData ¶ added in v1.2.0
func (pkt *InfoPacket) LoadPacketData() error
LoadPacketData does nothing on Linux, as data is always fully parsed.
func (*InfoPacket) PermanentAccept ¶ added in v1.2.0
func (pkt *InfoPacket) PermanentAccept() error
PermanentAccept does nothing on an info-only packet.
func (*InfoPacket) PermanentBlock ¶ added in v1.2.0
func (pkt *InfoPacket) PermanentBlock() error
PermanentBlock does nothing on an info-only packet.
func (*InfoPacket) PermanentDrop ¶ added in v1.2.0
func (pkt *InfoPacket) PermanentDrop() error
PermanentDrop does nothing on an info-only packet.
func (*InfoPacket) RerouteToNameserver ¶ added in v1.2.0
func (pkt *InfoPacket) RerouteToNameserver() error
RerouteToNameserver does nothing on an info-only packet.
func (*InfoPacket) RerouteToTunnel ¶ added in v1.2.0
func (pkt *InfoPacket) RerouteToTunnel() error
RerouteToTunnel does nothing on an info-only packet.
type Packet ¶
type Packet interface { // Verdicts. Accept() error Block() error Drop() error PermanentAccept() error PermanentBlock() error PermanentDrop() error RerouteToNameserver() error RerouteToTunnel() error FastTrackedByIntegration() bool InfoOnly() bool ExpectInfo() bool // Info. SetCtx(context.Context) Ctx() context.Context Info() *Info SetPacketInfo(Info) IsInbound() bool IsOutbound() bool SetInbound() SetOutbound() HasPorts() bool GetConnectionID() string // Payload. LoadPacketData() error Layers() gopacket.Packet Raw() []byte Payload() []byte // 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 behavior the same across all systems.