# `Linx.Netlink.Rtnl.Stats`
[🔗](https://github.com/oshlabs/linx/blob/v0.2.0/lib/linx/netlink/rtnl/stats.ex#L1)

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.

# `t`

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

# `decode`

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

Decodes a netlink message body into a `t:t/0`.

# `encode`

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

Encodes a `t:t/0` into its netlink message body.

# `get`

```elixir
@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`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
