Skip to content

Commit 636211c

Browse files
committed
nettrace: make some functions to monitor
Signed-off-by: Menglong Dong <imagedong@tencent.com>
1 parent ce6309b commit 636211c

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/gen_trace.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def get_arg_count(name):
117117
btf_data = btf_file.read()
118118
reg_text = f"'{name}' type_id=([0-9]+)"
119119
match = re.search(reg_text, btf_data)
120+
if not match:
121+
return 0
122+
120123
type_id = match.group(1)
121124
match = re.search(f"\\[{type_id}\\].*vlen=([0-9]+)", btf_data)
122125
return match.group(1)
@@ -197,9 +200,16 @@ def gen_trace(trace, group, p_name):
197200
if 'skb' in trace or 'sock' in trace:
198201
arg_count = '0'
199202
if 'monitor' in trace:
200-
trace['arg_count'] = get_arg_count(target)
201-
arg_count = trace['arg_count']
202-
fields_str += append_trace_field('arg_count', trace, 'raw')
203+
if 'arg_count' not in trace:
204+
trace['arg_count'] = get_arg_count(target)
205+
arg_count = trace['arg_count']
206+
else:
207+
arg_count = trace['arg_count']
208+
if not arg_count:
209+
print(f"BTF not found for {target}, skip monitor", file=sys.stderr)
210+
trace['monitor'] = 0
211+
else:
212+
fields_str += append_trace_field('arg_count', trace, 'raw')
203213
if 'skb' in trace:
204214
skb_index = int(trace["skb"]) + 1
205215
skb_str = f'\n\t.skb = {skb_index},'

src/trace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ static void __print_trace_group(trace_group_t *group, int level)
6363
if (status & TRACE_INVALID)
6464
sprintf_end(buf, ",%s", PFMT_WARN_STR("invalid"));
6565

66+
if (trace->monitor)
67+
sprintf_end(buf, ",%s", PFMT_WARN_STR("monitor"));
68+
6669
/* skip the prefix of __trace_ */
6770
name = trace->prog + TRACE_PREFIX_LEN - 1;
6871
if (buf[0]) {

src/trace.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ children:
3434
msg: packet is dropped by GRO
3535
- name: enqueue_to_backlog:0
3636
analyzer: ret
37+
monitor: 1
3738
rules:
3839
- <<: *rule_ret_err
3940
msg: failed to enqeueu to CPU backlog
@@ -53,6 +54,7 @@ children:
5354
msg: packet is redirected by XDP program
5455
- name: xdp_do_generic_redirect:1
5556
analyzer: ret
57+
monitor: 1
5658
rules:
5759
- <<: *rule_ret_err
5860
msg: XDP failed to redirect skb
@@ -70,6 +72,7 @@ children:
7072
children:
7173
- name: __dev_queue_xmit:0
7274
analyzer: ret
75+
monitor: 1
7376
rules:
7477
- <<: *rule_ret_err
7578
msg: failed to queue packet to qdisc
@@ -80,6 +83,7 @@ children:
8083
msg: skb is successfully sent to the NIC driver
8184
- name: pfifo_enqueue
8285
analyzer: qdisc
86+
monitor: 1
8387
target: pfifo_enqueue
8488
rules:
8589
- exp: ne 0
@@ -165,6 +169,7 @@ children:
165169
cond: '[ $(verlte "$(uname -r)" "5.16") -eq -1 ]' # valid when kernel < 5.16
166170
backup: *ipt_do_table
167171
analyzer: iptable
172+
monitor: 1
168173
target: ipt_do_table
169174
rules:
170175
- exp: eq 0
@@ -192,6 +197,7 @@ children:
192197
msg: NAT happens (packet address will change)
193198
level: warn
194199
- name: nf_hook_slow
200+
monitor: 1
195201
analyzer: nf
196202
rules:
197203
- exp: eq -1
@@ -214,6 +220,8 @@ children:
214220
- tcp_packet:1
215221
- name: tcp_in_window:4
216222
analyzer: ret
223+
monitor: 1
224+
arg_count: 7
217225
rules:
218226
- exp: eq 0
219227
level: warn
@@ -326,6 +334,7 @@ children:
326334
adv: check your target tcp port
327335
- name: inet6_lookup_listener:2
328336
analyzer: ret
337+
monitor: 1
329338
rules:
330339
- exp: eq 0
331340
level: warn

0 commit comments

Comments
 (0)