From d92109b3c88d6c65cd8e12ceb8ca0b7a46eb2cb9 Mon Sep 17 00:00:00 2001 From: Simon Sundberg Date: Thu, 6 May 2021 15:36:25 +0200 Subject: [PATCH] pping: Replace -j and -m options with -F/--format The format option can take the values "standard" (default), "json" and ppviz (new name for "machine-friendly"). Signed-off-by: Simon Sundberg --- pping/pping.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pping/pping.c b/pping/pping.c index 9ae69f2..5cbc2d3 100644 --- a/pping/pping.c +++ b/pping/pping.c @@ -78,7 +78,7 @@ struct pping_config { int ifindex; char ifname[IF_NAMESIZE]; bool json_format; - bool machine_format; + bool ppviz_format; bool force; }; @@ -91,8 +91,7 @@ static const struct option long_options[] = { { "rate-limit", required_argument, NULL, 'r' }, // Sampling rate-limit in ms { "force", no_argument, NULL, 'f' }, // Detach any existing XDP program on interface { "cleanup-interval", required_argument, NULL, 'c' }, // Map cleaning interval in s - { "json", no_argument, NULL, 'j' }, // Output in JSON format - { "machine-friendly", no_argument, NULL, 'm' }, // Ouput in Kathie's "machine friendly" format + { "format", required_argument, NULL, 'F' }, // Which format to output in (standard/json/ppviz) { 0, 0, NULL, 0 } }; @@ -143,8 +142,11 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config) double rate_limit_ms, cleanup_interval_s; config->ifindex = 0; + config->force = false; + config->json_format = false; + config->ppviz_format = false; - while ((opt = getopt_long(argc, argv, "hfjmi:r:c:", long_options, + while ((opt = getopt_long(argc, argv, "hfi:r:c:F:", long_options, NULL)) != -1) { switch (opt) { case 'i': @@ -181,11 +183,15 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config) config->cleanup_interval = cleanup_interval_s * NS_PER_SECOND; break; - case 'j': - config->json_format = true; - break; - case 'm': - config->machine_format = true; + case 'F': + if (strcmp(optarg, "json") == 0) { + config->json_format = true; + } else if (strcmp(optarg, "ppviz") == 0) { + config->ppviz_format = true; + } else if (strcmp(optarg, "standard") != 0) { + fprintf(stderr, "format must be \"standard\", \"json\" or \"ppviz\"\n"); + return -EINVAL; + } break; case 'f': config->force = true; @@ -493,7 +499,7 @@ static int format_ip_address(int af, const struct in6_addr *addr, char *buf, return -EINVAL; } -static char *proto_to_str(__u16 proto) +static const char *proto_to_str(__u16 proto) { static char buf[8]; @@ -530,7 +536,8 @@ static void print_rtt_event_standard(void *ctx, int cpu, void *data, ntohs(e->flow.saddr.port), daddr, ntohs(e->flow.daddr.port)); } -static void print_rtt_event_mf(void *ctx, int cpu, void *data, __u32 data_size) +static void print_rtt_event_ppviz(void *ctx, int cpu, void *data, + __u32 data_size) { const struct rtt_event *e = data; char saddr[INET6_ADDRSTRLEN]; @@ -708,9 +715,6 @@ int main(int argc, char *argv[]) .flow_map = "flow_state", .rtt_map = "rtt_events", .xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST, - .json_format = false, - .machine_format = false, - .force = false, }; struct perf_buffer *pb = NULL; @@ -741,12 +745,10 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (config.json_format && config.machine_format) - fprintf(stderr, "Cannot output in both JSON and \"machine-friendly\" format, will use JSON\n"); if (config.json_format) pb_opts.sample_cb = print_rtt_event_json; - else if (config.machine_format) - pb_opts.sample_cb = print_rtt_event_mf; + else if (config.ppviz_format) + pb_opts.sample_cb = print_rtt_event_ppviz; err = load_attach_bpfprogs(&obj, &config, &tc_attached, &xdp_attached); if (err) {