Skip to content

IPv4 routing table: add() ignores netmask and ifconfig leaves stale connected routes #774

Closed

Description

@LSantha

Summary

Two related routing-table hygiene defects that became easy to hit once ifconfig started installing a connected route:

  1. IPv4RoutingTable.add() de-duplicates on destination + gateway + device and ignores the netmask, so adding a route with a different prefix silently replaces the existing one.
  2. Ifconfig.setDefault() never removes the previous connected route, so re-addressing an interface leaves the old subnet route up.

Steps to Reproduce

1. add() ignores the netmask

# ifconfig eth-pci(0,3,0) 10.0.2.15 255.255.255.0
# route
10.0.2.0  -  255.255.255.0  -  null  -  U  -  0  -  eth-pci(0,3,0)
# route -a 10.0.2.0/16 eth-pci(0,3,0)
# route
10.0.2.0  -  255.255.0.0  -  null  -  U  -  0  -  eth-pci(0,3,0)

The /16 replaced the /24 connected route. The table now has no route for the rest of the /24 subnet.

2. ifconfig leaves the old connected route up

# ifconfig eth-pci(0,3,0) 10.0.2.15 255.255.255.0
# ifconfig eth-pci(0,3,0) 10.0.3.15 255.255.255.0
# route
10.0.2.0  -  255.255.255.0  -  null  -  U  -  0  -  eth-pci(0,3,0)
10.0.3.0  -  255.255.255.0  -  null  -  U  -  0  -  eth-pci(0,3,0)

Both connected routes are present. IPv4RoutingTable.search() now uses longest-prefix match with a gateway tie-break at equal prefix length, so with two /24s present the winner between them is decided by insertion order rather than by anything meaningful.

Expected Behavior

  • Adding a route with an explicit prefix creates a second entry rather than replacing one with a different prefix.
  • Re-addressing an interface removes the connected route for its previous address/mask.

Actual Behavior

Both routes are silently clobbered as described above.

Root Cause

  1. net/src/net/org/jnode/net/ipv4/IPv4RoutingTable.java - add() compares destination, gateway and device but not getSubnetmask().
  2. net/src/net/org/jnode/net/ipv4/config/impl/Ifconfig.java - addConnectedRoute() only ever adds.

Notes

Found while reviewing #770.

Environment

  • Commit: 0b1055d (PR IPv4 routing fixes: connected routes, LPM, route prefix support #770 branch opencode/issue768-20261016180433)
  • Host JDK: openjdk version "1.8.0_504"
  • Build target: cd-x86-lite
  • Bitness: 32-bit
  • Run: qemu-system-x86_64 -cdrom all/build/cdroms/jnode-x86-lite.iso -m 1G -nographic
  • ISO: all/build/cdroms/jnode-x86-lite.iso
  • Boot reached System has finished: yes

Related: #768, #770

Triage Addendum (auto, 2026-10-16)


✅ Ticket Runner Status

Field Value
Phase DONE
Turn 1/3
Retries 0/3
PR #776
Review in progress no
Started 2026-10-16T18:42:20.717Z

Activity

  1. added
    kind/bugConfirmed bug report with a repro or stack trace.
    area/netnet/ — network stack, sockets, ARP, IPv4, DNS, Ethernet.
    on Oct 16, 2026
  2. LSantha commented on Oct 16, 2026

    @LSantha
    OwnerAuthor

    /oc triage issue #774

    Triage run ONLY. Load the jnode-triage-issue skill and obey it. Output is exactly one ## Triage comment plus kind/area label edits. FORBIDDEN in this run: git checkout -b, git push, gh pr create, any branch, any PR. Audit kind/area labels (correct mislabels), assess repro-sufficiency, estimate blast radius, post one ## Triage comment (clear shape when actionable, vague shape with the needs-info literals only when human input is truly required).

  3. LSantha commented on Oct 16, 2026

    @LSantha
    OwnerAuthor

    Triage

    github run

  4. LSantha commented on Oct 16, 2026

    @LSantha
    OwnerAuthor

    /oc Please proceed with this task.

  5. LSantha commented on Oct 16, 2026

    @LSantha
    OwnerAuthor

    🤖 Partially fixed. Commit 16fb65274 on opencode/issue774-20261016184429.

    Defect 1 — fixed. IPv4RoutingTable.add() now includes getSubnetmask() in the dedup key (net/src/net/org/jnode/net/ipv4/IPv4RoutingTable.java:69), so adding 10.0.2.0/16 next to an existing 10.0.2.0/24 on the same device creates a second entry instead of clobbering the first. New net/src/test/org/jnode/net/ipv4/IPv4RoutingTableTest.java (registered in AllTests) covers same-dest-different-mask, same-dest-same-mask-different-device, same-dest-same-mask-different-gateway, replacement of an identical route, and idempotent re-add.

    sh build.sh -f net/build-tests.xml all-junit → Tests run: 28, Failures: 0, Errors: 0. Verified non-vacuous: reverting only the add() change makes testAddKeepsRouteWithSameDestinationAndDifferentMask fail.

    Defect 2 — not in this change. Ifconfig.addConnectedRoute() does not exist on master; it arrives with #768/#770, so there is no stale-connected-route behaviour to fix here and nothing to boot-test (the route -a 10.0.2.0/16 repro syntax is also #768's IPv4NetworkArgument). This matches the triage split: defect 1 lands standalone, defect 2 follows #770.

    Notes for whoever picks up defect 2 after #770 merges:

    • addrInfo.getSubnetMask(previousAddress) before setDefaultAddress() gives the mask needed to build the old connected route.
    • IPv4RoutingTable.remove() is Vector.remove(Object) and IPv4Route has no equals(), so remove(new IPv4Route(...)) is a no-op. removeConnectedRoute() has to locate the existing instance (iterate entries() and match on destination/mask/device) or IPv4Route needs equals()/hashCode().

    Related: #768, #770

  6. LSantha commented on Oct 16, 2026

    @LSantha
    OwnerAuthor

    Created PR #776

    github run

  7. added
    agent/doneThe agent finished successfully; PR opened or comment posted.
    on Oct 16, 2026
  8. added a commit that references this issue on Oct 16, 2026
  9. LSantha commented on Oct 20, 2026

    @LSantha
    OwnerAuthor

    /run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/doneThe agent finished successfully; PR opened or comment posted.area/netnet/ — network stack, sockets, ARP, IPv4, DNS, Ethernet.kind/bugConfirmed bug report with a repro or stack trace.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions