diff --git a/constant/rule.go b/constant/rule.go index 251ed4e9..f8670f7d 100644 --- a/constant/rule.go +++ b/constant/rule.go @@ -34,7 +34,6 @@ const ( RuleActionTypeRouteOptions = "route-options" RuleActionTypeEvaluate = "evaluate" RuleActionTypeRespond = "respond" - RuleActionTypeDirect = "direct" RuleActionTypeBypass = "bypass" RuleActionTypeReject = "reject" RuleActionTypeHijackDNS = "hijack-dns" diff --git a/docs/schema.json b/docs/schema.json index 96107d14..0b674f31 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -14982,112 +14982,6 @@ "action" ] }, - { - "type": "object", - "properties": { - "action": { - "const": "direct" - }, - "bind_interface": { - "type": "string" - }, - "inet4_bind_address": { - "type": "string" - }, - "inet6_bind_address": { - "type": "string" - }, - "bind_address_no_port": { - "type": "boolean" - }, - "protect_path": { - "type": "string" - }, - "routing_mark": { - "anyOf": [ - { - "type": "integer", - "minimum": 0, - "maximum": 4294967295 - }, - { - "type": "string" - } - ] - }, - "reuse_addr": { - "type": "boolean" - }, - "netns": { - "type": "string", - "x-tag-reference": "network_namespace" - }, - "connect_timeout": { - "$ref": "#/$defs/Duration" - }, - "tcp_fast_open": { - "type": "boolean" - }, - "tcp_multi_path": { - "type": "boolean" - }, - "disable_tcp_keep_alive": { - "type": "boolean" - }, - "tcp_keep_alive": { - "$ref": "#/$defs/Duration" - }, - "tcp_keep_alive_interval": { - "$ref": "#/$defs/Duration" - }, - "udp_fragment": { - "type": "boolean" - }, - "domain_resolver": { - "$ref": "#/$defs/DomainResolver" - }, - "network_strategy": { - "type": "string", - "enum": [ - "default", - "fallback", - "hybrid" - ] - }, - "network_type": { - "anyOf": [ - { - "$ref": "#/$defs/InterfaceType" - }, - { - "type": "array", - "items": { - "$ref": "#/$defs/InterfaceType" - } - } - ] - }, - "fallback_network_type": { - "anyOf": [ - { - "$ref": "#/$defs/InterfaceType" - }, - { - "type": "array", - "items": { - "$ref": "#/$defs/InterfaceType" - } - } - ] - }, - "fallback_delay": { - "$ref": "#/$defs/Duration" - } - }, - "required": [ - "action" - ] - }, { "type": "object", "properties": { diff --git a/option/rule_action.go b/option/rule_action.go index ae052004..e9bf1e16 100644 --- a/option/rule_action.go +++ b/option/rule_action.go @@ -2,10 +2,7 @@ package option import ( "context" - "fmt" - "net/netip" "reflect" - "time" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/schema" @@ -16,10 +13,9 @@ import ( ) type _RuleAction struct { - Action string `json:"action,omitempty" enum:"route,route-options,direct,bypass,reject,hijack-dns,sniff,resolve"` + Action string `json:"action,omitempty" enum:"route,route-options,bypass,reject,hijack-dns,sniff,resolve"` RouteOptions RouteActionOptions `json:"-"` RouteOptionsOptions RouteOptionsActionOptions `json:"-"` - DirectOptions DirectActionOptions `json:"-"` BypassOptions RouteActionOptions `json:"-"` RejectOptions RejectActionOptions `json:"-"` SniffOptions RouteActionSniff `json:"-"` @@ -39,8 +35,6 @@ func (r RuleAction) MarshalJSON() ([]byte, error) { v = r.RouteOptions case C.RuleActionTypeRouteOptions: v = r.RouteOptionsOptions - case C.RuleActionTypeDirect: - v = r.DirectOptions case C.RuleActionTypeBypass: v = r.BypassOptions case C.RuleActionTypeReject: @@ -72,8 +66,6 @@ func (r *RuleAction) UnmarshalJSON(data []byte) error { v = &r.RouteOptions case C.RuleActionTypeRouteOptions: v = &r.RouteOptionsOptions - case C.RuleActionTypeDirect: - v = &r.DirectOptions case C.RuleActionTypeBypass: v = &r.BypassOptions case C.RuleActionTypeReject: @@ -246,48 +238,6 @@ func (r *DNSRouteOptionsActionOptions) UnmarshalJSON(data []byte) error { return nil } -type DirectActionOptions struct { - AbstractDialerOptions -} - -func (d DirectActionOptions) Descriptions() []string { - var descriptions []string - if d.BindInterface != "" { - descriptions = append(descriptions, "bind_interface="+d.BindInterface) - } - if d.Inet4BindAddress != nil { - descriptions = append(descriptions, "inet4_bind_address="+d.Inet4BindAddress.Build(netip.IPv4Unspecified()).String()) - } - if d.Inet6BindAddress != nil { - descriptions = append(descriptions, "inet6_bind_address="+d.Inet6BindAddress.Build(netip.IPv6Unspecified()).String()) - } - if d.RoutingMark != 0 { - descriptions = append(descriptions, "routing_mark="+fmt.Sprintf("0x%x", d.RoutingMark)) - } - if d.ReuseAddr { - descriptions = append(descriptions, "reuse_addr") - } - if d.ConnectTimeout != 0 { - descriptions = append(descriptions, "connect_timeout="+time.Duration(d.ConnectTimeout).String()) - } - if d.TCPFastOpen { - descriptions = append(descriptions, "tcp_fast_open") - } - if d.TCPMultiPath { - descriptions = append(descriptions, "tcp_multi_path") - } - if d.UDPFragment != nil { - descriptions = append(descriptions, "udp_fragment="+fmt.Sprint(*d.UDPFragment)) - } - if d.DomainStrategy != DomainStrategy(C.DomainStrategyAsIS) { - descriptions = append(descriptions, "domain_strategy="+d.DomainStrategy.String()) - } - if d.FallbackDelay != 0 { - descriptions = append(descriptions, "fallback_delay="+time.Duration(d.FallbackDelay).String()) - } - return descriptions -} - type _RejectActionOptions struct { Method string `json:"method,omitempty" enum:"default,drop,reply"` NoDrop bool `json:"no_drop,omitempty"` @@ -391,7 +341,6 @@ func routeActionUnion(builder schema.Builder) (*schema.Node, error) { return actionUnion(builder, []actionVariant{ {action: C.RuleActionTypeRoute, actionOptional: true, structType: reflect.TypeFor[RouteActionOptions]()}, {action: C.RuleActionTypeRouteOptions, structType: reflect.TypeFor[RawRouteOptionsActionOptions]()}, - {action: C.RuleActionTypeDirect, structType: reflect.TypeFor[DirectActionOptions]()}, {action: C.RuleActionTypeBypass, structType: reflect.TypeFor[RouteActionOptions]()}, {action: C.RuleActionTypeReject, build: rejectProperties}, {action: C.RuleActionTypeHijackDNS}, diff --git a/route/reference_rule.go b/route/reference_rule.go index 86464b65..ebf8ee31 100644 --- a/route/reference_rule.go +++ b/route/reference_rule.go @@ -125,7 +125,7 @@ func collectRuleReferences(rules []option.Rule, mode string, outbounds *[]string *outbounds = append(*outbounds, action.BypassOptions.Outbound) final = true } - case C.RuleActionTypeDirect, C.RuleActionTypeReject, C.RuleActionTypeHijackDNS: + case C.RuleActionTypeReject, C.RuleActionTypeHijackDNS: final = true case C.RuleActionTypeResolve: *transports = append(*transports, action.ResolveOptions.Server) diff --git a/route/rule/rule_action.go b/route/rule/rule_action.go index cb656118..6fd1707a 100644 --- a/route/rule/rule_action.go +++ b/route/rule/rule_action.go @@ -9,7 +9,6 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/dialer" "github.com/sagernet/sing-box/common/sniff" "github.com/sagernet/sing-box/common/tlsspoof" C "github.com/sagernet/sing-box/constant" @@ -19,7 +18,6 @@ import ( F "github.com/sagernet/sing/common/format" "github.com/sagernet/sing/common/logger" M "github.com/sagernet/sing/common/metadata" - N "github.com/sagernet/sing/common/network" "github.com/miekg/dns" ) @@ -45,7 +43,7 @@ func newRuleActionRouteOptions(options option.RawRouteOptionsActionOptions) (Rul }, nil } -func NewRuleAction(ctx context.Context, logger logger.ContextLogger, action option.RuleAction) (adapter.RuleAction, error) { +func NewRuleAction(logger logger.ContextLogger, action option.RuleAction) (adapter.RuleAction, error) { switch action.Action { case "": return nil, nil @@ -73,28 +71,6 @@ func NewRuleAction(ctx context.Context, logger logger.ContextLogger, action opti Outbound: action.BypassOptions.Outbound, RuleActionRouteOptions: routeOptions, }, nil - case C.RuleActionTypeDirect: - directDialer, err := dialer.New(ctx, option.DialerOptions{ - AbstractDialerOptions: action.DirectOptions.AbstractDialerOptions, - }, false) - if err != nil { - return nil, err - } - var description string - descriptions := action.DirectOptions.Descriptions() - switch len(descriptions) { - case 0: - case 1: - description = F.ToString("(", descriptions[0], ")") - case 2: - description = F.ToString("(", descriptions[0], ",", descriptions[1], ")") - default: - description = F.ToString("(", descriptions[0], ",", descriptions[1], ",...)") - } - return &RuleActionDirect{ - Dialer: directDialer, - description: description, - }, nil case C.RuleActionTypeReject: return &RuleActionReject{ Method: action.RejectOptions.Method, @@ -395,19 +371,6 @@ func (r *RuleActionDNSRouteOptions) String() string { return F.ToString("route-options(", strings.Join(descriptions, ","), ")") } -type RuleActionDirect struct { - Dialer N.Dialer - description string -} - -func (r *RuleActionDirect) Type() string { - return C.RuleActionTypeDirect -} - -func (r *RuleActionDirect) String() string { - return "direct" + r.description -} - var ( ErrReset = E.New("connection reset") ErrDrop = E.New("packet dropped") diff --git a/route/rule/rule_default.go b/route/rule/rule_default.go index 3aef4a1c..7950b7e2 100644 --- a/route/rule/rule_default.go +++ b/route/rule/rule_default.go @@ -53,7 +53,7 @@ type RuleItem interface { } func NewDefaultRule(ctx context.Context, logger log.ContextLogger, options option.DefaultRule) (*DefaultRule, error) { - action, err := NewRuleAction(ctx, logger, options.RuleAction) + action, err := NewRuleAction(logger, options.RuleAction) if err != nil { return nil, E.Cause(err, "action") } @@ -306,7 +306,7 @@ type LogicalRule struct { } func NewLogicalRule(ctx context.Context, logger log.ContextLogger, options option.LogicalRule) (*LogicalRule, error) { - action, err := NewRuleAction(ctx, logger, options.RuleAction) + action, err := NewRuleAction(logger, options.RuleAction) if err != nil { return nil, E.Cause(err, "action") }