Skip to content

Commit 9c63f44

Browse files
committed
Add MAC and hostname rule items
1 parent d14417d commit 9c63f44

27 files changed

Lines changed: 1089 additions & 5 deletions

adapter/inbound.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package adapter
22

33
import (
44
"context"
5+
"net"
56
"net/netip"
67
"time"
78

@@ -82,6 +83,8 @@ type InboundContext struct {
8283
SourceGeoIPCode string
8384
GeoIPCode string
8485
ProcessInfo *ConnectionOwner
86+
SourceMACAddress net.HardwareAddr
87+
SourceHostname string
8588
QueryType uint16
8689
FakeIP bool
8790

adapter/neighbor.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package adapter
2+
3+
import (
4+
"net"
5+
"net/netip"
6+
)
7+
8+
type NeighborResolver interface {
9+
LookupMAC(address netip.Addr) (net.HardwareAddr, bool)
10+
LookupHostname(address netip.Addr) (string, bool)
11+
Start() error
12+
Close() error
13+
}

adapter/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Router interface {
2626
RuleSet(tag string) (RuleSet, bool)
2727
Rules() []Rule
2828
NeedFindProcess() bool
29+
NeedFindNeighbor() bool
30+
NeighborResolver() NeighborResolver
2931
AppendTracker(tracker ConnectionTracker)
3032
ResetNetwork()
3133
}

docs/configuration/dns/rule.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
icon: material/alert-decagram
33
---
44

5+
!!! quote "Changes in sing-box 1.14.0"
6+
7+
:material-plus: [source_mac_address](#source_mac_address)
8+
:material-plus: [source_hostname](#source_hostname)
9+
510
!!! quote "Changes in sing-box 1.13.0"
611

712
:material-plus: [interface_address](#interface_address)
@@ -149,6 +154,12 @@ icon: material/alert-decagram
149154
"default_interface_address": [
150155
"2000::/3"
151156
],
157+
"source_mac_address": [
158+
"00:11:22:33:44:55"
159+
],
160+
"source_hostname": [
161+
"my-device"
162+
],
152163
"wifi_ssid": [
153164
"My WIFI"
154165
],
@@ -408,6 +419,26 @@ Matches network interface (same values as `network_type`) address.
408419

409420
Match default interface address.
410421

422+
#### source_mac_address
423+
424+
!!! question "Since sing-box 1.14.0"
425+
426+
!!! quote ""
427+
428+
Only supported on Linux with `route.find_neighbor` enabled.
429+
430+
Match source device MAC address.
431+
432+
#### source_hostname
433+
434+
!!! question "Since sing-box 1.14.0"
435+
436+
!!! quote ""
437+
438+
Only supported on Linux with `route.find_neighbor` enabled.
439+
440+
Match source device hostname from DHCP leases.
441+
411442
#### wifi_ssid
412443

413444
!!! quote ""

docs/configuration/dns/rule.zh.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
icon: material/alert-decagram
33
---
44

5+
!!! quote "sing-box 1.14.0 中的更改"
6+
7+
:material-plus: [source_mac_address](#source_mac_address)
8+
:material-plus: [source_hostname](#source_hostname)
9+
510
!!! quote "sing-box 1.13.0 中的更改"
611

712
:material-plus: [interface_address](#interface_address)
@@ -149,6 +154,12 @@ icon: material/alert-decagram
149154
"default_interface_address": [
150155
"2000::/3"
151156
],
157+
"source_mac_address": [
158+
"00:11:22:33:44:55"
159+
],
160+
"source_hostname": [
161+
"my-device"
162+
],
152163
"wifi_ssid": [
153164
"My WIFI"
154165
],
@@ -407,6 +418,26 @@ Available values: `wifi`, `cellular`, `ethernet` and `other`.
407418

408419
匹配默认接口地址。
409420

421+
#### source_mac_address
422+
423+
!!! question "自 sing-box 1.14.0 起"
424+
425+
!!! quote ""
426+
427+
仅支持 Linux,且需要 `route.find_neighbor` 已启用。
428+
429+
匹配源设备 MAC 地址。
430+
431+
#### source_hostname
432+
433+
!!! question "自 sing-box 1.14.0 起"
434+
435+
!!! quote ""
436+
437+
仅支持 Linux,且需要 `route.find_neighbor` 已启用。
438+
439+
匹配源设备从 DHCP 租约获取的主机名。
440+
410441
#### wifi_ssid
411442

412443
!!! quote ""

docs/configuration/inbound/tun.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
icon: material/new-box
33
---
44

5+
!!! quote "Changes in sing-box 1.14.0"
6+
7+
:material-plus: [include_mac_address](#include_mac_address)
8+
:material-plus: [exclude_mac_address](#exclude_mac_address)
9+
510
!!! quote "Changes in sing-box 1.13.0"
611

712
:material-plus: [auto_redirect_reset_mark](#auto_redirect_reset_mark)
@@ -125,6 +130,12 @@ icon: material/new-box
125130
"exclude_package": [
126131
"com.android.captiveportallogin"
127132
],
133+
"include_mac_address": [
134+
"00:11:22:33:44:55"
135+
],
136+
"exclude_mac_address": [
137+
"66:77:88:99:aa:bb"
138+
],
128139
"platform": {
129140
"http_proxy": {
130141
"enabled": false,
@@ -548,6 +559,30 @@ Limit android packages in route.
548559

549560
Exclude android packages in route.
550561

562+
#### include_mac_address
563+
564+
!!! question "Since sing-box 1.14.0"
565+
566+
!!! quote ""
567+
568+
Only supported on Linux with `auto_route` and `auto_redirect` enabled.
569+
570+
Limit MAC addresses in route. Not limited by default.
571+
572+
Conflict with `exclude_mac_address`.
573+
574+
#### exclude_mac_address
575+
576+
!!! question "Since sing-box 1.14.0"
577+
578+
!!! quote ""
579+
580+
Only supported on Linux with `auto_route` and `auto_redirect` enabled.
581+
582+
Exclude MAC addresses in route.
583+
584+
Conflict with `include_mac_address`.
585+
551586
#### platform
552587

553588
Platform-specific settings, provided by client applications.

docs/configuration/inbound/tun.zh.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
icon: material/new-box
33
---
44

5+
!!! quote "sing-box 1.14.0 中的更改"
6+
7+
:material-plus: [include_mac_address](#include_mac_address)
8+
:material-plus: [exclude_mac_address](#exclude_mac_address)
9+
510
!!! quote "sing-box 1.13.0 中的更改"
611

712
:material-plus: [auto_redirect_reset_mark](#auto_redirect_reset_mark)
@@ -126,6 +131,12 @@ icon: material/new-box
126131
"exclude_package": [
127132
"com.android.captiveportallogin"
128133
],
134+
"include_mac_address": [
135+
"00:11:22:33:44:55"
136+
],
137+
"exclude_mac_address": [
138+
"66:77:88:99:aa:bb"
139+
],
129140
"platform": {
130141
"http_proxy": {
131142
"enabled": false,
@@ -536,6 +547,30 @@ TCP/IP 栈。
536547

537548
排除路由的 Android 应用包名。
538549

550+
#### include_mac_address
551+
552+
!!! question "自 sing-box 1.14.0 起"
553+
554+
!!! quote ""
555+
556+
仅支持 Linux,且需要 `auto_route` 和 `auto_redirect` 已启用。
557+
558+
限制被路由的 MAC 地址。默认不限制。
559+
560+
`exclude_mac_address` 冲突。
561+
562+
#### exclude_mac_address
563+
564+
!!! question "自 sing-box 1.14.0 起"
565+
566+
!!! quote ""
567+
568+
仅支持 Linux,且需要 `auto_route` 和 `auto_redirect` 已启用。
569+
570+
排除路由的 MAC 地址。
571+
572+
`include_mac_address` 冲突。
573+
539574
#### platform
540575

541576
平台特定的设置,由客户端应用提供。

docs/configuration/route/index.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ icon: material/alert-decagram
44

55
# Route
66

7+
!!! quote "Changes in sing-box 1.14.0"
8+
9+
:material-plus: [find_neighbor](#find_neighbor)
10+
:material-plus: [dhcp_lease_files](#dhcp_lease_files)
11+
712
!!! quote "Changes in sing-box 1.12.0"
813

914
:material-plus: [default_domain_resolver](#default_domain_resolver)
@@ -35,6 +40,8 @@ icon: material/alert-decagram
3540
"override_android_vpn": false,
3641
"default_interface": "",
3742
"default_mark": 0,
43+
"find_neighbor": false,
44+
"dhcp_lease_files": [],
3845
"default_domain_resolver": "", // or {}
3946
"default_network_strategy": "",
4047
"default_network_type": [],
@@ -107,6 +114,30 @@ Set routing mark by default.
107114

108115
Takes no effect if `outbound.routing_mark` is set.
109116

117+
#### find_neighbor
118+
119+
!!! question "Since sing-box 1.14.0"
120+
121+
!!! quote ""
122+
123+
Only supported on Linux.
124+
125+
Enable neighbor resolution for source MAC address and hostname lookup.
126+
127+
Required for `source_mac_address` and `source_hostname` rule items.
128+
129+
#### dhcp_lease_files
130+
131+
!!! question "Since sing-box 1.14.0"
132+
133+
!!! quote ""
134+
135+
Only supported on Linux.
136+
137+
Custom DHCP lease file paths for hostname and MAC address resolution.
138+
139+
Automatically detected from common DHCP servers (dnsmasq, odhcpd, ISC dhcpd, Kea) if empty.
140+
110141
#### default_domain_resolver
111142

112143
!!! question "Since sing-box 1.12.0"

docs/configuration/route/index.zh.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ icon: material/alert-decagram
44

55
# 路由
66

7+
!!! quote "sing-box 1.14.0 中的更改"
8+
9+
:material-plus: [find_neighbor](#find_neighbor)
10+
:material-plus: [dhcp_lease_files](#dhcp_lease_files)
11+
712
!!! quote "sing-box 1.12.0 中的更改"
813

914
:material-plus: [default_domain_resolver](#default_domain_resolver)
@@ -37,6 +42,8 @@ icon: material/alert-decagram
3742
"override_android_vpn": false,
3843
"default_interface": "",
3944
"default_mark": 0,
45+
"find_neighbor": false,
46+
"dhcp_lease_files": [],
4047
"default_network_strategy": "",
4148
"default_fallback_delay": ""
4249
}
@@ -106,6 +113,30 @@ icon: material/alert-decagram
106113

107114
如果设置了 `outbound.routing_mark` 设置,则不生效。
108115

116+
#### find_neighbor
117+
118+
!!! question "自 sing-box 1.14.0 起"
119+
120+
!!! quote ""
121+
122+
仅支持 Linux。
123+
124+
启用邻居解析以查找源 MAC 地址和主机名。
125+
126+
`source_mac_address``source_hostname` 规则项需要此选项。
127+
128+
#### dhcp_lease_files
129+
130+
!!! question "自 sing-box 1.14.0 起"
131+
132+
!!! quote ""
133+
134+
仅支持 Linux。
135+
136+
用于主机名和 MAC 地址解析的自定义 DHCP 租约文件路径。
137+
138+
为空时自动从常见 DHCP 服务器(dnsmasq、odhcpd、ISC dhcpd、Kea)检测。
139+
109140
#### default_domain_resolver
110141

111142
!!! question "自 sing-box 1.12.0 起"

0 commit comments

Comments
 (0)