Use mtk sdk HWNAT driver to replace hw flow offload

Considering some problems with openwrt flow offload now, I try to use the hwnat driver of mtk sdk. Compared with flow offload, it is more stable and supports wifi offload. This is the sdk driver source code published by mtk https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/

Based on the above source code, I modified the hwnat driver that can run stably under linux 5.10. It supports offload of ipv4, ipv6 and wifi. For some reason I'm using the switch driver instead of the dsa driver. The steps to use this driver are as follows

  1. https://github.com/padavanonly/openwrt/tree/master/target/linux/ramips

Replace ramips folder of your openwrt source directory with the folder corresponding to the link

  1. This folder is only adapted to wr1200js, newifi d1, and k2p now. If you are on other models, you should refer to these two commits to modify the source code to adapt to your router.
    https://github.com/padavanonly/openwrt/commit/8a99f52a38e302a35acc31a8155d3b5243a3d7ad
    https://github.com/padavanonly/openwrt/commit/419d4efc0ee4f74d7c4151f5c3310e16c0cb870d

  2. Run rm .config. In theory, after re-make menuconfig, kmod-ramips_hnat will be automatically added to .config. Flash the compiled firmware, when you see the following log, it means hwnat is running successfully. To avoid conflicts, you should disable flow offload.

5 Likes

For the second step, the wan of 7621 has two cases. If your wan is port4, it should be

mediatek,portmap = "llllw";

ucidef_add_switch "switch0" \
  "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6u@eth0" "5u@eth1"
  ;;

And if your wan is port0, it should be

  mediatek,portmap = "wllll";

ucidef_add_switch "switch0" \
 "1:lan" "2:lan" "3:lan" "4:lan"   "0:wan" "6u@eth0" "5u@eth1"
  ;;

You can see whether your wan is port0 or port4 from the switch0 node in the original dts

3 Likes

But there are some mt7621 routers that only support one gmac, such as newifi3 d2, so the above steps are not suitable for these routers. I don't have time to adapt this kind of router, I hope people with energy can study it.

Can use on coolwolfsnow lede?

Any openwrt could use this driver if the kernel version is 5.10. But I haven't test firewall4.

Really appreciate your guidance

I'm curious how hard it would be to port this to DSA and kernel 5.15.x. Exciting that you have it up and running with 5.10 and the older switch code. Anything that helps out these little chipsets is a good thing. Thanks for digging into it. Hopefully people can pile on and get this into a usable PR.

In theory 5.15 can be used directly. As for dsa, mtk sdk lacks related patches, and I have the need to use switch myself, so I have no motivation to test dsa.

Good work.
It may sound ridiculous, but I want to ask can I disable the kernel driver in runtime to avoid using HWNAT? As we need monitoring bandwith sometimes but with HWNAT enabled, it won't work corretly...

solution found: using rmmod mtkhnat or modprobe mtkhnat to toggle mtkhwnat

i adapted it for my netgear r 6260, it's working, but is normal that no switch config in luci is present?

Anyone got this working on Redmi AX6000?

that's very easy i do not have that device, but check if kernel 5.10 or 5.4 is right
also that is not mt7621 chipset

swconfig package is needed

Hi @MeIsReallyBa
I have managed to compile OpenWrt 22.03 with your drivers for my DIR-878.
It works as expected, but I encountered one problem. I want to separate LAN 1 ports, so I create a new VLAN tagged to cpu and untagged to LAN 1, then I create a new interface for it. The new interface works, I got an IP address and internet connection from LAN 1, but the speed is very slow, around 1-2Mbps. If hnat is disabled using rmmod mtkhnat, I get full speed on LAN 1. Is it normal?
Sorry if this is a stupid question, I'm completely new to this, in fact it took me a week to successfully compile the firmware

you need select "bridge" in this interface

Hi, any chance you are interested in porting the mediatek target for 5.15? No clue about which files to patch to make it work for routers like Redmi AX6000.

I would like to know how to modify the installation and compilation of this version of openwrt with mediatek drivers with mtk hwnat, I tried to compile with the source code but the router does not start normally with the compilation. the router I have is the MI4A Gigabit. Is there another method or if someone has the image ready.