dnsreplay: Add `--source-ip` and `--source-port` options
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 9 Mar 2017 14:59:44 +0000 (15:59 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Mar 2017 17:33:08 +0000 (18:33 +0100)
(cherry picked from commit 658b9c44802ae9791e8ce06a38a9ff84647d9463)

pdns/dnsreplay.cc

index 6ce3c065b7c0c48dee5e1855b73f1a74eb988fbe..30e31f65342c50451b63ea5b227fd48043cea481 100644 (file)
@@ -709,7 +709,9 @@ try
     ("speedup", po::value<float>()->default_value(1), "replay at this speedup")
     ("timeout-msec", po::value<uint32_t>()->default_value(500), "wait at least this many milliseconds for a reply")
     ("ecs-stamp", "Add original IP address to ECS in replay")
-    ("ecs-mask", po::value<uint16_t>(), "Replace first octet of src IP address with this value in ECS");
+    ("ecs-mask", po::value<uint16_t>(), "Replace first octet of src IP address with this value in ECS")
+    ("source-ip", po::value<string>()->default_value(""), "IP to send the replayed packet from")
+    ("source-port", po::value<uint16_t>()->default_value(0), "Port to send the replayed packet from");
 
   po::options_description alloptions;
   po::options_description hidden("hidden options");
@@ -759,6 +761,10 @@ try
   s_socket= new Socket(AF_INET, SOCK_DGRAM);
 
   s_socket->setNonBlocking();
+
+  if(g_vm.count("source-ip") && !g_vm["source-ip"].as<string>().empty())
+    s_socket->bind(ComboAddress(g_vm["source-ip"].as<string>(), g_vm["source-port"].as<uint16_t>()));
+
   setSocketReceiveBuffer(s_socket->getHandle(), 2000000);
   setSocketSendBuffer(s_socket->getHandle(), 2000000);