Thanks Fewi
I was on the same tack as you stated in your post. I have been able to get the outbound interface working fine using routing marks and a custom routing table. The issue now for me is I already have a huge mangle table for my packet marking rules.
To keep things tidy and to get maximum performance, I already have a stack of packet marking rules at the top of the routing table. These are filtered by routing mark. Below these are a stack of routing marking rules that are using DSCP codepoints, IP addresses and ports as filters. By putting these below as each packet flows through the router, it only needs to iterate up to about 10 packet marking rules based on a single parameter, being connection mark. It looks like this (Lines 0 to 3 removed for clarity)
[admin@MikroTik] > ip firewall mangle print detail
Flags: X - disabled, I - invalid, D - dynamic
3 ;;; Mark VOIP
chain=forward action=mark-packet new-packet-mark=VOIP passthrough=no
connection-mark=VOIP
4 ;;; Mark VC
chain=forward action=mark-packet new-packet-mark=VC passthrough=no
connection-mark=VC
5 ;;; Fast traffic
chain=forward action=mark-packet new-packet-mark=fast-traffic
passthrough=no connection-mark=fast-traffic
6 chain=output action=mark-packet new-packet-mark=fast-traffic
passthrough=no connection-mark=fast-traffic
7 ;;; slow traffic
chain=forward action=mark-packet new-packet-mark=Slow-Traffic
passthrough=no connection-mark=slow-traffic
8 ;;; http-upload
chain=forward action=mark-packet new-packet-mark=http-upload
passthrough=no connection-mark=http-upload
9 ;;; vpn-passthrough
chain=forward action=mark-packet new-packet-mark=vpn-passthrough
passthrough=no connection-mark=vpn-passthrough
10 ;;; Mark codepoint 46 as VOIP connection
chain=forward action=mark-connection new-connection-mark=VOIP
passthrough=no src-address=192.168.44.0/24 dscp=46
11 ;;; Zultys out 1 as VOIP
chain=forward action=mark-connection new-connection-mark=VOIP
passthrough=no protocol=udp src-address=192.168.44.12
12 ;;; Zultys out 2 as VOIP
chain=forward action=mark-connection new-connection-mark=VOIP
passthrough=no protocol=udp src-address=192.168.44.13
13 ;;; Classify ICMP as VOIP
chain=forward action=mark-connection new-connection-mark=VOIP
passthrough=no protocol=icmp
14 ;;; Mark VC
chain=forward action=mark-connection new-connection-mark=VC
passthrough=no protocol=udp src-address=192.168.44.32
15 ;;; DSCP 45
chain=forward action=mark-connection new-connection-mark=VC
passthrough=no dscp=45
16 chain=forward action=mark-packet new-packet-mark=http-upload
passthrough=no connection-mark=http-upload
17 ;;; Mark n-able as slow queue
chain=forward action=mark-connection new-connection-mark=slow-traffic
passthrough=yes src-address=192.168.44.5
18 ;;; Mark mail as slow queue
chain=forward action=mark-connection new-connection-mark=slow-traffic
passthrough=yes protocol=tcp dst-port=25
19 chain=forward action=mark-packet new-packet-mark=Slow-Traffic
passthrough=no connection-mark=slow-traffic
20 ;;; Mark HTTP outbound as http-upload
chain=forward action=mark-connection new-connection-mark=http-upload
passthrough=yes protocol=tcp src-port=80,443
21 ;;; Mark RDP and others as fast traffic
chain=forward action=mark-connection new-connection-mark=fast-traffic
passthrough=yes protocol=tcp src-port=3389,22,8291,7100-7150,7505
22 chain=forward action=mark-packet new-packet-mark=fast-traffic
passthrough=no connection-mark=fast-traffic
23 ;;; Fast output for router management
chain=output action=mark-connection new-connection-mark=fast-traffic
passthrough=yes protocol=tcp src-port=8291
24 chain=output action=mark-packet new-packet-mark=fast-traffic
passthrough=no connection-mark=fast-traffic
So I thought I could mark incoming new connections that come in on the specified interface with a routing mark. As I wanted the routing mark to be processed at least once on the way out, I used a connection mark on the originating packet. This would allow the packet to turn around and on the way out it would create a routing mark. This rule would be set to passthrough so the mangle table could create new connection marks for my QoS packet marking setup. I was hoping a single routing mark on the first packet would be enough and that the router would cache the routing table for all subsequent packets. The first rules looked like this. NOTE I have an input rule and a preroute rule so I could catch traffic to and through the router.
[MikroTik] > ip firewall mangle print detail
Flags: X - disabled, I - invalid, D - dynamic
0 ;;; Adhoc inbound connection on BDSL interface
chain=input action=mark-connection new-connection-mark=adhoc-bdsl
passthrough=no connection-state=new in-interface=4-Amcom-BDSL
1 chain=prerouting action=mark-connection new-connection-mark=adhoc-bdsl
passthrough=no connection-state=new in-interface=4-Amcom-BDSL
2 chain=prerouting action=mark-routing new-routing-mark=adhoc-bdsl
passthrough=yes connection-mark=adhoc-bdsl
Unfortunately it seems that the router does not cache routes for a single connection. It seems I have to use the connection marking method permanently for the adhoc-routing mechanism, so I will need to use a far less efficient method for my packet marking. I will have to change all my connection marking rules based on my QoS parameters to packet marking rules and the router will have to do much more work now.
That is, unless there is a way to get the router to cache its routes on a “per connection” basis.
Do you think this is possible?
Mark