Eunomia  0.1.0
A lightweight eBPF-based CloudNative Monitor tool for Container Security and Observability
tcp.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2  *
3  * Copyright (c) 2022, 郑昱笙,濮雯旭,张典典(牛校牛子队)
4  * All rights reserved.
5  */
6 
7 #ifndef TCP_CMD_H
8 #define TCP_CMD_H
9 
10 #include "libbpf_print.h"
11 #include "model/tracker.h"
12 #include "prometheus/counter.h"
13 #include "prometheus_server.h"
14 
15 extern "C"
16 {
17 #include <tcpconnect/tcp_tracker.h>
18 }
19 
20 union sender
21 {
22  struct in_addr x4;
23  struct in6_addr x6;
24 };
25 
28 
30 class tcp_tracker : public tracker_with_config<tcp_env, tcp_event>
31 {
32 public:
34 
36  static std::unique_ptr<tcp_tracker> create_tracker_with_default_env(tracker_event_handler handler);
37  static std::unique_ptr<tcp_tracker> create_tracker_with_args(
38  tracker_event_handler handler,
39  const std::vector<std::string> &args)
40  {
41  return create_tracker_with_default_env(handler);
42  }
43 
44  // start tcp tracker
45  void start_tracker();
46 
47  // used for prometheus exporter
48  struct prometheus_event_handler : public event_handler<tcp_event>
49  {
50  prometheus::Family<prometheus::Counter> &eunomia_tcp_v4_counter;
51  prometheus::Family<prometheus::Counter> &eunomia_tcp_v6_counter;
53 
56  };
57  static int fill_src_dst(sender &s, sender &d,const tcp_event &e);
58 
59  // convert event to json
60  struct json_event_handler_base : public event_handler<tcp_event>
61  {
62  std::string to_json(const struct tcp_event &e);
63  };
64 
65  // used for json exporter, inherits from json_event_handler
67  {
69  };
70 
71  struct plain_text_event_printer : public event_handler<tcp_event>
72  {
74  };
75 
76  struct csv_event_printer : public event_handler<tcp_event>
77  {
79  };
80 
81 private:
82  static void handle_tcp_sample_event(void *ctx, int cpu, void *data, unsigned int data_sz);
83 };
84 
85 #endif
tcp_tracker::json_event_printer::handle
void handle(tracker_event< tcp_event > &e)
implement this function to handle the event
Definition: tcp.cpp:81
tracker.h
tcp_tracker::prometheus_event_handler::report_prometheus_event
void report_prometheus_event(tracker_event< tcp_event > &e)
Definition: tcp.cpp:152
tcp_tracker::tcp_tracker
tcp_tracker(config_data config)
Definition: tcp.cpp:16
eunomia_mode::server
@ server
tcp_tracker::csv_event_printer
Definition: tcp.h:76
tcp_tracker::fill_src_dst
static int fill_src_dst(sender &s, sender &d, const tcp_event &e)
Definition: tcp.cpp:39
tcp_tracker::prometheus_event_handler::eunomia_tcp_v4_counter
prometheus::Family< prometheus::Counter > & eunomia_tcp_v4_counter
Definition: tcp.h:50
tcp_tracker::json_event_printer
Definition: tcp.h:66
tcp_tracker::prometheus_event_handler::prometheus_event_handler
prometheus_event_handler(prometheus_server &server)
Definition: tcp.cpp:189
event_handler
the event handler for single type
Definition: event_handler.h:52
tcp_tracker::start_tracker
void start_tracker()
start the tracker thread
Definition: tcp.cpp:33
tcp_tracker::prometheus_event_handler::handle
void handle(tracker_event< tcp_event > &e)
implement this function to handle the event
Definition: tcp.cpp:201
tcp_tracker
trace tcp start and exit
Definition: tcp.h:30
tcp_tracker::plain_text_event_printer::handle
void handle(tracker_event< tcp_event > &e)
implement this function to handle the event
Definition: tcp.cpp:86
tracker_with_config< tcp_env, tcp_event >::config_data
tracker_config< tcp_env, tcp_event > config_data
type alias for env and config
Definition: tracker.h:65
tcp_tracker::csv_event_printer::handle
void handle(tracker_event< tcp_event > &e)
implement this function to handle the event
Definition: tcp.cpp:125
tracker_with_config
tracker template with env and data
Definition: tracker.h:59
tcp_tracker::json_event_handler_base
Definition: tcp.h:60
tcp_tracker::prometheus_event_handler
Definition: tcp.h:48
tcp_tracker::prometheus_event_handler::eunomia_tcp_v6_counter
prometheus::Family< prometheus::Counter > & eunomia_tcp_v6_counter
Definition: tcp.h:51
tcp_tracker::create_tracker_with_args
static std::unique_ptr< tcp_tracker > create_tracker_with_args(tracker_event_handler handler, const std::vector< std::string > &args)
Definition: tcp.h:37
tcp_tracker::plain_text_event_printer
Definition: tcp.h:71
prometheus_server.h
sender::x6
struct in6_addr x6
Definition: tcp.h:23
tracker_event
the basic event type
Definition: event_handler.h:31
tcp_tracker::json_event_handler_base::to_json
std::string to_json(const struct tcp_event &e)
Definition: tcp.cpp:59
tcp_tracker::create_tracker_with_default_env
static std::unique_ptr< tcp_tracker > create_tracker_with_default_env(tracker_event_handler handler)
create a tracker with deafult config
Definition: tcp.cpp:22
libbpf_print.h
sender
Definition: tcp.h:20
sender::x4
struct in_addr x4
Definition: tcp.h:22
prometheus_server
Definition: prometheus_server.h:22
tracker_with_config< tcp_env, tcp_event >::tracker_event_handler
std::shared_ptr< event_handler< tcp_event > > tracker_event_handler
type alias for event handler
Definition: tracker.h:67
config
seccomp_config config
Definition: seccomp_test.cpp:13