-
Notifications
You must be signed in to change notification settings - Fork 29
Low-level networking #15
Comments
I think the amount of focus depends entirely on who gets involved! For Rust 2018 the main goal is async/await and layers above it, but with enough interest we could pursue other layers in parallel. |
Makes sense. I'm definitely interested in helping however I can with this group, but as a whole I tend to be more interested in the lower-level layers of the stack. |
Low-Level Networking should ideally be a sub-group of this WG |
Agreed, I'm very interested in this! |
I'm interested in this from the embedded side, hoping to be able to build up an asynchronous network stack all the way from the hardware to the application service. |
In this sub-group protocols will mainly refer to IP,TCP,ARP,BGP,etc - I'm sure those common crates and components would be really useful in embedded space too |
At Cloudflare we've begun using Rust for a major project at L3/L4. I'm interested in helping contribute in whatever way I can. |
@bubaflub anyone that has the muscle to solve this issue comprehensively would unlock so much potential: tokio-rs/mio#839 |
What do we need libcap for? I'm working on mio-afpacket which adds support for raw sockets on linux. The same can be done for other platforms. I also plan to add tokio shim on top of it. |
Hi, main author of libpnet here. I'm not sure that I'll have time to follow the thread/WG, but I'll do a quick braindump/retrospective of my experience and thoughts with libpnet, Rust, and low-level networking, and try to answer any questions. libpnet
Datalink/Layer 2This is what I would consider most mature in libpnet. It provides a cross-platform abstraction for synchronous datalink programming on Windows, Linux, assorted BSDs, and macOS. It has no problem saturating dual-10G links (I did not have the hardware to test beyond that). The Good
The Bad
The Ugly
Streaming iteratorsAs an aside, in my opinion, to do good synchronous low level networking, you need streaming iterators. The abstraction "this set of bytes is valid until the end of the block" is incredibly powerful, and enables safe zero-copy networking. Network/Transport Layers 3/4Don't even bother. The Good
The Bad and Ugly
Packet abstractionsThese are great, but I would not do what libpnet does again. The Good
The Bad/Ugly
What I would do next timeI think a more sensible approach for a packet abstraction is to not write Rust. I would propose a rust-like DSL, which compiles to Rust, and gives a scapy-level experience. There should be minimal magic. libpnet's packet code generates lots of traits and implementations, which people find confusing. I have a lot more thoughts on this, but I will save them for another time. AsyncThis is a thing everyone wants. When I started libpnet, Rust's story was "we use green threads". Then it was "we do zero overhead abstractions". For libpnet, I settled on synchronous, blocking networking. This is great for when you are handling millions of packets per second - you don't want or need the overhead of a full async runtime. It's not so great for anything else. I haven't spent much time on how to implement this - no doubt it's different for each platform. It looks like @polachok is working on Linux support for this, he might be a better person to ask. BSDs/macOS follow an everything is a file approach, so I imagine the code is similar to async file handling. libpnet would need a big overhaul to support async well. DocumentationAs a general rule, documentation for anything low-level networking is sparse and conflicting at best. There are a few good resources around, they tend to be hard to find though. I would hope that any Rust work in this area would fix that ;) Let me know if I can be of any more use/lend any further insight. |
@polachok Windows doesn't support raw sockets, so at least for it we would need a solution that integrates with |
@stephanbuys Since you brought it up, I'll expand on some technical details for L2 networking. NativeLinuxLinux exposes L2 networking through the standard Berkeley socket APIs, with BSDs/macOSThese platforms take the unix-y "everything is a file" approach. You open either Non-nativeWindowsWindows does not support L2 networking out of the box. It requires a driver to do it. Usually this will be WinPcap or Npcap, but you can write your own. These function very similarly to BPF for sending/receiving, but the set up is rather different. libpcaplibpcap is what you would usually reach for in the C world. It already supports every platform which I mention here, and would mean we only need to target a single API. The main downside is that you cannot (last time I checked) reach the same level of performance as is otherwise possible (with eg. netmap/DPDK). netmap/DPDK/pf_ringThere are a bunch of userspace networking libraries which cut out the middle man and work directly with the NIC (ish, library dependent). These typically enable you to process packets at line speed on serious hardware (40G/100G). Their APIs vary quite a bit - but obviously don't conform to anything that looks like the file/socket APIs. I believe they all offer versions of libpcap, but take a performance hit when doing so. The platform support also varies. See also:
Long story short - this needs to be implemented very differently on every platform, unless pcap is targetted. |
@mrmonday great summary!
@stephanbuys agreed, that sounds great!
@Nemo157 You may be interested in smoltcp-rs/smoltcp#208. |
I'm very interested in the low level networking topics. |
@stephanbuys A better approach in my opinion would be to implement platform APIs in rust via C FFI when possible (AF_PACKET on linux, bpf on bsd/osx, pcap on windows) and create an umbrella crate which would choose appropriate way for the platform via #cfg. This approach would allow both advanced users (who know what kind of options do they want to set) and newcomers (who want an easy to use cross-platform interface) to benefit. |
As the author of a QUIC implementation I'm interested. Though QUIC does not require raw sockets in any sense as it's implemented atop UDP, an implementation has much in common with a TCP stack. |
Is/will this working group be focused on the lower-level layers of the network stack (e.g. projects like libpnet and smoltcp)? If so are there particular areas that are of interest? There may be some overlap with the embedded-wg here.
The text was updated successfully, but these errors were encountered: