Skip to content

IPv6 interface filtering logic appears too permissive in findFirstValidIPv6Address() #4354

Description

@DanielWu-star

Which Component
Nacos Discovery, InetIPv6Utils

Describe the bug

While reviewing the IPv6 address discovery implementation, I noticed that the network interface filtering condition appears to be overly permissive:

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

This condition evaluates to true for most network interfaces.

For example:

isUp() | isVirtual() | isLoopback() | Result -- | -- | -- | -- false | false | false | true true | true | false | true true | false | true | true

As a result, interfaces that are down, virtual, or loopback may still be processed.

Compared with the previous implementation:

if (ifc.isUp()) {

the filtering logic appears to have been significantly relaxed.

I'm not sure whether this behavior is intentional or if the condition should use logical AND (&&) instead of OR (||).


Simplest demo

N/A

The issue was identified through source code analysis.


To Reproduce

  1. Review the implementation of findFirstValidIPv6Address().
  2. Observe the following condition:
if (ifc.isUp() || !ifc.isVirtual() || !ifc.isLoopback()) {
  1. Evaluate the condition against different network interface states.
  2. Notice that most interfaces pass the filter regardless of their operational state.

Expected behavior

Only valid network interfaces should be considered when searching for a usable IPv6 address.

For example:

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

or another equivalent filtering strategy.

If the current behavior is intentional, it would be helpful to clarify the rationale behind it.


Screenshots

N/A


Additional context

Current implementation:

private @Nullable InetAddress findFirstValidIPv6Address()

Previous implementation:

public InetAddress findFirstNonLoopbackIPv6Address()

The previous implementation only processed interfaces where:

if (ifc.isUp())

This issue was identified by comparing the old and new implementations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions