Style: code style
This commit is contained in:
parent
5852245045
commit
96e5a52651
5 changed files with 55 additions and 42 deletions
72
README.md
72
README.md
|
@ -33,7 +33,7 @@ Documentations are now moved to [GitHub Wiki](https://github.com/Dreamacro/clash
|
||||||
|
|
||||||
## Advanced usage for this fork branch
|
## Advanced usage for this fork branch
|
||||||
### TUN configuration
|
### TUN configuration
|
||||||
Support macOS Linux and Windows.
|
Support macOS,Linux and Windows.
|
||||||
|
|
||||||
For Windows, you should download the [Wintun](https://www.wintun.net) driver and copy `wintun.dll` into the System32 directory.
|
For Windows, you should download the [Wintun](https://www.wintun.net) driver and copy `wintun.dll` into the System32 directory.
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -45,19 +45,19 @@ tun:
|
||||||
auto-route: true # auto set global route
|
auto-route: true # auto set global route
|
||||||
```
|
```
|
||||||
### Rules configuration
|
### Rules configuration
|
||||||
- Support rule `GEOSITE`
|
- Support rule `GEOSITE`.
|
||||||
- Support `multiport` condition for rule `SRC-PORT` and `DST-PORT`
|
- Support `multiport` condition for rule `SRC-PORT` and `DST-PORT`.
|
||||||
- Support not match condition for rule `GEOIP`
|
- Support not match condition for rule `GEOIP`.
|
||||||
- Support `network` condition for all rules
|
- Support `network` condition for all rules.
|
||||||
|
|
||||||
The `GEOSITE` and `GEOIP` databases via https://github.com/Loyalsoldier/v2ray-rules-dat
|
The `GEOSITE` and `GEOIP` databases via https://github.com/Loyalsoldier/v2ray-rules-dat.
|
||||||
```yaml
|
```yaml
|
||||||
rules:
|
rules:
|
||||||
# network condition for rules
|
# network condition for rules
|
||||||
- DOMAIN-SUFFIX,bilibili.com,DIRECT,tcp
|
- DOMAIN-SUFFIX,bilibili.com,DIRECT,tcp
|
||||||
- DOMAIN-SUFFIX,bilibili.com,REJECT,udp
|
- DOMAIN-SUFFIX,bilibili.com,REJECT,udp
|
||||||
|
|
||||||
# multiport condition for rule SRC-PORT and DST-PORT
|
# multiport condition for rules SRC-PORT and DST-PORT
|
||||||
- DST-PORT,123/136/137-139,DIRECT,udp
|
- DST-PORT,123/136/137-139,DIRECT,udp
|
||||||
|
|
||||||
# rule GEOSITE
|
# rule GEOSITE
|
||||||
|
@ -84,21 +84,34 @@ rules:
|
||||||
```
|
```
|
||||||
|
|
||||||
### Proxies configuration
|
### Proxies configuration
|
||||||
Support outbound transport protocol `VLESS`
|
Support outbound transport protocol `VLESS`.
|
||||||
|
|
||||||
|
The XTLS only support TCP transport by the XRAY-CORE.
|
||||||
```yaml
|
```yaml
|
||||||
proxies:
|
proxies:
|
||||||
- name: "vless"
|
- name: "vless-tcp"
|
||||||
type: vless
|
type: vless
|
||||||
server: server
|
server: server
|
||||||
port: 443
|
port: 443
|
||||||
uuid: uuid
|
uuid: uuid
|
||||||
|
network: tcp
|
||||||
|
servername: example.com # AKA SNI
|
||||||
# udp: true
|
# udp: true
|
||||||
|
# flow: xtls-rprx-direct # xtls-rprx-origin # enable XTLS
|
||||||
# skip-cert-verify: true
|
# skip-cert-verify: true
|
||||||
# servername: example.com # priority over wss host
|
|
||||||
# network: ws # not support xtls
|
- name: "vless-ws"
|
||||||
# ws-path: /path
|
type: vless
|
||||||
# ws-headers:
|
server: server
|
||||||
# Host: v2ray.com
|
port: 443
|
||||||
|
uuid: uuid
|
||||||
|
udp: true
|
||||||
|
network: ws
|
||||||
|
servername: example.com # priority over wss host
|
||||||
|
# skip-cert-verify: true
|
||||||
|
ws-path: /path
|
||||||
|
ws-headers:
|
||||||
|
Host: example.com
|
||||||
|
|
||||||
- name: "vless-h2"
|
- name: "vless-h2"
|
||||||
type: vless
|
type: vless
|
||||||
|
@ -106,7 +119,8 @@ proxies:
|
||||||
port: 443
|
port: 443
|
||||||
uuid: uuid
|
uuid: uuid
|
||||||
network: h2
|
network: h2
|
||||||
# flow: xtls-rprx-direct # xtls-rprx-origin xtls-rprx-direct # enable xtls
|
servername: example.com
|
||||||
|
# skip-cert-verify: true
|
||||||
h2-opts:
|
h2-opts:
|
||||||
host:
|
host:
|
||||||
- http.example.com
|
- http.example.com
|
||||||
|
@ -119,16 +133,17 @@ proxies:
|
||||||
port: 443
|
port: 443
|
||||||
uuid: uuid
|
uuid: uuid
|
||||||
# udp: true
|
# udp: true
|
||||||
# network: http
|
network: http
|
||||||
# flow: xtls-rprx-direct # xtls-rprx-origin xtls-rprx-direct # enable xtls
|
servername: example.com
|
||||||
# http-opts:
|
# skip-cert-verify: true
|
||||||
# # method: "GET"
|
http-opts:
|
||||||
# # path:
|
method: "GET"
|
||||||
# # - '/'
|
path:
|
||||||
# # - '/video'
|
- '/'
|
||||||
# # headers:
|
- '/video'
|
||||||
# # Connection:
|
headers:
|
||||||
# # - keep-alive
|
Connection:
|
||||||
|
- keep-alive
|
||||||
|
|
||||||
- name: vless-grpc
|
- name: vless-grpc
|
||||||
server: server
|
server: server
|
||||||
|
@ -136,7 +151,6 @@ proxies:
|
||||||
type: vless
|
type: vless
|
||||||
uuid: uuid
|
uuid: uuid
|
||||||
network: grpc
|
network: grpc
|
||||||
# flow: xtls-rprx-direct # xtls-rprx-origin xtls-rprx-direct # enable xtls
|
|
||||||
servername: example.com
|
servername: example.com
|
||||||
# skip-cert-verify: true
|
# skip-cert-verify: true
|
||||||
grpc-opts:
|
grpc-opts:
|
||||||
|
@ -154,7 +168,7 @@ tproxy-port: 9898
|
||||||
tun:
|
tun:
|
||||||
enable: false
|
enable: false
|
||||||
```
|
```
|
||||||
Create user given name `clash`
|
Create user given name `clash`.
|
||||||
|
|
||||||
Run Clash by user `clash` as a daemon.
|
Run Clash by user `clash` as a daemon.
|
||||||
|
|
||||||
|
@ -186,9 +200,9 @@ $ systemctl start clash
|
||||||
```
|
```
|
||||||
|
|
||||||
### Display Process name
|
### Display Process name
|
||||||
Add field `Process` to `Metadata` and prepare to get process name for Restful API `GET /connections`
|
Add field `Process` to `Metadata` and prepare to get process name for Restful API `GET /connections`.
|
||||||
|
|
||||||
To display process name in GUI please use https://yaling888.github.io/yacd/
|
To display process name in GUI please use https://yaling888.github.io/yacd/.
|
||||||
|
|
||||||
## Premium Release
|
## Premium Release
|
||||||
[Release](https://github.com/Dreamacro/clash/releases/tag/premium)
|
[Release](https://github.com/Dreamacro/clash/releases/tag/premium)
|
||||||
|
|
|
@ -35,7 +35,7 @@ type VlessOption struct {
|
||||||
Port int `proxy:"port"`
|
Port int `proxy:"port"`
|
||||||
UUID string `proxy:"uuid"`
|
UUID string `proxy:"uuid"`
|
||||||
Flow string `proxy:"flow,omitempty"`
|
Flow string `proxy:"flow,omitempty"`
|
||||||
FlowShow bool `proxy:"flow_show,omitempty"`
|
FlowShow bool `proxy:"flow-show,omitempty"`
|
||||||
TLS bool `proxy:"tls,omitempty"`
|
TLS bool `proxy:"tls,omitempty"`
|
||||||
UDP bool `proxy:"udp,omitempty"`
|
UDP bool `proxy:"udp,omitempty"`
|
||||||
Network string `proxy:"network,omitempty"`
|
Network string `proxy:"network,omitempty"`
|
||||||
|
|
|
@ -304,6 +304,8 @@ func updateIPTables(dns *config.DNS, general *config.General) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tproxy.CleanUpTProxyLinuxIPTables()
|
||||||
|
|
||||||
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
|
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -29,17 +29,13 @@ func SetTProxyLinuxIPTables(ifname string, tport int, dport int) error {
|
||||||
return fmt.Errorf("current operations system [%s] are not support iptables or command iptables does not exist", runtime.GOOS)
|
return fmt.Errorf("current operations system [%s] are not support iptables or command iptables does not exist", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
|
||||||
//if _, err = execCmd("modprobe xt_TPROXY"); err != nil {
|
|
||||||
// return errors.New("xt_TPROXY module does not exist, please install it")
|
|
||||||
//}
|
|
||||||
|
|
||||||
user, err := U.Lookup(USERNAME)
|
user, err := U.Lookup(USERNAME)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("the user \" %s\" does not exist, please create it", USERNAME)
|
return fmt.Errorf("the user \" %s\" does not exist, please create it", USERNAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ifname == "" {
|
if ifname == "" {
|
||||||
return errors.New("interface name can not be empty")
|
return errors.New("the 'interface-name' can not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
ownerUid := user.Uid
|
ownerUid := user.Uid
|
||||||
|
|
15
rule/port.go
15
rule/port.go
|
@ -68,6 +68,7 @@ func (p *Port) matchPortReal(portRef string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPort(port string, adapter string, isSource bool, network C.NetWork) (*Port, error) {
|
func NewPort(port string, adapter string, isSource bool, network C.NetWork) (*Port, error) {
|
||||||
|
//the port format should be like this: "123/136/137-139" or "[123]/[136-139]"
|
||||||
ports := strings.Split(port, "/")
|
ports := strings.Split(port, "/")
|
||||||
if len(ports) > 28 {
|
if len(ports) > 28 {
|
||||||
return nil, fmt.Errorf("%s, too many ports to use, maximum support 28 ports", errPayload.Error())
|
return nil, fmt.Errorf("%s, too many ports to use, maximum support 28 ports", errPayload.Error())
|
||||||
|
@ -79,22 +80,22 @@ func NewPort(port string, adapter string, isSource bool, network C.NetWork) (*Po
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
subPort := strings.Split(strings.Trim(p, "[ ]"), "-")
|
subPorts := strings.Split(p, "-")
|
||||||
subPortLen := len(subPort)
|
subPortsLen := len(subPorts)
|
||||||
if subPortLen > 2 {
|
if subPortsLen > 2 {
|
||||||
return nil, errPayload
|
return nil, errPayload
|
||||||
}
|
}
|
||||||
|
|
||||||
portStart, err := strconv.Atoi(subPort[0])
|
portStart, err := strconv.Atoi(strings.Trim(subPorts[0], "[ ]"))
|
||||||
if err != nil || portStart < 0 || portStart > 65535 {
|
if err != nil || portStart < 0 || portStart > 65535 {
|
||||||
return nil, errPayload
|
return nil, errPayload
|
||||||
}
|
}
|
||||||
|
|
||||||
if subPortLen == 1 {
|
if subPortsLen == 1 {
|
||||||
portList = append(portList, portReal{portStart, -1})
|
portList = append(portList, portReal{portStart, -1})
|
||||||
|
|
||||||
} else if subPortLen == 2 {
|
} else if subPortsLen == 2 {
|
||||||
portEnd, err1 := strconv.Atoi(subPort[1])
|
portEnd, err1 := strconv.Atoi(strings.Trim(subPorts[1], "[ ]"))
|
||||||
if err1 != nil || portEnd < 0 || portEnd > 65535 {
|
if err1 != nil || portEnd < 0 || portEnd > 65535 {
|
||||||
return nil, errPayload
|
return nil, errPayload
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue