wwqgtxx a9ce5da09d
Some checks failed
Build / build (map[abi:1 goarch:loong64 goos:linux output:loong64-abi1]) (push) Failing after 17m35s
Build / build (map[abi:2 goarch:loong64 goos:linux output:loong64-abi2]) (push) Failing after 6m14s
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin goversion:1.20 output:amd64-compatible-go120]) (push) Failing after 4m27s
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin goversion:1.22 output:amd64-compatible-go122]) (push) Failing after 3m49s
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin output:amd64-compatible]) (push) Failing after 2m56s
Build / build (map[goamd64:v1 goarch:amd64 goos:freebsd output:amd64-compatible]) (push) Failing after 4m31s
Build / build (map[goamd64:v1 goarch:amd64 goos:linux goversion:1.20 output:amd64-compatible-go120 test:test]) (push) Failing after 4m16s
Build / build (map[goamd64:v1 goarch:amd64 goos:linux output:amd64-compatible test:test]) (push) Failing after 5m3s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.20 output:amd64-compatible-go120]) (push) Failing after 8m5s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.21 output:amd64-compatible-go121]) (push) Failing after 2m4s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.22 output:amd64-compatible-go122]) (push) Failing after 1m59s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows output:amd64-compatible]) (push) Failing after 2m6s
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin goversion:1.20 output:amd64-go120]) (push) Failing after 3m13s
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin goversion:1.22 output:amd64-go122]) (push) Failing after 3m6s
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin output:amd64]) (push) Failing after 5m4s
Build / build (map[goamd64:v3 goarch:amd64 goos:freebsd output:amd64]) (push) Failing after 5m26s
Build / build (map[goamd64:v3 goarch:amd64 goos:linux goversion:1.20 output:amd64-go120]) (push) Failing after 4m52s
Build / build (map[goamd64:v3 goarch:amd64 goos:linux output:amd64]) (push) Failing after 4m35s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.20 output:amd64-go120]) (push) Failing after 3m52s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.21 output:amd64-go121]) (push) Failing after 3m48s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.22 output:amd64-go122]) (push) Failing after 1m6s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows output:amd64]) (push) Failing after 1m34s
Build / build (map[goarch:386 goos:android ndk:i686-linux-android34 output:386]) (push) Failing after 4m59s
Build / build (map[goarch:386 goos:freebsd output:386]) (push) Failing after 3m21s
Build / build (map[goarch:386 goos:linux goversion:1.20 output:386-go120]) (push) Failing after 3m36s
Build / build (map[goarch:386 goos:linux output:386]) (push) Failing after 2m36s
Build / build (map[goarch:386 goos:windows goversion:1.20 output:386-go120]) (push) Failing after 2m32s
Build / build (map[goarch:386 goos:windows goversion:1.21 output:386-go121]) (push) Failing after 2m40s
Build / build (map[goarch:386 goos:windows goversion:1.22 output:386-go122]) (push) Failing after 1m24s
Build / build (map[goarch:386 goos:windows output:386]) (push) Failing after 1m36s
Build / build (map[goarch:amd64 goos:android ndk:x86_64-linux-android34 output:amd64]) (push) Failing after 3m41s
Build / build (map[goarch:arm goarm:5 goos:linux output:armv5]) (push) Failing after 3m21s
Build / build (map[goarch:arm goarm:6 goos:linux output:armv6]) (push) Failing after 3m29s
Build / build (map[goarch:arm goarm:7 goos:linux output:armv7]) (push) Failing after 2m57s
Build / build (map[goarch:arm goarm:7 goos:windows output:armv7]) (push) Failing after 54s
Build / build (map[goarch:arm goos:android ndk:armv7a-linux-androideabi34 output:armv7]) (push) Failing after 3m55s
Build / build (map[goarch:arm64 goos:android ndk:aarch64-linux-android34 output:arm64-v8]) (push) Failing after 3m37s
Build / build (map[goarch:arm64 goos:darwin goversion:1.20 output:arm64-go120]) (push) Failing after 1m50s
Build / build (map[goarch:arm64 goos:darwin goversion:1.22 output:arm64-go122]) (push) Failing after 1m59s
Build / build (map[goarch:arm64 goos:darwin output:arm64]) (push) Failing after 2m50s
Build / build (map[goarch:arm64 goos:freebsd output:arm64]) (push) Failing after 2m18s
Build / build (map[goarch:arm64 goos:linux output:arm64]) (push) Failing after 2m36s
Build / build (map[goarch:arm64 goos:windows output:arm64]) (push) Failing after 1m14s
Build / build (map[goarch:mips gomips:hardfloat goos:linux output:mips-hardfloat]) (push) Failing after 2m14s
Build / build (map[goarch:mips gomips:softfloat goos:linux output:mips-softfloat]) (push) Failing after 2m4s
Build / build (map[goarch:mips64 goos:linux output:mips64]) (push) Failing after 2m49s
Build / build (map[goarch:mips64le goos:linux output:mips64le]) (push) Failing after 2m30s
Build / build (map[goarch:mipsle gomips:hardfloat goos:linux output:mipsle-hardfloat]) (push) Failing after 2m6s
Build / build (map[goarch:mipsle gomips:softfloat goos:linux output:mipsle-softfloat]) (push) Failing after 30s
Build / build (map[goarch:riscv64 goos:linux output:riscv64]) (push) Failing after 2m20s
Build / build (map[goarch:s390x goos:linux output:s390x]) (push) Failing after 2m34s
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 1m52s
Build / Upload-Prerelease (push) Has been skipped
Build / Upload-Release (push) Has been skipped
Build / Docker (push) Has been skipped
fix: key missing for tun inbound
https://github.com/MetaCubeX/mihomo/issues/1672
2024-12-28 11:39:45 +08:00

182 lines
6.7 KiB
Go

package inbound
import (
"errors"
"strings"
C "github.com/metacubex/mihomo/constant"
LC "github.com/metacubex/mihomo/listener/config"
"github.com/metacubex/mihomo/listener/sing_tun"
"github.com/metacubex/mihomo/log"
)
type TunOption struct {
BaseOption
Device string `inbound:"device,omitempty"`
Stack string `inbound:"stack,omitempty"`
DNSHijack []string `inbound:"dns-hijack,omitempty"`
AutoRoute bool `inbound:"auto-route,omitempty"`
AutoDetectInterface bool `inbound:"auto-detect-interface,omitempty"`
MTU uint32 `inbound:"mtu,omitempty"`
GSO bool `inbound:"gso,omitempty"`
GSOMaxSize uint32 `inbound:"gso-max-size,omitempty"`
Inet4Address []string `inbound:"inet4-address,omitempty"`
Inet6Address []string `inbound:"inet6-address,omitempty"`
IPRoute2TableIndex int `inbound:"iproute2-table-index,omitempty"`
IPRoute2RuleIndex int `inbound:"iproute2-rule-index,omitempty"`
AutoRedirect bool `inbound:"auto-redirect,omitempty"`
AutoRedirectInputMark uint32 `inbound:"auto-redirect-input-mark,omitempty"`
AutoRedirectOutputMark uint32 `inbound:"auto-redirect-output-mark,omitempty"`
StrictRoute bool `inbound:"strict-route,omitempty"`
RouteAddress []string `inbound:"route-address,omitempty"`
RouteAddressSet []string `inbound:"route-address-set,omitempty"`
RouteExcludeAddress []string `inbound:"route-exclude-address,omitempty"`
RouteExcludeAddressSet []string `inbound:"route-exclude-address-set,omitempty"`
IncludeInterface []string `inbound:"include-interface,omitempty"`
ExcludeInterface []string `inbound:"exclude-interface,omitempty"`
IncludeUID []uint32 `inbound:"include-uid,omitempty"`
IncludeUIDRange []string `inbound:"include-uid-range,omitempty"`
ExcludeUID []uint32 `inbound:"exclude-uid,omitempty"`
ExcludeUIDRange []string `inbound:"exclude-uid-range,omitempty"`
IncludeAndroidUser []int `inbound:"include-android-user,omitempty"`
IncludePackage []string `inbound:"include-package,omitempty"`
ExcludePackage []string `inbound:"exclude-package,omitempty"`
EndpointIndependentNat bool `inbound:"endpoint-independent-nat,omitempty"`
UDPTimeout int64 `inbound:"udp-timeout,omitempty"`
FileDescriptor int `inbound:"file-descriptor,omitempty"`
Inet4RouteAddress []string `inbound:"inet4-route-address,omitempty"`
Inet6RouteAddress []string `inbound:"inet6-route-address,omitempty"`
Inet4RouteExcludeAddress []string `inbound:"inet4-route-exclude-address,omitempty"`
Inet6RouteExcludeAddress []string `inbound:"inet6-route-exclude-address,omitempty"`
}
func (o TunOption) Equal(config C.InboundConfig) bool {
return optionToString(o) == optionToString(config)
}
type Tun struct {
*Base
config *TunOption
l *sing_tun.Listener
tun LC.Tun
}
func NewTun(options *TunOption) (*Tun, error) {
base, err := NewBase(&options.BaseOption)
if err != nil {
return nil, err
}
stack, exist := C.StackTypeMapping[strings.ToLower(options.Stack)]
if !exist {
return nil, errors.New("invalid tun stack")
}
routeAddress, err := LC.StringSliceToNetipPrefixSlice(options.RouteAddress)
if err != nil {
return nil, err
}
routeExcludeAddress, err := LC.StringSliceToNetipPrefixSlice(options.RouteExcludeAddress)
if err != nil {
return nil, err
}
inet4Address, err := LC.StringSliceToNetipPrefixSlice(options.Inet4Address)
if err != nil {
return nil, err
}
inet6Address, err := LC.StringSliceToNetipPrefixSlice(options.Inet6Address)
if err != nil {
return nil, err
}
inet4RouteAddress, err := LC.StringSliceToNetipPrefixSlice(options.Inet4RouteAddress)
if err != nil {
return nil, err
}
inet6RouteAddress, err := LC.StringSliceToNetipPrefixSlice(options.Inet6RouteAddress)
if err != nil {
return nil, err
}
inet4RouteExcludeAddress, err := LC.StringSliceToNetipPrefixSlice(options.Inet4RouteExcludeAddress)
if err != nil {
return nil, err
}
inet6RouteExcludeAddress, err := LC.StringSliceToNetipPrefixSlice(options.Inet6RouteExcludeAddress)
if err != nil {
return nil, err
}
return &Tun{
Base: base,
config: options,
tun: LC.Tun{
Enable: true,
Device: options.Device,
Stack: stack,
DNSHijack: options.DNSHijack,
AutoRoute: options.AutoRoute,
AutoDetectInterface: options.AutoDetectInterface,
MTU: options.MTU,
GSO: options.GSO,
GSOMaxSize: options.GSOMaxSize,
Inet4Address: inet4Address,
Inet6Address: inet6Address,
IPRoute2TableIndex: options.IPRoute2TableIndex,
IPRoute2RuleIndex: options.IPRoute2RuleIndex,
AutoRedirect: options.AutoRedirect,
AutoRedirectInputMark: options.AutoRedirectInputMark,
AutoRedirectOutputMark: options.AutoRedirectOutputMark,
StrictRoute: options.StrictRoute,
RouteAddress: routeAddress,
RouteAddressSet: options.RouteAddressSet,
RouteExcludeAddress: routeExcludeAddress,
RouteExcludeAddressSet: options.RouteExcludeAddressSet,
IncludeInterface: options.IncludeInterface,
ExcludeInterface: options.ExcludeInterface,
IncludeUID: options.IncludeUID,
IncludeUIDRange: options.IncludeUIDRange,
ExcludeUID: options.ExcludeUID,
ExcludeUIDRange: options.ExcludeUIDRange,
IncludeAndroidUser: options.IncludeAndroidUser,
IncludePackage: options.IncludePackage,
ExcludePackage: options.ExcludePackage,
EndpointIndependentNat: options.EndpointIndependentNat,
UDPTimeout: options.UDPTimeout,
FileDescriptor: options.FileDescriptor,
Inet4RouteAddress: inet4RouteAddress,
Inet6RouteAddress: inet6RouteAddress,
Inet4RouteExcludeAddress: inet4RouteExcludeAddress,
Inet6RouteExcludeAddress: inet6RouteExcludeAddress,
},
}, nil
}
// Config implements constant.InboundListener
func (t *Tun) Config() C.InboundConfig {
return t.config
}
// Address implements constant.InboundListener
func (t *Tun) Address() string {
return t.l.Address()
}
// Listen implements constant.InboundListener
func (t *Tun) Listen(tunnel C.Tunnel) error {
var err error
t.l, err = sing_tun.New(t.tun, tunnel, t.Additions()...)
if err != nil {
return err
}
log.Infoln("Tun[%s] proxy listening at: %s", t.Name(), t.Address())
return nil
}
// Close implements constant.InboundListener
func (t *Tun) Close() error {
return t.l.Close()
}
var _ C.InboundListener = (*Tun)(nil)