The "output" chain and VRFs/routing marks

Long time no post! :slight_smile:

I have a feeling that I already know the answer to this, but I’m hoping that I am overlooking some clever option or workaround.

Is there any way to influence which routing table packets generated by the router itself get processed by?

Here’s the situation: postulate 2 VRFs on a MikroTik router. Then postulate a common, overlapping prefix shared by both VRFs (e.g., 192.168.1.0/24), and the MikroTik holding 192.168.1.1 on an interface in each VRF. And then finally, postulate 2 devices, both associated with a different VRF but which both hold the same IP address within their respective VRF (e.g., 192.168.1.2). This is, of course, perfectly doable, and part of the point of VRFs.

But now, on top of all of this, I want device 1 in VRF 1 with IP address 192.168.1.2 and device 2 in VRF 2 with the same IP address 192.168.1.2 to both be able to take advantage of services offered by the host MikroTik at 192.168.1.1 (for example: NTP, TFTP, and so on). So far as I can tell, this is impossible. The problem is that the “output” chain always traverses the “main” routing table, so the MikroTik gets the NTP request or whatever from the client, but there is “no route to host” when it tries to send a response. I can make it work for one of the two clients either by adding a route entry to the main routing table or adding to IP route rules, but I can’t have it work for both clients (as long as they both have the same IP address).

Is there no way through connection tracking to have the MT respond via the VRF/table that the incoming request was received on? If not, any hacky workarounds that anybody might suggest? (I could accomplish this with MetaROUTER, but I don’t want the overhead if I can avoid it.)

Thanks,

– Nathan

Can’t some mangle rules on the output chain do this? Something like

/ip firewall mangle
add action=mark-routing chain=output out-interface=interface1 new-routing-mark=MARK1 passthrough=no
add action=mark-routing chain=output out-interface=interface2 new-routing-mark=MARK2 passthrough=no

MARK1 and MARK2 being the VRF marks?

Maybe use a connection mark per incoming interface to set the proper routing mark on output…

/ip firewall mangle
add action=mark-routing chain=output connection-mark=C-IF1 new-routing-mark=MARK1 passthrough=no
add action=mark-connection chain=prerouting in-interface=interface1 new-connection-mark=C-IF1 passthrough=no

docmarius,

Thanks. I am definitely sure that the first example wouldn’t work, because you can’t match on out-interface until the out-interface has been determined, and it can only be determined once you have already picked and traversed a specific routing table, so by the time out-interface has been determined, it is already too late.

However, your second example worked perfectly! It makes perfect sense, and I could swear that I tried something similar to this, and I was surprised when it did not work, but then later I managed to rationalize why it didn’t. I’ll have to figure out now what exactly I was doing wrong the first time!

It also happens to work just fine if I mark the connection in the “input” chain instead of “prerouting”, so that I am not marking all traffic being sent out by hosts on that VRF.

Thanks again,

– Nathan

You are correct in thinking that the “output” chain is after routing decisions are made. But the “output” chain apparently has a “routing adjustment” phase, which I assume is used if the routing mark was changed.
See: https://wiki.mikrotik.com/wiki/Manual:Packet_Flow_v6

My current policy routing mangle rules are as follows:

/ip firewall mangle
add action=mark-connection chain=prerouting comment=Wan2 connection-mark=no-mark connection-state=new in-interface=Wan2 \
    new-connection-mark=Wan2 passthrough=yes
add action=mark-packet chain=output connection-mark=Wan2 new-packet-mark=Wan2 packet-mark=no-mark passthrough=yes
add action=mark-routing chain=output new-routing-mark=Wan2 packet-mark=Wan2 passthrough=no
add action=mark-packet chain=prerouting connection-mark=Wan2 new-packet-mark=Wan2 packet-mark=no-mark passthrough=yes
add action=mark-routing chain=prerouting new-routing-mark=Wan2 packet-mark=Wan2 passthrough=no

Trying to account for both input and dstnat’ed forward traffic.
Also using packet marking on connection marked packets seem to be recommended, but the manual doesn’t seem to mention to much about all this.

Correct, route markings in output chain for locally generated traffic will be taken into account in the “route adjustment”, last phase of output chain, as mentioned.

I’m having the same issue.
I want to traceroute from one interface answered by this interface IP and not by the default route.

useful information, thanks

Instead you could use bookmark in your browser. Right-click the posting date line an select add bookmark.

OK BOSS! :smiley:

sorry for thanking here. :stuck_out_tongue_winking_eye:

msatter, have you decided your mentor is bartoz, though instead of shall not quote, and applying it as thou shalt not thank? ;-PP