Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially confusing displayed index of DNS rules #2360

Open
4 of 5 tasks
john-jane-doe opened this issue Dec 10, 2024 · 0 comments
Open
4 of 5 tasks

Potentially confusing displayed index of DNS rules #2360

john-jane-doe opened this issue Dec 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@john-jane-doe
Copy link

Operating system

Linux

System version

Ubuntu 20.04.6 LTS (Linux 6.5.0-1025-azure)

Installation type

Original sing-box Command Line

If you are using a graphical client, please provide the version of the client.

No response

Version

sing-box version 1.10.3-93966bdd

Environment: go1.23.1 linux/amd64
Tags: with_gvisor,with_dhcp,with_wireguard,with_reality_server,with_clash_api,with_quic,with_utls,with_ech
Revision: 93966bdd36fc466de7b66d5e36900e3df568e936
CGO: enabled

Description

Seems sing-box outputs a strange index (1, 3, 5, ...) for matched DNS rules:

displayRuleIndex := currentRuleIndex
if displayRuleIndex != -1 {
displayRuleIndex += displayRuleIndex + 1
}
ruleDescription := currentRule.String()
if ruleDescription != "" {
r.logger.DebugContext(ctx, "match[", displayRuleIndex, "] ", currentRule, " => ", currentRule.Action())
} else {
r.logger.DebugContext(ctx, "match[", displayRuleIndex, "] => ", currentRule.Action())
}

This behavior is different from the displayed index when showing matched route rule:

sing-box/route/route.go

Lines 375 to 380 in 93966bd

ruleDescription := currentRule.String()
if ruleDescription != "" {
r.logger.DebugContext(ctx, "match[", currentRuleIndex, "] ", currentRule, " => ", currentRule.Action())
} else {
r.logger.DebugContext(ctx, "match[", currentRuleIndex, "] => ", currentRule.Action())
}

Reproduction

{
    "log": {
        "level": "debug"
    },
    "dns": {
        "servers": [
            {
                "tag": "demo-1",
                "address": "8.8.8.8"
            },
            {
                "tag": "demo-2",
                "address": "8.8.4.4"
            },
            {
                "tag": "demo-3",
                "address": "1.1.1.1"
            }
        ],
        "rules": [
            {
                "domain": [
                    "www.demo-1.com"
                ],
                "server": "demo-1"
            },
            {
                "domain": [
                    "www.demo-2.com"
                ],
                "server": "demo-2"
            },
            {
                "domain": [
                    "www.demo-3.com"
                ],
                "server": "demo-3"
            }
        ]
    },
    "inbounds": [
        {
            "type": "mixed",
            "listen": "127.0.0.1",
            "listen_port": 7890
        }
    ],
    "outbounds": [
        {
            "type": "direct",
            "tag": "direct",
        }
    ]
}

Logs

# Why 1, 3, 5 instead of 1, 2, 3 or 0, 1, 2?
DEBUG[0007] [4215554483 0ms] dns: lookup domain www.demo-1.com
DEBUG[0007] [4215554483 0ms] router: match[1] domain=www.demo-1.com => route(demo-1)
DEBUG[0007] [4215554483 0ms] router: match[1] => route(demo-1)
...
DEBUG[0012] [1933278907 0ms] dns: lookup domain www.demo-2.com
DEBUG[0012] [1933278907 0ms] router: match[3] domain=www.demo-2.com => route(demo-2)
DEBUG[0012] [1933278907 0ms] router: match[3] => route(demo-2)
...
DEBUG[0017] [3735997981 0ms] dns: lookup domain www.demo-3.com
DEBUG[0017] [3735997981 0ms] router: match[5] domain=www.demo-3.com => route(demo-3)
DEBUG[0017] [3735997981 0ms] router: match[5] => route(demo-3)
...

Supporter

Integrity requirements

  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
  • I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
  • I confirm that I have provided the complete configuration files and logs, rather than just providing parts I think are useful out of confidence in my own intelligence.
@nekohasekai nekohasekai added the bug Something isn't working label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants