Yigal Reiss
Yigal Reiss

Reputation: 71

Emulate arrival of traffic on specific interface

I would like to emulate arrival of traffic on a specific interface (e.g. eth0). I have quite strict requirements (and quite possibly this is not possible):

  1. I need to emulate arrival on a specific interface. E.g. on eth0. Sending the packets on another interface (e.g. tap0) does not resolve my problem.
  2. The solution has to be self contained, i.e. not involving another machine, not requiring connection of cables between interfaces or whatever other 'external' solutions.

To provide some context, I need the packets that I am sending to traverse the ip chain (specificlly I'm interested in netfilter hooks) exactly as if arriving on the defined interface. For example, if a rule exists in the iptables in the FORWARD chain of the filter table whose acceptance rule is '-i eth0', then the rule should match any packet sent by the requested mechanism.

Upvotes: 0

Views: 80

Answers (1)

Joel C
Joel C

Reputation: 3158

You'll need to create a kernel module to manually inject your packet(s) into the networking stack. The basic steps you'll need are:

  1. Create an SKB
  2. Set up the headers and data
  3. Find the struct net_device of the device you want to spoof (see here)
  4. Set skb->dev to the net_device found in step 3
  5. Call netif_rx_ni(skb) to push the packet up the stack

There is some code that does the vast majority of this at http://cdn.kerio.com/dwn/control/control-9.0.0-442/kerio-control-kipf-9.0.0-442-linux.tgz in drivers/ipf/linux/pkt.c at line 691 (the pkt_tx_rx_eth function). You can also see how the kernel TUN driver does it here.

Hope this helps! best of luck.

Upvotes: 1

Related Questions