Skip to content

Commit 5d26cb0

Browse files
committed
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.
1 parent 7e13a55 commit 5d26cb0

37 files changed

+3477
-1156
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ stamp-h1*
1919

2020
/autom4te.cache/
2121
/.deps/
22+
/packet/.deps/
2223
/ChangeLog
2324
/INSTALL
2425
/mtr
26+
/mtr-packet
2527
/mtr.8
2628

2729
/mtr-*.tar.gz

Makefile.am

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
EXTRA_DIST = SECURITY img/mtr_icon.xpm
1+
EXTRA_DIST = \
2+
SECURITY \
3+
mtr.bat \
4+
img/mtr_icon.xpm \
5+
packet/testpacket.py \
6+
packet/lint.sh
27

3-
sbin_PROGRAMS = mtr
8+
sbin_PROGRAMS = mtr mtr-packet
9+
TESTS = packet/testpacket.py
410

511
PATHFILES =
612
CLEANFILES = $(PATHFILES)
713
EXTRA_DIST += $(PATHFILES:=.in)
814
edit_cmd = sed \
915
-e 's|@VERSION[@]|$(VERSION)|g'
1016

11-
$(PATHFILES): Makefile
17+
%.8: $(srcdir)/%.8.in
1218
@ rm -f $@ $@.tmp
1319
$(AM_V_at) $(MKDIR_P) $$(dirname $@)
1420
$(AM_V_GEN) srcdir=''; \
1521
test -f ./$@.in || srcdir=$(srcdir)/; \
1622
$(edit_cmd) $${srcdir}$@.in >$@.tmp
1723
@ mv $@.tmp $@
1824

19-
dist_man_MANS = mtr.8
20-
PATHFILES += mtr.8
25+
$(PATHFILES): Makefile
26+
27+
dist_man_MANS = mtr.8 mtr-packet.8
28+
PATHFILES += mtr.8 mtr-packet.8
2129

2230
install-exec-hook:
23-
`setcap cap_net_raw+ep $(DESTDIR)$(sbindir)/mtr` \
24-
|| chmod u+s $(DESTDIR)$(sbindir)/mtr
31+
`setcap cap_net_raw+ep $(DESTDIR)$(sbindir)/mtr-packet` \
32+
|| chmod u+s $(DESTDIR)$(sbindir)/mtr-packet
2533

2634
mtr_SOURCES = mtr.c mtr.h \
2735
net.c net.h \
@@ -32,6 +40,7 @@ mtr_SOURCES = mtr.c mtr.h \
3240
report.c report.h \
3341
select.c select.h \
3442
utils.c utils.h \
43+
packet/cmdparse.c packet/cmdparse.h \
3544
mtr-curses.h \
3645
img/mtr_icon.xpm \
3746
mtr-gtk.h
@@ -65,6 +74,60 @@ mtr_INCLUDES = $(GLIB_CFLAGS) -I$(top_builddir) -I$(top_srcdir)
6574
mtr_CFLAGS = $(GTK_CFLAGS) $(NCURSES_CFLAGS)
6675
mtr_LDADD = $(GTK_LIBS) $(NCURSES_LIBS) $(RESOLV_LIBS)
6776

77+
78+
mtr_packet_SOURCES = \
79+
packet/packet.c \
80+
packet/cmdparse.c packet/cmdparse.h \
81+
packet/command.c packet/command.h \
82+
packet/platform.h \
83+
packet/probe.c packet/probe.h \
84+
packet/protocols.h \
85+
packet/timeval.c packet/timeval.h \
86+
packet/wait.h
87+
88+
89+
if CYGWIN
90+
91+
mtr_packet_SOURCES += \
92+
packet/command_cygwin.c packet/command_cygwin.h \
93+
packet/probe_cygwin.c packet/probe_cygwin.h \
94+
packet/wait_cygwin.c
95+
mtr_packet_LDADD = -lcygwin -licmp -lws2_32
96+
97+
dist_windows_aux = \
98+
$(srcdir)/mtr.bat \
99+
$(srcdir)/AUTHORS \
100+
$(srcdir)/COPYING \
101+
$(srcdir)/README \
102+
$(srcdir)/NEWS
103+
104+
distwindir = $(distdir)-win-$(host_cpu)
105+
106+
# Bundle necessary files for a Windows binary distribution
107+
distdir-win: $(dist_windows_aux) mtr.exe mtr-packet.exe
108+
rm -fr $(distwindir)
109+
mkdir -p $(distwindir) $(distwindir)/bin $(distwindir)/terminfo
110+
cp $(dist_windows_aux) -t $(distwindir)
111+
cp mtr.exe mtr-packet.exe -t $(distwindir)/bin
112+
ldd mtr.exe | grep -v cygdrive | awk '{ print $$3 }' | xargs cp -t $(distwindir)/bin
113+
cp `find /usr/share/terminfo -name cygwin | xargs dirname` -r $(distwindir)/terminfo
114+
115+
# Zip up a Windows binary distribution
116+
dist-windows-bin: distdir-win
117+
rm -f $(distwindir).zip
118+
zip -rq $(distwindir).zip $(distwindir)
119+
rm -fr $(distwindir)
120+
121+
else # if CYGWIN
122+
123+
mtr_packet_SOURCES += \
124+
packet/command_unix.c packet/command_unix.h \
125+
packet/probe_unix.c packet/probe_unix.h \
126+
packet/wait_unix.c
127+
128+
endif # if CYGWIN
129+
130+
68131
if BUILD_BASH_COMPLETION
69132
dist_bashcompletion_DATA = bash-completion/mtr
70133
endif

bootstrap.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
aclocal $ACLOCAL_OPTS
44
autoheader
55
automake --add-missing --copy --foreign
6-
autoconf
7-
6+
autoconf --force

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ m4_ifdef([AM_SILENT_RULES],
1717
[AM_SILENT_RULES([yes])],
1818
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
1919

20+
AC_CANONICAL_HOST
2021
AC_PROG_CC
2122

2223
# Check pkg-config availability.
@@ -29,6 +30,8 @@ before running ./bootstrap.sh again.])
2930
])
3031
PKG_PROG_PKG_CONFIG
3132

33+
AM_CONDITIONAL([CYGWIN], [test "$host_os" = cygwin])
34+
3235
# Check bytes in types.
3336
AC_CHECK_SIZEOF([unsigned char], [1])
3437
AC_CHECK_SIZEOF([unsigned short], [2])

display.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdio.h>
2222
#include <stdlib.h>
2323
#include <sys/types.h>
24+
#include <time.h>
2425

2526
#include "mtr.h"
2627
#include "display.h"
@@ -107,8 +108,12 @@ extern void display_open(struct mtr_ctl *ctl)
107108
}
108109

109110

110-
extern void display_close(struct mtr_ctl *ctl, time_t now)
111+
extern void display_close(struct mtr_ctl *ctl)
111112
{
113+
time_t now;
114+
115+
now = time(NULL);
116+
112117
switch(ctl->DisplayMode) {
113118
case DisplayReport:
114119
report_close(ctl);

display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum {
5353
/* Prototypes for display.c */
5454
extern void display_detect(struct mtr_ctl *ctl, int *argc, char ***argv);
5555
extern void display_open(struct mtr_ctl *ctl);
56-
extern void display_close(struct mtr_ctl *ctl, time_t now);
56+
extern void display_close(struct mtr_ctl *ctl);
5757
extern void display_redraw(struct mtr_ctl *ctl);
5858
extern void display_rawxmit(struct mtr_ctl *ctl, int hostnum, int seq);
5959
extern void display_rawping(struct mtr_ctl *ctl, int hostnum, int msec, int seq);

0 commit comments

Comments
 (0)