Skip to content

[release-1.14] northd: set dl_src for packets redirected by router port#6102

Merged
zhangzujian merged 1 commit intokubeovn:release-1.14from
zhangzujian:dl-src-1.14
Dec 25, 2025
Merged

[release-1.14] northd: set dl_src for packets redirected by router port#6102
zhangzujian merged 1 commit intokubeovn:release-1.14from
zhangzujian:dl-src-1.14

Conversation

@zhangzujian
Copy link
Copy Markdown
Member

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes

Fixes #(issue-number)

Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zhangzujian, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the Kube-OVN controller by removing the Underlay-to-Overlay (U2O) interconnection logic, simplifying pod event handling, and introducing a new startup cleanup for obsolete U2O OpenFlow rules. Concurrently, it enhances the OVN northd component with a patch to correctly manage the data link source for packets redirected by router ports, addressing a specific networking behavior.

Highlights

  • OVN northd Logic Enhancement: Introduced a new patch to the OVN northd component that specifically sets the data link source (dl_src) for packets that are redirected by router ports. This ensures correct MAC address handling in complex routing scenarios within the OVN network.
  • Removal of U2O Interconnection Logic: The Kube-OVN controller's explicit handling of Underlay-to-Overlay (U2O) interconnection flows for pods and subnets has been removed. This includes the deletion of dedicated queue workers, event handlers, and OpenFlow management functions related to U2O.
  • Obsolete U2O Flow Cleanup: A new mechanism has been added to clear obsolete U2O OpenFlow rules from OVS bridges during the controller's initialization, ensuring a clean state and preventing stale flows.
  • Controller Code Refactoring: Streamlined the Kube-OVN controller by removing the deletePodQueue and its associated functions, simplifying the pod event handling logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the handling of packets redirected by a router port by moving the logic from node-level OVS flow rules to a centralized implementation in northd. This is a good architectural improvement that simplifies the daemon's responsibilities.

The changes include:

  • Adding a new patch for northd to create logical flows that modify the source MAC address of redirected packets.
  • Removing the now-obsolete U2O (Underlay to Overlay) feature from the kube-ovn-cni daemon, including related functions, work queues, and OpenFlow rule management.
  • Adding a cleanup function (ClearU2OFlows) to remove any lingering OVS flows from the old implementation upon daemon startup.

The implementation is solid. I have a couple of suggestions for the new C code in northd to improve readability and maintainability.

Comment on lines +26 to +45
+ if (!op->nbsp || !op->od || !op->od->nbs ||
+ !op->od->n_router_ports || !op->od->n_localnet_ports) {
+ return;
+ }
+ if (!lsp_is_enabled(op->nbsp)) {
+ return;
+ }
+ if (!strcmp(op->nbsp->type, "virtual") ||
+ !strcmp(op->nbsp->type, "localport")) {
+ return;
+ }
+ if (lsp_is_external(op->nbsp) || lsp_is_router(op->nbsp) ||
+ op->has_unknown) {
+ return;
+ }
+
+ if (op->n_lsp_addrs != 1 || !strlen(op->lsp_addrs[0].ea_s) ||
+ (!op->lsp_addrs[0].n_ipv4_addrs && !op->lsp_addrs[0].n_ipv6_addrs)) {
+ return;
+ }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better readability, the series of if statements at the beginning of build_lswitch_mod_dl_src_rules can be combined into a single if block. This would clearly separate the precondition checks from the main logic of the function.

    if (!op->nbsp || !op->od || !op->od->nbs ||
        !op->od->n_router_ports || !op->od->n_localnet_ports ||
        !lsp_is_enabled(op->nbsp) ||
        !strcmp(op->nbsp->type, "virtual") ||
        !strcmp(op->nbsp->type, "localport") ||
        lsp_is_external(op->nbsp) || lsp_is_router(op->nbsp) ||
        op->has_unknown ||
        op->n_lsp_addrs != 1 || !strlen(op->lsp_addrs[0].ea_s) ||
        (!op->lsp_addrs[0].n_ipv4_addrs && !op->lsp_addrs[0].n_ipv6_addrs)) {
        return;
    }

Comment on lines +63 to +83
+ for (size_t j = 0; j < op->lsp_addrs[0].n_ipv4_addrs; j++) {
+ ds_clear(match);
+ ds_put_format(match,
+ "inport == %s && ip4.src == %s && eth.src != %s",
+ rp->json_key, op->lsp_addrs[0].ipv4_addrs[j].addr_s,
+ op->lsp_addrs[0].ea_s);
+ ovn_lflow_add_with_hint(lflows, op->od, S_SWITCH_IN_L2_LKUP, 60,
+ ds_cstr(match), ds_cstr(actions),
+ &op->nbsp->header_, op->lflow_ref);
+ }
+
+ for (size_t j = 0; j < op->lsp_addrs[0].n_ipv6_addrs; j++) {
+ ds_clear(match);
+ ds_put_format(match,
+ "inport == %s && ip6.src == %s && eth.src != %s",
+ rp->json_key, op->lsp_addrs[0].ipv6_addrs[j].addr_s,
+ op->lsp_addrs[0].ea_s);
+ ovn_lflow_add_with_hint(lflows, op->od, S_SWITCH_IN_L2_LKUP, 60,
+ ds_cstr(match), ds_cstr(actions),
+ &op->nbsp->header_, op->lflow_ref);
+ }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The loops for creating IPv4 and IPv6 flows are nearly identical. To improve maintainability and reduce code duplication, consider refactoring this logic into a helper function. This function could accept the address family (ip4 or ip6) and the list of addresses as parameters.

@zhangzujian zhangzujian marked this pull request as ready for review December 25, 2025 01:01
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. feature New network feature labels Dec 25, 2025
@zhangzujian zhangzujian changed the title northd: set dl_src for packets redirected by router port [release-1.14] northd: set dl_src for packets redirected by router port Dec 25, 2025
@zhangzujian zhangzujian merged commit c975191 into kubeovn:release-1.14 Dec 25, 2025
129 of 136 checks passed
@zhangzujian zhangzujian deleted the dl-src-1.14 branch December 25, 2025 02:35
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 20496212592

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 30 (0.0%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.1%) to 21.488%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/daemon/controller_linux.go 0 3 0.0%
pkg/ovs/ovs-ofctl.go 0 27 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/ovs/ovs-ofctl.go 1 0.0%
pkg/daemon/controller.go 2 0.0%
Totals Coverage Status
Change from base Build 20481335950: 0.1%
Covered Lines: 10649
Relevant Lines: 49558

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New network feature size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants