Style: code style

This commit is contained in:
yaling888 2021-07-09 02:19:43 +08:00
parent 5852245045
commit 96e5a52651
5 changed files with 55 additions and 42 deletions

View File

@ -33,7 +33,7 @@ Documentations are now moved to [GitHub Wiki](https://github.com/Dreamacro/clash
## Advanced usage for this fork branch
### 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.
```yaml
@ -45,19 +45,19 @@ tun:
auto-route: true # auto set global route
```
### Rules configuration
- Support rule `GEOSITE`
- Support `multiport` condition for rule `SRC-PORT` and `DST-PORT`
- Support not match condition for rule `GEOIP`
- Support `network` condition for all rules
- Support rule `GEOSITE`.
- Support `multiport` condition for rule `SRC-PORT` and `DST-PORT`.
- Support not match condition for rule `GEOIP`.
- 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
rules:
# network condition for rules
- DOMAIN-SUFFIX,bilibili.com,DIRECT,tcp
- 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
# rule GEOSITE
@ -84,21 +84,34 @@ rules:
```
### Proxies configuration
Support outbound transport protocol `VLESS`
Support outbound transport protocol `VLESS`.
The XTLS only support TCP transport by the XRAY-CORE.
```yaml
proxies:
- name: "vless"
- name: "vless-tcp"
type: vless
server: server
port: 443
uuid: uuid
network: tcp
servername: example.com # AKA SNI
# udp: true
# flow: xtls-rprx-direct # xtls-rprx-origin # enable XTLS
# skip-cert-verify: true
# servername: example.com # priority over wss host
# network: ws # not support xtls
# ws-path: /path
# ws-headers:
# Host: v2ray.com
- name: "vless-ws"
type: vless
server: server
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"
type: vless
@ -106,7 +119,8 @@ proxies:
port: 443
uuid: uuid
network: h2
# flow: xtls-rprx-direct # xtls-rprx-origin xtls-rprx-direct # enable xtls
servername: example.com
# skip-cert-verify: true
h2-opts:
host:
- http.example.com
@ -119,16 +133,17 @@ proxies:
port: 443
uuid: uuid
# udp: true
# network: http
# flow: xtls-rprx-direct # xtls-rprx-origin xtls-rprx-direct # enable xtls
# http-opts:
# # method: "GET"
# # path:
# # - '/'
# # - '/video'
# # headers:
# # Connection:
# # - keep-alive
network: http
servername: example.com
# skip-cert-verify: true
http-opts:
method: "GET"
path:
- '/'
- '/video'
headers:
Connection:
- keep-alive
- name: vless-grpc
server: server
@ -136,7 +151,6 @@ proxies:
type: vless
uuid: uuid
network: grpc
# flow: xtls-rprx-direct # xtls-rprx-origin xtls-rprx-direct # enable xtls
servername: example.com
# skip-cert-verify: true
grpc-opts:
@ -154,7 +168,7 @@ tproxy-port: 9898
tun:
enable: false
```
Create user given name `clash`
Create user given name `clash`.
Run Clash by user `clash` as a daemon.
@ -186,9 +200,9 @@ $ systemctl start clash
```
### 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
[Release](https://github.com/Dreamacro/clash/releases/tag/premium)

View File

@ -35,7 +35,7 @@ type VlessOption struct {
Port int `proxy:"port"`
UUID string `proxy:"uuid"`
Flow string `proxy:"flow,omitempty"`
FlowShow bool `proxy:"flow_show,omitempty"`
FlowShow bool `proxy:"flow-show,omitempty"`
TLS bool `proxy:"tls,omitempty"`
UDP bool `proxy:"udp,omitempty"`
Network string `proxy:"network,omitempty"`

View File

@ -304,6 +304,8 @@ func updateIPTables(dns *config.DNS, general *config.General) {
return
}
tproxy.CleanUpTProxyLinuxIPTables()
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
if err != nil {

View File

@ -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)
}
//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)
if err != nil {
return fmt.Errorf("the user \" %s\" does not exist, please create it", USERNAME)
}
if ifname == "" {
return errors.New("interface name can not be empty")
return errors.New("the 'interface-name' can not be empty")
}
ownerUid := user.Uid

View File

@ -68,6 +68,7 @@ func (p *Port) matchPortReal(portRef string) bool {
}
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, "/")
if len(ports) > 28 {
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
}
subPort := strings.Split(strings.Trim(p, "[ ]"), "-")
subPortLen := len(subPort)
if subPortLen > 2 {
subPorts := strings.Split(p, "-")
subPortsLen := len(subPorts)
if subPortsLen > 2 {
return nil, errPayload
}
portStart, err := strconv.Atoi(subPort[0])
portStart, err := strconv.Atoi(strings.Trim(subPorts[0], "[ ]"))
if err != nil || portStart < 0 || portStart > 65535 {
return nil, errPayload
}
if subPortLen == 1 {
if subPortsLen == 1 {
portList = append(portList, portReal{portStart, -1})
} else if subPortLen == 2 {
portEnd, err1 := strconv.Atoi(subPort[1])
} else if subPortsLen == 2 {
portEnd, err1 := strconv.Atoi(strings.Trim(subPorts[1], "[ ]"))
if err1 != nil || portEnd < 0 || portEnd > 65535 {
return nil, errPayload
}