Merge pull request #124 from ifupdown-ng/feature/ifquery-virtual

Feature/ifquery virtual
This commit is contained in:
Maximilian Wilhelm 2020-11-04 20:40:56 +01:00 committed by GitHub
commit 748a226786
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -159,6 +159,7 @@ list_interfaces(struct lif_dict *collection, struct match_options *opts)
}
static bool listing = false, listing_stat = false, listing_running = false;
static bool allow_undefined = false;
void
list_state(struct lif_dict *state, struct match_options *opts)
@ -228,6 +229,13 @@ set_property(const char *opt_arg)
match_opts.property = opt_arg;
}
static void
set_allow_undefined(const char *opt_arg)
{
(void) opt_arg;
allow_undefined = true;
}
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},
@ -235,6 +243,7 @@ static struct if_option local_options[] = {
{'D', "dot", NULL, "generate a dependency graph", false, set_output_dot},
{'L', "list", NULL, "list matching interfaces", false, set_listing},
{'P', "pretty-print", NULL, "pretty print the interfaces instead of just listing", false, set_pretty_print},
{'U', "allow-undefined", NULL, "allow querying undefined (virtual) interfaces", false, set_allow_undefined},
};
static struct if_option_group local_option_group = {
@ -307,6 +316,9 @@ ifquery_main(int argc, char *argv[])
if (entry != NULL)
iface = entry->data;
if (entry == NULL && allow_undefined)
iface = lif_interface_collection_find(&collection, argv[idx]);
}
if (iface == NULL)

View file

@ -54,6 +54,11 @@ configuration file to the current format.
When listing interfaces, print their configuration in a format
that is compatible with *interfaces*(5) files.
*-U, --allow-undefined*
Create virtual interfaces for any interfaces not explicitly
defined in the configuration file. This is primarily useful
for property queries.
*-S, --state-file* _FILE_
Use _FILE_ as the state database.

View file

@ -34,7 +34,9 @@ tests_init \
vlan_explicit_learned_dependency \
vlan_guessed_learned_dependency \
vlan_complex_learned_dependency \
wireguard
wireguard \
allow_undefined_positive \
allow_undefined_negative
noargs_body() {
atf_check -s exit:1 -e ignore ifquery -S/dev/null
@ -226,3 +228,17 @@ wireguard_body() {
-o match:"use wireguard" \
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/wireguard.interfaces wg0
}
allow_undefined_positive_body() {
atf_check -s exit:0 \
-o ignore \
-e ignore \
ifquery -U -i /dev/null -p address foo
}
allow_undefined_negative_body() {
atf_check -s exit:1 \
-o ignore \
-e ignore \
ifquery -i /dev/null -p address foo
}