cmd/stunstamp: implement ICMP{v6} probing (#13354)

This adds both userspace and kernel timestamping.

Updates tailscale/corp#22114

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited
2024-09-04 08:36:47 -07:00
committed by GitHub
parent c4d0237e5c
commit 6d6b1773ea
3 changed files with 179 additions and 16 deletions

View File

@@ -460,7 +460,7 @@ type connAndMeasureFn struct {
// newConnAndMeasureFn returns a connAndMeasureFn or an error. It may return
// nil for both if some combination of the supplied timestampSource, protocol,
// or connStability is unsupported.
func newConnAndMeasureFn(source timestampSource, protocol protocol, stable connStability) (*connAndMeasureFn, error) {
func newConnAndMeasureFn(forDst netip.Addr, source timestampSource, protocol protocol, stable connStability) (*connAndMeasureFn, error) {
info := getProtocolSupportInfo(protocol)
if !info.stableConn && bool(stable) {
return nil, nil
@@ -493,8 +493,14 @@ func newConnAndMeasureFn(source timestampSource, protocol protocol, stable connS
}, nil
}
case protocolICMP:
// TODO(jwhited): implement
return nil, nil
conn, err := getICMPConn(forDst, source)
if err != nil {
return nil, err
}
return &connAndMeasureFn{
conn: conn,
fn: mkICMPRTTFn(source),
}, nil
case protocolHTTPS:
localPort := 0
if stable {
@@ -558,7 +564,7 @@ func getConns(
if !ok {
for _, source := range []timestampSource{timestampSourceUserspace, timestampSourceKernel} {
var cf *connAndMeasureFn
cf, err = newConnAndMeasureFn(source, protocol, stableConn)
cf, err = newConnAndMeasureFn(addr, source, protocol, stableConn)
if err != nil {
return
}
@@ -569,7 +575,7 @@ func getConns(
for _, source := range []timestampSource{timestampSourceUserspace, timestampSourceKernel} {
var cf *connAndMeasureFn
cf, err = newConnAndMeasureFn(source, protocol, unstableConn)
cf, err = newConnAndMeasureFn(addr, source, protocol, unstableConn)
if err != nil {
return
}
@@ -953,13 +959,6 @@ func main() {
log.Fatal("nothing to probe")
}
// TODO(jwhited): remove protocol restriction
for k := range portsByProtocol {
if k != protocolSTUN && k != protocolHTTPS && k != protocolTCP {
log.Fatal("ICMP is not yet supported")
}
}
if len(*flagDERPMap) < 1 {
log.Fatal("derp-map flag is unset")
}