Gennaro Cimmino f286d9af81 realtek: dsa: count the routes using an L2 next hop
Routes through one gateway share a single L2 entry: the second route to
be installed finds the first one already there and takes it as it is.
Nothing recorded that, so the first route to be torn down took the next
hop bit off the entry the others were still forwarding through, and when
the driver had created that entry itself it was invalidated outright and
the row handed back to the switch.

Count them. Taking a next hop claims a reference on its entry, dropping
one releases it, and the entry is only given back when the last is gone
and the bridge is not holding it either.

The reference is keyed on the flag that already says whether the next
hop is in hardware, because the caller runs this again for every route
behind a gateway on every neighbour event, and an unconditional count
would climb for as long as the neighbour keeps changing state. A next
hop that moves to another row - a gateway whose MAC changed - releases
the row it left, after asking that row whether it is still the one the
reference was taken on, because whoever claims a dropped row next counts
itself from zero. When that was the last reference the row is
given back there and then, by the same step a removal uses, because
nothing would ever come looking for it again.

An entry that was invalid when it was claimed has its count zeroed
first: nothing clears the map when the switch ages a row out by itself,
so what is in the cell may belong to a route that is long gone.

The count pins at its ceiling instead of wrapping. Seven bits hold 127
where the vendor SDK gives the same counter, nh_used_cnt, sixteen; an
entry that reached the ceiling is never freed by the driver again, which
leaves a row in use but never hands a live one to somebody else.

Both checks stay in front of the count, the way the removal already
tested the entry before touching it. An entry that is still the one that
was installed but no longer a next hop is left alone, and its reference
is not dropped. Inside the driver only the release clears that bit, and
it runs once the count has reached zero; the switch can also take the
row away on its own, and a row re-learnt under that address afterwards
carries a count nobody will spend - the same staleness the paragraph
above bounds, not a new one.

The search, the count and the write now happen under priv->reg_mutex,
which is what the bridge FDB handlers already hold across the same
read-modify-write, so nothing can come between them. That mutex is also
ctrl->lock, so an L3 caller must not hold it across these two; none
does. The add still runs inside an RCU read-side section it should not,
which it did before this patch as well - the table accessors it already
called sleep.

Functionally tested on a Hasivo S1100W-8XGT-SE (RTL9303), kernel
6.18.52, with CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD=y and
ip_forward=0, so only the hardware can forward. Two routes through one
gateway share one L2 entry; removing either of them leaves it valid and
still a next hop, and the other route keeps forwarding. Removing the
second one takes the next hop bit off it. The row a moved next hop
leaves behind was not exercised: a second MAC for the gateway cannot be
arranged from the test image, so that path is by inspection. That kernel
carries no atomic-sleep or lock debugging, so a clean log says nothing
about the RCU section above.

Not exercised on RTL838x or RTL931x: neither config carries a setup op,
which is what both notifiers gate on, so the routing side never reaches
them. RTL839x does reach it and is untested - no hardware here.

Compile-tested on realtek/rtl930x and realtek/rtl839x.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Gennaro Cimmino <gcimmino@rayonra.net>
Link: https://github.com/openwrt/openwrt/pull/25231
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-09-18 07:36:02 +02:00
2026-09-13 20:46:35 +01:00
2026-09-12 16:49:17 +02:00
…
…
…

OpenWrt logo

OpenWrt Project is a Linux operating system targeting embedded devices. Instead of trying to create a single, static firmware, OpenWrt provides a fully writable filesystem with package management. This frees you from the application selection and configuration provided by the vendor and allows you to customize the device through the use of packages to suit any application. For developers, OpenWrt is the framework to build an application without having to build a complete firmware around it; for users this means the ability for full customization, to use the device in ways never envisioned.

Sunshine!

Download

Built firmware images are available for many architectures and come with a package selection to be used as WiFi home router. To quickly find a factory image usable to migrate from a vendor stock firmware to OpenWrt, try the Firmware Selector.

If your device is supported, please follow the Info link to see install instructions or consult the support resources listed below.

An advanced user may require additional or specific package. (Toolchain, SDK, ...) For everything else than simple firmware download, try the wiki download page:

Development

To build your own firmware you need a GNU/Linux, BSD or macOS system (case sensitive filesystem required). Cygwin is unsupported because of the lack of a case sensitive file system.

Requirements

You need the following tools to compile OpenWrt, the package names vary between distributions. A complete list with distribution specific packages is found in the Build System Setup documentation.

binutils bzip2 diff find flex gawk gcc-6+ getopt grep install libc-dev libz-dev
make4.1+ perl python3.8+ rsync subversion unzip which

Quickstart

  1. Run ./scripts/feeds update -a to obtain all the latest package definitions defined in feeds.conf / feeds.conf.default

  2. Run ./scripts/feeds install -a to install symlinks for all obtained packages into package/feeds/

  3. Run make menuconfig to select your preferred configuration for the toolchain, target system & firmware packages.

  4. Run make to build your firmware. This will download all sources, build the cross-compile toolchain and then cross-compile the GNU/Linux kernel & all chosen applications for your target system.

The main repository uses multiple sub-repositories to manage packages of different categories. All packages are installed via the OpenWrt package manager called opkg. If you're looking to develop the web interface or port packages to OpenWrt, please find the fitting repository below.

  • LuCI Web Interface: Modern and modular interface to control the device via a web browser.

  • OpenWrt Packages: Community repository of ported packages.

  • OpenWrt Routing: Packages specifically focused on (mesh) routing.

  • OpenWrt Video: Packages specifically focused on display servers and clients (Xorg and Wayland).

Support Information

For a list of supported devices see the OpenWrt Hardware Database

Documentation

Support Community

  • Forum: For usage, projects, discussions and hardware advise.
  • Support Chat: Channel #openwrt on oftc.net.

Developer Community

License

OpenWrt is licensed under GPL-2.0

S
Description
This repository is a mirror of https://git.openwrt.org/openwrt/openwrt.git It is for reference only and is not active for check-ins. We will continue to accept Pull Requests here. They will be merged via staging trees then into openwrt.git.
Readme BSD-2-Clause BSD-3-Clause GPL-1 GPL-2 ISC Linux-syscall-note MIT
1.2 GiB
0 Stars 1 Watchers 0 Forks
Languages
C 60.6%
Makefile 23.1%
Shell 8.1%
Perl 2.6%
UnrealScript 2.4%
Other 3%