inetdiag

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 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 (
	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")
)
View Source
var Protocol_name = map[int32]string{
	0:  "IPPROTO_UNUSED",
	6:  "IPPROTO_TCP",
	17: "IPPROTO_UDP",
	33: "IPPROTO_DCCP",
}
View Source
var Protocol_value = map[string]int32{
	"IPPROTO_UNUSED": 0,
	"IPPROTO_TCP":    6,
	"IPPROTO_UDP":    17,
	"IPPROTO_DCCP":   33,
}

Functions

This section is empty.

Types

type BBRInfo added in v0.0.7

type BBRInfo struct {
	Bw         int64  // Max-filtered BW (app throughput) estimate in bytes/second
	MinRtt     uint32 // Min-filtered RTT in uSec
	PacingGain uint32 // Pacing gain shifted left 8 bits
	CwndGain   uint32 // Cwnd gain shifted left 8 bits
}

BBRInfo corresponds to linux struct tcp_bbr_info. Used for decoding attribute Type:INET_DIAG_BBRINFO

type DCTCPInfo added in v0.0.7

type DCTCPInfo struct {
	Enabled uint16
	CEState uint16
	Alpha   uint32
	ABEcn   uint32
	ABTot   uint32
}

INET_DIAG_DCTCPINFO

type HostCond added in v0.0.7

type HostCond struct {
	Family    uint8  // __u8 family
	PrefixLen uint8  // __u8 prefix_len
	Port      uint16 // int port
	Addr      uint32 // __be32	addr[0];
}

These are related to filters. We don't currently use filters, so we ignore this type.

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. INET_DIAG_INFO

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

type MarkCond added in v0.0.7

type MarkCond struct {
	Mark uint32
	Mask uint32
}

type MemInfo added in v0.0.7

type MemInfo struct {
	Rmem uint32
	Wmem uint32
	Fmem uint32
	Tmem uint32
}

MemInfo corresponds to the linux struct inet_diag_meminfo. In is used to decode attribute Type INET_DIAG_MEMINFO

type Protocol added in v0.0.7

type Protocol uint8

if (tb[INET_DIAG_PROTOCOL])

s->raw_prot = rta_getattr_u8(tb[INET_DIAG_PROTOCOL]);
const (
	Protocol_IPPROTO_UNUSED Protocol = 0
	Protocol_IPPROTO_TCP    Protocol = 6
	Protocol_IPPROTO_UDP    Protocol = 17
	Protocol_IPPROTO_DCCP   Protocol = 33
)

type SocketMemInfo added in v0.0.7

type SocketMemInfo struct {
	RmemAlloc  uint32
	Rcvbuf     uint32
	WmemAlloc  uint32
	Sndbuf     uint32
	FwdAlloc   uint32
	WmemQueued uint32
	Optmem     uint32
	Backlog    uint32
	Drops      uint32
}

Haven't found a corresponding linux struct, but the message is described in https://manpages.debian.org/stretch/manpages/sock_diag.7.en.html INET_DIAG_SKMEMINFO

type VegasInfo added in v0.0.7

type VegasInfo struct {
	Enabled  uint32
	RTTCount uint32
	RTT      uint32
	MinRTT   uint32
}

INET_DIAG_VEGASINFO

Jump to

Keyboard shortcuts

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