# README
diag

This is a work in progress version of diag
. It provides a C-binding free API to the netlink based socket statistics system.
Example
package main
import (
"fmt"
"os"
"github.com/florianl/go-diag"
)
func main() {
// open a netlink socket
nl, err := diag.Open(&diag.Config{})
if err != nil {
fmt.Fprintf(os.Stderr, "could not open netlink socket: %v\n", err)
return
}
defer nl.Close()
// Dump all TCP sockets
tcpSockets, err := nl.TCPDump()
if err != nil {
fmt.Fprintf(os.Stderr, "could not dump data: %v\n", err)
return
}
// Loop over tcpSockets and print out source- and destination IP with
// the respective port information.
for _, socket := range tcpSockets {
src := diag.ToNetipAddr(socket.ID.Src)
srcPort := diag.Ntohs(socket.ID.SPort)
dst := diag.ToNetipAddr(socket.ID.Dst)
dstPort := diag.Ntohs(socket.ID.DPort)
fmt.Printf("%v:%d -> %v:%d\n", src, srcPort, dst, dstPort)
}
}
Requirements
- A version of Go that is supported by upstream
# Functions
Ntohs converts in from network byte order to host byte order represenation.
Open establishes a netlink socket for traffic control.
ToNetipAddr converts an IP in [4]uint32 representation to netip.Addr.
ToNetipAddrWithFamily converts an IP in [4]uint32 representation to netip.Addr using family as hint to interpret the IP.
# Structs
Based on tcp_bbr_info.
Config contains options for NETLINK_SOCK_DIAG.
Based on tcp_dctcp_info.
Diag represents a netlink wrapper.
Based on inet_diag_msg.
Based on inet_diag_req_v2.
Based on __kernel_sockaddr_storage in include/uapi/linux/socket.h.
Based on inet_diag_meminfo.
NetAttribute contains various elements.
NetObject represents a network response.
NetOption defines a query to network sockets.
No description provided by the author
Based on inet_diag_sockid.
Based on inet_diag_sockopt Bitfield1 and Bitfield2 are the Go representations for the following bit fields:
__u8 recverr:1, is_icsk:1, freebind:1, hdrincl:1, mc_loop:1, transparent:1, mc_all:1, nodefrag:1; __u8 bind_address_no_port:1, recverr_rfc4884:1, defer_connect:1, unused:5;.
TcpInfo based on tcp_info in include/uapi/linux/tcp.h.
UnixAttribute contains various elements.
Based on unix_diag_msg.
Based on unix_diag_req.
Based on unix_diag_rqlen.
Based on unix_diag_vfs.
No description provided by the author
UnixOption defines a query to Unix sockets.
Based on tcpvegas_info.