Skip to content

[PWCI] "[ovs-dev] ovs-tcpdump: Update the usage information to be more helpful."#6

Open
ovsrobot wants to merge 4 commits intomainfrom
series_472073
Open

[PWCI] "[ovs-dev] ovs-tcpdump: Update the usage information to be more helpful."#6
ovsrobot wants to merge 4 commits intomainfrom
series_472073

Conversation

@ovsrobot
Copy link
Owner

@ovsrobot ovsrobot commented Sep 3, 2025

NOTE: This is an auto submission for "[ovs-dev] ovs-tcpdump: Update the usage information to be more helpful.".

See "http://patchwork.ozlabs.org/project/openvswitch/list/?series=472073" for details.

Summary by Sourcery

Fix memory leaks in DPDK flow parsing, correct offload_data lookup for DPDK flow destruction, and refresh AUTHORS and ovs-tcpdump usage information

Bug Fixes:

  • Free allocated spec and mask on unknown IPv4 fragment parse errors to prevent memory leaks
  • Free allocated frag_spec and frag_mask on unknown IPv6 fragment parse errors to prevent memory leaks
  • Use physdev->hw_info.offload_data instead of netdev->hw_info.offload_data when destroying DPDK flows to correct RCU lookup

Documentation:

  • Update AUTHORS.rst with refreshed contributor information
  • Improve usage output in the ovs-tcpdump utility

Summary by CodeRabbit

  • New Features

    • ovs-tcpdump help now dynamically reflects the installed tcpdump’s options and can be shown without providing an interface.
  • Bug Fixes

    • Improved stability by fixing resource cleanup on certain error paths.
    • Corrected counter updates for DPDK offloaded flows to better reflect the underlying device.
  • Documentation

    • Added Linda Wang to the Authors list.

Linda Wang and others added 4 commits September 1, 2025 16:52
For vport devices hardware offload counters were being incremented
on the physical device but decremented on the vport, causing
incorrect statistics that didn't return to zero when flows are
removed.

Fix by using physdev instead of netdev for counter decrements to match
the increment behavior.

Fixes: 0e6366c ("netdev-offload-dpdk: Implement hw-offload statistics read.")
Signed-off-by: Linda Wang <linda.wang@jaguarmicro.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
The error paths should release any allocated resources that are not
added to the patterns.

Found by Coverity.

Fixes: c1a5d0e ("netdev-offload-dpdk: Support IPv4 fragmentation types.")
Fixes: 1318929 ("netdev-offload-dpdk: Support IPv6 fragmentation types.")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
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 <aconole@redhat.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 3, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes memory leaks in DPDK flow parsing, corrects an RCU data retrieval bug in flow teardown, and refines the ovs-tcpdump usage text (plus updates the AUTHORS list).

File-Level Changes

Change Details Files
Prevent memory leaks in flow parsing error paths
  • Free spec and mask on unknown IPv4 fragment errors
  • Free frag_spec and frag_mask on unknown IPv6 fragment errors
lib/netdev-offload-dpdk.c
Fix offload_data retrieval in flow destroy
  • Switch ovsrcu_get operand from netdev->hw_info to physdev->hw_info
lib/netdev-offload-dpdk.c
Enhance ovs-tcpdump usage output
  • Clarify option descriptions
  • Improve formatting of help text
  • Add concrete example usages
utilities/ovs-tcpdump.in
Update AUTHORS list
  • Sync AUTHORS.rst with recent contributions
AUTHORS.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

Updates AUTHORS.rst to add an author entry. In lib/netdev-offload-dpdk.c, adds memory frees on error paths and switches counter updates to use physdev. In utilities/ovs-tcpdump.in, makes usage dynamic by invoking the underlying tcpdump’s help, adjusts help flow, and adds a parameterized usage(tcpdump_prog).

Changes

Cohort / File(s) Summary of Changes
Documentation: Authors list
AUTHORS.rst
Added new author entry for Linda Wang, positioned between existing entries.
DPDK offload: error handling and counters
lib/netdev-offload-dpdk.c
Frees IPv4/IPv6 frag spec/mask on error in parse_flow_match; in flow destroy, retrieves offload data from physdev for rte_flow_counters updates.
ovs-tcpdump dynamic usage/help flow
utilities/ovs-tcpdump.in
usage() signature changed to usage(tcpdump_prog='tcpdump'); dynamically embeds tcpdump --help output; main flow defers validation, sets print_usage flag on -h/--help, validates tcpdump in PATH, then calls usage(dump_cmd) if requested.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant O as ovs-tcpdump
  participant S as System PATH
  participant T as tcpdump

  rect rgb(245,248,255)
    note right of U: Request help (-h/--help)
    U->>O: Invoke with -h/--help
    O->>S: Locate tcpdump program
    alt tcpdump found
      O->>T: Run `tcpdump --help`
      T-->>O: Help text (stdout)
      O-->>U: Print ovs-tcpdump usage + embedded tcpdump help
    else tcpdump missing
      O-->>U: Error: tcpdump not found
    end
  end

  rect rgb(245,255,245)
    note right of U: Normal run
    U->>O: Invoke with interface/args
    O->>S: Locate tcpdump program
    alt validation ok
      O->>T: Execute tcpdump with args
      T-->>O: Stream output
      O-->>U: Forward output
    else validation error
      O-->>U: Print error/usage as applicable
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my ears at tidy C,
Freeing specs to leak no sea.
I sniff the wire with tcpdump’s lore,
Now usage sings from help it bore.
New names inked on AUTHORS’ scroll—
A hop, a fix, control in whole. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch series_472073

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
utilities/ovs-tcpdump.in (1)

500-506: Show usage even if tcpdump is missing.

Currently, requesting “--help” fails if dump_cmd isn’t in PATH. Consider printing wrapper usage anyway and annotating that underlying help isn’t available.

-    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 print_usage:
+        # usage() handles missing tcpdump and will note it.
+        usage(dump_cmd)
+
+    if not py_which(dump_cmd):
+        print("Error: unable to execute '%s' (check PATH)" % dump_cmd)
+        sys.exit(1)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e0ee785 and 4e870f6.

📒 Files selected for processing (3)
  • AUTHORS.rst (1 hunks)
  • lib/netdev-offload-dpdk.c (3 hunks)
  • utilities/ovs-tcpdump.in (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: linux clang dpdk --enable-shared
  • GitHub Check: linux gcc test -ljemalloc
  • GitHub Check: linux gcc dpdk --enable-shared
  • GitHub Check: linux gcc check check-dpdk dpdk
  • GitHub Check: linux clang --enable-afxdp
  • GitHub Check: linux clang test --enable-shared
  • GitHub Check: linux clang check check-dpdk dpdk
  • GitHub Check: linux clang --disable-ssl
  • GitHub Check: linux gcc --disable-ssl
  • GitHub Check: linux clang test -ljemalloc
  • GitHub Check: linux gcc test --enable-shared
  • GitHub Check: linux clang address,undefined test
  • GitHub Check: linux clang c99
  • GitHub Check: linux gcc test
  • GitHub Check: linux gcc c99
  • GitHub Check: clang-analyze-cache
  • GitHub Check: linux deb no dpdk
  • GitHub Check: linux rpm fedora
  • GitHub Check: osx clang --disable-ssl
  • GitHub Check: build oss-fuzz fuzzers
🔇 Additional comments (6)
AUTHORS.rst (1)

298-299: LGTM: author entry looks correct and alphabetized.

Placement and formatting match surrounding entries.

lib/netdev-offload-dpdk.c (2)

1527-1531: Good fix: free IPv4 spec/mask on error path.

Prevents leaks when encountering unknown IPv4 frag flags before the item is added to patterns.


1612-1616: Good fix: free IPv6 frag spec/mask on error path.

Prevents leaks when encountering unknown IPv6 frag conditions.

utilities/ovs-tcpdump.in (3)

463-463: Initialize print_usage: good call.

Enables deferred usage printing without short-circuiting argument parsing.


470-471: Defer help printing instead of exiting early: good UX.

Keeps validation order predictable and allows including tcpdump’s help text.


507-510: Interface check after help: good.

Prevents spurious errors when only requesting usage.

Comment on lines 2381 to 2384
data = (struct netdev_offload_dpdk_data *)
ovsrcu_get(void *, &netdev->hw_info.offload_data);
ovsrcu_get(void *, &physdev->hw_info.offload_data);
data->rte_flow_counters[tid]--;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Use physdev for counter decrement to match increment site.

Switching offload_data source to physdev keeps rte_flow_counters consistent with creation (which increments on physdev). Consider adding a brief comment here to document the invariant.

Run to verify that all inc/dec sites consistently use physdev:


🏁 Script executed:

#!/bin/bash
rg -n -C2 --type=c 'rte_flow_counters\[[^]]+\]\+\+|rte_flow_counters\[[^]]+\]\-\-' lib/netdev-offload-dpdk.c

Length of output: 558


Synchronize counter sites to use physdev

In lib/netdev-offload-dpdk.c at the increment site (around line 932), you’re still doing:

ovsrcu_get(void *, &netdev->hw_info.offload_data);

but the delete path now uses physdev->hw_info.offload_data. Change the increment to use physdev so both ++ and -- touch the same counter array.

Comment on lines +128 to +131
def usage(tcpdump_prog='tcpdump'):
tcpd_help = _doexec(*([tcpdump_prog, '--help']))
tcpd_help.wait()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make help capture robust (stderr, fallback to -h, avoid deadlocks).

Some tcpdump builds print help to stderr or only support “-h”. Use subprocess.run with stderr=STDOUT and fallback to “-h”, and avoid wait()+read() sequencing.

Apply this diff to usage():

-def usage(tcpdump_prog='tcpdump'):
-    tcpd_help = _doexec(*([tcpdump_prog, '--help']))
-    tcpd_help.wait()
+def usage(tcpdump_prog='tcpdump'):
+    # Try -h first, then --help; capture stdout+stderr; tolerate missing binary.
+    help_text = ""
+    for args in ((tcpdump_prog, '-h'), (tcpdump_prog, '--help')):
+        try:
+            proc = subprocess.run(args, stdout=subprocess.PIPE,
+                                  stderr=subprocess.STDOUT, text=True)
+            help_text = (proc.stdout or "").strip()
+            if help_text:
+                break
+        except FileNotFoundError:
+            help_text = f"(unable to execute '{tcpdump_prog}' — only ovs-tcpdump options shown)"
+            break

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In utilities/ovs-tcpdump.in around lines 128 to 131, the usage() function
currently calls _doexec(... '--help') and then wait()+read(), which can deadlock
and misses help printed to stderr or when only '-h' is supported; change it to
use subprocess.run to invoke tcpdump with '--help' capturing combined output
(stderr=subprocess.STDOUT) and text=True, and if that returns a non-zero exit or
no output, retry with '-h'; remove wait()/read() sequencing and use the
completed process' stdout as the help text for further processing.

Comment on lines +150 to 154
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Print captured help safely.

Use the captured help_text string; avoids decode errors and works with the revised usage() above.

-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')})
+The following are the '%(tcpdump_prog)s' options:
+%(tcpdump_help)s
+""" % {'prog': sys.argv[0], 'tcpdump_prog': tcpdump_prog,
+       'tcpdump_help': help_text})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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)
The following are the '%(tcpdump_prog)s' options:
%(tcpdump_help)s
""" % {'prog': sys.argv[0], 'tcpdump_prog': tcpdump_prog,
'tcpdump_help': help_text})
sys.exit(0)
🤖 Prompt for AI Agents
In utilities/ovs-tcpdump.in around lines 150 to 154, the usage string is
currently inserting tcpd_help.stdout.read().decode('utf-8') which can cause
decode errors; change the interpolation to use the already-captured help_text
string (e.g., replace tcpd_help.stdout.read().decode('utf-8') with help_text) so
the usage() prints the safe, pre-decoded help_text and update the dict passed to
% accordingly.

ovsrobot pushed a commit that referenced this pull request Sep 19, 2025
When vport_add_channel() is called duplicate, the resources for previously
specified sock was not freed. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    #0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    #1 0x922630 in xmalloc__ lib/util.c:141
    #2 0x922718 in xmalloc lib/util.c:176
    #3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    #4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    #5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    #6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    #7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    #8 0x616354 in dpif_port_add lib/dpif.c:602
    #9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    #10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    #11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    #12 0x416dbc in iface_create vswitchd/bridge.c:2246
    #13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    #14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    #15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    #16 0x420884 in bridge_run vswitchd/bridge.c:3440
    #17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Fixes: 69c5158 ("dpif-netlink: don't allocate per thread netlink sockets")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
ovsrobot pushed a commit that referenced this pull request Oct 9, 2025
When vport_add_channel() is called duplicate, the resources for previously
specified sock was not freed. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    #0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    #1 0x922630 in xmalloc__ lib/util.c:141
    #2 0x922718 in xmalloc lib/util.c:176
    #3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    #4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    #5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    #6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    #7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    #8 0x616354 in dpif_port_add lib/dpif.c:602
    #9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    #10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    #11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    #12 0x416dbc in iface_create vswitchd/bridge.c:2246
    #13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    #14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    #15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    #16 0x420884 in bridge_run vswitchd/bridge.c:3440
    #17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Reproduce steps:
    ovs-vsctl add-br br-ovs
    ovs-vsctl add-port br-ovs test -- set interface test type=internal
    ip netns add ns_test
    ip link set test netns ns_test
    ip netns del ns_test
    ifconfig br-ovs up
    sleep 1
    ifconfig br-ovs down
    sleep 1
    ovs-vsctl del-br br-ovs

Fixes: 69c5158 ("dpif-netlink: don't allocate per thread netlink sockets")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants