From 9dda330543e4782daeaeb185521b839d00c40738 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Thu, 30 May 2024 02:23:33 +0000 Subject: [PATCH 1/2] workflow-test.yaml: set go version --- .github/workflows/test.yml | 3 +-- go.mod | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 29c5fdad..033a506f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,8 +31,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.22' - check-latest: true + go-version: '1.22.0' - name: Checkout codebase uses: actions/checkout@v4 - name: Test with unix diff --git a/go.mod b/go.mod index 4d699f70..bcd3966f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nxtrace/NTrace-core -go 1.22 +go 1.22.0 require ( github.com/akamensky/argparse v1.4.0 From d0fb43e94724902641f10b139e13806958f78c03 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Thu, 30 May 2024 03:23:10 +0000 Subject: [PATCH 2/2] add ipv4 tcp dontFragment option --- cmd/cmd.go | 3 +++ fast_trace/fast_trace ipv6.go | 1 + fast_trace/fast_trace.go | 2 ++ trace/tcp_ipv4.go | 3 +++ trace/trace.go | 2 ++ 5 files changed, 11 insertions(+) diff --git a/cmd/cmd.go b/cmd/cmd.go index 5a80a8a4..ab2e7997 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -70,6 +70,7 @@ func Excute() { Help: "Choose the language for displaying [en, cn]"}) file := parser.String("", "file", &argparse.Options{Help: "Read IP Address or domain name from file"}) nocolor := parser.Flag("C", "nocolor", &argparse.Options{Help: "Disable Colorful Output"}) + dontFragment := parser.Flag("", "dont-fragment", &argparse.Options{Default: false, Help: "Set the Don't Fragment bit (IPv4 TCP only)"}) err := parser.Parse(os.Args) if err != nil { @@ -112,6 +113,7 @@ func Excute() { PktSize: *packetSize, Timeout: time.Duration(*timeout) * time.Millisecond, File: *file, + DontFragment: *dontFragment, } fastTrace.FastTest(*tcp, *output, paramsFastTrace) @@ -270,6 +272,7 @@ func Excute() { IPGeoSource: ipgeo.GetSource(*dataOrigin), Timeout: time.Duration(*timeout) * time.Millisecond, PktSize: *packetSize, + DontFragment: *dontFragment, } // 暂时弃用 diff --git a/fast_trace/fast_trace ipv6.go b/fast_trace/fast_trace ipv6.go index b4675ee6..e6e8c3e3 100644 --- a/fast_trace/fast_trace ipv6.go +++ b/fast_trace/fast_trace ipv6.go @@ -39,6 +39,7 @@ func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) { SrcAddr: f.ParamsFastTrace.SrcAddr, PktSize: f.ParamsFastTrace.PktSize, Lang: f.ParamsFastTrace.Lang, + DontFragment: f.ParamsFastTrace.DontFragment, } if oe { diff --git a/fast_trace/fast_trace.go b/fast_trace/fast_trace.go index 6728b8aa..5c291b54 100644 --- a/fast_trace/fast_trace.go +++ b/fast_trace/fast_trace.go @@ -34,6 +34,7 @@ type ParamsFastTrace struct { PktSize int Timeout time.Duration File string + DontFragment bool } type IpListElement struct { @@ -68,6 +69,7 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) { SrcAddr: f.ParamsFastTrace.SrcAddr, PktSize: f.ParamsFastTrace.PktSize, Lang: f.ParamsFastTrace.Lang, + DontFragment: f.ParamsFastTrace.DontFragment, } if oe { diff --git a/trace/tcp_ipv4.go b/trace/tcp_ipv4.go index 170dea16..4bf1c297 100644 --- a/trace/tcp_ipv4.go +++ b/trace/tcp_ipv4.go @@ -219,6 +219,9 @@ func (t *TCPTracer) send(ttl int) error { TTL: uint8(ttl), //Flags: layers.IPv4DontFragment, // 我感觉没必要 } + if t.DontFragment { + ipHeader.Flags = layers.IPv4DontFragment + } // 使用Uint16兼容32位系统,防止在rand的时候因使用int32而溢出 sequenceNumber := uint32(r.Intn(math.MaxUint16)) tcpHeader := &layers.TCP{ diff --git a/trace/trace.go b/trace/trace.go index a0ef2826..d49dba2a 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -42,6 +42,7 @@ type Config struct { AsyncPrinter func(res *Result) PktSize int Maptrace bool + DontFragment bool } type Method string @@ -81,6 +82,7 @@ func Traceroute(method Method, config Config) (*Result, error) { if config.DestIP.To4() != nil { tracer = &UDPTracer{Config: config} } else { + //TODO: IPv6 UDP trace 在做了,指新建文件夹( return nil, errors.New("IPv6 UDP Traceroute is not supported") } case TCPTrace: