Skip to content

Commit fc9daaa

Browse files
committed
Merge pull request #598 from mtomaschewski/netif-requires
nanny: add device references to policy match (bsc#941611)
2 parents 6435dcb + 8c57ff2 commit fc9daaa

File tree

6 files changed

+303
-60
lines changed

6 files changed

+303
-60
lines changed

client/ifup.c

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,93 @@ __ni_ifup_generate_match_dev(xml_node_t *node, ni_ifworker_t *w)
7373
return xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, node, w->name);
7474
}
7575

76+
static ni_bool_t
77+
__ni_ifup_generate_match_link_port_ref(xml_node_t *match, xml_node_t *port)
78+
{
79+
const char *type = xml_node_get_attr(port, NI_CLIENT_IFCONFIG_PORT_TYPE);
80+
ni_iftype_t ptype = ni_linktype_name_to_type(type);
81+
xml_node_t *ref, *ovsbr;
82+
83+
switch (ptype) {
84+
case NI_IFTYPE_OVS_BRIDGE:
85+
ovsbr = xml_node_get_child(port, NI_CLIENT_IFCONFIG_BRIDGE);
86+
if (!ovsbr || ni_string_empty(ovsbr->cdata))
87+
return FALSE;
88+
89+
if (!(ref = xml_node_new(NI_NANNY_IFPOLICY_MATCH_REF, match)))
90+
return FALSE;
91+
92+
if (!xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, ref, ovsbr->cdata)) {
93+
xml_node_free(ref);
94+
return FALSE;
95+
}
96+
break;
97+
98+
default:
99+
/* other port types need master only */
100+
break;
101+
}
102+
return TRUE;
103+
}
104+
105+
static ni_bool_t
106+
__ni_ifup_generate_match_link_ref(xml_node_t *match, xml_node_t *link)
107+
{
108+
xml_node_t *ref, *master, *port;
109+
110+
if (!(master = xml_node_get_child(link, NI_CLIENT_IFCONFIG_MASTER)))
111+
return TRUE; /* <link> does not contain a <master> node */
112+
113+
if (ni_string_empty(master->cdata))
114+
return FALSE;
115+
116+
if (!(ref = xml_node_new(NI_NANNY_IFPOLICY_MATCH_REF, match)))
117+
return FALSE;
118+
119+
if (!xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, ref, master->cdata)) {
120+
xml_node_free(ref);
121+
return FALSE;
122+
}
123+
124+
if ((port = xml_node_get_child(link, NI_CLIENT_IFCONFIG_LINK_PORT)))
125+
return __ni_ifup_generate_match_link_port_ref(match, port);
126+
127+
return TRUE; /* master ref at least */
128+
}
129+
130+
static ni_bool_t
131+
__ni_ifup_generate_match_master_ref(xml_node_t *match, ni_ifworker_t *master)
132+
{
133+
xml_node_t *ref;
134+
135+
if (!master || ni_string_empty(master->name))
136+
return FALSE;
137+
138+
if (!(ref = xml_node_new(NI_NANNY_IFPOLICY_MATCH_REF, match)))
139+
return FALSE;
140+
141+
if (!xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, ref, master->name)) {
142+
xml_node_free(ref);
143+
return FALSE;
144+
}
145+
146+
return TRUE;
147+
}
148+
149+
static ni_bool_t
150+
__ni_ifup_generate_match_refs(xml_node_t *match, ni_ifworker_t *w)
151+
{
152+
xml_node_t *link;
153+
154+
if (w->masterdev)
155+
return __ni_ifup_generate_match_master_ref(match, w->masterdev);
156+
157+
if ((link = xml_node_get_child(w->config.node, NI_CLIENT_IFCONFIG_LINK)))
158+
return __ni_ifup_generate_match_link_ref(match, link);
159+
160+
return TRUE; /* no refs is not an error */
161+
}
162+
76163
static xml_node_t *
77164
__ni_ifup_generate_match(const char *name, ni_ifworker_t *w)
78165
{
@@ -81,18 +168,34 @@ __ni_ifup_generate_match(const char *name, ni_ifworker_t *w)
81168
if (!(match = xml_node_new(name, NULL)))
82169
goto error;
83170

171+
ni_debug_wicked_xml(w->config.node, NI_LOG_DEBUG,
172+
"generate policy match for %s (type %s)", w->name,
173+
ni_linktype_type_to_name(w->iftype));
174+
84175
if (!__ni_ifup_generate_match_dev(match, w))
85176
goto error;
86177

87-
/* Ignore child dependency for following device types */
178+
/* Ignore child dependency for following device types:
179+
* - ovs-system: otherwise ovs-system would require all ports
180+
* in all ovs-bridges and want to get at least one up ...
181+
* this is not what we want :-)
182+
*/
88183
switch (w->iftype) {
89184
case NI_IFTYPE_OVS_SYSTEM:
90185
goto done;
91186
break;
92187
default:
188+
if (ni_string_eq(w->name, ni_linktype_type_to_name(NI_IFTYPE_OVS_SYSTEM)))
189+
goto done;
93190
break;
94191
}
95192

193+
if (!__ni_ifup_generate_match_refs(match, w)) {
194+
ni_debug_application("%s: unable to generate policy match device references",
195+
w->name);
196+
goto error;
197+
}
198+
96199
if (w->children.count) {
97200
xml_node_t *or;
98201
unsigned int i;

include/wicked/fsm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ extern void ni_fsm_policy_free(ni_fsm_policy_t *);
287287
extern ni_bool_t ni_fsm_policy_update(ni_fsm_policy_t *, xml_node_t *);
288288
extern ni_fsm_policy_t * ni_fsm_policy_by_name(ni_fsm_t *, const char *);
289289
extern ni_bool_t ni_fsm_policy_remove(ni_fsm_t *, ni_fsm_policy_t *);
290-
extern unsigned int ni_fsm_policy_get_applicable_policies(ni_fsm_t *, ni_ifworker_t *,
290+
extern unsigned int ni_fsm_policy_get_applicable_policies(const ni_fsm_t *, ni_ifworker_t *,
291291
const ni_fsm_policy_t **, unsigned int);
292-
extern ni_bool_t ni_fsm_exists_applicable_policy(ni_fsm_policy_t *, ni_ifworker_t *);
292+
extern ni_bool_t ni_fsm_exists_applicable_policy(const ni_fsm_t *, ni_fsm_policy_t *, ni_ifworker_t *);
293293
extern xml_node_t * ni_fsm_policy_transform_document(xml_node_t *, ni_fsm_policy_t * const *, unsigned int);
294294
extern const char * ni_fsm_policy_name(const ni_fsm_policy_t *);
295295
extern xml_location_t * ni_fsm_policy_location(const ni_fsm_policy_t *);
@@ -313,7 +313,7 @@ extern unsigned int ni_fsm_fail_count(ni_fsm_t *);
313313
extern ni_ifworker_t * ni_fsm_ifworker_by_object_path(ni_fsm_t *, const char *);
314314
extern ni_ifworker_t * ni_fsm_ifworker_by_ifindex(ni_fsm_t *, unsigned int);
315315
extern ni_ifworker_t * ni_fsm_ifworker_by_netdev(ni_fsm_t *, const ni_netdev_t *);
316-
extern ni_ifworker_t * ni_fsm_ifworker_by_name(ni_fsm_t *, ni_ifworker_type_t, const char *);
316+
extern ni_ifworker_t * ni_fsm_ifworker_by_name(const ni_fsm_t *, ni_ifworker_type_t, const char *);
317317
extern ni_ifworker_t * ni_fsm_ifworker_by_policy_name(ni_fsm_t *, ni_ifworker_type_t, const char *);
318318
extern ni_ifworker_t * ni_fsm_recv_new_netif(ni_fsm_t *fsm, ni_dbus_object_t *object, ni_bool_t refresh);
319319
extern ni_ifworker_t * ni_fsm_recv_new_netif_path(ni_fsm_t *fsm, const char *path);

nanny/nanny.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ ni_nanny_register_device(ni_nanny_t *mgr, ni_ifworker_t *w)
530530
mdev->allowed? ", user control allowed" : "",
531531
mdev->monitor? ", monitored (auto-enabled)" : "");
532532

533-
if (ni_fsm_exists_applicable_policy(mgr->fsm->policies, w))
533+
if (ni_fsm_exists_applicable_policy(mgr->fsm, mgr->fsm->policies, w))
534534
ni_nanny_schedule_recheck(&mgr->recheck, w);
535535

536536
ni_ifworker_set_progress_callback(w, ni_managed_device_progress, mdev);
@@ -556,7 +556,7 @@ ni_nanny_unregister_device(ni_nanny_t *mgr, ni_ifworker_t *w)
556556
ni_ifworker_set_completion_callback(w, NULL, NULL);
557557

558558
if (!ni_ifworker_is_factory_device(w) ||
559-
!ni_fsm_exists_applicable_policy(mgr->fsm->policies, w)) {
559+
!ni_fsm_exists_applicable_policy(mgr->fsm, mgr->fsm->policies, w)) {
560560
ni_nanny_unschedule(&mgr->recheck, w);
561561
}
562562
}

src/client/ifconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#define NI_CLIENT_IFCONFIG_MODE "mode"
3232
#define NI_CLIENT_IFCONFIG_LINK "link"
3333
#define NI_CLIENT_IFCONFIG_MASTER "master"
34+
#define NI_CLIENT_IFCONFIG_LINK_PORT "port"
35+
#define NI_CLIENT_IFCONFIG_PORT_TYPE "type"
36+
#define NI_CLIENT_IFCONFIG_BRIDGE "bridge"
3437
#define NI_CLIENT_IFCONFIG_IPV4 "ipv4"
3538
#define NI_CLIENT_IFCONFIG_IPV6 "ipv6"
3639
#define NI_CLIENT_IFCONFIG_IP_ENABLED "enabled"
@@ -45,6 +48,7 @@
4548
#define NI_NANNY_IFPOLICY_MATCH_COND_CHILD "child"
4649
#define NI_NANNY_IFPOLICY_MATCH_ALWAYS_TRUE "any"
4750
#define NI_NANNY_IFPOLICY_MATCH_DEV "device"
51+
#define NI_NANNY_IFPOLICY_MATCH_REF "reference"
4852
#define NI_NANNY_IFPOLICY_MATCH_MIN_STATE "minimum-device-state"
4953
#define NI_NANNY_IFPOLICY_MATCH_LINK_TYPE "link-type"
5054
#define NI_NANNY_IFPOLICY_MERGE "merge"

0 commit comments

Comments
 (0)