Skip to content

Commit

Permalink
Merge branch 'policy_null' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
wipawel committed May 19, 2015
2 parents 08eb8f0 + 5ac8098 commit 7dc8e61
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 25 deletions.
20 changes: 4 additions & 16 deletions client/ifup.c
Expand Up @@ -55,32 +55,20 @@ struct ni_nanny_fsm_monitor {
static xml_node_t *
__ni_ifup_generate_match_dev(xml_node_t *node, ni_ifworker_t *w)
{
ni_netdev_t *dev;
ni_iftype_t iftype;
const char *type;

if (!node || !w || ni_string_empty(w->name))
return NULL;

/* Conditional <link-type> generation */
{
/* TODO: the type has to be from config, _not_ from device
* (dev is probably a not ready one just using our name),
* but this info is lost in translation... isn't it?
*/
if (!(dev = w->device) || !ni_string_eq(w->name, dev->name))
goto skip;

if (dev->link.type == NI_IFTYPE_UNKNOWN)
goto skip;

type = ni_linktype_type_to_name(dev->link.type);
if (ni_string_empty(type))
goto skip;
iftype = ni_ifworker_iftype_from_xml(w->config.node);
type = ni_linktype_type_to_name(iftype);

if (iftype != NI_IFTYPE_UNKNOWN && !ni_string_empty(type)) {
if (!xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_LINK_TYPE, node, type))
return NULL; /* Error */
}
skip:

return xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, node, w->name);
}
Expand Down
1 change: 1 addition & 0 deletions include/wicked/fsm.h
Expand Up @@ -334,6 +334,7 @@ extern ni_bool_t ni_ifworker_match_netdev_name(const ni_ifworker_t *, const cha
extern ni_bool_t ni_ifworker_match_netdev_alias(const ni_ifworker_t *, const char *);
extern ni_bool_t ni_ifworker_match_netdev_ifindex(const ni_ifworker_t *, unsigned int);
extern ni_bool_t ni_ifworker_match_alias(const ni_ifworker_t *, const char *);
extern ni_iftype_t ni_ifworker_iftype_from_xml(xml_node_t *);
extern void ni_ifworker_set_config(ni_ifworker_t *, xml_node_t *, const char *);
extern ni_bool_t ni_ifworker_control_set_usercontrol(ni_ifworker_t *, ni_bool_t);
extern ni_bool_t ni_ifworker_control_set_persistent(ni_ifworker_t *, ni_bool_t);
Expand Down
5 changes: 4 additions & 1 deletion nanny/device.c
Expand Up @@ -188,6 +188,9 @@ ni_factory_device_apply_policy(ni_fsm_t *fsm, ni_ifworker_t *w, ni_managed_polic
ni_fsm_policy_t *policy = mpolicy->fsm_policy;
xml_node_t *config = NULL;

if (!policy)
return -1;

ni_debug_nanny("%s: configuring factory device using policy %s",
w->name, ni_fsm_policy_name(policy));

Expand Down Expand Up @@ -224,7 +227,7 @@ ni_managed_device_apply_policy(ni_managed_device_t *mdev, ni_managed_policy_t *m
ni_fsm_policy_t *policy = mpolicy->fsm_policy;
xml_node_t *config = NULL;

if (!(w = ni_managed_device_get_worker(mdev)))
if (!policy || !(w = ni_managed_device_get_worker(mdev)))
return -1;

/* If the device is up and running, do not reconfigure unless the policy
Expand Down
6 changes: 4 additions & 2 deletions nanny/nanny.c
Expand Up @@ -379,8 +379,10 @@ ni_nanny_create_policy(ni_dbus_object_t **policy_object, ni_nanny_t *mgr, const
ni_debug_nanny("Policy \"%s\" already exists", pname);
rv = 0;
}
else
policy = ni_fsm_policy_new(fsm, pname, pnode);
else if (!(policy = ni_fsm_policy_new(fsm, pname, pnode))) {
ni_error("Unable to create policy object from %s", doc_string);
goto error;
}

config = xml_node_new(NI_CLIENT_IFCONFIG, NULL);
config = ni_fsm_policy_transform_document(config, &policy, 1);
Expand Down
40 changes: 35 additions & 5 deletions src/fsm-policy.c
Expand Up @@ -258,7 +258,7 @@ ni_fsm_policy_new(ni_fsm_t *fsm, const char *name, xml_node_t *node)
ni_fsm_policy_t *policy;
ni_fsm_policy_t *pos, **tail;

policy = calloc(1, sizeof(*policy));
policy = xcalloc(1, sizeof(*policy));
ni_string_dup(&policy->name, name);

if (!__ni_fsm_policy_from_xml(policy, node)) {
Expand Down Expand Up @@ -548,6 +548,9 @@ ni_fsm_policy_transform_document(xml_node_t *node, ni_fsm_policy_t * const *poli
const ni_fsm_policy_t *policy = policies[i];
ni_fsm_policy_action_t *action;

if (!policy)
continue;

for (action = policy->actions; action && node; action = action->next) {
switch (action->type) {
case NI_IFPOLICY_ACTION_MERGE:
Expand Down Expand Up @@ -1283,6 +1286,21 @@ __ni_fsm_policy_match_class_check(const ni_ifcondition_t *cond, ni_ifworker_t *w
return rv;
}

static ni_bool_t
__ni_fsm_policy_match_linktype_check(const ni_ifcondition_t *cond, ni_ifworker_t *w)
{
ni_bool_t rv;
ni_iftype_t iftype = (ni_iftype_t) cond->args.uint;

rv = (iftype == w->iftype);

if (ni_debug_guard(NI_LOG_DEBUG2, NI_TRACE_IFCONFIG)) {
ni_trace("%s: %s condition is %s",
w->name, __func__, ni_format_boolean(rv));
}
return rv;
}

static ni_ifcondition_t *
__ni_fsm_policy_match_class_new(xml_node_t *node, const char *classname)
{
Expand All @@ -1301,6 +1319,17 @@ __ni_fsm_policy_match_class_new(xml_node_t *node, const char *classname)
return result;
}

static ni_ifcondition_t *
__ni_fsm_policy_match_linktype_new(xml_node_t *node, ni_iftype_t iftype)
{
ni_ifcondition_t *result;

result = ni_ifcondition_new(__ni_fsm_policy_match_linktype_check);
result->args.uint = iftype;

return result;
}

static ni_ifcondition_t *
ni_ifcondition_class(xml_node_t *node)
{
Expand All @@ -1310,14 +1339,15 @@ ni_ifcondition_class(xml_node_t *node)
static ni_ifcondition_t *
ni_ifcondition_linktype(xml_node_t *node)
{
char namebuf[128];
ni_iftype_t iftype;

if (ni_linktype_name_to_type(node->cdata) < 0) {
iftype = ni_linktype_name_to_type(node->cdata);
if (iftype >= __NI_IFTYPE_MAX) {
ni_error("%s: unknown link type \"%s\"", xml_node_location(node), node->cdata);
return NULL;
}
snprintf(namebuf, sizeof(namebuf), "netif-%s", node->cdata);
return __ni_fsm_policy_match_class_new(node, namebuf);

return __ni_fsm_policy_match_linktype_new(node, iftype);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/fsm.c
Expand Up @@ -1814,7 +1814,7 @@ ni_ifworker_extra_waittime_from_xml(ni_ifworker_t *w)
w->extra_waittime = (extra_timeout*1000);
}

static ni_iftype_t
ni_iftype_t
ni_ifworker_iftype_from_xml(xml_node_t *config)
{
ni_iftype_t iftype;
Expand Down
7 changes: 7 additions & 0 deletions wicked.spec.in
Expand Up @@ -67,6 +67,13 @@ BuildRequires: dbus-1-devel
BuildRequires: libgcrypt-devel
BuildRequires: pkg-config

# Prerequire the logger package
%if 0%{?suse_version} > 1310
Requires(pre): util-linux-systemd
%else
Requires(pre): util-linux
%endif

%if %{with systemd}
%{?systemd_requires}
%if 0%{?suse_version:1}
Expand Down

0 comments on commit 7dc8e61

Please sign in to comment.