Documentation ¶
Overview ¶
Package inetdiag provides basic structs and utilities for INET_DIAG messaages. Based on uapi/linux/inet_diag.h.
Index ¶
Constants ¶
const ( TCPDIAG_GETSOCK = 18 // uapi/linux/inet_diag.h SOCK_DIAG_BY_FAMILY = 20 // uapi/linux/sock_diag.h )
Constants from linux.
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 INET_DIAG_MAX )
inet_diag.h
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?
const TCPF_ALL = 0xFFF
Variables ¶
var ( ErrParseFailed = errors.New("Unable to parse InetDiagMsg") ErrNotType20 = errors.New("NetlinkMessage wrong type") )
Error types.
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") )
Functions ¶
func LoadNext ¶
func LoadNext(rdr io.Reader) (*syscall.NetlinkMessage, error)
LoadNext is a simple utility to read the next NetlinkMessage from a source reader, e.g. from a file of saved netlink messages.
func OneType ¶
func OneType(inetType uint8) ([]*syscall.NetlinkMessage, error)
OneType handles the request and response for a single type, e.g. INET or INET6 TODO maybe move this to top level?
func ParseRouteAttr ¶
func ParseRouteAttr(b []byte) ([]syscall.NetlinkRouteAttr, error)
ParseRouteAttr parses a byte array into a NetlinkRouteAttr struct.
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.
func ParseInetDiagMsg ¶
func ParseInetDiagMsg(data []byte) (*InetDiagMsg, []byte)
ParseInetDiagMsg returns the InetDiagMsg itself, and the aligned byte array containing the message content. Modified from original to also return attribute data array.
func (*InetDiagMsg) String ¶
func (msg *InetDiagMsg) String() string
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 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 ParsedMessage ¶
type ParsedMessage struct { Timestamp time.Time Header syscall.NlMsghdr InetDiagMsg *InetDiagMsg Attributes [INET_DIAG_MAX]*syscall.NetlinkRouteAttr }
ParsedMessage is a container for parsed InetDiag messages and attributes.
func Parse ¶
func Parse(msg *syscall.NetlinkMessage, skipLocal bool) (*ParsedMessage, error)
Parse parses the NetlinkMessage into a ParsedMessage. If skipLocal is true, it will return nil for loopback, local unicast, multicast, and unspecified connections. Note that Parse does not populate the Timestamp field, so caller should do so.