Merge pull request #83 from ifupdown-ng/feature/alias-keywords-for-iface
inherit/template system improvements
This commit is contained in:
commit
d177bfa553
10 changed files with 61 additions and 5 deletions
|
@ -30,7 +30,7 @@ print_interface(struct lif_interface *iface)
|
|||
if (iface->is_auto)
|
||||
printf("auto %s\n", iface->ifname);
|
||||
|
||||
printf("iface %s\n", iface->ifname);
|
||||
printf("%s %s\n", iface->is_template ? "template" : "iface", iface->ifname);
|
||||
|
||||
struct lif_node *iter;
|
||||
LIF_DICT_FOREACH(iter, &iface->vars)
|
||||
|
|
|
@ -96,6 +96,12 @@ acquire_state_lock(const char *state_path, const char *lifname)
|
|||
bool
|
||||
skip_interface(struct lif_interface *iface, const char *ifname)
|
||||
{
|
||||
if (iface->is_template)
|
||||
{
|
||||
fprintf(stderr, "%s: cannot change state on %s (template interface)\n", argv0, ifname);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (exec_opts.force)
|
||||
return false;
|
||||
|
||||
|
|
15
dist/ifupdown-ng.conf.example
vendored
15
dist/ifupdown-ng.conf.example
vendored
|
@ -8,3 +8,18 @@
|
|||
# compatibility with legacy setups, and may be disabled for performance
|
||||
# improvements in setups where only ifupdown-ng executors are used.
|
||||
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
|
||||
|
||||
# implicit_template_conversion:
|
||||
# In some legacy configs, a template may be declared as an iface, and
|
||||
# ifupdown-ng automatically converts those declarations to a proper
|
||||
# template. If this setting is disabled, inheritance will continue to
|
||||
# work against non-template interfaces without converting them to a
|
||||
# template.
|
||||
implicit_template_conversion = 1
|
||||
|
|
|
@ -47,6 +47,10 @@ with an address of *203.0.113.2* and gateway of *203.0.113.1*.
|
|||
associated with the declaration will be stored inside
|
||||
_object_.
|
||||
|
||||
*template* _object_
|
||||
Begins a new declaration for _object_, like *iface*, except
|
||||
that _object_ is defined as a *template*.
|
||||
|
||||
# SUPPORTED KEYWORDS FOR OBJECT TRIPLES
|
||||
|
||||
Any keyword may be used inside an interface declaration block, but
|
||||
|
@ -79,9 +83,10 @@ the system will only respond to certain keywords by default:
|
|||
Interfaces associated with the parent are taken down at
|
||||
the same time as the parent.
|
||||
|
||||
*inherit* _interface_
|
||||
Designates that the parent interface should inherit
|
||||
configuration data from _interface_.
|
||||
*inherit* _object_
|
||||
Designates that the configured interface should inherit
|
||||
configuration data from _object_. Normally _object_
|
||||
must be a *template*.
|
||||
|
||||
*use* _option_
|
||||
Designates that an option should be used. See _OPTIONS_
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
struct lif_config_file lif_config = {
|
||||
.allow_addon_scripts = true,
|
||||
.allow_any_iface_as_template = true,
|
||||
};
|
||||
|
||||
static bool
|
||||
|
@ -43,6 +44,8 @@ set_bool_value(const char *key, const char *value, void *opaque)
|
|||
|
||||
static struct lif_config_handler handlers[] = {
|
||||
{"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},
|
||||
{"implicit_template_conversion", set_bool_value, &lif_config.implicit_template_conversion},
|
||||
};
|
||||
|
||||
bool
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
struct lif_config_file {
|
||||
bool allow_addon_scripts;
|
||||
bool allow_any_iface_as_template;
|
||||
bool implicit_template_conversion;
|
||||
};
|
||||
|
||||
extern struct lif_config_file lif_config;
|
||||
|
|
|
@ -162,7 +162,9 @@ handle_auto(struct lif_dict *collection, const char *filename, size_t lineno, ch
|
|||
return false;
|
||||
}
|
||||
|
||||
cur_iface->is_auto = true;
|
||||
if (!cur_iface->is_template)
|
||||
cur_iface->is_auto = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -236,6 +238,15 @@ handle_iface(struct lif_dict *collection, const char *filename, size_t lineno, c
|
|||
return false;
|
||||
}
|
||||
|
||||
/* mark the cur_iface as a template iface if `template` keyword
|
||||
* is used.
|
||||
*/
|
||||
if (!strcmp(token, "template"))
|
||||
{
|
||||
cur_iface->is_auto = false;
|
||||
cur_iface->is_template = true;
|
||||
}
|
||||
|
||||
/* in original ifupdown config, we can have "inet loopback"
|
||||
* or "inet dhcp" or such to designate hints. lets pick up
|
||||
* those hints here.
|
||||
|
@ -336,7 +347,9 @@ static const struct parser_keyword keywords[] = {
|
|||
{"gateway", handle_gateway},
|
||||
{"iface", handle_iface},
|
||||
{"inherit", handle_inherit},
|
||||
{"interface", handle_iface},
|
||||
{"source", handle_source},
|
||||
{"template", handle_iface},
|
||||
{"use", handle_use},
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "libifupdown/interface.h"
|
||||
#include "libifupdown/config-file.h"
|
||||
|
||||
bool
|
||||
lif_address_parse(struct lif_address *address, const char *presentation)
|
||||
|
@ -239,6 +240,13 @@ lif_interface_collection_inherit(struct lif_interface *interface, struct lif_dic
|
|||
if (parent == NULL)
|
||||
return false;
|
||||
|
||||
if (!lif_config.allow_any_iface_as_template && !parent->is_template)
|
||||
return false;
|
||||
|
||||
/* maybe convert any interface we are inheriting from into a template */
|
||||
if (lif_config.implicit_template_conversion)
|
||||
parent->is_template = true;
|
||||
|
||||
lif_dict_add(&interface->vars, "inherit", strdup(ifname));
|
||||
interface->is_bond = parent->is_bond;
|
||||
interface->is_bridge = parent->is_bridge;
|
||||
|
|
|
@ -50,6 +50,7 @@ struct lif_interface {
|
|||
bool is_auto;
|
||||
bool is_bridge;
|
||||
bool is_bond;
|
||||
bool is_template;
|
||||
|
||||
struct lif_dict vars;
|
||||
|
||||
|
|
|
@ -341,6 +341,9 @@ handle_dependents(const struct lif_execute_opts *opts, struct lif_interface *par
|
|||
bool
|
||||
lif_lifecycle_run(const struct lif_execute_opts *opts, struct lif_interface *iface, struct lif_dict *collection, struct lif_dict *state, const char *lifname, bool up)
|
||||
{
|
||||
if (iface->is_template)
|
||||
return false;
|
||||
|
||||
if (lifname == NULL)
|
||||
lifname = iface->ifname;
|
||||
|
||||
|
|
Loading…
Reference in a new issue