Module architecture — pyroute2 0.9.4 documentation

# 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:

And synchronous sockets:

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

## Netlink messages

To handle the data going through the sockets, the library uses different message classes. To create a custom message type, one should inherit:

> - nlmsg to create a netlink message class

> - genlmsg to create generic netlink message class

> - nla to create a NLA class

The messages hierarchy:

## PF_ROUTE messages

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

## Internet protocols

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