Skip to content

Commit

Permalink
netwatcher:fix bug (#925)
Browse files Browse the repository at this point in the history
* add use protocol percentage

* update

* delete

* delete

* move net_watcher to MagicEyes

* adaptation version

* update

* fix bug

* fix bug

* fix bug

* fix bug

* update

* fix mysql
  • Loading branch information
wynyibo authored Oct 14, 2024
1 parent 4f71180 commit 05a715f
Show file tree
Hide file tree
Showing 10 changed files with 1,247 additions and 830 deletions.
382 changes: 225 additions & 157 deletions MagicEyes/src/backend/net/net_watcher/bpf/common.bpf.h

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions MagicEyes/src/backend/net/net_watcher/bpf/drop.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
// net_watcher libbpf 丢包

#include "common.bpf.h"
static __always_inline
int __tp_kfree(struct trace_event_raw_kfree_skb *ctx)
static __always_inline int __tp_kfree(struct trace_event_raw_kfree_skb *ctx)
{
if(!drop_reason)
if (!drop_reason)
return 0;
struct sk_buff *skb=ctx->skbaddr;
if (skb == NULL) // 判断是否为空
struct sk_buff *skb = ctx->skbaddr;
if (skb == NULL)
return 0;
struct iphdr *ip = skb_to_iphdr(skb);
struct tcphdr *tcp = skb_to_tcphdr(skb);
struct packet_tuple pkt_tuple = {0};
get_pkt_tuple(&pkt_tuple, ip, tcp);

struct reasonissue *message;
struct reasonissue *message;
message = bpf_ringbuf_reserve(&kfree_rb, sizeof(*message), 0);
if(!message){
if (!message)
{
return 0;
}
message->saddr = pkt_tuple.saddr;
Expand All @@ -41,8 +41,8 @@ int __tp_kfree(struct trace_event_raw_kfree_skb *ctx)
message->protocol = ctx->protocol;
message->location = (long)ctx->location;
message->drop_reason = ctx->reason;
bpf_ringbuf_submit(message,0);
if(stack_info)
bpf_ringbuf_submit(message, 0);
if (stack_info)
getstack(ctx);
return 0;
}
}
12 changes: 3 additions & 9 deletions MagicEyes/src/backend/net/net_watcher/bpf/mysql.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ static __always_inline int __handle_mysql_start(struct pt_regs *ctx) {
u32 size = 0;
char *sql;

if (command != COM_QUERY) {
return 0;
}

bpf_probe_read(&info.size, sizeof(info.size), &com_data->com_query.length);
bpf_probe_read_str(&sql, sizeof(sql), &com_data->com_query.query);
bpf_probe_read_str(&info.msql, sizeof(info.msql), sql);
// bpf_printk("sql1==%s size1==%lu", info.msql,info.size);
bpf_probe_read(&sql, sizeof(sql), &com_data->com_query.query);
bpf_probe_read(&info.msql, sizeof(info.msql), sql);
//bpf_printk("sql==%s size1==%lu", info.msql,info.size);
info.start_time = bpf_ktime_get_ns() / 1000;

bpf_map_update_elem(&queries, &tid, &info, BPF_ANY);
Expand Down Expand Up @@ -70,8 +66,6 @@ static __always_inline int __handle_mysql_end(struct pt_regs *ctx) {
bpf_get_current_comm(&message->comm, sizeof(comm));
message->size = info->size;
bpf_probe_read_str(&message->msql, sizeof(message->msql), info->msql);
// bpf_printk("C==%d D==%lu S==%lu SQL==%s",count,
// message->duratime,message->size,message->msql);

bpf_ringbuf_submit(message, 0);
return 0;
Expand Down
7 changes: 4 additions & 3 deletions MagicEyes/src/backend/net/net_watcher/bpf/net_watcher.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,15 @@ int BPF_KPROBE(icmp_reply, struct icmp_bxm *icmp_param, struct sk_buff *skb) {

// mysql
SEC("uprobe/_Z16dispatch_commandP3THDPK8COM_DATA19enum_server_command")
int BPF_KPROBE(query__start) { return __handle_mysql_start(ctx); }
int BPF_UPROBE(query__start) { return __handle_mysql_start(ctx); }

SEC("uretprobe/_Z16dispatch_commandP3THDPK8COM_DATA19enum_server_command")
int BPF_KPROBE(query__end) { return __handle_mysql_end(ctx); }
int BPF_UPROBE(query__end) { return __handle_mysql_end(ctx); }

//redis
SEC("uprobe/processCommand")
int BPF_KPROBE(redis_processCommand) { return __handle_redis_start(ctx); }
int BPF_KPROBE(redis_processCommand) {
return __handle_redis_start(ctx); }

SEC("uretprobe/call")
int BPF_KPROBE(redis_call) { return __handle_redis_end(ctx); }
Expand Down
2 changes: 1 addition & 1 deletion MagicEyes/src/backend/net/net_watcher/bpf/netfilter.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int store_nf_time(struct sk_buff *skb, int hook)
{
if(!net_filter)
return 0;
if (skb == NULL) // 判断是否为空
if (skb == NULL)
return 0;
struct iphdr *ip = skb_to_iphdr(skb);
struct tcphdr *tcp = skb_to_tcphdr(skb);
Expand Down
Loading

0 comments on commit 05a715f

Please sign in to comment.