This commit is contained in:
世界 2025-02-18 17:30:03 +08:00
parent f2d26f5842
commit 00870d2833
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
17 changed files with 29 additions and 18 deletions

View file

@ -12,6 +12,11 @@ import (
mDNS "github.com/miekg/dns"
)
var (
DefaultNetworks = []string{N.NetworkTCP, N.NetworkUDP}
DefaultIPNetworks = []string{N.NetworkTCP, N.NetworkUDP, N.NetworkICMPv4, N.NetworkICMPv6}
)
type NetworkList string
func (v *NetworkList) UnmarshalJSON(content []byte) error {
@ -37,9 +42,9 @@ func (v *NetworkList) UnmarshalJSON(content []byte) error {
return nil
}
func (v NetworkList) Build() []string {
func (v NetworkList) Build(defaultNetworks []string) []string {
if v == "" {
return []string{N.NetworkTCP, N.NetworkUDP}
return defaultNetworks
}
return strings.Split(string(v), "\n")
}

View file

@ -60,7 +60,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
inbound.listener = listener.New(listener.Options{
Context: ctx,
Logger: logger,
Network: options.Network.Build(),
Network: options.Network.Build(option.DefaultIPNetworks),
Listen: options.ListenOptions,
ConnectionHandler: inbound,
PacketHandler: inbound,

View file

@ -2,6 +2,7 @@ package direct
import (
"context"
"github.com/sagernet/sing-tun"
"net"
"net/netip"
"time"
@ -27,6 +28,7 @@ func RegisterOutbound(registry *outbound.Registry) {
var (
_ N.ParallelDialer = (*Outbound)(nil)
_ dialer.ParallelNetworkDialer = (*Outbound)(nil)
_ adapter.DirectRouteOutbound = (*Outbound)(nil)
)
type Outbound struct {
@ -50,7 +52,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeDirect, tag, []string{N.NetworkTCP, N.NetworkUDP}, options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeDirect, tag, option.DefaultIPNetworks, options.DialerOptions),
logger: logger,
//nolint:staticcheck
domainStrategy: C.DomainStrategy(options.DomainStrategy),
@ -242,6 +244,10 @@ func (h *Outbound) ListenSerialNetworkPacket(ctx context.Context, destination M.
return conn, newDestination, nil
}
func (h *Outbound) NewDirectRouteConnection(metadata adapter.InboundContext, routeContext tun.DirectRouteContext) (tun.DirectRouteDestination, error) {
}
/*func (h *Outbound) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
if h.loopBack.CheckConn(metadata.Source.AddrPort(), M.AddrPortFromNet(conn.LocalAddr())) {
return E.New("reject loopback connection to ", metadata.Destination)

View file

@ -52,7 +52,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
if err != nil {
return nil, err
}
networkList := options.Network.Build()
networkList := options.Network.Build(option.DefaultIPNetworks)
var password string
if options.AuthString != "" {
password = options.AuthString

View file

@ -64,7 +64,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
if err != nil {
return nil, err
}
networkList := options.Network.Build()
networkList := options.Network.Build(option.DefaultIPNetworks)
client, err := hysteria2.NewClient(hysteria2.ClientOptions{
Context: ctx,
Dialer: outboundDialer,

View file

@ -57,7 +57,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
Listen: options.ListenOptions,
}),
networkIsDefault: options.Network == "",
network: options.Network.Build(),
network: options.Network.Build(option.DefaultIPNetworks),
authenticator: auth.NewAuthenticator(options.Users),
}
if common.Contains(inbound.network, N.NetworkUDP) {

View file

@ -53,7 +53,7 @@ func NewTProxy(ctx context.Context, router adapter.Router, logger log.ContextLog
tproxy.listener = listener.New(listener.Options{
Context: ctx,
Logger: logger,
Network: options.Network.Build(),
Network: options.Network.Build(option.DefaultIPNetworks),
Listen: options.ListenOptions,
ConnectionHandler: tproxy,
OOBPacketHandler: tproxy,

View file

@ -84,7 +84,7 @@ func newInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
inbound.listener = listener.New(listener.Options{
Context: ctx,
Logger: logger,
Network: options.Network.Build(),
Network: options.Network.Build(option.DefaultIPNetworks),
Listen: options.ListenOptions,
ConnectionHandler: inbound,
PacketHandler: inbound,

View file

@ -92,7 +92,7 @@ func newMultiInbound(ctx context.Context, router adapter.Router, logger log.Cont
inbound.listener = listener.New(listener.Options{
Context: ctx,
Logger: logger,
Network: options.Network.Build(),
Network: options.Network.Build(option.DefaultIPNetworks),
Listen: options.ListenOptions,
ConnectionHandler: inbound,
PacketHandler: inbound,

View file

@ -77,7 +77,7 @@ func newRelayInbound(ctx context.Context, router adapter.Router, logger log.Cont
inbound.listener = listener.New(listener.Options{
Context: ctx,
Logger: logger,
Network: options.Network.Build(),
Network: options.Network.Build(option.DefaultIPNetworks),
Listen: options.ListenOptions,
ConnectionHandler: inbound,
PacketHandler: inbound,

View file

@ -49,7 +49,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeShadowsocks, tag, options.Network.Build(), options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeShadowsocks, tag, options.Network.Build(option.DefaultIPNetworks), options.DialerOptions),
logger: logger,
dialer: outboundDialer,
method: method,

View file

@ -51,7 +51,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeSOCKS, tag, options.Network.Build(), options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeSOCKS, tag, options.Network.Build(option.DefaultIPNetworks), options.DialerOptions),
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),
logger: logger,
client: socks.NewClient(outboundDialer, options.ServerOptions.Build(), version, options.Username, options.Password),

View file

@ -43,7 +43,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeTrojan, tag, options.Network.Build(), options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeTrojan, tag, options.Network.Build(option.DefaultIPNetworks), options.DialerOptions),
logger: logger,
dialer: outboundDialer,
serverAddr: options.ServerOptions.Build(),

View file

@ -80,7 +80,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
return &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeTUIC, tag, options.Network.Build(), options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeTUIC, tag, options.Network.Build(option.DefaultIPNetworks), options.DialerOptions),
logger: logger,
client: client,
udpStream: options.UDPOverStream,

View file

@ -46,7 +46,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeVLESS, tag, options.Network.Build(), options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeVLESS, tag, options.Network.Build(option.DefaultIPNetworks), options.DialerOptions),
logger: logger,
dialer: outboundDialer,
serverAddr: options.ServerOptions.Build(),

View file

@ -46,7 +46,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeVMess, tag, options.Network.Build(), options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeVMess, tag, options.Network.Build(option.DefaultIPNetworks), options.DialerOptions),
logger: logger,
dialer: outboundDialer,
serverAddr: options.ServerOptions.Build(),

View file

@ -45,7 +45,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
deprecated.Report(ctx, deprecated.OptionWireGuardGSO)
}
outbound := &Outbound{
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeWireGuard, tag, []string{N.NetworkTCP, N.NetworkUDP}, options.DialerOptions),
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeWireGuard, tag, option.DefaultNetworks, options.DialerOptions),
ctx: ctx,
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),
logger: logger,