Live data from Hacker News

Ubus (OpenWrt micro bus architecture)

openwrt.org

11–20 of 56 posts

Re: Ubus (OpenWrt micro bus architecture)

#11
post #9
post #7

Earlier quoted context omitted.

I think any language with a large runtime would be out of the question, because Openwrt has to fit into system with very limited storage.

To put it in context: On some devices you have 32MB flash storage in total . 32 Megabytes, not gigabytes. This is not a typo. This needs to fit the bootloader, the Linux kernel, the initrd, the rootfs containing all the user-space tools making OpenWRT an actual usable OS and whatever daemons you need to implement your particular network needs. Oh and you probably want the WebUI too. In 32MBs. There are newspapers onl…

This is a good point. But Ocaml and Ada are not in the 2MB helloworld club (eg Ocaml is more like 200k), don't know about Go. Also accounting that to a single binary is not the right perspective I think - adopting a safe language in OpenWRT should be arranged so that all the programs using that language can share the same copy of the runtime.

Re: Ubus (OpenWrt micro bus architecture)

#12
In case you want to react to stuff connecting to your router via ubus:

iw event | awk '/new station/ {print $4}' | xargs -n 1 sh -c 'ubus send new_station {\"mac\":\"$1\"}' _

(Yes, this contains silly hacks to work around busybox limitations)

Re: Ubus (OpenWrt micro bus architecture)

#13
post #9
post #7

Earlier quoted context omitted.

I think any language with a large runtime would be out of the question, because Openwrt has to fit into system with very limited storage.

To put it in context: On some devices you have 32MB flash storage in total . 32 Megabytes, not gigabytes. This is not a typo. This needs to fit the bootloader, the Linux kernel, the initrd, the rootfs containing all the user-space tools making OpenWRT an actual usable OS and whatever daemons you need to implement your particular network needs. Oh and you probably want the WebUI too. In 32MBs. There are newspapers onl…

It's even less than that. Current OpenWrt versions work on devices with 8 MB of flash and 64 MB of RAM. OpenWrt 19.07 worked on 4MB/32MB devices.

Re: Ubus (OpenWrt micro bus architecture)

#15
post #12

In case you want to react to stuff connecting to your router via ubus: iw event | awk '/new station/ {print $4}' | xargs -n 1 sh -c 'ubus send new_station {\"mac\":\"$1\"}' _ (Yes, this contains silly hacks to work around busybox limitations)

I'm pretty sure that there already is an event emmitted upon station connection

Re: Ubus (OpenWrt micro bus architecture)

#16
post #11
post #9

Earlier quoted context omitted.

To put it in context: On some devices you have 32MB flash storage in total . 32 Megabytes, not gigabytes. This is not a typo. This needs to fit the bootloader, the Linux kernel, the initrd, the rootfs containing all the user-space tools making OpenWRT an actual usable OS and whatever daemons you need to implement your particular network needs. Oh and you probably want the WebUI too. In 32MBs. There are newspapers onl…

This is a good point. But Ocaml and Ada are not in the 2MB helloworld club (eg Ocaml is more like 200k), don't know about Go. Also accounting that to a single binary is not the right perspective I think - adopting a safe language in OpenWRT should be arranged so that all the programs using that language can share the same copy of the runtime.

200k is very large in the OpenWrt world

Re: Ubus (OpenWrt micro bus architecture)

#17
post #12

In case you want to react to stuff connecting to your router via ubus: iw event | awk '/new station/ {print $4}' | xargs -n 1 sh -c 'ubus send new_station {\"mac\":\"$1\"}' _ (Yes, this contains silly hacks to work around busybox limitations)

I'm pretty sure that there already is an event emmitted upon station connection

Certainly not by default anyway. That would have been great though. Double-checked with ubus listen in case it had changed over the last couple of years.

Re: Ubus (OpenWrt micro bus architecture)

#18
post #10
post #2

Did they consider using a memory-safe language for this?

There is no real case to be made against the idea of memory safety, but there is a case to be made for C. You can write C code such that its unit tested, fuzzed, statically analyzed and reviewed, and often embedded code has one or two specific jobs. I would have loved to see Zig here, as it makes all of the above (testing, analysis, code clarity for review) easier, but its also not memory safe necessarily. You could…

> You could use Rust, assuming it had existed back when they started it, and you would get memory safety, but also an entire kitchen sink of useless garbage (like C++). Youd also have to shell out to unsafe{} in a lot of places, unless you use a crate for it, which will then do unsafe{} for you.

I'm not saying C is a wrong choice here, but this argument doesn't make much sense to me. All the other languages also come with "useless garbage" (some even with a collector for them). I don't see why you'd need that many unsafe blocks either.

I feel like Rust, as a language, is much better equipped for writing a daemon like this. I'll even go as far as to say that modern C++ (C++2x) is a better choice than C for this stuff with its superior memory and resource management tools.

Of course most of the OpenWRT development is done in C, so doing it in another language requires a very good reason. I wouldn't look at the concept of "a networked daemon exchanging messages between arbitrary services" and think C of all languages is a good fit unless every other developer on the team can only write C.

Zig would've been a nice way to meet halfway, but the language isn't finished yet.

Of course the point is moot because this particular project existed years before any of the modern alternatives or many of the C++ improvements were even available. Still, if they'd start a project like this again, I'd hope they'd pick a better language for it.

Re: Ubus (OpenWrt micro bus architecture)

#19
post #11

Earlier quoted context omitted.

This is a good point. But Ocaml and Ada are not in the 2MB helloworld club (eg Ocaml is more like 200k), don't know about Go. Also accounting that to a single binary is not the right perspective I think - adopting a safe language in OpenWRT should be arranged so that all the programs using that language can share the same copy of the runtime.

200k is very large in the OpenWrt world

Ada then?

Eg on https://ada.godbolt.org/ you can see the default program compiled to ~25 lines of assembler.

edit: actually it contains a call to a bounds check function that presumably is in the runtime library, i don't know how big that is.

A major point in this is that C also has a fairly big runtime library that should be factored into the comparison!

Re: Ubus (OpenWrt micro bus architecture)

#20
post #19

Earlier quoted context omitted.

200k is very large in the OpenWrt world

Ada then? Eg on https://ada.godbolt.org/ you can see the default program compiled to ~25 lines of assembler. edit: actually it contains a call to a bounds check function that presumably is in the runtime library, i don't know how big that is. A major point in this is that C also has a fairly big runtime library that should be factored into the comparison!

> A major point in this is that C also has a fairly big runtime library that should be factored into the comparison!

But libc will be there anyways, unless you are rewriting absolutely all of userland.

Post reply on HN