-
Notifications
You must be signed in to change notification settings - Fork 20
Issue#4 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Issue#4 #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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""" | ||
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indenting looks weird here ? That should confuse Python. |
||
|
|
||
| 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): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,12 @@ def __init__(self, subsys, subscriptions): | |
| self.conntrack = None | ||
| self.handle = None | ||
|
|
||
| self.subsys = subsys | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is it use ? Do you plan to do something with it ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used on next list (open a conntrack handler), however it is not really used in the class. The reason is that I saw several reports of dereferencements of data when using python clib because the garbage collector lost track of a variable used in the c library and cleaned it up. |
||
| self.subscriptions = subscriptions | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
|
||
| # 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): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,10 @@ | |
| # | ||
| #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_int | ||
| #nfct_handle_p = c_int | ||
| nf_conntrack_p = c_void_p | ||
| nfct_handle_p = c_void_p | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is a fix, it is a fix: you can remove commented lines. |
||
|
|
||
| class nfct_conntrack_compare_t(Structure): | ||
| _fields_ = ( | ||
|
|
@@ -33,7 +35,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 | ||
|
|
@@ -81,7 +83,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 | ||
|
|
||
| #-------------------------------------------------------------------------- | ||
|
|
@@ -93,7 +95,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 | ||
|
|
||
| #-------------------------------------------------------------------------- | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indent here too.