I have an issue with using a connection-mark in a NAT rule. (Background: We have a webcam behind a static IP and I want to limit access, it should be reachable only if the right subdomain - let’s say webcam.domain.tld, revealed by the HTTP Host:-header - was used.)
I have the following basic NAT rule (works):
chain=dstnat action=dst-nat to-addresses=192.168.200.11 to-ports=80 protocol=tcp in-interface=pppoe-out1 dst-port=80
I have the following mangle rule (works):
chain=prerouting action=mark-connection new-connection-mark=webcam passthrough=yes protocol=tcp dst-address=<public_ip> layer7-protocol=webcam dst-port=80 connection-mark=no-mark
I have the following L7 protocol rule (works):
NAME REGEXP
0 webcam Host: webcam.domain.tld
I can see requests made via the webcam.domain.tld URL to get marked as webcam (in WinBox).
Now, when I change the NAT rule to have the requirement “connection-mark=webcam”, it does NOT work anymore. No connection gets marked (and NATed) anymore.
It seems things are not happening in the order pre-routing, NAT?! Otherwise I would expect the mangle rule to still work?
Actually, this was my first approach. But since it did not work, I tried the step with the mangle rule inbetween, because there I could see that the connection actually gets marked (hence the rule worked). Or is there a more elegant method to troubleshoot an L7 regex?
webcam(any single character)domain(any single character)tld
Well, good point. I changed it to webcam.domain.tld now. (double backslashes when in terminal)
But something is really buggy with this L7 function; try the following:
The L7 rule itself is working, I can verify this by checking the connections - as long as I do not use the rule in NAT. If I connect using www.domain.tld it’s not marked, when I connect to webcam.domain.tld it gets marked. Perfect.
The problem (bug?) is in the NAT rule. It doesn’t matter if I add connection-mark or directly l7-protocol there, the NAT stops working.
since you tell router to just nat packet that marked with “webcam-mark”, and there is no packet to be nat at first packet (SYN) that have mark with “webcam-mark”. So, no connection can be established, and then no connection to be mark … IMHO