From 73f3690432e128f43751ac170ec2fddeeae710bd Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Tue, 28 Jul 2020 22:39:20 +0200 Subject: [PATCH] Deduce which addons to 'use' from parameters names (closes #6) Signed-off-by: Maximilian Wilhelm --- libifupdown/interface-file.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libifupdown/interface-file.c b/libifupdown/interface-file.c index e8dd906..205c920 100644 --- a/libifupdown/interface-file.c +++ b/libifupdown/interface-file.c @@ -19,6 +19,7 @@ #include "libifupdown/interface-file.h" #include "libifupdown/fgetline.h" #include "libifupdown/tokenize.h" +#include "libifupdown/compar.h" bool lif_interface_file_parse(struct lif_dict *collection, const char *filename) @@ -138,6 +139,23 @@ lif_interface_file_parse(struct lif_dict *collection, const char *filename) else if (cur_iface != NULL) { lif_dict_add(&cur_iface->vars, token, strdup(bufp)); + + /* Check if token looks like - and assume is an addon */ + char *word_end = strchr(token, '-'); + if (word_end) + { + /* Copy word1 to not mangle *token */ + char *addon = strndup(token, word_end - token); + lif_dict_add_once(&cur_iface->vars, "use", addon, compar_str); + + /* pass requires as compatibility env vars to appropriate executors (bridge, bond) */ + if (!strcmp(addon, "dhcp")) + cur_iface->is_dhcp = true; + else if (!strcmp(addon, "bridge")) + cur_iface->is_bridge = true; + else if (!strcmp(addon, "bond")) + cur_iface->is_bond = true; + } } }