Getting Linux routing table using netlink.

In the previous article we discussed monitoring of the network interfaces using netlink. Now it’s time to do something more complex and interesting.
Let’s discover how to get and print system routing table like a “ip route” command do.

Continue reading “Getting Linux routing table using netlink.”

Monitoring Linux networking state using netlink

Once in my work i needed to monitor all changes in the Linux networking subsystem: adding or deleting IP addresses, routes and so on.
Maybe the best way to do this is use socket-based netlink technology. Using netlink we can “subscribe” to some network-related notifications from the kernel, also it’s possible to send commands to the network stack and change routing table, interfaces configurations and packets filtering. For example, popular utilities like “iproute2” is also using netlink to do their job.
Easiest way to access netlink sockets from the userspace is to use libnetlink library which provides a bunch of macroses, defines and functions.
Worst part of this library and whole netlink technology is a lack of the good examples.
Good solution in this case is use iproute2 source code to discover things you interesting in. This article is also may be used as good startup point.

Continue reading “Monitoring Linux networking state using netlink”