Commit Graph

750 Commits

Author SHA1 Message Date
Matt Kimball
5c8cc179bc cleanup: reindented C source with GNU indent
Ran the C source through:

    indent --k-and-r-style --no-tabs --break-function-decl-args
2017-02-04 13:25:23 -08:00
Matt Kimball
b8718f19f3 cleanup: Fix #ifdef structure which confuses 'ident'
The 'indent' tool is confused by some strange #ifdef structure
around HAVE_IPINFO in report.c.  Cleaned up that structure
so 'indent' can be used successfully.
2017-02-04 13:18:13 -08:00
R.E. Wolff
a59381d92a More whitespace mangling for consistency in net.c 2017-01-27 09:40:49 +01:00
Roger Wolff
93b787c42b Merge pull request #188 from jbruggeman/master
Improve readability of net.c
2017-01-27 09:36:34 +01:00
Joe Bruggeman
8bab806067 cleanup the if blocks in net.c to improve readability 2017-01-26 16:40:53 -05:00
Joe Bruggeman
f84a496ddd Replace all tabs tabs in net.c with spaces
Partial fix for #187
2017-01-26 16:32:44 -05:00
R.E. Wolff
7476ad564e put ifdefs around IPV6 only part. Fixes #184 2017-01-18 00:04:26 +01:00
R.E. Wolff
c4c4ef8e55 asn fix from meingtsla, fixes #163. Pong! 2017-01-15 00:51:47 +01:00
Roger Wolff
75d8eb352a Merge pull request #181 from matt-kimball/cygwin-host-unreach
mtr-packet: Report probe status on host unreachable (Cygwin)
2017-01-08 17:17:30 +01:00
Matt Kimball
ed301d9e9c mtr-packet: Report probe status on host unreachable (Cygwin)
When IcmpParseReplies returned with a probe completion, but the
probe's status was IP_DEST_HOST_UNREACHABLE, mtr-packet was failing
to report the probe result, and was instead printing an unhelpful
error message without any reference to a particular probe.  Now
it will report a "no-route" result with the token associated with
the probe.

This fixes issue #179.
2017-01-08 07:36:27 -08:00
Roger Wolff
7f0446c093 Merge pull request #180 from kerolasa/pedantry
couple maintenance changes
2017-01-07 13:01:13 +01:00
Sami Kerola
dd42b2305a
docs: FSF moved back in 2005
Update license file from the source.

Reference: https://www.fsf.org/news/fsf-moving.html
Source: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-06 22:05:10 +00:00
Sami Kerola
e80318df8b
build-sys: update .gitignore file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-06 22:05:10 +00:00
Sami Kerola
a67db88c08
smatch: fix couple warnings
ui/mtr.c:616:21: warning: Using plain integer as NULL pointer
packet/cmdparse.c:80:18: warning: Variable length array is used.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-06 22:05:10 +00:00
Sami Kerola
9c7ad75699
smatch: extern keyword is needed only in header
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-06 22:05:10 +00:00
Roger Wolff
e66683e216 Merge pull request #178 from kasper93/errno
Add missing errno.h include.
2017-01-05 16:09:01 +01:00
Roger Wolff
ea3c8d1364 Merge pull request #177 from kasper93/master
Change finding of mtr-packet a bit to make things more convenient for developers/hackers.
2017-01-05 16:07:57 +01:00
Kacper Michajłow
82999fe464 Add missing errno.h include.
This fixes compilation with Clang on Cygwin.
2017-01-04 17:53:22 +01:00
Kacper Michajłow
7600812a6d Relax mtr-packet search rules.
First, mtr-packet or override path taken from MTR_PACKET env variable will be search in PATH if not found we falllback to current directory search. This way we can use mtr without installing or setting any additional env variables.

Also fix batch file to support paths with spaces on Windows.
2017-01-04 17:35:19 +01:00
Roger Wolff
0e5edbdccb Merge pull request #175 from matt-kimball/portability-fixes
Portability fixes - Solaris, NetBSD and OpenBSD
2016-12-31 19:04:59 +01:00
Matt Kimball
54294e8c28 build: fix compiler warnings when for OpenBSD, NetBSD and Solaris
When building for NetBSD, the compiler was warning about
index into an array with a character when using isspace() and
similar macros.

IPPROTO_SCTP is also not defined by NetBSD, so there were
warnings about unused SCTP related variables.

OpenBSD complains about using sprintf rather than snprintf.
It's a good idea to use snprintf, anyway, to avoid buffer overruns,
though I believe in these particular cases sprintf was safe.
Nevertheless, snprintf is now used instead.

Solaris requires strings.h to find index().

Solaris complaints about a missing sentinel pointer unless
the terminating NULL in execl is cast to a "char *".
2016-12-30 13:10:28 -08:00
Matt Kimball
f19df41bba build: Fix Solaris build issues
Prefer ncurses over curses, since curses on Solaris is lacking
wattr_on and wattr_off, but ncurses has them.

Check if sys/ctypes.h exists, since Solaris lacks it.

When sending an IPv6 probe, check if the send socket is already
bound to the intended source address, and if so, avoid rebinding.
Rebinding return an error on Solaris.
2016-12-30 13:10:23 -08:00
Matt Kimball
42651675e6 build: if linking with ncurses fails, try curses (for NetBSD)
NetBSD doesn't use ncurses, but instead has its own version of curses.
So, if we don't find ncurses during configure, try linking against
curses.

On NetBSD, we must include limits.h to find CHAR_MAX.

On OpenBSD, we must include sys/socket.h to get sockaddr_storage.
2016-12-30 13:09:11 -08:00
Roger Wolff
c5fa044209 Merge pull request #174 from matt-kimball/ipv6-disabled-fallback
mtr-packet: Fall back to IPv4 only support if IPv6 sockets fail to open
2016-12-29 08:05:13 +01:00
Matt Kimball
8f5502cd54 mtr-packet: Fall back to IPv4 only support if IPv6 sockets fail to open
If we fail to open any IPv6 sockets, rather than aborting with an
unrecoverable error, fall back to IPv4 only support.  Socket
creation might fail, for example, when Linux is booted with
the kernel command-line "ipv6.disable=1".

In the case where opening IPv6 sockets fail,
'check-support feature ip-6' will indicate there is no support
for sending IPv6 probes.

Stricter error reporting revealed that test for protocols other
than ICMP were running on Cygwin.  Modified the tests such that
they won't run if the protocol isn't supported.
2016-12-27 17:36:48 -08:00
Roger Wolff
883d40b1eb Merge pull request #172 from matt-kimball/ncurses-check
build: use AC_CHECK_LIB for ncurses, rather than pkg-tool
2016-12-26 22:34:46 +01:00
Matt Kimball
f8e6dfa4fb build: use AC_CHECK_LIB for ncurses, rather than pkg-tool
pkg-tool is indeed an elegant way to check for the presence
of libraries.  When using pkg-config to check for ncurses, this
works great... for Linux.  Unfortunately, on FreeBSD and MacOS,
ncurses is installed by default, but pkg-config is not.  When
pkg-config is installed on these systems, it doesn't know about
the system installed ncurses.

Therefore, somewhat counterintuitively, it is better for portability
to just us AC_CHECK_LIB instead of PKG_CHECK_MODULES to find
ncurses.
2016-12-26 01:32:38 -08:00
Roger Wolff
a82413a7a8 Merge pull request #171 from matt-kimball/master
split raw socket access into mtr-packet subprocess
2016-12-25 23:14:11 +01:00
Matt Kimball
b9437b9161 build: moved front-end source into ui subdir
Cleaned up the directory structure.

Moved the source to the main mtr executable into the ui/ subdirectory.

Moved mtr.bat and mangen.sh into build-aux/

Moved the man pages into man/

Fixed a few omissions in Makefile.am for 'make dist'
2016-12-25 09:53:19 -08:00
Matt Kimball
2ff8de3102 mtr-packet: drop capabilities + using BSD's linked lists for probes
At startup, we now use cap_set_proc to drop all privileged
capabilities for the mtr-packet process.  This means that
capabilities granted through the commandline setcap to the
mtr-packet executable will only be in effect while the necessary
raw sockets are opened, and will be dropped before any command
requests are read.

Now we use BSD's queue.h linked list support for storing outstanding
probes.  This makes iterating through in-flight probes more efficient,
as we don't need to loop through many unused probe entires when only
a few probes are outstanding.

Changed mtr-packet's default probe size to 64 bytes, to match
mainline mtr's default.

The code consistently uses 'exit(EXIT_FAILURE)' instead of 'exit(1)'.
The effect is the same, but the intent is clearer.
2016-12-25 09:26:34 -08:00
Matt Kimball
5f76affc0e Merge branch mtr-packet into 'master' 2016-12-23 09:56:58 -08:00
Matt Kimball
4149c2cfbe mtr-packet: allow local address binding
A probe can be bound to a local address with the 'local-ip-4' or
'local-ip-6' arguments to 'send-probe'.  The '-a' commandline
argument to mtr will cause sent probes to be bound to the specified
address.

Changed argument names for consistency:

    'localport' is now 'local-port'
    'bitpattern' is now 'bit-pattern'

mtr now opens and connects a UDP socket at startup to determine the
local address for display in the UI.

Windows error codes resulting from send-probe are now using the
same error strings which are used to report errors in the
Unix implementation.

We now use the mtr commandline timeout value for sent probes.
Edited the help and man page to reflect that the timeout value
no longer applies to only TCP probes, but now all probes.

With this change, I believe the mtr-packet implementation is at
feature parity with mainline mtr.
2016-12-23 09:37:47 -08:00
Matt Kimball
7abc1cbd78 mtr-packet: MPLS decoding and local UDP port usage
mtr-packet will decode any MPLS labels embedded in an
ICMP reply which results from a probe, and report those
labels with the probe reply.

When sending a UDP probe, a local port can be specified
for probe origination.  In the same way that the legacy mtr
code found a location to store a unique identifier for the probe,
we'll use the destination port, the local port or the checksum
field, depending on what probe arguments have been specified.

Both MPLS and local UDP port options have been documented in the
mtr-packet man page.

Update the SECURITY documentation to reflect mtr-packet, and did
minor copyediting in the README.  Also, update my email address
in AUTHORS.
2016-12-22 07:28:29 -08:00
Matt Kimball
fcda9e8b82 mtr-packet: TCP and SCTP probes
Added support for generating probes using TCP or SCTP, for both
IPv4 and IPv6.  These protocols require that we create a unique
socket for each probe and watch for either a TTL expiration of
the initial packet sent during a connection attempt from that
socket or for socket connection success.

We now allocate a unique port number or ICMP sequence ID when
a probe is created, rather than using the command token for this
purpose.  This relieves the calling application of the burden
of picking sensible command token values, and allows command
tokens values greater than 16 bits.  However, the existing mtr
code continues to use the same command tokens values it has
previously used as port numbers, so there is no difference when
the calling program is mtr.

Split mtr's command pipe handling out from net.c and into cmdpipe.c
in the interest of future maintainability.

Split probe.py's simple probes out from the individual protocol
test cases and into common code which can be used by many
protocol tests.
2016-12-20 10:09:29 -08:00
Roger Wolff
137c97552a Merge pull request #165 from kerolasa/2016-10-29
2016-10-29 usage improvements
2016-12-19 10:15:12 +01:00
Matt Kimball
560e6802c1 mtr-packet: packet customization options (size, fill, mark, tos)
Added send-probe arguments to customize the packet size,
the bitpattern which fills the packet, the IP "type of service"
and the Linux routing mark.  These arguments are documented
in the mtr-packet man page, and have been hooked up to mtr's
commandline parameters.

Internally to mtr-packet, the code is now more consistent about
using errno to return error codes.

Added instrutions for building on Windows to the README.

Fixed the Makefile to build the man pages with BSD make, for FreeBSD.
BSD make lacks the GNU make extension for '%' wildcard matching.

Added a helper program for testing which listens for an ICMP
packet with a particular sequence and prints information about
that packet.
2016-12-17 07:24:07 -08:00
Matt Kimball
88d1a95087 mtr-packet: UDP probe support
Added support send using UDP as the protocol for sending probes,
rather than ICMP.  Both IPv4 and IPv6 UDP probes are supported.
We are using the source port in the UDP packet for identifying
the particular probe transmitted.  This is a bit less reliable
than ICMP, where we are also able to store our PID for verifying
the probe has been transmitted by this instance of mtr-packet,
but space is limited, and it is what the pre-existing mtr
implementation does.

We report no-route and network-down errors in response to errors
from sendto(), in addition to reporting them from errors in
the connect() used to determine the source address of an outgoing
probe.

The mtr-packet tests now properly parse the replies from
mtr-packet, as opposed to simply matching regular expressions
against the output.  This is better because it give us future
compatibility with additional reply arguments from mtr-packet.

A better introduction to mtr-packet is now included in the
mtr-packet man page.

The dual code paths for sending IPv6 probes between Linux
and non-Linux Unix-likes has been eliminated.  The Linux path
gave us direct control over the IP header, but wasn't necessary
and would make maintainence more difficult, so now Linux uses
the more indirect setsockopt() method of setting IPv6 header
fields.
2016-12-14 09:33:38 -08:00
Matt Kimball
6df4e45df4 mtr-packet: IPv6 support
mtr-packet can now send and receive ICMPv6 probes.

We now determine the source address for an outgoing probe by
opening a UDP socket to the destination, though no outgoing packets
are sent through this UDP socket.  IPv6 made this necessary, but
it now occurs for IPv4, too.

mtr-packet now uses sockaddr_storage for passing around addresses,
rather than sockaddr_in, as it can work for either IPv4 or IPv6.

To improve the maintainability of the code, the packet construction
and interpetation has been moved from probe_unix.c to construct_unix.c
and deconstruct_unix.c.

The way that Windows reads from the command stream has been changed to
avoid the possibility of hanging in a Sleep without an active read
of the command stream.

"send-probe" will now respond with "no-route" or "network-down"
when those conditions apply.

The test code has been moved to a test directory and split into
the following modules:

probe.py - tests for sending probes
cmdparse.py - tests for command parsing
mtrpacket.py - infrastructure for testing mtr-packet

The mtr-packet man page has been updated to describe ip-6 options
and now has an example of tracing a route to a remote host.

The mtr-packet network initialization has been split into two halves
to minimize the operations which occur with elevated privileges.
2016-12-09 11:14:06 -08:00
Roger Wolff
cc7937693e Merge pull request #169 from matt-kimball/issue168-multihost
cmdline: multiple host names dropped all but one host  (issue #168)
2016-12-07 18:05:10 +01:00
Matt Kimball
c419873ace cmdline: multiple host names dropped all but one host (issue #168)
Change 1ed2bab broke multiple host names, either specified through
the --filename option, or listed on the commandline.  This was
due to well-intentioned refactoring of the hostname linked list
management which happened to lose all host names other than the
last name in the list.

I've fixed the append_to_names to walk the list of host names before
appending a new host name.  This does make the building of host names
O(n^2) rather than O(n), but I'm skeptical that will impact anyone's
life in a negative way, because it only happens at startup, and
it does simplify the code.

Also, multiple host names will now work in all non-interactive modes
(i.e. report, txt, json, xml, raw, csv) instead of just CSV mode.
2016-12-07 07:53:47 -08:00
Matt Kimball
ac58c7a4b7 test: Fix mtr-packet tests for Python 3
The mtr-packet test suite was written to run with Python 2, and lacked
the Unicode to bytes and bytes to Unicode conversions required to
run with Python 3.  This change adds those conversions, and the result
works with either Python 2 or Python 3.

Also, close the subprocess's stdin and stdout explicitly.  Python 3's
unittest complains about unclosed file descriptors otherwise.
2016-12-04 10:03:44 -08:00
Sami Kerola
032d82f326
build-sys: update .gitignore file 2016-12-04 11:08:16 +00:00
Sami Kerola
22b7454a2f
docs: improve mtr-packet(8) manual page
Indent argument descriptions, and groff_man(7) style.
2016-12-04 11:07:17 +00:00
Matt Kimball
5d26cb0c05 Added mtr-packet subprocess
The mtr-packet tool isolates the raw socket sending/receiving of
packets from the mtr user interface.  By isolating the socket
interactions to a separate process, we can be sure that any security
flaws in the user-interface code doesn't expose a raw socket
interface to an attacker attempting to escalate privileges.

This is a bare-bones implementation, only support ICMP,
only support IP version 4, and missing many of the probe customization
features available in mtr.  It will require some more work to reach
feature parity with the current mtr implementation.  But it's a start.

The include mtr-packet man page explains the protocol format
used to communicate with this new process.

Included is an automated test for mtr-packet, implemented using
Python's unittest module.  Though the code actually being tested
is implemented in C, Python make it easy to write test cases.
'make check' will test the current build.

An alternate code-path for Windows is included in the mtr-packet
tool.  The mechanism for sending and receiving network probes
is significantly different for Windows, as compared to Unix-like
operating systems, but the interface provided by mtr-packet is
the same.  'make dist-windows-bin' will make a Windows binary
distribution.  A Cygwin build environment is required, but the
resulting binary distribution doesn't require that Cygwin be
already installed.

Tested on:

Ubuntu 16.10, FreeBSD 11.0, MacOS 10.12.1 (Sierra), Windows 7

Since the code changes are significant, more esoteric operating
systems may require changes.
2016-11-30 17:14:43 -08:00
meingtsla
993cbb8c5e asn_{open,close}: Always initialize ipinfo hash table
Currently the only pathway to asn_open() is through display_open(), so hcreate() for ipinfo was only happening if -y or -z was specified at startup.

The ability to toggle ipinfo display in interactive mode was introduced in commit d4bb85a80ee3eb76d803e3cd04de2ccdf0379415; however, no pathway to asn_open on a toggle event was provided.  This means ipinfo results were not being stored, resulting in repeated ipinfo DNS queries being made for the same IP addresses.

To fix this, always set up the hash table if there is a possibility of toggling ipinfo display.
2016-10-29 21:16:04 -07:00
Sami Kerola
59b1737c01
docs: add very basic --sctp documentation to manual page
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-10-29 14:43:43 +01:00
Sami Kerola
8fe6244480
cleanup: use single logic to handle conditional options
Options that exist depending on compile time configuration are made
conditional in usage() and getopt_long().  Removing not-supported options
from manual per compile time configuration would be nice, but making that to
work is a bit tricky.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-10-29 14:19:16 +01:00
R.E. Wolff
7e13a55af9 Merge branch 'master' of github.com:traviscross/mtr 2016-10-29 11:50:34 +02:00
R.E. Wolff
e5c045115b header alignment issue found&fixed by meingtsla. Fixes #164 2016-10-29 11:50:13 +02:00
rewolff
6b2d89f530 Merge pull request #162 from vaygr/row-color-fix
Respect theme foreground color
2016-10-28 00:05:41 +02:00