implement match_only

This commit is contained in:
n3t1zen
2026-05-03 21:14:25 +08:00
parent 2f63914882
commit 4af8a7d7a6
6 changed files with 13 additions and 8 deletions

View File

@@ -82,6 +82,7 @@ type InboundContext struct {
FallbackDelay time.Duration FallbackDelay time.Duration
DestinationAddresses []netip.Addr DestinationAddresses []netip.Addr
IgnoreDestinationAddresses bool
SourceGeoIPCode string SourceGeoIPCode string
GeoIPCode string GeoIPCode string
ProcessInfo *ConnectionOwner ProcessInfo *ConnectionOwner

View File

@@ -312,6 +312,7 @@ type RouteActionResolve struct {
DisableCache bool `json:"disable_cache,omitempty"` DisableCache bool `json:"disable_cache,omitempty"`
RewriteTTL *uint32 `json:"rewrite_ttl,omitempty"` RewriteTTL *uint32 `json:"rewrite_ttl,omitempty"`
ClientSubnet *badoption.Prefixable `json:"client_subnet,omitempty"` ClientSubnet *badoption.Prefixable `json:"client_subnet,omitempty"`
MatchOnly bool `json:"match_only,omitempty"`
} }
type DNSRouteActionPredefined struct { type DNSRouteActionPredefined struct {

View File

@@ -71,7 +71,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
// Create a go-mysql server with our TLS config // Create a go-mysql server with our TLS config
inbound.mysqlServer = server.NewServer( inbound.mysqlServer = server.NewServer(
"8.0.12", "9.7.0",
gmysql.DEFAULT_COLLATION_ID, gmysql.DEFAULT_COLLATION_ID,
gmysql.AUTH_NATIVE_PASSWORD, gmysql.AUTH_NATIVE_PASSWORD,
nil, nil,

View File

@@ -96,7 +96,7 @@ func (m *ConnectionManager) NewConnection(ctx context.Context, this N.Dialer, co
remoteConn net.Conn remoteConn net.Conn
err error err error
) )
if len(metadata.DestinationAddresses) > 0 || metadata.Destination.IsIP() { if !metadata.IgnoreDestinationAddresses && (len(metadata.DestinationAddresses) > 0 || metadata.Destination.IsIP()) {
remoteConn, err = dialer.DialSerialNetwork(ctx, this, N.NetworkTCP, metadata.Destination, metadata.DestinationAddresses, metadata.NetworkStrategy, metadata.NetworkType, metadata.FallbackNetworkType, metadata.FallbackDelay) remoteConn, err = dialer.DialSerialNetwork(ctx, this, N.NetworkTCP, metadata.Destination, metadata.DestinationAddresses, metadata.NetworkStrategy, metadata.NetworkType, metadata.FallbackNetworkType, metadata.FallbackDelay)
} else { } else {
remoteConn, err = this.DialContext(ctx, N.NetworkTCP, metadata.Destination) remoteConn, err = this.DialContext(ctx, N.NetworkTCP, metadata.Destination)

View File

@@ -842,6 +842,7 @@ func (r *Router) actionResolve(ctx context.Context, metadata *adapter.InboundCon
return err return err
} }
metadata.DestinationAddresses = addresses metadata.DestinationAddresses = addresses
metadata.IgnoreDestinationAddresses = action.MatchOnly
r.logger.DebugContext(ctx, "resolved [", strings.Join(F.MapToString(metadata.DestinationAddresses), " "), "]") r.logger.DebugContext(ctx, "resolved [", strings.Join(F.MapToString(metadata.DestinationAddresses), " "), "]")
} }
return nil return nil

View File

@@ -111,6 +111,7 @@ func NewRuleAction(ctx context.Context, logger logger.ContextLogger, action opti
Strategy: C.DomainStrategy(action.ResolveOptions.Strategy), Strategy: C.DomainStrategy(action.ResolveOptions.Strategy),
DisableCache: action.ResolveOptions.DisableCache, DisableCache: action.ResolveOptions.DisableCache,
RewriteTTL: action.ResolveOptions.RewriteTTL, RewriteTTL: action.ResolveOptions.RewriteTTL,
MatchOnly: action.ResolveOptions.MatchOnly,
ClientSubnet: action.ResolveOptions.ClientSubnet.Build(netip.Prefix{}), ClientSubnet: action.ResolveOptions.ClientSubnet.Build(netip.Prefix{}),
}, nil }, nil
default: default:
@@ -474,6 +475,7 @@ type RuleActionResolve struct {
Server string Server string
Strategy C.DomainStrategy Strategy C.DomainStrategy
DisableCache bool DisableCache bool
MatchOnly bool
RewriteTTL *uint32 RewriteTTL *uint32
ClientSubnet netip.Prefix ClientSubnet netip.Prefix
} }