The kernel features that make raw Ethernet fast and precise, behind an API that is hard to misuse.
Filtered in the kernel
An EtherType set, untagged, 802.1Q, 802.1ad or double-tagged, compiles to classic BPF. The filter is attached before the socket is bound, so no unwanted frame is ever queued. You can also bring your own program and test it without a kernel.
Filtering framesZero-copy receive
A TPACKET_V3 ring hands out frames borrowed from shared memory. The borrow ends at the next receive, enforced by the compiler, and the steady-state loop makes no allocations.
Receiving framesTimestamps that say whose they are
Received and transmitted frames carry their timestamp and which clock made it, the NIC's or the kernel's; transmit timestamps come back matched to their frame by id, with the PTP hardware clock behind the interface. Safe next to ptp4l.
TimestampsVLAN tags as on the wire
Many drivers strip the 802.1Q tag into metadata. rawether puts it back in place, in head-room the ring reserves, so your parser sees the frame as it was sent.
VLAN tagsFrames without index arithmetic
p.frame() gives you the addresses, up to two VLAN tags, the EtherType and the payload, and returns nothing instead of panicking on a short frame. FrameBuilder writes frames into a reused buffer, padded to the minimum.
Reading the headerBatched and timed send
sendmmsg sends up to 64 frames per system call. SO_TXTIME launch times feed etf and taprio, and missed deadlines are counted, not lost silently.
Launch-time transmissionDrops are counted
stats() keeps a running total of the kernel's received and dropped counters, so a full ring shows up as a number instead of a silent gap.
Counting dropsAny event loop
AsFd and AsRawFd, non-blocking mode, timed and blocking receive. Plugs into poll, mio or tokio without an async dependency in the crate.
Event loops and asyncLeast privilege
Grant CAP_NET_RAW to the binary, not root. drop_capabilities() sheds every capability for the whole process once the sockets are open, or refuses if a thread would keep one. Every descriptor is close-on-exec.
Threat modelTested on a real kernel
Kernel behaviour is checked in CI on Linux, macOS and FreeBSD, from drops under load to links going down; the parsers run under Miri and a fuzzer. The block ring receives 2.8 M frames/s over veth, 1.8× libpcap; the frame ring answers in 15 µs.
Performance