Linx.Netlink (Linx v0.1.0)

Copy Markdown View Source

Netlink for Elixir — a client for the Linux kernel's AF_NETLINK interface.

Netlink is how userspace talks to many kernel subsystems: the networking stack (rtnetlink), and — through generic netlink — WireGuard, nl80211 and more. Linx.Netlink speaks it directly, encoding and decoding messages in Elixir; a small NIF handles the one thing the BEAM cannot do safely on its own — entering another network namespace.

The library is layered, lower layers ignorant of higher ones:

Each protocol family then lives in its own namespace. The first is rtnetlink — the kernel's networking interface — under Linx.Netlink.Rtnl.

Example

# List the host's network interfaces.
{:ok, sock} = Linx.Netlink.Rtnl.open()
{:ok, links} = Linx.Netlink.Rtnl.Link.list(sock)
:ok = Linx.Netlink.Socket.close(sock)

Protocol families

Two protocol families are supported: rtnetlink (Linx.Netlink.Rtnl — links, addresses, routes, neighbours, rules) and nfnetlink (Linx.Netlink.Nfnl — the transport under Linx.Netfilter). The wire layers (Socket, Message, Attr, Request, Codec) are family-agnostic and shared across both. A concurrent-request connection process, a multicast monitor, and generic netlink (NETLINK_GENERIC) are future work.