denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.66k stars 5.25k forks source link

Support Raw Sockets and Datalinks (Layer 3/2) #5709

Open hazae41 opened 4 years ago

hazae41 commented 4 years ago

Since UDP and Unix sockets are implemented, and since Deno is now released, we could plan to add raw sockets (layer 3) and datalink (layer 2) support.

Tokio does not implement them, but I found some methods in tokio/mio

These methods are syscalls to socket We can use them with the domain AF_INET or AF_INET6 (for IP packets) or AF_PACKET (for datalink packets) and the type SOCK_RAW in order to add the features to tokio/mio and then to deno

Otherwise, we could use libpnet, which already implements the features, but may not be as good as Tokio

bartlomieju commented 4 years ago

@hazae41 do you have some specific use case in mind? I'm not sure if exposing Mio structures would be very useful, but I want to be proved wrong.

hazae41 commented 4 years ago

I think any low-level feature would be good for Deno because it would permit the usage of both web technologies and low-level technologies at one place.

This would permit web developers to get started with low-level stuff without having to learn C, and maybe allow them to get started with IoT.

It could also be very useful for small use cases where we want to focus on flexibility and simplicity rather than performances, like proof-of-concepts, small hacks, tutorials, etc.

I think implementing layers 2&3 may be the first step into the low-level world.

callionica commented 3 years ago

I am attempting to build a filtering/forwarding network appliance that combines a DNS server with Ethernet packet routing. The idea is that when a packet comes in, the IP destination is extracted and compared to the DNS data (and permissions) to ensure that only traffic to IPs with permitted domains is forwarded to the gateway. (Providing only DNS filtering without the packet forwarding part would allow apps to bypass the filtering simply by using IP addresses instead of names).

I think my filter needs access to low level sockets, so there's a use case for you. (But if you can see some other way to implement, do let me know).