Live data from Hacker News

What happens if you write a TCP stack in Python?

jvns.ca

121–125 of 125 posts

Re: What happens if you write a TCP stack in Python?

#121
What if every python virtual machine had a full TCP/IP stack?

IPv6 has enough address space. Object storage takes care of disk access. Generally it might be way less efficent? What would the OS look like? It seems like a lot of OS services would disappear? You'd have a cloud of processes. Each process vm would be like a cell in a body. Maybe each process vm would load an auth module. Or not.

Re: What happens if you write a TCP stack in Python?

#122

Earlier quoted context omitted.

I'd like to see you bit-bang a 10MHz signal with an 8 MHz clock. You'd need something substantially faster (Nyquist and such).

TCP != ethernet. A TCP stack can run over serial and othe link layers (PPP, SLIP, etc). PPP is absolutely doable on very small microcontrollers.

Problem is that using PPP or SLIP doesn't relieve you from having to implement at least some kind of crude TCP stack.

But if you use TCP offloading, then you can communicate using TCP as cheaply as doing any traditional serial communication. I've seen those crude TCP stack implementations and those are barely LAN capable. Using those over Internet wouldn't be a great idea. Often these TCP stacks are used just as serial - tcp converters. Using RWIN of 16 (max) bytes due UART buffering limits etc. Not sending ACK before whole 16 byte is cleared and so on.

So with really low end devices, it's better to off load TCP to custom hardware. Many embedded devices use that approach. In such cases you'll only call to IP address and port, and when it connects, you'll have your TCP/IP connection in pure serial. TCP-modems isn't any different from other good old Hayes modems. It's just dial-up over Internet and TCP.

Btw. If the system is able to run CPython, Linux, or something similar, it's already a pretty powerful system.

Re: What happens if you write a TCP stack in Python?

#123

Earlier quoted context omitted.

TCP != ethernet. A TCP stack can run over serial and othe link layers (PPP, SLIP, etc). PPP is absolutely doable on very small microcontrollers.

Problem is that using PPP or SLIP doesn't relieve you from having to implement at least some kind of crude TCP stack. But if you use TCP offloading, then you can communicate using TCP as cheaply as doing any traditional serial communication. I've seen those crude TCP stack implementations and those are barely LAN capable. Using those over Internet wouldn't be a great idea. Often these TCP stacks are used just as seri…

Even without any kind of offloading, you can manage a perfectly good TCP implementation and super-minimal web browser with a few kilobytes of ram and 100KHz.

Re: What happens if you write a TCP stack in Python?

#124

You don't need to spoof a different MAC or IP to implement your own stack on a raw socket, Python is not too slow to handle negotiating a connection, and your interpretation of how tcp/ip works is flawed. I highly recommend you read a good book about tcp/ip and learn how the kernel works with network applications of different types. In terms of using Scapy for your packet crafting, here are some guides with examples…

I think you'll find that either publishing an ARP entry or filtering incoming packets in the kernel is required for handling a TCP stream over raw sockets.

As the outbound TCP SYN is manually crafted and sent over a raw socket, without any corresponding state table entry on the sender's kernel, incoming TCP responses will be rejected by the kernel with a RST.

I suggested to Julia that she manually publish an ARP entry for another IP which she could send and receive on. The kernel not having an interface with that IP assigned to it would ignore responses while also passing them to the raw socket. An alternative would be to use an iptables rule to drop incoming packets for the relevant flow - although that may be more difficult to manage depending on what you're doing.

Re: What happens if you write a TCP stack in Python?

#125

Earlier quoted context omitted.

I'd like to see you bit-bang a 10MHz signal with an 8 MHz clock. You'd need something substantially faster (Nyquist and such).

TCP != ethernet. A TCP stack can run over serial and othe link layers (PPP, SLIP, etc). PPP is absolutely doable on very small microcontrollers.

It said 'ethernet' in the parent comment to mine, not TCP.
Post reply on HN