Repository navigation
feat(kernel): dispatch IPv6 frames to the NDP stack - #182
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #181, which audited
ipv6.rsand added the RFC 4861 hop-limitgate so the surface would be safe to expose. This exposes it.
Problem
ETHER_TYPE_IPV6has been defined in net.rs since the constant block waswritten, but the ethertype match never named it:
Every IPv6 frame fell through to
Err(NotImplemented), andipv6.rs— 1200+lines of parser, NDP neighbor cache and ICMPv6 — had no caller at all.
Changes
NetworkStackgains anIpv6Stack. Its address is not a new constructorparameter. RFC 4291 modified EUI-64 derives the
fe80::/64address from theMAC, so
macalready determines it; accepting a second, separately-suppliedvalue would only let the two disagree.
Ipv6Addr::link_local_from_macandIpv6Stack::newareconst fn, soNetworkStack::newstaysconst.handle_ipv6adapts the two calling conventions.Ipv6Stack::process_packetreturnsOption<usize>over a bare IPv6 datagram;the net.rs handlers return a framed length where 0 means "consumed, no reply".
A
NonebecomesOk(0), keeping every drop — malformed, forged, or simply notaddressed to us — out of the error channel, exactly as
handle_arpandhandle_ipv4already do. The datagram lands in a scratch buffer first becausethe Ethernet header must precede data whose length is not yet known; that is
the same shape
handle_icmp_packetuses.Tests
link_local_from_mac_follows_modified_eui64pins the derivation against thecanonical 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
Ipv6Stackbuilds the Neighbor Solicitation, so its checksum and hoplimit come from the same code that later validates them.
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 -- --checkcargo clippy --workspace -- -D warningscargo build --workspacecargo build -p oncrix-kernel --bin oncrix-kernel --target aarch64-unknown-nonecargo build -p oncrix-kernel --bin oncrix-kernel --target riscv64gc-unknown-none-elfbash scripts/run-tests.sh— 4596 passed, 0 skipped (kernel 359 → 362)Scope
Only the ICMPv6 paths
ipv6.rsalready implements become reachable: echorequest and Neighbor Solicitation/Advertisement. TCP and UDP over IPv6 remain
unhandled —
process_packetreturnsOk(None)for them, so they are droppedrather than misparsed.