Merge pull request #29 from ifupdown-ng/feature/ifupdown2-keyword-rewrite

add compatibility with problematic ifupdown2 terms
This commit is contained in:
Maximilian Wilhelm 2020-08-19 10:21:56 +02:00 committed by GitHub
commit aa11601893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 6 deletions

View file

@ -20,8 +20,6 @@
#include "libifupdown/libifupdown.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
struct if_applet;
struct if_option {

View file

@ -16,9 +16,38 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#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 <word1>-<word*> and assume <word1> is an addon */

View file

@ -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

View file

@ -0,0 +1,7 @@
iface vrf-red
vrf-table 1
auto eth0
iface eth0
use dhcp
vrf vrf-red

View file

@ -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
}