Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netwatcher:fix bug #925

Merged
merged 16 commits into from
Oct 14, 2024
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;
}
}
8 changes: 3 additions & 5 deletions MagicEyes/src/backend/net/net_watcher/bpf/mysql.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ static __always_inline int __handle_mysql_start(struct pt_regs *ctx) {
}

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("sql1==%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 +70,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
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
Loading