My target is simple : Build a high volume, fast, low latency soft switch using IP forwarding. I have a server test 'Server' and 2 test clients : 'Client1' & 'Client2'. 'Client1:c1' is sending udp packets to 'Server:s1' & 'Client2:c2' is sending udp packets to 'Server:s2'. I just wanna forward 'Client:c1' packets to 'Client:c2' and vice versa. Wouldn't mind if this is possible using only 1 port in sevrer. 'Client1' & 'Client2' is currently a simple udp sender thread which is sending udp packet continiously. Now I am applying rule :
sudo iptables --table nat --append PREROUTING --protocol udp --destination 'Server' --dport 's1' --jump DNAT --to-destination 'Client2:c2'
sudo iptables --table nat --append PREROUTING --protocol udp --destination 'Server' --dport 's2' --jump DNAT --to-destination 'Client1:c1'
sudo iptables --table nat --append POSTROUTING --protocol udp --destination 'Client2' --dport 'c2' --jump SNAT --to-source 'Server:s0'
sudo iptables --table nat --append POSTROUTING --protocol udp --destination 'Client1' --dport 'c1' --jump SNAT --to-source 'Server:s0'
And If I apply this rule at once and then start both 'Client1' & 'Client2' thread, it works just fine. Even if I delete all rules at once it also works fine but the problem starts if I start adding/deleting this rules 1 by 1 in the time where 'Client1' & 'Client2' is continiously sending data.
behaviour 1 : 'Client1' & 'Client2' running (nothing is happening as no rules are applied) and then I apply the 4 rules to 'Server' at once, then it should work just like previous, but not.. now 'Server' is only forwarding 'Client1' packets to 'Client2' and even SNAT isn't working for that. though after some indefinite time it works though. Other behaviour is just like this, when I am applying some rule to 'Server' iptable, the rule isn't taking effect immediately if 'Client1' & 'Client2' is running.
behaviour 2 : It also happened to me that I flushed the nat table and server was still forwarding for some time.
behaviour 3 : when applying/deleting per rule 1 by 1 while 'Client1' & 'Client2' is still sending/receiving, it wasn't taking effect randomly
I searched and found out in several post that iptables rule takes effect immediately, but for our case it isn't, specially some rules working and some not suddenly and what we are doing wrong here? is there some kind of cache 'Server' iptable maintaing or does it need reload though I found there is no option for reloading? ** I am not interested in 'socat' as it takes the packets to user-space which has bottleneck for high volume packets.** Thanks in advance for any help..!