Linx.Netlink.Rtnl.Stats (Linx v0.1.0)

Copy Markdown View Source

rtnetlink interface statistics — the RTM_GETSTATS reads.

get/2 returns one interface's counters; list/1 dumps every interface's. Both verbs are read-only — no CAP_NET_ADMIN needed.

The counters live on the :link field as a Linx.Netlink.Rtnl.Stats.Link64 sub-struct. IFLA_STATS_LINK_64 is the only stats class Linx decodes today; the kernel exposes others (XSTATS, OFFLOAD_XSTATS, AF_SPEC) under sibling attribute IDs and they will be added as the need arises.

The wire format — struct if_stats_msg (include/uapi/linux/rtnetlink.h) and the IFLA_STATS_* attributes (include/uapi/linux/if_link.h) — is declared with the Linx.Netlink.Codec DSL.

Summary

Functions

Decodes a netlink message body into a t/0.

Encodes a t/0 into its netlink message body.

Returns the statistics for the link named name.

Returns the statistics for every link in the socket's namespace.

Types

t()

@type t() :: %Linx.Netlink.Rtnl.Stats{
  family: term(),
  filter_mask: term(),
  ifindex: term(),
  link: term()
}

Functions

decode(body)

@spec decode(binary()) :: t()

Decodes a netlink message body into a t/0.

encode(message)

@spec encode(t()) :: binary()

Encodes a t/0 into its netlink message body.

get(socket, name)

@spec get(Linx.Netlink.Socket.t(), binary()) :: {:ok, t()} | {:error, term()}

Returns the statistics for the link named name.

Resolves the interface index by name first, then issues a single RTM_GETSTATS request with that index. Returns {:error, %Linx.Netlink.Error{}} if there is no such interface.

list(socket)

@spec list(Linx.Netlink.Socket.t()) :: {:ok, [t()]} | {:error, term()}

Returns the statistics for every link in the socket's namespace.