[HN Gopher] Show HN: MicroTCP, a minimal TCP/IP stack
___________________________________________________________________
Show HN: MicroTCP, a minimal TCP/IP stack
Author : cozis
Score : 94 points
Date : 2023-10-31 15:43 UTC (7 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| cozis wrote:
| Hello HN! This is a project I've started this year to learn about
| sockets and network programming. Nothing serious, just a hobby
| project! I'd love to hear your opinions about it and feel free to
| ask questions
| surteen wrote:
| What is the licensing for this code?
| wolf550e wrote:
| (I'm not OP)
|
| 1. There is no license, so it's proprietary code.
|
| 2. It's a student project, you shouldn't use it for anything.
| OJFord wrote:
| > 2. It's a student project, you shouldn't use it for
| anything.
|
| I'm a graduate, should you use it if I write it?
| tptacek wrote:
| Not if you call it a student project! Probably your
| TCP/IP stack should not be someone's hobby project. A
| good threshold test: do you need to care about the
| license? If so...
| dariosalvi78 wrote:
| Bene!
| swimwiththebeat wrote:
| How did you even get started with this? There are many systems
| I'd love to learn to implement from scratch like databases,
| network stacks, and caches, but the task seems so vast and
| daunting that it's hard to get started. Learning from existing
| codebases is also difficult b/c there's so much code to go over
| and understand. Can you elaborate on what your process was to
| build this without any help?
| coddle-hark wrote:
| No OP but I think there's three parts to really getting TCP/IP:
|
| - Read the spec(s)
|
| - Learn the OS APIs deeply
|
| - Look at a bunch of real network data in e.g. Wireguard
| OJFord wrote:
| > Look at a bunch of real network data in e.g. Wireguard
|
| I think you probably meant data in e.g. Wire _shark_?
|
| But another good suggestion (or maybe what you meant) might
| be to look at 'real' (production) networking _code_ in e.g.
| Wireguard, I imagine.
| technothrasher wrote:
| I wrote a little embedded TCP stack a while back as a learning
| project. I just read the RFCs and coded away. I'm sure it's the
| world's least efficient stack, but it wasn't too hard to get
| basic functionality.
| vlovich123 wrote:
| The strategy that works best for me is to just start at the
| simplest step & iterate from there. Do research online to find
| blog posts / articles describing how to solve specific
| problems. When doing reading, make sure to note terms of art
| that repeat so that you know what to look for.
|
| So the first step I would do to start on a TCP/IP stack would
| be "how to open a raw socket" (granted you have to know the
| magic phrase here). There's also tons of "how to implement TCP
| stack" articles (same for ethernet etc) that probably are good
| starting points if I didn't know that magic phrase. The other
| thing is to find people to talk to who know more than you to
| answer those questions.
|
| Once you have that, you can setup a real TCP socket on one end
| and a raw socket client on the other & then the same thing in
| reverse. Then look up the TCP/IP framing on Wikipedia (+ read
| up on the broad overview of how TCP works and the various
| parts). Once you have the framing implemented, try implementing
| the basic sequence to establish a connection. Then keep noting
| what features a full TCP stack has, which are required, & which
| are missing from my implementation (that's when I'd start
| reaching for the standards that everyone references).
|
| Of course, if you want to do something novel beyond just "hey I
| have confidence that I can implement such a stack myself" (e.g
| implementing something with certain performance
| characteristics) that requires a deeper understanding of how
| things work and a good filter on possible ideas & which ones
| are going to likely work out the best (that is gained through
| expertise, creativity & intelligence)
| pipes wrote:
| If you made this into a book, I'd buy it! Especially if it
| was structured so that each chapter had a coding exercise
| that built on the previous one so that by the end I had a
| working stack.
|
| My favourite programming book is structured like this
| "elements of computer systems" also referred to as "from nand
| to Tetris"
| Lukeisun wrote:
| I am not very familiar with this kind of stuff either but I
| have read through "Beej's Guide to Network Programming"
| https://beej.us/guide/bgnet/html/split/. Which seems like
| enough to implement something like OP posted.
|
| As for db's/other interesting things, I haven't read them
| myself but this site seems solid https://build-your-own.org/.
| If anyone has any real experience with this site, I would love
| to hear it!
| tpmx wrote:
| Something similar from... a while ago. How does it compare?
|
| https://web.archive.org/web/20060615041317/http://www.sics.s...
|
| _uIP is an implementation of the TCP /IP protocol stack intended
| for small 8-bit and 16-bit microcontrollers. It provides the
| necessary protocols for Internet communication, with a very small
| code footprint and RAM requirements - the uIP code size is on the
| order of a few kilobytes and RAM usage is on the order of a few
| hundred bytes._
|
| https://github.com/adamdunkels/uip
|
| https://en.wikipedia.org/wiki/UIP_(software)
|
| (I believe uIP was extracted and improved upon from Contiki, a
| C64 OS with TCP/IP support written in C in 2002:
| https://www.c64-wiki.com/wiki/Contiki)
| jug wrote:
| Haha, oof, it's evil to compare to that! Adam is a "10x
| programmer" genius.
| tpmx wrote:
| Yeah, it felt a bit evil, but I also really wanted to share
| this because it predates HN and deserves sharing, so... :)
| riedel wrote:
| Was about to post the same. Contiki actually came to fame
| though as it was commonly used for sensor networks an IoT
| application. Particularly integrating 6lowpan (ZigBee IPv6)
| made it interesting for us at the time.
| squarefoot wrote:
| "The dream is to serve my blog from an STM32 board!"
|
| That (uControllers and small systems in general) should be among
| the best use cases as there is obviously a much higher demand for
| a low footprint network stack in that field, also with an eye to
| Single Pair Ethernet, should it become cheaper and widely
| supported in common uCs in the future.
| Uptrenda wrote:
| As a networking nerd I respect the project OP. Very good learning
| exercise. There are still many unsolved problems in networking,
| too. It's a bit of an esoteric field.
| waynesonfire wrote:
| I really want to understand how this fits into my mental model.
| Wtf is a TCP/IP stack? It's blurry because I _GUESS_ some of it
| maybe lives on the network card, some in the kernel, and some in
| usermode. So, when one decides to write their own network stack,
| what abstractions are they building on top of?
|
| Maybe it would be helpful to understand this from the perspective
| of that STM32 board. So it has an ethernet jack, maybe? Is that
| the abstraction that a TCP/IP stack would have to build on top
| of?
|
| Now, if that's the case, why is it that in this case the user is
| using a TAP device? Is it because they didn't want to write a
| kernel driver? E.g. is interacting with the TAP device the
| equivalent of the "fuse" abstraction for filesystems?
| dboreham wrote:
| > Wtf is a TCP/IP stack?
|
| You may want to consider toning it down. Readers here would be
| expected to know all this.
|
| And yes TAP is a user mode raw interface to the NIC.
| waynesonfire wrote:
| > Readers here would be expected to know all this.
|
| I'm not asking about the OSI model. I've long moved beyond
| that. Sorry that wasn't clear from my message I was typing in
| haste. I suspect very few readers here have implemented a
| TCP/IP stack or would even know where to begin. So, I'm
| acknowledging this.
|
| There is a comment in this thread asking, "How did you even
| get started with this?" and it was able to successfully
| solicit the response that I was looking for.
| sitzkrieg wrote:
| the osi model layers describe exactly what is going on in
| embedded systems (well all), though. look at a mcu board
| with ethernet. find the magjack. then the PHY, then the
| MAC, then...
| bvrmn wrote:
| > the osi model layers describe exactly what is going on
| in embedded systems
|
| Unless it doesn't. OSI describes non-existing stack from
| the long gone past.
| spc476 wrote:
| Start at the hardware/IP layer. Easiest would be serial
| port for the hardware, and there are at least two methods
| of sending IP over serial, SLIP and PPP---there are
| documents out there that describe how those work. Then work
| on IP. IP itself is fairly easy---it's just best effort and
| IP options are just that---options. Then ICMP. Once you
| have that, then you can at least ping the device. UDP is
| the next easiest to implement, it's just portnumbers to an
| otherwise IP packet.
| pipes wrote:
| That's a big assumption. Who says they are expected to know
| this?
| fragmede wrote:
| Personally I say yes but who cares what I say. Let's see
| what this poll says in a few hours.
|
| https://news.ycombinator.com/item?id=38092364
| hujun wrote:
| the purpose of using TAP is to be able to write IP stack in
| user mode code; however TAP is not the only way on linux, you
| could also use raw(AF_PACKET)or XDP socket, they also allow
| you bypass kernel IP stack
___________________________________________________________________
(page generated 2023-10-31 23:00 UTC)