Skip to content

Commit 804e0a8

Browse files
authored
Merge pull request #146 from OpenCloudOS/dev
Dev
2 parents 37a6103 + c158544 commit 804e0a8

File tree

7 files changed

+23
-26
lines changed

7 files changed

+23
-26
lines changed

src/analysis.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,9 @@ DEFINE_ANALYZER_ENTRY(rtt, TRACE_MODE_ALL_MASK)
10441044
char *msg = malloc(1024);
10451045

10461046
msg[0] = '\0';
1047-
sprintf(msg, PFMT_EMPH_STR(" *rtt:%ums, rtt_min:%ums*"),
1048-
event->first_rtt, event->last_rtt);
1047+
sprintf(msg, PFMT_EMPH_STR(" *rtt:%u.%03ums, rtt_min:%u.%03ums*"),
1048+
event->first_rtt / 1000, event->first_rtt % 1000,
1049+
event->last_rtt / 1000, event->last_rtt % 1000);
10491050
entry_set_msg(e, msg);
10501051

10511052
return RESULT_CONT;

src/progs/core.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include <bpf/bpf_endian.h>
55
#include <bpf/bpf_tracing.h>
66

7+
#include "skb_parse.h"
78
#include "shared.h"
8-
9-
#include "kprobe_trace.h"
109
#include "core.h"
1110

1211
#ifdef KERN_VER
@@ -783,9 +782,6 @@ DEFINE_KPROBE_INIT(tcp_ack_update_rtt, tcp_ack_update_rtt, 6,
783782
if ((long)first_rtt < 0)
784783
return -1;
785784

786-
first_rtt = first_rtt / 1000;
787-
last_rtt = last_rtt / 1000;
788-
789785
if (first_rtt < info->args->first_rtt || last_rtt < info->args->last_rtt)
790786
return -1;
791787

src/progs/core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef _H_PROG_CORE
22
#define _H_PROG_CORE
33

4-
#include "skb_parse.h"
5-
64
typedef struct {
75
u16 func1;
86
u16 func2;

src/progs/kprobe.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#define KBUILD_MODNAME ""
2-
#include <kheaders.h>
3-
#include <bpf/bpf_helpers.h>
4-
#include <bpf/bpf_endian.h>
5-
#include <bpf/bpf_tracing.h>
62

3+
#include "skb_parse.h"
74
#include "shared.h"
85
#include "core.h"
96

10-
#include "kprobe_trace.h"
11-
127
#define pt_regs_param_0 PT_REGS_PARM1
138
#define pt_regs_param_1 PT_REGS_PARM2
149
#define pt_regs_param_2 PT_REGS_PARM3

src/progs/shared.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define MAX_FUNC_STACK 16
55

66
#include "skb_shared.h"
7-
87
#include "kprobe_trace.h"
98

109
typedef struct {

src/progs/skb_parse.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#ifndef _H_BPF_SKB_UTILS
88
#define _H_BPF_SKB_UTILS
99

10+
#include <kheaders.h>
11+
#include <bpf/bpf_helpers.h>
12+
#include <bpf/bpf_endian.h>
13+
#include <bpf/bpf_tracing.h>
1014
#include <bpf/bpf_core_read.h>
1115

1216
#include "skb_macro.h"
@@ -46,6 +50,7 @@ const volatile bool bpf_func_exist[BPF_LOCAL_FUNC_MAX] = {0};
4650
#endif
4751

4852
#define skb_cb(__skb) ((void *)(__skb) + bpf_core_field_offset(typeof(*__skb), cb))
53+
#define __ptr(a) ((void *)(a))
4954

5055
#define CONFIG() ({ \
5156
int _key = 0; \
@@ -439,7 +444,7 @@ static inline int probe_parse_sk(struct sock *sk, sock_t *ske,
439444

440445
switch (l4_proto) {
441446
case IPPROTO_TCP: {
442-
struct tcp_sock *tp = (void *)sk;
447+
struct tcp_sock *tp = __ptr(sk);
443448

444449
if (bpf_core_type_exists(struct tcp_sock)) {
445450
ske->l4.tcp.packets_out = _C(tp, packets_out);
@@ -472,7 +477,7 @@ static inline int probe_parse_sk(struct sock *sk, sock_t *ske,
472477
if (!bpf_core_type_exists(struct inet_connection_sock))
473478
return 0;
474479

475-
icsk = (void *)sk;
480+
icsk = __ptr(sk);
476481
bpf_probe_read_kernel(&ske->ca_state, sizeof(u8),
477482
(u8 *)icsk +
478483
bpf_core_field_offset(struct inet_connection_sock,
@@ -566,7 +571,7 @@ static inline int probe_parse_skb_sk(struct sock *sk, struct sk_buff *skb,
566571
/* parse L4 information from the socket */
567572
switch (l4_proto) {
568573
case IPPROTO_TCP: {
569-
struct tcp_sock *tp = (void *)sk;
574+
struct tcp_sock *tp = __ptr(sk);
570575
struct tcp_skb_cb *cb;
571576

572577
cb = skb_cb(skb);
@@ -664,7 +669,7 @@ static __always_inline int probe_parse_skb(struct sk_buff *skb, struct sock *sk,
664669
/* mac header is set properly, we can use it directly. */
665670
struct ethhdr *eth = ctx->data + ctx->mac_header;
666671

667-
l3 = (void *)eth + ETH_HLEN;
672+
l3 = __ptr(eth) + ETH_HLEN;
668673
l3_proto = bpf_ntohs(_(eth->h_proto));
669674
}
670675

@@ -697,9 +702,9 @@ static inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
697702
pkt_args_t *bpf_args)
698703
{
699704
struct ethhdr *eth = SKB_DATA(skb);
700-
struct iphdr *ip = (void *)(eth + 1);
705+
struct iphdr *ip = __ptr(eth + 1);
701706

702-
if ((void *)ip > SKB_END(skb))
707+
if (__ptr(ip) > SKB_END(skb))
703708
goto err;
704709

705710
if (bpf_args && args_check(bpf_args, l3_proto, eth->h_proto))
@@ -714,8 +719,8 @@ static inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
714719
args_check(bpf_args, daddr, ip->daddr)))
715720
goto err;
716721

717-
l4_min_t *l4_p = (void *)(ip + 1);
718-
struct tcphdr *tcp = (void *)l4_p;
722+
l4_min_t *l4_p = __ptr(ip + 1);
723+
struct tcphdr *tcp = __ptr(l4_p);
719724

720725
switch (ip->protocol) {
721726
case IPPROTO_UDP:
@@ -733,7 +738,7 @@ static inline int direct_parse_skb(struct __sk_buff *skb, packet_t *pkt,
733738
pkt->l4.min = *l4_p;
734739
break;
735740
case IPPROTO_ICMP: {
736-
struct icmphdr *icmp = (void *)l4_p;
741+
struct icmphdr *icmp = __ptr(l4_p);
737742
if (SKB_CHECK_ICMP(skb))
738743
goto err;
739744

src/trace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,11 @@ static int trace_prepare_args()
542542
}
543543

544544
/* enable tcp_ack_update_rtt as monitor if rtt set */
545-
if (bpf_args->first_rtt || bpf_args->last_rtt)
545+
if (bpf_args->first_rtt || bpf_args->last_rtt) {
546+
bpf_args->first_rtt *= 1000;
547+
bpf_args->last_rtt *= 1000;
546548
trace_tcp_ack_update_rtt.monitor = 2;
549+
}
547550

548551
if (trace_prepare_mode(args))
549552
goto err;

0 commit comments

Comments
 (0)