Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pynetfilter_conntrack/conntrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ def register_callback(self, callback, event_type=NFCT_T_ALL, data=None):
return: NFCT_CB_CONTINUE, NFCT_CB_FAILURE, NFCT_CB_STOP,
or NFCT_CB_STOLEN (like continue, but ct is not freed).
"""
self.event_type = event_type
self.callback = nfct_callback_t(callback)
self.callback_arg = data
nfct_callback_register(self.handle, event_type, self.callback, self.callback_arg)
ret = nfct_callback_register(self.handle, self.event_type, self.callback, self.callback_arg)
if ret == -1:
self._error('nfct_callback_register')
elif ret != 0:
self._error('nfct_callback_register unknown return code')

def unregister_callback(self):
"""Unregister callback"""
Expand Down Expand Up @@ -90,9 +95,13 @@ def query(self, command, argument):

May raise a RuntimeError.
"""
ret = nfct_query(self.handle, command, argument)
if ret != 0:
self.query_type = command

ret = nfct_query(self.handle, self.query_type, byref(argument))
if ret == -1:
self._error('nfct_query')
elif ret != 0:
self._error('nfct_query unknown return code')

def catch(self, callback):
"""
Expand Down
7 changes: 5 additions & 2 deletions pynetfilter_conntrack/conntrack_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ def __init__(self, subsys, subscriptions):
self.conntrack = None
self.handle = None

self.subsys = subsys
self.subscriptions = subscriptions

# Open a conntrack handler
self.handle = nfct_open(subsys, subscriptions)
if not self.handle:
self.handle = nfct_open(self.subsys, self.subscriptions)
if self.handle == None:
self._error('nfct_new')

def _error(self, func_name):
Expand Down
10 changes: 5 additions & 5 deletions pynetfilter_conntrack/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#
#nf_conntrack_p = POINTER(nf_conntrack)
#nfct_handle_p = POINTER(nfct_handle)
nf_conntrack_p = c_int
nfct_handle_p = c_int
nf_conntrack_p = c_void_p
nfct_handle_p = c_void_p

class nfct_conntrack_compare_t(Structure):
_fields_ = (
Expand All @@ -33,7 +33,7 @@ class nfct_conntrack_compare_t(Structure):
# void *data)
#
# Callback type
nfct_callback_t = CFUNCTYPE(c_int, c_int, nf_conntrack_p, c_void_p)
nfct_callback_t = CFUNCTYPE(c_int, c_uint, nf_conntrack_p, c_void_p)

#--------------------------------------------------------------------------
# struct nf_conntrack *nfct_new(void): Allocate a new conntrack
Expand Down Expand Up @@ -81,7 +81,7 @@ class nfct_conntrack_compare_t(Structure):
# On error, -1 is returned and errno is explicitely set. On success, 0
# is returned
nfct_query = library.nfct_query
nfct_query.argtypes = (nfct_handle_p, c_int, c_void_p)
nfct_query.argtypes = (nfct_handle_p, c_uint, c_void_p)
nfct_query.restype = c_int

#--------------------------------------------------------------------------
Expand All @@ -93,7 +93,7 @@ class nfct_conntrack_compare_t(Structure):
# void *data);
# Register callback.
nfct_callback_register = library.nfct_callback_register
nfct_callback_register.argtypes = (nfct_handle_p, c_int, nfct_callback_t, c_void_p)
nfct_callback_register.argtypes = (nfct_handle_p, c_uint, nfct_callback_t, c_void_p)
nfct_callback_register.restype = c_int

#--------------------------------------------------------------------------
Expand Down