There is some confusion about which options can be passed to ovs-tcpdump
when gathering data.  The interpretation sometimes is that ovs-tcpdump
only accepts a specific small set of options and discards other options.
This leads to questions such as, "How can I use '-C' or set the snaplen
with ovs-tcpdump like tcpdump allows?"  To correct this, print the
dump_cmd help after the ovs-tcpdump options.

As part of this rework, we delay printing the usage data until after
all arguments are processed, which allows setting the dumpcmd as well
for the --help option.

Signed-off-by: Aaron Conole <[email protected]>
---
 utilities/ovs-tcpdump.in | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index f3e90fdbba..164883e54d 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -125,7 +125,10 @@ def username():
     return pwd.getpwuid(os.getuid())[0]
 
 
-def usage():
+def usage(tcpdump_prog='tcpdump'):
+    tcpd_help = _doexec(*([tcpdump_prog, '--help']))
+    tcpd_help.wait()
+
     print("""\
 %(prog)s: Open vSwitch tcpdump helper.
 usage: %(prog)s -i interface [TCPDUMP OPTIONS]
@@ -143,7 +146,11 @@ The following options are available:
                               Default 'miINTERFACE'
    --span                     If specified, mirror all ports (optional)
    --filter                   Set an OpenFlow formatted preselection filter
-""" % {'prog': sys.argv[0]})
+
+The following are the '%(tcpdump_prog)s' options:
+%(tcpdump_help)s
+""" % {'prog': sys.argv[0], 'tcpdump_prog': tcpdump_prog,
+       'tcpdump_help': tcpd_help.stdout.read().decode('utf-8')})
     sys.exit(0)
 
 
@@ -453,13 +460,15 @@ def main():
     mirror_select_all = False
     dump_cmd = 'tcpdump'
     mirror_filter = None
+    print_usage = False
 
     for cur, nxt in argv_tuples(sys.argv[1:]):
         if skip_next:
             skip_next = False
             continue
         if cur in ['-h', '--help']:
-            usage()
+            print_usage = True
+            continue
         elif cur in ['-V', '--version']:
             print("ovs-tcpdump (Open vSwitch) @VERSION@@VERSION_SUFFIX@")
             sys.exit(0)
@@ -488,14 +497,17 @@ def main():
             continue
         tcpdargs.append(cur)
 
-    if interface is None:
-        print("Error: must at least specify an interface with '-i' option")
-        sys.exit(1)
-
     if not py_which(dump_cmd):
         print("Error: unable to execute '%s' (check PATH)" % dump_cmd)
         sys.exit(1)
 
+    if print_usage:
+        usage(dump_cmd)
+
+    if interface is None:
+        print("Error: must at least specify an interface with '-i' option")
+        sys.exit(1)
+
     if '-l' not in tcpdargs:
         tcpdargs.insert(0, '-l')
 
-- 
2.49.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to