Permalink
Browse files

Added support for DSR NATs via --dsr

  • Loading branch information...
insomniacslk committed Sep 20, 2016
1 parent 0678b49 commit 3716453b9e0eeb05df6d3d7b1929b70adb8518a0
@@ -46,6 +46,7 @@ class DublinTraceroute {
IPv4Address target_;
const uint8_t npaths_,
max_ttl_;
const bool dsr_; // direct server response
std::mutex mutex_tracerouting,
mutex_sniffed_packets;
IPv4Address my_address;
@@ -56,45 +57,52 @@ class DublinTraceroute {
static const uint16_t default_dstport = 33434;
static const uint8_t default_npaths = 20;
static const uint8_t default_max_ttl = 30;
static const bool default_dsr = false;
DublinTraceroute(
const std::string &dst,
const uint16_t srcport = default_srcport,
const uint16_t dstport = default_dstport,
const uint8_t npaths = default_npaths,
const uint8_t max_ttl = default_max_ttl
const uint8_t max_ttl = default_max_ttl,
const bool dsr = default_dsr
):
srcport_(srcport),
dstport_(dstport),
dst_(dst),
npaths_(npaths),
max_ttl_(max_ttl)
max_ttl_(max_ttl),
dsr_(dsr)
{ }
DublinTraceroute(
const char *dst,
const uint16_t srcport = default_srcport,
const uint16_t dstport = default_dstport,
const uint8_t npaths = default_npaths,
const uint8_t max_ttl = default_max_ttl
const uint8_t max_ttl = default_max_ttl,
const bool dsr = default_dsr
):
srcport_(srcport),
dstport_(dstport),
dst_(std::string(dst)),
npaths_(npaths),
max_ttl_(max_ttl)
max_ttl_(max_ttl),
dsr_(dsr)
{ }
~DublinTraceroute() { std::lock_guard<std::mutex> lock(mutex_tracerouting); };
DublinTraceroute(const DublinTraceroute& source):
srcport_(source.srcport_),
dstport_(source.dstport_),
dst_(source.dst_),
npaths_(source.npaths_),
max_ttl_(source.max_ttl_)
max_ttl_(source.max_ttl_),
dsr_(source.dsr_)
{ }

inline const uint16_t srcport() const { return srcport_; }
inline const uint16_t dstport() const { return dstport_; }
inline const uint8_t npaths() const { return npaths_; }
inline const uint8_t max_ttl() const { return max_ttl_; }
inline const bool dsr() const { return dsr_; }
inline const std::string &dst() const { return dst_; }
inline const IPv4Address &target() const { return target_; }
void target(const IPv4Address &addr) { target_ = addr; }
@@ -24,9 +24,10 @@ class TracerouteResults {
private:
std::shared_ptr<flow_map_t> flows_;
bool compressed_;
bool dsr_;

public:
TracerouteResults(std::shared_ptr<flow_map_t> flows);
TracerouteResults(std::shared_ptr<flow_map_t> flows, const bool dsr /* = false */);
~TracerouteResults() { };
inline flow_map_t &flows() { return *flows_; }
std::shared_ptr<IP> match_packet(const Packet &packet);
@@ -170,7 +170,7 @@ TracerouteResults &DublinTraceroute::traceroute() {
}
std::shared_ptr<Sniffer> sniffer(_sniffer);

TracerouteResults *results = new TracerouteResults(flows);
TracerouteResults *results = new TracerouteResults(flows, dsr());

// configure the sniffing handler
auto handler = std::bind(
@@ -22,12 +22,14 @@ R"(Dublin Traceroute
[--dport=dest_base_port]
[--npaths=num_paths]
[--max-ttl=max_ttl]
[--dsr]
Options:
-s SRC_PORT --sport=SRC_PORT the source port to send packets from
-d DST_PORT --dport=DST_PORT the base destination port to send packets to
-n NPATHS --npaths=NPATHS the number of paths to probe
-t MAX_TTL --max-ttl=MAX_TTL the maximum TTL to probe
-d --dsr the network has a DSR NAT. May help when you only see a few hops
See documentation at https://dublin-traceroute.net
@@ -42,6 +44,7 @@ main(int argc, char **argv) {
long dport = DublinTraceroute::default_dstport;
long npaths = DublinTraceroute::default_npaths;
long max_ttl = DublinTraceroute::default_max_ttl;
bool dsr = DublinTraceroute::default_dsr;

std::map <std::string, docopt::value> args = docopt::docopt(
USAGE,
@@ -69,8 +72,11 @@ main(int argc, char **argv) {
CONVERT_TO_LONG_OR_EXIT(arg.second, dport);
} else if (arg.first == "--npaths") {
CONVERT_TO_LONG_OR_EXIT(arg.second, npaths);
} else if (arg.first == "--max-ttl")
} else if (arg.first == "--max-ttl") {
CONVERT_TO_LONG_OR_EXIT(arg.second, max_ttl);
} else if (arg.first == "--dsr") {
dsr = arg.second.asBool();
}
}
#undef CONVERT_TO_LONG_OR_EXIT
std::cout << "Source port: " << sport << std::endl;
@@ -103,7 +109,8 @@ main(int argc, char **argv) {
sport,
dport,
npaths,
max_ttl
max_ttl,
dsr
);
std::cout
<< "Traceroute from 0.0.0.0:" << Dublin.srcport()
@@ -21,8 +21,8 @@
#include "dublintraceroute/icmp_messages.h"


TracerouteResults::TracerouteResults(std::shared_ptr<flow_map_t> flows):
flows_(flows), compressed_(false) {
TracerouteResults::TracerouteResults(std::shared_ptr<flow_map_t> flows, const bool dsr = true):
flows_(flows), compressed_(false), dsr_(dsr) {
}


@@ -68,8 +68,10 @@ std::shared_ptr<IP> TracerouteResults::match_packet(const Packet &packet) {
unsigned int index = 0;
for (auto &hop: *hops) {
auto &sent = hop.sent()->rfind_pdu<IP>();
if (sent.src_addr() != inner_ip.src_addr())
continue;
if (!dsr_) {
if (sent.src_addr() != inner_ip.src_addr())
continue;
}
auto &udp = hop.sent()->rfind_pdu<UDP>();
/*
* The original paris-traceroute would match the checksum, but

0 comments on commit 3716453

Please sign in to comment.