mirror of https://github.com/MetaCubeX/mihomo
feat: tun add `exclude-src-port`,`exclude-src-port-range`,`exclude-dst-port` and `exclude-dst-port-range` on linux
This commit is contained in:
parent
a22efd5c91
commit
2a40eba0ca
|
@ -279,8 +279,10 @@ type RawTun struct {
|
||||||
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"`
|
||||||
ExcludePort []uint16 `yaml:"exclude-port" json:"exclude-port,omitempty"`
|
ExcludeSrcPort []uint16 `yaml:"exclude-src-port" json:"exclude-src-port,omitempty"`
|
||||||
ExcludePortRange []string `yaml:"exclude-port-range" json:"exclude-port-range,omitempty"`
|
ExcludeSrcPortRange []string `yaml:"exclude-src-port-range" json:"exclude-src-port-range,omitempty"`
|
||||||
|
ExcludeDstPort []uint16 `yaml:"exclude-dst-port" json:"exclude-dst-port,omitempty"`
|
||||||
|
ExcludeDstPortRange []string `yaml:"exclude-dst-port-range" json:"exclude-dst-port-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"`
|
||||||
|
@ -1562,8 +1564,10 @@ func parseTun(rawTun RawTun, general *General) error {
|
||||||
IncludeUIDRange: rawTun.IncludeUIDRange,
|
IncludeUIDRange: rawTun.IncludeUIDRange,
|
||||||
ExcludeUID: rawTun.ExcludeUID,
|
ExcludeUID: rawTun.ExcludeUID,
|
||||||
ExcludeUIDRange: rawTun.ExcludeUIDRange,
|
ExcludeUIDRange: rawTun.ExcludeUIDRange,
|
||||||
ExcludePort: rawTun.ExcludePort,
|
ExcludeSrcPort: rawTun.ExcludeSrcPort,
|
||||||
ExcludePortRange: rawTun.ExcludePortRange,
|
ExcludeSrcPortRange: rawTun.ExcludeSrcPortRange,
|
||||||
|
ExcludeDstPort: rawTun.ExcludeDstPort,
|
||||||
|
ExcludeDstPortRange: rawTun.ExcludeDstPortRange,
|
||||||
IncludeAndroidUser: rawTun.IncludeAndroidUser,
|
IncludeAndroidUser: rawTun.IncludeAndroidUser,
|
||||||
IncludePackage: rawTun.IncludePackage,
|
IncludePackage: rawTun.IncludePackage,
|
||||||
ExcludePackage: rawTun.ExcludePackage,
|
ExcludePackage: rawTun.ExcludePackage,
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -28,7 +28,7 @@ require (
|
||||||
github.com/metacubex/sing-quic v0.0.0-20250404030904-b2cc8aab562c
|
github.com/metacubex/sing-quic v0.0.0-20250404030904-b2cc8aab562c
|
||||||
github.com/metacubex/sing-shadowsocks v0.2.8
|
github.com/metacubex/sing-shadowsocks v0.2.8
|
||||||
github.com/metacubex/sing-shadowsocks2 v0.2.2
|
github.com/metacubex/sing-shadowsocks2 v0.2.2
|
||||||
github.com/metacubex/sing-tun v0.4.6-0.20250407014348-50cddb7347dc
|
github.com/metacubex/sing-tun v0.4.6-0.20250408105608-48dbc456318f
|
||||||
github.com/metacubex/sing-vmess v0.1.14-0.20250228002636-abc39e113b82
|
github.com/metacubex/sing-vmess v0.1.14-0.20250228002636-abc39e113b82
|
||||||
github.com/metacubex/sing-wireguard v0.0.0-20241126021510-0827d417b589
|
github.com/metacubex/sing-wireguard v0.0.0-20241126021510-0827d417b589
|
||||||
github.com/metacubex/tfo-go v0.0.0-20241231083714-66613d49c422
|
github.com/metacubex/tfo-go v0.0.0-20241231083714-66613d49c422
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -121,8 +121,8 @@ github.com/metacubex/sing-shadowsocks v0.2.8 h1:wIhlaigswzjPw4hej75sEvWte3QR0+AJ
|
||||||
github.com/metacubex/sing-shadowsocks v0.2.8/go.mod h1:X3x88XtJpBxG0W0/ECOJL6Ib0SJ3xdniAkU/6/RMWU0=
|
github.com/metacubex/sing-shadowsocks v0.2.8/go.mod h1:X3x88XtJpBxG0W0/ECOJL6Ib0SJ3xdniAkU/6/RMWU0=
|
||||||
github.com/metacubex/sing-shadowsocks2 v0.2.2 h1:eaf42uVx4Lr21S6MDYs0ZdTvGA0GEhDpb9no4+gdXPo=
|
github.com/metacubex/sing-shadowsocks2 v0.2.2 h1:eaf42uVx4Lr21S6MDYs0ZdTvGA0GEhDpb9no4+gdXPo=
|
||||||
github.com/metacubex/sing-shadowsocks2 v0.2.2/go.mod h1:BhOug03a/RbI7y6hp6q+6ITM1dXjnLTmeWBHSTwvv2Q=
|
github.com/metacubex/sing-shadowsocks2 v0.2.2/go.mod h1:BhOug03a/RbI7y6hp6q+6ITM1dXjnLTmeWBHSTwvv2Q=
|
||||||
github.com/metacubex/sing-tun v0.4.6-0.20250407014348-50cddb7347dc h1:Zn0Fst8C/uBJmwXArUMN7b9yQJXJY9S0nRJtTiYIq6Q=
|
github.com/metacubex/sing-tun v0.4.6-0.20250408105608-48dbc456318f h1:l+G+z6JzcTleAN8aoBq2JODex0jE6ufmjogfOScp+Ew=
|
||||||
github.com/metacubex/sing-tun v0.4.6-0.20250407014348-50cddb7347dc/go.mod h1:V0N4rr0dWPBEE20ESkTXdbtx2riQYcb6YtwC5w/9wl0=
|
github.com/metacubex/sing-tun v0.4.6-0.20250408105608-48dbc456318f/go.mod h1:V0N4rr0dWPBEE20ESkTXdbtx2riQYcb6YtwC5w/9wl0=
|
||||||
github.com/metacubex/sing-vmess v0.1.14-0.20250228002636-abc39e113b82 h1:zZp5uct9+/0Hb1jKGyqDjCU4/72t43rs7qOq3Rc9oU8=
|
github.com/metacubex/sing-vmess v0.1.14-0.20250228002636-abc39e113b82 h1:zZp5uct9+/0Hb1jKGyqDjCU4/72t43rs7qOq3Rc9oU8=
|
||||||
github.com/metacubex/sing-vmess v0.1.14-0.20250228002636-abc39e113b82/go.mod h1:nE7Mdzj/QUDwgRi/8BASPtsxtIFZTHA4Yst5GgwbGCQ=
|
github.com/metacubex/sing-vmess v0.1.14-0.20250228002636-abc39e113b82/go.mod h1:nE7Mdzj/QUDwgRi/8BASPtsxtIFZTHA4Yst5GgwbGCQ=
|
||||||
github.com/metacubex/sing-wireguard v0.0.0-20241126021510-0827d417b589 h1:Z6bNy0HLTjx6BKIkV48sV/yia/GP8Bnyb5JQuGgSGzg=
|
github.com/metacubex/sing-wireguard v0.0.0-20241126021510-0827d417b589 h1:Z6bNy0HLTjx6BKIkV48sV/yia/GP8Bnyb5JQuGgSGzg=
|
||||||
|
|
|
@ -50,8 +50,10 @@ type Tun struct {
|
||||||
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"`
|
||||||
ExcludePort []uint16 `yaml:"exclude-port" json:"exclude-port,omitempty"`
|
ExcludeSrcPort []uint16 `yaml:"exclude-src-port" json:"exclude-src-port,omitempty"`
|
||||||
ExcludePortRange []string `yaml:"exclude-port-range" json:"exclude-port-range,omitempty"`
|
ExcludeSrcPortRange []string `yaml:"exclude-src-port-range" json:"exclude-src-port-range,omitempty"`
|
||||||
|
ExcludeDstPort []uint16 `yaml:"exclude-dst-port" json:"exclude-dst-port,omitempty"`
|
||||||
|
ExcludeDstPortRange []string `yaml:"exclude-dst-port-range" json:"exclude-dst-port-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"`
|
||||||
|
|
|
@ -39,8 +39,10 @@ type TunOption struct {
|
||||||
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"`
|
||||||
ExcludePort []uint16 `yaml:"exclude-port" json:"exclude-port,omitempty"`
|
ExcludeSrcPort []uint16 `inbound:"exclude-src-port,omitempty"`
|
||||||
ExcludePortRange []string `yaml:"exclude-port-range" json:"exclude-port-range,omitempty"`
|
ExcludeSrcPortRange []string `inbound:"exclude-src-port-range,omitempty"`
|
||||||
|
ExcludeDstPort []uint16 `inbound:"exclude-dst-port,omitempty"`
|
||||||
|
ExcludeDstPortRange []string `inbound:"exclude-dst-port-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"`
|
||||||
|
@ -139,8 +141,10 @@ func NewTun(options *TunOption) (*Tun, error) {
|
||||||
IncludeUIDRange: options.IncludeUIDRange,
|
IncludeUIDRange: options.IncludeUIDRange,
|
||||||
ExcludeUID: options.ExcludeUID,
|
ExcludeUID: options.ExcludeUID,
|
||||||
ExcludeUIDRange: options.ExcludeUIDRange,
|
ExcludeUIDRange: options.ExcludeUIDRange,
|
||||||
ExcludePort: options.ExcludePort,
|
ExcludeSrcPort: options.ExcludeSrcPort,
|
||||||
ExcludePortRange: options.ExcludePortRange,
|
ExcludeSrcPortRange: options.ExcludeSrcPortRange,
|
||||||
|
ExcludeDstPort: options.ExcludeDstPort,
|
||||||
|
ExcludeDstPortRange: options.ExcludeDstPortRange,
|
||||||
IncludeAndroidUser: options.IncludeAndroidUser,
|
IncludeAndroidUser: options.IncludeAndroidUser,
|
||||||
IncludePackage: options.IncludePackage,
|
IncludePackage: options.IncludePackage,
|
||||||
ExcludePackage: options.ExcludePackage,
|
ExcludePackage: options.ExcludePackage,
|
||||||
|
|
|
@ -212,12 +212,20 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
||||||
return nil, E.Cause(err, "parse exclude_uid_range")
|
return nil, E.Cause(err, "parse exclude_uid_range")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
excludePort := uidToRange(options.ExcludePort)
|
excludeSrcPort := uidToRange(options.ExcludeSrcPort)
|
||||||
if len(options.ExcludePortRange) > 0 {
|
if len(options.ExcludeSrcPortRange) > 0 {
|
||||||
var err error
|
var err error
|
||||||
excludePort, err = parseRange(excludePort, options.ExcludePortRange)
|
excludeSrcPort, err = parseRange(excludeSrcPort, options.ExcludeSrcPortRange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, E.Cause(err, "parse exclude_port_range")
|
return nil, E.Cause(err, "parse exclude_src_port_range")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
excludeDstPort := uidToRange(options.ExcludeDstPort)
|
||||||
|
if len(options.ExcludeDstPortRange) > 0 {
|
||||||
|
var err error
|
||||||
|
excludeDstPort, err = parseRange(excludeDstPort, options.ExcludeDstPortRange)
|
||||||
|
if err != nil {
|
||||||
|
return nil, E.Cause(err, "parse exclude_dst_port_range")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +356,8 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
||||||
ExcludeInterface: options.ExcludeInterface,
|
ExcludeInterface: options.ExcludeInterface,
|
||||||
IncludeUID: includeUID,
|
IncludeUID: includeUID,
|
||||||
ExcludeUID: excludeUID,
|
ExcludeUID: excludeUID,
|
||||||
ExcludePort: excludePort,
|
ExcludeSrcPort: excludeSrcPort,
|
||||||
|
ExcludeDstPort: excludeDstPort,
|
||||||
IncludeAndroidUser: options.IncludeAndroidUser,
|
IncludeAndroidUser: options.IncludeAndroidUser,
|
||||||
IncludePackage: options.IncludePackage,
|
IncludePackage: options.IncludePackage,
|
||||||
ExcludePackage: options.ExcludePackage,
|
ExcludePackage: options.ExcludePackage,
|
||||||
|
|
Loading…
Reference in New Issue