[HN Gopher] LwIP - Lightweight IP Stack
       ___________________________________________________________________
        
       LwIP - Lightweight IP Stack
        
       Author : fidotron
       Score  : 166 points
       Date   : 2024-09-06 01:00 UTC (22 hours ago)
        
 (HTM) web link (www.nongnu.org)
 (TXT) w3m dump (www.nongnu.org)
        
       | tony-allan wrote:
       | From the article:
       | 
       | "This making lwIP suitable for use in embedded systems with tens
       | of kilobytes of free RAM and room for around 40 kilobytes of code
       | ROM."
        
         | tonyarkles wrote:
         | I've run it on a Cortex M4 with a built-in Ethernet MAC
         | peripheral. It was shockingly simple to integrate... basically
         | just needed to set up a receive ISR that handed packets to the
         | LwIP stack and a transmit function that the LwIP stack could
         | call to send packets.
        
           | yuye wrote:
           | That simple? We've got an overseas software team that was
           | tasked with doing the exact same.
           | 
           | 6 months later and they still haven't got a working
           | implementation.
        
             | 1oooqooq wrote:
             | they are probably testing with more than the best case
             | simple connection before declaring success, unlike everyone
             | here.
        
               | yuye wrote:
               | I love your optimism.
               | 
               | I've seen their implementation. It was horrible. We
               | eventually took the project away from them and had the
               | local team work on it.
               | 
               | Also a fun story: they didn't use version control at all.
               | When we eventually forced them to use git, they put the
               | whole codebase in a .zip file and committed that.
        
               | pts_ wrote:
               | Your onshore contract handlers were definitely difficult
               | to work with. The number 1 reason for bad work are bad
               | managers. See Boeing.
        
               | _joel wrote:
               | I've worked with offshore companies that are similarly as
               | bad, but then again there have been some that have been
               | excellent. In your case, I don't know how they lasted 6
               | months if they're not committing to git etc, if that's
               | the standard. They should be brought into the daily
               | standups as 6 months to wait for some delivery seems a
               | bit waterfally (apologies if this is a
               | mischaracterisation).
        
               | aleph_minus_one wrote:
               | > They should be brought into the daily standups as 6
               | months to wait for some delivery seems a bit waterfally
               | (apologies if this is a mischaracterisation).
               | 
               | At least it it a clear mischaracterisation of waterfall:
               | 
               | * https://changelog.com/posts/waterfall-doesnt-mean-what-
               | you-t...
               | 
               | * HN discussion:
               | https://news.ycombinator.com/item?id=37405049
               | 
               | * http://bawiki.com/wiki/Waterfall.html
               | 
               | * HN discussion:
               | https://news.ycombinator.com/item?id=26760606
        
               | _joel wrote:
               | That's why I said waterfally
        
             | rramadass wrote:
             | Are they integrating LwIP as it is or are they hacking its
             | source to fit into your architecture?
             | 
             | I did the latter a decade ago for a home-grown SoC and it
             | is non-trivial. And then testing it with
             | conformance/performance in mind takes more time.
        
             | Thervicarl wrote:
             | I have run it on a few hundred systems with Cortex R5 (used
             | in a production context so demonstrated to be stable over
             | tens of thousands of hours).
             | 
             | At that time there was a reference port for the Hercules
             | development board available on-line. It was mostly working
             | straight out of the box. I just had to fix a few issues
             | with the Halcogen generated files (since then, TI has fixed
             | the bugs), configure the lwIP options (to have DHCP and
             | only use UDP). Since then (7 years ago), I have not touched
             | the code once.
        
             | rowanG077 wrote:
             | Well you need an Ethernet phy driver. If you have that that
             | can work with the api of lwip it really is that easy.
        
         | leptons wrote:
         | LwIP is part of Espressif's ESP-IDF framework, for the popular
         | ESP32 devices. I've been working with LwIP for years on this
         | platform, and while it does work, it still takes up more memory
         | than I'd like it to. Thankfully we now have ESP32 devices with
         | 2MB of RAM.
        
       | stevefolta wrote:
       | What is nongnu.org, and what is its relationship to gnu.org?
        
         | TheDong wrote:
         | nongnu.org is also run by the same people as gnu.org, but hosts
         | software which isn't currently officially part of the gnu
         | project.
         | 
         | Basically, it's an area for software that is aligned with the
         | GNU philosophy, might one day become part of the GNU project,
         | but isn't officially currently part of the GNU project.
         | 
         | https://savannah.nongnu.org/register/requirements.php
         | 
         | https://savannah.nongnu.org/maintenance/GNUvsNonGNU/
        
       | mannyv wrote:
       | I love these tiny TCP stacks.
       | 
       | I used to work with TinyTCP back when. What's interesting is if a
       | search for tinytcp turns up a bunch of them. Awesome!
       | 
       | Apparently there's no tiny ipv6 stack?
        
         | convolvatron wrote:
         | Lwip has v6 support
        
         | RachelF wrote:
         | Yes, it's impressive. I had to write one in assembly years ago.
         | However, could only do UDP unfortunately as I didn't have
         | enough memory for code and TCP buffers in 64kB.
        
       | kaycebasques wrote:
       | Pico W uses this, right? https://github.com/raspberrypi/pico-
       | examples/blob/master/pic...
        
         | MathMonkeyMan wrote:
         | Yep! <https://github.com/dgoffredo/picoro/blob/main/include/pic
         | oro...>
        
       | tptacek wrote:
       | Similarly, for Go programmers:
       | https://pkg.go.dev/inet.af/netstack
        
         | ranger_danger wrote:
         | also gVisor has a tcp/ip stack, tun2socks uses it
        
           | tptacek wrote:
           | netstack is the gVisor IP stack. :)
        
         | Gazoche wrote:
         | And similarly, for Rust: https://github.com/smoltcp-rs/smoltcp
         | 
         | I've been using it in a toy OS project and it works
         | brilliantly.
        
       | throwawayabcdef wrote:
       | see also uip and contiki as well as the other creations from Mr.
       | Dunkles:
       | 
       | https://dunkels.com/adam/software.html
        
       | jacobmarble wrote:
       | Adam Dunkels also wrote (most of) Protothreads.
       | https://dunkels.com/adam/pt/
        
         | cristoperb wrote:
         | He also wrote uIP, the TCP/IP stack for the Contiki OS which is
         | even smaller than LwIP
         | 
         | https://en.wikipedia.org/wiki/UIP_(software)
        
       | lovidico wrote:
       | What's the news value of this? LWIP is the most popular embedded
       | network stack and has been around for ages. It also is awful to
       | use and riddled with undocumented issues (in my experience,
       | anyway)
        
         | fragmede wrote:
         | https://xkcd.com/1053/
        
         | wmf wrote:
         | https://xkcd.com/1053/ (jinx)
         | 
         | It's allowed to repost "classic" stuff on HN as long as it
         | isn't too frequent.
        
         | unmole wrote:
         | In my experience, it is a breeze to use. ~10 years ago, we
         | managed to significantly cut down the cost of IP cameras by
         | using lwIP with NuttX which allowed us to use a cheaper
         | microcontroller instead of a more expensive chip that could run
         | Linux.
         | 
         | Plugging in a new TCP congestion control scheme was also
         | straightforward.
        
         | kragen wrote:
         | what kind of undocumented issues have you run into, and what
         | did you have to do to deal with them?
        
         | fargle wrote:
         | the stack itself is extremely solid and works perfectly with
         | reasonable performance. the codebase is extremely stable and
         | has not had major changes, nor significant bugs in ages.
         | 
         | the biggest problem with lwip is the documentation. you have
         | doxygen API docs that tell you exactly what the interfaces are
         | (and not much more than the reading the header filed does), you
         | have a few pages of "how to ..." and higher level background.
         | but often it's slightly bit rotted, subtly hasn't kept up with
         | design changes. so it's difficult to learn - you effectively
         | have to thoroughly read the code to get the big picture. and if
         | you make a mistake in handling your application callbacks, you
         | can easily leak buffers or create other problems. it's not
         | "awful to use", it's actually very simple - once you understand
         | it, which is seriously hampered by truly lacking documentation.
         | 
         | the second issue is that the SoC vendors inevitably pay some
         | overseas contractor to do the port and MAC/PHY drivers and
         | example code, just like another [1] comment describes. that's
         | where a lot of the instability and bugs come in. it's _not_
         | lwip, it 's the port that sucks.
         | 
         | [1] https://news.ycombinator.com/item?id=41462602
        
       | kneep wrote:
       | I guess it's the most used TCP/IP stack in resource constrained
       | devices. But it seemed that for long, there's no competent
       | alternative to it. https://github.com/FreeRTOS/FreeRTOS-Plus-TCP
       | looks like a promising one.
        
         | schnitzelbot wrote:
         | There are high quality alternatives:
         | 
         | - NetXDuo from ThreadX. It's Opensource for a while now.
         | 
         | - Zephyr also brings its own stack
        
           | bfrog wrote:
           | It'd be interesting to see a breakdown of IP stacks for MCUs,
           | their performance, how many security issues, etc.
           | 
           | NetX, Zephyr, LwIP, and SmolTCP all sort of fit in this realm
           | these days it seems like. Probably others too... but yeah
           | hard to discern the differences at a high level without
           | digging in.
        
         | quailfarmer wrote:
         | LWIP integrates quite well with the FreeRTOS scheduler, I've
         | used that combo before. How does the "plus-TCP" stack compare?
        
           | schnitzelbot wrote:
           | The quality usually depends on the vendor adapting it to
           | their silicon.
           | 
           | If you look at ST and their STM32 the lwip integration is
           | extremely bug ridden. Just read all the articles in their
           | forum from "Piranha". I also struggled with extremely hard to
           | debug bugs coming from their adaption layers.
           | 
           | Lwip itself has a solid quality.
        
             | high_priest wrote:
             | Can you say, with which hardware does, the LWIP stack, work
             | well?
        
             | aftbit wrote:
             | That sounds like ST. They make some really intriguing chips
             | at good prices, but the tradeoff is that their hardware and
             | software are full of bugs.
        
       | quailfarmer wrote:
       | I really like LWIP because it lets you use the same block of
       | memory allocated by the Ethernet MAC DMA for the lifetime of the
       | packet. You can really optimize the memory "pools" for your use
       | case to reduce the number of memcpys.
        
       | taspeotis wrote:
       | Written in C you say?
       | 
       | https://git.savannah.nongnu.org/cgit/lwip.git/log/?qt=grep&q...
       | 
       | Then you've got stuff like this whose commit messages don't
       | really hint at "memory will leak to remote attackers through the
       | network"
       | 
       | https://savannah.nongnu.org/bugs/?58553
        
         | tptacek wrote:
         | This code is over 2 decades old. Pointing out that it's written
         | in C is just about the least interesting thing you can say
         | about it.
         | 
         | https://web.archive.org/web/20160304140507/https://citeseerx...
        
       | weinzierl wrote:
       | IP Stack is a bit of an understatement. It comes with enough to
       | be a HTTP client, a HTTP server or a MQTT client - and that is
       | the way I've seen it used in practice.
       | 
       | It is more like the busybox of embedded networking, but with a
       | much more convenient license.
        
       | evanjrowley wrote:
       | What is nongnu.org and how does it relate to gnu.org?
       | 
       | EDIT: I found an answer[0].                 StevePerkins on May
       | 22, 2016 | unvote | next [-]            http://savannah.gnu.org
       | is a hosting site for "official" GNU software (i.e. sponsored by
       | the Free Software Foundation).
       | http://savannah.nongnu.org is a hosting site for "community"
       | projects that are not sponsored by the FSF.
       | 
       | [0] https://news.ycombinator.com/item?id=11747093
        
       | rramadass wrote:
       | For those folks interested in implementing their own lightweight
       | TCP/IP stack, Jeremy Bentham's book; _TCP /IP Lean_ is a great
       | resource.
        
       | gregfjohnson wrote:
       | We used LwIP for a project some years ago, and found a very nice
       | way to do system testing.
       | 
       | The project involved multiple microcontrollers communicating over
       | an internal LAN. They used a small embedded kernel named
       | MicroCOS, with LwIP as the IP stack.
       | 
       | We had cross-platform build tools set up, so we could build our
       | stand-alone microprocessor applications either for native
       | execution or with gcc, compiling to x64 code and executable on
       | developer boxes. In the latter case, we implemented the lowest
       | level link-layer part of LwIP using a mock, that used standard
       | TCP/IP! We wrote a small TCP server and would spool up the micro-
       | controller applications, which would then talk to each other on
       | the developer machines as though they were running inside the
       | actual system.
       | 
       | This setup worked really well, and we used it for years during
       | the development effort for the project.
        
       | spacechild1 wrote:
       | I first heard about LwIP when I worked with the ESP32. Espressiv
       | seems to maintain its own fork with some ESP-specific patches:
       | https://github.com/espressif/esp-lwip
        
       | bfrog wrote:
       | How does LwIP compare to SmolTCP at this point?
        
       | bangaladore wrote:
       | For those looking for options like LwIP, consider NetXDuo [1] and
       | its counterparts ThreadX, FileX, LevelX, and UsbX (I use TinyUSB
       | instead).
       | 
       | It has been one of the top commercial RTOS network stacks for, I
       | think, 20 years. It moved hands a couple of times and now is
       | supported by the Eclipse Foundation and is MIT-licensed. I'd use
       | it over LwIP.
       | 
       | [1] https://github.com/eclipse-threadx/netxduo
        
         | GrqP wrote:
         | This.
        
       ___________________________________________________________________
       (page generated 2024-09-06 23:01 UTC)