Adds optional per-node multiplexing and socket options, applied after
ParseShareLink at all three outbound build sites (group members, standalone
node targets, chain hops) and BEFORE withMark so the loop-guard escape mark
(255) is always re-asserted last and wins — a per-node mark that is neither 0
nor 255 is refused (would break the nft escape rule → routing loop).
- model.go: Node.{Mux,MuxConcurrency,XUDPConcurrency,XUDPProxyUDP443,Mark,
TCPFastOpen,TCPKeepAliveIdle}; uci.go parses them. All zero-value = off, so
existing nodes emit byte-identical outbounds.
- generate.go: applyNodeOpts() emits outbound-level `mux` (XUDP keys only for
vless/vmess) + streamSettings.sockopt tcp knobs; skips mux under XTLS Vision.
- nodes.js: modalonly mux/XUDP/sockopt fields (depends on mux).
- tests: node_opts_test.go (mux emitted/off, XUDP gating, vision skip,
loop-guard mark wins, tcp knobs).
Verified live on the 512M VM: mux node emits {enabled,concurrency:8,
xudpConcurrency:16,xudpProxyUDP443:reject}; sockopt.mark==255 preserved;
xray -test OK. r9.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
216 lines
5.2 KiB
Go
216 lines
5.2 KiB
Go
package main
|
|
|
|
// Data model for the xray control-plane. This is the parsed, typed form of the
|
|
// UCI desired-state (/etc/config/shater) plus subscription-cache nodes. Every
|
|
// generator/apply step consumes *Model; nothing downstream touches raw UCI.
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Model is the whole desired-state.
|
|
type Model struct {
|
|
Globals Globals
|
|
Inbounds []Inbound
|
|
Subscriptions []Subscription
|
|
Nodes []Node // manual nodes + subscription-cache nodes (see Node.FromSub)
|
|
Groups []Group
|
|
Chains []Chain
|
|
Egresses []Egress
|
|
Rulesets []Ruleset
|
|
Rules []Rule
|
|
Resolvers []Resolver
|
|
DNSRules []DNSRule
|
|
}
|
|
|
|
// Globals is the single `config globals` section.
|
|
type Globals struct {
|
|
Enabled bool
|
|
LogLevel string
|
|
KillSwitch string // closed|open
|
|
DNSMode string // nftset|fakeip
|
|
IPv6 bool
|
|
FwmarkBase uint32
|
|
TableBase uint32
|
|
ConfirmTimeout int
|
|
ResolverFallback string
|
|
ProbeURL string // observatory health-probe URL (default gstatic/generate_204)
|
|
ProbeInterval string // observatory probe interval (e.g. 60s)
|
|
}
|
|
|
|
func defaultGlobals() Globals {
|
|
return Globals{
|
|
Enabled: true,
|
|
LogLevel: "warning",
|
|
KillSwitch: "closed",
|
|
DNSMode: "nftset",
|
|
IPv6: true,
|
|
FwmarkBase: 0x2000,
|
|
TableBase: 0x2000,
|
|
}
|
|
}
|
|
|
|
// Inbound is a `config inbound` (multi-LAN tproxy entry).
|
|
type Inbound struct {
|
|
Name string
|
|
Enabled bool
|
|
Network string
|
|
TproxyPort int
|
|
TCP bool
|
|
UDP bool
|
|
Sniff bool
|
|
}
|
|
|
|
// Subscription is a `config subscription`.
|
|
type Subscription struct {
|
|
Name string
|
|
Enabled bool
|
|
URL string
|
|
UpdateInterval string
|
|
FetchVia string // direct|proxy
|
|
UA string
|
|
HWID string // auto|<fixed>
|
|
DeviceOS string
|
|
VerOS string
|
|
DeviceModel string
|
|
Headers []string // raw "Key: val"
|
|
}
|
|
|
|
// Node is a manual node (`config node`) or a subscription-cache node.
|
|
type Node struct {
|
|
Name string
|
|
Enabled bool
|
|
URI string
|
|
FromSub string // "" = manual; else subscription name
|
|
Fingerprint string
|
|
Stale bool
|
|
|
|
// Per-node multiplexing + sockopt (T1). All optional; zero values = off, so
|
|
// existing nodes emit byte-identical outbounds. See applyNodeOpts in generate.go.
|
|
Mux bool // enable outbound mux
|
|
MuxConcurrency int // streams per mux connection (xray `concurrency`)
|
|
XUDPConcurrency int // vless/vmess only (UDP-over-mux)
|
|
XUDPProxyUDP443 string // reject|allow|skip (vless/vmess only)
|
|
Mark uint32 // sockopt mark; 0 = use loop-guard 255 (a different value is refused)
|
|
TCPFastOpen string // "" inherit | "1" on | "0" off
|
|
TCPKeepAliveIdle int // seconds; 0 = omit
|
|
}
|
|
|
|
// Group is a `config group`.
|
|
type Group struct {
|
|
Name string
|
|
Source string // subscription|manual
|
|
Subscription string
|
|
Nodes []string // manual node names
|
|
Strategy string // leastping|random|roundrobin|failover|single
|
|
Include []string
|
|
Exclude []string
|
|
ProbeURL string
|
|
ProbeInterval string
|
|
}
|
|
|
|
// Chain is a `config chain` (multi-hop L1..Ln).
|
|
type Chain struct {
|
|
Name string
|
|
Hops []string // "group:<name>" | "node:<name>"
|
|
}
|
|
|
|
// Egress is a `config egress`.
|
|
type Egress struct {
|
|
Name string
|
|
Type string // interface|proxy|direct|block
|
|
Interface string
|
|
Target string
|
|
}
|
|
|
|
// Ruleset is a `config ruleset` (reusable domain/ip list).
|
|
type Ruleset struct {
|
|
Name string
|
|
Type string // domain|ipcidr
|
|
Source string // inline|file|url
|
|
URL string
|
|
Path string
|
|
Format string
|
|
UpdateInterval string
|
|
Entries []string
|
|
}
|
|
|
|
// Rule is a `config rule` (ordered, first-match).
|
|
type Rule struct {
|
|
Name string
|
|
Enabled bool
|
|
Order int
|
|
Src []string
|
|
DstDomain []string
|
|
DstRuleset []string
|
|
DstIP []string
|
|
DstPort string
|
|
Proto string
|
|
Target string // chain:|group:|node:|direct|block
|
|
Egress string
|
|
Kill string
|
|
}
|
|
|
|
// Resolver is a `config resolver`.
|
|
type Resolver struct {
|
|
Name string
|
|
Type string // doh|dot|plain|local|fakeip
|
|
Address string
|
|
Detour string
|
|
Pool string // fakeip CIDR pool (e.g. 198.18.0.0/15)
|
|
}
|
|
|
|
// DNSRule is a `config dns_rule`.
|
|
type DNSRule struct {
|
|
Order int
|
|
MatchDomain []string
|
|
MatchSrc []string
|
|
Resolver string
|
|
}
|
|
|
|
// --- small parse helpers shared across uci/sub ---
|
|
|
|
func parseBool(s string) bool {
|
|
switch strings.ToLower(strings.TrimSpace(s)) {
|
|
case "1", "true", "yes", "on", "enabled":
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func parseUint32(s string, def uint32) uint32 {
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
return def
|
|
}
|
|
base := 10
|
|
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
|
base = 16
|
|
s = s[2:]
|
|
}
|
|
v, err := strconv.ParseUint(s, base, 32)
|
|
if err != nil {
|
|
return def
|
|
}
|
|
return uint32(v)
|
|
}
|
|
|
|
func parseInt(s string, def int) int {
|
|
v, err := strconv.Atoi(strings.TrimSpace(s))
|
|
if err != nil {
|
|
return def
|
|
}
|
|
return v
|
|
}
|
|
|
|
// splitTarget splits "kind:name" into ("kind","name"); bare "direct"/"block"
|
|
// return (value, "").
|
|
func splitTarget(t string) (kind, name string) {
|
|
t = strings.TrimSpace(t)
|
|
if i := strings.IndexByte(t, ':'); i >= 0 {
|
|
return t[:i], t[i+1:]
|
|
}
|
|
return t, ""
|
|
}
|