mwan3rtmon rewrite in ucode (Re: ucode for scripts)

Etienne Champetier champetier.etienne at gmail.com
Sat Nov 8 16:22:29 PST 2025


Le sam. 8 nov. 2025 à 16:52, Jonas Lochmann <openwrt at jonaslochmann.de> a écrit :
>
> Am Sat, Nov 08, 2025 at 01:11:17PM -0500, schrieb Etienne Champetier:
> > I also had a look at rewriting mwan3rtmon in ucode recently and I'm
> > wondering if we could just get rid of it.
> > Basically this script watches the main routing table to copy all non
> > default routes, and also fill an ipset,
>
> It does this per interface and keeps the default rules of that
> particular interface while also removing source based routing in case
> of IPv6. (Well, this can be disabled, but I would not recommend that.)

Thanks for pointing that out, I missed that sed line

> > but I think using rules like 'lookup main suppress_prefixlength 0' we
> > should be able to remove mwan3rtmon.
>
> But where do we get the default routes from then?

We still need something for the default routes indeed, but we can simplify a bit
Have something like
```
1000: from all lookup main suppress_prefixlength 0
```
and then in table 1 / 2 ... just have the default route of each wan

This would also remove the need for the mwan3_connected_ipv4/6 ipsets
as the mark doesn't matter if you match rule 1000 first.

> I see no possibility to skip mwan3rtmon.

If we only have wans with static ips then we don't need mwan3rtmon anymore ...
so we would still need it :), but if it only handles default routes
that's way less work to do.

> I thought of trying to put this into netifd, but it looks like it does
> not recognize routes added by other services (e.g. openvpn).
>
> > Also found some example rtnl code in
> > https://github.com/jow-/ucode/issues/184 if you are looking for some
>
> I consider https://github.com/jow-/ucode/blob/master/lib/rtnl.c more
> interesting. But it feels like many things in OpenWrt where the source
> code is the documentation/things are not documented. Same for mwan3
> where I know the architecture from working with the source code, but
> I don't know any description telling how mwan3, its parts and the linux
> network stack work together.

Yep, there is very little explanation of why each piece is present
Example, the ip rule
```
1001:    from all iif wan1 lookup 1
```
I think it is used if we bind to the ip of wan1 (and not the device)
to ensure the traffic goes out the right interface, but maybe it's for
something else :(



More information about the openwrt-devel mailing list