virt: Fix network interface filtering
authorRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Thu, 31 Jan 2019 14:05:28 +0000 (14:05 +0000)
committerRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Fri, 22 Mar 2019 16:35:46 +0000 (16:35 +0000)
Previously network device filtering was not working properly
if InterfaceFormat was set to 'name' or 'address' values.
Additionally implementation for filtering by interface number
was missing.

Change-Id: Ic6aa1d355423305d08bcab8282dc29009b200b5a
Signed-off-by: Radoslaw Jablonski <radoslawx.jablonski@intel.com>
src/virt.c

index 92c120f..5b4dbb8 100644 (file)
@@ -2609,6 +2609,7 @@ static void lv_add_network_interfaces(struct lv_read_state *state,
   for (int j = 0; j < xml_interfaces->nodeNr; ++j) {
     char *path = NULL;
     char *address = NULL;
+    const int itf_number = j + 1;
 
     xmlNodePtr xml_interface = xml_interfaces->nodeTab[j];
     if (!xml_interface)
@@ -2630,11 +2631,31 @@ static void lv_add_network_interfaces(struct lv_read_state *state,
       }
     }
 
-    if ((ignore_device_match(il_interface_devices, domname, path) == 0 &&
-         ignore_device_match(il_interface_devices, domname, address) == 0)) {
-      add_interface_device(state, dom, path, address, j + 1);
+    bool device_ignored = false;
+    switch (interface_format) {
+    case if_name:
+      if (ignore_device_match(il_interface_devices, domname, path) != 0)
+        device_ignored = true;
+      break;
+    case if_address:
+      if (ignore_device_match(il_interface_devices, domname, address) != 0)
+        device_ignored = true;
+      break;
+    case if_number: {
+      char number_string[4];
+      snprintf(number_string, sizeof(number_string), "%d", itf_number);
+      if (ignore_device_match(il_interface_devices, domname, number_string) !=
+          0)
+        device_ignored = true;
+    } break;
+    default:
+      ERROR(PLUGIN_NAME " plugin: Unknown interface_format option: %d",
+            interface_format);
     }
 
+    if (!device_ignored)
+      add_interface_device(state, dom, path, address, itf_number);
+
     if (path)
       xmlFree(path);
     if (address)