dmicmp DMOD library module.
dmicmp builds and parses ICMP messages (RFC 792 for ICMPv4, RFC 4443 for
ICMPv6) and plugs into dmip's
protocol dispatch: it registers as the handler for ICMP's own IP protocol
number (answering an incoming Echo Request with an Echo Reply inline, no
extra thread needed) and as dmip's default handler, replying with an
ICMPv4 Destination Unreachable to any IP packet whose protocol nobody
else claimed. See docs/dmicmp.md for the full design
rationale, including the deliberate, temporary IPv6-send gap (no
dmip_v6_send() yet) and the echo-reply listener registry used for
sending our own Echo Request ("ping").
mkdir -p build
cd build
cmake ..
cmake --build .Pass -DDMOD_DIR=/path/to/local/dmod to build against a local dmod checkout
instead of fetching develop from GitHub.
make DMOD_MODE=DMOD_MODULE DMOD_DIR=/path/to/dmodTests are built automatically alongside the module (see tests/). Once built,
run them with ctest:
cd build
ctest --output-on-failurectest installs the test module's dependencies with dmf-get and then runs
it through dmod_loader. To run it manually instead:
export DMOD_DMF_DIR=$(pwd)/build/dmf
dmf-get install -d ${DMOD_DMF_DIR}/test_dmicmp-local.dmd -y
dmod_loader build/dmf/test_dmicmp.dmfdmicmp needs no setup from other modules to do its core job (answering
pings, reporting an unclaimed protocol) - it registers itself with dmip
automatically in dmod_init(). A module that wants to send its own ping
or report its own delivery failure calls it directly:
#include "dmicmp.h"
/* Report "port unreachable" for a UDP datagram nobody's listening for */
dmicmp_v4_send_dest_unreachable(dmicmp_v4_dest_unreachable_port,
original_ip_packet, original_ip_packet_len,
DMARP_DEFAULT_TIMEOUT_MS);
/* Send a ping and find out about the reply */
dmicmp_register_echo_listener(my_identifier, my_echo_reply_handler);
dmicmp_v4_send_echo_request(&dst, my_identifier, 1, NULL, 0, DMARP_DEFAULT_TIMEOUT_MS);| Function | Description |
|---|---|
dmicmp_build_header() / _parse_header() |
Build/parse the 8-byte common ICMP header |
dmicmp_v4_checksum_valid() / _v6_checksum_valid() |
Verify a received ICMP message's checksum |
dmicmp_v4_send_error() |
General-purpose: send an arbitrary ICMPv4 error message (any type/code) about some undeliverable original packet |
dmicmp_v4_send_dest_unreachable() |
Thin wrapper over dmicmp_v4_send_error() for the common Destination Unreachable case |
dmicmp_v4_send_echo_request() |
Send an ICMPv4 Echo Request ("ping") |
dmicmp_register_echo_listener() / _unregister_echo_listener() |
Learn about the Echo Reply matching a ping's identifier |
See include/dmicmp.h for the full declarations and docs/api-reference.md for the complete reference.
See the docs/ directory:
- dmicmp.md - Design overview and rationale
- api-reference.md - Complete API documentation
View documentation using dmf-man dmicmp.
dmicmp/
├── docs/ # Documentation (markdown format)
├── include/ # Public headers
│ └── dmicmp.h
├── src/
│ └── dmicmp.c
├── tests/
│ ├── CMakeLists.txt
│ └── dmicmp_test.c
├── CMakeLists.txt
├── Makefile
├── dmicmp.dmr
└── manifest.dmm
Patryk Kubiak
MIT