Skip to content

Commit e3db531

Browse files
committed
nettrace: print conguestion state for sock mode
Signed-off-by: Menglong Dong <imagedong@tencent.com>
1 parent 16d4912 commit e3db531

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

shared/bpf/skb_macro.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#endif
4747

4848
#ifdef COMPAT_MODE
49+
#define bpf_core_helper_exist(name) \
50+
bpf_core_enum_value_exists(enum bpf_func_id, BPF_FUNC_##name)
51+
4952
#undef bpf_core_type_exists
5053
#define bpf_core_type_exists(type) false
5154

@@ -54,6 +57,11 @@
5457

5558
#undef bpf_core_enum_value_exists
5659
#define bpf_core_enum_value_exists(value) false
60+
61+
#undef bpf_core_field_offset
62+
#define bpf_core_field_offset(type, field) offsetof(type, field)
63+
#else
64+
#define bpf_core_helper_exist(name) false
5765
#endif
5866

5967
#endif

shared/bpf/skb_parse.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010
#undef bpf_core_type_exists
1111
#undef bpf_core_field_exists
1212
#undef bpf_core_enum_value_exists
13+
#undef bpf_core_field_offset
1314
#include <bpf/bpf_core_read.h>
1415

1516
#include "skb_macro.h"
1617
#include "skb_shared.h"
1718

18-
#ifndef COMPAT_MODE
19-
#define bpf_core_helper_exist(name) \
20-
bpf_core_enum_value_exists(enum bpf_func_id, BPF_FUNC_##name)
21-
#else
22-
#define bpf_core_helper_exist(name) false
23-
#endif
2419

2520
typedef struct {
2621
pkt_args_t pkt;
@@ -416,6 +411,12 @@ static try_inline int __probe_parse_sk(parse_ctx_t *ctx)
416411
ske->state = _C(skc, skc_state);
417412

418413
icsk = (void *)sk;
414+
bpf_probe_read_kernel(&ske->ca_state, sizeof(u8),
415+
(u8 *)icsk +
416+
bpf_core_field_offset(struct inet_connection_sock,
417+
icsk_retransmits) -
418+
1);
419+
419420
if (bpf_core_helper_exist(jiffies64))
420421
ske->timer_out = _C(icsk, icsk_timeout) - (unsigned long)bpf_jiffies64();
421422

shared/bpf/skb_shared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef struct {
118118
u8 proto_l4;
119119
u8 timer_pending;
120120
u8 state;
121+
u8 ca_state;
121122
} sock_t;
122123

123124
#define TCP_FLAGS_ACK (1 << 4)

shared/pkt_utils.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ static const char *state_name[] = {
173173
[TCP_LISTEN] = "LISTEN",
174174
[TCP_CLOSING] = "CLOSING",
175175
};
176+
static const char *ca_name[] = {
177+
[TCP_CA_Open] = "CA_Open",
178+
[TCP_CA_Disorder] = "CA_Disorder",
179+
[TCP_CA_CWR] = "CA_CWR",
180+
[TCP_CA_Recovery] = "CA_Recovery",
181+
[TCP_CA_Loss] = "CA_Loss",
182+
};
183+
184+
typedef struct {
185+
u8 icsk_ca_state:5,
186+
icsk_ca_initialized:1,
187+
icsk_ca_setsockopt:1,
188+
icsk_ca_dst_locked:1;
189+
190+
} tcp_ca_data_t;
176191

177192
int ts_print_sock(char *buf, sock_t *ske, char *minfo, bool date_format)
178193
{
@@ -236,10 +251,13 @@ int ts_print_sock(char *buf, sock_t *ske, char *minfo, bool date_format)
236251
}
237252

238253
switch (l4) {
239-
case IPPROTO_TCP:
240-
BUF_FMT(" %s info:(%u %u)", state_name[ske->state],
254+
case IPPROTO_TCP: {
255+
tcp_ca_data_t *ca_state = (void *)&ske->ca_state;
256+
BUF_FMT(" %s %s info:(%u %u)", state_name[ske->state],
257+
ca_name[ca_state->icsk_ca_state],
241258
ske->l4.tcp.packets_out,
242259
ske->l4.tcp.retrans_out);
260+
}
243261
case IPPROTO_UDP:
244262
hz = kernel_hz();
245263
hz = hz > 0 ? hz : 1;

0 commit comments

Comments
 (0)