I want to write a transparent proxy, setting a default route 0.0.0.0 for system, let all packets go through my tun(or wintun on windows) device.
By doing this I can read Ip frame from tun device, and inject into my lwip network stack to handle.
In order to learn how to do, I just read some transparent tools like https://github.com/eycorsican/leaf/blob/d35e649e620ab9f49be927962849f31e81054230/leaf/src/proxy/tun/inbound.rs#L111
But I stuck in routing loop. 0.0.0.0 default routes will routing all packets go through tun, so I can read all system packet.
If writing packets into tun device, and then kernel make a routing decision, it saw a default routes there and send it to tun device again which I just written a moment ago.
My question is:
Does it will read packets I just written?
If not, How the kernel or tun device avoid this?
As the https://superuser.com/a/1614808/944262 answer said
Either use a network namespace (then you can have two default routes)
I sure know user network stack can parse Ip frame which read from tun device, But what the aim to use it?