Skip to content

[netif] verify unicast netlink ACKs and gate cache updates#3245

Draft
binarylogic wants to merge 4 commits intoopenthread:mainfrom
binarylogic:netif-unicast-ack
Draft

[netif] verify unicast netlink ACKs and gate cache updates#3245
binarylogic wants to merge 4 commits intoopenthread:mainfrom
binarylogic:netif-unicast-ack

Conversation

@binarylogic
Copy link
Copy Markdown

Summary

This PR hardens Linux unicast netif handling by tying cache mutation to verified netlink outcomes.

Problem

UpdateIp6UnicastAddresses() previously updated mIp6UnicastAddresses optimistically, without confirming whether the kernel accepted each unicast add/remove request.
When RTNETLINK rejected a request, OTBR cache could diverge from kernel state.

Changes

  • Unicast address updates now verify the matching netlink ACK by request sequence.
  • ACK wait is bounded by an absolute timeout deadline.
  • ACK parsing validates nlmsgerr payload length before dereference.
  • Transient recv() interruptions (EINTR, EAGAIN, EWOULDBLOCK) are retried while waiting.
  • Idempotent outcomes are treated as success:
    • add: EEXIST
    • remove: ENOENT, EADDRNOTAVAIL
  • UpdateIp6UnicastAddresses() now mutates local cache only for operations that succeeded.

Why this is safe

  • Successful paths preserve existing behavior.
  • Failure handling is stricter and prevents cache/kernel drift.
  • Timeout handling avoids indefinite wait on unrelated netlink traffic.

Validation

  • clang-format check (LLVM 19) on modified files.
  • git diff --check clean.
  • Linux CI/runtime validation is still required for full end-to-end netlink path verification.

Fixes #3244

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 2, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 resolves a critical issue where the OpenThread Border Router (OTBR) cache could diverge from the Linux kernel's network interface state. Previously, unicast IPv6 address updates were optimistically applied to the local cache without confirming the kernel's acceptance via netlink responses. This change hardens the netif handling by introducing a robust mechanism to verify netlink ACKs for unicast address additions and removals, ensuring that the local cache accurately reflects the kernel's state and preventing inconsistencies.

Highlights

  • Netlink ACK Verification: Implemented robust verification of netlink ACKs for unicast IPv6 address additions and removals to ensure kernel operations are confirmed.
  • Timeout Mechanism: Introduced a bounded timeout for waiting on netlink ACKs, preventing indefinite waits and improving system responsiveness.
  • Error Handling and Idempotency: Enhanced netlink error parsing by validating payload length and treating idempotent outcomes (e.g., EEXIST for add, ENOENT/EADDRNOTAVAIL for remove) as successful operations.
  • Cache Synchronization: Modified the local cache (mIp6UnicastAddresses) to only reflect changes that have been successfully acknowledged by the kernel, preventing divergence between OTBR's state and the actual network interface configuration.
  • Transient Error Retries: Added retry logic for transient recv() interruptions (EINTR, EAGAIN, EWOULDBLOCK) during netlink communication, improving reliability.

🧠 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.

Changelog
  • src/host/posix/netif.cpp
    • Refactored UpdateIp6UnicastAddresses to use a temporary updatedUnicastAddresses vector to manage pending changes.
    • Modified UpdateIp6UnicastAddresses to conditionally update the mIp6UnicastAddresses member based on the otbrError returned by ProcessUnicastAddressChange.
    • Added warning logs for failed unicast address additions or removals, providing better diagnostic information.
  • src/host/posix/netif.hpp
    • Updated the signature of ProcessUnicastAddressChange to return otbrError, allowing for explicit error propagation.
  • src/host/posix/netif_linux.cpp
    • Included <poll> and <chrono> headers to support timeout and polling functionality for netlink operations.
    • Changed ProcessUnicastAddressChange to return otbrError, aligning with the updated header definition.
    • Implemented a netlink ACK verification loop with a kNetlinkAckTimeoutMs (1000ms) deadline to ensure timely responses.
    • Utilized poll() to wait for netlink responses, incorporating retry logic for EINTR to handle signal interruptions gracefully.
    • Processed received netlink messages, verifying sequence numbers and message types to match the original request.
    • Validated nlmsgerr payload length before dereferencing to prevent potential memory access issues.
    • Interpreted specific kernel errors (EEXIST for add, ENOENT, EADDRNOTAVAIL for remove) as successful idempotent operations.
    • Added detailed error logging for netlink failures, including the specific errno.
  • src/host/posix/netif_unix.cpp
    • Modified ProcessUnicastAddressChange to return otbrError, aligning with the updated header definition.
    • Provided a default success return (OTBR_ERROR_NONE) for ProcessUnicastAddressChange on non-Linux platforms, maintaining compatibility.
Activity
  • No human activity has been recorded on this pull request since its creation.
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

@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 significantly improves the robustness of unicast address management on Linux by verifying netlink acknowledgements before mutating the internal address cache. This prevents state divergence between the border router and the kernel. The implementation is well-done, with careful handling of timeouts, transient errors, and idempotent operations. I have one suggestion to improve the efficiency of the address removal logic in netif.cpp.

Comment thread src/host/posix/netif.cpp Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 65.30612% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.95%. Comparing base (2b41187) to head (7af0fe0).
⚠️ Report is 1387 commits behind head on main.

Files with missing lines Patch % Lines
src/host/posix/netif_linux.cpp 44.68% 21 Missing and 5 partials ⚠️
tests/gtest/test_netif.cpp 72.72% 6 Missing ⚠️
src/host/posix/netif.cpp 93.10% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3245       +/-   ##
===========================================
- Coverage   55.77%   34.95%   -20.83%     
===========================================
  Files          87      145       +58     
  Lines        6890    17859    +10969     
  Branches        0     1483     +1483     
===========================================
+ Hits         3843     6242     +2399     
- Misses       3047    11286     +8239     
- Partials        0      331      +331     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[netif] keep unicast cache aligned with netlink ACK results

1 participant