inetdiag

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: Apache-2.0 Imports: 6 Imported by: 19

Documentation

Overview

Package inetdiag provides basic structs and utilities for INET_DIAG messaages. Based on uapi/linux/inet_diag.h.

Index

Constants

View Source
const (
	INET_DIAG_NONE = iota
	INET_DIAG_MEMINFO
	INET_DIAG_INFO
	INET_DIAG_VEGASINFO
	INET_DIAG_CONG
	INET_DIAG_TOS
	INET_DIAG_TCLASS
	INET_DIAG_SKMEMINFO
	INET_DIAG_SHUTDOWN
	INET_DIAG_DCTCPINFO
	INET_DIAG_PROTOCOL
	INET_DIAG_SKV6ONLY
	INET_DIAG_LOCALS
	INET_DIAG_PEERS
	INET_DIAG_PAD
	INET_DIAG_MARK
	INET_DIAG_BBRINFO
	INET_DIAG_CLASS_ID
	INET_DIAG_MD5SIG
	// TODO - Should check whether this matches the current linux header.
	INET_DIAG_MAX
)

inet_diag.h

View Source
const (
	TCPDIAG_GETSOCK     = 18 // uapi/linux/inet_diag.h
	SOCK_DIAG_BY_FAMILY = 20 // uapi/linux/sock_diag.h
)

Constants from linux.

View Source
const SizeofInetDiagReqV2 = int(unsafe.Sizeof(InetDiagReqV2{})) // Should be 0x38

SizeofInetDiagReqV2 is the size of the struct. TODO should we just make this explicit in the code?

View Source
const TCPF_ALL = 0xFFF

Variables

View Source
var (
	// ErrBadPid is used when the PID is mismatched between the netlink socket and the calling process.
	ErrBadPid = errors.New("bad PID, can't listen to NL socket")

	// ErrBadSequence is used when the Netlink response has a bad sequence number.
	ErrBadSequence = errors.New("bad sequence number, can't interpret NetLink response")

	// ErrBadMsgData is used when the NHetlink response has bad or missing data.
	ErrBadMsgData = errors.New("bad message data from netlink message")
)

Functions

This section is empty.

Types

type InetDiagMsg

type InetDiagMsg struct {
	IDiagFamily  uint8
	IDiagState   uint8
	IDiagTimer   uint8
	IDiagRetrans uint8
	ID           InetDiagSockID
	IDiagExpires uint32
	IDiagRqueue  uint32
	IDiagWqueue  uint32
	IDiagUID     uint32
	IDiagInode   uint32
}

InetDiagMsg is the linux binary representation of a InetDiag message header, as in linux/inet_diag.h Note that netlink messages use host byte ordering, unless NLA_F_NET_BYTEORDER flag is present.

type InetDiagReqV2

type InetDiagReqV2 struct {
	SDiagFamily   uint8
	SDiagProtocol uint8
	IDiagExt      uint8
	Pad           uint8
	IDiagStates   uint32
	ID            InetDiagSockID
}

InetDiagReqV2 is the Netlink request struct, as in linux/inet_diag.h Note that netlink messages use host byte ordering, unless NLA_F_NET_BYTEORDER flag is present.

func NewInetDiagReqV2

func NewInetDiagReqV2(family, protocol uint8, states uint32) *InetDiagReqV2

NewInetDiagReqV2 creates a new request.

func (*InetDiagReqV2) Len

func (req *InetDiagReqV2) Len() int

Len is provided for json serialization?

func (*InetDiagReqV2) Serialize

func (req *InetDiagReqV2) Serialize() []byte

Serialize is provided for json serialization? TODO - should use binary functions instead?

type InetDiagSockID

type InetDiagSockID struct {
	IDiagSPort [2]byte
	IDiagDPort [2]byte
	IDiagSrc   [16]byte
	IDiagDst   [16]byte
	IDiagIf    [4]byte
	// TODO - change this to [2]uint32 ?
	IDiagCookie [8]byte
}

InetDiagSockID is the binary linux representation of a socket, as in linux/inet_diag.h Linux code comments indicate this struct uses the network byte order!!!

func (*InetDiagSockID) Cookie

func (id *InetDiagSockID) Cookie() uint64

Cookie returns the SockID's 64 bit unsigned cookie.

func (*InetDiagSockID) DPort

func (id *InetDiagSockID) DPort() uint16

DPort returns the host byte ordered port. In general, Netlink is supposed to use host byte order, but this seems to be an exception. Perhaps Netlink is reading a tcp stack structure that holds the port in network byte order.

func (*InetDiagSockID) DstIP

func (id *InetDiagSockID) DstIP() net.IP

DstIP returns a golang net encoding of destination address.

func (*InetDiagSockID) Interface

func (id *InetDiagSockID) Interface() uint32

Interface returns the interface number.

func (*InetDiagSockID) SPort

func (id *InetDiagSockID) SPort() uint16

SPort returns the host byte ordered port. In general, Netlink is supposed to use host byte order, but this seems to be an exception. Perhaps Netlink is reading a tcp stack structure that holds the port in network byte order.

func (*InetDiagSockID) SrcIP

func (id *InetDiagSockID) SrcIP() net.IP

SrcIP returns a golang net encoding of source address.

func (*InetDiagSockID) String

func (id *InetDiagSockID) String() string

Jump to

Keyboard shortcuts

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