I agree with the Cloudflare sentiment, and as someone who writes network services professionally, neglecting this irritates me to no end. (Btw. you can feel the writer’s frustration dripping between the lines )
The problem is that wg itself is connection-less, i.e. there is no “new” connection, just another handshake.
Let’s assume that wg did it the way you suggest. I am using my phone and in communication with a wg “server”. I’m using mobile data. I walk into my favorite coffee shop. My phone connects to their wifi. My phone sends out wg packets with the src address appropriate for my previously used LTE connection and not with the address acquired over wifi. Connection fails.
Clearly the packet should go out on the default route and pick up its src address from the pref address there.
This is what I tried to explain. The two decisions:
don’t differentiate between peers as “server” and “client”
support roaming IPs
don’t allow for setting the src address.
It’s not lazy coding, but a result of a philosophy regarding the protocol. One which obviously quite a few people don’t agree with… but not exactly a bug.
you packet ingresses the diagram titled “routing” at K
routing decision is made - please bear in mind that you packet has no src address, and so your third rule does not mach your packet - main is selected
src addr is set based on pref src in main
packet goes to output
(if snat happens, it happens here - but now this is of no interest for us)
at the end of output “routing adjustment” occurs - here the src address is already set and your third rule now matches: the packet is rerouted according to the *myas routing table; however in the routing adjustment phase, pref addr - as I wrote - is not consulted
Hence your packet goes out on the correct interface with the src address not set as you expected.
Please feel free to say so if you disagree on how/why this is happening…
Explained above. In the “routing decision” phase your rule cannot and does not match the packet, only in the “routing adjustment” does it pick up the route it eventually takes.
Let me be a bit clearer on this: someone actually wrote the code and it was not included. I know not what the future holds but if I were in a position to suggest what Mikrotik should do (which I am clearly not in,) I would probably wait until it’s settled in the kernel.
I think VRF support would be more elegant, however - and more practically - if the underlying behavior is clearly understood, dnat is in 99% of cases totally fine.
Thank you for your unusually thoughtful reply. Hope this clears things up at least somewhat.