From e300867d26a78e48615aa80dc056845c5d0b1382 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Wed, 14 Oct 2020 02:44:00 -0600 Subject: [PATCH] ifquery: add ifquery --running this is like ifquery --state except it dumps only the running interface names --- cmd/ifquery.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/ifquery.c b/cmd/ifquery.c index 8455db0..1443b2e 100644 --- a/cmd/ifquery.c +++ b/cmd/ifquery.c @@ -158,6 +158,8 @@ list_interfaces(struct lif_dict *collection, struct match_options *opts) printf("}\n"); } +static bool listing = false, listing_stat = false, listing_running = false; + void list_state(struct lif_dict *state, struct match_options *opts) { @@ -176,12 +178,14 @@ list_state(struct lif_dict *state, struct match_options *opts) continue; struct lif_state_record *rec = entry->data; - printf("%s=%s %zu\n", entry->key, rec->mapped_if, rec->refcount); + + if (listing_running) + printf("%s\n", entry->key); + else + printf("%s=%s %zu\n", entry->key, rec->mapped_if, rec->refcount); } } -static bool listing = false, listing_stat = false; - static void set_listing(const char *opt_arg) { @@ -196,6 +200,13 @@ set_show_state(const char *opt_arg) listing_stat = true; } +static void +set_show_running(const char *opt_arg) +{ + (void) opt_arg; + listing_running = true; +} + static void set_pretty_print(const char *opt_arg) { @@ -217,6 +228,7 @@ set_property(const char *opt_arg) } static struct if_option local_options[] = { + {'r', "running", NULL, "show configured (running) interfaces", false, set_show_running}, {'s', "state", NULL, "show configured state", false, set_show_state}, {'p', "property", "property PROPERTY", "print values of properties matching PROPERTY", true, set_property}, {'D', "dot", NULL, "generate a dependency graph", false, set_output_dot}, @@ -257,7 +269,7 @@ ifquery_main(int argc, char *argv[]) } /* --list --state is not allowed */ - if (listing && listing_stat) + if (listing && (listing_stat || listing_running)) generic_usage(self_applet, EXIT_FAILURE); if (listing) @@ -265,7 +277,7 @@ ifquery_main(int argc, char *argv[]) list_interfaces(&collection, &match_opts); return EXIT_SUCCESS; } - else if (listing_stat) + else if (listing_stat || listing_running) { list_state(&state, &match_opts); return EXIT_SUCCESS;