Monitoring netlink events with IPDB

103 views
Skip to first unread message

Eugene Crosser

unread,
Jul 25, 2017, 8:45:44 AM7/25/17
to pyroute2-dev
Hello,

I understand that you can read (all) netlink events as they happen into your python script if you call IPRoute.bind() and then .get(). I also understand that IPBD uses the same mechanism internally, to keep its snapshot of the network configuration state up to date. But I cannot find in the documentation if it is possible to use IPDB interfaces to listen to events. Ideally, it would be nice to be able to register some sort of callback, so that while you are processing an event, you can be sure that nobody will concurrently modify the state of the snapshot.

Does anything along these lines exist?

Thanks,

Eugene

Ragan Gidde

unread,
Jul 25, 2017, 8:50:25 AM7/25/17
to pyroute2-dev
May be this can serve the purpose:

register_callback(self, callback, mode='post') method of pyroute2.ipdb.main.IPDB instance
    IPDB callbacks are routines executed on a RT netlink
    message arrival. There are two types of callbacks:
    "post" and "pre" callbacks.

Thanks & Regards,
Ragan.

Eugene Crosser

unread,
Jul 25, 2017, 9:20:49 AM7/25/17
to pyroute2-dev
Thanks, it looks like exactly the right thing!
It is still not quite clear, (1) if it is guaranteed that no other thread will touch the state while the `post` callback is running, and (2) if it is allowed to perform actions on the IPDB instance that was passed to the callback function. The latter is easy to check though.

Eugene
Reply all
Reply to author
Forward
0 new messages