Skip to content

Commit

Permalink
mtr v0.82
Browse files Browse the repository at this point in the history
 - Removed old Changelog file appended at the end as oldest changes.

2011-03-28 Mark Kamichoff <prox@prolixium.com>
 - Enable decoding of ICMP extensions for MPLS for curses and report
   interfaces.  Use the -e flag or press 'e' to enable it.

source: ftp://ftp.bitwizard.nl/mtr/mtr-0.82.tar.gz
  • Loading branch information
rewolff authored and traviscross committed Feb 3, 2013
1 parent b955477 commit a932cb2
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autom4te.cache
.deps
13 changes: 0 additions & 13 deletions ChangeLog

This file was deleted.

26 changes: 23 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
WHAT'S NEW?
V0.81 Fix for https://bugs.launchpad.net/mtr/+bug/776211
don't have time right now to integrate some submitted patches.
Sorry.
V0.82 Removed old Changelog file appended at the end as oldest
changes.
2011-03-28 Mark Kamichoff <prox@prolixium.com>
Enable decoding of ICMP extensions for MPLS for curses and
report interfaces. Use the -e flag or press 'e' to enable it.
V0.81 Moved to git. Testing git...
V0.80 Some compilation fixes for BSD by Jeremy Chadwick
<freebsd@jdc.parodius.com>
V0.78/0.79 some compilation fixes for BSD&others by
Expand Down Expand Up @@ -273,3 +276,20 @@ WHAT'S NEW?
Both the build process and the networking code have
been cleaned up and reorganized. mtr now builds
cleanly with GTK+ 0.99.8.

--- Below is the contents of the old "Changelog file" that annoyed some
people as it didn't contain any recent changes/news.

2002-03-06 Cougar <cougar@random.ee>
+ If hop doesn't respond, draw its name in red (GTK) or bold (curses)

2002-02-09 bodq <bohdan@vstu.edu.ua>
* Added --address option to bind to given IP addess

2001-04-15 root <alane@geeksrus.net>

* Added this file so that automake won't complain.
* Commented out the test for res_init in configure.in;
it does not work for GLIBC2 systems (e.g., RedHat 7+).
* Fixed the subordinate CHECK_LIBS on the test for res_mkquery,
so that they test for res_mkquery, not res_init.
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_INIT(mtr.c)
AM_INIT_AUTOMAKE(mtr, 0.81)
AM_INIT_AUTOMAKE(mtr, 0.82)


AC_SUBST(GTK_OBJ)
Expand Down
21 changes: 20 additions & 1 deletion curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ int mtr_curses_keyaction(void)
return ActionReset;
if (tolower(c) == 'd')
return ActionDisplay;
if (tolower(c) == 'e')
return ActionMPLS;
if (tolower(c) == 'n')
return ActionDNS;
if (c == '+')
Expand Down Expand Up @@ -263,6 +265,7 @@ int mtr_curses_keyaction(void)
mvprintw(2, 0, "Command:\n" );
printw(" ?|h help\n" );
printw(" d switching display mode\n" );
printw(" e toggle MPLS information on/off\n" );
printw(" n toggle DNS on/off\n" );
printw(" o str set the columns to display, default str='LRS N BAWV'\n" );
printw(" j toggle latency(LS NABWV)/jitter(DR AGJMXI) stats\n" );
Expand All @@ -288,11 +291,12 @@ void mtr_curses_hosts(int startstat)
{
int max;
int at;
struct mplslen *mpls, *mplss;
ip_t *addr, *addrs;
int y, x;
char *name;

int i, j;
int i, j, k;
int hd_len;
char buf[1024];

Expand All @@ -301,6 +305,7 @@ void mtr_curses_hosts(int startstat)
for(at = net_min () + display_offset; at < max; at++) {
printw("%2d. ", at + 1);
addr = net_addr(at);
mpls = net_mpls(at);

if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
name = dns_lookup(addr);
Expand Down Expand Up @@ -339,9 +344,20 @@ void mtr_curses_hosts(int startstat)
buf[hd_len] = 0;
printw("%s", buf);

for (k=0; k < mpls->labels && enablempls; k++) {
if((k+1 < mpls->labels) || (mpls->labels == 1)) {
/* if we have more labels */
printw("\n [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
} else {
/* bottom label */
printw("\n [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
}
}

/* Multi path by Min */
for (i=0; i < MAXPATH; i++ ) {
addrs = net_addrs(at, i);
mplss = net_mplss(at, i);
if ( addrcmp( (void *) addrs, (void *) addr, af ) == 0 ) continue;
if ( addrcmp( (void *) addrs, (void *) &unspec_addr, af ) == 0 ) break;

Expand All @@ -352,6 +368,9 @@ void mtr_curses_hosts(int startstat)
} else {
printw("\n %s", strlongip( addrs ) );
}
for (k=0; k < mplss->labels && enablempls; k++) {
printw("\n [MPLS: Lbl %lu Exp %u S %u TTL %u]", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
}
attroff(A_BOLD);
}

Expand Down
2 changes: 1 addition & 1 deletion display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* Don't put a trailing comma in enumeration lists. Some compilers
(notably the one on Irix 5.2) do not like that. -- REW */
enum { ActionNone, ActionQuit, ActionReset, ActionDisplay,
ActionClear, ActionPause, ActionResume, ActionDNS,
ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS,
ActionScrollDown, ActionScrollUp };
enum { DisplayReport, DisplayCurses, DisplayGTK, DisplaySplit,
DisplayRaw, DisplayXML, DisplayCSV, DisplayTXT};
Expand Down
15 changes: 14 additions & 1 deletion mtr.8
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mtr \- a network diagnostic tool
.SH SYNOPSIS
.B mtr
[\c
.B \-hvrctglspniu46\c
.B \-hvrctglspeniu46\c
]
[\c
.B \-\-help\c
Expand All @@ -35,6 +35,9 @@ mtr \- a network diagnostic tool
.B \-\-raw\c
]
[\c
.B \-\-mpls\c
]
[\c
.B \-\-no-dns\c
]
[\c
Expand Down Expand Up @@ -161,6 +164,16 @@ Use this option to force
to use the curses based terminal
interface (if available).

.TP
.B \-e
.TP
.B \-\-mpls
.br
Use this option to tell
.B mtr
to display information from ICMP extensions for MPLS (RFC 4950)
that are encoded in the response packets.

.TP
.B \-n
.TP
Expand Down
9 changes: 7 additions & 2 deletions mtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ char *Hostname = NULL;
char *InterfaceAddress = NULL;
char LocalHostname[128];
int dns = 1;
int enablempls = 0;
int cpacketsize = 64; /* default packet size */
int bitpattern = 0;
int tos = 0;
Expand Down Expand Up @@ -141,6 +142,7 @@ void parse_arg (int argc, char **argv)
overload psize<0, ->rand(min,max) */
{ "bitpattern", 1, 0, 'b' },/* overload b>255, ->rand(0,255) */
{ "tos", 1, 0, 'Q' }, /* typeof service (0,255) */
{ "mpls", 0, 0, 'e' },
{ "no-dns", 0, 0, 'n' },
{ "address", 1, 0, 'a' },
{ "first-ttl", 1, 0, 'f' }, /* -f & -m are borrowed from traceroute */
Expand All @@ -155,7 +157,7 @@ void parse_arg (int argc, char **argv)
while(1) {
/* added f:m:o: byMin */
opt = getopt_long(argc, argv,
"vhrwxtglpo:i:c:s:b:Q:na:f:m:u46", long_options, NULL);
"vhrwxtglpo:i:c:s:b:Q:ena:f:m:u46", long_options, NULL);
if(opt == -1)
break;

Expand Down Expand Up @@ -199,6 +201,9 @@ void parse_arg (int argc, char **argv)
case 'a':
InterfaceAddress = optarg;
break;
case 'e':
enablempls = 1;
break;
case 'n':
dns = 0;
break;
Expand Down Expand Up @@ -377,7 +382,7 @@ int main(int argc, char **argv)
if (PrintHelp) {
printf("usage: %s [-hvrwctglspniu46] [--help] [--version] [--report]\n"
"\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"
"\t\t[--raw] [--split] [--no-dns] [--address interface]\n" /* BL */
"\t\t[--raw] [--split] [--mpls] [--no-dns] [--address interface]\n" /* BL */
"\t\t[--psize=bytes/-s bytes]\n" /* ok */
"\t\t[--report-wide|-w] [-u]\n" /* rew */
"\t\t[--interval=SECONDS] HOSTNAME [PACKETSIZE]\n", argv[0]);
Expand Down
1 change: 1 addition & 0 deletions mtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef struct in6_addr ip_t;
typedef struct in_addr ip_t;
#endif

extern int enablempls;
extern int dns;
extern int use_dns;

Expand Down
77 changes: 75 additions & 2 deletions net.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ struct nethost {
int transit;
int saved[SAVED_PINGS];
int saved_seq_offset;
struct mplslen mpls;
struct mplslen mplss[MAXPATH];
};


Expand Down Expand Up @@ -434,7 +436,7 @@ void net_send_query(int index)

/* We got a return on something we sent out. Record the address and
time. */
void net_process_ping(int seq, void * addr, struct timeval now)
void net_process_ping(int seq, struct mplslen mpls, void * addr, struct timeval now)
{
int index;
int totusec;
Expand Down Expand Up @@ -467,10 +469,12 @@ void net_process_ping(int seq, void * addr, struct timeval now)
(void *) &unspec_addr, af ) == 0 ) {
/* should be out of if as addr can change */
addrcpy( (void *) &(host[index].addr), addrcopy, af );
host[index].mpls = mpls;
display_rawhost(index, (void *) &(host[index].addr));

/* multi paths by Min */
addrcpy( (void *) &(host[index].addrs[0]), addrcopy, af );
host[index].mplss[0] = mpls;
} else {
for( i=0; i<MAXPATH; ) {
if( addrcmp( (void *) &(host[index].addrs[i]), (void *) &addrcopy,
Expand All @@ -482,6 +486,7 @@ void net_process_ping(int seq, void * addr, struct timeval now)
if( addrcmp( (void *) &(host[index].addrs[i]), addrcopy, af ) != 0 &&
i<MAXPATH ) {
addrcpy( (void *) &(host[index].addrs[i]), addrcopy, af );
host[index].mplss[i] = mpls;

/* rafaelmartins: multi path support to '--raw' */
display_rawhost(index, (void *) &(host[index].addrs[i]));
Expand Down Expand Up @@ -565,6 +570,10 @@ void net_process_return(void)
int echoreplytype = 0, timeexceededtype = 0, unreachabletype = 0;
int sequence = 0;

/* MPLS decoding */
struct mplslen mpls;
mpls.labels = 0;

gettimeofday(&now, NULL);
switch ( af ) {
case AF_INET:
Expand Down Expand Up @@ -623,6 +632,10 @@ void net_process_return(void)
header = (struct ICMPHeader *)(packet + sizeof (struct IPHeader) +
sizeof (struct ICMPHeader) +
sizeof (struct IPHeader));

if(num > 160)
decodempls(num, packet, &mpls, 156);

break;
#ifdef ENABLE_IPV6
case AF_INET6:
Expand All @@ -632,6 +645,10 @@ void net_process_return(void)
header = (struct ICMPHeader *) ( packet +
sizeof (struct ICMPHeader) +
sizeof (struct ip6_hdr) );

if(num > 140)
decodempls(num, packet, &mpls, 136);

break;
#endif
}
Expand All @@ -656,6 +673,10 @@ void net_process_return(void)
udpheader = (struct UDPHeader *)(packet + sizeof (struct IPHeader) +
sizeof (struct ICMPHeader) +
sizeof (struct IPHeader));

if(num > 160)
decodempls(num, packet, &mpls, 156);

break;
#ifdef ENABLE_IPV6
case AF_INET6:
Expand All @@ -665,6 +686,10 @@ void net_process_return(void)
udpheader = (struct UDPHeader *) ( packet +
sizeof (struct ICMPHeader) +
sizeof (struct ip6_hdr) );

if(num > 140)
decodempls(num, packet, &mpls, 136);

break;
#endif
}
Expand All @@ -674,7 +699,7 @@ void net_process_return(void)
}

if (sequence)
net_process_ping(sequence, (void *)fromaddress, now);
net_process_ping (sequence, mpls, (void *) fromaddress, now);
}


Expand All @@ -689,6 +714,15 @@ ip_t *net_addrs(int at, int i)
return (ip_t *)&(host[at].addrs[i]);
}

void *net_mpls(int at)
{
return (struct mplslen *)&(host[at].mplss);
}

void *net_mplss(int at, int i)
{
return (struct mplslen *)&(host[at].mplss[i]);
}

int net_loss(int at)
{
Expand Down Expand Up @@ -1261,3 +1295,42 @@ void addrcpy( char * a, char * b, int af ) {
#endif
}
}

/* Decode MPLS */
void decodempls(int num, char *packet, struct mplslen *mpls, int offset) {

int i;
unsigned int ext_ver, ext_res, ext_chk, obj_hdr_len;
u_char obj_hdr_class, obj_hdr_type;

/* loosely derived from the traceroute-nanog.c
* decoding by Jorge Boncompte */
ext_ver = packet[offset]>>4;
ext_res = (packet[offset]&15)+ packet[offset+1];
ext_chk = ((unsigned int)packet[offset+2]<<8)+packet[offset+3];

/* Check for ICMP extension header */
if (ext_ver == 2 && ext_res == 0 && ext_chk != 0 && num >= (offset+6)) {
obj_hdr_len = ((int)packet[offset+4]<<8)+packet[offset+5];
obj_hdr_class = packet[offset+6];
obj_hdr_type = packet[offset+7];

/* make sure we have an MPLS extension */
if (obj_hdr_len >= 8 && obj_hdr_class == 1 && obj_hdr_type == 1) {
/* how many labels do we have? will be at least 1 */
mpls->labels = (obj_hdr_len-4)/4;

/* save all label objects */
for(i=0; (i<mpls->labels) && (i < MAXLABELS) && (num >= (offset+8)+(i*4)); i++) {

/* piece together the 20 byte label value */
mpls->label[i] = ((unsigned long) (packet[(offset+8)+(i*4)] << 12 & 0xff000) +
(unsigned int) (packet[(offset+9)+(i*4)] << 4 & 0xff0) +
(packet[(offset+10)+(i*4)] >> 4 & 0xf));
mpls->exp[i] = (packet[(offset+10)+(i*4)] >> 1) & 0x7;
mpls->s[i] = (packet[(offset+10)+(i*4)] & 0x1); /* should be 1 if only one label */
mpls->ttl[i] = packet[(offset+11)+(i*4)];
}
}
}
}
Loading

0 comments on commit a932cb2

Please sign in to comment.