Merge pull request #29 from ifupdown-ng/feature/ifupdown2-keyword-rewrite
add compatibility with problematic ifupdown2 terms
This commit is contained in:
commit
aa11601893
5 changed files with 58 additions and 6 deletions
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include "libifupdown/libifupdown.h"
|
#include "libifupdown/libifupdown.h"
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
|
|
||||||
|
|
||||||
struct if_applet;
|
struct if_applet;
|
||||||
|
|
||||||
struct if_option {
|
struct if_option {
|
||||||
|
|
|
@ -16,9 +16,38 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "libifupdown/interface-file.h"
|
#include "libifupdown/libifupdown.h"
|
||||||
#include "libifupdown/fgetline.h"
|
|
||||||
#include "libifupdown/tokenize.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
|
bool
|
||||||
lif_interface_file_parse(struct lif_dict *collection, const char *filename)
|
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)
|
else if (cur_iface != NULL)
|
||||||
{
|
{
|
||||||
|
token = maybe_remap_token(token);
|
||||||
|
|
||||||
lif_dict_add(&cur_iface->vars, token, strdup(bufp));
|
lif_dict_add(&cur_iface->vars, token, strdup(bufp));
|
||||||
|
|
||||||
/* Check if token looks like <word1>-<word*> and assume <word1> is an addon */
|
/* Check if token looks like <word1>-<word*> and assume <word1> is an addon */
|
||||||
|
|
|
@ -28,4 +28,8 @@
|
||||||
#include "libifupdown/lifecycle.h"
|
#include "libifupdown/lifecycle.h"
|
||||||
#include "libifupdown/tokenize.h"
|
#include "libifupdown/tokenize.h"
|
||||||
|
|
||||||
|
#ifndef ARRAY_SIZE
|
||||||
|
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
7
tests/fixtures/vrf-ifupdown2.interfaces
vendored
Normal file
7
tests/fixtures/vrf-ifupdown2.interfaces
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
iface vrf-red
|
||||||
|
vrf-table 1
|
||||||
|
|
||||||
|
auto eth0
|
||||||
|
iface eth0
|
||||||
|
use dhcp
|
||||||
|
vrf vrf-red
|
|
@ -19,7 +19,9 @@ tests_init \
|
||||||
inheritance_0 \
|
inheritance_0 \
|
||||||
inheritance_1 \
|
inheritance_1 \
|
||||||
implicit_vlan \
|
implicit_vlan \
|
||||||
vrf_dependency
|
vrf_dependency \
|
||||||
|
vrf_ifupdown2_rewrite \
|
||||||
|
vrf_ifupdown2_dependency
|
||||||
|
|
||||||
noargs_body() {
|
noargs_body() {
|
||||||
atf_check -s exit:1 -e ignore ifquery -S/dev/null
|
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" \
|
atf_check -s exit:0 -o match:"requires vrf-red" \
|
||||||
ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vrf.interfaces eth0
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue