Non-RTNL platforms¶
pyroute2 offers experimental support for platforms that do not provide Netlink/RTNL, including BSD systems.
BSD systems¶
The library provides very basic RTNL API for BSD systems via protocol emulation. Only getters are supported yet, no setters.
BSD employs PF_ROUTE sockets to send notifications about network object changes, but the protocol doesn not allow changing links/addresses/etc like Netlink.
To change network setting one have to rely on system calls or external tools. Thus IPRoute on BSD systems is not as effective as on Linux, where all the changes are done via Netlink.
The monitoring started with bind() is implemented as an implicit thread, started by the bind() call. This is done to have only one notification FD, used both for normal calls and notifications. This allows to use IPRoute objects in poll/select calls.
On Linux systems RTNL API is provided by the netlink protocol, so no implicit threads are started by default to monitor the system updates. IPRoute.bind(...) may start the async cache thread, but only when asked explicitly:
#
# Normal monitoring. Always starts monitoring thread on
# FreeBSD / OpenBSD, no threads on Linux.
#
with IPRoute() as ipr:
ipr.bind()
...
#
# Monitoring with async cache. Always starts cache thread
# on Linux, ignored on FreeBSD / OpenBSD.
#
with IPRoute() as ipr:
ipr.bind(async_cache=True)
...
On all the supported platforms, be it Linux or BSD, the IPRoute.recv(...) method returns valid netlink RTNL raw binary payload and IPRoute.get(...) returns parsed RTNL messages.
Windows systems¶
Windows systems are not supported, but the library provides some proof-of-concept how to build an RTNL-compatible core on top of WinAPI calls.
Only two methods are provided so far. If you're interested in extending the functionality, you're welcome to propose PRs.
Warning
Using pyroute2 on Windows requires installing win_inet_pton module, you can use pip install win_inet_pton.
- class pyroute2.iproute.windows.IPRoute(*argv, **kwarg)¶
- get_links(*argv, **kwarg)¶
Get network interfaces list:
>>> pprint(ipr.get_links()) [{'attrs': (['IFLA_ADDRESS', '52:54:00:7a:8a:49'], ['IFLA_IFNAME', '{F444467B-3549-455D-81F2-AB617C7421AB}']), 'change': 0, 'family': 0, 'flags': 0, 'header': {}, 'ifi_type': 0, 'index': 7}]
- get_addr(*argv, **kwarg)¶
Get IP addresses:
>>> pprint(ipr.get_addr()) [{'attrs': (['IFA_ADDRESS', '192.168.122.81'], ['IFA_LOCAL', '192.168.122.81'], ['IFA_LABEL', '{F444467B-3549-455D-81F2-AB617C7421AB}']), 'family': <AddressFamily.AF_INET: 2>, 'flags': 0, 'header': {}, 'index': 7, 'prefixlen': 24, 'scope': 0}]