ruvix-net
Minimal networking stack for the RuVix Cognition Kernel (ADR-087 Phase E).
Overview
This crate provides a complete no_std networking stack suitable for embedded systems and OS kernels. It implements:
- Ethernet II frame handling
- ARP address resolution with cache management
- IPv4 routing and header processing
- UDP datagram transport
- ICMP echo (ping) support
Architecture
+------------------+
| Application | UDP send/receive
+------------------+
|
+------------------+
| NetworkStack | Coordinates all layers
+------------------+
|
+--------+---------+
| | |
v v v
+------+ +-------+ +------+
| UDP | | ICMP | | ARP |
+------+ +-------+ +------+
| | |
v v v
+------------------+
| IPv4 | Routing, TTL, checksum
+------------------+
|
+------------------+
| Ethernet | Frame encapsulation
+------------------+
|
+------------------+
| NetworkDevice | Hardware abstraction
+------------------+
Features
std- Enable standard library supportalloc- Enable heap allocation via the alloc crate
By default, the crate is #![no_std] compatible with zero heap allocations.
Usage
use ;
// Create a network device (or use your own hardware driver)
let device = new;
// Configure the stack
let config = StackConfig ;
// Create the network stack
let mut stack = new;
// Send a UDP datagram
let result = stack.send_udp;
// Receive packets
let mut buf = ;
if let Ok = stack.receive
Layer Details
Ethernet (ethernet.rs)
MacAddress- 6-byte hardware address with broadcast/multicast detectionEthernetFrame- Parsing and serialization of Ethernet II framesEtherType- Protocol identifiers (IPv4, ARP, IPv6)
ARP (arp.rs)
ArpPacket- ARP request/reply packet handlingArpCache- Fixed-size cache with timeout-based eviction- Supports Ethernet/IPv4 address resolution
IPv4 (ipv4.rs)
Ipv4Addr- 4-byte IP address with classification methodsIpv4Header- Full header parsing with checksum verificationProtocol- Transport protocol identifiers (UDP, TCP, ICMP)
UDP (udp.rs)
UdpHeader- Datagram header with pseudo-header checksumUdpSocket- Minimal socket abstraction for binding and sending
ICMP (icmp.rs)
IcmpHeader- Generic ICMP message handlingIcmpEcho- Echo request/reply (ping) supportIcmpDestUnreachable,IcmpTimeExceeded- Error messages
Device (device.rs)
NetworkDevicetrait - Hardware abstraction for send/receiveLoopbackDevice- Testing device that echoes framesNullDevice- Discard device for testing
Stack (stack.rs)
NetworkStack- Integrated network stack combining all layersStackConfig- IP address, gateway, and behavior settings- Automatic ARP resolution and ICMP echo handling
Network Device Trait
To integrate with actual hardware, implement the NetworkDevice trait:
use ;
Memory Usage
The stack is designed for constrained environments:
- ARP Cache: 64 entries x ~24 bytes = ~1.5 KB
- No heap allocation in default configuration
- Fixed buffers for packet processing
Error Handling
All operations return NetResult<T> which is Result<T, NetError>. Error types include:
PacketTooShort- Truncated packetInvalidEthernetFrame- Malformed Ethernet headerIpv4ChecksumError- IPv4 checksum mismatchArpNotFound- Destination MAC not in cacheUdpChecksumError- UDP checksum mismatch- And more...
Testing
License
MIT OR Apache-2.0