mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-11-30 00:21:48 +00:00
保留完整 8 位 TOS 参数,传播初始化失败,修复 Linux 策略路由选源与 MTR socket 轮换,并为 Windows 非零 ICMPv4 TOS 使用 WinDivert。补齐三平台抓包、Linux 隔离路由验收及平台文档。
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
//go:build linux && !android
|
|
|
|
package trace
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/nxtrace/NTrace-core/internal/routeprobe"
|
|
)
|
|
|
|
var queryProbeRoute = routeprobe.Query
|
|
|
|
func resolveProbeRouteSource(method Method, cfg Config) (string, error) {
|
|
ctx := cfg.Context
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
timeout := cfg.Timeout
|
|
if timeout <= 0 {
|
|
timeout = time.Second
|
|
}
|
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
|
defer cancel()
|
|
r, err := queryProbeRoute(ctx, probeRouteRequest(method, cfg))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if r.Source == "" {
|
|
return "", fmt.Errorf("probe route did not provide a source address")
|
|
}
|
|
return r.Source, nil
|
|
}
|
|
|
|
func probeRouteRequest(method Method, cfg Config) routeprobe.Request {
|
|
// Raw probe sockets serialize transport headers in user space. Their kernel
|
|
// route lookup has no transport ports, even when the probe uses fixed ports.
|
|
return routeprobe.Request{
|
|
Method: string(method), DstIP: cfg.DstIP, SrcAddr: cfg.SrcAddr, SourceDevice: cfg.SourceDevice,
|
|
TOS: cfg.TOS, FWMark: cfg.FWMark, FWMarkSet: cfg.FWMarkSet,
|
|
HeaderIncluded: method == UDPTrace && cfg.DstIP.To4() != nil,
|
|
}
|
|
}
|