diff options
author | Quentin Monnet <quentin.monnet@netronome.com> | 2017-10-19 18:46:19 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-10-21 21:11:31 -0400 |
commit | 9cbe1f581d17baff7e93936feb041c90b29eb6a8 (patch) | |
tree | 340bf4f384d93493c7e618f600a0706221a17db9 | |
parent | f3ae608edb3be2e9a3f668d47aced3553eaf6c14 (diff) |
tools: bpftool: add pointer to file argument to print_hex()
Make print_hex() able to print to any file instead of standard output
only, and rename it to fprint_hex(). The function can now be called with
the info() macro, for example, without splitting the output between
standard and error outputs.
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | tools/bpf/bpftool/main.c | 8 | ||||
-rw-r--r-- | tools/bpf/bpftool/main.h | 2 | ||||
-rw-r--r-- | tools/bpf/bpftool/map.c | 20 | ||||
-rw-r--r-- | tools/bpf/bpftool/prog.c | 4 |
4 files changed, 17 insertions, 17 deletions
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index e02d00d6e00b..8662199ee050 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c | |||
@@ -100,7 +100,7 @@ bool is_prefix(const char *pfx, const char *str) | |||
100 | return !memcmp(str, pfx, strlen(pfx)); | 100 | return !memcmp(str, pfx, strlen(pfx)); |
101 | } | 101 | } |
102 | 102 | ||
103 | void print_hex(void *arg, unsigned int n, const char *sep) | 103 | void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep) |
104 | { | 104 | { |
105 | unsigned char *data = arg; | 105 | unsigned char *data = arg; |
106 | unsigned int i; | 106 | unsigned int i; |
@@ -111,13 +111,13 @@ void print_hex(void *arg, unsigned int n, const char *sep) | |||
111 | if (!i) | 111 | if (!i) |
112 | /* nothing */; | 112 | /* nothing */; |
113 | else if (!(i % 16)) | 113 | else if (!(i % 16)) |
114 | printf("\n"); | 114 | fprintf(f, "\n"); |
115 | else if (!(i % 8)) | 115 | else if (!(i % 8)) |
116 | printf(" "); | 116 | fprintf(f, " "); |
117 | else | 117 | else |
118 | pfx = sep; | 118 | pfx = sep; |
119 | 119 | ||
120 | printf("%s%02hhx", i ? pfx : "", data[i]); | 120 | fprintf(f, "%s%02hhx", i ? pfx : "", data[i]); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index 844e4ef6db56..41e6c7d3fcad 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h | |||
@@ -67,7 +67,7 @@ enum bpf_obj_type { | |||
67 | extern const char *bin_name; | 67 | extern const char *bin_name; |
68 | 68 | ||
69 | bool is_prefix(const char *pfx, const char *str); | 69 | bool is_prefix(const char *pfx, const char *str); |
70 | void print_hex(void *arg, unsigned int n, const char *sep); | 70 | void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); |
71 | void usage(void) __attribute__((noreturn)); | 71 | void usage(void) __attribute__((noreturn)); |
72 | 72 | ||
73 | struct cmd { | 73 | struct cmd { |
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 0528a5379e6c..b1dad76215ed 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c | |||
@@ -216,12 +216,12 @@ static void print_entry(struct bpf_map_info *info, unsigned char *key, | |||
216 | !break_names; | 216 | !break_names; |
217 | 217 | ||
218 | printf("key:%c", break_names ? '\n' : ' '); | 218 | printf("key:%c", break_names ? '\n' : ' '); |
219 | print_hex(key, info->key_size, " "); | 219 | fprint_hex(stdout, key, info->key_size, " "); |
220 | 220 | ||
221 | printf(single_line ? " " : "\n"); | 221 | printf(single_line ? " " : "\n"); |
222 | 222 | ||
223 | printf("value:%c", break_names ? '\n' : ' '); | 223 | printf("value:%c", break_names ? '\n' : ' '); |
224 | print_hex(value, info->value_size, " "); | 224 | fprint_hex(stdout, value, info->value_size, " "); |
225 | 225 | ||
226 | printf("\n"); | 226 | printf("\n"); |
227 | } else { | 227 | } else { |
@@ -230,13 +230,13 @@ static void print_entry(struct bpf_map_info *info, unsigned char *key, | |||
230 | n = get_possible_cpus(); | 230 | n = get_possible_cpus(); |
231 | 231 | ||
232 | printf("key:\n"); | 232 | printf("key:\n"); |
233 | print_hex(key, info->key_size, " "); | 233 | fprint_hex(stdout, key, info->key_size, " "); |
234 | printf("\n"); | 234 | printf("\n"); |
235 | for (i = 0; i < n; i++) { | 235 | for (i = 0; i < n; i++) { |
236 | printf("value (CPU %02d):%c", | 236 | printf("value (CPU %02d):%c", |
237 | i, info->value_size > 16 ? '\n' : ' '); | 237 | i, info->value_size > 16 ? '\n' : ' '); |
238 | print_hex(value + i * info->value_size, | 238 | fprint_hex(stdout, value + i * info->value_size, |
239 | info->value_size, " "); | 239 | info->value_size, " "); |
240 | printf("\n"); | 240 | printf("\n"); |
241 | } | 241 | } |
242 | } | 242 | } |
@@ -492,8 +492,8 @@ static int do_dump(int argc, char **argv) | |||
492 | print_entry(&info, key, value); | 492 | print_entry(&info, key, value); |
493 | } else { | 493 | } else { |
494 | info("can't lookup element with key: "); | 494 | info("can't lookup element with key: "); |
495 | print_hex(key, info.key_size, " "); | 495 | fprint_hex(stderr, key, info.key_size, " "); |
496 | printf("\n"); | 496 | fprintf(stderr, "\n"); |
497 | } | 497 | } |
498 | 498 | ||
499 | prev_key = key; | 499 | prev_key = key; |
@@ -587,7 +587,7 @@ static int do_lookup(int argc, char **argv) | |||
587 | print_entry(&info, key, value); | 587 | print_entry(&info, key, value); |
588 | } else if (errno == ENOENT) { | 588 | } else if (errno == ENOENT) { |
589 | printf("key:\n"); | 589 | printf("key:\n"); |
590 | print_hex(key, info.key_size, " "); | 590 | fprint_hex(stdout, key, info.key_size, " "); |
591 | printf("\n\nNot found\n"); | 591 | printf("\n\nNot found\n"); |
592 | } else { | 592 | } else { |
593 | err("lookup failed: %s\n", strerror(errno)); | 593 | err("lookup failed: %s\n", strerror(errno)); |
@@ -642,14 +642,14 @@ static int do_getnext(int argc, char **argv) | |||
642 | 642 | ||
643 | if (key) { | 643 | if (key) { |
644 | printf("key:\n"); | 644 | printf("key:\n"); |
645 | print_hex(key, info.key_size, " "); | 645 | fprint_hex(stdout, key, info.key_size, " "); |
646 | printf("\n"); | 646 | printf("\n"); |
647 | } else { | 647 | } else { |
648 | printf("key: None\n"); | 648 | printf("key: None\n"); |
649 | } | 649 | } |
650 | 650 | ||
651 | printf("next key:\n"); | 651 | printf("next key:\n"); |
652 | print_hex(nextkey, info.key_size, " "); | 652 | fprint_hex(stdout, nextkey, info.key_size, " "); |
653 | printf("\n"); | 653 | printf("\n"); |
654 | 654 | ||
655 | exit_free: | 655 | exit_free: |
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index d60f5307b6e2..aa6d72ea3807 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c | |||
@@ -224,7 +224,7 @@ static int show_prog(int fd) | |||
224 | printf("name %s ", info.name); | 224 | printf("name %s ", info.name); |
225 | 225 | ||
226 | printf("tag "); | 226 | printf("tag "); |
227 | print_hex(info.tag, BPF_TAG_SIZE, ""); | 227 | fprint_hex(stdout, info.tag, BPF_TAG_SIZE, ""); |
228 | printf("\n"); | 228 | printf("\n"); |
229 | 229 | ||
230 | if (info.load_time) { | 230 | if (info.load_time) { |
@@ -319,7 +319,7 @@ static void dump_xlated(void *buf, unsigned int len, bool opcodes) | |||
319 | 319 | ||
320 | if (opcodes) { | 320 | if (opcodes) { |
321 | printf(" "); | 321 | printf(" "); |
322 | print_hex(insn + i, 8, " "); | 322 | fprint_hex(stdout, insn + i, 8, " "); |
323 | printf("\n"); | 323 | printf("\n"); |
324 | } | 324 | } |
325 | 325 | ||