Permalink
Browse files

Merge pull request #16 from insomniacslk/min_ttl

Added support for --min-ttl
  • Loading branch information...
insomniacslk committed Oct 3, 2016
2 parents 97c145f + 3ea7077 commit 6b6be67df1ea17c7de20b8ee1e4fab664ee177eb
@@ -227,6 +227,7 @@ Usage:
dublin-traceroute <target> [--sport=SRC_PORT]
[--dport=dest_base_port]
[--npaths=num_paths]
[--min-ttl=min_ttl]
[--max-ttl=max_ttl]
[--broken-nat]
[--help]
@@ -238,7 +239,8 @@ 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
-t MIN_TTL --min-ttl=MIN_TTL the MINIMUM TTL to probe. Must be greater or equal than the minimum TTL
-T MAX_TTL --max-ttl=MAX_TTL the maximum TTL to probe
-b --broken-nat the network has a broken NAT configuration (e.g. no payload fixup). Try this if you see less hops than expected
@@ -15,7 +15,7 @@
* break on destination unreachable
* improve documentation
* put everything under a namespace
* implement command line parser in main.cc
* ~~implement command line parser in main.cc~~ done in [commit 8a3ae75](https://github.com/insomniacslk/dublin-traceroute/commit/8a3ae7513645afdad5eabd8d6f368383dff98c8b)
* Add an uninstall target in the Makefile for the python extension
* Fix the memory leak where TracerouteResults is not freed
* IP_ID_MATCHING must become a constructor parameter
@@ -30,3 +30,4 @@
* Integrate the ASN graph with a world map (e.g. openstreetmap or google maps)
* Add --webserver to the python CLI to expose a SimpleHTTPServer that serves a PNG with the traceroute diagram
* heat map/flame graph of the network latencies over time (links history)
* ~~improve the build system (there is just a static Makefile now)~~ done in [commit ffa9d3c](https://github.com/insomniacslk/dublin-traceroute/commit/ffa9d3c306fb772e2c95963a94cdc386b0126206), using CMake
@@ -45,6 +45,7 @@ class DublinTraceroute {
const std::string dst_;
IPv4Address target_;
const uint8_t npaths_,
min_ttl_,
max_ttl_;
const bool broken_nat_;
std::mutex mutex_tracerouting,
@@ -56,20 +57,23 @@ class DublinTraceroute {
static const uint16_t default_srcport = 12345;
static const uint16_t default_dstport = 33434;
static const uint8_t default_npaths = 20;
static const uint8_t default_min_ttl = 1;
static const uint8_t default_max_ttl = 30;
static const bool default_broken_nat = 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 min_ttl = default_min_ttl,
const uint8_t max_ttl = default_max_ttl,
const bool broken_nat = default_broken_nat
):
srcport_(srcport),
dstport_(dstport),
dst_(dst),
npaths_(npaths),
min_ttl_(min_ttl),
max_ttl_(max_ttl),
broken_nat_(broken_nat)
{ }
@@ -78,13 +82,15 @@ class DublinTraceroute {
const uint16_t srcport = default_srcport,
const uint16_t dstport = default_dstport,
const uint8_t npaths = default_npaths,
const uint8_t min_ttl = default_min_ttl,
const uint8_t max_ttl = default_max_ttl,
const bool broken_nat = default_broken_nat
):
srcport_(srcport),
dstport_(dstport),
dst_(std::string(dst)),
npaths_(npaths),
min_ttl_(min_ttl),
max_ttl_(max_ttl),
broken_nat_(broken_nat)
{ }
@@ -94,13 +100,15 @@ class DublinTraceroute {
dstport_(source.dstport_),
dst_(source.dst_),
npaths_(source.npaths_),
min_ttl_(source.min_ttl_),
max_ttl_(source.max_ttl_),
broken_nat_(source.broken_nat_)
{ }
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 min_ttl() const { return min_ttl_; }
inline const uint8_t max_ttl() const { return max_ttl_; }
inline const bool broken_nat() const { return broken_nat_; }
inline const std::string &dst() const { return dst_; }
@@ -23,11 +23,12 @@
class TracerouteResults {
private:
std::shared_ptr<flow_map_t> flows_;
uint8_t min_ttl = 1;
bool compressed_;
bool broken_nat_;
public:
TracerouteResults(std::shared_ptr<flow_map_t> flows, const bool broken_nat /* = false */);
TracerouteResults(std::shared_ptr<flow_map_t> flows, const uint8_t min_ttl /* = 1 */, const bool broken_nat /* = false */);
~TracerouteResults() { };
inline flow_map_t &flows() { return *flows_; }
std::shared_ptr<IP> match_packet(const Packet &packet);
@@ -69,6 +69,11 @@ std::shared_ptr<flow_map_t> DublinTraceroute::generate_per_flow_packets() {
target(IPv4Address(dst()));
}
// check for valid min and max TTL
if (min_ttl_ > max_ttl_) {
throw std::invalid_argument("max_ttl must be greater or equal than min_ttl");
}
// forge the packets to send
for (uint16_t dport = dstport(); dport < dstport() + npaths(); dport++) {
hops_t hops(new std::vector<Hop>());
@@ -86,7 +91,7 @@ std::shared_ptr<flow_map_t> DublinTraceroute::generate_per_flow_packets() {
* UDP.sport
* UDP.dport
*/
for (uint8_t ttl = 1; ttl <= max_ttl_; ttl++) {
for (uint8_t ttl = min_ttl_; ttl <= max_ttl_; ttl++) {
/*
* Adjust the payload for each flow to obtain the same UDP
* checksum. The UDP checksum is used to identify the flow.
@@ -170,7 +175,7 @@ TracerouteResults &DublinTraceroute::traceroute() {
}
std::shared_ptr<Sniffer> sniffer(_sniffer);
TracerouteResults *results = new TracerouteResults(flows, broken_nat());
TracerouteResults *results = new TracerouteResults(flows, min_ttl_, broken_nat());
// configure the sniffing handler
auto handler = std::bind(
@@ -15,14 +15,15 @@
#include <dublintraceroute/dublin_traceroute.h>
const char *shortopts = "hvs:d:n:t:b";
const char *shortopts = "hvs:d:n:t:T:b";
const struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{"sport", required_argument, NULL, 's'},
{"dport", required_argument, NULL, 'd'},
{"npaths", required_argument, NULL, 'n'},
{"max-ttl", required_argument, NULL, 't'},
{"min-ttl", required_argument, NULL, 't'},
{"max-ttl", required_argument, NULL, 'T'},
{"broken-nat", no_argument, NULL, 'b'},
{NULL, 0, NULL, 0},
};
@@ -36,6 +37,7 @@ Written by Andrea Barberio - https://insomniac.slackware.it
dublin-traceroute <target> [--sport=SRC_PORT]
[--dport=dest_base_port]
[--npaths=num_paths]
[--min-ttl=min_ttl]
[--max-ttl=max_ttl]
[--broken-nat]
[--help]
@@ -47,7 +49,8 @@ Written by Andrea Barberio - https://insomniac.slackware.it
-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
-t MIN_TTL --min-ttl=MIN_TTL the minimum TTL to probe
-T MAX_TTL --max-ttl=MAX_TTL the maximum TTL to probe. Must be greater or equal than the minimum TTL
-b --broken-nat the network has a broken NAT configuration (e.g. no payload fixup). Try this if you see less hops than expected
@@ -64,6 +67,7 @@ main(int argc, char **argv) {
long sport = DublinTraceroute::default_srcport;
long dport = DublinTraceroute::default_dstport;
long npaths = DublinTraceroute::default_npaths;
long min_ttl = DublinTraceroute::default_min_ttl;
long max_ttl = DublinTraceroute::default_max_ttl;
bool broken_nat = DublinTraceroute::default_broken_nat;
@@ -102,6 +106,9 @@ main(int argc, char **argv) {
TO_LONG(npaths, optarg);
break;
case 't':
TO_LONG(min_ttl, optarg);
break;
case 'T':
TO_LONG(max_ttl, optarg);
break;
case 'b':
@@ -136,10 +143,18 @@ main(int argc, char **argv) {
std::cerr << "Number of paths must be between 1 and 65535" << std::endl;
std::exit(EXIT_FAILURE);
}
if (min_ttl < 1 || min_ttl > 255) {
std::cerr << "Min TTL must be between 1 and 255" << std::endl;
std::exit(EXIT_FAILURE);
}
if (max_ttl < 1 || max_ttl > 255) {
std::cerr << "Max TTL must be between 1 and 255" << std::endl;
std::exit(EXIT_FAILURE);
}
if (min_ttl > max_ttl) {
std::cerr << "Min TTL must be smaller or equal than max TTL" << std::endl;
std::exit(EXIT_FAILURE);
}
if (dport + npaths - 1 > 65535) {
std::cerr << "Destination port + number of paths must not exceed 65535" << std::endl;
std::exit(EXIT_FAILURE);
@@ -152,6 +167,7 @@ main(int argc, char **argv) {
sport,
dport,
npaths,
min_ttl,
max_ttl,
broken_nat
);
@@ -160,6 +176,7 @@ main(int argc, char **argv) {
<< " to " << Dublin.dst()
<< ":" << Dublin.dstport() << "~" << (Dublin.dstport() + npaths - 1)
<< " (probing " << npaths << " path" << (npaths == 1 ? "" : "s")
<< ", min TTL is " << min_ttl
<< ", max TTL is " << max_ttl << ")"
<< std::endl;
@@ -21,8 +21,8 @@
#include "dublintraceroute/icmp_messages.h"
TracerouteResults::TracerouteResults(std::shared_ptr<flow_map_t> flows, const bool broken_nat = true):
flows_(flows), compressed_(false), broken_nat_(broken_nat) {
TracerouteResults::TracerouteResults(std::shared_ptr<flow_map_t> flows, const uint8_t min_ttl = 1, const bool broken_nat = true):
flows_(flows), min_ttl(min_ttl), compressed_(false), broken_nat_(broken_nat) {
}
@@ -107,7 +107,7 @@ void TracerouteResults::show(std::ostream &stream) {
icmpmessages icmpm;
for (auto &iter: flows()) {
unsigned int hopnum = 1;
unsigned int hopnum = min_ttl;
unsigned int index = 0;
uint16_t prev_nat_id = 0;
stream << "== Flow ID " << iter.first << " ==" << std::endl;
@@ -117,7 +117,7 @@ void TracerouteResults::show(std::ostream &stream) {
stream << "*" << std::endl;
} else {
// print the IP address of the hop
stream << hop.received()->src_addr() << " (" << *hop.name() << ")";
stream << hop.received()->src_addr() << " (" << *hop.name() << ")";
// print the response IP ID, useful to detect
// loops due to NATs, fake hops, etc

0 comments on commit 6b6be67

Please sign in to comment.