Skip to content

fix(nacos): correct network interface filter logic in InetIPv6Utils#4355

Open
DanielWu-star wants to merge 1 commit into
alibaba:2025.1.xfrom
DanielWu-star:fix/ipv6-network-interface-filter-logic
Open

fix(nacos): correct network interface filter logic in InetIPv6Utils#4355
DanielWu-star wants to merge 1 commit into
alibaba:2025.1.xfrom
DanielWu-star:fix/ipv6-network-interface-filter-logic

Conversation

@DanielWu-star

Copy link
Copy Markdown

Describe what this PR does / why we need it

The current IPv6 interface filtering logic in findFirstValidIPv6Address() uses:

if (ifc.isUp() || !ifc.isVirtual() || !ifc.isLoopback())

This condition evaluates to true for most network interfaces, including interfaces that are down, virtual, or loopback.

As a result, the filtering logic appears to be much less restrictive than intended when selecting a valid IPv6 address.

This PR refines the interface filtering condition to only consider active, non-virtual, and non-loopback interfaces during IPv6 address discovery.

Does this pull request fix one issue?

Fix #4354

Describe how you did it

Replaced:

if (ifc.isUp() || !ifc.isVirtual() || !ifc.isLoopback())

with:

if (ifc.isUp() && !ifc.isVirtual() && !ifc.isLoopback())

This aligns the interface filtering behavior with the method's purpose of discovering a valid IPv6 address from usable network interfaces.

Describe how to verify it

  1. Build and run the project with IPv6 enabled.
  2. Create multiple network interfaces with different states (up/down, virtual/non-virtual, loopback/non-loopback).
  3. Invoke IPv6 address discovery.
  4. Verify that only active, non-virtual, and non-loopback interfaces are considered.
  5. Confirm that IPv6 address selection still works correctly for normal network configurations.

Special notes for reviews

This change was proposed based on the discussion in #4354.

If the current behavior is intentional, please let me know and I can further investigate the original design rationale.

The network interface filter condition in findFirstValidIPv6Address()
incorrectly used OR (||) operators instead of AND (&&) operators.

Current behavior:
  if (ifc.isUp() || !ifc.isVirtual() || !ifc.isLoopback())
This means any interface that is UP, OR non-virtual, OR non-loopback
would pass the filter, which allows DOWN/virtual/loopback interfaces
to be incorrectly selected.

Expected behavior:
  if (ifc.isUp() && !ifc.isVirtual() && !ifc.isLoopback())
The interface should only be selected when ALL conditions are met:
it is UP, NOT virtual, AND NOT a loopback interface.
@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

IPv6 interface filtering logic appears too permissive in findFirstValidIPv6Address()

2 participants