FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-nfqueue/python/libnetfilter_queue_python.i at master · Lasertooth/python-nfqueue · GitHub
Lasertooth
/
python-nfqueue
Public
forked from
jrazer/python-nfqueue
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-nfqueue
/
python
/
libnetfilter_queue_python.i
Copy path
More file actions
More file actions
Latest commit
History
History
History
98 lines (80 loc) · 2.52 KB
Breadcrumbs
python-nfqueue
/
python
/
libnetfilter_queue_python.i
Copy path
File metadata and controls
98 lines (80 loc) · 2.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
Grab a Python function object as a Python object.
%typemap(in) PyObject *pyfunc {
if
(!
PyCallable_Check
($input)) {
PyErr_SetString
(PyExc_TypeError,
"
Need a callable object!
"
);
return
NULL
;
}
$
1
= $input;
}
%{
#
include
<
arpa/inet.h
>
#
include
<
linux/netfilter.h
>
#
include
<
linux/ip.h
>
#
include
<
nfq_utils.h
>
int
swig_nfq_callback
(
struct
nfq_q_handle
*qh,
struct
nfgenmsg
*nfmsg,
struct
nfq_data
*nfad,
void
*data)
{
int
id =
0
;
struct
nfqnl_msg_packet_hdr
*ph;
unsigned
char
*payload_data;
int
payload_len;
if
(data ==
NULL
) {
fprintf
(stderr,
"
No callback set !
\n
"
);
return
-
1
;
}
ph =
nfq_get_msg_packet_hdr
(nfad);
if
(ph){
id =
ntohl
(ph->
packet_id
);
}
if
((payload_len =
nfq_get_payload
(nfad, &payload_data)) <
0
) {
fprintf
(stderr,
"
Couldn't get payload
\n
"
);
return
-
1
;
}
/*
printf("callback called\n");
printf("callback argument: %p\n",data);
*/
{
PyObject *func, *arglist, *payload_obj;
PyObject *result;
struct
payload
*p;
/*
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
*/
func = (PyObject *) data;
p =
malloc
(
sizeof
(
struct
payload
));
p->
data
= payload_data;
p->
len
= payload_len;
p->
id
= id;
p->
qh
= qh;
p->
nfad
= nfad;
payload_obj =
SWIG_NewPointerObj
((
void
*) p, SWIGTYPE_p_payload,
0
/*
| SWIG_POINTER_OWN
*/
);
arglist =
Py_BuildValue
(
"
(N)
"
,payload_obj);
result =
PyEval_CallObject
(func,arglist);
Py_DECREF
(arglist);
if
(result) {
Py_DECREF
(result);
}
result =
PyErr_Occurred
();
if
(result) {
printf
(
"
callback failure !
\n
"
);
PyErr_Print
();
}
/*
SWIG_PYTHON_THREAD_END_ALLOW;
*/
}
return
nfq_set_verdict
(qh, id,
NF_ACCEPT
,
0
,
NULL
);
}
%}
%extend queue {
int
set_callback
(PyObject *pyfunc)
{
self->
_cb
= (
void
*)pyfunc;
/*
printf("callback argument: %p\n",pyfunc);
*/
Py_INCREF
(pyfunc);
return
0
;
}
};
%typemap (out)
const
char
* get_data {
$result =
PyString_FromStringAndSize
($
1
,arg1->
len
);
//
blah
}
%extend payload {
const
char
*
get_data
(
void
) {
return
self->
data
;
}
};
Back
|
FazBrowse Home
|
New Git URL