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:
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
-
Review the implementation of
findFirstValidIPv6Address().
-
Observe the following condition:
if (ifc.isUp() || !ifc.isVirtual() || !ifc.isLoopback()) {
-
Evaluate the condition against different network interface states.
-
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:
This issue was identified by comparing the old and new implementations.
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:
This condition evaluates to
truefor most network interfaces.For example:
As a result, interfaces that are down, virtual, or loopback may still be processed.
Compared with the previous implementation:
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
findFirstValidIPv6Address().Expected behavior
Only valid network interfaces should be considered when searching for a usable IPv6 address.
For example:
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:
Previous implementation:
The previous implementation only processed interfaces where:
This issue was identified by comparing the old and new implementations.