Skip to content

Commit 451edb5

Browse files
committed
libbpf-tools: remove print_drop_reasons and add warn on parse failure
Remove print_drop_reasons function and replace its call with a warning message in main when parse_reason_enum fails. Signed-off-by: Zi Li <[email protected]> Signed-off-by: Amaindex <[email protected]>
1 parent 6af9933 commit 451edb5

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

libbpf-tools/tcpdrop.bpf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#include "tcpdrop.h"
2-
#include "vmlinux.h"
1+
#include <vmlinux.h>
2+
33
#include <bpf/bpf_core_read.h>
44
#include <bpf/bpf_endian.h>
55
#include <bpf/bpf_helpers.h>
66
#include <bpf/bpf_tracing.h>
77

8+
#include "tcpdrop.h"
9+
810
#ifndef AF_INET
911
#define AF_INET 2
1012
#endif

libbpf-tools/tcpdrop.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,6 @@ static int parse_reason_enum(void)
181181
return 0;
182182
}
183183

184-
static void print_drop_reasons(void)
185-
{
186-
if (!drop_reason_inited) {
187-
return;
188-
}
189-
190-
printf("Parsed drop reasons:\n");
191-
for (int i = 0; i <= drop_reason_max; i++) {
192-
printf(" ID: %d, Name: %s\n", i, drop_reasons[i]);
193-
}
194-
}
195-
196184
static const char *get_drop_reason_name(int reason)
197185
{
198186
if (reason >= 0 && reason <= drop_reason_max && drop_reason_inited)
@@ -399,8 +387,8 @@ int main(int argc, char **argv)
399387
}
400388

401389
parse_reason_enum();
402-
if (drop_reason_inited) {
403-
print_drop_reasons();
390+
if (!drop_reason_inited) {
391+
warn("Failed to parse drop reasons, some reasons may show as UNKNOWN.\n");
404392
}
405393

406394
rb = ring_buffer__new(bpf_map__fd(skel->maps.events), handle_event,

0 commit comments

Comments
 (0)