Skip to content

Commit

Permalink
Merge pull request #49 from hengyoush/fix/1.3.1
Browse files Browse the repository at this point in the history
[Fix] fix 1.3.1 bugs
  • Loading branch information
hengyoush authored Sep 18, 2024
2 parents cf40c56 + 218b624 commit 49b58e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions agent/compatible/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func init() {
SupportBTF: true,
},
}
baseVersion.addBackupInstrumentFunction(bpf.AgentStepTDEV_OUT, InstrumentFunction{"kprobe/__dev_queue_xmit", "DevQueueXmit"})
v5d15 := copyKernelVersion(baseVersion)
KernelVersionsMap.Put(v5d15.Version, v5d15)

Expand Down
2 changes: 1 addition & 1 deletion agent/conn/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (p *Processor) run() {
var conn *Connection4
isIpv6 := event.ConnInfo.Laddr.In6.Sin6Family == common.AF_INET6
if isIpv6 {
common.DefaultLog.Warnf("ipv6: %x", event.ConnInfo.Laddr.In6.Sin6Addr.In6U.U6Addr8[:])
common.DefaultLog.Debugf("ipv6: %x", event.ConnInfo.Laddr.In6.Sin6Addr.In6U.U6Addr8[:])
}
if event.ConnType == bpf.AgentConnTypeTKConnect {
conn = &Connection4{
Expand Down
25 changes: 14 additions & 11 deletions bpf/pktlatency.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ static __always_inline void reverse_sock_key_no_copy(struct sock_key* key) {
key->dport = temp;
}
static void __always_inline print_sock_key(struct sock_key* key) {
// bpf_printk("print_sock_key port: sport:%u, dport:%u", key->sport, key->dport);
// bpf_printk("print_sock_key addr: saddr:%llx, saddr:%llx", key->sip[0], key->sip[1]);
// bpf_printk("print_sock_key addr: daddr:%llx, daddr:%llx", key->dip[0], key->dip[1]);
// bpf_printk("print_sock_key port: sport:%u, dport:%u\n", key->sport, key->dport);
// bpf_printk("print_sock_key addr: saddr:%llx, saddr:%llx\n", key->sip[0], key->sip[1]);
// bpf_printk("print_sock_key addr: daddr:%llx, daddr:%llx\n", key->dip[0], key->dip[1]);
// bpf_printk("print_sock_key family: family:%u", key->family);
}
static void __always_inline parse_kern_evt_body(struct parse_kern_evt_body *param) {
Expand Down Expand Up @@ -909,7 +909,7 @@ static __inline void read_sockaddr_kernel(struct conn_info_t* conn_info,

conn_info->laddr.in6.sin6_port = lport;
conn_info->raddr.in6.sin6_port = rport;
if (family == AF_INET) {
if (family == AF_INET || !use_ipv6(sk_common)) {
conn_info->laddr.in6.sin6_addr.in6_u.u6_addr32[0] = _C(sk_common, skc_rcv_saddr);
conn_info->raddr.in6.sin6_addr.in6_u.u6_addr32[0] = _C(sk_common, skc_daddr);
// BPF_CORE_READ_INTO(&conn_info->laddr.in4.sin_addr.s_addr, sk_common, skc_rcv_saddr);
Expand Down Expand Up @@ -1037,6 +1037,9 @@ enum endpoint_role_t role, uint64_t start_ts) {
// pr_bpf_debug("raddr: null");
}
struct tcp_sock * tcp_sk = get_socket_from_fd(fd);
if (!tcp_sk) {
tcp_sk = _C(socket, sk);
}
// s => d
struct sock_key key = {0};
parse_sock_key_sk((struct sock*)tcp_sk, &key);
Expand All @@ -1047,6 +1050,8 @@ enum endpoint_role_t role, uint64_t start_ts) {
// }

// print_sock_key(&key);
struct sock_common *sk_common = (struct sock_common *) tcp_sk;
bool is_ipv6 = use_ipv6(sk_common);
if (socket == NULL) {
// conn_info.laddr.in4.sin_addr.s_addr = role == kRoleClient ? key.sip : key.dip;
// conn_info.laddr.in4.sin_port = role == kRoleClient ? key.sport : key.dport;
Expand All @@ -1057,10 +1062,9 @@ enum endpoint_role_t role, uint64_t start_ts) {
conn_info.laddr.in6.sin6_port = key.sport ;
conn_info.raddr.in6.sin6_port = key.dport;
uint16_t family = -1;
struct sock_common *sk_common = (struct sock_common *) tcp_sk;
BPF_CORE_READ_INTO(&family, sk_common, skc_family);
// bpf_printk("AF: %d", family);
if (family == AF_INET) {
if (family == AF_INET || !is_ipv6) {
// conn_info.laddr.in4.sin_addr.s_addr = (u32)key.sip[0] ;
// conn_info.raddr.in4.sin_addr.s_addr = (u32)key.dip[0];
conn_info.laddr.in6.sin6_addr.in6_u.u6_addr32[0] = (u32)key.sip[0];
Expand All @@ -1072,6 +1076,10 @@ enum endpoint_role_t role, uint64_t start_ts) {
conn_info.laddr.sa.sa_family = family;
conn_info.raddr.sa.sa_family = family;
}
if (!use_ipv6(sk_common)) {
conn_info.laddr.sa.sa_family = AF_INET;
conn_info.raddr.sa.sa_family = AF_INET;
}

// bpf_printk("submit_new_conn laddr: port:%u", conn_info.laddr.in4.sin_port);
// bpf_printk("submit_new_conn raddr: port:%u", conn_info.raddr.in4.sin_port);
Expand Down Expand Up @@ -1203,11 +1211,6 @@ static __always_inline bool create_conn_info_in_data_syscall(void* ctx, struct t
return false;
}

// if (key.sport==3306) {
// bpf_printk("update conninfo! fa: %d", family);
// print_sock_key(&key);
// }

u32 send_initial_seq = 0;
u32 rcv_initial_seq = 0;
u32 write_seq = _C(tcp_sk, write_seq);
Expand Down

0 comments on commit 49b58e3

Please sign in to comment.