Coverage Report

Created: 2026-05-14 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ntopng/include/ParsedFlow.h
Line
Count
Source
1
/*
2
 *
3
 * (C) 2013-26 - ntop.org
4
 *
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 *
20
 */
21
22
#ifndef _PARSED_FLOW_H_
23
#define _PARSED_FLOW_H_
24
25
#include "ntop_includes.h"
26
27
class ParsedFlow : public ParsedFlowCore, public ParsedeBPF {
28
 private:
29
  bool has_parsed_ebpf, is_swapped;
30
  json_object* additional_fields_json;
31
  ndpi_serializer* additional_fields_tlv;
32
  char* l7_info;
33
  char *http_url, *http_site, *http_user_agent, *dhcp_client_name, *sip_call_id;
34
  ndpi_http_method http_method;
35
  char* dns_query;
36
  char* end_reason;
37
  char *tls_server_name, *bittorrent_hash, *tcp_fingerprint;
38
  char* ja4c_hash;
39
  char* flow_risk_info;
40
  char* ot_info;
41
  char* external_alert;
42
  char* l7_json;
43
  IpAddress next_hop;
44
  char *smtp_rcp_to, *smtp_mail_from;
45
  u_int32_t src_ip_addr_pre_nat, dst_ip_addr_pre_nat, src_ip_addr_post_nat,
46
      dst_ip_addr_post_nat;
47
  u_int32_t tcp_stats_src_to_dst, tcp_stats_dst_to_src;
48
  u_int8_t tls_unsafe_cipher, flow_verdict;
49
  ndpi_os os_hint;
50
  u_int16_t tls_cipher;
51
  u_int16_t http_ret_code;
52
  u_int16_t dns_query_type, dns_ret_code, dns_query_id;
53
  u_int32_t l7_error_code;
54
  u_int16_t src_port_pre_nat, dst_port_pre_nat, src_port_post_nat,
55
      dst_port_post_nat;
56
  custom_app_t custom_app;
57
  ndpi_confidence_t confidence;
58
  ndpi_risk ndpi_flow_risk_bitmap;
59
  char* ndpi_flow_risk_name;
60
  FlowSource flow_source;
61
  char* wlan_ssid;
62
  struct {
63
    char *src, *dst;
64
  } bgp;
65
  u_int8_t wtp_mac_address[6];
66
  struct {
67
    u_int8_t src_to_dst, dst_to_src;
68
  } qoe;
69
  char *hr_src_to_dst_bytes, *hr_dst_to_src_bytes;
70
71
 public:
72
  ParsedFlow();
73
74
  ParsedFlow(const ParsedFlow& pf);
75
76
  void addAdditionalField(const char* key, json_object* field);
77
  void addAdditionalField(ndpi_deserializer* deserializer);
78
79
0
  inline json_object* getAdditionalFieldsJSON() {
80
0
    return additional_fields_json;
81
0
  };
82
0
  inline ndpi_serializer* getAdditionalFieldsTLV() {
83
0
    ndpi_serializer* tlv = additional_fields_tlv;
84
0
    additional_fields_tlv = NULL;
85
0
    return tlv;
86
0
  };
87
0
  inline bool hasParsedeBPF() const { return has_parsed_ebpf; };
88
0
  inline void setParsedeBPF() { has_parsed_ebpf = true; };
89
0
  inline void setParsedProcessInfo() {
90
0
    process_info_set = true;
91
0
    setParsedeBPF();
92
0
  }
93
0
  inline void setParsedContainerInfo() {
94
0
    container_info_set = true;
95
0
    setParsedeBPF();
96
0
  }
97
98
  virtual ~ParsedFlow();
99
100
  void freeMemory();
101
  void swap();
102
  void fromLua(lua_State* L, int index);
103
104
0
  inline void setL7Info(const char* str) {
105
0
    if (l7_info != NULL) free(l7_info);
106
0
    if (str) {
107
0
      l7_info = strdup(str);
108
0
    } else
109
0
      l7_info = NULL;
110
0
  }
111
0
  inline void setHTTPurl(const char* str) {
112
0
    if (http_url != NULL) free(http_url);
113
0
    if (str) {
114
0
      http_url = strdup(str);
115
0
    } else
116
0
      http_url = NULL;
117
0
  }
118
0
  inline void setHTTPsite(const char* str) {
119
0
    if (http_site != NULL) free(http_site);
120
0
    if (str) {
121
0
      http_site = strdup(str);
122
0
    } else
123
0
      http_site = NULL;
124
0
  }
125
0
  inline void setHTTPuserAgent(const char* str) {
126
0
    if (http_user_agent != NULL) free(http_user_agent);
127
0
    if (str) {
128
0
      http_user_agent = strdup(str);
129
0
    } else
130
0
      http_user_agent = NULL;
131
0
  }
132
0
  inline void setHTTPMethod(ndpi_http_method m) { http_method = m; }
133
0
  inline void setDNSQuery(const char* str) {
134
0
    if (dns_query != NULL) free(dns_query);
135
0
    if (str) {
136
0
      dns_query = strdup(str);
137
0
    } else
138
0
      dns_query = NULL;
139
0
  }
140
0
  inline void setTLSserverName(const char* str) {
141
0
    if (tls_server_name != NULL) free(tls_server_name);
142
0
    if (str) {
143
0
      tls_server_name = strdup(str);
144
0
    } else
145
0
      tls_server_name = NULL;
146
0
  }
147
0
  inline void setBittorrentHash(const char* str) {
148
0
    if (bittorrent_hash != NULL) free(bittorrent_hash);
149
0
    if (str) {
150
0
      bittorrent_hash = strdup(str);
151
0
    } else
152
0
      bittorrent_hash = NULL;
153
0
  }
154
0
  inline void setTCPFingerprint(const char* str) {
155
0
    if (tcp_fingerprint != NULL) free(tcp_fingerprint);
156
0
    if (str) {
157
0
      tcp_fingerprint = strdup(str);
158
0
    } else
159
0
      tcp_fingerprint = NULL;
160
0
  }
161
0
  inline void setJA4cHash(const char* str) {
162
0
    if (ja4c_hash != NULL) free(ja4c_hash);
163
0
    if (str) {
164
0
      ja4c_hash = strdup(str);
165
0
    } else
166
0
      ja4c_hash = NULL;
167
0
  }
168
0
  inline void setRiskInfo(const char* str) {
169
0
    if (flow_risk_info != NULL) free(flow_risk_info);
170
0
    if (str) {
171
0
      flow_risk_info = strdup(str);
172
0
    } else
173
0
      flow_risk_info = NULL;
174
0
  }
175
0
  inline void setOTInfo(const char* str) {
176
0
    if (ot_info != NULL) free(ot_info);
177
0
    if (str) {
178
0
      ot_info = strdup(str);
179
0
    } else
180
0
      ot_info = NULL;
181
0
  }
182
0
  inline void setExternalAlert(const char* str) {
183
0
    if (external_alert != NULL) free(external_alert);
184
0
    if (str) {
185
0
      external_alert = strdup(str);
186
0
    } else
187
0
      external_alert = NULL;
188
0
  }
189
0
  inline void setL7JSON(const char* str) {
190
0
    if (l7_json != NULL) free(l7_json);
191
0
    if (str) {
192
0
      l7_json = strdup(str);
193
0
    } else
194
0
      l7_json = NULL;
195
0
  }
196
0
  inline void setTLSUnsafeCipher(u_int8_t v) { tls_unsafe_cipher = v; }
197
0
  inline void setTLSCipher(u_int16_t v) { tls_cipher = v; }
198
0
  inline void setFlowVerdict(u_int8_t v) { flow_verdict = v; }
199
0
  inline void setHTTPRetCode(u_int16_t v) { http_ret_code = v; }
200
0
  inline void setDNSQueryType(u_int16_t v) { dns_query_type = v; }
201
0
  inline void setDNSRetCode(u_int16_t v) { dns_ret_code = v; }
202
0
  inline void setDNSQueryId(u_int16_t v) { dns_query_id = v; }
203
0
  inline void setL7ErrorCode(u_int32_t v) { l7_error_code = v; }
204
0
  inline void setCustomApp(custom_app_t c) { custom_app = c; }
205
0
  inline void setConfidence(ndpi_confidence_t c) { confidence = c; }
206
0
  inline void setRisk(ndpi_risk r) { ndpi_flow_risk_bitmap = r; }
207
0
  inline void setFlowSource(FlowSource n) { flow_source = n; }
208
0
  inline void setEndReason(const char* str) {
209
0
    if (end_reason != NULL) free(end_reason);
210
0
    if (str) {
211
0
      end_reason = strdup(str);
212
0
    } else
213
0
      end_reason = NULL;
214
0
  }
215
0
  inline void setSMTPRcptTo(const char* str) {
216
0
    if (smtp_rcp_to != NULL) free(smtp_rcp_to);
217
0
    if (str) {
218
0
      smtp_rcp_to = strdup(str);
219
0
    } else
220
0
      smtp_rcp_to = NULL;
221
0
  }
222
0
  inline void setSMTPMailFrom(const char* str) {
223
0
    if (smtp_mail_from != NULL) free(smtp_mail_from);
224
0
    if (str) {
225
0
      smtp_mail_from = strdup(str);
226
0
    } else
227
0
      smtp_mail_from = NULL;
228
0
  }
229
0
  inline void setRiskName(const char* str) {
230
0
    if (ndpi_flow_risk_name != NULL) free(ndpi_flow_risk_name);
231
0
    if (str) {
232
0
      ndpi_flow_risk_name = strdup(str);
233
0
    } else
234
0
      ndpi_flow_risk_name = NULL;
235
0
  }
236
0
  inline void setDHCPClientName(const char* str) {
237
0
    if (dhcp_client_name != NULL) free(dhcp_client_name);
238
0
    if (str) {
239
0
      dhcp_client_name = strdup(str);
240
0
    } else
241
0
      dhcp_client_name = NULL;
242
0
  }
243
0
  inline void setSIPCallId(const char* str) {
244
0
    if (sip_call_id != NULL) free(sip_call_id);
245
0
    if (str) {
246
0
      sip_call_id = strdup(str);
247
0
    } else
248
0
      sip_call_id = NULL;
249
0
  }
250
0
  inline void setPreNATSrcIp(u_int32_t v) { src_ip_addr_pre_nat = v; };
251
0
  inline void setPreNATDstIp(u_int32_t v) { dst_ip_addr_pre_nat = v; };
252
0
  inline void setPostNATSrcIp(u_int32_t v) { src_ip_addr_post_nat = v; };
253
0
  inline void setPostNATDstIp(u_int32_t v) { dst_ip_addr_post_nat = v; };
254
0
  inline void setPreNATSrcPort(u_int16_t v) { src_port_pre_nat = v; };
255
0
  inline void setPreNATDstPort(u_int16_t v) { dst_port_pre_nat = v; };
256
0
  inline void setPostNATSrcPort(u_int16_t v) { src_port_post_nat = v; };
257
0
  inline void setPostNATDstPort(u_int16_t v) { dst_port_post_nat = v; };
258
0
  inline void setNextHop(IpAddress* v) { next_hop.set(v); }
259
0
  inline void setWLANSSID(const char* str) {
260
0
    if (wlan_ssid != NULL) free(wlan_ssid);
261
0
    if (str) wlan_ssid = strdup(str); else wlan_ssid = NULL;
262
0
  }
263
0
  inline void setClientBGPInfo(const char* str) {
264
0
    if (bgp.src != NULL) free(bgp.src);
265
0
    if (str) bgp.src = strdup(str); else bgp.src = NULL;
266
0
  }
267
0
  inline void setServerBGPInfo(const char* str) {
268
0
    if (bgp.dst != NULL) free(bgp.dst);
269
0
    if (str) bgp.dst = strdup(str); else bgp.dst = NULL;
270
0
  }
271
0
  inline void setWTPMACAddress(const char* str) {
272
0
    Utils::parseMac(wtp_mac_address, str);
273
0
  }
274
275
  /* ****** */
276
0
  inline char* getL7Info(bool setToNULL = false) {
277
0
    char* r = l7_info;
278
0
    if (setToNULL) l7_info = NULL;
279
0
    return (r);
280
0
  }
281
0
  inline char* getHTTPurl(bool setToNULL = false) {
282
0
    char* r = http_url;
283
0
    if (setToNULL) http_url = NULL;
284
0
    return (r);
285
0
  }
286
0
  inline char* getHTTPsite(bool setToNULL = false) {
287
0
    char* r = http_site;
288
0
    if (setToNULL) http_site = NULL;
289
0
    return (r);
290
0
  }
291
0
  inline char* getHTTPuserAgent(bool setToNULL = false) {
292
0
    char* r = http_user_agent;
293
0
    if (setToNULL) http_user_agent = NULL;
294
0
    return (r);
295
0
  }
296
0
  inline ndpi_http_method getHTTPMethod() { return (http_method); }
297
0
  inline char* getDNSQuery(bool setToNULL = false) {
298
0
    char* r = dns_query;
299
0
    if (setToNULL) dns_query = NULL;
300
0
    return (r);
301
0
  }
302
0
  inline char* getTLSserverName(bool setToNULL = false) {
303
0
    char* r = tls_server_name;
304
0
    if (setToNULL) tls_server_name = NULL;
305
0
    return (r);
306
0
  }
307
0
  inline char* getBittorrentHash(bool setToNULL = false) {
308
0
    char* r = bittorrent_hash;
309
0
    if (setToNULL) bittorrent_hash = NULL;
310
0
    return (r);
311
0
  }
312
0
  inline char* getTCPFingerprint(bool setToNULL = false) {
313
0
    char* r = tcp_fingerprint;
314
0
    if (setToNULL) tcp_fingerprint = NULL;
315
0
    return (r);
316
0
  }
317
0
  inline char* getJA4cHash(bool setToNULL = false) {
318
0
    char* r = ja4c_hash;
319
0
    if (setToNULL) ja4c_hash = NULL;
320
0
    return (r);
321
0
  }
322
0
  inline char* getRiskInfo(bool setToNULL = false) {
323
0
    char* r = flow_risk_info;
324
0
    if (setToNULL) flow_risk_info = NULL;
325
0
    return (r);
326
0
  }
327
0
  inline char* getOTInfo(bool setToNULL = false) {
328
0
    char* r = ot_info;
329
0
    if (setToNULL) ot_info = NULL;
330
0
    return (r);
331
0
  }
332
0
  inline char* getExternalAlert(bool setToNULL = false) {
333
0
    char* r = external_alert;
334
0
    if (setToNULL) external_alert = NULL;
335
0
    return (r);
336
0
  }
337
0
  inline char* getL7JSON(bool setToNULL = false) {
338
0
    char* r = l7_json;
339
0
    if (setToNULL) l7_json = NULL;
340
0
    return (r);
341
0
  }
342
0
  inline char* getEndReason(bool setToNull = false) {
343
0
    char* r = end_reason;
344
0
    if (setToNull) end_reason = NULL;
345
0
    return (r);
346
0
  }
347
0
  inline char* getSMTPRcptTo(bool setToNull = false) {
348
0
    char* r = smtp_rcp_to;
349
0
    if (setToNull) smtp_rcp_to = NULL;
350
0
    return (r);
351
0
  }
352
0
  inline char* getSMTPMailFrom(bool setToNull = false) {
353
0
    char* r = smtp_mail_from;
354
0
    if (setToNull) smtp_mail_from = NULL;
355
0
    return (r);
356
0
  }
357
0
  inline char* getDHCPClientName(bool setToNull = false) {
358
0
    char* r = dhcp_client_name;
359
0
    if (setToNull) dhcp_client_name = NULL;
360
0
    return (r);
361
0
  }
362
0
  inline char* getSIPCallId(bool setToNull = false) {
363
0
    char* r = sip_call_id;
364
0
    if (setToNull) sip_call_id = NULL;
365
0
    return (r);
366
0
  }
367
0
  inline IpAddress* getNextHop() { return (&next_hop); }
368
0
  inline char* getWLANSSID(bool setToNull = false) {
369
0
    char* r = wlan_ssid;
370
0
    if (setToNull) wlan_ssid = NULL;
371
0
    return (r);
372
0
  }
373
0
  inline char* getClientBGPInfo() { return(bgp.src ? bgp.src : (char*)""); }
374
0
  inline char* getServerBGPInfo() { return(bgp.dst ? bgp.dst : (char*)""); }
375
  
376
0
  inline u_int8_t* getWTPMACAddress() { return wtp_mac_address; }
377
378
0
  inline u_int32_t getPreNATSrcIp() { return src_ip_addr_pre_nat; };
379
0
  inline u_int32_t getPreNATDstIp() { return dst_ip_addr_pre_nat; };
380
0
  inline u_int32_t getPostNATSrcIp() { return src_ip_addr_post_nat; };
381
0
  inline u_int32_t getPostNATDstIp() { return dst_ip_addr_post_nat; };
382
0
  inline u_int16_t getPreNATSrcPort() { return src_port_pre_nat; };
383
0
  inline u_int16_t getPreNATDstPort() { return dst_port_pre_nat; };
384
0
  inline u_int16_t getPostNATSrcPort() { return src_port_post_nat; };
385
0
  inline u_int16_t getPostNATDstPort() { return dst_port_post_nat; };
386
0
  inline u_int8_t getTLSUnsafeCipher() { return (tls_unsafe_cipher); }
387
0
  inline u_int16_t getTLSCipher() { return (tls_cipher); }
388
0
  inline u_int8_t getFlowVerdict() { return (flow_verdict); }
389
0
  inline u_int16_t getHTTPRetCode() { return (http_ret_code); }
390
0
  inline u_int16_t getDNSQueryType() { return (dns_query_type); }
391
0
  inline u_int16_t getDNSRetCode() { return (dns_ret_code); }
392
0
  inline u_int16_t getDNSQueryId() { return (dns_query_id); }
393
0
  inline u_int32_t getL7ErrorCode() { return (l7_error_code); }
394
0
  inline custom_app_t getCustomApp() { return (custom_app); }
395
0
  inline ndpi_confidence_t getConfidence() { return (confidence); }
396
0
  inline ndpi_risk getRisk() { return (ndpi_flow_risk_bitmap); }
397
0
  inline char* getRiskName() { return (ndpi_flow_risk_name); }
398
0
  inline bool isSwapped() { return (is_swapped); }
399
0
  inline FlowSource getFlowSource() { return (flow_source); }
400
0
  inline u_int8_t getQoESrc2Dst() { return (qoe.src_to_dst); }
401
0
  inline u_int8_t getQoEDst2Src() { return (qoe.dst_to_src); }
402
0
  inline void setQoESrc2Dst(u_int8_t t) { qoe.src_to_dst = t; }
403
0
  inline void setQoEDst2Src(u_int8_t t) { qoe.dst_to_src = t; }
404
0
  inline void setOSHint(ndpi_os t) { os_hint = t; }
405
0
  inline void setHRSrcToDstBytes(const char* str) {
406
0
    if (hr_src_to_dst_bytes != NULL) free(hr_src_to_dst_bytes);
407
0
    hr_src_to_dst_bytes = str ? strdup(str) : NULL;
408
0
  }
409
0
  inline void setHRDstToSrcBytes(const char* str) {
410
0
    if (hr_dst_to_src_bytes != NULL) free(hr_dst_to_src_bytes);
411
0
    hr_dst_to_src_bytes = str ? strdup(str) : NULL;
412
0
  }
413
0
  inline char* getHRSrcToDstBytes(bool setToNull = false) {
414
0
    char* r = hr_src_to_dst_bytes;
415
0
    if (setToNull) hr_src_to_dst_bytes = NULL;
416
0
    return r;
417
0
  }
418
0
  inline char* getHRDstToSrcBytes(bool setToNull = false) {
419
0
    char* r = hr_dst_to_src_bytes;
420
0
    if (setToNull) hr_dst_to_src_bytes = NULL;
421
0
    return r;
422
0
  }
423
0
  inline ndpi_os getOSHint() { return (os_hint); }
424
0
  inline void setTCPStats(u_int32_t value, bool cli2src) {
425
0
    if (cli2src)
426
0
      tcp_stats_src_to_dst = value;
427
0
    else
428
0
      tcp_stats_dst_to_src = value;
429
0
  }
430
  u_int32_t get_private_flow_id();
431
0
  inline u_int32_t get_tcp_stats(bool cli2srv) {
432
0
    return (cli2srv ? tcp_stats_src_to_dst : tcp_stats_dst_to_src);
433
0
  }
434
  void print();
435
};
436
437
#endif /* _PARSED_FLOW_H_ */