2

I want to build a testbed including a client and a web server, where I can replay some logged http get requests to the web server. So I am planning to exactly simulating the actual traffic with requests with their original source address and port number.

To build the client, I am hopping that I can use the socket option IP_FREEBIND to bind to any possible source address and port number. Is there any known code for this purpose? (I really do not want to reinvent the wheel) Should I use the raw sockets as this thread is suggesting?

Any help will be greatly appreciated.

Community
  • 1
  • 1
Amir
  • 5,996
  • 13
  • 48
  • 61

2 Answers2

1

IP_FREEBIND is for listening on an address that the current host isn't configured with yet, so that if it's later configured with that address, your program can receive connections to it. It doesn't let you send packets that pretend to be from a different computer. You'd need a raw socket for that.

If you fake your packets' source address on the client, remember that the server will send its responses to that faked address. Your client has to be able to receive those return packets, because you need working two-way communication just to establish a TCP connection, before you can send the actual HTTP request. You could use raw sockets to implement your own whole fake IP layer, but it'd probably be much simpler to do your testing on an isolated network and just configure the client machine with whatever IP address you want the test requests to come from.

Wyzard
  • 33,849
  • 3
  • 67
  • 87
  • the set of source addresses could be any thing! I cannot set those addresses up on the client interfaces... How about IP_TRANSPARENT option? My network is isolated btw... – Amir Jan 16 '13 at 04:40
  • By "isolated network" I mean one that's not connected to the Internet. You can assign any address you want to your test client, even one that'd normally belong to some host "out there" on the Internet. IP_TRANSPARENT looks like it might do what you want, but you'll still need to set up routing on your test network so that packets sent to the fake address are delivered to the client machine. – Wyzard Jan 16 '13 at 13:19
  • Lets say I have figured out the routing in an isolated network disconnected from internet. The number of source addresses can be millions. It is practically impossible to assign them to the interface. – Amir Jan 16 '13 at 17:31
  • There is also another solution I was thinking and it is static nat. What if for each connection I add a rule to the iptable to the packet transformation for me... do you think it is scalable to thousand of connections? – Amir Jan 16 '13 at 17:32
0

You can try tcpcopy which replays http traffic with original source address.

wangbin579
  • 61
  • 2