Skip to content

Fix get nexthop IP address for OVN mgmt interface - #4131

Merged
yboaron merged 1 commit into
submariner-io:develfrom
yboaron:fix-ovn-gateway-network-address
Aug 17, 2026
Merged

Fix get nexthop IP address for OVN mgmt interface#4131
yboaron merged 1 commit into
submariner-io:develfrom
yboaron:fix-ovn-gateway-network-address

Conversation

@yboaron

@yboaron yboaron commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

The getNextHopOnK8sMgmtIntf() function would return Dst.IP when no explicit gateway was set on a route. However, Dst.IP is the network address (the base of the CIDR), not a valid host IP.

This PR adds validation to skip routes where Dst.IP equals the network address (IP & Mask == IP). This ensures only valid host IPs are used as gateways.

Also added test case to verify network addresses are rejected and only valid host addresses are used as gateways.

Fixes: #4121

Summary by CodeRabbit

  • Bug Fixes

    • Fixed route selection to avoid using a network address as a gateway when no explicit gateway is configured.
    • Preserved valid gateway-less host routes during host-network reconciliation.
    • Ensured routes with valid gateways are preferred during route selection.
    • Improved host-network routing reliability when multiple routes are available.
  • Tests

    • Added coverage for network-address routes, host routes, and gateway selection scenarios.

@submariner-bot

Copy link
Copy Markdown
Contributor

🤖 Created branch: z_pr4131/yboaron/fix-ovn-gateway-network-address
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 49cc4f0e-8820-4637-b370-a2f3edcfcaea

📥 Commits

Reviewing files that changed from the base of the PR and between 216fa46 and 4f5ccce.

📒 Files selected for processing (1)
  • pkg/routeagent_driver/handlers/ovn/handler_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/routeagent_driver/handlers/ovn/handler_test.go

Walkthrough

OVN host-network route selection skips gateway-less network-address routes while retaining gateway-less host routes. Regression tests verify valid gateway selection and host-route handling during reconciliation.

Changes

OVN gateway route selection

Layer / File(s) Summary
Gateway validation and regression coverage
pkg/routeagent_driver/handlers/ovn/host_networking.go, pkg/routeagent_driver/handlers/ovn/handler_test.go
getNextHopOnK8sMgmtIntf skips gateway-less network-address routes and accepts /32 and /128 host routes. Regression tests verify both behaviors and valid gateway selection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: ⚪ Minimal · up to 4f5cc

This localized fix rejects invalid network-address gateways and adds coverage for the behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested labels: bug, ready-to-test

Suggested reviewers: skitt, vthapar, oats87

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix to next-hop selection for the OVN management interface.
Linked Issues check ✅ Passed The changes address [#4121] by rejecting network addresses as gateways while preserving valid host-route selection.
Out of Scope Changes check ✅ Passed The implementation and regression tests remain within the scope of the gateway-selection fix described in [#4121].
Actionable Comments Resolved ✅ Passed The PR page marks the check passed: the sole actionable CodeRabbit comment is resolved; the diff adds /32-/128 handling and a Gw=nil host-route regression test.

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

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

@yboaron yboaron added the backport This change requires a backport to eligible release branches label Aug 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/routeagent_driver/handlers/ovn/host_networking.go`:
- Around line 183-187: The route filtering in getNextHopOnK8sMgmtIntf must skip
masked network-address routes without rejecting valid /32 or /128 host routes;
update pkg/routeagent_driver/handlers/ovn/host_networking.go#L183-L187
accordingly. Add a Gw == nil host-route case in
pkg/routeagent_driver/handlers/ovn/handler_test.go#L822-L895 and verify its
Dst.IP is selected after a network-address route is skipped.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b10259b-a5d4-4dfa-bc9f-10f20aff2dc4

📥 Commits

Reviewing files that changed from the base of the PR and between a5d2aba and e456685.

📒 Files selected for processing (2)
  • pkg/routeagent_driver/handlers/ovn/handler_test.go
  • pkg/routeagent_driver/handlers/ovn/host_networking.go

Comment thread pkg/routeagent_driver/handlers/ovn/host_networking.go Outdated
@yboaron
yboaron enabled auto-merge (squash) August 12, 2026 12:45
@yboaron
yboaron force-pushed the fix-ovn-gateway-network-address branch from e456685 to 216fa46 Compare August 12, 2026 13:08
The getNextHopOnK8sMgmtIntf() function would return Dst.IP
when no explicit gateway was set on a route. However, Dst.IP is the
network address (the base of the CIDR), not a valid host IP.

Fix: Added validation to skip routes where Dst.IP equals the network
address (IP & Mask == IP), but allow host routes (/32 or /128) where
Dst.IP is a valid host address.

Tests: Added test cases to verify:
1. Network addresses are rejected when route order changes
2. Host routes (/32 or /128) with Gw=nil are accepted

Addresses CodeRabbit review comment about preserving /32 and /128 routes.

Fixes: submariner-io#4121
Signed-off-by: Yossi Boaron <yboaron@redhat.com>
@yboaron
yboaron force-pushed the fix-ovn-gateway-network-address branch from 216fa46 to 4f5ccce Compare August 13, 2026 13:02
@yboaron yboaron added the ready-to-test When a PR is ready for full E2E testing label Aug 13, 2026
@yboaron

yboaron commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

cc @tpantelis

@yboaron
yboaron merged commit fb14c55 into submariner-io:devel Aug 17, 2026
57 checks passed
@submariner-bot

Copy link
Copy Markdown
Contributor

🤖 Closed branches: [z_pr4131/yboaron/fix-ovn-gateway-network-address]

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

Labels

backport This change requires a backport to eligible release branches backport-handled ready-to-test When a PR is ready for full E2E testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway health checks sometimes fail after ROKS node shutdown/reboot

3 participants