summaryrefslogtreecommitdiff
path: root/python/netlink/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/netlink/core.py')
-rw-r--r--python/netlink/core.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/python/netlink/core.py b/python/netlink/core.py
index 3298e2ce..f43fd2c1 100644
--- a/python/netlink/core.py
+++ b/python/netlink/core.py
@@ -10,6 +10,8 @@ This module provides an interface to netlink sockets
The module contains the following public classes:
- Socket -- The netlink socket
+ - Message -- The netlink message
+ - Callback -- The netlink callback handler
- Object -- Abstract object (based on struct nl_obect in libnl) used as
base class for all object types which can be put into a Cache
- Cache -- A collection of objects which are derived from the base
@@ -34,8 +36,9 @@ import sys
import socket
__all__ = [
- 'Message',
'Socket',
+ 'Message',
+ 'Callback',
'DumpParams',
'Object',
'Cache',
@@ -153,6 +156,30 @@ class Message(object):
def send(self, sock):
sock.send(self)
+class Callback(object):
+ """Netlink callback"""
+
+ def __init__(self, kind=capi.NL_CB_DEFAULT):
+ if isinstance(kind, Callback):
+ self._cb = capi.py_nl_cb_clone(kind._cb)
+ else:
+ self._cb = capi.nl_cb_alloc(kind)
+
+ def __del__(self):
+ capi.py_nl_cb_put(self._cb)
+
+ def set_type(self, t, k, handler, obj):
+ return capi.py_nl_cb_set(self._cb, t, k, handler, obj)
+
+ def set_all(self, k, handler, obj):
+ return capi.py_nl_cb_set_all(self._cb, k, handler, obj)
+
+ def set_err(self, k, handler, obj):
+ return capi.py_nl_cb_err(self._cb, k, handler, obj)
+
+ def clone(self):
+ return Callback(self)
+
class Socket(object):
"""Netlink socket"""