nmsg 1.1.2
msgmod_plugin.h
1/*
2 * Copyright (c) 2008, 2009, 2013, 2015 by Farsight Security, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef NMSG_MSGMOD_PLUGIN_H
18#define NMSG_MSGMOD_PLUGIN_H
19
20#include <nmsg.h>
21
22#include <protobuf-c/protobuf-c.h>
23#include <nmsg/nmsg.pb-c.h>
24
26
28#define NMSG_MSGMOD_VERSION 9
29
31typedef nmsg_res (*nmsg_msgmod_init_fp)(void **clos);
32
34typedef nmsg_res (*nmsg_msgmod_fini_fp)(void **clos);
35
37typedef nmsg_res (*nmsg_msgmod_payload_to_pres_fp)(Nmsg__NmsgPayload *np,
38 char **pres,
39 const char *endline);
40
42typedef nmsg_res (*nmsg_msgmod_ipdg_to_payload_fp)(void *clos,
43 const struct nmsg_ipdg *dg,
44 uint8_t **pbuf, size_t *sz);
45
46typedef nmsg_res (*nmsg_msgmod_pkt_to_payload_fp)(void *clos,
47 nmsg_pcap_t pcap,
48 nmsg_message_t *m);
49
50typedef nmsg_res (*nmsg_msgmod_pcap_init_fp)(void *clos, nmsg_pcap_t pcap);
51
53typedef nmsg_res (*nmsg_msgmod_msg_load_fp)(nmsg_message_t m, void **msg_clos);
54
56typedef nmsg_res (*nmsg_msgmod_msg_fini_fp)(nmsg_message_t m, void *msg_clos);
57
59typedef nmsg_res (*nmsg_msgmod_field_print_fp)(nmsg_message_t m,
60 struct nmsg_msgmod_field *field,
61 void *ptr,
62 struct nmsg_strbuf *sb,
63 const char *endline);
64
66typedef nmsg_res (*nmsg_msgmod_field_get_fp)(nmsg_message_t m,
67 struct nmsg_msgmod_field *field,
68 unsigned val_idx,
69 void **data,
70 size_t *len,
71 void *msg_clos);
72
74typedef nmsg_res (*nmsg_msgmod_field_format_fp)(nmsg_message_t m,
75 struct nmsg_msgmod_field *field,
76 void *ptr,
77 struct nmsg_strbuf *sb,
78 const char *endline);
79
81typedef nmsg_res (*nmsg_msgmod_field_parse_fp)(nmsg_message_t m,
82 struct nmsg_msgmod_field *field,
83 const char *value,
84 void **ptr,
85 size_t *len,
86 const char *endline);
87
89#define NMSG_MSGMOD_FIELD_PRINTER(funcname) \
90 nmsg_res funcname(nmsg_message_t m, \
91 struct nmsg_msgmod_field *field, \
92 void *ptr, \
93 struct nmsg_strbuf *sb, \
94 const char *endline)
95
97#define NMSG_MSGMOD_FIELD_GETTER(funcname) \
98 nmsg_res funcname(nmsg_message_t m, \
99 struct nmsg_msgmod_field *field, \
100 unsigned val_idx, \
101 void **data, \
102 size_t *len, \
103 void *msg_clos)
104
106#define NMSG_MSGMOD_FIELD_FORMATTER(funcname) \
107 nmsg_res funcname(nmsg_message_t m, \
108 struct nmsg_msgmod_field *field, \
109 void *ptr, \
110 struct nmsg_strbuf *sb, \
111 const char *endline)
112
114#define NMSG_MSGMOD_FIELD_PARSER(funcname) \
115 nmsg_res funcname(nmsg_message_t m, \
116 struct nmsg_msgmod_field *field, \
117 const char *value, \
118 void **ptr, \
119 size_t *len, \
120 const char *endline)
121
123#define NMSG_MSGMOD_REQUIRED_INIT \
124 .msgver = NMSG_MSGMOD_VERSION, \
125 .protobuf_c_version_number = PROTOBUF_C_VERSION_NUMBER
126
147
149 const char *name;
150
152 unsigned flags;
153
155 nmsg_msgmod_field_print_fp print;
156
158 nmsg_msgmod_field_get_fp get;
159
161 const ProtobufCFieldDescriptor *descr;
162
163 /* Optional custom field formatter function. */
164 nmsg_msgmod_field_format_fp format;
165
166 /* Optional custom field parser function. */
167 nmsg_msgmod_field_parse_fp parse;
168
170 void *_reserved1;
171 void *_reserved0;
172};
173
175#define NMSG_MSGMOD_FIELD_END { 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
176
190typedef enum {
191 nmsg_msgmod_type_transparent,
192 nmsg_msgmod_type_opaque
193} nmsg_msgmod_type;
194
214
218 nmsg_msgmod_type type;
219
225
231
235 nmsg_msgmod_init_fp init;
236
240 nmsg_msgmod_fini_fp fini;
241
247 nmsg_msgmod_msg_load_fp msg_load;
248
252 nmsg_msgmod_msg_fini_fp msg_fini;
253
262 nmsg_msgmod_payload_to_pres_fp payload_to_pres;
263
270 nmsg_msgmod_ipdg_to_payload_fp ipdg_to_payload;
271
279 const ProtobufCMessageDescriptor *pbdescr;
280
287
294 nmsg_msgmod_pkt_to_payload_fp pkt_to_payload;
295
305
310 nmsg_msgmod_pcap_init_fp pcap_init;
311
315 void *_reserved9;
316 void *_reserved8;
317 void *_reserved7;
318 void *_reserved6;
319 void *_reserved5;
320 void *_reserved4;
321 void *_reserved3;
322 void *_reserved2;
323 void *_reserved1;
324 void *_reserved0;
325};
326
327#endif /* NMSG_MSGMOD_PLUGIN_H */
nmsg_msgmod_field_type
Enum mapping protocol buffer schema types to nmsg-specific types for "transparent" modules.
Definition msgmod.h:72
Base nmsg support header.
nmsg_res
nmsg result code
Definition res.h:25
Generic ID to name map.
Definition nmsg.h:63
Parsed IP datagram.
Definition ipdg.h:31
Structure mapping protocol buffer schema fields to nmsg_msgmod_field_type values for "transparent" mo...
nmsg_msgmod_field_type type
Intended (nmsg) type of this protobuf field.
nmsg_msgmod_field_print_fp print
Optional custom field printer function.
unsigned flags
Flags for this field.
nmsg_msgmod_field_get_fp get
Optional custom field getter function.
const char * name
Name of the field.
Structure exported by message modules to implement a new message type.
struct nmsg_idname vendor
Vendor ID and name.
nmsg_msgmod_ipdg_to_payload_fp ipdg_to_payload
Module function to convert reassembled IP datagrams to NMSG payloads.
nmsg_msgmod_fini_fp fini
Module finalization function.
nmsg_msgmod_init_fp init
Module initialization function.
uint32_t protobuf_c_version_number
protobuf-c version number.
nmsg_msgmod_payload_to_pres_fp payload_to_pres
Module function to convert protobuf payloads to presentation form.
struct nmsg_idname msgtype
Message type and name.
const ProtobufCMessageDescriptor * pbdescr
Pointer to the ProtobufCMessageDescriptor for the protocol buffer schema.
nmsg_msgmod_pkt_to_payload_fp pkt_to_payload
Module function to convert raw IP packets to NMSG payloads.
nmsg_msgmod_pcap_init_fp pcap_init
Optional module function to perform further initialization of pcap inputs (e.g., setting up custom fi...
nmsg_msgmod_type type
Module type.
int msgver
Module interface version.
nmsg_msgmod_msg_load_fp msg_load
Per-message load function.
nmsg_msgmod_msg_fini_fp msg_fini
Per-message finalization function.
struct nmsg_msgmod_field * fields
Array mapping protobuf fields to nmsg types.
String buffer.
Definition strbuf.h:28