yichya / luci-app-xray

(Almost) full feature Xray client for OpenWrt
Mozilla Public License 2.0
555 stars 328 forks source link

自定义Custom Configurations行为不符合预期 #320

Closed ghggn closed 1 year ago

ghggn commented 1 year ago

添加的配置如下

{
  "rules" : [
      {
        "type": "field",
        "inboundTag": [
          "tproxy_tcp_inbound",
          "tproxy_udp_inbound",
          "dns_conf_inbound",
          "socks_inbound",
          "https_inbound",
          "http_inbound"
        ],
        "outboundTag": "direct",
        "ip": [
          "geoip:cn"
        ]
      }
    ]
}

合并后如下

...
      {
        "type": "field",
        "inboundTag": [
          "tproxy_tcp_inbound",
          "tproxy_udp_inbound",
          "dns_conf_inbound"
        ],
        "outboundTag": "direct",
        "ip": [
          "geoip:cn"
        ]
      },
...

但国外IP却匹配到了direct通道 一些示例xray log:

Fri Jul 21 10:41:02 2023 daemon.info xray[4458]: Xray 1.8.1 (Xray, Penetrates Everything.) OpenWrt (go1.19.9 linux/amd64)
Fri Jul 21 10:41:02 2023 daemon.info xray[4458]: A unified platform for anti-censorship.
Fri Jul 21 10:41:02 2023 daemon.err xray[4458]: 2023/07/21 10:41:02 Using confdir from arg: /var/etc/xray
Fri Jul 21 10:41:02 2023 daemon.info xray[4458]: 2023/07/21 10:41:02 [Info] infra/conf/serial: Reading config: /var/etc/xray/config.json
Fri Jul 21 10:41:02 2023 daemon.info xray[4458]: 2023/07/21 10:41:02 [Info] infra/conf/serial: Reading config: /var/etc/xray/config_custom.json
Fri Jul 21 10:41:02 2023 daemon.info xray[4458]: 2023/07/21 10:41:02 [Warning] core: Xray 1.8.1 started
Fri Jul 21 10:41:03 2023 daemon.info xray[4458]: 2023/07/21 10:41:03 127.0.0.1:41010 accepted udp:119.29.29.29:53 [dns_server_inbound_5300 >> direct]
Fri Jul 21 10:41:03 2023 daemon.info xray[4458]: 2023/07/21 10:41:03 192.168.2.102:8802 accepted udp:121.138.137.209:61065 [tproxy_udp_inbound >> direct]
Fri Jul 21 10:41:03 2023 daemon.info xray[4458]: 2023/07/21 10:41:03 192.168.2.100:53472 accepted tcp:149.154.167.151:443 [tproxy_tcp_inbound >> direct]
Fri Jul 21 10:41:03 2023 daemon.info xray[4458]: 2023/07/21 10:41:03 192.168.2.100:53476 accepted tcp:149.154.175.59:443 [tproxy_tcp_inbound >> direct]
Fri Jul 21 10:41:03 2023 daemon.info xray[4458]: 2023/07/21 10:41:03 192.168.2.100:53471 accepted tcp:91.108.56.142:443 [tproxy_tcp_inbound >> direct]
Fri Jul 21 10:41:03 2023 daemon.info xray[4458]: 2023/07/21 10:41:03 192.168.2.100:53481 accepted tcp:91.108.56.142:80 [tproxy_tcp_inbound >> direct]
ghggn commented 1 year ago

我详细看了下日志, 是任何IP都被匹配到了direct, 包括DNS解析请求 , 想不通, 我怀疑是不是我环境有问题 ?

yichya commented 1 year ago

我没看明白你具体做了啥,Custom Configurations 遵循 https://xtls.github.io/config/features/multiple.html 中的描述,你加的这个东西不会合并在任何地方

ghggn commented 1 year ago

抱歉 我上面写错了 我添加的配置是:

{
  "routing": {
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "tproxy_tcp_inbound",
          "tproxy_udp_inbound",
          "dns_conf_inbound",
          "https_inbound",
          "http_inbound"
        ],
        "outboundTag": "direct",
        "ip": [
          "geoip:cn"
        ]
      }
    ]
  }
}
yichya commented 1 year ago

抱歉 我上面写错了 我添加的配置是:

{
  "routing": {
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "tproxy_tcp_inbound",
          "tproxy_udp_inbound",
          "dns_conf_inbound",
          "https_inbound",
          "http_inbound"
        ],
        "outboundTag": "direct",
        "ip": [
          "geoip:cn"
        ]
      }
    ]
  }
}

如果你这样写的话你会把 luci-app-xray 已经生成的所有 routing 规则覆盖掉,只剩下这一个,满足这个规则的请求会转发到 direct 上,其他请求因为没有路由会默认选择第一个 outbound,然后 luci-app-xray 生成的配置中第一个 outbound 也是 direct,所以说

我详细看了下日志, 是任何IP都被匹配到了direct, 包括DNS解析请求 , 想不通, 我怀疑是不是我环境有问题 ?

确实就应该是这样的。

ghggn commented 1 year ago

感谢解答 我把默认配置的rules复制出来 添加自己的修改 这样确实可以使用了 我看官方文档里说 数组有一个内容时 会查找tag相同的进行替换(inbounds和outbounds) 我以为任何数组类型都有同样的逻辑

yichya commented 1 year ago

下个版本里面会额外准备一个必定走代理的 HTTP / Socks 入口。