tUpdate source file for clarity - icmphop - Add hops in ipv6 traceroute
(HTM) git clone git://git.z3bra.org/icmphop.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 2bd7eacac3bf4e23890df8d18c24fb981e0ed8c4
(DIR) parent 0eca802c92d2838b2424c11d3925bbe3e0296e7b
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Thu, 13 Oct 2022 18:01:25 +0200
Update source file for clarity
Diffstat:
M icmphop.go | 56 +++++++++++++++++++++----------
1 file changed, 38 insertions(+), 18 deletions(-)
---
(DIR) diff --git a/icmphop.go b/icmphop.go
t@@ -1,11 +1,12 @@
/*
- * Insert hops in ipv6 traceroute
+ * Insert hops in traceroute (ipv6 only)
*
- * Create a tunnel interface to send back ICMP timeout exceeded error
- * messages when targetting a specific ipv6 address.
+ * Create a virtual interface, and send "time exceeded" messages
+ * until the TTL match a specified number, effectively adding hops
+ * to a traceroute.
*
- * In order to add hops, the destination address' last byte must be the
- * TTL number
+ * The source of the error messages is changed so the traceroute
+ * appears to be incrementing, up to the requested destination.
*
* by wgs
*/
t@@ -23,11 +24,16 @@ import (
"golang.zx2c4.com/wireguard/tun"
)
-const TUN_HEADER = 4
-const IPV6_HEADER = 40
-const ICMP_HEADER = 4
+const (
+ TUN_HEADER = 4
+ IPV6_HEADER = 40
+ ICMP_HEADER = 4
+)
-/* compute IPv6 checksum for a given packet */
+/*
+ * Compute IPv6 checksum for a given packet
+ * https://datatracker.ietf.org/doc/html/rfc4443#section-2.3
+ */
func checksum(body []byte, srcIP, dstIP net.IP) (crc []byte) {
out := make([]byte, 2)
// from golang.org/x/net/icmp/message.go
t@@ -71,6 +77,7 @@ func ipv6_header(src, dst net.IP, len uint16) []byte {
header[6] = 0x3a // Next header (58, ICMPv6)
header[7] = 0x40 // Hop Limit (64)
+ // source / destination ipv6
copy(header[8:], src[:16])
copy(header[24:], dst[:16])
t@@ -135,9 +142,18 @@ func main() {
packet := buf[TUN_HEADER : TUN_HEADER+sz]
- // Skip packet if the specified number of hops cannot
- // be inserted by only changing the last byte
+ /*
+ * Skip packet if the specified number of hops cannot
+ * be inserted by only changing the last byte
+ */
if packet[39] < hops {
+ if *verbose == true {
+ log.Printf("%s %s > %s Dropped (last byte 0x%02x < 0x%02x)",
+ *ifname,
+ net.IP(packet[24:40]).String(),
+ net.IP(packet[8:24]).String(),
+ packet[39], hops-1)
+ }
continue
}
t@@ -147,14 +163,18 @@ func main() {
copy(dst, packet[8:8+16])
copy(src, packet[24:24+16])
- // If TTL is lower than the configured number of hops,
- // start sending ICMP time exceeded replies to the
- // originating source.
+ /*
+ * If TTL is lower than the configured number of hops,
+ * start sending ICMP time exceeded replies to the
+ * originating source.
+ */
if ttl < hops+1 {
- // Use hexa representation of TTL as the
- // last byte of source address, thus
- // incrementing hops until final destination
- // is reached
+ /*
+ * Use hexa representation of TTL as the
+ * last byte of source address, thus
+ * incrementing hops until final destination
+ * is reached
+ */
src[15] = src[15] - hops + ttl
// ICMP error must fit in 1280 bytes (ipv6 min. mtu)