title: How to pass packets between two network interfaces through manually written filter?
body: <p>I have two physical network adapters on the Linux machine: eth0 and eth1. eth0 is for users and eth1 has outer Network access. 
  Then I can do <code>iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE</code> and users can connect to Network behind the NAT.</p>
  
  <p>What I want to do: manually capture packets from eth0, inspect it (may be making some changes, dump etc.) and write back to eth1. Something like this:</p>
  
  <pre><code>         +-------------------------------------+
           |            / my program \           |
  user --- |eth0 ----- |tap0 --- tap1| ----- eth1| --- Network
           +-------------------------------------+
  </code></pre>
  
  <p>I've written a program, that opens tap0 and tap1, simply read from tap0 and write to tap1 and vice versa (no packet changes for now):</p>
  
  <pre><code>tap0 192.168.100.1
  tap1 192.168.200.1
  </code></pre>
  
  <p>Then: </p>
  
  <pre><code>ip route add &lt;outer network IP&gt; via 192.168.100.1
  iptables -t nat -A POSTROUTING -o tap0 -j MASQUERADE
  </code></pre>
  
  <p>I also tried; </p>
  
  <pre><code>iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE`)
  </code></pre>
  
  <p>I see ARP requests incoming on tap0, and outgoing from tap1 (repeated by my program), but nothing more.</p>
  
  <p><strong>How to make this packets to go to eth1? How to make all incoming packets on eth0 to go through my filter and to outer network (not only specific address)?</strong></p>