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.iproute.linux.AsyncIPRoute, pyroute2.netlink.rtnl.iprsocket.AsyncIPRSocket, pyroute2.plan9.client.Plan9ClientSocket, pyroute2.plan9.server.Plan9ServerSocket, pyroute2.dhcp.dhcp4socket.AsyncDHCP4Socket

And syncronous sockets:

Inheritance diagram of pyroute2.iproute.linux.IPRoute, pyroute2.iproute.linux.IPRoute, pyroute2.iproute.linux.RawIPRoute, pyroute2.netlink.rtnl.iprsocket.IPRSocket, pyroute2.iwutil.IW, pyroute2.ipset.IPSet, pyroute2.ipvs.IPVS, pyroute2.netlink.uevent.UeventSocket, pyroute2.netlink.taskstats.TaskStats, pyroute2.netlink.generic.wireguard.WireGuard, pyroute2.netlink.generic.ethtool.NlEthtool, pyroute2.netlink.ipq.IPQSocket, pyroute2.netlink.nfnetlink.nfctsocket.NFCTSocket, pyroute2.netlink.nfnetlink.nftsocket.NFTSocket, pyroute2.netlink.event.EventSocket, pyroute2.netlink.event.acpi_event.AcpiEventSocket, pyroute2.netlink.event.dquot.DQuotSocket, pyroute2.netlink.event.thermal.ThermalEventSocket, pyroute2.netlink.devlink.DevlinkSocket, pyroute2.netlink.diag.DiagSocket

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