chore: rename routing final as fallback

This commit is contained in:
mzz2017
2023-02-18 03:01:51 +08:00
parent 914aec31a2
commit de08c7c861
11 changed files with 64 additions and 31 deletions

View File

@ -45,7 +45,7 @@ type ControlPlane struct {
SimulatedLpmTries [][]netip.Prefix
SimulatedDomainSet []DomainSet
Final string
Fallback string
// mutex protects the dnsCache.
dnsCacheMu sync.Mutex
@ -289,9 +289,9 @@ func NewControlPlane(
for _, rule := range rules {
debugBuilder.WriteString(rule.String(true) + "\n")
}
log.Debugf("RoutingA:\n%vfinal: %v\n", debugBuilder.String(), routingA.Final)
log.Debugf("RoutingA:\n%vfallback: %v\n", debugBuilder.String(), routingA.Fallback)
}
if err = routing.ApplyMatcherBuilder(log, builder, rules, routingA.Final); err != nil {
if err = routing.ApplyMatcherBuilder(log, builder, rules, routingA.Fallback); err != nil {
return nil, fmt.Errorf("ApplyMatcherBuilder: %w", err)
}
if err = builder.Build(); err != nil {
@ -308,7 +308,7 @@ func NewControlPlane(
outbounds: outbounds,
SimulatedLpmTries: builder.SimulatedLpmTries,
SimulatedDomainSet: builder.SimulatedDomainSet,
Final: routingA.Final,
Fallback: routingA.Fallback,
dnsCacheMu: sync.Mutex{},
dnsCache: make(map[string]*dnsCache),
dnsUpstream: DnsUpstreamRaw{

View File

@ -272,7 +272,7 @@ enum __attribute__((packed)) MatchType {
MatchType_IpVersion,
MatchType_Mac,
MatchType_ProcessName,
MatchType_Final,
MatchType_Fallback,
};
enum L4ProtoType {
L4ProtoType_TCP = 1,
@ -1106,9 +1106,9 @@ routing(const __u32 flag[6], const void *l4hdr, const __be32 saddr[4],
if (_is_wan && equal16(match_set->pname, _pname)) {
good_subrule = true;
}
} else if (match_set->type == MatchType_Final) {
} else if (match_set->type == MatchType_Fallback) {
#ifdef __DEBUG_ROUTING
bpf_printk("CHECK: hit final");
bpf_printk("CHECK: hit fallback");
#endif
good_subrule = true;
} else {

View File

@ -30,7 +30,7 @@ type RoutingMatcherBuilder struct {
rules []bpfMatchSet
SimulatedLpmTries [][]netip.Prefix
SimulatedDomainSet []DomainSet
Final string
Fallback string
err error
}
@ -215,13 +215,13 @@ func (b *RoutingMatcherBuilder) AddProcessName(f *config_parser.Function, values
}
}
func (b *RoutingMatcherBuilder) AddFinal(outbound string) {
func (b *RoutingMatcherBuilder) AddFallback(outbound string) {
if b.err != nil {
return
}
b.Final = outbound
b.Fallback = outbound
b.rules = append(b.rules, bpfMatchSet{
Type: uint8(consts.MatchType_Final),
Type: uint8(consts.MatchType_Fallback),
Outbound: b.OutboundToId(outbound),
})
}
@ -250,9 +250,9 @@ func (b *RoutingMatcherBuilder) Build() (err error) {
m.Close()
}
// Write routings.
// Final rule MUST be the last.
if b.rules[len(b.rules)-1].Type != uint8(consts.MatchType_Final) {
b.err = fmt.Errorf("final rule MUST be the last")
// Fallback rule MUST be the last.
if b.rules[len(b.rules)-1].Type != uint8(consts.MatchType_Fallback) {
b.err = fmt.Errorf("fallback rule MUST be the last")
return b.err
}
routingsLen := uint32(len(b.rules))