From f4a4211c0ab6ec5a7e7bb533e0dda64be6230bc4 Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Thu, 28 May 2020 15:05:26 +0000 Subject: [PATCH] Network Viewer program (bandwidth) (#151) Brings bandwidth monitoring with eBPF. --- includes/bpf_load.h | 6 +- kernel/Makefile | 3 +- kernel/netdata_ebpf.h | 25 +- kernel/network_viewer_kern.c | 532 +++++++++++++++++++++++++++++++++++ library/api.c | 4 +- library/bpf_load.c | 16 +- user/Makefile | 9 +- 7 files changed, 577 insertions(+), 18 deletions(-) create mode 100644 kernel/network_viewer_kern.c diff --git a/includes/bpf_load.h b/includes/bpf_load.h index 4eb0fa9a..4c7bddf1 100644 --- a/includes/bpf_load.h +++ b/includes/bpf_load.h @@ -33,8 +33,8 @@ extern int prog_cnt; /* There is a one-to-one mapping between map_fd[] and map_data[]. * The map_data[] just contains more rich info on the given map. - */ extern int map_fd[MAX_MAPS]; + */ extern struct bpf_map_data map_data[MAX_MAPS]; extern int map_data_count; @@ -50,8 +50,8 @@ extern int map_data_count; * * returns zero on success */ -int load_bpf_file(char *path, int pid); -int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map); +int load_bpf_file(int *map_fd,char *path, int pid); +int load_bpf_file_fixup_map(int *map_fd,const char *path, fixup_map_cb fixup_map); void read_trace_pipe(void); int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); diff --git a/kernel/Makefile b/kernel/Makefile index 155ab5ca..c08826f1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -34,8 +34,9 @@ CURRENT_KERNEL=$(shell echo $(VER_MAJOR)\*65536 + $(VER_MINOR)\*256 + $(VER_PATC latency_process_kern.o: latency_process_kern.c process_kern.o: process_kern.c +network_viewer_kern.o: network_viewer_kern.c -all: process_kern.o latency_process_kern.o +all: process_kern.o latency_process_kern.o network_viewer_kern.o %.o: %.c if [ -w /usr/src/linux/include/generated/autoconf.h ]; then if [ "$(CURRENT_KERNEL)" -ge 328448 ]; then sed -i -e 's/\(#define CONFIG_CC_HAS_ASM_INLINE 1\)/\/\/\1/' /usr/src/linux/include/generated/autoconf.h; fi ; fi diff --git a/kernel/netdata_ebpf.h b/kernel/netdata_ebpf.h index 7efb6c38..545c3d19 100644 --- a/kernel/netdata_ebpf.h +++ b/kernel/netdata_ebpf.h @@ -10,7 +10,6 @@ struct netdata_error_report_t { int err; }; -# define NETDATA_GLOBAL_COUNTER 24 //fork() creates process // @@ -49,6 +48,9 @@ struct netdata_pid_stat_t { __u32 close_err; }; +//ebpf_process.c +# define NETDATA_GLOBAL_COUNTER 24 + # define NETDATA_KEY_CALLS_DO_SYS_OPEN 0 # define NETDATA_KEY_ERROR_DO_SYS_OPEN 1 @@ -84,4 +86,25 @@ struct netdata_pid_stat_t { # define NETDATA_KEY_ERROR_VFS_READV 22 # define NETDATA_KEY_BYTES_VFS_READV 23 +//network_viewer.c +# define NETDATA_SOCKET_COUNTER 13 + +# define NETDATA_KEY_CALLS_TCP_SENDMSG 0 +# define NETDATA_KEY_ERROR_TCP_SENDMSG 1 +# define NETDATA_KEY_BYTES_TCP_SENDMSG 2 + +# define NETDATA_KEY_CALLS_TCP_CLEANUP_RBUF 3 +# define NETDATA_KEY_ERROR_TCP_CLEANUP_RBUF 4 +# define NETDATA_KEY_BYTES_TCP_CLEANUP_RBUF 5 + +# define NETDATA_KEY_CALLS_TCP_CLOSE 6 + +# define NETDATA_KEY_CALLS_UDP_RECVMSG 7 +# define NETDATA_KEY_ERROR_UDP_RECVMSG 8 +# define NETDATA_KEY_BYTES_UDP_RECVMSG 9 + +# define NETDATA_KEY_CALLS_UDP_SENDMSG 10 +# define NETDATA_KEY_ERROR_UDP_SENDMSG 11 +# define NETDATA_KEY_BYTES_UDP_SENDMSG 12 + #endif diff --git a/kernel/network_viewer_kern.c b/kernel/network_viewer_kern.c new file mode 100644 index 00000000..40728e5c --- /dev/null +++ b/kernel/network_viewer_kern.c @@ -0,0 +1,532 @@ +#define KBUILD_MODNAME "network_viewer" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "bpf_helpers.h" +#include "netdata_ebpf.h" + +/************************************************************************************ + * + * Hash Table Section + * + ***********************************************************************************/ + +/** + * Union used to store ip addresses + */ +union netdata_ip { + __u8 addr8[16]; + __u16 addr16[8]; + __u32 addr32[4]; +}; + +/** + * Structure to store socket information + */ +typedef struct netdata_socket { + __u64 pid_tgid; + __u64 first; + __u64 ct; + __u16 retransmit; //It is never used with UDP + __u64 sent; + __u64 recv; + __u8 protocol; //Should this to be in the index? + __u8 removeme; +} netdata_socket_t; + +/** + * Index used together previous structure + */ +typedef struct netdata_socket_idx { + __u32 pid; + union netdata_ip saddr; + union netdata_ip daddr; + __u16 dport; +} netdata_socket_idx_t; + +/** + * Bandwidth information, the index for this structure is the TGID + */ +typedef struct netdata_bandwidth { + __u64 first; + __u64 ct; + __u64 sent; + __u64 received; + __u8 removed; +} netdata_bandwidth_t; + +/** + * Bandwidth hash table + */ +struct bpf_map_def SEC("maps") tbl_bandwidth = { +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) + .type = BPF_MAP_TYPE_HASH, +#else + .type = BPF_MAP_TYPE_PERCPU_HASH, +#endif + .key_size = sizeof(__u32), + .value_size = sizeof(netdata_bandwidth_t), + .max_entries = 65536 +}; + +/** + * IPV4 hash table + * + */ +struct bpf_map_def SEC("maps") tbl_conn_ipv4_stats = { +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) + .type = BPF_MAP_TYPE_HASH, +#else + .type = BPF_MAP_TYPE_PERCPU_HASH, +#endif + .key_size = sizeof(netdata_socket_idx_t), + .value_size = sizeof(netdata_socket_t), + .max_entries = 65536 +}; + +/** + * IPV6 hash table + * + */ +struct bpf_map_def SEC("maps") tbl_conn_ipv6_stats = { +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) + .type = BPF_MAP_TYPE_HASH, +#else + .type = BPF_MAP_TYPE_PERCPU_HASH, +#endif + .key_size = sizeof(netdata_socket_idx_t), + .value_size = sizeof(netdata_socket_t), + .max_entries = 65536 +}; + + +/** + * UDP hash table, this table is necessry to collect the + * correct size. More details inside UDP section. + */ +struct bpf_map_def SEC("maps") tbl_nv_udp_conn_stats = { +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) + .type = BPF_MAP_TYPE_HASH, +#else + .type = BPF_MAP_TYPE_PERCPU_HASH, +#endif + .key_size = sizeof(__u64), + .value_size = sizeof(void *), + .max_entries = 8192 +}; + +/* + * Hash table used to create charts based in calls. +*/ +struct bpf_map_def SEC("maps") tbl_sock_total_stats = { +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) + .type = BPF_MAP_TYPE_HASH, +#else + .type = BPF_MAP_TYPE_PERCPU_HASH, +#endif + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_SOCKET_COUNTER +}; + +/************************************************************************************ + * + * Common Section + * + ***********************************************************************************/ + +/** + * Function used to update 64 bit values and avoid overflow + */ +static void netdata_update_u64(u64 *res, u64 value) +{ + if ( (0xFFFFFFFFFFFFFFFF - *res) <= value) + *res = value; + else + *res += value; +} + +/* + * Update hash table tbl_sock_total_stats +*/ +static void netdata_update_global(__u32 key, __u64 value) +{ + u64 *res; + res = bpf_map_lookup_elem(&tbl_sock_total_stats, &key); + if (res) { + netdata_update_u64(res, value) ; + } else + bpf_map_update_elem(&tbl_sock_total_stats, &key, &value, BPF_NOEXIST); +} + +/** + * Set Index value + * + * Read information from socket to update the index. +*/ +static __u16 set_idx_value(netdata_socket_idx_t *nsi, struct inet_sock *is, uint32_t pid) +{ + __u16 family; + + nsi->pid = pid; + //Read Family + bpf_probe_read(&family, sizeof(u16), &is->sk.__sk_common.skc_family); + //Read source and destination IPs + if ( family == AF_INET ) { //AF_INET + bpf_probe_read(&nsi->saddr.addr32[0], sizeof(u32), &is->inet_saddr); + bpf_probe_read(&nsi->daddr.addr32[0], sizeof(u32), &is->inet_daddr); + } + // Check necessary according https://elixir.bootlin.com/linux/v5.6.14/source/include/net/sock.h#L199 +#if IS_ENABLED(CONFIG_IPV6) + else if ( family == AF_INET6 ){ + struct in6_addr *addr6 = &is->sk.sk_v6_rcv_saddr; + bpf_probe_read(&nsi->saddr.addr8, sizeof(__u8)*16, &addr6->s6_addr); + + addr6 = &is->sk.sk_v6_daddr; + bpf_probe_read(&nsi->daddr.addr8, sizeof(__u8)*16, &addr6->s6_addr); + } +#endif + + //Read destination port + bpf_probe_read(&nsi->dport, sizeof(u16), &is->inet_dport); + + return family; +} + +/** + * Update time and bytes sent and received + */ +static void update_socket_stats(netdata_socket_t *ptr, __u64 sent, __u64 received) +{ + ptr->ct = bpf_ktime_get_ns(); + + netdata_update_u64(&ptr->sent, sent); + netdata_update_u64(&ptr->recv, received); +} + +/** + * Reset socket stat when PID is not associated more with previous TGID + */ +static void reset_socket_stats(netdata_socket_t *val, __u64 sent, __u64 received) +{ + val->first = bpf_ktime_get_ns(); + val->ct = val->first; + val->retransmit = 0; + val->sent = sent; + val->recv = received; + val->removeme = 0; +} + +/** + * Update the table for the index idx + */ +static void update_socket_table(struct bpf_map_def *tbl, netdata_socket_idx_t *idx, __u64 sent, __u64 received, __u64 pid_tgid, __u8 protocol) +{ + netdata_socket_t *val; + netdata_socket_t data = { }; + + val = (netdata_socket_t *) bpf_map_lookup_elem(tbl, idx); + if (val) { + if ( val->pid_tgid != pid_tgid) { + val->pid_tgid = pid_tgid; + reset_socket_stats(val, sent, received); + } else { + update_socket_stats(val, sent, received); + } + } else { + data.pid_tgid = pid_tgid; + data.first = bpf_ktime_get_ns(); + data.protocol = protocol; + update_socket_stats(&data, sent, received); + + bpf_map_update_elem(tbl, idx, &data, BPF_ANY); + } +} + + +/** + * Update the table for the specified PID + */ +static void update_pid_stats(__u32 pid,__u64 sent, __u64 received) +{ + netdata_bandwidth_t *b; + netdata_bandwidth_t data = { }; + + b = (netdata_bandwidth_t *) bpf_map_lookup_elem(&tbl_bandwidth, &pid); + if (b) { + b->ct = bpf_ktime_get_ns(); + netdata_update_u64(&b->sent, sent); + netdata_update_u64(&b->received, received); + } else { + data.first = bpf_ktime_get_ns(); + data.ct = data.first; + data.sent = sent; + data.received = received; + + bpf_map_update_elem(&tbl_bandwidth, &pid, &data, BPF_ANY); + } +} + + +/************************************************************************************ + * + * TCP Section + * + ***********************************************************************************/ + +/** + * https://elixir.bootlin.com/linux/v5.6.14/source/net/ipv4/tcp.c#L1436 + */ +#if NETDATASEL < 2 +SEC("kretprobe/tcp_sendmsg") +#else +SEC("kprobe/tcp_sendmsg") +#endif +int netdata_tcp_sendmsg(struct pt_regs* ctx) +{ +#if NETDATASEL < 2 + int ret = (int)PT_REGS_RC(ctx); +#endif + __u16 family; + netdata_socket_idx_t idx = { }; + struct bpf_map_def *tbl; + + __u64 pid_tgid = bpf_get_current_pid_tgid(); + __u32 pid = (__u32)(pid_tgid >> 32); + __u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid); + size_t sent = (size_t)PT_REGS_PARM3(ctx); + struct inet_sock *is = inet_sk((struct sock *)PT_REGS_PARM1(ctx)); + + netdata_update_global(NETDATA_KEY_CALLS_TCP_SENDMSG, 1); + + family = set_idx_value(&idx, is, pid); + tbl = (family == AF_INET6)?&tbl_conn_ipv6_stats:&tbl_conn_ipv4_stats; + + netdata_update_global(NETDATA_KEY_BYTES_TCP_SENDMSG, (__u64)sent); + update_socket_table(tbl, &idx, (__u64) sent, 0, pid_tgid, 6); + + update_pid_stats(tgid, (__u64) sent, 0); + +#if NETDATASEL < 2 + if (ret < 0) { + netdata_update_global(NETDATA_KEY_ERROR_TCP_SENDMSG, 1); + } +#endif + + return 0; +} + +/** + * https://elixir.bootlin.com/linux/v5.6.14/source/net/ipv4/tcp.c#L1528 + */ +SEC("kprobe/tcp_cleanup_rbuf") +int netdata_tcp_cleanup_rbuf(struct pt_regs* ctx) +{ + __u16 family; + netdata_socket_idx_t idx = { }; + struct bpf_map_def *tbl; + + __u64 pid_tgid = bpf_get_current_pid_tgid(); + __u32 pid = (__u32)(pid_tgid >> 32); + __u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid); + int copied = (int)PT_REGS_PARM2(ctx); + struct inet_sock *is = inet_sk((struct sock *)PT_REGS_PARM1(ctx)); + + netdata_update_global(NETDATA_KEY_CALLS_TCP_CLEANUP_RBUF, 1); + if (copied < 0) { + netdata_update_global(NETDATA_KEY_ERROR_TCP_CLEANUP_RBUF, 1); + return 0; + } + + family = set_idx_value(&idx, is, pid); + tbl = (family == AF_INET6)?&tbl_conn_ipv6_stats:&tbl_conn_ipv4_stats; + + netdata_update_global(NETDATA_KEY_BYTES_TCP_CLEANUP_RBUF, (__u64) copied); + update_socket_table(tbl, &idx, 0, (__u64) copied, pid_tgid, 6); + + update_pid_stats(tgid, 0, (__u64) copied); + + return 0; +} + +/** + * https://elixir.bootlin.com/linux/v5.6.14/source/net/ipv4/tcp.c#L2351 + */ +SEC("kprobe/tcp_close") +int netdata_tcp_close(struct pt_regs* ctx) +{ + __u16 family; + netdata_socket_idx_t idx = { }; + struct bpf_map_def *tbl; + netdata_socket_t *val; + + __u64 pid_tgid = bpf_get_current_pid_tgid(); + __u32 pid = (__u32)(pid_tgid >> 32); + struct inet_sock *is = inet_sk((struct sock *)PT_REGS_PARM1(ctx)); + + netdata_update_global(NETDATA_KEY_CALLS_TCP_CLOSE, 1); + + family = set_idx_value(&idx, is, pid); + tbl = (family == AF_INET6)?&tbl_conn_ipv6_stats:&tbl_conn_ipv4_stats; + val = (netdata_socket_t *) bpf_map_lookup_elem(tbl, &idx); + if (val) { + //The socket information needs to be removed after read on user ring + val->removeme = 1; + } + + return 0; +} + +/************************************************************************************ + * + * UDP Section + * + ***********************************************************************************/ + +/* We can only get the accurate number of copied bytes from the return value, so we pass our + * sock* pointer from the kprobe to the kretprobe via a map (udp_recv_sock) to get all required info + * + * The same issue exists for TCP, but we can conveniently use the downstream function tcp_cleanup_rbuf +*/ + +/** + * https://elixir.bootlin.com/linux/v5.6.14/source/net/ipv4/udp.c#L1726 + */ +SEC("kprobe/udp_recvmsg") +int trace_udp_recvmsg(struct pt_regs* ctx) +{ + __u64 pid_tgid = bpf_get_current_pid_tgid(); + struct sock *sk = (struct sock*)PT_REGS_PARM1(ctx); + + bpf_map_update_elem(&tbl_nv_udp_conn_stats, &pid_tgid, &sk, BPF_ANY); + netdata_update_global(NETDATA_KEY_CALLS_UDP_RECVMSG, 1); + + return 0; +} + +/** + * https://elixir.bootlin.com/linux/v5.6.14/source/net/ipv4/udp.c#L1726 + */ +SEC("kretprobe/udp_recvmsg") +int trace_udp_ret_recvmsg(struct pt_regs* ctx) +{ + __u64 pid_tgid = bpf_get_current_pid_tgid(); + __u32 pid = (__u32)(pid_tgid >> 32); + __u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid); + struct bpf_map_def *tbl; + + __u16 family; + netdata_socket_idx_t idx = { }; + + struct sock **skpp = bpf_map_lookup_elem(&tbl_nv_udp_conn_stats, &pid_tgid); + if (skpp == 0) { + return 0; + } + + struct inet_sock *is = inet_sk((struct sock *)*skpp); + int copied = (int)PT_REGS_RC(ctx); + + if (copied < 0) { + netdata_update_global(NETDATA_KEY_ERROR_UDP_RECVMSG, 1); + bpf_map_delete_elem(&tbl_nv_udp_conn_stats, &pid_tgid); + return 0; + } + + bpf_map_delete_elem(&tbl_nv_udp_conn_stats, &pid_tgid); + + family = set_idx_value(&idx, is, pid); + tbl = (family == AF_INET6)?&tbl_conn_ipv6_stats:&tbl_conn_ipv4_stats; + + netdata_update_global(NETDATA_KEY_BYTES_UDP_RECVMSG, (__u64) copied); + update_socket_table(tbl, &idx, 0, (__u64) copied, pid_tgid, 17); + + update_pid_stats(tgid, 0, (__u64) copied); + + return 0; +} + +/** + * https://elixir.bootlin.com/linux/v5.6.14/source/net/ipv4/udp.c#L965 + */ +#if NETDATASEL < 2 +SEC("kretprobe/udp_sendmsg") +#else +SEC("kprobe/udp_sendmsg") +#endif +int trace_udp_sendmsg(struct pt_regs* ctx) +{ +#if NETDATASEL < 2 + int ret = (int)PT_REGS_RC(ctx); +#endif + __u64 pid_tgid = bpf_get_current_pid_tgid(); + __u32 pid = (__u32)(pid_tgid >> 32); + __u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid); + struct bpf_map_def *tbl; + + __u16 family; + size_t sent = (size_t)PT_REGS_PARM3(ctx); + netdata_socket_idx_t idx = { }; + struct inet_sock *is = inet_sk((struct sock *)PT_REGS_PARM1(ctx)); + + netdata_update_global(NETDATA_KEY_CALLS_UDP_SENDMSG, 1); + + family = set_idx_value(&idx, is, pid); + tbl = (family == AF_INET6)?&tbl_conn_ipv6_stats:&tbl_conn_ipv4_stats; + + update_socket_table(tbl, &idx, (__u64) sent, 0, pid_tgid, 17); + + netdata_update_global(NETDATA_KEY_BYTES_UDP_SENDMSG, (__u64) sent); + update_pid_stats(tgid, (__u64) sent, 0); + +#if NETDATASEL < 2 + if (ret < 0) { + netdata_update_global(NETDATA_KEY_ERROR_UDP_SENDMSG, 1); + } +#endif + + return 0; +} + +/************************************************************************************ + * + * Process Section + * + ***********************************************************************************/ + +/** + * https://elixir.bootlin.com/linux/latest/source/kernel/exit.c#L711 + */ +SEC("kprobe/do_exit") +int netdata_sys_exit(struct pt_regs* ctx) +{ + netdata_bandwidth_t *b; + __u64 pid_tgid = bpf_get_current_pid_tgid(); + __u32 pid = (__u32)(pid_tgid >> 32); + __u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid); + + //Am I the child? + if ( pid != tgid ) + return 0; + + //Remove PID from table + b = (netdata_bandwidth_t *) bpf_map_lookup_elem(&tbl_bandwidth, &tgid); + if (b) { + b->removed = 1; + } + + return 0; +} + +char _license[] SEC("license") = "GPL"; +u32 _version SEC("version") = LINUX_VERSION_CODE; + diff --git a/library/api.c b/library/api.c index fe2baea8..6bff4c8d 100644 --- a/library/api.c +++ b/library/api.c @@ -56,7 +56,9 @@ void foce_map(int fd) { struct map_me_to_others key = {}, next_key; int values[2]; while (bpf_map_get_next_key(fd, &key, &next_key) == 0) { - bpf_map_lookup_elem(fd, &next_key, values); + if (!bpf_map_lookup_elem(fd, &next_key, values) ) { + bpf_map_delete_elem(fd, &next_key); + } } int pmu_fd = 0; diff --git a/library/bpf_load.c b/library/bpf_load.c index 13f047db..8c8247e0 100644 --- a/library/bpf_load.c +++ b/library/bpf_load.c @@ -36,7 +36,7 @@ static char license[128]; static int kern_version; static bool processed_sec[128]; char bpf_log_buf[BPF_LOG_BUF_SIZE]; -int map_fd[MAX_MAPS]; +//int map_fd[MAX_MAPS]; int prog_fd[MAX_PROGS]; int event_fd[MAX_PROGS]; int prog_cnt; @@ -422,7 +422,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size, i return 0; } -static int load_maps(struct bpf_map_data *maps, int nr_maps, +static int load_maps(int *map_fd, struct bpf_map_data *maps, int nr_maps, fixup_map_cb fixup_map) { int i, numa_node; @@ -669,7 +669,7 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx, return nr_maps; } -static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map, int pid) +static int do_load_bpf_file(int *map_fd,const char *path, fixup_map_cb fixup_map, int pid) { int fd, i, ret, maps_shndx = -1, strtabidx = -1; Elf *elf; @@ -752,7 +752,7 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map, int pid) nr_maps, strerror(-nr_maps)); goto done; } - if (load_maps(map_data, nr_maps, fixup_map)) + if (load_maps(map_fd, map_data, nr_maps, fixup_map)) goto done; map_data_count = nr_maps; @@ -992,14 +992,14 @@ int unload_bpf_file(const char *path) } */ -int load_bpf_file(char *path, int pid) +int load_bpf_file(int *map_fd,char *path, int pid) { - return do_load_bpf_file(path, NULL, pid); + return do_load_bpf_file(map_fd, path, NULL, pid); } -int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map) +int load_bpf_file_fixup_map(int *map_fd,const char *path, fixup_map_cb fixup_map) { - return do_load_bpf_file(path, fixup_map, 0); + return do_load_bpf_file(map_fd, path, fixup_map, 0); } void read_trace_pipe(void) diff --git a/user/Makefile b/user/Makefile index cc1b67bb..f578cde6 100644 --- a/user/Makefile +++ b/user/Makefile @@ -24,17 +24,18 @@ EXTRA_CFLAGS += -fno-stack-protector all: $(OBJECT_LIBLOAD) $(KERNEL_PROGRAM) cp $(KERNEL_DIR)rprocess_kern.o rnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o cp $(KERNEL_DIR)pprocess_kern.o pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o - cp $(KERNEL_DIR)dprocess_kern.o dnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o cp $(KERNEL_DIR)dlatency_process_kern.o dlatency_process_kern.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o + cp $(KERNEL_DIR)rnetwork_viewer_kern.o rnetdata_ebpf_socket.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o + cp $(KERNEL_DIR)pnetwork_viewer_kern.o pnetdata_ebpf_socket.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o $(CC) $(EXTRA_CFLAGS) -L. -I../includes/ -o process_monitor process_user.c $(LIBS) $(CC) $(EXTRA_CFLAGS) -L. -I../includes/ -o process_latency latency_process_user.c $(LIBS) $(CC) $(EXTRA_CFLAGS) -pthread -L. -I../includes/ -o process_test latency_test.c $(LIBS) ifneq ("$(STATIC)","1") - if [ -f libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) ]; then tar -cf ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar $(LIBLOAD_DIR)libbpf_kernel*.so libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) [pr]netdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o; else echo "ERROR: Cannot find libbpf_kernel.so"; exit 1; fi + if [ -f libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) ]; then tar -cf ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar $(LIBLOAD_DIR)libbpf_kernel*.so libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) [pr]netdata_ebpf_*.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o; else echo "ERROR: Cannot find libbpf_kernel.so"; exit 1; fi else - if [ -f libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) ]; then tar -cf ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) [pr]netdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o; else echo "ERROR: Cannot find necessary libraries."; exit 1; fi + if [ -f libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) ]; then tar -cf ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar libnetdata_ebpf.so.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) [pr]netdata_ebpf_*.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o; else echo "ERROR: Cannot find necessary libraries."; exit 1; fi endif - if [ "$${DEBUG:-0}" -eq 1 ]; then tar -uvf ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar dnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o process_latency process_monitor process_test ../tools/check-kernel-config.sh ../tools/install.sh ../tools/uninstall.sh; fi + if [ "$${DEBUG:-0}" -eq 1 ]; then tar -uvf ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar dnetdata_ebpf_*.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o process_latency process_monitor process_test ../tools/check-kernel-config.sh ../tools/install.sh ../tools/uninstall.sh; fi xz ../artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar ( cd ../artifacts; sha256sum netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar.xz > netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar.xz.sha256sum )