Commit Graph
184 Commits
Author SHA1 Message Date
tsosunchia fc0277a93f darwin: avoid promiscuous pcap for TCP and UDP sniffing 2026-04-08 18:05:21 +08:00
tsosunchia 5d8918c191 Add Linux test for non-syscall packet conn binding 2026-04-07 22:11:08 +08:00
tsosunchia 7c8c03fc07 Fix source config test for Windows CI 2026-04-07 22:02:54 +08:00
tsosunchia 212254d380 Prevent unsupported binds and invalid sniff handles 2026-04-07 21:56:13 +08:00
tsosunchia 28d90ae267 Tighten regression cleanup and source device errors 2026-04-07 21:10:29 +08:00
tsosunchia 30fe4881a6 Remove Windows source-device runtime warnings 2026-04-07 19:47:50 +08:00
tsosunchia 0ca093b6aa Harden source-device handling and WinDivert regression checks 2026-04-07 18:27:09 +08:00
tsosunchia 2a5717aedf Fix explicit source/device handling across platforms
Keep the default traceroute path unchanged when neither --source nor --dev is set so existing source address selection, socket setup, and logging stay untouched.

Add a shared explicit source/device normalization helper and route the CLI traceroute path, standalone --mtu path, fast_trace, and server trace requests through it. The helper keeps --source higher priority than --dev, resolves device-derived source addresses by destination family, rejects devices without a usable address, and emits at most one runtime warning.

On macOS, bind TCP and UDP send sockets to the requested interface with IP_BOUND_IF/IPV6_BOUND_IF so explicit --dev survives utun default routes. On Linux, bind ICMP/TCP/UDP send sockets with SO_BINDTODEVICE only when a source device is explicitly configured.

On Windows, keep the existing no-rewrite constraint for real device binding. Explicit --dev now resolves a source address, clears SourceDevice before the tracer is built, and surfaces a single warning that actual egress still follows system routing.

Update CLI help text and README platform notes to document the supported --dev semantics, and add unit tests that cover no-op behavior without explicit overrides, --source priority, device family resolution, mismatch errors, and the Windows downgrade warning.
2026-04-07 17:00:53 +08:00
tsosunchia e4e6c7d270 Catch WinDivert panics in the shared Windows open path 2026-03-22 12:58:59 +08:00
tsosunchia b513155647 Handle missing WinDivert runtime gracefully on Windows 2026-03-22 12:53:04 +08:00
tsosunchia a4efe60ea0 Add regression CI 2026-03-21 09:15:34 +08:00
tsosunchia 2e4aa79eb6 Fix Windows MTU WinDivert timeout and filter handling 2026-03-19 15:13:00 +08:00
tsosunchia 7b8e68710c Fix cancellation handling across DNS, trace, and ws flows 2026-03-19 12:22:02 +08:00
tsosunchia 997918c3e1 fix: improve winDivertCapture close handling and cleanup logic 2026-03-19 11:48:57 +08:00
tsosunchia d05329276b Fix CLI, MTU, logging, and websocket regressions 2026-03-19 11:08:20 +08:00
tsosunchia 7f61abfee6 Fix websocket shutdown race and Darwin MTU fallback 2026-03-19 08:40:42 +08:00
tsosunchia 21396148d0 fix: improve Windows mtu handling and privilege prompts 2026-03-19 00:14:08 +08:00
tsosunchia e060c33777 feat: Enhance traceroute output handling and add tests
- Added support for output path and default output flag in traceroute commands.
- Implemented output path resolution logic with conflict checks.
- Updated globalping and MTR modes to handle new output options.
- Enhanced MTU mode with styled output and improved result printing.
- Refactored table printer to support clear screen option and added tests for table output.
- Introduced new logging functions in tracelog for better file handling and real-time output.
- Added comprehensive tests for new features and existing functionalities.
2026-03-18 22:49:22 +08:00
tsosunchia 976156ba91 fix: restore windows icmpv6 tos handling 2026-03-17 23:12:15 +08:00
tsosunchia cff34d401e feat: update probe packet size handling and defaults across CLI and server 2026-03-17 22:11:13 +08:00
tsosunchia d9dbcc2a38 feat: align psize semantics and add tos 2026-03-17 16:41:10 +08:00
tsosunchia f6816f9592 feat: add standalone mtu mode metadata and flavor gating 2026-03-17 11:33:36 +08:00
tsosunchia 168e482ab9 fix: align mtu mode hop pmtu detection 2026-03-17 00:09:36 +08:00
tsosunchia 3c956068ee fix: make mtu probing follow hop pmtu updates 2026-03-16 23:51:16 +08:00
tsosunchia e448ad7320 fix: show hop-level pmtu updates in mtu mode 2026-03-16 23:37:22 +08:00
tsosunchia 4d967ba7aa feat: add standalone mtu trace mode 2026-03-16 23:10:06 +08:00
tsosunchia 0b0c6662e8 修复 MTR 调度 goroutine 泄漏 2026-03-15 22:11:44 +08:00
tsosunchia 4f4cb0dc16 feat: enhance target port stripping and add tests for edge cases 2026-03-10 23:20:48 +08:00
tsosunchia d96c09a6ff refactor remaining gocyclo hotspots 2026-03-08 14:09:03 +08:00
tsosunchia 5d735b41bd refactor mtr core gocyclo hotspots 2026-03-08 11:59:02 +08:00
tsosunchia 65e2661668 Plan reduce gocyclo complexity 2026-03-08 11:32:39 +08:00
tsosunchia eecc232450 Plan gocyclo complexity improvements 2026-03-08 11:06:51 +08:00
tsosunchia 81797d4b5f Improve gocyclo complexity 2026-03-08 10:54:41 +08:00
tsosunchia d8e93c2a35 feat: improve fast trace flag naming and enhance layout computation tests 2026-03-07 23:05:43 +08:00
tsosunchia 77abf1b515 Refactor MTR signal handling and context management
- Unified signal handling in MTR CLI using `signal.NotifyContext(...)` for Ctrl-C/SIGTERM, removing the need for separate `sigCh` and goroutine.
- Updated `runMTRTUI`, `runMTRReport`, and `runMTRRaw` functions to utilize the new context management.
- Enhanced `mtrUI` to safely call `cancel()` only if it is not nil.
- Modified `IPDBOneClient` to clone HTTP clients with timeout settings, ensuring proper timeout handling without modifying global state.
- Adjusted raw aggregation keys in the frontend to collapse based on TTL, improving display of timeout/success results.
- Added context support in various tracer functions to allow cancellation and timeout handling.
- Improved error handling and test coverage for MTR operations, ensuring robustness against nil results and empty responses.
- Refined DNS resolver functions to use mutexes for thread-safe access to the geo resolver override.
2026-03-06 14:07:58 +08:00
tsosunchia a9a2325762 feat: enhance build scripts and improve error handling for Windows TCP traces 2026-03-06 13:48:16 +08:00
tsosunchia f69903a00c fix(web): resolve post-v1.5.0 review findings
Address all three review findings from the v1.5.0..HEAD audit:\n- Remove Web MTR reliance on process-wide globals (SrcDev/DisableMPLS) by passing session-scoped trace.Config fields.\n- Apply dot_server consistently to Web/API Geo DNS and LeoMoe/FastIP initialization via scoped resolver setup.\n- Restore Web MTR default per-hop cadence to 1000ms and send hop_interval_ms from frontend.\n\nAlso added regression tests in server/trace_handler_test.go and util/dns_resolver_test.go, and updated CLAUDE.md.\n\nValidation passed:\n- go test ./...\n- go build ./...\n- go build -tags flavor_ntr ./...\n- go build -tags flavor_tiny ./...\n- node --check server/web/assets/app.js
2026-03-06 13:04:42 +08:00
tsosunchia 9eff7aabf4 feat: introduce build variants for NextTrace with flavor options
- Added three build flavors: `nexttrace` (full), `nexttrace-tiny`, and `ntr` (MTR-focused).
- Updated README.md and README_zh_CN.md to reflect new build variants and their features.
- Implemented manual build instructions for each flavor.
- Enhanced command-line argument parsing to accommodate flavor-specific options.
- Disabled WebUI and Globalping features in `nexttrace-tiny` and `ntr` flavors.
- Created separate files for handling Globalping and WebUI functionality based on build flavor.
- Added error handling for unavailable features in non-full builds.
2026-03-05 22:05:38 +08:00
tsosunchia 357c03604d feat: remove unnecessary -checklinkname flag from build scripts and documentation 2026-03-02 16:31:46 +08:00
tsosunchia f131a99dc1 fix: 限制mtr模式最大跳数为 255,确保调度器稳定性 2026-03-02 00:23:17 +08:00
tsosunchia efb437fbac fix: improve error handling and logging across multiple packages
- Enhanced error handling in `mtr_ui.go` to log warnings when raw mode cannot be enabled.
- Updated `geofeed.go` to return a more informative error instead of panicking when geofeed data cannot be loaded.
- Refined error handling in `ptr.go` to return an error if `ptrPath` is not configured.
- Improved error handling in `fast_trace.go` for network interface address retrieval.
- Added error checks in `chunzhen.go` and `ipapicom.go` for HTTP request creation and response reading.
- Enhanced error handling in `ipdbone.go` to return descriptive errors for authentication failures.
- Updated `ipfilter.go` to ensure proper IP parsing before filtering.
- Improved error handling in `ipinfoLocal.go` for database access and record parsing.
- Enhanced error handling in `ipsb.go` for HTTP request creation and response reading.
- Added checks for closed channels in `leo.go` to prevent panics.
- Improved panic recovery in `ws_handler.go` to log errors in the write loop.
- Added read deadline to WebSocket connections in `ws_handler.go` to prevent blocking.
- Enhanced configuration checks in `globalping.go` to avoid nil pointer dereferences.
- Improved error logging in `icmp_ipv4.go` and `icmp_ipv6.go` for send errors.
- Enhanced error handling in `icmp_darwin.go`, `icmp_unix.go`, and `icmp_windows.go` for checksum setting.
- Improved error handling in TCP and UDP implementations across various platforms for checksum settings.
- Enhanced error handling in `tracemap.go` for proxy configuration.
- Improved type assertions in `util.go` for DNS cache lookups.
2026-03-02 00:14:49 +08:00
tsosunchia 3a6ba0a99e fix(web-mtr): 修复 Per-Hop 并发下超发残影与长持锁阻塞问题
- 修复 WebSocket MTR per-hop 路径中 traceMu 长时间持锁,改为仅初始化阶段短暂加锁,避免持续探测期间阻塞其他请求
- 新增 hop_interval_ms 请求字段,保留 interval_ms 兼容,并按 hop_interval_ms -> interval_ms -> 1000ms 回退
- 前端新增 knownFinalTTL 截断逻辑:命中目标 TTL 后下调水标并清理高 TTL 过期行,拦截后续高 TTL 迟到数据
- 在 clearResult(resetState) 中重置截断水标,避免会话间状态污染
- 新增前端截断行为测试,覆盖下调、剪枝、丢弃与重置场景
- 回归通过:前端聚合测试、Go 构建与现有测试集均通过
2026-03-01 22:38:33 +08:00
tsosunchia 89ce9a660d feat: 增强 MTR 调度器,支持每跳多个并发探测,优化超时处理和统计逻辑 2026-03-01 20:20:25 +08:00
tsosunchia ad3ecbd401 fix: 统一处理 context.Canceled 错误检查,确保一致性
feat(ipgeo): 在 API 请求中添加 defer 关闭响应体
fix: 修复 MTR 模式中错误处理逻辑,确保资源正确释放
test: 更新测试用例以验证 context.Canceled 错误处理
refactor: 优化 mplsSet 初始化逻辑
test: 修改测试断言为 require,增强错误处理
2026-03-01 19:24:20 +08:00
tsosunchia e63c4159c1 fix(trace): 优化 CanonicalHostname 函数,简化去掉尾点的逻辑 2026-03-01 18:51:43 +08:00
tsosunchia c8323b97cc feat(mtr): 实现 ClearHop 方法以清除过期聚合数据,避免 ghost row 并防止 Snt 膨胀 2026-03-01 03:36:55 +08:00
tsosunchia 7e2226f186 feat(mtr): discard over-final TTL destination replies and remove Round label from CLI output
remove higher-TTL destination folding after final TTL is known
discard disabled TTL results before accounting/callback/lowering
keep lowering + MigrateStats behavior unchanged
drop "Round:" from TUI status line and table fallback
add regressions for late over-final replies and raw emission fidelity
2026-03-01 03:15:36 +08:00
tsosunchia 92e93ff0d4 feat(mtr): 压缩 TUI 指标区、折叠高 TTL 目标、重排显示模式并新增 -y/--ipinfo
本次修改仅影响 CLI 下的 MTR TUI 模式,不涉及 --report/--wide/--raw、普通 traceroute 或 Web MTR。

主要变更:
- 指标区压缩:将 Loss% 列宽缩至 5、Snt 缩至 3、RTT 五列缩至 7,列名不变,双行表头仍保留,提高 Host 列宽度。
- 目标折叠:目标在某个 TTL 确认后,后续更高 TTL 的 dst‑ip 响应不再单独显示,而是折叠到最终 TTL;折叠后 Snt 不得超过 MaxPerHop,超出部分丢弃;调度器区分 originTTL/accountTTL,disabled TTL 的 dst‑ip 回复允许折叠。
- 显示模式扩展:新增 HostModeBase (0),五档依次为 IP/PTR、ASN、City、Owner、Full;默认显示 IP/PTR。`y` 键循环顺序调整为 0→1→2→3→4→0。
- 新增 CLI 参数 `-y, --ipinfo` (0..4) 用于设置 TUI 初始显示模式;在 --report/--wide/--raw 中可解析但被忽略;非法值报错。
- `runMTRTUI`/`newMTRUI` 支持传入初始 mode,`r` 键重置统计不再影响显示模式。
- 当 mode ≥ ASN 且无 ASN 时插入 `AS???` 占位符;Base 模式不显示占位符。
- 更新 CLI 帮助、README 与 README_zh_CN 文档,说明新的默认模式、y 键循环和 `-y/--ipinfo` 映射关系。
- 新增或调整单元测试,覆盖显示模式循环、默认与初始值、参数校验与忽略逻辑、主机信息渲染、紧凑布局以及目标折叠等场景。

非目标:report/wide/raw 模式、Web MTR 和普通 traceroute。
2026-03-01 02:03:56 +08:00
tsosunchia 233d4eea5d Implement per-hop independent MTR scheduler and associated tests
- Added `mtr_scheduler.go` to implement a per-hop independent scheduling mechanism for MTR (My Traceroute) probes.
- Introduced `mtrTTLProber` interface for probing TTLs and handling probe results.
- Implemented `runMTRScheduler` function to manage the scheduling of probes based on TTL, handle errors, and aggregate results.
- Added configuration options for hop intervals, maximum hops, and error handling.
- Created `mtr_scheduler_test.go` to include comprehensive unit tests for the scheduler, covering various scenarios such as maximum probes per hop, context cancellation, destination detection, error budgets, and reset functionality.
- Mocked TTL prober to simulate probe responses and track probe counts for testing.
2026-02-28 15:47:40 +08:00
tsosunchia d41d8b2fba feat: Introduce MTR raw streaming functionality
- Added support for streaming probe-level MTR raw events via `trace.RunMTRRaw`.
- Implemented a new `mtrRawAggregator` to handle raw MTR data aggregation.
- Updated the web client to handle `mtr_raw` messages and render statistics accordingly.
- Introduced new JavaScript module `mtr_agg.js` for aggregating MTR raw data.
- Created new printer functions for formatting MTR raw records.
- Added tests for the new MTR raw functionality to ensure correct behavior.
- Deprecated the legacy snapshot aggregator for MTR.
2026-02-28 09:41:25 +08:00