From 4af8a7d7a69dcd2326363033cc9a5f01171a9424 Mon Sep 17 00:00:00 2001 From: n3t1zen Date: Sun, 3 May 2026 21:14:25 +0800 Subject: [PATCH] implement match_only --- adapter/inbound.go | 13 +++++++------ option/rule_action.go | 1 + protocol/mysql/inbound.go | 2 +- route/conn.go | 2 +- route/route.go | 1 + route/rule/rule_action.go | 2 ++ 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/adapter/inbound.go b/adapter/inbound.go index 1941df5b..bb950c86 100644 --- a/adapter/inbound.go +++ b/adapter/inbound.go @@ -81,12 +81,13 @@ type InboundContext struct { FallbackNetworkType []C.InterfaceType FallbackDelay time.Duration - DestinationAddresses []netip.Addr - SourceGeoIPCode string - GeoIPCode string - ProcessInfo *ConnectionOwner - QueryType uint16 - FakeIP bool + DestinationAddresses []netip.Addr + IgnoreDestinationAddresses bool + SourceGeoIPCode string + GeoIPCode string + ProcessInfo *ConnectionOwner + QueryType uint16 + FakeIP bool // rule cache diff --git a/option/rule_action.go b/option/rule_action.go index 43108255..24e8863b 100644 --- a/option/rule_action.go +++ b/option/rule_action.go @@ -312,6 +312,7 @@ type RouteActionResolve struct { DisableCache bool `json:"disable_cache,omitempty"` RewriteTTL *uint32 `json:"rewrite_ttl,omitempty"` ClientSubnet *badoption.Prefixable `json:"client_subnet,omitempty"` + MatchOnly bool `json:"match_only,omitempty"` } type DNSRouteActionPredefined struct { diff --git a/protocol/mysql/inbound.go b/protocol/mysql/inbound.go index dbf9a98e..fe759fee 100644 --- a/protocol/mysql/inbound.go +++ b/protocol/mysql/inbound.go @@ -71,7 +71,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo // Create a go-mysql server with our TLS config inbound.mysqlServer = server.NewServer( - "8.0.12", + "9.7.0", gmysql.DEFAULT_COLLATION_ID, gmysql.AUTH_NATIVE_PASSWORD, nil, diff --git a/route/conn.go b/route/conn.go index 899d2939..618e986c 100644 --- a/route/conn.go +++ b/route/conn.go @@ -96,7 +96,7 @@ func (m *ConnectionManager) NewConnection(ctx context.Context, this N.Dialer, co remoteConn net.Conn 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) } else { remoteConn, err = this.DialContext(ctx, N.NetworkTCP, metadata.Destination) diff --git a/route/route.go b/route/route.go index 70444b01..91a76be8 100644 --- a/route/route.go +++ b/route/route.go @@ -842,6 +842,7 @@ func (r *Router) actionResolve(ctx context.Context, metadata *adapter.InboundCon return err } metadata.DestinationAddresses = addresses + metadata.IgnoreDestinationAddresses = action.MatchOnly r.logger.DebugContext(ctx, "resolved [", strings.Join(F.MapToString(metadata.DestinationAddresses), " "), "]") } return nil diff --git a/route/rule/rule_action.go b/route/rule/rule_action.go index cac814e7..10d1a06c 100644 --- a/route/rule/rule_action.go +++ b/route/rule/rule_action.go @@ -111,6 +111,7 @@ func NewRuleAction(ctx context.Context, logger logger.ContextLogger, action opti Strategy: C.DomainStrategy(action.ResolveOptions.Strategy), DisableCache: action.ResolveOptions.DisableCache, RewriteTTL: action.ResolveOptions.RewriteTTL, + MatchOnly: action.ResolveOptions.MatchOnly, ClientSubnet: action.ResolveOptions.ClientSubnet.Build(netip.Prefix{}), }, nil default: @@ -474,6 +475,7 @@ type RuleActionResolve struct { Server string Strategy C.DomainStrategy DisableCache bool + MatchOnly bool RewriteTTL *uint32 ClientSubnet netip.Prefix }