@@ -246,31 +246,39 @@ type RawTun struct {
246
246
DNSHijack []string `yaml:"dns-hijack" json:"dns-hijack"`
247
247
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
248
248
AutoDetectInterface bool `yaml:"auto-detect-interface"`
249
- RedirectToTun []string `yaml:"-" json:"-"`
250
249
251
250
MTU uint32 `yaml:"mtu" json:"mtu,omitempty"`
252
251
GSO bool `yaml:"gso" json:"gso,omitempty"`
253
252
GSOMaxSize uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
254
253
//Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4_address,omitempty"`
255
- Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6_address,omitempty"`
256
- StrictRoute bool `yaml:"strict-route" json:"strict_route,omitempty"`
254
+ Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6_address,omitempty"`
255
+ IPRoute2TableIndex int `yaml:"iproute2-table-index" json:"iproute2_table_index,omitempty"`
256
+ IPRoute2RuleIndex int `yaml:"iproute2-rule-index" json:"iproute2_rule_index,omitempty"`
257
+ AutoRedirect bool `yaml:"auto-redirect" json:"auto_redirect,omitempty"`
258
+ AutoRedirectInputMark uint32 `yaml:"auto-redirect-input-mark" json:"auto_redirect_input_mark,omitempty"`
259
+ AutoRedirectOutputMark uint32 `yaml:"auto-redirect-output-mark" json:"auto_redirect_output_mark,omitempty"`
260
+ StrictRoute bool `yaml:"strict-route" json:"strict_route,omitempty"`
261
+ RouteAddress []netip.Prefix `yaml:"route-address" json:"route_address,omitempty"`
262
+ RouteAddressSet []string `yaml:"route-address-set" json:"route_address_set,omitempty"`
263
+ RouteExcludeAddress []netip.Prefix `yaml:"route-exclude-address" json:"route_exclude_address,omitempty"`
264
+ RouteExcludeAddressSet []string `yaml:"route-exclude-address-set" json:"route_exclude_address_set,omitempty"`
265
+ IncludeInterface []string `yaml:"include-interface" json:"include-interface,omitempty"`
266
+ ExcludeInterface []string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
267
+ IncludeUID []uint32 `yaml:"include-uid" json:"include_uid,omitempty"`
268
+ IncludeUIDRange []string `yaml:"include-uid-range" json:"include_uid_range,omitempty"`
269
+ ExcludeUID []uint32 `yaml:"exclude-uid" json:"exclude_uid,omitempty"`
270
+ ExcludeUIDRange []string `yaml:"exclude-uid-range" json:"exclude_uid_range,omitempty"`
271
+ IncludeAndroidUser []int `yaml:"include-android-user" json:"include_android_user,omitempty"`
272
+ IncludePackage []string `yaml:"include-package" json:"include_package,omitempty"`
273
+ ExcludePackage []string `yaml:"exclude-package" json:"exclude_package,omitempty"`
274
+ EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"`
275
+ UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"`
276
+ FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
277
+
257
278
Inet4RouteAddress []netip.Prefix `yaml:"inet4-route-address" json:"inet4_route_address,omitempty"`
258
279
Inet6RouteAddress []netip.Prefix `yaml:"inet6-route-address" json:"inet6_route_address,omitempty"`
259
280
Inet4RouteExcludeAddress []netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4_route_exclude_address,omitempty"`
260
281
Inet6RouteExcludeAddress []netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6_route_exclude_address,omitempty"`
261
- IncludeInterface []string `yaml:"include-interface" json:"include-interface,omitempty"`
262
- ExcludeInterface []string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
263
- IncludeUID []uint32 `yaml:"include-uid" json:"include_uid,omitempty"`
264
- IncludeUIDRange []string `yaml:"include-uid-range" json:"include_uid_range,omitempty"`
265
- ExcludeUID []uint32 `yaml:"exclude-uid" json:"exclude_uid,omitempty"`
266
- ExcludeUIDRange []string `yaml:"exclude-uid-range" json:"exclude_uid_range,omitempty"`
267
- IncludeAndroidUser []int `yaml:"include-android-user" json:"include_android_user,omitempty"`
268
- IncludePackage []string `yaml:"include-package" json:"include_package,omitempty"`
269
- ExcludePackage []string `yaml:"exclude-package" json:"exclude_package,omitempty"`
270
- EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"`
271
- UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"`
272
- FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
273
- TableIndex int `yaml:"table-index" json:"table-index"`
274
282
}
275
283
276
284
type RawTuicServer struct {
@@ -564,13 +572,13 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
564
572
}
565
573
config .RuleProviders = ruleProviders
566
574
567
- subRules , err := parseSubRules (rawCfg , proxies )
575
+ subRules , err := parseSubRules (rawCfg , proxies , ruleProviders )
568
576
if err != nil {
569
577
return nil , err
570
578
}
571
579
config .SubRules = subRules
572
580
573
- rules , err := parseRules (rawCfg .Rule , proxies , subRules , "rules" )
581
+ rules , err := parseRules (rawCfg .Rule , proxies , ruleProviders , subRules , "rules" )
574
582
if err != nil {
575
583
return nil , err
576
584
}
@@ -666,7 +674,6 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
666
674
updater .ExternalUIURL = cfg .ExternalUIURL
667
675
}
668
676
669
- cfg .Tun .RedirectToTun = cfg .EBpf .RedirectToTun
670
677
return & General {
671
678
Inbound : Inbound {
672
679
Port : cfg .Port ,
@@ -845,6 +852,7 @@ func parseListeners(cfg *RawConfig) (listeners map[string]C.InboundListener, err
845
852
}
846
853
847
854
func parseRuleProviders (cfg * RawConfig ) (ruleProviders map [string ]providerTypes.RuleProvider , err error ) {
855
+ RP .SetTunnel (T .Tunnel )
848
856
ruleProviders = map [string ]providerTypes.RuleProvider {}
849
857
// parse rule provider
850
858
for name , mapping := range cfg .RuleProvider {
@@ -854,12 +862,11 @@ func parseRuleProviders(cfg *RawConfig) (ruleProviders map[string]providerTypes.
854
862
}
855
863
856
864
ruleProviders [name ] = rp
857
- RP .SetRuleProvider (rp )
858
865
}
859
866
return
860
867
}
861
868
862
- func parseSubRules (cfg * RawConfig , proxies map [string ]C.Proxy ) (subRules map [string ][]C.Rule , err error ) {
869
+ func parseSubRules (cfg * RawConfig , proxies map [string ]C.Proxy , ruleProviders map [ string ]providerTypes. RuleProvider ) (subRules map [string ][]C.Rule , err error ) {
863
870
subRules = map [string ][]C.Rule {}
864
871
for name := range cfg .SubRules {
865
872
subRules [name ] = make ([]C.Rule , 0 )
@@ -869,7 +876,7 @@ func parseSubRules(cfg *RawConfig, proxies map[string]C.Proxy) (subRules map[str
869
876
return nil , fmt .Errorf ("sub-rule name is empty" )
870
877
}
871
878
var rules []C.Rule
872
- rules , err = parseRules (rawRules , proxies , subRules , fmt .Sprintf ("sub-rules[%s]" , name ))
879
+ rules , err = parseRules (rawRules , proxies , ruleProviders , subRules , fmt .Sprintf ("sub-rules[%s]" , name ))
873
880
if err != nil {
874
881
return nil , err
875
882
}
@@ -922,7 +929,7 @@ func verifySubRuleCircularReferences(n string, subRules map[string][]C.Rule, arr
922
929
return nil
923
930
}
924
931
925
- func parseRules (rulesConfig []string , proxies map [string ]C.Proxy , subRules map [string ][]C.Rule , format string ) ([]C.Rule , error ) {
932
+ func parseRules (rulesConfig []string , proxies map [string ]C.Proxy , ruleProviders map [ string ]providerTypes. RuleProvider , subRules map [string ][]C.Rule , format string ) ([]C.Rule , error ) {
926
933
var rules []C.Rule
927
934
928
935
// parse rules
@@ -971,6 +978,12 @@ func parseRules(rulesConfig []string, proxies map[string]C.Proxy, subRules map[s
971
978
return nil , fmt .Errorf ("%s[%d] [%s] error: %s" , format , idx , line , parseErr .Error ())
972
979
}
973
980
981
+ for _ , name := range parsed .ProviderNames () {
982
+ if _ , ok := ruleProviders [name ]; ! ok {
983
+ return nil , fmt .Errorf ("%s[%d] [%s] error: rule set [%s] not found" , format , idx , line , name )
984
+ }
985
+ }
986
+
974
987
rules = append (rules , parsed )
975
988
}
976
989
@@ -1455,31 +1468,39 @@ func parseTun(rawTun RawTun, general *General) error {
1455
1468
DNSHijack : rawTun .DNSHijack ,
1456
1469
AutoRoute : rawTun .AutoRoute ,
1457
1470
AutoDetectInterface : rawTun .AutoDetectInterface ,
1458
- RedirectToTun : rawTun .RedirectToTun ,
1459
-
1460
- MTU : rawTun .MTU ,
1461
- GSO : rawTun .GSO ,
1462
- GSOMaxSize : rawTun .GSOMaxSize ,
1463
- Inet4Address : []netip.Prefix {tunAddressPrefix },
1464
- Inet6Address : rawTun .Inet6Address ,
1465
- StrictRoute : rawTun .StrictRoute ,
1471
+
1472
+ MTU : rawTun .MTU ,
1473
+ GSO : rawTun .GSO ,
1474
+ GSOMaxSize : rawTun .GSOMaxSize ,
1475
+ Inet4Address : []netip.Prefix {tunAddressPrefix },
1476
+ Inet6Address : rawTun .Inet6Address ,
1477
+ IPRoute2TableIndex : rawTun .IPRoute2TableIndex ,
1478
+ IPRoute2RuleIndex : rawTun .IPRoute2RuleIndex ,
1479
+ AutoRedirect : rawTun .AutoRedirect ,
1480
+ AutoRedirectInputMark : rawTun .AutoRedirectInputMark ,
1481
+ AutoRedirectOutputMark : rawTun .AutoRedirectOutputMark ,
1482
+ StrictRoute : rawTun .StrictRoute ,
1483
+ RouteAddress : rawTun .RouteAddress ,
1484
+ RouteAddressSet : rawTun .RouteAddressSet ,
1485
+ RouteExcludeAddress : rawTun .RouteExcludeAddress ,
1486
+ RouteExcludeAddressSet : rawTun .RouteExcludeAddressSet ,
1487
+ IncludeInterface : rawTun .IncludeInterface ,
1488
+ ExcludeInterface : rawTun .ExcludeInterface ,
1489
+ IncludeUID : rawTun .IncludeUID ,
1490
+ IncludeUIDRange : rawTun .IncludeUIDRange ,
1491
+ ExcludeUID : rawTun .ExcludeUID ,
1492
+ ExcludeUIDRange : rawTun .ExcludeUIDRange ,
1493
+ IncludeAndroidUser : rawTun .IncludeAndroidUser ,
1494
+ IncludePackage : rawTun .IncludePackage ,
1495
+ ExcludePackage : rawTun .ExcludePackage ,
1496
+ EndpointIndependentNat : rawTun .EndpointIndependentNat ,
1497
+ UDPTimeout : rawTun .UDPTimeout ,
1498
+ FileDescriptor : rawTun .FileDescriptor ,
1499
+
1466
1500
Inet4RouteAddress : rawTun .Inet4RouteAddress ,
1467
1501
Inet6RouteAddress : rawTun .Inet6RouteAddress ,
1468
1502
Inet4RouteExcludeAddress : rawTun .Inet4RouteExcludeAddress ,
1469
1503
Inet6RouteExcludeAddress : rawTun .Inet6RouteExcludeAddress ,
1470
- IncludeInterface : rawTun .IncludeInterface ,
1471
- ExcludeInterface : rawTun .ExcludeInterface ,
1472
- IncludeUID : rawTun .IncludeUID ,
1473
- IncludeUIDRange : rawTun .IncludeUIDRange ,
1474
- ExcludeUID : rawTun .ExcludeUID ,
1475
- ExcludeUIDRange : rawTun .ExcludeUIDRange ,
1476
- IncludeAndroidUser : rawTun .IncludeAndroidUser ,
1477
- IncludePackage : rawTun .IncludePackage ,
1478
- ExcludePackage : rawTun .ExcludePackage ,
1479
- EndpointIndependentNat : rawTun .EndpointIndependentNat ,
1480
- UDPTimeout : rawTun .UDPTimeout ,
1481
- FileDescriptor : rawTun .FileDescriptor ,
1482
- TableIndex : rawTun .TableIndex ,
1483
1504
}
1484
1505
1485
1506
return nil
0 commit comments