0

I'm implementing some kind of router which has multiple internet connections, based on current throughput of those connections it would forward packets/frames using faster connection.

In order to test my implementation I have to have some actual packets to route. In order to generate some traffic I implemented IP packet fragmentation. I almost found myself implementing TCP reliable connection to generate some traffic. I tried to look for a way to generate some traffic and thought I would open socket connection from IP A on local machine to IP B on remote host. I would send some data on that connection so I wouldn't have to bother with packet generation.

And here is the problem, I must intercept those packets in order to route them in my router. I initially thought I would create some rule to forward every packet to IP B back to localhost, I would open raw socket on localhost and filter out all packets with destination IP B. I tried to make iptables rule: sudo iptables -t nat -A OUTPUT -d some_ip -j DNAT --to-destination 127.0.0.1 but as I found out it was changing destination IP address of packet, and I just wanted to intercept original packet in order to route it.

Do you have any idea how to generate some traffic that I could capture or how to configure iptables to forward packets going to specified IP back to host but preserving original destination IP address?

Clarification: The program I'm developing is distributed system, think of it as of few Raspberry Pis of which one is actual process routing packets and the rest are relays with dedicated internet connections, the router process chooses best relay to forward the packets. The processes across the system communicate via MPI communicator, the whole thing is implemented using MPI. So in a sense it's kind of software-router if that makes sense.

  • I don’t understand the frame of your question. Are you saying that you are developing router software and you are testing it by running it in a process on a computer that isn’t even configured as a router?  If that’s the case, then the question makes some sense (but it sounds like a dubious way of testing router software). … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete. – Scott Jul 13 at 17:22
0

I'm implementing some kind of router which has multiple internet connections, based on current throughput of those connections it would forward packets/frames using faster connection.

That won't work for standard protocols like TCP or UDP because they are not multi-homed. Each of your internet "connections" will have a different IP, and that IP cannot change during a single TCP or UDP connection.

The best you can do is to distribute new TCP or UDP connections to your different internet providers according to current usage. And you might actually be able to do it by changing iptables NAT rules as required (the connection tracker of the Linux kernel will make sure that existing connections don't change their route).

Do you have any idea [...] how to configure iptables to forward packets going to specified IP back to host but preserving original destination IP address?

You can't.

If this is for a specific application where you control both the ends of the communication, consider using a multi-homed protocol (e.g. SCTP or Multipath TCP) instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.