Eunomia  0.1.0
A lightweight eBPF-based CloudNative Monitor tool for Container Security and Observability
hot_update.h
Go to the documentation of this file.
1 #ifndef HOT_UPDATE_H
2 #define HOT_UPDATE_H
3 
4 #include <fstream>
5 #include <iostream>
6 #include <string>
7 
8 #include "../json.hpp"
9 #include "../base64.h"
10 
12 
14 {
16  std::string name;
17  std::vector<std::string> maps_name;
18  std::vector<std::string> progs_name;
19  int data_sz;
20  std::string data;
22  std::vector<char> base64_decode_buffer;
23 
24  std::string to_json()
25  {
26  json j;
27  j["name"] = name;
28  j["maps"] = maps_name;
29  j["progs"] = progs_name;
30  j["data_sz"] = data_sz;
31  j["data"] = data;
32  return j.dump();
33  }
34  void from_json_str(const std::string& j_str)
35  {
36  json jj = json::parse(j_str);
37  name = jj["name"];
38  maps_name = jj["maps"];
39  progs_name = jj["progs"];
40  data_sz = jj["data_sz"];
41  data = jj["data"];
42  }
43 };
44 
45 static std::string bpf_skeleton_encode(const struct bpf_object_skeleton *skeleton) {
47 
48  data.name ==skeleton->name;
49  data.data_sz = skeleton->data_sz;
50  data.data = base64_encode((const unsigned char *)skeleton->data, data.data_sz);
51  for (int i = 0; i < skeleton->map_cnt; i++)
52  {
53  data.maps_name.push_back(skeleton->maps[i].name);
54  }
55  for (int i = 0; i < skeleton->prog_cnt; i++)
56  {
57  data.progs_name.push_back(skeleton->progs[i].name);
58  }
59  return data.to_json();
60 }
61 
62 #endif
ebpf_update_meta_data::name
std::string name
meta data
Definition: hot_update.h:16
ebpf_update_meta_data::progs_name
std::vector< std::string > progs_name
Definition: hot_update.h:18
ebpf_update_meta_data::data
std::string data
Definition: hot_update.h:20
ebpf_update_meta_data::from_json_str
void from_json_str(const std::string &j_str)
Definition: hot_update.h:34
ebpf_update_meta_data::base64_decode_buffer
std::vector< char > base64_decode_buffer
buffer to base 64 decode
Definition: hot_update.h:22
json
nlohmann::json json
Definition: hot_update.h:11
ebpf_update_meta_data::data_sz
int data_sz
Definition: hot_update.h:19
ebpf_update_meta_data::maps_name
std::vector< std::string > maps_name
Definition: hot_update.h:17
ebpf_update_meta_data
Definition: hot_update.h:13
ebpf_update_meta_data::to_json
std::string to_json()
Definition: hot_update.h:24