Skip to content

feat(kernel): dispatch IPv6 frames to the NDP stack - #182

Merged
kernalix7 merged 1 commit into
mainfrom
feat/wire-ipv6-dispatch
Aug 12, 2026
Merged

kernalix7 merged 1 commit into
mainfrom
feat/wire-ipv6-dispatch

Conversation

@kernalix7

Copy link
Copy Markdown
Owner

Follow-up to #181, which audited ipv6.rs and added the RFC 4861 hop-limit
gate so the surface would be safe to expose. This exposes it.

Problem

ETHER_TYPE_IPV6 has been defined in net.rs since the constant block was
written, but the ethertype match never named it:

match eth.ether_type {
    ETHER_TYPE_ARP  => self.handle_arp(&eth, payload, reply_buf),
    ETHER_TYPE_IPV4 => self.handle_ipv4(&eth, payload, reply_buf),
    _ => Err(Error::NotImplemented),
}

Every IPv6 frame fell through to Err(NotImplemented), and ipv6.rs — 1200+
lines of parser, NDP neighbor cache and ICMPv6 — had no caller at all.

Changes

NetworkStack gains an Ipv6Stack. Its address is not a new constructor
parameter. RFC 4291 modified EUI-64 derives the fe80::/64 address from the
MAC, so mac already determines it; accepting a second, separately-supplied
value would only let the two disagree. Ipv6Addr::link_local_from_mac and
Ipv6Stack::new are const fn, so NetworkStack::new stays const.

handle_ipv6 adapts the two calling conventions.
Ipv6Stack::process_packet returns Option<usize> over a bare IPv6 datagram;
the net.rs handlers return a framed length where 0 means "consumed, no reply".
A None becomes Ok(0), keeping every drop — malformed, forged, or simply not
addressed to us — out of the error channel, exactly as handle_arp and
handle_ipv4 already do. The datagram lands in a scratch buffer first because
the Ethernet header must precede data whose length is not yet known; that is
the same shape handle_icmp_packet uses.

Tests

link_local_from_mac_follows_modified_eui64 pins the derivation against the
canonical RFC 4291 Appendix A vector, including that the universal/local bit is
inverted rather than set. That is the usual way to get EUI-64 wrong, and it
would surface only as neighbor discovery quietly failing on the wire.

The two net.rs tests drive a full exchange rather than a hand-rolled packet: a
peer Ipv6Stack builds the Neighbor Solicitation, so its checksum and hop
limit come from the same code that later validates them.

ipv6_frame_answers_neighbor_solicitation       ok
ipv6_frame_with_forwarded_hop_limit_is_dropped ok

The first asserts the frame comes back as a Neighbor Advertisement addressed to
the solicitor, with its MAC learned. The second sends that identical frame with
hop limit 64 and asserts Ok(0) plus an untouched neighbor cache — proving the
#181 gate survives the wiring. The checksum is deliberately left intact there,
since the hop limit is not part of the ICMPv6 pseudo-header, so the test
isolates the gate rather than the checksum.

Verification

  • cargo fmt --all -- --check
  • cargo clippy --workspace -- -D warnings
  • cargo build --workspace
  • cargo build -p oncrix-kernel --bin oncrix-kernel --target aarch64-unknown-none
  • cargo build -p oncrix-kernel --bin oncrix-kernel --target riscv64gc-unknown-none-elf
  • bash scripts/run-tests.sh — 4596 passed, 0 skipped (kernel 359 → 362)

Scope

Only the ICMPv6 paths ipv6.rs already implements become reachable: echo
request and Neighbor Solicitation/Advertisement. TCP and UDP over IPv6 remain
unhandled — process_packet returns Ok(None) for them, so they are dropped
rather than misparsed.

`ETHER_TYPE_IPV6` has been defined in net.rs since the constant block was
written, but the ethertype match never named it, so every IPv6 frame fell
through to `Err(NotImplemented)` and `ipv6.rs` had no caller at all.

Wire it up:

- `NetworkStack` gains an `Ipv6Stack`. Its address is not a new constructor
  parameter: RFC 4291 modified EUI-64 derives the `fe80::/64` address from the
  MAC, so `mac` already determines it and accepting a second value would only
  let the two disagree. `Ipv6Addr::link_local_from_mac` and `Ipv6Stack::new`
  are `const fn` so `NetworkStack::new` stays const.

- `handle_ipv6` adapts the two calling conventions. `Ipv6Stack::process_packet`
  returns `Option<usize>` over a bare IPv6 datagram; the net.rs handlers return
  a framed length with 0 meaning "consumed, no reply". A `None` therefore
  becomes `Ok(0)`, which keeps every drop — malformed, forged, or simply not
  for us — out of the error channel, matching `handle_arp` and `handle_ipv4`.
  The datagram is built in a scratch buffer first because the Ethernet header
  has to precede data whose length is not yet known, the same shape
  `handle_icmp_packet` already uses.

Three tests. `link_local_from_mac_follows_modified_eui64` pins the derivation,
including that the universal/local bit is inverted rather than set — the usual
way to get EUI-64 wrong, and one that would surface only as neighbor discovery
quietly failing on the wire.

The two net.rs tests drive a full exchange: a peer `Ipv6Stack` builds the
Neighbor Solicitation, so its checksum and hop limit come from the same code
that later validates them, and the frame comes back as a Neighbor
Advertisement addressed to the solicitor with its MAC learned.
`ipv6_frame_with_forwarded_hop_limit_is_dropped` sends that identical frame
with hop limit 64 and asserts `Ok(0)` and an untouched cache, proving the
RFC 4861 gate added in #181 survives the wiring. The checksum is deliberately
left intact there — the hop limit is not in the ICMPv6 pseudo-header — so the
test isolates the gate rather than the checksum.

Suite: 4596 passed, 0 skipped.
@kernalix7
kernalix7 merged commit 67ceb9a into main Aug 12, 2026
3 checks passed
@kernalix7
kernalix7 deleted the feat/wire-ipv6-dispatch branch August 12, 2026 18:30
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.

1 participant