forked from farsightsec/pynmsg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmsg.pxi
254 lines (211 loc) · 9.92 KB
/
nmsg.pxi
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# Copyright (c) 2009-2015, 2018-2019 by Farsight Security, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cdef extern from "stdio.h":
ctypedef void FILE
FILE *stdout
cdef extern from "stdbool.h":
ctypedef int bool
cdef extern from "stdint.h":
ctypedef unsigned char uint8_t
ctypedef unsigned short uint16_t
ctypedef unsigned int uint32_t
ctypedef unsigned long long uint64_t
ctypedef signed char int8_t
ctypedef signed short int16_t
ctypedef signed int int32_t
ctypedef signed long long int64_t
cdef extern from "stdlib.h":
ctypedef unsigned long size_t
void free(void *ptr)
void *malloc(size_t size)
void *realloc(void *ptr, size_t size)
size_t strlen(char *s)
char *strcpy(char *dest, char *src)
cdef extern from "time.h":
struct timespec:
long tv_sec
long tv_nsec
cdef extern from "Python.h":
void Py_INCREF(object)
void Py_DECREF(object)
void PyEval_InitThreads()
int PyErr_CheckSignals()
int PyErr_ExceptionMatches(object)
cdef extern from "nmsg.h" nogil:
cdef enum:
NMSG_WBUFSZ_MIN = 512
NMSG_WBUFSZ_MAX = 1048576
NMSG_WBUFSZ_JUMBO = 8192
NMSG_WBUFSZ_ETHER = 1280
cdef enum:
NMSG_MSGMOD_FIELD_REPEATED = 0x01
NMSG_MSGMOD_FIELD_REQUIRED = 0x02
cdef enum:
nmsg_alias_operator
nmsg_alias_group
ctypedef struct ProtobufCBinaryData:
size_t len
uint8_t *data
ctypedef enum nmsg_res:
nmsg_res_success
nmsg_res_failure
nmsg_res_eof
nmsg_res_memfail
nmsg_res_magic_mismatch
nmsg_res_version_mismatch
nmsg_res_pbuf_ready
nmsg_res_notimpl
nmsg_res_stop
nmsg_res_again
nmsg_res_parse_error
nmsg_res_pcap_error
nmsg_res_read_failrue
ctypedef enum nmsg_msgmod_field_type:
nmsg_msgmod_ft_enum
nmsg_msgmod_ft_bytes
nmsg_msgmod_ft_string
nmsg_msgmod_ft_mlstring
nmsg_msgmod_ft_ip
nmsg_msgmod_ft_uint16
nmsg_msgmod_ft_uint32
nmsg_msgmod_ft_uint64
nmsg_msgmod_ft_int16
nmsg_msgmod_ft_int32
nmsg_msgmod_ft_int64
nmsg_msgmod_ft_double
nmsg_msgmod_ft_bool
ctypedef enum nmsg_output_type:
nmsg_output_type_stream
nmsg_output_type_pres
nmsg_output_type_callback
struct nmsg_input:
pass
struct nmsg_io:
pass
struct nmsg_message:
pass
struct nmsg_msgmod:
pass
struct nmsg_msgmodset:
pass
struct nmsg_output:
pass
struct nmsg_pcap:
pass
struct nmsg_pres:
pass
struct nmsg_rate:
pass
struct nmsg_ipreasm:
pass
struct nmsg_strbuf:
pass
struct nmsg_zbuf:
pass
struct nmsg_ipdg:
int proto_network
int proto_transport
unsigned len_network
unsigned len_transport
unsigned len_payload
unsigned char *network
unsigned char *transport
unsigned char *payload
ctypedef nmsg_input * nmsg_input_t
ctypedef nmsg_io * nmsg_io_t
ctypedef nmsg_message * nmsg_message_t
ctypedef nmsg_msgmod * nmsg_msgmod_t
ctypedef nmsg_output * nmsg_output_t
ctypedef nmsg_pcap * nmsg_pcap_t
ctypedef nmsg_pres * nmsg_pres_t
ctypedef nmsg_rate * nmsg_rate_t
ctypedef nmsg_ipreasm * nmsg_ipreasm_t
ctypedef nmsg_strbuf * nmsg_strbuf_t
ctypedef nmsg_zbuf * nmsg_zbuf_t
ctypedef void (*nmsg_cb_message)(nmsg_message_t, void *user)
nmsg_res nmsg_init()
void nmsg_set_autoclose(bool)
void nmsg_set_debug(int)
char * nmsg_res_lookup(unsigned res)
char * nmsg_alias_by_key(unsigned ae, unsigned key)
unsigned nmsg_alias_by_value(unsigned ae, char *value)
nmsg_io_t nmsg_io_init()
nmsg_res nmsg_io_add_input(nmsg_io_t, nmsg_input_t, void *user)
nmsg_res nmsg_io_add_output(nmsg_io_t, nmsg_output_t, void *user)
nmsg_res nmsg_io_loop(nmsg_io_t) nogil
void nmsg_io_breakloop(nmsg_io_t)
void nmsg_io_destroy(nmsg_io_t *)
void nmsg_io_set_debug(nmsg_io_t, int debug)
unsigned nmsg_msgmod_get_max_vid()
unsigned nmsg_msgmod_get_max_msgtype(unsigned vid)
const char * nmsg_msgmod_vid_to_vname(unsigned vid)
char * nmsg_msgmod_msgtype_to_mname(unsigned vid, unsigned msgtype)
nmsg_msgmod_t nmsg_msgmod_lookup(unsigned vid, unsigned msgtype)
nmsg_msgmod_t nmsg_msgmod_lookup_byname(char *vname, char *mname)
unsigned nmsg_msgmod_vname_to_vid(char *vname)
unsigned nmsg_msgmod_mname_to_msgtype(unsigned vid, char *mname)
nmsg_res nmsg_msgmod_init(nmsg_msgmod_t mod, void **clos)
nmsg_res nmsg_msgmod_fini(nmsg_msgmod_t mod, void **clos)
nmsg_message_t nmsg_message_init(nmsg_msgmod_t mod)
void nmsg_message_destroy(nmsg_message_t *msg)
nmsg_res nmsg_message_get_num_fields(nmsg_message_t msg, size_t *n_fields)
nmsg_res nmsg_message_get_field_name(nmsg_message_t msg, unsigned idx, char **field_name)
nmsg_res nmsg_message_get_field_type_by_idx(nmsg_message_t msg, unsigned field_idx, nmsg_msgmod_field_type *type)
nmsg_res nmsg_message_get_field_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned val_idx, void **data, size_t *len)
nmsg_res nmsg_message_get_field_flags_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned *flags)
nmsg_res nmsg_message_set_field(nmsg_message_t msg, char *field_name, unsigned val_idx, uint8_t *data, size_t len)
int32_t nmsg_message_get_vid(nmsg_message_t msg)
int32_t nmsg_message_get_msgtype(nmsg_message_t msg)
void nmsg_message_get_time(nmsg_message_t msg, timespec *ts)
uint32_t nmsg_message_get_source(nmsg_message_t msg)
uint32_t nmsg_message_get_operator(nmsg_message_t msg)
uint32_t nmsg_message_get_group(nmsg_message_t msg)
void nmsg_message_set_time(nmsg_message_t msg, timespec *ts)
void nmsg_message_set_source(nmsg_message_t msg, unsigned source)
void nmsg_message_set_operator(nmsg_message_t msg, unsigned operator)
void nmsg_message_set_group(nmsg_message_t msg, unsigned group)
nmsg_res nmsg_message_enum_name_to_value(nmsg_message_t msg, char *field_name, char *name, unsigned *value)
nmsg_res nmsg_message_enum_name_to_value_by_idx(nmsg_message_t msg, unsigned field_idx, char *name, unsigned *value)
nmsg_res nmsg_message_enum_value_to_name(nmsg_message_t msg, char *field_name, unsigned value, char **name)
nmsg_res nmsg_message_enum_value_to_name_by_idx(nmsg_message_t msg, unsigned field_idx, unsigned value, char **name)
nmsg_input_t nmsg_input_open_file(int fd) nogil
nmsg_input_t nmsg_input_open_json(int fd) nogil
nmsg_input_t nmsg_input_open_sock(int fd) nogil
nmsg_input_t nmsg_input_open_null()
nmsg_res nmsg_input_close(nmsg_input_t *input)
nmsg_res nmsg_input_read(nmsg_input_t input, nmsg_message_t *msg)
nmsg_res nmsg_input_read_null(nmsg_input_t input, uint8_t *buf, size_t buf_len, timespec *ts, nmsg_message_t **msgarray, size_t *n_msg) nogil
void nmsg_input_set_filter_msgtype(nmsg_input_t input, unsigned vid, unsigned msgtype)
void nmsg_input_set_filter_source(nmsg_input_t input, unsigned source)
void nmsg_input_set_filter_operator(nmsg_input_t input, unsigned operator)
void nmsg_input_set_filter_group(nmsg_input_t input, unsigned group)
nmsg_res nmsg_input_set_blocking_io(nmsg_input_t input, bool flag)
nmsg_output_t nmsg_output_open_file(int fd, size_t bufsz)
nmsg_output_t nmsg_output_open_json(int fd)
nmsg_output_t nmsg_output_open_sock(int fd, size_t bufsz)
nmsg_output_t nmsg_output_open_callback(nmsg_cb_message cb, void *user)
nmsg_res nmsg_output_flush(nmsg_output_t output)
nmsg_res nmsg_output_write(nmsg_output_t output, nmsg_message_t msg)
nmsg_res nmsg_output_close(nmsg_output_t *output)
void nmsg_output_set_buffered(nmsg_output_t output, bool buffered)
void nmsg_output_set_filter_msgtype(nmsg_output_t output, unsigned vid, unsigned msgtype)
void nmsg_output_set_rate(nmsg_output_t output, nmsg_rate_t rate)
void nmsg_output_set_endline(nmsg_output_t output, char *endline)
void nmsg_output_set_source(nmsg_output_t output, unsigned source)
void nmsg_output_set_operator(nmsg_output_t output, unsigned operator)
void nmsg_output_set_group(nmsg_output_t output, unsigned group)
void nmsg_output_set_zlibout(nmsg_output_t output, bool zlibout)
nmsg_res nmsg_ipdg_parse(nmsg_ipdg *, unsigned etype, size_t, unsigned char *pkt)
nmsg_res nmsg_message_from_json(char *, nmsg_message_t *) nogil
nmsg_res nmsg_message_to_json(nmsg_message_t, char **)