Recent versions of Cygwin implement pipe() using Windows' named
pipes, and put the read end of the pipe in FILE_PIPE_COMPLETE_OPERATION
mode, which doesn't allow overlapped I/O operations.
For the relevant commit in the Cygwin repository, see
9e4d308cd592fe383dec58ea6523c1b436888ef8
The solution here is to maintain a Windows event object which is
set only when any ICMP requests are pending. We can do an alertable
wait on that event object, which will allow us to complete ICMP
requests.
Thanks to Adam Schultz for research into this issue and a first
attempt at a fix.
In certain scenarios, the routing policy database may affect packet
routing. When selecting an address in `mtr`, assign a packet mark if
`SO_MARK` is defined and a mark has been supplied.
The `set_privileged_socket_opt` function is currently called only when
`SO_MARK` or `SO_BINDTODEVICE` are defined. On systems that do not support
either feature, `set_privileged_socket_opt` is expected to be unused. Adding
an annotation suppresses compiler warnings.
This commit introduces three unit tests focused on interface binding,
packet marking, and IP source address spoofing/selection. Each of these
tests builds upon the original `MtrPacketTest` base class. To evaluate
these network-dependent features, the tests utilize an emulated network
environment. To enable this, a small network emulation library, `netem`,
has been developed specifically for this purpose. `Netem` allows for the
creation of arbitrary network configurations for testing and can reliably
set up and clean up virtual network environments on Linux systems. The only
dependencies are `iproute2` and `libc`, which are generally pre-installed
on most Linux hosts.
The commit adds three tests that are expected to fail:
1. Interface Binding: Evaluates the capability of `mtr-packet` to bind to
a specific interface.
2. Packet Marking: Assesses the ability of `mtr-packet` to apply a Linux
networking mark (fwmark).
3. Source Address Selection: Tests `mtr-packet`'s ability to spoof or bind
to a specified source address.
This commit addresses an issue where mtr would fail with EPERM because setting the
SO_BINDTODEVICE socket option requires the CAP_NET_RAW capability.
Changes:
- Refactor the code to abstract setting privileged socket options. This
includes a common interface for setting capabilities depending on the
platform (with or without LIBCAP).
- Replace direct setsockopt calls with the new abstracted function for
setting both SO_MARK and SO_BINDTODEVICE.
- Update capability management in `drop_excess_capabilities` to retain
CAP_NET_RAW when needed.
Modify the capability-dropping logic to specifically retain CAP_NET_ADMIN if it
is initially provided, in adherence to least-privilege principles.
Details:
1. Update the `drop_excess_capabilities` function to only drop capabilities that
are unnecessary, retaining CAP_NET_ADMIN when needed for setting the socket
mark.
2. Introduce logic in `set_socket_mark` to temporarily elevate CAP_NET_ADMIN
into the effective set for the duration of the packet mark setting
operation.
In the test folder, there was lint.sh, but I think flake8 is a better
tool.
Added a compile job for linux, this runs compilation as defined in
the README, runs a sample mtr and runs cmdparse.py test. Need
documentation on what other tests to run and whether to include the
testing in tox instead of running them individually.
Not adding in this PR support for cygwin or freebsd, as that will need
investigation on how to run.
Minor:
- Fixed a typo in configure.ac that used ---- vs -- for a flag option.