mirror of
https://github.com/h3xduck/TripleCross.git
synced 2026-01-08 17:13:09 +08:00
Completed detachment of probes, enabling to attach and detach at will. Work needs to be done with xdp tho
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -22,6 +22,4 @@ typedef struct module_config_t{
|
|||||||
|
|
||||||
extern module_config_t module_config;
|
extern module_config_t module_config;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <bpf/libbpf.h>
|
#include <bpf/libbpf.h>
|
||||||
#include "xdp_filter.skel.h"
|
#include "xdp_filter.skel.h"
|
||||||
|
|
||||||
|
//Connections
|
||||||
int attach_handle_sched_process_exec(struct xdp_filter_bpf *skel){
|
int attach_handle_sched_process_exec(struct xdp_filter_bpf *skel){
|
||||||
skel->links.handle_sched_process_exec = bpf_program__attach(skel->progs.handle_sched_process_exec);
|
skel->links.handle_sched_process_exec = bpf_program__attach(skel->progs.handle_sched_process_exec);
|
||||||
return libbpf_get_error(skel->links.handle_sched_process_exec);
|
return libbpf_get_error(skel->links.handle_sched_process_exec);
|
||||||
@@ -15,4 +16,17 @@ int attach_sched_all(struct xdp_filter_bpf *skel){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Disconnections
|
||||||
|
int detach_link_generic(struct bpf_link *link){
|
||||||
|
int ret = bpf_link__destroy(link);
|
||||||
|
if(ret!=0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int detach_sched_all(struct xdp_filter_bpf *skel){
|
||||||
|
return detach_link_generic(skel->links.handle_sched_process_exec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -46,9 +46,10 @@ int attach_xdp_all(struct xdp_filter_bpf *skel, __u32 ifindex, __u32 flags){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int detach_xdp_all(__u32 fd, __u32 ifindex, __u32 flags){
|
int detach_xdp_all(__u32 ifindex, __u32 fd, __u32 flags){
|
||||||
int err = bpf_set_link_xdp_fd(ifindex, fd, flags);
|
int err = bpf_set_link_xdp_fd(ifindex, fd, flags);
|
||||||
if(err<0){
|
if(err<0){
|
||||||
|
perror("j");
|
||||||
fprintf(stderr, "Failed to detach XDP program\n");
|
fprintf(stderr, "Failed to detach XDP program\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,8 +223,46 @@ int main(int argc, char**argv){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Received signal to stop, detach program from network interface
|
//Received signal to stop, detach program from network interface
|
||||||
detach_xdp_all(-1, ifindex, flags);
|
err = detach_sched_all(skel);
|
||||||
|
if(err<0){
|
||||||
|
perror("ERR");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
printf("A:%i", err);fflush(stdout);
|
||||||
|
detach_xdp_all(ifindex, -1, flags);
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
|
err = attach_sched_all(skel);
|
||||||
|
if(err<0){
|
||||||
|
perror("ERR");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
printf("B:%i", err);fflush(stdout);
|
||||||
|
|
||||||
|
exiting = false;
|
||||||
|
while (!exiting) {
|
||||||
|
err = ring_buffer__poll(rb, 100 /* timeout, ms */);
|
||||||
|
|
||||||
|
//Checking if a signal occured
|
||||||
|
if (err == -EINTR) {
|
||||||
|
err = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (err < 0) {
|
||||||
|
printf("Error polling ring buffer: %d\n", err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = detach_sched_all(skel);
|
||||||
|
if(err<0){
|
||||||
|
perror("ERR");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
printf("C:%i", err);fflush(stdout);
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
ring_buffer__free(rb);
|
ring_buffer__free(rb);
|
||||||
|
|||||||
Reference in New Issue
Block a user