What I want to implentent is something like below.
192.168.1.1 192.168.1.2
+--------+ +----------+ +-----------+ +---------+ +---------+
| APP0 +<---->+ tap0 +<------->+ myapp +<--------->+ tap1 +<----->+ APP1 |
+--------+ +----------+ +-----------+ +---------+ +---------+
- Launch
myapp
, which will create two tap device,tap0
andtap1
.myapp
will forward packet between this two tap devices. APP0
andAPP1
will communicate with standard tcp socket API.- All those app and tap device is in one linux system (Centos7.5).
But after create two tap devices, ping -I tap0 192.168.1.2
not success.
First I find there is ARP problem, and I resolve them by set accept_local
and rp_filter
file.
echo 1 > /proc/sys/net/ipv4/conf/tap0/accept_local
echo 1 > /proc/sys/net/ipv4/conf/tap1/accept_local
echo 2 > /proc/sys/net/ipv4/conf/tap0/rp_filter
echo 2 > /proc/sys/net/ipv4/conf/tap1/rp_filter;
With tcpdump
tool, I found ICMP request reached tap1
, but tap1
's ICMP reply went to lo
device. Linux will route local traffic all through lo
deivce.
How can I make local traffic skip lo
device and went to the tap devices?
I did some search and find some solutions which need to config NAT policy. I think they are complicate.