Documentation ¶
Index ¶
- Constants
- Variables
- func SetConfig(file string)
- func SetHomeDir(root string)
- type AdapterType
- type Chain
- type Conn
- type ConnContext
- type Connection
- type DNSMode
- func (e DNSMode) MarshalJSON() ([]byte, error)
- func (e DNSMode) MarshalText() ([]byte, error)
- func (e DNSMode) MarshalYAML() (any, error)
- func (e DNSMode) String() string
- func (e *DNSMode) UnmarshalJSON(data []byte) error
- func (e *DNSMode) UnmarshalText(data []byte) error
- func (e *DNSMode) UnmarshalYAML(unmarshal func(any) error) error
- type DNSPrefer
- type DelayHistory
- type DelayHistoryStoreType
- type Dialer
- type DomainMatcher
- type FilterMode
- func (e FilterMode) MarshalJSON() ([]byte, error)
- func (e FilterMode) MarshalText() ([]byte, error)
- func (e FilterMode) MarshalYAML() (interface{}, error)
- func (e FilterMode) String() string
- func (e *FilterMode) UnmarshalJSON(data []byte) error
- func (e *FilterMode) UnmarshalText(data []byte) error
- func (e *FilterMode) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Group
- type HTTPVersion
- type InboundConfig
- type InboundListener
- type IpMatcher
- type Listener
- type Metadata
- func (m *Metadata) AddrPort() netip.AddrPort
- func (m *Metadata) AddrType() int
- func (m *Metadata) Pure() *Metadata
- func (m *Metadata) RemoteAddress() string
- func (m *Metadata) Resolved() bool
- func (m *Metadata) RuleHost() string
- func (m *Metadata) SetRemoteAddr(addr net.Addr) error
- func (m *Metadata) SetRemoteAddress(rawAddress string) error
- func (m *Metadata) SourceAddrPort() netip.AddrPort
- func (m *Metadata) SourceAddress() string
- func (m *Metadata) SourceDetail() string
- func (m *Metadata) SourceValid() bool
- func (m *Metadata) String() string
- func (m *Metadata) SwapSrcDst()
- func (m *Metadata) UDPAddr() *net.UDPAddr
- func (m *Metadata) Valid() bool
- type MultiAddrListener
- type NatTable
- type NetWork
- type PacketAdapter
- type PacketConn
- type PacketConnContext
- type PacketSender
- type PlainContext
- type Proxy
- type ProxyAdapter
- type ProxyState
- type Rule
- type RuleGroup
- type RuleType
- type TUNStack
- func (e TUNStack) MarshalJSON() ([]byte, error)
- func (e TUNStack) MarshalText() ([]byte, error)
- func (e TUNStack) MarshalYAML() (any, error)
- func (e TUNStack) String() string
- func (e *TUNStack) UnmarshalJSON(data []byte) error
- func (e *TUNStack) UnmarshalText(data []byte) error
- func (e *TUNStack) UnmarshalYAML(unmarshal func(any) error) error
- type Tunnel
- type Type
- type UDPPacket
- type UDPPacketInAddr
- type WriteBack
- type WriteBackProxy
Constants ¶
const ( DefaultTCPTimeout = dialer.DefaultTCPTimeout DefaultUDPTimeout = dialer.DefaultUDPTimeout DefaultDropTime = 12 * DefaultTCPTimeout DefaultTLSTimeout = DefaultTCPTimeout DefaultTestURL = "https://www.gstatic.com/generate_204" )
const Name = "clash"
Variables ¶
var ( GeositeName = "GeoSite.dat" GeoipName = "GeoIP.dat" ASNName = "ASN.mmdb" )
var ( Meta = true Version = "1.10.0" BuildTime = "unknown time" ClashName = "clash" )
var DNSModeMapping = map[string]DNSMode{ DNSNormal.String(): DNSNormal, DNSFakeIP.String(): DNSFakeIP, DNSMapping.String(): DNSMapping, }
DNSModeMapping is a mapping for EnhancedMode enum
var ErrNotSupport = errors.New("no support")
var FilterModeMapping = map[string]FilterMode{ FilterBlackList.String(): FilterBlackList, FilterWhiteList.String(): FilterWhiteList, }
FilterModeMapping is a mapping for FilterMode enum
var Path = func() *path { homeDir, err := os.UserHomeDir() if err != nil { homeDir, _ = os.Getwd() } allowUnsafePath, _ := strconv.ParseBool(os.Getenv("SKIP_SAFE_PATH_CHECK")) homeDir = P.Join(homeDir, ".config", Name) if _, err = os.Stat(homeDir); err != nil { if configHome, ok := os.LookupEnv("XDG_CONFIG_HOME"); ok { homeDir = P.Join(configHome, Name) } } return &path{homeDir: homeDir, configFile: "config.yaml", allowUnsafePath: allowUnsafePath} }()
Path is used to get the configuration path
on Unix systems, `$HOME/.config/clash`. on Windows, `%USERPROFILE%/.config/clash`.
Functions ¶
Types ¶
type AdapterType ¶
type AdapterType int
AdapterType is enum of adapter type
const ( Direct AdapterType = iota Reject RejectDrop Compatible Pass Dns Relay Selector Fallback URLTest LoadBalance Shadowsocks ShadowsocksR Snell Socks5 Http Vmess Vless Trojan Hysteria Hysteria2 WireGuard Tuic Ssh )
Adapter Type
func (AdapterType) String ¶
func (at AdapterType) String() string
type Conn ¶
type Conn interface { N.ExtendedConn Connection }
type ConnContext ¶
type ConnContext interface { PlainContext Metadata() *Metadata Conn() *N.BufferedConn }
type Connection ¶
type Connection interface { Chains() Chain AppendToChains(adapter ProxyAdapter) RemoteDestination() string }
type DNSMode ¶
type DNSMode int
func (DNSMode) MarshalJSON ¶
MarshalJSON serialize EnhancedMode with json
func (DNSMode) MarshalText ¶
MarshalText serialize EnhancedMode
func (DNSMode) MarshalYAML ¶
MarshalYAML serialize EnhancedMode with yaml
func (*DNSMode) UnmarshalJSON ¶
UnmarshalJSON unserialize EnhancedMode with json
func (*DNSMode) UnmarshalText ¶
UnmarshalText unserialize EnhancedMode
type DelayHistory ¶
type DelayHistoryStoreType ¶
type DelayHistoryStoreType int
type DomainMatcher ¶
type FilterMode ¶
type FilterMode int
const ( FilterBlackList FilterMode = iota FilterWhiteList )
func (FilterMode) MarshalJSON ¶
func (e FilterMode) MarshalJSON() ([]byte, error)
func (FilterMode) MarshalText ¶
func (e FilterMode) MarshalText() ([]byte, error)
func (FilterMode) MarshalYAML ¶
func (e FilterMode) MarshalYAML() (interface{}, error)
func (FilterMode) String ¶
func (e FilterMode) String() string
func (*FilterMode) UnmarshalJSON ¶
func (e *FilterMode) UnmarshalJSON(data []byte) error
func (*FilterMode) UnmarshalText ¶
func (e *FilterMode) UnmarshalText(data []byte) error
func (*FilterMode) UnmarshalYAML ¶
func (e *FilterMode) UnmarshalYAML(unmarshal func(interface{}) error) error
type HTTPVersion ¶
type HTTPVersion string
const ( // HTTPVersion11 is HTTP/1.1. HTTPVersion11 HTTPVersion = "http/1.1" // HTTPVersion2 is HTTP/2. HTTPVersion2 HTTPVersion = "h2" // HTTPVersion3 is HTTP/3. HTTPVersion3 HTTPVersion = "h3" )
type InboundConfig ¶
type InboundConfig interface { Name() string Equal(config InboundConfig) bool }
type InboundListener ¶
type Metadata ¶
type Metadata struct { NetWork NetWork `json:"network"` Type Type `json:"type"` SrcIP netip.Addr `json:"sourceIP"` DstIP netip.Addr `json:"destinationIP"` SrcGeoIP []string `json:"sourceGeoIP"` // can be nil if never queried, empty slice if got no result DstGeoIP []string `json:"destinationGeoIP"` // can be nil if never queried, empty slice if got no result SrcIPASN string `json:"sourceIPASN"` DstIPASN string `json:"destinationIPASN"` SrcPort uint16 `json:"sourcePort,string"` // `,string` is used to compatible with old version json output DstPort uint16 `json:"destinationPort,string"` // `,string` is used to compatible with old version json output InIP netip.Addr `json:"inboundIP"` InPort uint16 `json:"inboundPort,string"` // `,string` is used to compatible with old version json output InName string `json:"inboundName"` InUser string `json:"inboundUser"` Host string `json:"host"` DNSMode DNSMode `json:"dnsMode"` Uid uint32 `json:"uid"` Process string `json:"process"` ProcessPath string `json:"processPath"` SpecialProxy string `json:"specialProxy"` SpecialRules string `json:"specialRules"` RemoteDst string `json:"remoteDestination"` DSCP uint8 `json:"dscp"` RawSrcAddr net.Addr `json:"-"` RawDstAddr net.Addr `json:"-"` // Only domain rule SniffHost string `json:"sniffHost"` }
Metadata is used to store connection address
func (*Metadata) Pure ¶
Pure is used to solve unexpected behavior when dialing proxy connection in DNSMapping mode.
func (*Metadata) RemoteAddress ¶
func (*Metadata) SetRemoteAddress ¶
func (*Metadata) SourceAddrPort ¶
func (*Metadata) SourceAddress ¶
func (*Metadata) SourceDetail ¶
func (*Metadata) SourceValid ¶
func (*Metadata) SwapSrcDst ¶
func (m *Metadata) SwapSrcDst()
type MultiAddrListener ¶
type NatTable ¶
type NatTable interface { GetOrCreate(key string, maker func() PacketSender) (PacketSender, bool) Delete(key string) GetForLocalConn(lAddr, rAddr string) *net.UDPConn AddForLocalConn(lAddr, rAddr string, conn *net.UDPConn) bool RangeForLocalConn(lAddr string, f func(key string, value *net.UDPConn) bool) GetOrCreateLockForLocalConn(lAddr string, key string) (*sync.Cond, bool) DeleteForLocalConn(lAddr, key string) DeleteLockForLocalConn(lAddr, key string) }
type PacketAdapter ¶
type PacketAdapter interface { UDPPacket // Metadata returns destination metadata Metadata() *Metadata // Key is a SNAT key Key() string }
PacketAdapter is a UDP Packet adapter for socks/redir/tun
func NewPacketAdapter ¶
func NewPacketAdapter(packet UDPPacket, metadata *Metadata) PacketAdapter
type PacketConn ¶
type PacketConn interface { N.EnhancePacketConn Connection }
type PacketConnContext ¶
type PacketConnContext interface { PlainContext Metadata() *Metadata PacketConn() net.PacketConn }
type PacketSender ¶
type PacketSender interface { // Send will send PacketAdapter nonblocking // the implement must call UDPPacket.Drop() inside Send Send(PacketAdapter) // Process is a blocking loop to send PacketAdapter to PacketConn and update the WriteBackProxy Process(PacketConn, WriteBackProxy) // ResolveUDP do a local resolve UDP dns blocking if metadata is not resolved ResolveUDP(*Metadata) error // Close stop the Process loop Close() }
type PlainContext ¶
type PlainContext interface {
ID() uuid.UUID
}
type Proxy ¶
type Proxy interface { ProxyAdapter Adapter() ProxyAdapter AliveForTestUrl(url string) bool DelayHistory() []DelayHistory ExtraDelayHistories() map[string]ProxyState LastDelayForTestUrl(url string) uint16 URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (uint16, error) // Deprecated: use DialContext instead. Dial(metadata *Metadata) (Conn, error) // Deprecated: use DialPacketConn instead. DialUDP(metadata *Metadata) (PacketConn, error) }
type ProxyAdapter ¶
type ProxyAdapter interface { Name() string Type() AdapterType Addr() string SupportUDP() bool SupportXUDP() bool SupportTFO() bool MarshalJSON() ([]byte, error) // Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead. // StreamConn wraps a protocol around net.Conn with Metadata. // // Examples: // conn, _ := net.DialContext(context.Background(), "tcp", "host:port") // conn, _ = adapter.StreamConnContext(context.Background(), conn, metadata) // // It returns a C.Conn with protocol which start with // a new session (if any) StreamConnContext(ctx context.Context, c net.Conn, metadata *Metadata) (net.Conn, error) // DialContext return a C.Conn with protocol which // contains multiplexing-related reuse logic (if any) DialContext(ctx context.Context, metadata *Metadata, opts ...dialer.Option) (Conn, error) ListenPacketContext(ctx context.Context, metadata *Metadata, opts ...dialer.Option) (PacketConn, error) // SupportUOT return UDP over TCP support SupportUOT() bool SupportWithDialer() NetWork DialContextWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (Conn, error) ListenPacketWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (PacketConn, error) // IsL3Protocol return ProxyAdapter working in L3 (tell dns module not pass the domain to avoid loopback) IsL3Protocol(metadata *Metadata) bool // Unwrap extracts the proxy from a proxy-group. It returns nil when nothing to extract. Unwrap(metadata *Metadata, touch bool) Proxy }
type ProxyState ¶
type ProxyState struct { Alive bool `json:"alive"` History []DelayHistory `json:"history"` }
type RuleType ¶
type RuleType int
const ( Domain RuleType = iota DomainSuffix DomainKeyword DomainRegex GEOSITE GEOIP SrcGEOIP IPASN SrcIPASN IPCIDR SrcIPCIDR IPSuffix SrcIPSuffix SrcPort DstPort InPort DSCP InUser InName InType ProcessName ProcessPath ProcessNameRegex ProcessPathRegex RuleSet Network Uid SubRules MATCH AND OR NOT )
Rule Type
type TUNStack ¶
type TUNStack int
func (TUNStack) MarshalJSON ¶
MarshalJSON serialize TUNStack with json
func (TUNStack) MarshalText ¶
MarshalText serialize TUNStack with json
func (TUNStack) MarshalYAML ¶
MarshalYAML serialize TUNStack with yaml
func (*TUNStack) UnmarshalJSON ¶
UnmarshalJSON unserialize TUNStack with json
func (*TUNStack) UnmarshalText ¶
UnmarshalText unserialize TUNStack
type UDPPacket ¶
type UDPPacket interface { // Data get the payload of UDP Packet Data() []byte // WriteBack writes the payload with source IP/Port equals addr // - variable source IP/Port is important to STUN // - if addr is not provided, WriteBack will write out UDP packet with SourceIP/Port equals to original Target, // this is important when using Fake-IP. WriteBack // Drop call after packet is used, could recycle buffer in this function. Drop() // LocalAddr returns the source IP/Port of packet LocalAddr() net.Addr }
UDPPacket contains the data of UDP packet, and offers control/info of UDP packet's source