mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-14 00:51:12 +03:00
Add advertise tags support for Tailscale endpoint
This commit is contained in:
@@ -8,7 +8,8 @@ icon: material/new-box
|
|||||||
:material-plus: [relay_server_static_endpoints](#relay_server_static_endpoints)
|
:material-plus: [relay_server_static_endpoints](#relay_server_static_endpoints)
|
||||||
:material-plus: [system_interface](#system_interface)
|
:material-plus: [system_interface](#system_interface)
|
||||||
:material-plus: [system_interface_name](#system_interface_name)
|
:material-plus: [system_interface_name](#system_interface_name)
|
||||||
:material-plus: [system_interface_mtu](#system_interface_mtu)
|
:material-plus: [system_interface_mtu](#system_interface_mtu)
|
||||||
|
:material-plus: [advertise_tags](#advertise_tags)
|
||||||
|
|
||||||
!!! question "Since sing-box 1.12.0"
|
!!! question "Since sing-box 1.12.0"
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ icon: material/new-box
|
|||||||
"exit_node_allow_lan_access": false,
|
"exit_node_allow_lan_access": false,
|
||||||
"advertise_routes": [],
|
"advertise_routes": [],
|
||||||
"advertise_exit_node": false,
|
"advertise_exit_node": false,
|
||||||
|
"advertise_tags": [],
|
||||||
"relay_server_port": 0,
|
"relay_server_port": 0,
|
||||||
"relay_server_static_endpoints": [],
|
"relay_server_static_endpoints": [],
|
||||||
"system_interface": false,
|
"system_interface": false,
|
||||||
@@ -102,6 +104,14 @@ Example: `["192.168.1.1/24"]`
|
|||||||
|
|
||||||
Indicates whether the node should advertise itself as an exit node.
|
Indicates whether the node should advertise itself as an exit node.
|
||||||
|
|
||||||
|
#### advertise_tags
|
||||||
|
|
||||||
|
!!! question "Since sing-box 1.13.0"
|
||||||
|
|
||||||
|
Tags to advertise for this node, for ACL enforcement purposes.
|
||||||
|
|
||||||
|
Example: `["tag:server"]`
|
||||||
|
|
||||||
#### relay_server_port
|
#### relay_server_port
|
||||||
|
|
||||||
!!! question "Since sing-box 1.13.0"
|
!!! question "Since sing-box 1.13.0"
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ icon: material/new-box
|
|||||||
:material-plus: [relay_server_static_endpoints](#relay_server_static_endpoints)
|
:material-plus: [relay_server_static_endpoints](#relay_server_static_endpoints)
|
||||||
:material-plus: [system_interface](#system_interface)
|
:material-plus: [system_interface](#system_interface)
|
||||||
:material-plus: [system_interface_name](#system_interface_name)
|
:material-plus: [system_interface_name](#system_interface_name)
|
||||||
:material-plus: [system_interface_mtu](#system_interface_mtu)
|
:material-plus: [system_interface_mtu](#system_interface_mtu)
|
||||||
|
:material-plus: [advertise_tags](#advertise_tags)
|
||||||
|
|
||||||
!!! question "自 sing-box 1.12.0 起"
|
!!! question "自 sing-box 1.12.0 起"
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ icon: material/new-box
|
|||||||
"exit_node_allow_lan_access": false,
|
"exit_node_allow_lan_access": false,
|
||||||
"advertise_routes": [],
|
"advertise_routes": [],
|
||||||
"advertise_exit_node": false,
|
"advertise_exit_node": false,
|
||||||
|
"advertise_tags": [],
|
||||||
"relay_server_port": 0,
|
"relay_server_port": 0,
|
||||||
"relay_server_static_endpoints": [],
|
"relay_server_static_endpoints": [],
|
||||||
"system_interface": false,
|
"system_interface": false,
|
||||||
@@ -101,6 +103,14 @@ icon: material/new-box
|
|||||||
|
|
||||||
指示节点是否应将自己通告为出口节点。
|
指示节点是否应将自己通告为出口节点。
|
||||||
|
|
||||||
|
#### advertise_tags
|
||||||
|
|
||||||
|
!!! question "自 sing-box 1.13.0 起"
|
||||||
|
|
||||||
|
为此节点通告的标签,用于 ACL 执行。
|
||||||
|
|
||||||
|
示例:`["tag:server"]`
|
||||||
|
|
||||||
#### relay_server_port
|
#### relay_server_port
|
||||||
|
|
||||||
!!! question "自 sing-box 1.13.0 起"
|
!!! question "自 sing-box 1.13.0 起"
|
||||||
|
|||||||
@@ -12,22 +12,23 @@ import (
|
|||||||
|
|
||||||
type TailscaleEndpointOptions struct {
|
type TailscaleEndpointOptions struct {
|
||||||
DialerOptions
|
DialerOptions
|
||||||
StateDirectory string `json:"state_directory,omitempty"`
|
StateDirectory string `json:"state_directory,omitempty"`
|
||||||
AuthKey string `json:"auth_key,omitempty"`
|
AuthKey string `json:"auth_key,omitempty"`
|
||||||
ControlURL string `json:"control_url,omitempty"`
|
ControlURL string `json:"control_url,omitempty"`
|
||||||
Ephemeral bool `json:"ephemeral,omitempty"`
|
Ephemeral bool `json:"ephemeral,omitempty"`
|
||||||
Hostname string `json:"hostname,omitempty"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
AcceptRoutes bool `json:"accept_routes,omitempty"`
|
AcceptRoutes bool `json:"accept_routes,omitempty"`
|
||||||
ExitNode string `json:"exit_node,omitempty"`
|
ExitNode string `json:"exit_node,omitempty"`
|
||||||
ExitNodeAllowLANAccess bool `json:"exit_node_allow_lan_access,omitempty"`
|
ExitNodeAllowLANAccess bool `json:"exit_node_allow_lan_access,omitempty"`
|
||||||
AdvertiseRoutes []netip.Prefix `json:"advertise_routes,omitempty"`
|
AdvertiseRoutes []netip.Prefix `json:"advertise_routes,omitempty"`
|
||||||
AdvertiseExitNode bool `json:"advertise_exit_node,omitempty"`
|
AdvertiseExitNode bool `json:"advertise_exit_node,omitempty"`
|
||||||
RelayServerPort *uint16 `json:"relay_server_port,omitempty"`
|
AdvertiseTags badoption.Listable[string] `json:"advertise_tags,omitempty"`
|
||||||
RelayServerStaticEndpoints []netip.AddrPort `json:"relay_server_static_endpoints,omitempty"`
|
RelayServerPort *uint16 `json:"relay_server_port,omitempty"`
|
||||||
SystemInterface bool `json:"system_interface,omitempty"`
|
RelayServerStaticEndpoints []netip.AddrPort `json:"relay_server_static_endpoints,omitempty"`
|
||||||
SystemInterfaceName string `json:"system_interface_name,omitempty"`
|
SystemInterface bool `json:"system_interface,omitempty"`
|
||||||
SystemInterfaceMTU uint32 `json:"system_interface_mtu,omitempty"`
|
SystemInterfaceName string `json:"system_interface_name,omitempty"`
|
||||||
UDPTimeout UDPTimeoutCompat `json:"udp_timeout,omitempty"`
|
SystemInterfaceMTU uint32 `json:"system_interface_mtu,omitempty"`
|
||||||
|
UDPTimeout UDPTimeoutCompat `json:"udp_timeout,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TailscaleDNSServerOptions struct {
|
type TailscaleDNSServerOptions struct {
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ type Endpoint struct {
|
|||||||
exitNodeAllowLANAccess bool
|
exitNodeAllowLANAccess bool
|
||||||
advertiseRoutes []netip.Prefix
|
advertiseRoutes []netip.Prefix
|
||||||
advertiseExitNode bool
|
advertiseExitNode bool
|
||||||
|
advertiseTags []string
|
||||||
relayServerPort *uint16
|
relayServerPort *uint16
|
||||||
relayServerStaticEndpoints []netip.AddrPort
|
relayServerStaticEndpoints []netip.AddrPort
|
||||||
|
|
||||||
@@ -244,6 +245,7 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
|||||||
exitNodeAllowLANAccess: options.ExitNodeAllowLANAccess,
|
exitNodeAllowLANAccess: options.ExitNodeAllowLANAccess,
|
||||||
advertiseRoutes: options.AdvertiseRoutes,
|
advertiseRoutes: options.AdvertiseRoutes,
|
||||||
advertiseExitNode: options.AdvertiseExitNode,
|
advertiseExitNode: options.AdvertiseExitNode,
|
||||||
|
advertiseTags: options.AdvertiseTags,
|
||||||
relayServerPort: options.RelayServerPort,
|
relayServerPort: options.RelayServerPort,
|
||||||
relayServerStaticEndpoints: options.RelayServerStaticEndpoints,
|
relayServerStaticEndpoints: options.RelayServerStaticEndpoints,
|
||||||
udpTimeout: udpTimeout,
|
udpTimeout: udpTimeout,
|
||||||
@@ -359,25 +361,25 @@ func (t *Endpoint) Start(stage adapter.StartStage) error {
|
|||||||
localBackend := t.server.ExportLocalBackend()
|
localBackend := t.server.ExportLocalBackend()
|
||||||
perfs := &ipn.MaskedPrefs{
|
perfs := &ipn.MaskedPrefs{
|
||||||
Prefs: ipn.Prefs{
|
Prefs: ipn.Prefs{
|
||||||
RouteAll: t.acceptRoutes,
|
RouteAll: t.acceptRoutes,
|
||||||
|
AdvertiseRoutes: t.advertiseRoutes,
|
||||||
|
AdvertiseTags: t.advertiseTags,
|
||||||
},
|
},
|
||||||
RouteAllSet: true,
|
RouteAllSet: true,
|
||||||
ExitNodeIPSet: true,
|
ExitNodeIPSet: true,
|
||||||
AdvertiseRoutesSet: true,
|
AdvertiseRoutesSet: true,
|
||||||
}
|
AdvertiseTagsSet: true,
|
||||||
if len(t.advertiseRoutes) > 0 {
|
RelayServerPortSet: true,
|
||||||
perfs.AdvertiseRoutes = t.advertiseRoutes
|
RelayServerStaticEndpointsSet: true,
|
||||||
}
|
}
|
||||||
if t.advertiseExitNode {
|
if t.advertiseExitNode {
|
||||||
perfs.AdvertiseRoutes = append(perfs.AdvertiseRoutes, tsaddr.ExitRoutes()...)
|
perfs.AdvertiseRoutes = append(perfs.AdvertiseRoutes, tsaddr.ExitRoutes()...)
|
||||||
}
|
}
|
||||||
if t.relayServerPort != nil {
|
if t.relayServerPort != nil {
|
||||||
perfs.RelayServerPort = t.relayServerPort
|
perfs.RelayServerPort = t.relayServerPort
|
||||||
perfs.RelayServerPortSet = true
|
|
||||||
}
|
}
|
||||||
if len(t.relayServerStaticEndpoints) > 0 {
|
if len(t.relayServerStaticEndpoints) > 0 {
|
||||||
perfs.RelayServerStaticEndpoints = t.relayServerStaticEndpoints
|
perfs.RelayServerStaticEndpoints = t.relayServerStaticEndpoints
|
||||||
perfs.RelayServerStaticEndpointsSet = true
|
|
||||||
}
|
}
|
||||||
_, err = localBackend.EditPrefs(perfs)
|
_, err = localBackend.EditPrefs(perfs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user