Community discussions

MikroTik App
 
alphalt
Member Candidate
Member Candidate
Topic Author
Posts: 100
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Traffic flow: why packet does not traverse SRC-NAT

Fri Jan 04, 2013 3:35 pm

Hello to all,

Recently I had an application that I needed to source NAT time server packets in order to solve 'server-ip-missmatch' issue, but found that thos epackets do not traverse through SRC-NAT chain. I've investigated a little bit and found that packets are traversing through mangle/postrouting and after that packet is like dissapear from router. So I did simple test:
/ip firewall mangle
add action=mark-packet chain=prerouting disabled=no new-packet-mark=ntp passthrough=yes protocol=udp src-port=123
/ip firewall nat
add action=passthrough chain=srcnat disabled=no packet-mark=ntp
0 packets traverse through SRC-NAT chain. Then I did even like this:
/ip firewall mangle
add action=mark-packet chain=prerouting disabled=no new-packet-mark=ntp passthrough=yes
/ip firewall nat
add action=passthrough chain=srcnat disabled=no packet-mark=ntp
Only few packets pass SRC-NAT chain and after doing logging I've found that only packets with broadcast destination address thraverse through SRC-NAT.
Out interface is bridged, but I've tried with 'use-ip-firewall' and without this option still same case. Most of all I can't understand why packets traverse mangle/postrouting, but not nat/src-nat ? According to packet flow diagram, src-nat is right after mangle/postrouting in the same postrouting chain.
Could please someone give me small explanation on what's happening ?

P.S. Everything seems to be ok when time server is external. I have this problem only when time server is Mikrotik itself.
 
CelticComms
Forum Guru
Forum Guru
Posts: 1765
Joined: Wed May 02, 2012 5:48 am

Re: Traffic flow: why packet does not traverse SRC-NAT

Fri Jan 04, 2013 4:12 pm

You have passthrough=yes on the mark-routing rule. Are there any other mark-routing rules below it? If there are they could be overwriting the mark.
 
alphalt
Member Candidate
Member Candidate
Topic Author
Posts: 100
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Traffic flow: why packet does not traverse SRC-NAT

Fri Jan 04, 2013 4:15 pm

Hi,

Thanks for replying. No. I've created this rule just for testing, so its the only one rule for packet mark. I'm experiencing same issue even if mangle/postrouting rule action is just passthrough.
 
alphalt
Member Candidate
Member Candidate
Topic Author
Posts: 100
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Traffic flow: why packet does not traverse SRC-NAT

Fri Jan 04, 2013 4:55 pm

After some more test I see that packet traverse like this (I've used action 'log', no packet marking):

Mangle Out (bridge interface) -> Filter Out (bridge interface) -> Mangle Postrouting (bridge interface) -> Bridge Out (eth3) -> Bridge Snat (eth3)

This is completely different of what you can see in packet flow diagram. Obviously I do not get the main idea :(
 
alphalt
Member Candidate
Member Candidate
Topic Author
Posts: 100
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Traffic flow: why packet does not traverse SRC-NAT

Sun Jan 06, 2013 10:46 pm

At last I took clean router os machine, set NTP time server there and made some tests with packet logging on every possible chain without using any bridges. Situation is the same. Packets do not traverse snat chain if I query NTP server from local computer. Same situation is with ping packets to the router. Snat chain is not traversed. When NTP or ping packets forwards router then everything s ok. Could anyone please explain this ? Maybe Mikrotik guys can answer this ? This is a little bit confusing when you look at packet flow diagram and see that packet can't escape postrouting chain once it had entered it, but in this case mangle postrouting is traversed, but not nat snat :(
 
alphalt
Member Candidate
Member Candidate
Topic Author
Posts: 100
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Traffic flow: why packet does not traverse SRC-NAT

Tue Jan 08, 2013 1:49 pm

Ok, I've found an answer. Funny thing is that answer was in iptables manual :)
 
rpardamean
just joined
Posts: 1
Joined: Fri Feb 08, 2013 5:37 am

Re: Traffic flow: why packet does not traverse SRC-NAT

Fri Feb 08, 2013 6:07 am

alphalt, Im having the exact problem, may you explain me your finding from iptables manual.

Thanks.
 
alphalt
Member Candidate
Member Candidate
Topic Author
Posts: 100
Joined: Sat Aug 01, 2009 1:53 pm
Location: Denmark

Re: Traffic flow: why packet does not traverse SRC-NAT

Fri Feb 08, 2013 8:42 am

Hi,

Read this http://www.frozentux.net/iptables-tutor ... NGOFTABLES
Remember that ESTABLISHED packets bypass SNAT and DNAT chains. From chapter 7:
All connection tracking is handled in the PREROUTING chain, except locally generated packets which are handled in the OUTPUT chain. What this means is that iptables will do all recalculation of states and so on within the PREROUTING chain. If we send the initial packet in a stream, the state gets set to NEW within the OUTPUT chain, and when we receive a return packet, the state gets changed in the PREROUTING chain to ESTABLISHED, and so on. If the first packet is not originated by ourself, the NEW state is set within the PREROUTING chain of course. So, all state changes and calculations are done within the PREROUTING and OUTPUT chains of the nat table.
 
midsizewisp
Frequent Visitor
Frequent Visitor
Posts: 55
Joined: Tue Dec 08, 2009 10:34 pm

Re: Traffic flow: why packet does not traverse SRC-NAT

Wed Mar 05, 2014 10:47 pm

alphalt, I'm still not understanding this. Any chance you could post the code you used to make it work?

Who is online

Users browsing this forum: broderick, Google [Bot], hazem, holvoetn, qatar2022, Tony93 and 113 guests