mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 02:53:15 +08:00
chore: better config internal structure
This commit is contained in:
parent
53425bb9f2
commit
27bcb26ecd
@ -17,10 +17,18 @@ func SetTfo(open bool) {
|
|||||||
lc.DisableTFO = !open
|
lc.DisableTFO = !open
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Tfo() bool {
|
||||||
|
return !lc.DisableTFO
|
||||||
|
}
|
||||||
|
|
||||||
func SetMPTCP(open bool) {
|
func SetMPTCP(open bool) {
|
||||||
setMultiPathTCP(&lc.ListenConfig, open)
|
setMultiPathTCP(&lc.ListenConfig, open)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MPTCP() bool {
|
||||||
|
return getMultiPathTCP(&lc.ListenConfig)
|
||||||
|
}
|
||||||
|
|
||||||
func ListenContext(ctx context.Context, network, address string) (net.Listener, error) {
|
func ListenContext(ctx context.Context, network, address string) (net.Listener, error) {
|
||||||
return lc.Listen(ctx, network, address)
|
return lc.Listen(ctx, network, address)
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,7 @@ const multipathTCPAvailable = false
|
|||||||
|
|
||||||
func setMultiPathTCP(listenConfig *net.ListenConfig, open bool) {
|
func setMultiPathTCP(listenConfig *net.ListenConfig, open bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMultiPathTCP(listenConfig *net.ListenConfig) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -9,3 +9,7 @@ const multipathTCPAvailable = true
|
|||||||
func setMultiPathTCP(listenConfig *net.ListenConfig, open bool) {
|
func setMultiPathTCP(listenConfig *net.ListenConfig, open bool) {
|
||||||
listenConfig.SetMultipathTCP(open)
|
listenConfig.SetMultipathTCP(open)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMultiPathTCP(listenConfig *net.ListenConfig) bool {
|
||||||
|
return listenConfig.MultipathTCP()
|
||||||
|
}
|
||||||
|
493
config/config.go
493
config/config.go
@ -50,13 +50,12 @@ import (
|
|||||||
// General config
|
// General config
|
||||||
type General struct {
|
type General struct {
|
||||||
Inbound
|
Inbound
|
||||||
Controller
|
Mode T.TunnelMode `json:"mode"`
|
||||||
Mode T.TunnelMode `json:"mode"`
|
UnifiedDelay bool `json:"unified-delay"`
|
||||||
UnifiedDelay bool
|
|
||||||
LogLevel log.LogLevel `json:"log-level"`
|
LogLevel log.LogLevel `json:"log-level"`
|
||||||
IPv6 bool `json:"ipv6"`
|
IPv6 bool `json:"ipv6"`
|
||||||
Interface string `json:"interface-name"`
|
Interface string `json:"interface-name"`
|
||||||
RoutingMark int `json:"-"`
|
RoutingMark int `json:"routing-mark"`
|
||||||
GeoXUrl GeoXUrl `json:"geox-url"`
|
GeoXUrl GeoXUrl `json:"geox-url"`
|
||||||
GeoAutoUpdate bool `json:"geo-auto-update"`
|
GeoAutoUpdate bool `json:"geo-auto-update"`
|
||||||
GeoUpdateInterval int `json:"geo-update-interval"`
|
GeoUpdateInterval int `json:"geo-update-interval"`
|
||||||
@ -91,24 +90,48 @@ type Inbound struct {
|
|||||||
InboundMPTCP bool `json:"inbound-mptcp"`
|
InboundMPTCP bool `json:"inbound-mptcp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GeoXUrl config
|
||||||
|
type GeoXUrl struct {
|
||||||
|
GeoIp string `json:"geo-ip"`
|
||||||
|
Mmdb string `json:"mmdb"`
|
||||||
|
ASN string `json:"asn"`
|
||||||
|
GeoSite string `json:"geo-site"`
|
||||||
|
}
|
||||||
|
|
||||||
// Controller config
|
// Controller config
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
ExternalController string `json:"-"`
|
ExternalController string
|
||||||
ExternalControllerTLS string `json:"-"`
|
ExternalControllerTLS string
|
||||||
ExternalControllerUnix string `json:"-"`
|
ExternalControllerUnix string
|
||||||
ExternalUI string `json:"-"`
|
ExternalUI string
|
||||||
ExternalDohServer string `json:"-"`
|
ExternalDohServer string
|
||||||
Secret string `json:"-"`
|
Secret string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Experimental config
|
||||||
|
type Experimental struct {
|
||||||
|
Fingerprints []string
|
||||||
|
QUICGoDisableGSO bool
|
||||||
|
QUICGoDisableECN bool
|
||||||
|
IP4PEnable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPTables config
|
||||||
|
type IPTables struct {
|
||||||
|
Enable bool
|
||||||
|
InboundInterface string
|
||||||
|
Bypass []string
|
||||||
|
DnsRedirect bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NTP config
|
// NTP config
|
||||||
type NTP struct {
|
type NTP struct {
|
||||||
Enable bool `yaml:"enable"`
|
Enable bool
|
||||||
Server string `yaml:"server"`
|
Server string
|
||||||
Port int `yaml:"port"`
|
Port int
|
||||||
Interval int `yaml:"interval"`
|
Interval int
|
||||||
DialerProxy string `yaml:"dialer-proxy"`
|
DialerProxy string
|
||||||
WriteToSystem bool `yaml:"write-to-system"`
|
WriteToSystem bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNS config
|
// DNS config
|
||||||
@ -134,24 +157,11 @@ type DNS struct {
|
|||||||
|
|
||||||
// Profile config
|
// Profile config
|
||||||
type Profile struct {
|
type Profile struct {
|
||||||
StoreSelected bool `yaml:"store-selected"`
|
StoreSelected bool
|
||||||
StoreFakeIP bool `yaml:"store-fake-ip"`
|
StoreFakeIP bool
|
||||||
}
|
|
||||||
|
|
||||||
type TLS struct {
|
|
||||||
Certificate string `yaml:"certificate"`
|
|
||||||
PrivateKey string `yaml:"private-key"`
|
|
||||||
CustomTrustCert []string `yaml:"custom-certifactes"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// IPTables config
|
|
||||||
type IPTables struct {
|
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
|
||||||
InboundInterface string `yaml:"inbound-interface" json:"inbound-interface"`
|
|
||||||
Bypass []string `yaml:"bypass" json:"bypass"`
|
|
||||||
DnsRedirect bool `yaml:"dns-redirect" json:"dns-redirect"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sniffer config
|
||||||
type Sniffer struct {
|
type Sniffer struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
Sniffers map[snifferTypes.Type]SNIFF.SnifferConfig
|
Sniffers map[snifferTypes.Type]SNIFF.SnifferConfig
|
||||||
@ -161,21 +171,21 @@ type Sniffer struct {
|
|||||||
ParsePureIp bool
|
ParsePureIp bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Experimental config
|
// TLS config
|
||||||
type Experimental struct {
|
type TLS struct {
|
||||||
Fingerprints []string `yaml:"fingerprints"`
|
Certificate string
|
||||||
QUICGoDisableGSO bool `yaml:"quic-go-disable-gso"`
|
PrivateKey string
|
||||||
QUICGoDisableECN bool `yaml:"quic-go-disable-ecn"`
|
CustomTrustCert []string
|
||||||
IP4PEnable bool `yaml:"dialer-ip4p-convert"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is mihomo config manager
|
// Config is mihomo config manager
|
||||||
type Config struct {
|
type Config struct {
|
||||||
General *General
|
General *General
|
||||||
|
Controller *Controller
|
||||||
|
Experimental *Experimental
|
||||||
IPTables *IPTables
|
IPTables *IPTables
|
||||||
NTP *NTP
|
NTP *NTP
|
||||||
DNS *DNS
|
DNS *DNS
|
||||||
Experimental *Experimental
|
|
||||||
Hosts *trie.DomainTrie[resolver.HostValue]
|
Hosts *trie.DomainTrie[resolver.HostValue]
|
||||||
Profile *Profile
|
Profile *Profile
|
||||||
Rules []C.Rule
|
Rules []C.Rule
|
||||||
@ -190,15 +200,6 @@ type Config struct {
|
|||||||
TLS *TLS
|
TLS *TLS
|
||||||
}
|
}
|
||||||
|
|
||||||
type RawNTP struct {
|
|
||||||
Enable bool `yaml:"enable"`
|
|
||||||
Server string `yaml:"server"`
|
|
||||||
ServerPort int `yaml:"server-port"`
|
|
||||||
Interval int `yaml:"interval"`
|
|
||||||
DialerProxy string `yaml:"dialer-proxy"`
|
|
||||||
WriteToSystem bool `yaml:"write-to-system"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RawDNS struct {
|
type RawDNS struct {
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
PreferH3 bool `yaml:"prefer-h3" json:"prefer-h3"`
|
PreferH3 bool `yaml:"prefer-h3" json:"prefer-h3"`
|
||||||
@ -233,6 +234,15 @@ type RawClashForAndroid struct {
|
|||||||
UiSubtitlePattern string `yaml:"ui-subtitle-pattern" json:"ui-subtitle-pattern"`
|
UiSubtitlePattern string `yaml:"ui-subtitle-pattern" json:"ui-subtitle-pattern"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawNTP struct {
|
||||||
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
|
Server string `yaml:"server" json:"server"`
|
||||||
|
Port int `yaml:"port" json:"port"`
|
||||||
|
Interval int `yaml:"interval" json:"interval"`
|
||||||
|
DialerProxy string `yaml:"dialer-proxy" json:"dialer-proxy"`
|
||||||
|
WriteToSystem bool `yaml:"write-to-system" json:"write-to-system"`
|
||||||
|
}
|
||||||
|
|
||||||
type RawTun struct {
|
type RawTun struct {
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
Device string `yaml:"device" json:"device"`
|
Device string `yaml:"device" json:"device"`
|
||||||
@ -244,35 +254,35 @@ type RawTun struct {
|
|||||||
MTU uint32 `yaml:"mtu" json:"mtu,omitempty"`
|
MTU uint32 `yaml:"mtu" json:"mtu,omitempty"`
|
||||||
GSO bool `yaml:"gso" json:"gso,omitempty"`
|
GSO bool `yaml:"gso" json:"gso,omitempty"`
|
||||||
GSOMaxSize uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
GSOMaxSize uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
||||||
//Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4_address,omitempty"`
|
//Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
|
||||||
Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6_address,omitempty"`
|
Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
|
||||||
IPRoute2TableIndex int `yaml:"iproute2-table-index" json:"iproute2_table_index,omitempty"`
|
IPRoute2TableIndex int `yaml:"iproute2-table-index" json:"iproute2-table-index,omitempty"`
|
||||||
IPRoute2RuleIndex int `yaml:"iproute2-rule-index" json:"iproute2_rule_index,omitempty"`
|
IPRoute2RuleIndex int `yaml:"iproute2-rule-index" json:"iproute2-rule-index,omitempty"`
|
||||||
AutoRedirect bool `yaml:"auto-redirect" json:"auto_redirect,omitempty"`
|
AutoRedirect bool `yaml:"auto-redirect" json:"auto-redirect,omitempty"`
|
||||||
AutoRedirectInputMark uint32 `yaml:"auto-redirect-input-mark" json:"auto_redirect_input_mark,omitempty"`
|
AutoRedirectInputMark uint32 `yaml:"auto-redirect-input-mark" json:"auto-redirect-input-mark,omitempty"`
|
||||||
AutoRedirectOutputMark uint32 `yaml:"auto-redirect-output-mark" json:"auto_redirect_output_mark,omitempty"`
|
AutoRedirectOutputMark uint32 `yaml:"auto-redirect-output-mark" json:"auto-redirect-output-mark,omitempty"`
|
||||||
StrictRoute bool `yaml:"strict-route" json:"strict_route,omitempty"`
|
StrictRoute bool `yaml:"strict-route" json:"strict-route,omitempty"`
|
||||||
RouteAddress []netip.Prefix `yaml:"route-address" json:"route_address,omitempty"`
|
RouteAddress []netip.Prefix `yaml:"route-address" json:"route-address,omitempty"`
|
||||||
RouteAddressSet []string `yaml:"route-address-set" json:"route_address_set,omitempty"`
|
RouteAddressSet []string `yaml:"route-address-set" json:"route-address-set,omitempty"`
|
||||||
RouteExcludeAddress []netip.Prefix `yaml:"route-exclude-address" json:"route_exclude_address,omitempty"`
|
RouteExcludeAddress []netip.Prefix `yaml:"route-exclude-address" json:"route-exclude-address,omitempty"`
|
||||||
RouteExcludeAddressSet []string `yaml:"route-exclude-address-set" json:"route_exclude_address_set,omitempty"`
|
RouteExcludeAddressSet []string `yaml:"route-exclude-address-set" json:"route-exclude-address-set,omitempty"`
|
||||||
IncludeInterface []string `yaml:"include-interface" json:"include-interface,omitempty"`
|
IncludeInterface []string `yaml:"include-interface" json:"include-interface,omitempty"`
|
||||||
ExcludeInterface []string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
ExcludeInterface []string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
||||||
IncludeUID []uint32 `yaml:"include-uid" json:"include_uid,omitempty"`
|
IncludeUID []uint32 `yaml:"include-uid" json:"include-uid,omitempty"`
|
||||||
IncludeUIDRange []string `yaml:"include-uid-range" json:"include_uid_range,omitempty"`
|
IncludeUIDRange []string `yaml:"include-uid-range" json:"include-uid-range,omitempty"`
|
||||||
ExcludeUID []uint32 `yaml:"exclude-uid" json:"exclude_uid,omitempty"`
|
ExcludeUID []uint32 `yaml:"exclude-uid" json:"exclude-uid,omitempty"`
|
||||||
ExcludeUIDRange []string `yaml:"exclude-uid-range" json:"exclude_uid_range,omitempty"`
|
ExcludeUIDRange []string `yaml:"exclude-uid-range" json:"exclude-uid-range,omitempty"`
|
||||||
IncludeAndroidUser []int `yaml:"include-android-user" json:"include_android_user,omitempty"`
|
IncludeAndroidUser []int `yaml:"include-android-user" json:"include-android-user,omitempty"`
|
||||||
IncludePackage []string `yaml:"include-package" json:"include_package,omitempty"`
|
IncludePackage []string `yaml:"include-package" json:"include-package,omitempty"`
|
||||||
ExcludePackage []string `yaml:"exclude-package" json:"exclude_package,omitempty"`
|
ExcludePackage []string `yaml:"exclude-package" json:"exclude-package,omitempty"`
|
||||||
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"`
|
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"`
|
||||||
UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"`
|
UDPTimeout int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
|
||||||
FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
|
FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
|
||||||
|
|
||||||
Inet4RouteAddress []netip.Prefix `yaml:"inet4-route-address" json:"inet4_route_address,omitempty"`
|
Inet4RouteAddress []netip.Prefix `yaml:"inet4-route-address" json:"inet4-route-address,omitempty"`
|
||||||
Inet6RouteAddress []netip.Prefix `yaml:"inet6-route-address" json:"inet6_route_address,omitempty"`
|
Inet6RouteAddress []netip.Prefix `yaml:"inet6-route-address" json:"inet6-route-address,omitempty"`
|
||||||
Inet4RouteExcludeAddress []netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4_route_exclude_address,omitempty"`
|
Inet4RouteExcludeAddress []netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4-route-exclude-address,omitempty"`
|
||||||
Inet6RouteExcludeAddress []netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6_route_exclude_address,omitempty"`
|
Inet6RouteExcludeAddress []netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6-route-exclude-address,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RawTuicServer struct {
|
type RawTuicServer struct {
|
||||||
@ -290,6 +300,55 @@ type RawTuicServer struct {
|
|||||||
CWND int `yaml:"cwnd" json:"cwnd,omitempty"`
|
CWND int `yaml:"cwnd" json:"cwnd,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawIPTables struct {
|
||||||
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
|
InboundInterface string `yaml:"inbound-interface" json:"inbound-interface"`
|
||||||
|
Bypass []string `yaml:"bypass" json:"bypass"`
|
||||||
|
DnsRedirect bool `yaml:"dns-redirect" json:"dns-redirect"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawExperimental struct {
|
||||||
|
Fingerprints []string `yaml:"fingerprints"`
|
||||||
|
QUICGoDisableGSO bool `yaml:"quic-go-disable-gso"`
|
||||||
|
QUICGoDisableECN bool `yaml:"quic-go-disable-ecn"`
|
||||||
|
IP4PEnable bool `yaml:"dialer-ip4p-convert"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawProfile struct {
|
||||||
|
StoreSelected bool `yaml:"store-selected" json:"store-selected"`
|
||||||
|
StoreFakeIP bool `yaml:"store-fake-ip" json:"store-fake-ip"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawGeoXUrl struct {
|
||||||
|
GeoIp string `yaml:"geoip" json:"geoip"`
|
||||||
|
Mmdb string `yaml:"mmdb" json:"mmdb"`
|
||||||
|
ASN string `yaml:"asn" json:"asn"`
|
||||||
|
GeoSite string `yaml:"geosite" json:"geosite"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawSniffer struct {
|
||||||
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
|
OverrideDest bool `yaml:"override-destination" json:"override-destination"`
|
||||||
|
Sniffing []string `yaml:"sniffing" json:"sniffing"`
|
||||||
|
ForceDomain []string `yaml:"force-domain" json:"force-domain"`
|
||||||
|
SkipDomain []string `yaml:"skip-domain" json:"skip-domain"`
|
||||||
|
Ports []string `yaml:"port-whitelist" json:"port-whitelist"`
|
||||||
|
ForceDnsMapping bool `yaml:"force-dns-mapping" json:"force-dns-mapping"`
|
||||||
|
ParsePureIp bool `yaml:"parse-pure-ip" json:"parse-pure-ip"`
|
||||||
|
Sniff map[string]RawSniffingConfig `yaml:"sniff" json:"sniff"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawSniffingConfig struct {
|
||||||
|
Ports []string `yaml:"ports" json:"ports"`
|
||||||
|
OverrideDest *bool `yaml:"override-destination" json:"override-destination"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawTLS struct {
|
||||||
|
Certificate string `yaml:"certificate" json:"certificate"`
|
||||||
|
PrivateKey string `yaml:"private-key" json:"private-key"`
|
||||||
|
CustomTrustCert []string `yaml:"custom-certifactes" json:"custom-certifactes"`
|
||||||
|
}
|
||||||
|
|
||||||
type RawConfig struct {
|
type RawConfig struct {
|
||||||
Port int `yaml:"port" json:"port"`
|
Port int `yaml:"port" json:"port"`
|
||||||
SocksPort int `yaml:"socks-port" json:"socks-port"`
|
SocksPort int `yaml:"socks-port" json:"socks-port"`
|
||||||
@ -301,9 +360,9 @@ type RawConfig struct {
|
|||||||
InboundTfo bool `yaml:"inbound-tfo" json:"inbound-tfo"`
|
InboundTfo bool `yaml:"inbound-tfo" json:"inbound-tfo"`
|
||||||
InboundMPTCP bool `yaml:"inbound-mptcp" json:"inbound-mptcp"`
|
InboundMPTCP bool `yaml:"inbound-mptcp" json:"inbound-mptcp"`
|
||||||
Authentication []string `yaml:"authentication" json:"authentication"`
|
Authentication []string `yaml:"authentication" json:"authentication"`
|
||||||
SkipAuthPrefixes []netip.Prefix `yaml:"skip-auth-prefixes"`
|
SkipAuthPrefixes []netip.Prefix `yaml:"skip-auth-prefixes" json:"skip-auth-prefixes"`
|
||||||
LanAllowedIPs []netip.Prefix `yaml:"lan-allowed-ips"`
|
LanAllowedIPs []netip.Prefix `yaml:"lan-allowed-ips" json:"lan-allowed-ips"`
|
||||||
LanDisAllowedIPs []netip.Prefix `yaml:"lan-disallowed-ips"`
|
LanDisAllowedIPs []netip.Prefix `yaml:"lan-disallowed-ips" json:"lan-disallowed-ips"`
|
||||||
AllowLan bool `yaml:"allow-lan" json:"allow-lan"`
|
AllowLan bool `yaml:"allow-lan" json:"allow-lan"`
|
||||||
BindAddress string `yaml:"bind-address" json:"bind-address"`
|
BindAddress string `yaml:"bind-address" json:"bind-address"`
|
||||||
Mode T.TunnelMode `yaml:"mode" json:"mode"`
|
Mode T.TunnelMode `yaml:"mode" json:"mode"`
|
||||||
@ -334,52 +393,28 @@ type RawConfig struct {
|
|||||||
KeepAliveInterval int `yaml:"keep-alive-interval" json:"keep-alive-interval"`
|
KeepAliveInterval int `yaml:"keep-alive-interval" json:"keep-alive-interval"`
|
||||||
DisableKeepAlive bool `yaml:"disable-keep-alive" json:"disable-keep-alive"`
|
DisableKeepAlive bool `yaml:"disable-keep-alive" json:"disable-keep-alive"`
|
||||||
|
|
||||||
Sniffer RawSniffer `yaml:"sniffer" json:"sniffer"`
|
ProxyProvider map[string]map[string]any `yaml:"proxy-providers" json:"proxy-providers"`
|
||||||
ProxyProvider map[string]map[string]any `yaml:"proxy-providers"`
|
RuleProvider map[string]map[string]any `yaml:"rule-providers" json:"rule-providers"`
|
||||||
RuleProvider map[string]map[string]any `yaml:"rule-providers"`
|
Proxy []map[string]any `yaml:"proxies" json:"proxies"`
|
||||||
|
ProxyGroup []map[string]any `yaml:"proxy-groups" json:"proxy-groups"`
|
||||||
|
Rule []string `yaml:"rules" json:"rule"`
|
||||||
|
SubRules map[string][]string `yaml:"sub-rules" json:"sub-rules"`
|
||||||
|
Listeners []map[string]any `yaml:"listeners" json:"listeners"`
|
||||||
Hosts map[string]any `yaml:"hosts" json:"hosts"`
|
Hosts map[string]any `yaml:"hosts" json:"hosts"`
|
||||||
NTP RawNTP `yaml:"ntp" json:"ntp"`
|
|
||||||
DNS RawDNS `yaml:"dns" json:"dns"`
|
DNS RawDNS `yaml:"dns" json:"dns"`
|
||||||
Tun RawTun `yaml:"tun"`
|
NTP RawNTP `yaml:"ntp" json:"ntp"`
|
||||||
TuicServer RawTuicServer `yaml:"tuic-server"`
|
Tun RawTun `yaml:"tun" json:"tun"`
|
||||||
IPTables IPTables `yaml:"iptables"`
|
TuicServer RawTuicServer `yaml:"tuic-server" json:"tuic-server"`
|
||||||
Experimental Experimental `yaml:"experimental"`
|
IPTables RawIPTables `yaml:"iptables" json:"iptables"`
|
||||||
Profile Profile `yaml:"profile"`
|
Experimental RawExperimental `yaml:"experimental" json:"experimental"`
|
||||||
GeoXUrl GeoXUrl `yaml:"geox-url"`
|
Profile RawProfile `yaml:"profile" json:"profile"`
|
||||||
Proxy []map[string]any `yaml:"proxies"`
|
GeoXUrl RawGeoXUrl `yaml:"geox-url" json:"geox-url"`
|
||||||
ProxyGroup []map[string]any `yaml:"proxy-groups"`
|
Sniffer RawSniffer `yaml:"sniffer" json:"sniffer"`
|
||||||
Rule []string `yaml:"rules"`
|
TLS RawTLS `yaml:"tls" json:"tls"`
|
||||||
SubRules map[string][]string `yaml:"sub-rules"`
|
|
||||||
RawTLS TLS `yaml:"tls"`
|
|
||||||
Listeners []map[string]any `yaml:"listeners"`
|
|
||||||
|
|
||||||
ClashForAndroid RawClashForAndroid `yaml:"clash-for-android" json:"clash-for-android"`
|
ClashForAndroid RawClashForAndroid `yaml:"clash-for-android" json:"clash-for-android"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GeoXUrl struct {
|
|
||||||
GeoIp string `yaml:"geoip" json:"geoip"`
|
|
||||||
Mmdb string `yaml:"mmdb" json:"mmdb"`
|
|
||||||
ASN string `yaml:"asn" json:"asn"`
|
|
||||||
GeoSite string `yaml:"geosite" json:"geosite"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RawSniffer struct {
|
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
|
||||||
OverrideDest bool `yaml:"override-destination" json:"override-destination"`
|
|
||||||
Sniffing []string `yaml:"sniffing" json:"sniffing"`
|
|
||||||
ForceDomain []string `yaml:"force-domain" json:"force-domain"`
|
|
||||||
SkipDomain []string `yaml:"skip-domain" json:"skip-domain"`
|
|
||||||
Ports []string `yaml:"port-whitelist" json:"port-whitelist"`
|
|
||||||
ForceDnsMapping bool `yaml:"force-dns-mapping" json:"force-dns-mapping"`
|
|
||||||
ParsePureIp bool `yaml:"parse-pure-ip" json:"parse-pure-ip"`
|
|
||||||
Sniff map[string]RawSniffingConfig `yaml:"sniff" json:"sniff"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RawSniffingConfig struct {
|
|
||||||
Ports []string `yaml:"ports" json:"ports"`
|
|
||||||
OverrideDest *bool `yaml:"override-destination" json:"override-destination"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GroupsList = list.New()
|
GroupsList = list.New()
|
||||||
ProxiesList = list.New()
|
ProxiesList = list.New()
|
||||||
@ -418,41 +453,6 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||||||
TCPConcurrent: false,
|
TCPConcurrent: false,
|
||||||
FindProcessMode: P.FindProcessStrict,
|
FindProcessMode: P.FindProcessStrict,
|
||||||
GlobalUA: "clash.meta/" + C.Version,
|
GlobalUA: "clash.meta/" + C.Version,
|
||||||
Tun: RawTun{
|
|
||||||
Enable: false,
|
|
||||||
Device: "",
|
|
||||||
Stack: C.TunGvisor,
|
|
||||||
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
|
||||||
AutoRoute: true,
|
|
||||||
AutoDetectInterface: true,
|
|
||||||
Inet6Address: []netip.Prefix{netip.MustParsePrefix("fdfe:dcba:9876::1/126")},
|
|
||||||
},
|
|
||||||
TuicServer: RawTuicServer{
|
|
||||||
Enable: false,
|
|
||||||
Token: nil,
|
|
||||||
Users: nil,
|
|
||||||
Certificate: "",
|
|
||||||
PrivateKey: "",
|
|
||||||
Listen: "",
|
|
||||||
CongestionController: "",
|
|
||||||
MaxIdleTime: 15000,
|
|
||||||
AuthenticationTimeout: 1000,
|
|
||||||
ALPN: []string{"h3"},
|
|
||||||
MaxUdpRelayPacketSize: 1500,
|
|
||||||
},
|
|
||||||
IPTables: IPTables{
|
|
||||||
Enable: false,
|
|
||||||
InboundInterface: "lo",
|
|
||||||
Bypass: []string{},
|
|
||||||
DnsRedirect: true,
|
|
||||||
},
|
|
||||||
NTP: RawNTP{
|
|
||||||
Enable: false,
|
|
||||||
WriteToSystem: false,
|
|
||||||
Server: "time.apple.com",
|
|
||||||
ServerPort: 123,
|
|
||||||
Interval: 30,
|
|
||||||
},
|
|
||||||
DNS: RawDNS{
|
DNS: RawDNS{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
IPv6: false,
|
IPv6: false,
|
||||||
@ -483,11 +483,55 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||||||
"www.msftconnecttest.com",
|
"www.msftconnecttest.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Experimental: Experimental{
|
NTP: RawNTP{
|
||||||
|
Enable: false,
|
||||||
|
WriteToSystem: false,
|
||||||
|
Server: "time.apple.com",
|
||||||
|
Port: 123,
|
||||||
|
Interval: 30,
|
||||||
|
},
|
||||||
|
Tun: RawTun{
|
||||||
|
Enable: false,
|
||||||
|
Device: "",
|
||||||
|
Stack: C.TunGvisor,
|
||||||
|
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
||||||
|
AutoRoute: true,
|
||||||
|
AutoDetectInterface: true,
|
||||||
|
Inet6Address: []netip.Prefix{netip.MustParsePrefix("fdfe:dcba:9876::1/126")},
|
||||||
|
},
|
||||||
|
TuicServer: RawTuicServer{
|
||||||
|
Enable: false,
|
||||||
|
Token: nil,
|
||||||
|
Users: nil,
|
||||||
|
Certificate: "",
|
||||||
|
PrivateKey: "",
|
||||||
|
Listen: "",
|
||||||
|
CongestionController: "",
|
||||||
|
MaxIdleTime: 15000,
|
||||||
|
AuthenticationTimeout: 1000,
|
||||||
|
ALPN: []string{"h3"},
|
||||||
|
MaxUdpRelayPacketSize: 1500,
|
||||||
|
},
|
||||||
|
IPTables: RawIPTables{
|
||||||
|
Enable: false,
|
||||||
|
InboundInterface: "lo",
|
||||||
|
Bypass: []string{},
|
||||||
|
DnsRedirect: true,
|
||||||
|
},
|
||||||
|
Experimental: RawExperimental{
|
||||||
// https://github.com/quic-go/quic-go/issues/4178
|
// https://github.com/quic-go/quic-go/issues/4178
|
||||||
// Quic-go currently cannot automatically fall back on platforms that do not support ecn, so this feature is turned off by default.
|
// Quic-go currently cannot automatically fall back on platforms that do not support ecn, so this feature is turned off by default.
|
||||||
QUICGoDisableECN: true,
|
QUICGoDisableECN: true,
|
||||||
},
|
},
|
||||||
|
Profile: RawProfile{
|
||||||
|
StoreSelected: true,
|
||||||
|
},
|
||||||
|
GeoXUrl: RawGeoXUrl{
|
||||||
|
Mmdb: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb",
|
||||||
|
ASN: "https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb",
|
||||||
|
GeoIp: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat",
|
||||||
|
GeoSite: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat",
|
||||||
|
},
|
||||||
Sniffer: RawSniffer{
|
Sniffer: RawSniffer{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
Sniff: map[string]RawSniffingConfig{},
|
Sniff: map[string]RawSniffingConfig{},
|
||||||
@ -498,15 +542,6 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||||||
ParsePureIp: true,
|
ParsePureIp: true,
|
||||||
OverrideDest: true,
|
OverrideDest: true,
|
||||||
},
|
},
|
||||||
Profile: Profile{
|
|
||||||
StoreSelected: true,
|
|
||||||
},
|
|
||||||
GeoXUrl: GeoXUrl{
|
|
||||||
Mmdb: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb",
|
|
||||||
ASN: "https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb",
|
|
||||||
GeoIp: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat",
|
|
||||||
GeoSite: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat",
|
|
||||||
},
|
|
||||||
ExternalUIURL: "https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip",
|
ExternalUIURL: "https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,10 +556,6 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||||||
config := &Config{}
|
config := &Config{}
|
||||||
log.Infoln("Start initial configuration in progress") //Segment finished in xxm
|
log.Infoln("Start initial configuration in progress") //Segment finished in xxm
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
config.Experimental = &rawCfg.Experimental
|
|
||||||
config.Profile = &rawCfg.Profile
|
|
||||||
config.IPTables = &rawCfg.IPTables
|
|
||||||
config.TLS = &rawCfg.RawTLS
|
|
||||||
|
|
||||||
general, err := parseGeneral(rawCfg)
|
general, err := parseGeneral(rawCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -537,6 +568,42 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||||||
tlsC.SetGlobalUtlsClient(config.General.GlobalClientFingerprint)
|
tlsC.SetGlobalUtlsClient(config.General.GlobalClientFingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controller, err := parseController(rawCfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Controller = controller
|
||||||
|
|
||||||
|
experimental, err := parseExperimental(rawCfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Experimental = experimental
|
||||||
|
|
||||||
|
iptables, err := parseIPTables(rawCfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.IPTables = iptables
|
||||||
|
|
||||||
|
ntpCfg, err := parseNTP(rawCfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.NTP = ntpCfg
|
||||||
|
|
||||||
|
profile, err := parseProfile(rawCfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Profile = profile
|
||||||
|
|
||||||
|
tlsCfg, err := parseTLS(rawCfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.TLS = tlsCfg
|
||||||
|
|
||||||
proxies, providers, err := parseProxies(rawCfg)
|
proxies, providers, err := parseProxies(rawCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -576,9 +643,6 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||||||
}
|
}
|
||||||
config.Hosts = hosts
|
config.Hosts = hosts
|
||||||
|
|
||||||
ntpCfg := paresNTP(rawCfg)
|
|
||||||
config.NTP = ntpCfg
|
|
||||||
|
|
||||||
dnsCfg, err := parseDNS(rawCfg, hosts, rules, ruleProviders)
|
dnsCfg, err := parseDNS(rawCfg, hosts, rules, ruleProviders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -687,21 +751,18 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
|||||||
InboundTfo: cfg.InboundTfo,
|
InboundTfo: cfg.InboundTfo,
|
||||||
InboundMPTCP: cfg.InboundMPTCP,
|
InboundMPTCP: cfg.InboundMPTCP,
|
||||||
},
|
},
|
||||||
Controller: Controller{
|
UnifiedDelay: cfg.UnifiedDelay,
|
||||||
ExternalController: cfg.ExternalController,
|
Mode: cfg.Mode,
|
||||||
ExternalUI: cfg.ExternalUI,
|
LogLevel: cfg.LogLevel,
|
||||||
Secret: cfg.Secret,
|
IPv6: cfg.IPv6,
|
||||||
ExternalControllerUnix: cfg.ExternalControllerUnix,
|
Interface: cfg.Interface,
|
||||||
ExternalControllerTLS: cfg.ExternalControllerTLS,
|
RoutingMark: cfg.RoutingMark,
|
||||||
ExternalDohServer: cfg.ExternalDohServer,
|
GeoXUrl: GeoXUrl{
|
||||||
|
GeoIp: cfg.GeoXUrl.GeoIp,
|
||||||
|
Mmdb: cfg.GeoXUrl.Mmdb,
|
||||||
|
ASN: cfg.GeoXUrl.ASN,
|
||||||
|
GeoSite: cfg.GeoXUrl.GeoSite,
|
||||||
},
|
},
|
||||||
UnifiedDelay: cfg.UnifiedDelay,
|
|
||||||
Mode: cfg.Mode,
|
|
||||||
LogLevel: cfg.LogLevel,
|
|
||||||
IPv6: cfg.IPv6,
|
|
||||||
Interface: cfg.Interface,
|
|
||||||
RoutingMark: cfg.RoutingMark,
|
|
||||||
GeoXUrl: cfg.GeoXUrl,
|
|
||||||
GeoAutoUpdate: cfg.GeoAutoUpdate,
|
GeoAutoUpdate: cfg.GeoAutoUpdate,
|
||||||
GeoUpdateInterval: cfg.GeoUpdateInterval,
|
GeoUpdateInterval: cfg.GeoUpdateInterval,
|
||||||
GeodataMode: cfg.GeodataMode,
|
GeodataMode: cfg.GeodataMode,
|
||||||
@ -713,6 +774,61 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseController(cfg *RawConfig) (*Controller, error) {
|
||||||
|
return &Controller{
|
||||||
|
ExternalController: cfg.ExternalController,
|
||||||
|
ExternalUI: cfg.ExternalUI,
|
||||||
|
Secret: cfg.Secret,
|
||||||
|
ExternalControllerUnix: cfg.ExternalControllerUnix,
|
||||||
|
ExternalControllerTLS: cfg.ExternalControllerTLS,
|
||||||
|
ExternalDohServer: cfg.ExternalDohServer,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseExperimental(cfg *RawConfig) (*Experimental, error) {
|
||||||
|
return &Experimental{
|
||||||
|
Fingerprints: cfg.Experimental.Fingerprints,
|
||||||
|
QUICGoDisableGSO: cfg.Experimental.QUICGoDisableGSO,
|
||||||
|
QUICGoDisableECN: cfg.Experimental.QUICGoDisableECN,
|
||||||
|
IP4PEnable: cfg.Experimental.IP4PEnable,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseIPTables(cfg *RawConfig) (*IPTables, error) {
|
||||||
|
return &IPTables{
|
||||||
|
Enable: cfg.IPTables.Enable,
|
||||||
|
InboundInterface: cfg.IPTables.InboundInterface,
|
||||||
|
Bypass: cfg.IPTables.Bypass,
|
||||||
|
DnsRedirect: cfg.IPTables.DnsRedirect,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNTP(cfg *RawConfig) (*NTP, error) {
|
||||||
|
return &NTP{
|
||||||
|
Enable: cfg.NTP.Enable,
|
||||||
|
Server: cfg.NTP.Server,
|
||||||
|
Port: cfg.NTP.Port,
|
||||||
|
Interval: cfg.NTP.Interval,
|
||||||
|
DialerProxy: cfg.NTP.DialerProxy,
|
||||||
|
WriteToSystem: cfg.NTP.WriteToSystem,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseProfile(cfg *RawConfig) (*Profile, error) {
|
||||||
|
return &Profile{
|
||||||
|
StoreSelected: cfg.Profile.StoreSelected,
|
||||||
|
StoreFakeIP: cfg.Profile.StoreFakeIP,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseTLS(cfg *RawConfig) (*TLS, error) {
|
||||||
|
return &TLS{
|
||||||
|
Certificate: cfg.TLS.Certificate,
|
||||||
|
PrivateKey: cfg.TLS.PrivateKey,
|
||||||
|
CustomTrustCert: cfg.TLS.CustomTrustCert,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[string]providerTypes.ProxyProvider, err error) {
|
func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[string]providerTypes.ProxyProvider, err error) {
|
||||||
proxies = make(map[string]C.Proxy)
|
proxies = make(map[string]C.Proxy)
|
||||||
providersMap = make(map[string]providerTypes.ProxyProvider)
|
providersMap = make(map[string]providerTypes.ProxyProvider)
|
||||||
@ -1259,19 +1375,6 @@ func parseNameServerPolicy(nsPolicy *orderedmap.OrderedMap[string, any], rules [
|
|||||||
return policy, nil
|
return policy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func paresNTP(rawCfg *RawConfig) *NTP {
|
|
||||||
cfg := rawCfg.NTP
|
|
||||||
ntpCfg := &NTP{
|
|
||||||
Enable: cfg.Enable,
|
|
||||||
Server: cfg.Server,
|
|
||||||
Port: cfg.ServerPort,
|
|
||||||
Interval: cfg.Interval,
|
|
||||||
DialerProxy: cfg.DialerProxy,
|
|
||||||
WriteToSystem: cfg.WriteToSystem,
|
|
||||||
}
|
|
||||||
return ntpCfg
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[resolver.HostValue], rules []C.Rule, ruleProviders map[string]providerTypes.RuleProvider) (*DNS, error) {
|
func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[resolver.HostValue], rules []C.Rule, ruleProviders map[string]providerTypes.RuleProvider) (*DNS, error) {
|
||||||
cfg := rawCfg.DNS
|
cfg := rawCfg.DNS
|
||||||
if cfg.Enable && len(cfg.NameServer) == 0 {
|
if cfg.Enable && len(cfg.NameServer) == 0 {
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/metacubex/mihomo/component/profile/cachefile"
|
"github.com/metacubex/mihomo/component/profile/cachefile"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
SNI "github.com/metacubex/mihomo/component/sniffer"
|
SNI "github.com/metacubex/mihomo/component/sniffer"
|
||||||
|
tlsC "github.com/metacubex/mihomo/component/tls"
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
"github.com/metacubex/mihomo/component/updater"
|
"github.com/metacubex/mihomo/component/updater"
|
||||||
"github.com/metacubex/mihomo/config"
|
"github.com/metacubex/mihomo/config"
|
||||||
@ -90,7 +91,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateExperimental(cfg)
|
updateExperimental(cfg.Experimental)
|
||||||
updateUsers(cfg.Users)
|
updateUsers(cfg.Users)
|
||||||
updateProxies(cfg.Proxies, cfg.Providers)
|
updateProxies(cfg.Proxies, cfg.Providers)
|
||||||
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
||||||
@ -145,19 +146,31 @@ func GetGeneral() *config.General {
|
|||||||
LanDisAllowedIPs: inbound.DisAllowedIPs(),
|
LanDisAllowedIPs: inbound.DisAllowedIPs(),
|
||||||
AllowLan: listener.AllowLan(),
|
AllowLan: listener.AllowLan(),
|
||||||
BindAddress: listener.BindAddress(),
|
BindAddress: listener.BindAddress(),
|
||||||
|
InboundTfo: inbound.Tfo(),
|
||||||
|
InboundMPTCP: inbound.MPTCP(),
|
||||||
},
|
},
|
||||||
Controller: config.Controller{},
|
Mode: tunnel.Mode(),
|
||||||
Mode: tunnel.Mode(),
|
UnifiedDelay: adapter.UnifiedDelay.Load(),
|
||||||
LogLevel: log.Level(),
|
LogLevel: log.Level(),
|
||||||
IPv6: !resolver.DisableIPv6,
|
IPv6: !resolver.DisableIPv6,
|
||||||
GeodataMode: G.GeodataMode(),
|
Interface: dialer.DefaultInterface.Load(),
|
||||||
GeoAutoUpdate: G.GeoAutoUpdate(),
|
RoutingMark: int(dialer.DefaultRoutingMark.Load()),
|
||||||
GeoUpdateInterval: G.GeoUpdateInterval(),
|
GeoXUrl: config.GeoXUrl{
|
||||||
GeodataLoader: G.LoaderName(),
|
GeoIp: C.GeoIpUrl,
|
||||||
GeositeMatcher: G.SiteMatcherName(),
|
Mmdb: C.MmdbUrl,
|
||||||
Interface: dialer.DefaultInterface.Load(),
|
ASN: C.ASNUrl,
|
||||||
Sniffing: tunnel.IsSniffing(),
|
GeoSite: C.GeoSiteUrl,
|
||||||
TCPConcurrent: dialer.GetTcpConcurrent(),
|
},
|
||||||
|
GeoAutoUpdate: G.GeoAutoUpdate(),
|
||||||
|
GeoUpdateInterval: G.GeoUpdateInterval(),
|
||||||
|
GeodataMode: G.GeodataMode(),
|
||||||
|
GeodataLoader: G.LoaderName(),
|
||||||
|
GeositeMatcher: G.SiteMatcherName(),
|
||||||
|
TCPConcurrent: dialer.GetTcpConcurrent(),
|
||||||
|
FindProcessMode: tunnel.FindProcessMode(),
|
||||||
|
Sniffing: tunnel.IsSniffing(),
|
||||||
|
GlobalClientFingerprint: tlsC.GetGlobalFingerprint(),
|
||||||
|
GlobalUA: C.UA,
|
||||||
}
|
}
|
||||||
|
|
||||||
return general
|
return general
|
||||||
@ -188,14 +201,14 @@ func updateListeners(general *config.General, listeners map[string]C.InboundList
|
|||||||
listener.ReCreateTun(general.Tun, tunnel.Tunnel)
|
listener.ReCreateTun(general.Tun, tunnel.Tunnel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateExperimental(c *config.Config) {
|
func updateExperimental(c *config.Experimental) {
|
||||||
if c.Experimental.QUICGoDisableGSO {
|
if c.QUICGoDisableGSO {
|
||||||
_ = os.Setenv("QUIC_GO_DISABLE_GSO", strconv.FormatBool(true))
|
_ = os.Setenv("QUIC_GO_DISABLE_GSO", strconv.FormatBool(true))
|
||||||
}
|
}
|
||||||
if c.Experimental.QUICGoDisableECN {
|
if c.QUICGoDisableECN {
|
||||||
_ = os.Setenv("QUIC_GO_DISABLE_ECN", strconv.FormatBool(true))
|
_ = os.Setenv("QUIC_GO_DISABLE_ECN", strconv.FormatBool(true))
|
||||||
}
|
}
|
||||||
dialer.GetIP4PEnable(c.Experimental.IP4PEnable)
|
dialer.GetIP4PEnable(c.IP4PEnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateNTP(c *config.NTP) {
|
func updateNTP(c *config.NTP) {
|
||||||
|
22
hub/hub.go
22
hub/hub.go
@ -11,25 +11,25 @@ type Option func(*config.Config)
|
|||||||
|
|
||||||
func WithExternalUI(externalUI string) Option {
|
func WithExternalUI(externalUI string) Option {
|
||||||
return func(cfg *config.Config) {
|
return func(cfg *config.Config) {
|
||||||
cfg.General.ExternalUI = externalUI
|
cfg.Controller.ExternalUI = externalUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithExternalController(externalController string) Option {
|
func WithExternalController(externalController string) Option {
|
||||||
return func(cfg *config.Config) {
|
return func(cfg *config.Config) {
|
||||||
cfg.General.ExternalController = externalController
|
cfg.Controller.ExternalController = externalController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithExternalControllerUnix(externalControllerUnix string) Option {
|
func WithExternalControllerUnix(externalControllerUnix string) Option {
|
||||||
return func(cfg *config.Config) {
|
return func(cfg *config.Config) {
|
||||||
cfg.General.ExternalControllerUnix = externalControllerUnix
|
cfg.Controller.ExternalControllerUnix = externalControllerUnix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithSecret(secret string) Option {
|
func WithSecret(secret string) Option {
|
||||||
return func(cfg *config.Config) {
|
return func(cfg *config.Config) {
|
||||||
cfg.General.Secret = secret
|
cfg.Controller.Secret = secret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,18 +44,18 @@ func Parse(options ...Option) error {
|
|||||||
option(cfg)
|
option(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.General.ExternalUI != "" {
|
if cfg.Controller.ExternalUI != "" {
|
||||||
route.SetUIPath(cfg.General.ExternalUI)
|
route.SetUIPath(cfg.Controller.ExternalUI)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.General.ExternalController != "" {
|
if cfg.Controller.ExternalController != "" {
|
||||||
go route.Start(cfg.General.ExternalController, cfg.General.ExternalControllerTLS,
|
go route.Start(cfg.Controller.ExternalController, cfg.Controller.ExternalControllerTLS,
|
||||||
cfg.General.Secret, cfg.TLS.Certificate, cfg.TLS.PrivateKey, cfg.General.ExternalDohServer,
|
cfg.Controller.Secret, cfg.TLS.Certificate, cfg.TLS.PrivateKey, cfg.Controller.ExternalDohServer,
|
||||||
cfg.General.LogLevel == log.DEBUG)
|
cfg.General.LogLevel == log.DEBUG)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.General.ExternalControllerUnix != "" {
|
if cfg.Controller.ExternalControllerUnix != "" {
|
||||||
go route.StartUnix(cfg.General.ExternalControllerUnix, cfg.General.ExternalDohServer, cfg.General.LogLevel == log.DEBUG)
|
go route.StartUnix(cfg.Controller.ExternalControllerUnix, cfg.Controller.ExternalDohServer, cfg.General.LogLevel == log.DEBUG)
|
||||||
}
|
}
|
||||||
|
|
||||||
executor.ApplyConfig(cfg, true)
|
executor.ApplyConfig(cfg, true)
|
||||||
|
@ -68,16 +68,16 @@ type tunSchema struct {
|
|||||||
GSOMaxSize *uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
GSOMaxSize *uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
||||||
//Inet4Address *[]netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
|
//Inet4Address *[]netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
|
||||||
Inet6Address *[]netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
|
Inet6Address *[]netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
|
||||||
IPRoute2TableIndex *int `yaml:"iproute2-table-index" json:"iproute2_table_index,omitempty"`
|
IPRoute2TableIndex *int `yaml:"iproute2-table-index" json:"iproute2-table-index,omitempty"`
|
||||||
IPRoute2RuleIndex *int `yaml:"iproute2-rule-index" json:"iproute2_rule_index,omitempty"`
|
IPRoute2RuleIndex *int `yaml:"iproute2-rule-index" json:"iproute2-rule-index,omitempty"`
|
||||||
AutoRedirect *bool `yaml:"auto-redirect" json:"auto_redirect,omitempty"`
|
AutoRedirect *bool `yaml:"auto-redirect" json:"auto-redirect,omitempty"`
|
||||||
AutoRedirectInputMark *uint32 `yaml:"auto-redirect-input-mark" json:"auto_redirect_input_mark,omitempty"`
|
AutoRedirectInputMark *uint32 `yaml:"auto-redirect-input-mark" json:"auto-redirect-input-mark,omitempty"`
|
||||||
AutoRedirectOutputMark *uint32 `yaml:"auto-redirect-output-mark" json:"auto_redirect_output_mark,omitempty"`
|
AutoRedirectOutputMark *uint32 `yaml:"auto-redirect-output-mark" json:"auto-redirect-output-mark,omitempty"`
|
||||||
StrictRoute *bool `yaml:"strict-route" json:"strict-route,omitempty"`
|
StrictRoute *bool `yaml:"strict-route" json:"strict-route,omitempty"`
|
||||||
RouteAddress *[]netip.Prefix `yaml:"route-address" json:"route_address,omitempty"`
|
RouteAddress *[]netip.Prefix `yaml:"route-address" json:"route-address,omitempty"`
|
||||||
RouteAddressSet *[]string `yaml:"route-address-set" json:"route_address_set,omitempty"`
|
RouteAddressSet *[]string `yaml:"route-address-set" json:"route-address-set,omitempty"`
|
||||||
RouteExcludeAddress *[]netip.Prefix `yaml:"route-exclude-address" json:"route_exclude_address,omitempty"`
|
RouteExcludeAddress *[]netip.Prefix `yaml:"route-exclude-address" json:"route-exclude-address,omitempty"`
|
||||||
RouteExcludeAddressSet *[]string `yaml:"route-exclude-address-set" json:"route_exclude_address_set,omitempty"`
|
RouteExcludeAddressSet *[]string `yaml:"route-exclude-address-set" json:"route-exclude-address-set,omitempty"`
|
||||||
IncludeInterface *[]string `yaml:"include-interface" json:"include-interface,omitempty"`
|
IncludeInterface *[]string `yaml:"include-interface" json:"include-interface,omitempty"`
|
||||||
ExcludeInterface *[]string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
ExcludeInterface *[]string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
||||||
IncludeUID *[]uint32 `yaml:"include-uid" json:"include-uid,omitempty"`
|
IncludeUID *[]uint32 `yaml:"include-uid" json:"include-uid,omitempty"`
|
||||||
|
@ -34,16 +34,16 @@ type Tun struct {
|
|||||||
GSOMaxSize uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
GSOMaxSize uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
||||||
Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
|
Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
|
||||||
Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
|
Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
|
||||||
IPRoute2TableIndex int `yaml:"iproute2-table-index" json:"iproute2_table_index,omitempty"`
|
IPRoute2TableIndex int `yaml:"iproute2-table-index" json:"iproute2-table-index,omitempty"`
|
||||||
IPRoute2RuleIndex int `yaml:"iproute2-rule-index" json:"iproute2_rule_index,omitempty"`
|
IPRoute2RuleIndex int `yaml:"iproute2-rule-index" json:"iproute2-rule-index,omitempty"`
|
||||||
AutoRedirect bool `yaml:"auto-redirect" json:"auto_redirect,omitempty"`
|
AutoRedirect bool `yaml:"auto-redirect" json:"auto-redirect,omitempty"`
|
||||||
AutoRedirectInputMark uint32 `yaml:"auto-redirect-input-mark" json:"auto_redirect_input_mark,omitempty"`
|
AutoRedirectInputMark uint32 `yaml:"auto-redirect-input-mark" json:"auto-redirect-input-mark,omitempty"`
|
||||||
AutoRedirectOutputMark uint32 `yaml:"auto-redirect-output-mark" json:"auto_redirect_output_mark,omitempty"`
|
AutoRedirectOutputMark uint32 `yaml:"auto-redirect-output-mark" json:"auto-redirect-output-mark,omitempty"`
|
||||||
StrictRoute bool `yaml:"strict-route" json:"strict-route,omitempty"`
|
StrictRoute bool `yaml:"strict-route" json:"strict-route,omitempty"`
|
||||||
RouteAddress []netip.Prefix `yaml:"route-address" json:"route_address,omitempty"`
|
RouteAddress []netip.Prefix `yaml:"route-address" json:"route-address,omitempty"`
|
||||||
RouteAddressSet []string `yaml:"route-address-set" json:"route_address_set,omitempty"`
|
RouteAddressSet []string `yaml:"route-address-set" json:"route-address-set,omitempty"`
|
||||||
RouteExcludeAddress []netip.Prefix `yaml:"route-exclude-address" json:"route_exclude_address,omitempty"`
|
RouteExcludeAddress []netip.Prefix `yaml:"route-exclude-address" json:"route-exclude-address,omitempty"`
|
||||||
RouteExcludeAddressSet []string `yaml:"route-exclude-address-set" json:"route_exclude_address_set,omitempty"`
|
RouteExcludeAddressSet []string `yaml:"route-exclude-address-set" json:"route-exclude-address-set,omitempty"`
|
||||||
IncludeInterface []string `yaml:"include-interface" json:"include-interface,omitempty"`
|
IncludeInterface []string `yaml:"include-interface" json:"include-interface,omitempty"`
|
||||||
ExcludeInterface []string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
ExcludeInterface []string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
||||||
IncludeUID []uint32 `yaml:"include-uid" json:"include-uid,omitempty"`
|
IncludeUID []uint32 `yaml:"include-uid" json:"include-uid,omitempty"`
|
||||||
|
@ -21,35 +21,35 @@ type TunOption struct {
|
|||||||
MTU uint32 `inbound:"mtu,omitempty"`
|
MTU uint32 `inbound:"mtu,omitempty"`
|
||||||
GSO bool `inbound:"gso,omitempty"`
|
GSO bool `inbound:"gso,omitempty"`
|
||||||
GSOMaxSize uint32 `inbound:"gso-max-size,omitempty"`
|
GSOMaxSize uint32 `inbound:"gso-max-size,omitempty"`
|
||||||
Inet4Address []string `inbound:"inet4_address,omitempty"`
|
Inet4Address []string `inbound:"inet4-address,omitempty"`
|
||||||
Inet6Address []string `inbound:"inet6_address,omitempty"`
|
Inet6Address []string `inbound:"inet6-address,omitempty"`
|
||||||
IPRoute2TableIndex int `inbound:"iproute2-table-index"`
|
IPRoute2TableIndex int `inbound:"iproute2-table-index"`
|
||||||
IPRoute2RuleIndex int `inbound:"iproute2-rule-index"`
|
IPRoute2RuleIndex int `inbound:"iproute2-rule-index"`
|
||||||
AutoRedirect bool `inbound:"auto-redirect"`
|
AutoRedirect bool `inbound:"auto-redirect"`
|
||||||
AutoRedirectInputMark uint32 `inbound:"auto-redirect-input-mark"`
|
AutoRedirectInputMark uint32 `inbound:"auto-redirect-input-mark"`
|
||||||
AutoRedirectOutputMark uint32 `inbound:"auto-redirect-output-mark"`
|
AutoRedirectOutputMark uint32 `inbound:"auto-redirect-output-mark"`
|
||||||
StrictRoute bool `inbound:"strict_route,omitempty"`
|
StrictRoute bool `inbound:"strict-route,omitempty"`
|
||||||
RouteAddress []string `inbound:"route-address"`
|
RouteAddress []string `inbound:"route-address"`
|
||||||
RouteAddressSet []string `inbound:"route-address-set"`
|
RouteAddressSet []string `inbound:"route-address-set"`
|
||||||
RouteExcludeAddress []string `inbound:"route-exclude-address"`
|
RouteExcludeAddress []string `inbound:"route-exclude-address"`
|
||||||
RouteExcludeAddressSet []string `inbound:"route-exclude-address-set"`
|
RouteExcludeAddressSet []string `inbound:"route-exclude-address-set"`
|
||||||
IncludeInterface []string `inbound:"include-interface,omitempty"`
|
IncludeInterface []string `inbound:"include-interface,omitempty"`
|
||||||
ExcludeInterface []string `inbound:"exclude-interface"`
|
ExcludeInterface []string `inbound:"exclude-interface"`
|
||||||
IncludeUID []uint32 `inbound:"include_uid,omitempty"`
|
IncludeUID []uint32 `inbound:"include-uid,omitempty"`
|
||||||
IncludeUIDRange []string `inbound:"include_uid_range,omitempty"`
|
IncludeUIDRange []string `inbound:"include-uid-range,omitempty"`
|
||||||
ExcludeUID []uint32 `inbound:"exclude_uid,omitempty"`
|
ExcludeUID []uint32 `inbound:"exclude-uid,omitempty"`
|
||||||
ExcludeUIDRange []string `inbound:"exclude_uid_range,omitempty"`
|
ExcludeUIDRange []string `inbound:"exclude-uid-range,omitempty"`
|
||||||
IncludeAndroidUser []int `inbound:"include_android_user,omitempty"`
|
IncludeAndroidUser []int `inbound:"include-android-user,omitempty"`
|
||||||
IncludePackage []string `inbound:"include_package,omitempty"`
|
IncludePackage []string `inbound:"include-package,omitempty"`
|
||||||
ExcludePackage []string `inbound:"exclude_package,omitempty"`
|
ExcludePackage []string `inbound:"exclude-package,omitempty"`
|
||||||
EndpointIndependentNat bool `inbound:"endpoint_independent_nat,omitempty"`
|
EndpointIndependentNat bool `inbound:"endpoint-independent-nat,omitempty"`
|
||||||
UDPTimeout int64 `inbound:"udp_timeout,omitempty"`
|
UDPTimeout int64 `inbound:"udp-timeout,omitempty"`
|
||||||
FileDescriptor int `inbound:"file-descriptor,omitempty"`
|
FileDescriptor int `inbound:"file-descriptor,omitempty"`
|
||||||
|
|
||||||
Inet4RouteAddress []string `inbound:"inet4_route_address,omitempty"`
|
Inet4RouteAddress []string `inbound:"inet4-route-address,omitempty"`
|
||||||
Inet6RouteAddress []string `inbound:"inet6_route_address,omitempty"`
|
Inet6RouteAddress []string `inbound:"inet6-route-address,omitempty"`
|
||||||
Inet4RouteExcludeAddress []string `inbound:"inet4_route_exclude_address,omitempty"`
|
Inet4RouteExcludeAddress []string `inbound:"inet4-route-exclude-address,omitempty"`
|
||||||
Inet6RouteExcludeAddress []string `inbound:"inet6_route_exclude_address,omitempty"`
|
Inet6RouteExcludeAddress []string `inbound:"inet6-route-exclude-address,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o TunOption) Equal(config C.InboundConfig) bool {
|
func (o TunOption) Equal(config C.InboundConfig) bool {
|
||||||
|
@ -225,6 +225,10 @@ func SetMode(m TunnelMode) {
|
|||||||
mode = m
|
mode = m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindProcessMode() P.FindProcessMode {
|
||||||
|
return findProcessMode
|
||||||
|
}
|
||||||
|
|
||||||
// SetFindProcessMode replace SetAlwaysFindProcess
|
// SetFindProcessMode replace SetAlwaysFindProcess
|
||||||
// always find process info if legacyAlways = true or mode.Always() = true, may be increase many memory
|
// always find process info if legacyAlways = true or mode.Always() = true, may be increase many memory
|
||||||
func SetFindProcessMode(mode P.FindProcessMode) {
|
func SetFindProcessMode(mode P.FindProcessMode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user