conntrack

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 10 Imported by: 0

README

Keep track of active TCP connections (by talking to the ip_conntrack kernel module).

what

Every call to c.Connections() will return all connections active since the last call to c.Connections(). The connections can either still be established, or have been terminated since the last call. Connections which are established and teared down in between calls to c.Connections() will also be reported.

status

seems to work

todo

ipv6.

Documentation

Index

Constants

View Source
const (
	// #defined in libnfnetlink/include/libnfnetlink/linux_nfnetlink.h
	NFNL_SUBSYS_CTNETLINK = 1
	NFNETLINK_V0          = 0

	// #defined in libnfnetlink/include/libnfnetlink/linux_nfnetlink_compat.h
	NF_NETLINK_CONNTRACK_NEW         = 0x00000001
	NF_NETLINK_CONNTRACK_UPDATE      = 0x00000002
	NF_NETLINK_CONNTRACK_DESTROY     = 0x00000004
	NF_NETLINK_CONNTRACK_EXP_NEW     = 0x00000008
	NF_NETLINK_CONNTRACK_EXP_UPDATE  = 0x00000010
	NF_NETLINK_CONNTRACK_EXP_DESTROY = 0x00000020

	// #defined in libnfnetlink/include/libnfnetlink/libnfnetlink.h
	NLA_F_NESTED        = uint16(1 << 15)
	NLA_F_NET_BYTEORDER = uint16(1 << 14)
	NLA_TYPE_MASK       = ^(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
)

Variables

This section is empty.

Functions

func Follow

func Follow(flags uint32) (<-chan Conn, func(), error)

Follow gives a channel with all changes.

func FollowSize

func FollowSize(bufferSize int, flags uint32) (<-chan Conn, func(), error)

Follow gives a channel with all changes, , using specified netlink buffer size.

func StreamAllConnections

func StreamAllConnections() chan Conn

Stream all connections instead of query for all of them at once.

Types

type Attr

type Attr struct {
	Msg            []byte
	Typ            int
	IsNested       bool
	IsNetByteorder bool
}

type CntlMsgTypes

type CntlMsgTypes int
const (
	IpctnlMsgCtNew            CntlMsgTypes = 0
	IpctnlMsgCtGet            CntlMsgTypes = 1
	IpctnlMsgCtDelete         CntlMsgTypes = 2
	IpctnlMsgCtGetCtrzero     CntlMsgTypes = 3
	IpctnlMsgCtGetStatsCpu    CntlMsgTypes = 4
	IpctnlMsgCtGetStats       CntlMsgTypes = 5
	IpctnlMsgCtGetDying       CntlMsgTypes = 6
	IpctnlMsgCtGetUnconfirmed CntlMsgTypes = 7
	IpctnlMsgMax              CntlMsgTypes = 8
)

type Conn

type Conn struct {
	MsgType  NfConntrackMsg
	TCPState string
	Status   CtStatus
	Orig     Tuple
	Reply    Tuple

	// ct.mark, used to set permission type of the flow.
	CtMark uint32

	// ct.id, used to identify connections.
	CtId uint32

	// For multitenancy.
	Zone uint16

	// Flow stats.
	ReplyPktLen   uint64
	ReplyPktCount uint64
	OrigPktLen    uint64
	OrigPktCount  uint64

	// Error, if any.
	Err error
}

func Connections

func Connections() ([]Conn, error)

Lists all the connections that conntrack is tracking.

func ConnectionsSize

func ConnectionsSize(bufferSize int) ([]Conn, error)

Lists all the connections that conntrack is tracking, using specified netlink buffer size.

func (Conn) ConnTCP

func (c Conn) ConnTCP(local map[string]struct{}) *ConnTCP

ConnTCP decides which way this connection is going and makes a ConnTCP.

type ConnTCP

type ConnTCP struct {
	Local      string // net.IP
	LocalPort  string // int
	Remote     string // net.IP
	RemotePort string // int
}

ConnTCP is a connection

func Established

func Established() ([]ConnTCP, error)

Established lists all established TCP connections.

func (ConnTCP) String

func (c ConnTCP) String() string

type ConnTrack

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

ConnTrack monitors the connections. It is build with Established() and Follow().

func New

func New() (*ConnTrack, error)

New returns a ConnTrack.

func (ConnTrack) Close

func (c ConnTrack) Close()

Close stops all monitoring and executables.

func (*ConnTrack) Connections

func (c *ConnTrack) Connections() []ConnTCP

Connections returns the list of all connections seen since last time you called it.

type ConntrackListReq

type ConntrackListReq struct {
	Header syscall.NlMsghdr
	Body   unix.Nfgenmsg
}

type CtStatus

type CtStatus uint32

Taken from include/uapi/linux/netfilter/nf_conntrack_common.h

const (
	IPS_EXPECTED CtStatus = 1 << iota
	IPS_SEEN_REPLY
	IPS_ASSURED
	IPS_CONFIRMED
	IPS_SRC_NAT
	IPS_DST_NAT
	IPS_SEQ_ADJUST
	IPS_SRC_NAT_DONE
	IPS_DST_NAT_DONE
	IPS_DYING
	IPS_FIXED_TIMEOUT
	IPS_TEMPLATE
	IPS_UNTRACKED
	IPS_HELPER
	IPS_OFFLOAD

	IPS_NAT_MASK      = (IPS_DST_NAT | IPS_SRC_NAT)
	IPS_NAT_DONE_MASK = (IPS_DST_NAT_DONE | IPS_SRC_NAT_DONE)
)

type CtattrCounters

type CtattrCounters int
const (
	CtaCountersUnspec    CtattrCounters = 0
	CtaCountersPackets   CtattrCounters = 1 /* 64bit counters */
	CtaCountersBytes     CtattrCounters = 2 /* 64bit counters */
	CtaCounters32Packets CtattrCounters = 3 /* old 32bit counters, unused */
	CtaCounters32Bytes   CtattrCounters = 4 /* old 32bit counters, unused */
	CtaCountersMax       CtattrCounters = 5
)

type CtattrIp

type CtattrIp int
const (
	CtaIpUnspec CtattrIp = 0
	CtaIpV4Src  CtattrIp = 1
	CtaIpV4Dst  CtattrIp = 2
	CtaIpV6Src  CtattrIp = 3
	CtaIpV6Dst  CtattrIp = 4
	CtaIpMax    CtattrIp = 5
)

type CtattrL4proto

type CtattrL4proto int
const (
	CtaProtoUnspec     CtattrL4proto = 0
	CtaProtoNum        CtattrL4proto = 1
	CtaProtoSrcPort    CtattrL4proto = 2
	CtaProtoDstPort    CtattrL4proto = 3
	CtaProtoIcmpId     CtattrL4proto = 4
	CtaProtoIcmpType   CtattrL4proto = 5
	CtaProtoIcmpCode   CtattrL4proto = 6
	CtaProtoIcmpv6Id   CtattrL4proto = 7
	CtaProtoIcmpv6Type CtattrL4proto = 8
	CtaProtoIcmpv6Code CtattrL4proto = 9
	CtaProtoMax        CtattrL4proto = 10
)

type CtattrProtoinfo

type CtattrProtoinfo int
const (
	CtaProtoinfoUnspec CtattrProtoinfo = 0
	CtaProtoinfoTcp    CtattrProtoinfo = 1
	CtaProtoinfoDccp   CtattrProtoinfo = 2
	CtaProtoinfoSctp   CtattrProtoinfo = 3
	CtaProtoinfoMax    CtattrProtoinfo = 4
)

type CtattrProtoinfoTcp

type CtattrProtoinfoTcp int
const (
	CtaProtoinfoTcpUnspec         CtattrProtoinfoTcp = 0
	CtaProtoinfoTcpState          CtattrProtoinfoTcp = 1
	CtaProtoinfoTcpWscaleOriginal CtattrProtoinfoTcp = 2
	CtaProtoinfoTcpWscaleReply    CtattrProtoinfoTcp = 3
	CtaProtoinfoTcpFlagsOriginal  CtattrProtoinfoTcp = 4
	CtaProtoinfoTcpFlagsReply     CtattrProtoinfoTcp = 5
	CtaProtoinfoTcpMax            CtattrProtoinfoTcp = 6
)

type CtattrTuple

type CtattrTuple int
const (
	CtaTupleUnspec CtattrTuple = 0
	CtaTupleIp     CtattrTuple = 1
	CtaTupleProto  CtattrTuple = 2
	CtaTupleMax    CtattrTuple = 3
)

type CtattrType

type CtattrType int
const (
	CtaUnspec         CtattrType = 0
	CtaTupleOrig      CtattrType = 1
	CtaTupleReply     CtattrType = 2
	CtaStatus         CtattrType = 3
	CtaProtoinfo      CtattrType = 4
	CtaHelp           CtattrType = 5
	CtaNatSrc         CtattrType = 6
	CtaTimeout        CtattrType = 7
	CtaMark           CtattrType = 8
	CtaCountersOrig   CtattrType = 9
	CtaCountersReply  CtattrType = 10
	CtaUse            CtattrType = 11
	CtaId             CtattrType = 12
	CtaNatDst         CtattrType = 13
	CtaTupleMaster    CtattrType = 14
	CtaNatSeqAdjOrig  CtattrType = 15
	CtaNatSeqAdjReply CtattrType = 16
	CtaSecmark        CtattrType = 17
	CtaZone           CtattrType = 18
	CtaSecctx         CtattrType = 19
	CtaTimestamp      CtattrType = 20
	CtaMarkMask       CtattrType = 21
	CtaLabels         CtattrType = 22
	CtaLabelsMask     CtattrType = 23
	CtaMax            CtattrType = 24
)

type NfConntrackAttrGrp

type NfConntrackAttrGrp int
const (
	AttrGrpOrigIpv4     NfConntrackAttrGrp = 0
	AttrGrpReplIpv4     NfConntrackAttrGrp = 1
	AttrGrpOrigIpv6     NfConntrackAttrGrp = 2
	AttrGrpReplIpv6     NfConntrackAttrGrp = 3
	AttrGrpOrigPort     NfConntrackAttrGrp = 4
	AttrGrpReplPort     NfConntrackAttrGrp = 5
	AttrGrpIcmp         NfConntrackAttrGrp = 6
	AttrGrpMasterIpv4   NfConntrackAttrGrp = 7
	AttrGrpMasterIpv6   NfConntrackAttrGrp = 8
	AttrGrpMasterPort   NfConntrackAttrGrp = 9
	AttrGrpOrigCounters NfConntrackAttrGrp = 10
	AttrGrpReplCounters NfConntrackAttrGrp = 11
	AttrGrpOrigAddrSrc  NfConntrackAttrGrp = 12
	AttrGrpOrigAddrDst  NfConntrackAttrGrp = 13
	AttrGrpReplAddrSrc  NfConntrackAttrGrp = 14
	AttrGrpReplAddrDst  NfConntrackAttrGrp = 15
	AttrGrpMax          NfConntrackAttrGrp = 16
)

type NfConntrackMsg

type NfConntrackMsg int
const (
	NfctMsgUnknown NfConntrackMsg = 0
	NfctMsgNew     NfConntrackMsg = 1 << 0
	NfctMsgUpdate  NfConntrackMsg = 1 << 1
	NfctMsgDestroy NfConntrackMsg = 1 << 2
)

type NfConntrackQuery

type NfConntrackQuery int
const (
	NfctQCreate          NfConntrackQuery = 0
	NfctQUpdate          NfConntrackQuery = 1
	NfctQDestroy         NfConntrackQuery = 2
	NfctQGet             NfConntrackQuery = 3
	NfctQFlush           NfConntrackQuery = 4
	NfctQDump            NfConntrackQuery = 5
	NfctQDumpReset       NfConntrackQuery = 6
	NfctQCreateUpdate    NfConntrackQuery = 7
	NfctQDumpFilter      NfConntrackQuery = 8
	NfctQDumpFilterReset NfConntrackQuery = 9
)

type Tuple

type Tuple struct {
	Proto   int
	Src     net.IP
	SrcPort uint16
	Dst     net.IP
	DstPort uint16

	// ICMP stuff.
	IcmpId   uint16
	IcmpType uint8
	IcmpCode uint8
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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