mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-11-30 08:28:01 +00:00
* feat(trace): 支持 Linux fwmark 会话级策略路由探测 同步源地址选路与发送 socket 标记,覆盖三协议、双栈及 MTR 重建;增加 JSON 会话参数和隔离双出口回归。 * test(fwmark): 显式指定隔离网络的接口名称 * test(fwmark): 等待即时抓包就绪并修正错误输出检查 * fix(fwmark): 随机源端口不参与固定端口路由查询 * test(fwmark): 验证随机端口路由和显式接口约束 * test(fwmark): 验证目的地回包并隔离 ICMP 限速干扰 * test(fwmark): 移除内核不接受的源端口规则 * fix(fwmark): 路由查询前分配会话固定源端口 * fix(fwmark): 按原始 socket 语义查询路由并忽略传输端口
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
//go:build linux && !android
|
|
|
|
package trace
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/nxtrace/NTrace-core/internal/routeprobe"
|
|
)
|
|
|
|
func resolveFWMarkSource(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 := routeprobe.Query(ctx, fwmarkRouteRequest(method, cfg))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if r.Source == "" {
|
|
return "", fmt.Errorf("marked route did not provide a source address")
|
|
}
|
|
return r.Source, nil
|
|
}
|
|
|
|
func fwmarkRouteRequest(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: true,
|
|
}
|
|
}
|