Skip to content

VMNetworkInterface: require both IFF_UP and IFF_RUNNING in isUp() - #78

Merged
guillerodriguez merged 1 commit into
masterfrom
fix/vmnetworkinterface-isup-flags
Oct 22, 2026
Merged

guillerodriguez merged 1 commit into
masterfrom
fix/vmnetworkinterface-isup-flags

Conversation

@guillerodriguez

Copy link
Copy Markdown
Contributor

NetworkInterface.isUp() should return true when the interface is "up and running", so IFF_UP and IFF_RUNNING must both be set. The current implementation returns true when either flag is set. Fix it by requiring both flags, also matching what OpenJDK does.

On Haiku, where there is no IFF_RUNNING, use IFF_LINK instead. Commit c74aac5 avoided this because IFF_LINK can be set even when the interface is down. Now that both flags are required, IFF_UP combined with IFF_LINK means "up and running" as intended.

Fail compilation on other platforms that lack IFF_RUNNING.

Fixes #77 (BZ#42817)

NetworkInterface.isUp() should return true when the interface is
"up and running", so IFF_UP and IFF_RUNNING must both be set. The
current implementation returns true when either flag is set. Fix
it by requiring both flags, also matching what OpenJDK does.

On Haiku, where there is no IFF_RUNNING, use IFF_LINK instead.
Commit c74aac5 avoided this because IFF_LINK can be set even
when the interface is down. Now that both flags are required,
IFF_UP combined with IFF_LINK means "up and running" as intended.

Fail compilation on other platforms that lack IFF_RUNNING.

Fixes #77 (BZ#42817)

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
@guillerodriguez

Copy link
Copy Markdown
Contributor Author

@duncanmcqueen if you could re-run the checks from #75 (comment) on Haiku, that would be great.

This should fix the "interface up, cable disconnected" case:

Case IFF_UP only (prev) IFF_UP + IFF_LINK (new)
0. Up and connected up=true up=true
1. Down, cable connected up=false up=false
2. Up, cable disconnected up=true up=false
3. Loopback up=true up=true

@duncanmcqueen

Copy link
Copy Markdown
Contributor

I did the checks from #75 again on Haiku (hrev60228 x86_64, QEMU e1000) with this pull request (f622f62). The java-net library compiles with no errors. For case 2, I used the QEMU monitor command set_link e1000.0 off to disconnect the cable. A small C program shows the SIOCGIFFLAGS flags.

Case Flags NetBasics
0. Up and connected 0x3003 UP=1 LINK=1 up=true
1. Down, cable connected 0x3002 UP=0 LINK=1 up=false
2. Up, cable disconnected 0x2003 UP=1 LINK=0 up=false
3. Loopback 0x1009 UP=1 LINK=1 up=true

The socket test passed in all cases. The results are the same as your table. After I connected the cable again, the flags were 0x3003 again.

(I used Claude Code, an AI tool, to help with these tests and this comment.)

@guillerodriguez

Copy link
Copy Markdown
Contributor Author

@duncanmcqueen Thanks!

@guillerodriguez
guillerodriguez merged commit 5f867b7 into master Oct 22, 2026
3 checks passed
@guillerodriguez
guillerodriguez deleted the fix/vmnetworkinterface-isup-flags branch October 31, 2026 10:34
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.

NetworkInterface.isUp bug

3 participants