nmsg  0.9.0
msgmod_plugin.h
1 /*
2  * Copyright (c) 2008, 2009, 2013 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 
25 struct nmsg_msgmod_field;
26 
28 #define NMSG_MSGMOD_VERSION 9
29 
31 typedef nmsg_res (*nmsg_msgmod_init_fp)(void **clos);
32 
34 typedef nmsg_res (*nmsg_msgmod_fini_fp)(void **clos);
35 
37 typedef nmsg_res (*nmsg_msgmod_payload_to_pres_fp)(Nmsg__NmsgPayload *np,
38  char **pres,
39  const char *endline);
40 
42 typedef nmsg_res (*nmsg_msgmod_ipdg_to_payload_fp)(void *clos,
43  const struct nmsg_ipdg *dg,
44  uint8_t **pbuf, size_t *sz);
45 
46 typedef nmsg_res (*nmsg_msgmod_pkt_to_payload_fp)(void *clos,
47  nmsg_pcap_t pcap,
48  nmsg_message_t *m);
49 
50 typedef nmsg_res (*nmsg_msgmod_pcap_init_fp)(void *clos, nmsg_pcap_t pcap);
51 
53 typedef nmsg_res (*nmsg_msgmod_msg_load_fp)(nmsg_message_t m, void **msg_clos);
54 
56 typedef nmsg_res (*nmsg_msgmod_msg_fini_fp)(nmsg_message_t m, void *msg_clos);
57 
59 typedef 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 
66 typedef 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 
74 #define NMSG_MSGMOD_FIELD_PRINTER(funcname) \
75  nmsg_res funcname(nmsg_message_t m, \
76  struct nmsg_msgmod_field *field, \
77  void *ptr, \
78  struct nmsg_strbuf *sb, \
79  const char *endline)
80 
82 #define NMSG_MSGMOD_FIELD_GETTER(funcname) \
83  nmsg_res funcname(nmsg_message_t m, \
84  struct nmsg_msgmod_field *field, \
85  unsigned val_idx, \
86  void **data, \
87  size_t *len, \
88  void *msg_clos)
89 
91 #define NMSG_MSGMOD_REQUIRED_INIT \
92  .msgver = NMSG_MSGMOD_VERSION, \
93  .protobuf_c_version_number = PROTOBUF_C_VERSION_NUMBER
94 
106 
108  const char *name;
109 
111  unsigned flags;
112 
114  nmsg_msgmod_field_print_fp print;
115 
117  nmsg_msgmod_field_get_fp get;
118 
120  const ProtobufCFieldDescriptor *descr;
121 
123  void *_reserved3;
124  void *_reserved2;
125  void *_reserved1;
126  void *_reserved0;
127 };
128 
130 #define NMSG_MSGMOD_FIELD_END { 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
131 
145 typedef enum {
146  nmsg_msgmod_type_transparent,
147  nmsg_msgmod_type_opaque
148 } nmsg_msgmod_type;
149 
168  int msgver;
169 
173  nmsg_msgmod_type type;
174 
180 
186 
190  nmsg_msgmod_init_fp init;
191 
195  nmsg_msgmod_fini_fp fini;
196 
202  nmsg_msgmod_msg_load_fp msg_load;
203 
207  nmsg_msgmod_msg_fini_fp msg_fini;
208 
217  nmsg_msgmod_payload_to_pres_fp payload_to_pres;
218 
225  nmsg_msgmod_ipdg_to_payload_fp ipdg_to_payload;
226 
234  const ProtobufCMessageDescriptor *pbdescr;
235 
242 
249  nmsg_msgmod_pkt_to_payload_fp pkt_to_payload;
250 
260 
265  nmsg_msgmod_pcap_init_fp pcap_init;
266 
270  void *_reserved9;
271  void *_reserved8;
272  void *_reserved7;
273  void *_reserved6;
274  void *_reserved5;
275  void *_reserved4;
276  void *_reserved3;
277  void *_reserved2;
278  void *_reserved1;
279  void *_reserved0;
280 };
281 
282 #endif /* NMSG_MSGMOD_PLUGIN_H */
Structure exported by message modules to implement a new message type.
unsigned flags
Flags for this field.
nmsg_res
nmsg result code
Definition: res.h:25
nmsg_msgmod_msg_fini_fp msg_fini
Per-message finalization function.
nmsg_msgmod_type type
Module type.
Base nmsg support header.
uint32_t protobuf_c_version_number
protobuf-c version number.
struct nmsg_idname msgtype
Message type and name.
Parsed IP datagram.
Definition: ipdg.h:34
nmsg_msgmod_pkt_to_payload_fp pkt_to_payload
Module function to convert raw IP packets to NMSG payloads.
nmsg_msgmod_field_type
Enum mapping protocol buffer schema types to nmsg-specific types for "transparent" modules...
Definition: msgmod.h:73
Structure mapping protocol buffer schema fields to nmsg_msgmod_field_type values for "transparent" mo...
struct nmsg_idname vendor
Vendor ID and name.
nmsg_msgmod_init_fp init
Module initialization function.
nmsg_msgmod_msg_load_fp msg_load
Per-message load function.
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_field_type type
Intended (nmsg) type of this protobuf field.
nmsg_msgmod_field_print_fp print
Optional custom field printer function.
nmsg_msgmod_payload_to_pres_fp payload_to_pres
Module function to convert protobuf payloads to presentation form.
const char * name
Name of the field.
int msgver
Module interface version.
nmsg_msgmod_ipdg_to_payload_fp ipdg_to_payload
Module function to convert reassembled IP datagrams to NMSG payloads.
const ProtobufCMessageDescriptor * pbdescr
Pointer to the ProtobufCMessageDescriptor for the protocol buffer schema.
String buffer.
Definition: strbuf.h:32
nmsg_msgmod_fini_fp fini
Module finalization function.
Generic ID to name map.
Definition: nmsg.h:54
struct nmsg_msgmod_field * fields
Array mapping protobuf fields to nmsg types.