sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

tun.include_interface generates empty iifname rules

Open TakaiSaisei opened this issue 9 months ago • 5 comments

Operating system

Linux

System version

OpenWrt 24.10

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.13.0-rc.4

Environment: go1.25.7 linux/arm64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,badlinkname,tfogo_checklinkname0,with_naive_outbound,with_musl
Revision: 804606042f75e593433db76cc43d31056823bbfc
CGO: enabled

Description

When using tun inbound with auto_route + auto_redirect, include_interface and exclude_interface works correctly if only one interface is specified, but generates invalid nftables rules when more than one interface is provided.

Reproduction

Configuration with a single interface:

{
  "type": "tun",
  "tag": "tun-in",
  "address": ["172.18.0.1/30", "fdfe:dcba:9876::1/126"],
  "include_interface": ["br-lan"],
  "auto_route": true,
  "strict_route": true,
  "auto_redirect": true,
  "stack": "system"
}

Generated nft rule:

root@OpenWrt:~# nft list chain inet sing-box prerouting
table inet sing-box {
	chain prerouting {
		...
		iifname != "br-lan" counter packets 0 bytes 0 return

Configuration with multiple interfaces:

{
  "type": "tun",
  "tag": "tun-in",
  "address": ["172.18.0.1/30", "fdfe:dcba:9876::1/126"],
  "include_interface": ["br-lan", "wg0"],
  "auto_route": true,
  "strict_route": true,
  "auto_redirect": true,
  "stack": "system"
}

Generated nft rule:

root@OpenWrt:~# nft list chain inet sing-box prerouting
table inet sing-box {
	chain prerouting {
		...
		iifname != { "", "" } counter packets 457 bytes 26768 return

Logs


Supporter

Integrity requirements

  • [x] 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.
  • [x] 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.
  • [x] 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.
  • [x] 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.

TakaiSaisei avatar Feb 17 '26 00:02 TakaiSaisei

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Apr 18 '26 02:04 github-actions[bot]

Still an issue on the latest version

TakaiSaisei avatar Apr 19 '26 21:04 TakaiSaisei

Could you check if this has been correctly fixed in the latest stable version?

nekohasekai avatar Aug 21 '26 05:08 nekohasekai

I checked this against the current latest stable release, v1.14.0.

This appears to be fixed.

The original behavior maps directly to the two different code paths in sing-tun:

  • a single include_interface / exclude_interface is emitted as a direct expr.Cmp;
  • multiple interfaces are emitted as an anonymous nftables TypeIFName set.

That explains why:

include_interface: ["br-lan"]

worked, while:

include_interface: ["br-lan", "wg0"]

produced:

iifname != { "", "" }

The relevant fix is in SagerNet/sing-tun:

e5d2fab03586e41fbcb0ca8c5ff4db18e5d3365e
Fix multi include/exclude interfaces

For both multi-interface sets, it changed the set definition from effectively:

&nftables.Set{
    Table:     table,
    Anonymous: true,
    Constant:  true,
    KeyType:   nftables.TypeIFName,
}

to:

&nftables.Set{
    Table:        table,
    Anonymous:    true,
    Constant:     true,
    KeyType:      nftables.TypeIFName,
    KeyByteOrder: binaryutil.NativeEndian,
}

for both IncludeInterface and ExcludeInterface.

The same commit also updates:

github.com/sagernet/nftables
v0.3.0-beta.4 -> v0.3.0-mod.2

So the bug was confined to the multi-interface nftables-set path; the one-interface path never used that set representation, which is consistent with the original reproducer.

I also checked whether this actually reached stable rather than only testing.

Current sing-box v1.14.0 depends on:

github.com/sagernet/sing-tun v0.9.0-beta.4

and sing-tun v0.9.0-beta.4 is a descendant of e5d2fab (59 commits ahead of that fix).

So the fix is included in the current upstream stable v1.14.0.

I have not rerun the OpenWrt reproducer, so this is source/history verification rather than a runtime test, but the fix is specifically targeted at the exact failing multi-interface code path reported here.

Based on that, I think #3805 can be considered fixed in v1.14.0.

HeisLuka avatar Sep 09 '26 22:09 HeisLuka

I use sing-box 1.11.15-1 in OpenWRT 23.05. It has the same issue.

kinchinfong avatar Nov 20 '26 12:11 kinchinfong