/ip/firewall/mangle
add action=mark-packet chain=input in-interface-list=WireGuard new-packet-mark=encrypted passthrough=yes
add action=passthrough chain=output out-interface-list=!WireGuard packet-mark=encrypted passthrough=yes
/routing rule
add action=lookup-only-in-table disabled=no interface="General Wifi" table=mullvad_general
I have a single wireguard address, so I'm masquerading that interface "WG1" with a src-nat rule. I have X clients on my LAN network that connect through wifi that I want to route all traffic through the WG1 interface. The policy rule simply looks up and routes all traffic according to the rules in that mullvad_general table which is just a default route 0.0.0.0/0 which has a nexthop or gateway of the WG1 interface. Everything here works as expected. The issue is when the router responds to traffic after a client has forcefully disconnected or there is an interruption and it sends ICMP back to the target it sends it through the default route in the main table. Instead of sending it back through the expected WG1 interface.What do you mean interface, what are you trying to send through wireguard a subnet ??
With regards to your approach are you saying I need to do something like below.I have the same rule and and yours routes traffic coming in through WiFi. Output is local so you have to match on the connection-mark you set. In Mangle output you can route it or kill it by setting TTL to 0.
icmp out output: in:(unknown 0) out:WAN (4000), connection-state:related,snat proto ICMP (type 3, code 1), WAN-IP->52.50.114.126, NAT (10.0.8.4->10.65.230.150)->52.50.114.126, len 80
it (the icmp 3 generation) depends on remote server requirements - which it needs to know the status of remote device accessing its service/ports (ie. doing keep alive while file transfer nor the tcp flags status from remote clients etc) for the server to close its open connection. so when the server sense it doesn't get the ack or fin flags - the server raise question to the offending ip - to remote device with icmp message (which is unfortunately your router masquerade ip). the router doesn't have the logic to return it back to the source if the conntrack is disabled (since the router still have that phone macaddr on the table). so the router looks like *blatantly* forwarding unknown traffic everywhere.To be clear, I orginally thought the router was responding to a ICMP packet but the actual situation is that flow of TCP packets that cannot be delivered generate a ICMP packet from the router back to the source letting them know the packet cannot be delivered etc.
/ip/firewall/mangle
add action=change-ttl chain=output comment="kill related out ICMP packets" icmp-options=3:0-255 new-ttl=set:0 passthrough=no protocol=icmp
add action=change-ttl chain=postrouting comment="Kill related ICMP OUT" icmp-options=3:0-255 log=yes log-prefix=KillRelatedOUT new-ttl=set:0 \
out-interface=!wireguard passthrough=no protocol=icmp
agreed. related means conntrack should be enabled. otherwise we will see huge amount of alien Traffic.ps. filtering on related is not needed because it is always related when the router answers on behalf.
add action=change-ttl chain=prerouting connection-state=invalid,untracked in-interface=wireguard log=yes log-prefix=KillInvalidInWG new-ttl=set:0 passthrough=no
Reading this I think this is not the golden bullet because the incoming traffic can be valid and have a active connection tracking. Only when the router want to push the traffic to the client the client says, won't accept it because I don't have an active memory of that connection.invalid - a packet that does not have a determined state in connection tracking (usually - severe out-of-order packets, packets with wrong sequence/ack number, or in case of a resource over usage on the router), for this reason, an invalid packet will not participate in NAT (as only connection-state=new packets do), and will still contain original source IP address when routed. We strongly suggest dropping all connection-state=invalid packets in firewall filter forward and input chains
absolutelyReading this I think this is not the golden bullet because the incoming traffic can be valid and have a active connection tracking. Only when the router want to push the traffic to the client the client says, won't accept it because I don't have an active memory of that connection.
so, afaik, which I always did to make the work easier... i always taught myself there are 2 modes of firewalling :
So the invalid + untracked limits but does not account for all traffic. This is my thought on that.
yes. but this chicken and the eggs thing could be overlap one another. which is who will close the door first: the server or the router?So the issue is really in between the connection closing and the NAT entry being deleted, the router responds with ICMP.
as i said on my previous post, your router doesn't have the logic to send back those *alien Traffic* unless you create that routing and connection mark for the wg tunnel.My question and this thread revolves around should this be the behavior of the router, should there be an option to not respond to ICMP on behalf of a client that was traversing through a WG tunnel or should there be the capability to route the ICMP automatically back through the associated WG tunnel.
output: in:(unknown 0) out:WAN (4000), connection-mark:wg_mark connection-state:related,snat proto ICMP (type 3, code 1), WAN-IP->142.250.27.188, NAT (10.0.8.254->10.65.230.150)->142.250.27.188, len 576
/ip firewall filter
add action=drop chain=output comment="Drop outgoing related router packets." connection-state=related out-interface-list=WAN
/ip firewall mangle
add action=passthrough chain=postrouting connection-state=related log=yes log-prefix=DetectRelated out-interface-list=WAN src-address=10.0.8.254
Now you have connection marked traffic going through the WG did you still see related ICMP traffic trying to out through the WAN?Changed the title back to ICMP only as I did many tests and was unable to replicate TCP/UDP packets leaking so I suspect I probably saw those show up when I was messing around with configs. I do continue to see the related ICMP packets being dropped as per the original scenario I outlined above.
well, after all these approaches you have tested for your icmp leakage concern, the first thing I have had noticed was your wg masquerade setup - which actually already doing partially good easy job to streamline forwarding traffic from your phone to the internet via wg tunnel.It is much easier to use the policy rules to steer the entire incoming interface's traffic to use a particular routing table. So for me I continue to do it that way versus the connection marking route and therefore I still need the drop rule on the router output chain.
internet ---- router ---- lan
| |
wg ----------------|
/routing rule
add action=lookup-only-in-table disabled=no interface="Home_Wifi" table=wg1_route
icmp out output: in:(unknown 0) out:WAN (4000), connection-state:related,snat proto ICMP (type 3, code 1), WAN-IP->52.50.114.126, NAT (10.0.8.4->10.65.230.150)->52.50.114.126, len 80
/ip firewall filter
add action=drop chain=output comment="Drop outgoing related router packets." connection-state=related out-interface-list=WAN
This is testing with connection-marking.If you use connection marks it works as expected because the connection is marked first when it exits Home_Wifi and that mark lives with the connection and all associated packets until the connection dies.
output: in:(unknown 0) out:sfp28-12, connection-mark:mullvad_tun connection-state:related,snat proto ICMP (type 3, code 1), WAN-IP->34.107.243.93, NAT (10.0.4.4->10.69.54.29)->34.107.243.93, len 209