@@ -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+
76163static 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 ;
0 commit comments