interface: add config setting to restrict inheritance to template interfaces

This commit is contained in:
Ariadne Conill 2020-09-23 11:34:35 -06:00
parent a3987b46c8
commit 5c5c316ebf
4 changed files with 14 additions and 0 deletions

View file

@ -8,3 +8,10 @@
# compatibility with legacy setups, and may be disabled for performance # compatibility with legacy setups, and may be disabled for performance
# improvements in setups where only ifupdown-ng executors are used. # improvements in setups where only ifupdown-ng executors are used.
allow_addon_scripts = 1 allow_addon_scripts = 1
# allow_any_iface_as_template:
# Enable any interface to act as a template for another interface.
# This is presently the default, but is deprecated. An admin may choose
# to disable this setting in order to require inheritance from specified
# templates.
allow_any_iface_as_template = 1

View file

@ -20,6 +20,7 @@
struct lif_config_file lif_config = { struct lif_config_file lif_config = {
.allow_addon_scripts = true, .allow_addon_scripts = true,
.allow_any_iface_as_template = true,
}; };
static bool static bool
@ -43,6 +44,7 @@ set_bool_value(const char *key, const char *value, void *opaque)
static struct lif_config_handler handlers[] = { static struct lif_config_handler handlers[] = {
{"allow_addon_scripts", set_bool_value, &lif_config.allow_addon_scripts}, {"allow_addon_scripts", set_bool_value, &lif_config.allow_addon_scripts},
{"allow_any_iface_as_template", set_bool_value, &lif_config.allow_any_iface_as_template},
}; };
bool bool

View file

@ -20,6 +20,7 @@
struct lif_config_file { struct lif_config_file {
bool allow_addon_scripts; bool allow_addon_scripts;
bool allow_any_iface_as_template;
}; };
extern struct lif_config_file lif_config; extern struct lif_config_file lif_config;

View file

@ -16,6 +16,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "libifupdown/interface.h" #include "libifupdown/interface.h"
#include "libifupdown/config-file.h"
bool bool
lif_address_parse(struct lif_address *address, const char *presentation) lif_address_parse(struct lif_address *address, const char *presentation)
@ -239,6 +240,9 @@ lif_interface_collection_inherit(struct lif_interface *interface, struct lif_dic
if (parent == NULL) if (parent == NULL)
return false; return false;
if (!lif_config.allow_any_iface_as_template && !parent->is_template)
return false;
lif_dict_add(&interface->vars, "inherit", strdup(ifname)); lif_dict_add(&interface->vars, "inherit", strdup(ifname));
interface->is_bond = parent->is_bond; interface->is_bond = parent->is_bond;
interface->is_bridge = parent->is_bridge; interface->is_bridge = parent->is_bridge;