Module architecture

Sockets

The idea behind the pyroute2 framework is pretty simple. The library provides socket objects, that have:

  • shortcuts to establish higher level connections (netlink, 9p, ...)

  • extra methods to run queries and protocols

The library core is based on asyncio, and provides both asynchronous and synchronous versions of API, where the synchronous one is a wrapper around the async code. This way we avoid keeping two separate codebase while providing the legacy sync API.

The library provides asynchronous sockets:

Inheritance diagram of pyroute2.dhcp.dhcp4socket.AsyncDHCP4Socket, pyroute2.AsyncAcpiEventSocket, pyroute2.AsyncConntrack, pyroute2.AsyncDL, pyroute2.AsyncDQuotSocket, pyroute2.AsyncDevlinkSocket, pyroute2.AsyncEventSocket, pyroute2.AsyncGenericNetlinkSocket, pyroute2.AsyncIPRSocket, pyroute2.AsyncIPRoute, pyroute2.AsyncIPSet, pyroute2.AsyncIPVS, pyroute2.AsyncIPVSSocket, pyroute2.AsyncIW, pyroute2.AsyncL2tp, pyroute2.AsyncMPTCP, pyroute2.AsyncNFCTSocket, pyroute2.AsyncNFTSocket, pyroute2.AsyncNL80211, pyroute2.AsyncNlEthtool, pyroute2.AsyncTaskStats, pyroute2.AsyncThermalEventSocket, pyroute2.AsyncWireGuard, pyroute2.Plan9ClientSocket, pyroute2.Plan9ServerSocket, pyroute2.dhcp.dhcp4socket.AsyncDHCP4Socket

And synchronous sockets:

Inheritance diagram of pyroute2.AcpiEventSocket, pyroute2.Conntrack, pyroute2.DL, pyroute2.DQuotSocket, pyroute2.DevlinkSocket, pyroute2.DiagSocket, pyroute2.EventSocket, pyroute2.GenericNetlinkSocket, pyroute2.IPBatch, pyroute2.IPQSocket, pyroute2.IPRSocket, pyroute2.IPRoute, pyroute2.IPSet, pyroute2.IPVS, pyroute2.IPVSSocket, pyroute2.IW, pyroute2.L2tp, pyroute2.MPTCP, pyroute2.NFCTSocket, pyroute2.NFTSocket, pyroute2.NL80211, pyroute2.NetNS, pyroute2.NlEthtool, pyroute2.ProcEventSocket, pyroute2.RawIPRoute, pyroute2.TaskStats, pyroute2.ThermalEventSocket, pyroute2.UeventSocket, pyroute2.WireGuard

Not all the synchronous sockets have got their asynchronous counterpart yet, but this work is ongoing.

PF_ROUTE messages

PF_ROUTE socket is used to receive notifications from the BSD kernel. The PF_ROUTE messages:

Inheritance diagram of pyroute2.bsd.pf_route.freebsd.bsdmsg, pyroute2.bsd.pf_route.freebsd.if_msg, pyroute2.bsd.pf_route.freebsd.rt_msg_base, pyroute2.bsd.pf_route.freebsd.ifa_msg_base, pyroute2.bsd.pf_route.freebsd.ifma_msg_base, pyroute2.bsd.pf_route.freebsd.if_announcemsg, pyroute2.bsd.pf_route.rt_slot, pyroute2.bsd.pf_route.rt_msg, pyroute2.bsd.pf_route.ifa_msg, pyroute2.bsd.pf_route.ifma_msg

Internet protocols

Beside of the netlink protocols, the library implements a limited set of supplementary internet protocol to play with.

Inheritance diagram of pyroute2.protocols.udpmsg, pyroute2.protocols.ip4msg, pyroute2.protocols.udp4_pseudo_header, pyroute2.protocols.ethmsg, pyroute2.dhcp.dhcp4msg.dhcp4msg