-
Notifications
You must be signed in to change notification settings - Fork 1
/
ubpf_manager.h
94 lines (71 loc) · 2.82 KB
/
ubpf_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Created by thomas on 26/10/18.
//
#ifndef FRR_THESIS_UBPF_MANAGER_H
#define FRR_THESIS_UBPF_MANAGER_H
#include <ubpf_vm/vm/inc/ubpf.h>
#include <include/ebpf_mod_struct.h>
#include "uthash.h"
#include "bpf_plugin.h"
#include "insertion_point.h"
#include "context_function.h"
//typedef struct context context_t;
struct api_functions {
struct api_functions *next;
struct api_functions *prev;
closure_t *closure;
};
typedef struct vm_container {
struct ubpf_vm *vm;
unsigned int num_ext_fun; // count the number of external API function already registered in this VM
context_t *ctx;
plugin_t *p;
uint8_t *mem;// this pointer points on the top of extra memory granted for plugins
size_t total_mem;
uint8_t jit;
uint8_t add_memcheck_inst;
ubpf_jit_fn fun;
struct insertion_point_entry *pop;
uint8_t use_libffi;
struct api_functions *api_closures;
UT_hash_handle hh; // hh hash-table all vms
UT_hash_handle hh_plugin; // for plugins
UT_hash_handle hh_insertion_point;
void ((*on_delete)(void *));
size_t vm_name_len;
char vm_name[0];
// a vm_container contains the execution context for
// one single eBPF function
} vm_container_t;
/**
* Allocate space for uBPF machine and update the pointer given at argument
* @param vmc, pointer to a vm_container_t structure
* @return 1 if uBPF machine is successfully created, 0 otherwise
*/
vm_container_t *new_vm(anchor_t anchor, int seq, insertion_point_t *point, uint8_t jit,
const char *name, size_t name_len, plugin_t *p,
const void *obj_data, size_t obj_len, proto_ext_fun_t *api_proto,
void (*on_delete)(void *), int add_memcheck_insts, int use_libffi);
/**
* Destroy an uBPF machine. Memory related to the structure is not freed.
* The caller must explicitly free the memory after using the wrapper
* @param vmc structure containing a valid running instance of VM
* @return void
*/
void shutdown_vm(vm_container_t *vmc);
/**
* This is the last step, this function will execute the loaded code
* by passing the memory located at the address contained in the mem
* argument.
* @param vmc a uBPF machine already started with loaded code inside it
* @param mem pointer to the memory zone used by the loaded code
* @param mem_len size of the memory pointed by mem
* @return the result of the execution of the loaded code
*/
int run_injected_code(vm_container_t *vmc, uint64_t *ret_val, exec_info_t *info);
void start_ubpf_plugin_listener(proto_ext_fun_t *fn);
int safe_ubpf_register(vm_container_t *vmc, const char *name, void *fn, int fn_permissions);
int check_perms(int fun_perms, int plugin_perms);
int add_closure(vm_container_t *vmc, closure_t *closure);
void remove_closures(vm_container_t *vmc);
#endif //FRR_THESIS_UBPF_MANAGER_H