diff --git a/cmd/multicall.h b/cmd/multicall.h index bd7cf7d..647e0ba 100644 --- a/cmd/multicall.h +++ b/cmd/multicall.h @@ -20,8 +20,6 @@ #include "libifupdown/libifupdown.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x)) - struct if_applet; struct if_option { diff --git a/libifupdown/interface-file.c b/libifupdown/interface-file.c index 74d74c1..b59ca8a 100644 --- a/libifupdown/interface-file.c +++ b/libifupdown/interface-file.c @@ -16,9 +16,38 @@ #include #include #include -#include "libifupdown/interface-file.h" -#include "libifupdown/fgetline.h" -#include "libifupdown/tokenize.h" +#include "libifupdown/libifupdown.h" + +/* internally rewrite problematic ifupdown2 tokens to ifupdown-ng equivalents */ +struct remap_token { + const char *token; + const char *alternative; +}; + +static const struct remap_token tokens[] = { + {"vrf", "vrf-member"} +}; + +static int +token_cmp(const void *a, const void *b) +{ + const char *key = a; + const struct remap_token *token = b; + + return strcmp(key, token->token); +} + +static char * +maybe_remap_token(const char *token) +{ + const struct remap_token *tok = NULL; + static char tokbuf[4096]; + + tok = bsearch(token, tokens, ARRAY_SIZE(tokens), sizeof(*tokens), token_cmp); + strlcpy(tokbuf, tok != NULL ? tok->alternative : token, sizeof tokbuf); + + return tokbuf; +} bool lif_interface_file_parse(struct lif_dict *collection, const char *filename) @@ -167,6 +196,8 @@ lif_interface_file_parse(struct lif_dict *collection, const char *filename) } else if (cur_iface != NULL) { + token = maybe_remap_token(token); + lif_dict_add(&cur_iface->vars, token, strdup(bufp)); /* Check if token looks like - and assume is an addon */ diff --git a/libifupdown/libifupdown.h b/libifupdown/libifupdown.h index 87cc5fd..33da802 100644 --- a/libifupdown/libifupdown.h +++ b/libifupdown/libifupdown.h @@ -28,4 +28,8 @@ #include "libifupdown/lifecycle.h" #include "libifupdown/tokenize.h" +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x)) +#endif + #endif diff --git a/tests/fixtures/vrf-ifupdown2.interfaces b/tests/fixtures/vrf-ifupdown2.interfaces new file mode 100644 index 0000000..242cba5 --- /dev/null +++ b/tests/fixtures/vrf-ifupdown2.interfaces @@ -0,0 +1,7 @@ +iface vrf-red + vrf-table 1 + +auto eth0 +iface eth0 + use dhcp + vrf vrf-red diff --git a/tests/ifquery_test b/tests/ifquery_test index 0b557d7..f6afe13 100755 --- a/tests/ifquery_test +++ b/tests/ifquery_test @@ -19,7 +19,9 @@ tests_init \ inheritance_0 \ inheritance_1 \ implicit_vlan \ - vrf_dependency + vrf_dependency \ + vrf_ifupdown2_rewrite \ + vrf_ifupdown2_dependency noargs_body() { atf_check -s exit:1 -e ignore ifquery -S/dev/null @@ -118,3 +120,13 @@ vrf_dependency_body() { atf_check -s exit:0 -o match:"requires vrf-red" \ ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vrf.interfaces eth0 } + +vrf_ifupdown2_rewrite_body() { + atf_check -s exit:0 -o match:"vrf-member vrf-red" \ + ifquery -E $EXECUTORS -i $FIXTURES/vrf-ifupdown2.interfaces eth0 +} + +vrf_ifupdown2_dependency_body() { + atf_check -s exit:0 -o match:"requires vrf-red" \ + ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vrf-ifupdown2.interfaces eth0 +}