Skip to content

检测端口冲突时区分 tcp 和 udp 端口,防止误报#1243

Merged
juewuy merged 5 commits intojuewuy:devfrom
abcfy2:dev
Mar 23, 2026
Merged

检测端口冲突时区分 tcp 和 udp 端口,防止误报#1243
juewuy merged 5 commits intojuewuy:devfrom
abcfy2:dev

Conversation

@abcfy2
Copy link
Copy Markdown
Contributor

@abcfy2 abcfy2 commented Mar 22, 2026

Fix #1242

只有 DNS 端口是同时监听 TCP + UDP ,其余均是 TCP 端口,所以检查端口冲突的时候进行端口类型区分,防止误报。

所有修改过的文件全部使用 shfmt 格式化

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ed66026be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"$db_port") current_port_name="db_port" ;;
esac

if [ -z "$current_port_name" ] && echo "|$mix_port|$redir_port|$dns_port|$db_port|" | grep -q "|$port|"; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep duplicate-port guard active for existing ports

This condition disables duplicate checking whenever the input matches any configured internal port, so collisions between different settings can now slip through. For example, when editing db_port, entering the current mix_port value sets current_port_name and bypasses the duplicate check, which then writes conflicting ports and can break startup/binding later when both services try to use the same port. The duplicate guard should exclude only the field currently being edited, not all known ports.

Useful? React with 👍 / 👎.

- check_port 函数只负责检查端口范围和占用,移除重复检查逻辑
- 端口重复检查移到 inputport 函数中,只排除当前编辑的端口变量
- 修复编辑端口时错误地跳过所有已配置端口重复检查的 bug
@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 22, 2026

@codex review again

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c61c637e0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

scripts/menu.sh Outdated

if [ -n "$conflict_line" ]; then
if [ "$conflict_found" -eq 0 ]; then
conflict_info=$(check_port_with_info "$((redir_port + 1))" tcp)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Check redir companion port with UDP as well

This change now checks redir_port + 1 using tcp only, so an existing UDP listener on that port is no longer treated as a conflict. In TProxy mode that companion port is used for UDP traffic too (see scripts/starts/fw_iptables.sh where -p udp is redirected to $tproxy_port), so this false negative can let users save a conflicting port and then hit runtime bind/startup failures or broken UDP proxying.

Useful? React with 👍 / 👎.

tproxy_port (redir_port + 1) 在 TProxy 模式下同时用于 TCP 和 UDP,
端口冲突检查应使用 all 而非 tcp
@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 22, 2026

@codex review again

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b734fc6e1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +26 to +27
if $check_cmd 2>/dev/null | grep -q ":${port}[[:space:]]"; then
msg_alert "\033[31m$CHECK_PORT_OCCUPIED_ERR\033[0m"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reinstate config duplicate-port guard in check_port

check_port now only checks active listeners, so callers that rely on it directly (notably scripts/menus/7_gateway.sh at the check_port "$text" validations) can save a port already reserved by mix_port/redir_port/dns_port/db_port whenever CrashCore is stopped. This regression was introduced by removing the prior duplicate-config branch, and it allows writing conflicting settings that later fail when services bind on startup. Keep the new protocol-aware netstat logic, but restore duplicate-config rejection in this function (or add equivalent checks at those call sites).

Useful? React with 👍 / 👎.

在 7_gateway.sh 中设置 vms_port 和 sss_port 时,只检查了端口范围
和系统占用,未检查与 mix_port/redir_port/dns_port/db_port 的冲突。
当 CrashCore 停止时可能导致保存冲突端口配置,启动时绑定失败。
@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 22, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 22, 2026

@juewuy 可以审核了,没有明显的问题了。

@juewuy
Copy link
Copy Markdown
Owner

juewuy commented Mar 23, 2026

内核本身对于redirect、tproxy、mix端口都是强制占用udp的,并非只有DNS端口,目前唯一不占用udp的只有ui端口

@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 23, 2026

验证了一下的确如此,我调整下代码

@juewuy
Copy link
Copy Markdown
Owner

juewuy commented Mar 23, 2026

@abcfy2 另外不同版本netstat工具的输出格式可能不相同,如果有华硕设备尽量在华硕固件上完成测试

@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 23, 2026

这个我测试过是没问题的,华硕的 netstat 来自于 busybox ,busybox 提供的 netstat 基本上是 gnu netstat 的子集:

BusyBox v1.25.1 (2025-11-15 00:39:08 UTC) multi-call binary.

Usage: netstat [-ral] [-tuwx] [-enWp]

Display networking information

        -r      Routing table
        -a      All sockets
        -l      Listening sockets
                Else: connected sockets
        -t      TCP sockets
        -u      UDP sockets
        -w      Raw sockets
        -x      Unix sockets
                Else: all socket types
        -e      Other/more information
        -n      Don't resolve names
        -W      Wide display
        -p      Show PID/program name for sockets

常用的参数都支持

@abcfy2
Copy link
Copy Markdown
Contributor Author

abcfy2 commented Mar 23, 2026

@juewuy 更新了 PR ,除了 9999 端口之外,其余端口采用 TCP+UDP 检测

@juewuy juewuy merged commit cf35708 into juewuy:dev Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] dev 分支检查端口占用未区分 tcp 和 udp

2 participants