[ovs-dev] [PATCH] ovs-tcpdump: Fallback to read /proc/net/dev on Linux

Timothy Redaelli tredaelli at redhat.com
Mon Jan 13 16:47:03 UTC 2020

Currently, ovs-tcpdump uses python3-netifaces in order to get the list of
the network interfaces, but python3-netifaces may not be installed nor
available on some distributions (for example on RHEL7).

This commit adds, only for Linux, an alternative way (that is only used
when netifaces is not available) to read the list of the network interfaces
by reading "/proc/net/dev".

Signed-off-by: Timothy Redaelli <tredaelli at redhat.com>
 utilities/ovs-tcpdump.in | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index 0fa5dc418..5ec02383c 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -24,7 +24,21 @@ import subprocess
 import sys
 import time
-import netifaces
+    from netifaces import interfaces
+except ImportError:
+    if sys.platform in ['linux', 'linux2']:
+        def interfaces():
+            devices = []
+            with open("/proc/net/dev", "r") as f_netdev:
+                for line in f_netdev:
+                    if ":" not in line:
+                        continue
+                    devices.append(line.split(":")[0].strip())
+            return devices
+    else:
+        print("ERROR: Please install netifaces Python library.")
+        sys.exit(1)
     from ovs.db import idl
@@ -438,11 +452,11 @@ def main():
             mirror_interface = _make_mirror_name[sys.platform](interface)
     if sys.platform in _make_taps and \
-       mirror_interface not in netifaces.interfaces():
+       mirror_interface not in interfaces():
-    if mirror_interface not in netifaces.interfaces():
+    if mirror_interface not in interfaces():
         print("ERROR: Please create an interface called `%s`" %
         print("See your OS guide for how to do this.")

More information about the dev mailing list