-
Notifications
You must be signed in to change notification settings - Fork 2
/
chash.c
49 lines (42 loc) · 950 Bytes
/
chash.c
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
#include <Python.h>
#include "xdp-flowradar_kern.c"
#include <stdint.h>
static PyObject* c_hash(PyObject *self, PyObject *args) {
uint16_t result;
uint32_t saddr;
uint32_t daddr;
uint16_t sport;
uint16_t dport;
uint8_t proto;
uint16_t host;
uint8_t k;
if (!(PyArg_ParseTuple(
args, "IIHHBHB", &saddr, &daddr, &sport, &dport, &proto, &host, &k
))) {
return NULL;
}
struct five_tuple ft = {
.sport = sport,
.dport = dport,
.saddr = saddr,
.daddr = daddr,
.proto = proto,
};
return Py_BuildValue("H", hash(host, k, &ft));
}
static PyMethodDef CHashMethods[] =
{
{"c_hash", c_hash, METH_VARARGS, "c hash"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef cHashMod =
{
PyModuleDef_HEAD_INIT,
"cHash", "c hash",
-1,
CHashMethods
};
PyMODINIT_FUNC
PyInit_cHash(void) {
return PyModule_Create(&cHashMod);
}