Bug#472509: mtr: UDP patch
Hi Rogier, On Tue, 15 Apr 2008 18:35:00 +0200 Rogier Wolff [EMAIL PROTECTED] wrote: In my version we currently open sockets on line 327, drop permissions on line 333, and call srand and further things around 345. Which version are you looking at. (I'm in my 0.74 directory, which is currently the same as the released 0.73. ) Ah, that might explain the confusion :-) I patched against 0.72, which was the latest release at the time. If you need me to write a new patch against 0.73 let me know. Kind regards, Martin -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#472509: mtr: UDP patch
Hi Rogier, On Wed, 16 Apr 2008 11:27:00 +0200 Rogier Wolff [EMAIL PROTECTED] wrote: On Wed, Apr 16, 2008 at 11:03:19AM +0200, Martin Pels wrote: Which patch are you looking at? The wrong one apparently. Ok, I'm glad that's sorted :-) The one Mark attached to his message (mtr-0.72-prox5.patch) is moving the security stuff around, like you're saying. But the patches I added to my messages (mp-20080324-mtr-0.72-udp.patch and mp-20070724-mtr-0.72-udp.patch) do not. OK. So, what's the difference between the two? Why are there two patches, and where do I find the other one? (i.e. I can now only find one of them) Please send them both to me and Explain why I should apply both? which one? what order? why? There are two patches: mp-20070724-mtr-0.72-udp.patch and mp-20080324-mtr-0.72-udp.patch. I attached both. The 2007 patch does not have the GUI u command. Because of this net_selectsocket() can (and does) close either the ICMP or the UDP socket after it finds out which one will be needed. The 2008 patch does have the GUI u command. Because of this net_selectsocket() does not close one of the sockets, because it might be needed later when the program switches from ICMP to UDP or the other way round. That's the only difference. I leave it up to you to decide which one to apply. Kind regards, Martin diff -Naur mtr-0.72.orig/mtr.8 mtr-0.72/mtr.8 --- mtr-0.72.orig/mtr.8 2006-09-29 21:33:06.0 +0200 +++ mtr-0.72/mtr.8 2007-07-24 13:53:46.0 +0200 @@ -8,7 +8,7 @@ .SH SYNOPSIS .B mtr [\c -.B \-hvrctglspni46\c +.B \-hvrctglspniu46\c ] [\c .B \-\-help\c @@ -208,6 +208,11 @@ ECHO requests. The default value for this parameter is one second. .TP +.B \-u +.br +Use UDP datagrams instead of ICMP ECHO. + +.TP .B \-4 .br Use IPv4 only. diff -Naur mtr-0.72.orig/mtr.c mtr-0.72/mtr.c --- mtr-0.72.orig/mtr.c 2006-09-29 21:38:49.0 +0200 +++ mtr-0.72/mtr.c 2007-07-24 13:53:43.0 +0200 @@ -65,6 +65,7 @@ int bitpattern = 0; int tos = 0; int af = DEFAULT_AF; +int mtrtype = IPPROTO_ICMP; /* Use ICMP as default packet type */ /* begin ttl windows addByMin */ int fstTTL = 1;/* default start at first hop */ @@ -143,6 +144,7 @@ { address, 1, 0, 'a' }, { first-ttl, 1, 0, 'f' }, /* -f -m are borrowed from traceroute */ { max-ttl, 1, 0, 'm' }, +{ udp, 0, 0, 'u' }, /* UDP (default is ICMP) */ { inet, 0, 0, '4' }, /* IPv4 only */ { inet6, 0, 0, '6' }, /* IPv6 only */ { 0, 0, 0, 0 } @@ -152,7 +154,7 @@ while(1) { /* added f:m:o: byMin */ opt = getopt_long(argc, argv, - vhrxtglpo:i:c:s:b:Q:na:f:m:46, long_options, NULL); + vhrxtglpo:i:c:s:b:Q:na:f:m:u46, long_options, NULL); if(opt == -1) break; @@ -253,6 +255,9 @@ tos = 0; } break; +case 'u': + mtrtype = IPPROTO_UDP; + break; case '4': af = AF_INET; break; @@ -354,13 +359,19 @@ parse_arg (argc, argv); + /* Now that we know mtrtype we can select which socket to use */ + if (net_selectsocket() != 0) { +fprintf( stderr, mtr: Couldn't determine raw socket type.\n ); +exit( EXIT_FAILURE ); + } + if (PrintVersion) { printf (mtr VERSION \n); exit(0); } if (PrintHelp) { -printf(usage: %s [-hvrctglspni46] [--help] [--version] [--report]\n +printf(usage: %s [-hvrctglspniu46] [--help] [--version] [--report]\n \t\t[--report-cycles=COUNT] [--curses] [--gtk]\n \t\t[--raw] [--split] [--no-dns] [--address interface]\n /* BL */ \t\t[--psize=bytes/-s bytes]\n/* ok */ diff -Naur mtr-0.72.orig/net.c mtr-0.72/net.c --- mtr-0.72.orig/net.c 2006-09-29 21:31:01.0 +0200 +++ mtr-0.72/net.c 2007-07-24 13:53:35.0 +0200 @@ -54,6 +54,22 @@ uint16 sequence; }; +/* Structure of an UDP header. */ +struct UDPHeader { + uint16 srcport; + uint16 dstport; + uint16 length; + uint16 checksum; +}; + +/* Structure of an IPv4 UDP pseudoheader. */ +struct UDPv4PHeader { + uint32 saddr; + uint32 daddr; + uint8 zero; + uint8 protocol; + uint16 len; +}; /* Structure of an IP header. */ struct IPHeader { @@ -77,6 +93,7 @@ #define ICMP_TSTAMPREPLY 14 #define ICMP_TIME_EXCEEDED 11 +#define ICMP_UNREACHABLE3 #ifndef SOL_IP #define SOL_IP 0 @@ -131,8 +148,12 @@ inttimestamp; intsendsock4; +intsendsock4_icmp; +intsendsock4_udp; intrecvsock4; intsendsock6; +intsendsock6_icmp; +intsendsock6_udp; intrecvsock6; intsendsock; intrecvsock; @@ -175,7 +196,7 @@ extern int bitpattern; /* packet bit pattern used by ping */ extern int tos; /* type of service set in ping packet*/ extern int af; /* address family of remote target */ - +extern int mtrtype; /* type of query packet used */ /* return the number of microseconds to wait before sending the next ping */ @@ -206,14 +227,40 @@ }
Bug#472509: mtr: UDP patch
Hi Rogier, Thanks for the reply. On Mon, 14 Apr 2008 21:09:56 +0200 Rogier Wolff [EMAIL PROTECTED] wrote: Hi guys, Looks nice. One problem I have with this is that the amount of code that is exposed to security problems has gone up a factor of ten... How much work would it be to open both the new UDP port and the old ICMP port, and discard the one we don't need? How can the program switch (with the GUI u command) if it hasn't preopened the sockets anyway? Depending on whether IP_HDRINCL is defined net_preopen() creates an icmp and udp socket, or a single raw socket. If we have two sockets it is trivial to close them in net_selectsocket(). This is actually what I did in the first version of the patch I sent you last year (attached for completeness). If we only have a single raw socket there is nothing we need to close. Closing sockets will inevitably break the GUI u command, because after we drop privileges we cannot open new sockets. So maybe we should only enable this functionality when raw sockets are available. Kind regards, Martin On Mon, Apr 14, 2008 at 11:35:03AM -0400, Mark Kamichoff wrote: I wrote a patch for Mtr 0.72 to implement UDP support. You can find it attached. UDP mode is enabled using the -u commandline switch, or by typing u in the GUI. The patch has been tested on Debian testing/unstable, both on IPv4 and IPv6. I have written a patch (see attached) as well that adds similar UDP functionality. There are some differences in the choice of destination ports used, with the original goal of emulating classic traceroute(8) behavior. The port range of 100 can cause erroneous loss on some paths since it is used to store sequence numbers, but 'most' of the time it is not noticable. That being said, Martin's patch seems to be the best choice for inclusion, as it does not suffer from this problem, and is overall of cleaner design. It would be great to see it included in MTR, as I believe it would add considerable flexibility to the utility. - Mark -- Mark Kamichoff [EMAIL PROTECTED] http://prolixium.com/ Rensselaer Polytechnic Institute, Class of 2004 Only in mtr-0.72-new: .deps diff -ur mtr-0.72/ChangeLog mtr-0.72-new/ChangeLog --- mtr-0.72/ChangeLog 2004-08-26 03:56:53.0 -0400 +++ mtr-0.72-new/ChangeLog 2008-04-14 10:33:16.0 -0400 @@ -1,3 +1,24 @@ +2008-04-13 Mark Kamichoff [EMAIL PROTECTED] + + * Changed the UDP sequence number storage to be source port - + UDP_PORT_MIN. This allows us 100 packets to be in-flight at any + time, without losing track. Right now we're using the classic + traceroute ports, but might need to increase this in the future. + * Added UDP checksum calculation for both IPv4 and IPv6. Source + address _must_ be specified at this point, due to a problem with + getsockname(2) not filling in the address structure completely. + * Added a line in the curses output to display protocol type. + * Fixed IPv6 support (see first entry). + +2008-04-11 Mark Kamichoff [EMAIL PROTECTED] + + * Fixed bug displaying localaddr (always displayed ANY) + +2007-03-27 Mark Kamichoff [EMAIL PROTECTED] + + * Preliminary UDP (-P udp) support. IPv6 doesn't work with it, + yet, since we're using the IP ID field for sequence numbers. + 2002-03-06 Cougar [EMAIL PROTECTED] + If hop doesn't respond, draw its name in red (GTK) or bold (curses) Only in mtr-0.72-new: Makefile Only in mtr-0.72-new: config.h Only in mtr-0.72-new: config.log Only in mtr-0.72-new: config.status diff -ur mtr-0.72/curses.c mtr-0.72-new/curses.c --- mtr-0.72/curses.c 2006-09-29 15:40:09.0 -0400 +++ mtr-0.72-new/curses.c 2008-04-14 10:33:16.0 -0400 @@ -75,6 +75,7 @@ extern int tos; extern float WaitTime; extern int af; +extern int protocol; void pwcenter(char *str) { @@ -506,6 +507,22 @@ time(t); mvprintw(1, maxx-25, ctime(t)); + /* display protocol -- MK */ + if(protocol == 17) { +mvprintw(2, 0, Protocol: UDP\n); + } else { +#ifdef ENABLE_IPV6 +switch ( af ) { +case AF_INET6: + mvprintw(2, 0, Protocol: ICMPv6\n); + break; +#endif +case AF_INET: + mvprintw(2, 0, Protocol: ICMP\n); + break; +} + } + printw(Keys: ); attron(A_BOLD); printw(H); attroff(A_BOLD); printw(elp ); attron(A_BOLD); printw(D); attroff(A_BOLD); printw(isplay mode ); Only in mtr-0.72-new: curses.o Only in mtr-0.72-new: display.o Only in mtr-0.72-new: dns.o Only in mtr-0.72-new: getopt.o Only in mtr-0.72-new: getopt1.o Only in mtr-0.72-new/img: Makefile Only in mtr-0.72-new: mtr diff -ur mtr-0.72/mtr.c mtr-0.72-new/mtr.c --- mtr-0.72/mtr.c 2006-09-29 15:38:49.0 -0400 +++ mtr-0.72-new/mtr.c 2008-04-14 10:33:16.0 -0400 @@
Bug#472509: mtr: UDP patch
On Tue, Apr 15, 2008 at 04:41:15PM +0200, Martin Pels wrote: Depending on whether IP_HDRINCL is defined net_preopen() creates an icmp and udp socket, or a single raw socket. If we have two sockets it is trivial to close them in net_selectsocket(). This is actually what I did in the first version of the patch I sent you last year (attached for completeness). If we only have a single raw socket there is nothing we need to close. Closing sockets will inevitably break the GUI u command, because after we drop privileges we cannot open new sockets. So maybe we should only enable this functionality when raw sockets are available. OK. Why then was the opening of the sockets delayed to after the parsing of the cmdline? This is the problem: Lots of complicated code which might be exploited. I feel much more comfortable passing one (or two) open sockets down the line towards the rest of the code Roger. -- ** [EMAIL PROTECTED] ** http://www.BitWizard.nl/ ** +31-15-2600998 ** **Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233** *-- BitWizard writes Linux device drivers for any device you may have! --* Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement. Does it sit on the couch all day? Is it unemployed? Please be specific! Define 'it' and what it isn't doing. - Adapted from lxrbot FAQ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#472509: mtr: UDP patch
On Tue, 15 Apr 2008 17:15:18 +0200 Rogier Wolff [EMAIL PROTECTED] wrote: On Tue, Apr 15, 2008 at 04:41:15PM +0200, Martin Pels wrote: Depending on whether IP_HDRINCL is defined net_preopen() creates an icmp and udp socket, or a single raw socket. If we have two sockets it is trivial to close them in net_selectsocket(). This is actually what I did in the first version of the patch I sent you last year (attached for completeness). If we only have a single raw socket there is nothing we need to close. Closing sockets will inevitably break the GUI u command, because after we drop privileges we cannot open new sockets. So maybe we should only enable this functionality when raw sockets are available. OK. Why then was the opening of the sockets delayed to after the parsing of the cmdline? This is the problem: Lots of complicated code which might be exploited. I feel much more comfortable passing one (or two) open sockets down the line towards the rest of the code It is not. We open sockets on line 290, drop privileges on line 295 and start parsing options and arguments on line 310. Regards, Martin -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#472509: mtr: UDP patch
On Tue, Apr 15, 2008 at 05:56:36PM +0200, Martin Pels wrote: On Tue, 15 Apr 2008 17:15:18 +0200 Rogier Wolff [EMAIL PROTECTED] wrote: On Tue, Apr 15, 2008 at 04:41:15PM +0200, Martin Pels wrote: Depending on whether IP_HDRINCL is defined net_preopen() creates an icmp and udp socket, or a single raw socket. If we have two sockets it is trivial to close them in net_selectsocket(). This is actually what I did in the first version of the patch I sent you last year (attached for completeness). If we only have a single raw socket there is nothing we need to close. Closing sockets will inevitably break the GUI u command, because after we drop privileges we cannot open new sockets. So maybe we should only enable this functionality when raw sockets are available. OK. Why then was the opening of the sockets delayed to after the parsing of the cmdline? This is the problem: Lots of complicated code which might be exploited. I feel much more comfortable passing one (or two) open sockets down the line towards the rest of the code It is not. We open sockets on line 290, drop privileges on line 295 and start parsing options and arguments on line 310. In my version we currently open sockets on line 327, drop permissions on line 333, and call srand and further things around 345. Which version are you looking at. (I'm in my 0.74 directory, which is currently the same as the released 0.73. ) Roger. -- ** [EMAIL PROTECTED] ** http://www.BitWizard.nl/ ** +31-15-2600998 ** **Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233** *-- BitWizard writes Linux device drivers for any device you may have! --* Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement. Does it sit on the couch all day? Is it unemployed? Please be specific! Define 'it' and what it isn't doing. - Adapted from lxrbot FAQ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#472509: mtr: UDP patch
On Tue, Apr 15, 2008 at 05:56:36PM +0200, Martin Pels wrote: On Tue, 15 Apr 2008 17:15:18 +0200 Rogier Wolff [EMAIL PROTECTED] wrote: On Tue, Apr 15, 2008 at 04:41:15PM +0200, Martin Pels wrote: Depending on whether IP_HDRINCL is defined net_preopen() creates an icmp and udp socket, or a single raw socket. If we have two sockets it is trivial to close them in net_selectsocket(). This is actually what I did in the first version of the patch I sent you last year (attached for completeness). If we only have a single raw socket there is nothing we need to close. Closing sockets will inevitably break the GUI u command, because after we drop privileges we cannot open new sockets. So maybe we should only enable this functionality when raw sockets are available. OK. Why then was the opening of the sockets delayed to after the parsing of the cmdline? This is the problem: Lots of complicated code which might be exploited. I feel much more comfortable passing one (or two) open sockets down the line towards the rest of the code It is not. We open sockets on line 290, drop privileges on line 295 and start parsing options and arguments on line 310. In my version, I see the first executable lines in main to be: if ( ( net_preopen_result = net_preopen () ) ) { fprintf( stderr, mtr: unable to get raw sockets.\n ); and in your patch I see: @@ -322,8 +333,21 @@ struct sockaddr_in6 * sa6; #endif - /* Get the raw sockets first thing, so we can drop to user euid immediately */ + /* reset the random seed */ + srand (getpid()); + + display_detect(argc, argv); + + /* The field options are now in a static array all together, + but that requires a run-time initialization. -- REW */ + init_fld_options (); + + parse_mtr_options (getenv (MTR_OPTIONS)); + + parse_arg (argc, argv); + /* get raw sockets ASAP, so we can drop to user euid immediately * + * we need to do this after parsing options, to know the proto */ if ( ( net_preopen_result = net_preopen () ) ) { fprintf( stderr, mtr: unable to get raw sockets.\n ); exit( EXIT_FAILURE ); which I read as: the parse_arg, display_detect and parse_mtr_options have been moved to BEFORE opening the sockets and dropping privs. Roger. -- ** [EMAIL PROTECTED] ** http://www.BitWizard.nl/ ** +31-15-2600998 ** **Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233** *-- BitWizard writes Linux device drivers for any device you may have! --* Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement. Does it sit on the couch all day? Is it unemployed? Please be specific! Define 'it' and what it isn't doing. - Adapted from lxrbot FAQ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#472509: mtr: UDP patch
Hi guys, Looks nice. One problem I have with this is that the amount of code that is exposed to security problems has gone up a factor of ten... How much work would it be to open both the new UDP port and the old ICMP port, and discard the one we don't need? How can the program switch (with the GUI u command) if it hasn't preopened the sockets anyway? Roger. On Mon, Apr 14, 2008 at 11:35:03AM -0400, Mark Kamichoff wrote: I wrote a patch for Mtr 0.72 to implement UDP support. You can find it attached. UDP mode is enabled using the -u commandline switch, or by typing u in the GUI. The patch has been tested on Debian testing/unstable, both on IPv4 and IPv6. I have written a patch (see attached) as well that adds similar UDP functionality. There are some differences in the choice of destination ports used, with the original goal of emulating classic traceroute(8) behavior. The port range of 100 can cause erroneous loss on some paths since it is used to store sequence numbers, but 'most' of the time it is not noticable. That being said, Martin's patch seems to be the best choice for inclusion, as it does not suffer from this problem, and is overall of cleaner design. It would be great to see it included in MTR, as I believe it would add considerable flexibility to the utility. - Mark -- Mark Kamichoff [EMAIL PROTECTED] http://prolixium.com/ Rensselaer Polytechnic Institute, Class of 2004 Only in mtr-0.72-new: .deps diff -ur mtr-0.72/ChangeLog mtr-0.72-new/ChangeLog --- mtr-0.72/ChangeLog2004-08-26 03:56:53.0 -0400 +++ mtr-0.72-new/ChangeLog2008-04-14 10:33:16.0 -0400 @@ -1,3 +1,24 @@ +2008-04-13 Mark Kamichoff [EMAIL PROTECTED] + + * Changed the UDP sequence number storage to be source port - + UDP_PORT_MIN. This allows us 100 packets to be in-flight at any + time, without losing track. Right now we're using the classic + traceroute ports, but might need to increase this in the future. + * Added UDP checksum calculation for both IPv4 and IPv6. Source + address _must_ be specified at this point, due to a problem with + getsockname(2) not filling in the address structure completely. + * Added a line in the curses output to display protocol type. + * Fixed IPv6 support (see first entry). + +2008-04-11 Mark Kamichoff [EMAIL PROTECTED] + + * Fixed bug displaying localaddr (always displayed ANY) + +2007-03-27 Mark Kamichoff [EMAIL PROTECTED] + + * Preliminary UDP (-P udp) support. IPv6 doesn't work with it, + yet, since we're using the IP ID field for sequence numbers. + 2002-03-06 Cougar [EMAIL PROTECTED] + If hop doesn't respond, draw its name in red (GTK) or bold (curses) Only in mtr-0.72-new: Makefile Only in mtr-0.72-new: config.h Only in mtr-0.72-new: config.log Only in mtr-0.72-new: config.status diff -ur mtr-0.72/curses.c mtr-0.72-new/curses.c --- mtr-0.72/curses.c 2006-09-29 15:40:09.0 -0400 +++ mtr-0.72-new/curses.c 2008-04-14 10:33:16.0 -0400 @@ -75,6 +75,7 @@ extern int tos; extern float WaitTime; extern int af; +extern int protocol; void pwcenter(char *str) { @@ -506,6 +507,22 @@ time(t); mvprintw(1, maxx-25, ctime(t)); + /* display protocol -- MK */ + if(protocol == 17) { +mvprintw(2, 0, Protocol: UDP\n); + } else { +#ifdef ENABLE_IPV6 +switch ( af ) { +case AF_INET6: + mvprintw(2, 0, Protocol: ICMPv6\n); + break; +#endif +case AF_INET: + mvprintw(2, 0, Protocol: ICMP\n); + break; +} + } + printw(Keys: ); attron(A_BOLD); printw(H); attroff(A_BOLD); printw(elp ); attron(A_BOLD); printw(D); attroff(A_BOLD); printw(isplay mode ); Only in mtr-0.72-new: curses.o Only in mtr-0.72-new: display.o Only in mtr-0.72-new: dns.o Only in mtr-0.72-new: getopt.o Only in mtr-0.72-new: getopt1.o Only in mtr-0.72-new/img: Makefile Only in mtr-0.72-new: mtr diff -ur mtr-0.72/mtr.c mtr-0.72-new/mtr.c --- mtr-0.72/mtr.c2006-09-29 15:38:49.0 -0400 +++ mtr-0.72-new/mtr.c2008-04-14 10:33:16.0 -0400 @@ -65,6 +65,7 @@ int bitpattern = 0; int tos = 0; int af = DEFAULT_AF; +int protocol = 1; /* protocol number: icmp or udp */ /* begin ttl windows addByMin */ int fstTTL = 1;/* default start at first hop */ @@ -145,6 +146,7 @@ { max-ttl, 1, 0, 'm' }, { inet, 0, 0, '4' }, /* IPv4 only */ { inet6, 0, 0, '6' }, /* IPv6 only */ +{ protocol, 1, 0, 'P' }, { 0, 0, 0, 0 } }; @@ -152,7 +154,7 @@ while(1) { /* added f:m:o: byMin */ opt = getopt_long(argc, argv, - vhrxtglpo:i:c:s:b:Q:na:f:m:46, long_options, NULL); + vhrxtglpo:i:c:s:b:Q:na:f:m:46P:, long_options, NULL); if(opt == -1) break; @@ -264,6
Bug#472509: mtr: UDP patch
I wrote a patch for Mtr 0.72 to implement UDP support. You can find it attached. UDP mode is enabled using the -u commandline switch, or by typing u in the GUI. The patch has been tested on Debian testing/unstable, both on IPv4 and IPv6. I have written a patch (see attached) as well that adds similar UDP functionality. There are some differences in the choice of destination ports used, with the original goal of emulating classic traceroute(8) behavior. The port range of 100 can cause erroneous loss on some paths since it is used to store sequence numbers, but 'most' of the time it is not noticable. That being said, Martin's patch seems to be the best choice for inclusion, as it does not suffer from this problem, and is overall of cleaner design. It would be great to see it included in MTR, as I believe it would add considerable flexibility to the utility. - Mark -- Mark Kamichoff [EMAIL PROTECTED] http://prolixium.com/ Rensselaer Polytechnic Institute, Class of 2004 Only in mtr-0.72-new: .deps diff -ur mtr-0.72/ChangeLog mtr-0.72-new/ChangeLog --- mtr-0.72/ChangeLog 2004-08-26 03:56:53.0 -0400 +++ mtr-0.72-new/ChangeLog 2008-04-14 10:33:16.0 -0400 @@ -1,3 +1,24 @@ +2008-04-13 Mark Kamichoff [EMAIL PROTECTED] + + * Changed the UDP sequence number storage to be source port - + UDP_PORT_MIN. This allows us 100 packets to be in-flight at any + time, without losing track. Right now we're using the classic + traceroute ports, but might need to increase this in the future. + * Added UDP checksum calculation for both IPv4 and IPv6. Source + address _must_ be specified at this point, due to a problem with + getsockname(2) not filling in the address structure completely. + * Added a line in the curses output to display protocol type. + * Fixed IPv6 support (see first entry). + +2008-04-11 Mark Kamichoff [EMAIL PROTECTED] + + * Fixed bug displaying localaddr (always displayed ANY) + +2007-03-27 Mark Kamichoff [EMAIL PROTECTED] + + * Preliminary UDP (-P udp) support. IPv6 doesn't work with it, + yet, since we're using the IP ID field for sequence numbers. + 2002-03-06 Cougar [EMAIL PROTECTED] + If hop doesn't respond, draw its name in red (GTK) or bold (curses) Only in mtr-0.72-new: Makefile Only in mtr-0.72-new: config.h Only in mtr-0.72-new: config.log Only in mtr-0.72-new: config.status diff -ur mtr-0.72/curses.c mtr-0.72-new/curses.c --- mtr-0.72/curses.c 2006-09-29 15:40:09.0 -0400 +++ mtr-0.72-new/curses.c 2008-04-14 10:33:16.0 -0400 @@ -75,6 +75,7 @@ extern int tos; extern float WaitTime; extern int af; +extern int protocol; void pwcenter(char *str) { @@ -506,6 +507,22 @@ time(t); mvprintw(1, maxx-25, ctime(t)); + /* display protocol -- MK */ + if(protocol == 17) { +mvprintw(2, 0, Protocol: UDP\n); + } else { +#ifdef ENABLE_IPV6 +switch ( af ) { +case AF_INET6: + mvprintw(2, 0, Protocol: ICMPv6\n); + break; +#endif +case AF_INET: + mvprintw(2, 0, Protocol: ICMP\n); + break; +} + } + printw(Keys: ); attron(A_BOLD); printw(H); attroff(A_BOLD); printw(elp ); attron(A_BOLD); printw(D); attroff(A_BOLD); printw(isplay mode ); Only in mtr-0.72-new: curses.o Only in mtr-0.72-new: display.o Only in mtr-0.72-new: dns.o Only in mtr-0.72-new: getopt.o Only in mtr-0.72-new: getopt1.o Only in mtr-0.72-new/img: Makefile Only in mtr-0.72-new: mtr diff -ur mtr-0.72/mtr.c mtr-0.72-new/mtr.c --- mtr-0.72/mtr.c 2006-09-29 15:38:49.0 -0400 +++ mtr-0.72-new/mtr.c 2008-04-14 10:33:16.0 -0400 @@ -65,6 +65,7 @@ int bitpattern = 0; int tos = 0; int af = DEFAULT_AF; +int protocol = 1; /* protocol number: icmp or udp */ /* begin ttl windows addByMin */ int fstTTL = 1;/* default start at first hop */ @@ -145,6 +146,7 @@ { max-ttl, 1, 0, 'm' }, { inet, 0, 0, '4' }, /* IPv4 only */ { inet6, 0, 0, '6' }, /* IPv6 only */ +{ protocol, 1, 0, 'P' }, { 0, 0, 0, 0 } }; @@ -152,7 +154,7 @@ while(1) { /* added f:m:o: byMin */ opt = getopt_long(argc, argv, - vhrxtglpo:i:c:s:b:Q:na:f:m:46, long_options, NULL); + vhrxtglpo:i:c:s:b:Q:na:f:m:46P:, long_options, NULL); if(opt == -1) break; @@ -264,6 +266,15 @@ fprintf( stderr, IPv6 not enabled.\n ); break; #endif +case 'P': + if (!strcasecmp(icmp, optarg)) { + protocol = 1; + } else if (!strcasecmp(udp, optarg)) { + protocol = 17; + } else { +fprintf (stderr, mtr: unsupported protocol\n); +exit (1); + } } } @@ -322,8 +333,21 @@ struct sockaddr_in6 * sa6; #endif - /* Get the raw sockets first thing, so we can drop to user euid immediately */ + /* reset the random seed */ + srand (getpid()); + + display_detect(argc, argv); + + /* The field options are now in a static array all together, + but that requires a run-time initialization. -- REW
Bug#472509: mtr: UDP patch
Subject: mtr: UDP patch Package: mtr Version: 0.72 Severity: wishlist Tags: patch Hi, I wrote a patch for Mtr 0.72 to implement UDP support. You can find it attached. UDP mode is enabled using the -u commandline switch, or by typing u in the GUI. The patch has been tested on Debian testing/unstable, both on IPv4 and IPv6. -- System Information: Debian Release: lenny/sid APT prefers unstable APT policy: (600, 'unstable'), (500, 'oldstable'), (500, 'stable') Architecture: i386 (i686) Kernel: Linux 2.6.18-4-486 Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) Shell: /bin/sh linked to /bin/bash Versions of packages mtr depends on: ii libc6 2.7-9 GNU C Library: Shared libraries ii libglib1.21.2.10-17 The GLib library of C routines ii libgtk1.2 1.2.10-18 The GIMP Toolkit set of widgets fo ii libncurses5 5.6+20080308-1 Shared libraries for terminal hand pn xlibs none (no description available) mtr recommends no packages. diff -Naur mtr-0.72.orig/curses.c mtr-0.72/curses.c --- mtr-0.72.orig/curses.c 2006-09-29 21:40:09.0 +0200 +++ mtr-0.72/curses.c 2008-03-24 17:00:52.0 +0100 @@ -75,6 +75,7 @@ extern int tos; extern float WaitTime; extern int af; +extern int mtrtype; void pwcenter(char *str) { @@ -242,6 +243,17 @@ } return ActionNone; } + if (tolower(c) == 'u') { +switch ( mtrtype ) { +case IPPROTO_ICMP: + mtrtype = IPPROTO_UDP; + break; +case IPPROTO_UDP: + mtrtype = IPPROTO_ICMP; + break; +} +return ActionNone; + } /* reserve to display help message -Min */ if (tolower(c) == '?'|| tolower(c) == 'h') { mvprintw(2, 0, Command:\n ); @@ -256,7 +268,8 @@ printw( m n set the max time-to-live, default n= # of hops\n ); printw( s n set the packet size to n or random(n0)\n ); printw( b c set ping bit pattern to c(0..255) or random(c0)\n ); -printw( Q t set ping packet's TOS to t\n\n\n ); +printw( Q t set ping packet's TOS to t\n ); +printw( u switch between ICMP ECHO and UDP datagrams\n\n ); mvprintw(16, 0, press any key to go back... ); getch(); /* get any key */ diff -Naur mtr-0.72.orig/mtr.8 mtr-0.72/mtr.8 --- mtr-0.72.orig/mtr.8 2006-09-29 21:33:06.0 +0200 +++ mtr-0.72/mtr.8 2008-03-24 17:00:52.0 +0100 @@ -8,7 +8,7 @@ .SH SYNOPSIS .B mtr [\c -.B \-hvrctglspni46\c +.B \-hvrctglspniu46\c ] [\c .B \-\-help\c @@ -208,6 +208,11 @@ ECHO requests. The default value for this parameter is one second. .TP +.B \-u +.br +Use UDP datagrams instead of ICMP ECHO. + +.TP .B \-4 .br Use IPv4 only. diff -Naur mtr-0.72.orig/mtr.c mtr-0.72/mtr.c --- mtr-0.72.orig/mtr.c 2006-09-29 21:38:49.0 +0200 +++ mtr-0.72/mtr.c 2008-03-24 17:00:52.0 +0100 @@ -65,6 +65,7 @@ int bitpattern = 0; int tos = 0; int af = DEFAULT_AF; +int mtrtype = IPPROTO_ICMP; /* Use ICMP as default packet type */ /* begin ttl windows addByMin */ int fstTTL = 1;/* default start at first hop */ @@ -143,6 +144,7 @@ { address, 1, 0, 'a' }, { first-ttl, 1, 0, 'f' }, /* -f -m are borrowed from traceroute */ { max-ttl, 1, 0, 'm' }, +{ udp, 0, 0, 'u' }, /* UDP (default is ICMP) */ { inet, 0, 0, '4' }, /* IPv4 only */ { inet6, 0, 0, '6' }, /* IPv6 only */ { 0, 0, 0, 0 } @@ -152,7 +154,7 @@ while(1) { /* added f:m:o: byMin */ opt = getopt_long(argc, argv, - vhrxtglpo:i:c:s:b:Q:na:f:m:46, long_options, NULL); + vhrxtglpo:i:c:s:b:Q:na:f:m:u46, long_options, NULL); if(opt == -1) break; @@ -253,6 +255,9 @@ tos = 0; } break; +case 'u': + mtrtype = IPPROTO_UDP; + break; case '4': af = AF_INET; break; @@ -354,13 +359,19 @@ parse_arg (argc, argv); + /* Now that we know mtrtype we can select which socket to use */ + if (net_selectsocket() != 0) { +fprintf( stderr, mtr: Couldn't determine raw socket type.\n ); +exit( EXIT_FAILURE ); + } + if (PrintVersion) { printf (mtr VERSION \n); exit(0); } if (PrintHelp) { -printf(usage: %s [-hvrctglspni46] [--help] [--version] [--report]\n +printf(usage: %s [-hvrctglspniu46] [--help] [--version] [--report]\n \t\t[--report-cycles=COUNT] [--curses] [--gtk]\n \t\t[--raw] [--split] [--no-dns] [--address interface]\n /* BL */ \t\t[--psize=bytes/-s bytes]\n/* ok */ diff -Naur mtr-0.72.orig/net.c mtr-0.72/net.c --- mtr-0.72.orig/net.c 2006-09-29 21:31:01.0 +0200 +++ mtr-0.72/net.c 2008-03-24 17:05:10.0 +0100 @@ -54,6 +54,22 @@ uint16 sequence; }; +/* Structure of an UDP header. */ +struct UDPHeader { + uint16 srcport; + uint16 dstport; + uint16 length; + uint16 checksum; +}; + +/* Structure of an IPv4 UDP pseudoheader. */ +struct