Documentation ¶
Index ¶
- Constants
- Variables
- func SetConfig(file string)
- func SetHomeDir(root string)
- type AdapterType
- type Chain
- type Conn
- type ConnContext
- type Connection
- type DNSMode
- type DNSPrefer
- type DelayHistory
- type Dialer
- type EBpf
- type Group
- type HTTPVersion
- type InboundConfig
- type InboundListener
- type Listener
- type Metadata
- 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) SourceAddress() string
- func (m *Metadata) SourceDetail() string
- func (m *Metadata) String() string
- func (m *Metadata) UDPAddr() *net.UDPAddr
- func (m *Metadata) Valid() bool
- type MultiAddrListener
- type NatTable
- type NetWork
- type PacketAdapter
- type PacketConn
- type PacketConnContext
- type PlainContext
- type Proxy
- type ProxyAdapter
- type Rule
- type RuleGeoIP
- type RuleGeoSite
- type RuleGroup
- type RuleType
- type TUNStack
- type Type
- type UDPPacket
- type UDPPacketInAddr
Constants ¶
const ( DefaultTCPTimeout = 5 * time.Second DefaultUDPTimeout = DefaultTCPTimeout DefaultTLSTimeout = DefaultTCPTimeout )
const ( BpfFSPath = "/sys/fs/bpf/clash" TcpAutoRedirPort = 't'<<8 | 'r'<<0 ClashTrafficMark = 'c'<<24 | 'l'<<16 | 't'<<8 | 'm'<<0 )
const ( TCP NetWork = iota UDP ALLNet HTTP Type = iota HTTPS SOCKS4 SOCKS5 SHADOWSOCKS VMESS REDIR TPROXY TUNNEL TUN TUIC INNER )
Socks addr type
const Name = "clash"
Variables ¶
var ( GeodataMode bool GeoIpUrl string MmdbUrl string GeoSiteUrl string )
var ( GeositeName = "GeoSite.dat" GeoipName = "GeoIP.dat" )
var ( Meta = true Version = "1.10.0" BuildTime = "unknown time" ClashName = "clash.meta" )
var DNSModeMapping = map[string]DNSMode{ DNSNormal.String(): DNSNormal, DNSFakeIP.String(): DNSFakeIP, DNSMapping.String(): DNSMapping, }
DNSModeMapping is a mapping for EnhancedMode enum
var Path = func() *path { homeDir, err := os.UserHomeDir() if err != nil { homeDir, _ = os.Getwd() } homeDir = P.Join(homeDir, ".config", Name) return &path{homeDir: homeDir, configFile: "config.yaml"} }()
Path is used to get the configuration path
Functions ¶
Types ¶
type AdapterType ¶
type AdapterType int
AdapterType is enum of adapter type
const ( Direct AdapterType = iota Reject Compatible Pass Relay Selector Fallback URLTest URLTestDelayAndSpeed LoadBalance Shadowsocks ShadowsocksR Snell Socks5 Http Vmess Vless Trojan Hysteria WireGuard Tuic )
Adapter Type
func (AdapterType) String ¶
func (at AdapterType) String() string
type Conn ¶
type Conn interface { net.Conn Connection }
type ConnContext ¶
type ConnContext interface { PlainContext Metadata() *Metadata Conn() net.Conn }
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) MarshalYAML ¶
MarshalYAML serialize EnhancedMode with yaml
func (*DNSMode) UnmarshalJSON ¶
UnmarshalJSON unserialize EnhancedMode with json
type DelayHistory ¶
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 InboundListener interface { Name() string Listen(tcpIn chan<- ConnContext, udpIn chan<- PacketAdapter, natTable NatTable) error Close() error Address() string RawAddress() string Config() InboundConfig }
type Metadata ¶
type Metadata struct { NetWork NetWork `json:"network"` Type Type `json:"type"` SrcIP netip.Addr `json:"sourceIP"` DstIP netip.Addr `json:"destinationIP"` SrcPort string `json:"sourcePort"` DstPort string `json:"destinationPort"` InIP netip.Addr `json:"inboundIP"` InPort string `json:"inboundPort"` InName string `json:"inboundName"` 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"` // 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) SourceAddress ¶
func (*Metadata) SourceDetail ¶
type MultiAddrListener ¶
type NatTable ¶
type NatTable interface { Set(key string, e PacketConn) Get(key string) PacketConn GetOrCreateLock(key string) (*sync.Cond, bool) Delete(key string) GetLocalConn(lAddr, rAddr string) *net.UDPConn AddLocalConn(lAddr, rAddr string, conn *net.UDPConn) bool RangeLocalConn(lAddr string, f func(key, value any) bool) GetOrCreateLockForLocalConn(lAddr, key string) (*sync.Cond, bool) DeleteLocalConnMap(lAddr, key string) }
type PacketAdapter ¶
PacketAdapter is a UDP Packet adapter for socks/redir/tun
type PacketConn ¶
type PacketConn interface { net.PacketConn Connection }
type PacketConnContext ¶
type PacketConnContext interface { PlainContext Metadata() *Metadata PacketConn() net.PacketConn }
type PlainContext ¶
type Proxy ¶
type Proxy interface { ProxyAdapter Alive() bool DelayHistory() []DelayHistory LastDelay() uint16 URLTest(ctx context.Context, url string) (uint16, error) URLTestDelayAndSpeed(ctx context.Context, url string) (uint16, float64, 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.StreamConn(conn, metadata) // // It returns a C.Conn with protocol which start with // a new session (if any) StreamConn(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() bool DialContextWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (Conn, error) ListenPacketWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (PacketConn, error) // Unwrap extracts the proxy from a proxy-group. It returns nil when nothing to extract. Unwrap(metadata *Metadata, touch bool) Proxy }
type RuleGeoIP ¶
type RuleGeoIP interface {
GetIPMatcher() *router.GeoIPMatcher
}
type RuleGeoSite ¶
type RuleGeoSite interface {
GetDomainMatcher() *router.DomainMatcher
}
type RuleType ¶
type RuleType int
type TUNStack ¶
type TUNStack int
func (TUNStack) MarshalJSON ¶
MarshalJSON serialize TUNStack with json
func (TUNStack) MarshalYAML ¶
MarshalYAML serialize TUNStack with yaml
func (*TUNStack) UnmarshalJSON ¶
UnmarshalJSON unserialize TUNStack with json
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(b []byte, addr net.Addr) (n int, err error) // 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