From aa01b5368dc25a2b1bb9ee6b1718e7e1ad08765f Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Mon, 26 Mar 2018 06:37:16 +0200 Subject: [PATCH] bpf: print fields that interpreted as pointers using printaddr64 * bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_ELEM), BEGIN_BPF_CMD_DECODER(BPF_MAP_UPDATE_ELEM)): Print key and value fields using PRINT_FIELD_ADDR64. (BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_ELEM)): Print key field using PRINT_FIELD_ADDR64. (BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_NEXT_KEY)): Print key and next_key field using PRINT_FIELD_ADDR64. (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Print insns and log_buf fields using PRINT_FIELD_ADDR64. (BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN)): Print data_in and data_out fields using PRINT_FIELD_ADDR64. * tests/bpf.c: Update expected output. --- bpf.c | 22 +++++++++++----------- tests/bpf.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bpf.c b/bpf.c index 6b602b72..59826dec 100644 --- a/bpf.c +++ b/bpf.c @@ -188,16 +188,16 @@ END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD) BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_ELEM) { PRINT_FIELD_FD("{", attr, map_fd, tcp); - PRINT_FIELD_X(", ", attr, key); - PRINT_FIELD_X(", ", attr, value); + PRINT_FIELD_ADDR64(", ", attr, key); + PRINT_FIELD_ADDR64(", ", attr, value); } END_BPF_CMD_DECODER(RVAL_DECODED) BEGIN_BPF_CMD_DECODER(BPF_MAP_UPDATE_ELEM) { PRINT_FIELD_FD("{", attr, map_fd, tcp); - PRINT_FIELD_X(", ", attr, key); - PRINT_FIELD_X(", ", attr, value); + PRINT_FIELD_ADDR64(", ", attr, key); + PRINT_FIELD_ADDR64(", ", attr, value); PRINT_FIELD_XVAL(", ", attr, flags, bpf_map_update_elem_flags, "BPF_???"); } @@ -206,15 +206,15 @@ END_BPF_CMD_DECODER(RVAL_DECODED) BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_ELEM) { PRINT_FIELD_FD("{", attr, map_fd, tcp); - PRINT_FIELD_X(", ", attr, key); + PRINT_FIELD_ADDR64(", ", attr, key); } END_BPF_CMD_DECODER(RVAL_DECODED) BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_NEXT_KEY) { PRINT_FIELD_FD("{", attr, map_fd, tcp); - PRINT_FIELD_X(", ", attr, key); - PRINT_FIELD_X(", ", attr, next_key); + PRINT_FIELD_ADDR64(", ", attr, key); + PRINT_FIELD_ADDR64(", ", attr, next_key); } END_BPF_CMD_DECODER(RVAL_DECODED) @@ -223,7 +223,7 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD) PRINT_FIELD_XVAL("{", attr, prog_type, bpf_prog_types, "BPF_PROG_TYPE_???"); PRINT_FIELD_U(", ", attr, insn_cnt); - PRINT_FIELD_X(", ", attr, insns); + PRINT_FIELD_ADDR64(", ", attr, insns); tprintf(", license="); print_big_u64_addr(attr.license); @@ -234,7 +234,7 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD) break; PRINT_FIELD_U(", ", attr, log_level); PRINT_FIELD_U(", ", attr, log_size); - PRINT_FIELD_X(", ", attr, log_buf); + PRINT_FIELD_ADDR64(", ", attr, log_buf); /* kern_version field was added in Linux commit v4.1-rc1~84^2~50. */ if (len <= offsetof(struct BPF_PROG_LOAD_struct, kern_version)) @@ -309,8 +309,8 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN) PRINT_FIELD_U(", ", attr, retval); PRINT_FIELD_U(", ", attr, data_size_in); PRINT_FIELD_U(", ", attr, data_size_out); - PRINT_FIELD_X(", ", attr, data_in); - PRINT_FIELD_X(", ", attr, data_out); + PRINT_FIELD_ADDR64(", ", attr, data_in); + PRINT_FIELD_ADDR64(", ", attr, data_out); PRINT_FIELD_U(", ", attr, repeat); PRINT_FIELD_U(", ", attr, duration); tprints("}"); diff --git a/tests/bpf.c b/tests/bpf.c index 00cf8fed..16625a4e 100644 --- a/tests/bpf.c +++ b/tests/bpf.c @@ -392,7 +392,7 @@ static const struct bpf_attr_check BPF_MAP_LOOKUP_ELEM_checks[] = { { .data = { .BPF_MAP_LOOKUP_ELEM_data = { .map_fd = -1 } }, .size = offsetofend(struct BPF_MAP_LOOKUP_ELEM_struct, map_fd), - .str = "map_fd=-1, key=0, value=0" + .str = "map_fd=-1, key=NULL, value=NULL" }, { .data = { .BPF_MAP_LOOKUP_ELEM_data = { @@ -409,7 +409,7 @@ static const struct bpf_attr_check BPF_MAP_UPDATE_ELEM_checks[] = { { .data = { .BPF_MAP_UPDATE_ELEM_data = { .map_fd = -1 } }, .size = offsetofend(struct BPF_MAP_UPDATE_ELEM_struct, map_fd), - .str = "map_fd=-1, key=0, value=0, flags=BPF_ANY" + .str = "map_fd=-1, key=NULL, value=NULL, flags=BPF_ANY" }, { .data = { .BPF_MAP_UPDATE_ELEM_data = { @@ -428,7 +428,7 @@ static const struct bpf_attr_check BPF_MAP_DELETE_ELEM_checks[] = { { .data = { .BPF_MAP_DELETE_ELEM_data = { .map_fd = -1 } }, .size = offsetofend(struct BPF_MAP_DELETE_ELEM_struct, map_fd), - .str = "map_fd=-1, key=0" + .str = "map_fd=-1, key=NULL" }, { .data = { .BPF_MAP_DELETE_ELEM_data = { @@ -444,7 +444,7 @@ static const struct bpf_attr_check BPF_MAP_GET_NEXT_KEY_checks[] = { { .data = { .BPF_MAP_GET_NEXT_KEY_data = { .map_fd = -1 } }, .size = offsetofend(struct BPF_MAP_GET_NEXT_KEY_struct, map_fd), - .str = "map_fd=-1, key=0, next_key=0" + .str = "map_fd=-1, key=NULL, next_key=NULL" }, { .data = { .BPF_MAP_GET_NEXT_KEY_data = { @@ -512,7 +512,7 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = { .data = { .BPF_PROG_LOAD_data = { .prog_type = 1 } }, .size = offsetofend(struct BPF_PROG_LOAD_struct, prog_type), .str = "prog_type=BPF_PROG_TYPE_SOCKET_FILTER" - ", insn_cnt=0, insns=0, license=NULL" + ", insn_cnt=0, insns=NULL, license=NULL" }, { /* 1 */ .data = { .BPF_PROG_LOAD_data = { @@ -528,8 +528,8 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = { } }, .size = offsetofend(struct BPF_PROG_LOAD_struct, prog_flags), .str = "prog_type=0x10 /* BPF_PROG_TYPE_??? */" - ", insn_cnt=3134983661, insns=0, license=NULL" - ", log_level=42, log_size=3141592653, log_buf=0" + ", insn_cnt=3134983661, insns=NULL, license=NULL" + ", log_level=42, log_size=3141592653, log_buf=NULL" ", kern_version=KERNEL_VERSION(51966, 240, 13)" ", prog_flags=0", }, @@ -688,7 +688,7 @@ static const struct bpf_attr_check BPF_PROG_TEST_RUN_checks[] = { .data = { .BPF_PROG_TEST_RUN_data = { .prog_fd = -1 } }, .size = offsetofend(struct BPF_PROG_TEST_RUN_struct, prog_fd), .str = "test={prog_fd=-1, retval=0, data_size_in=0" - ", data_size_out=0, data_in=0, data_out=0" + ", data_size_out=0, data_in=NULL, data_out=NULL" ", repeat=0, duration=0}" }, {