optimize: show outbound name when notify kernel connectivity change

This commit is contained in:
mzz2017
2023-02-17 02:11:08 +08:00
parent 739682dabc
commit 791752399d
4 changed files with 12 additions and 10 deletions

View File

@ -517,7 +517,7 @@ func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr)
if page := path.Base(req.URL.Path); strings.HasPrefix(page, "generate_") {
return strconv.Itoa(resp.StatusCode) == strings.TrimPrefix(page, "generate_"), nil
}
return resp.StatusCode >= 200 && resp.StatusCode < 400, nil
return resp.StatusCode >= 200 && resp.StatusCode < 500, nil
}
func (d *Dialer) DnsCheck(ctx context.Context, dns netip.AddrPort, tcp bool) (ok bool, err error) {

View File

@ -28,7 +28,7 @@ func (c *ControlPlaneCore) OutboundAliveChangeCallback(outbound uint8) func(aliv
c.log.WithFields(logrus.Fields{
"alive": alive,
"network": networkType.StringWithoutDns(),
"outbound_id": outbound,
"outbound": c.outboundId2Name[outbound],
}).Warnf("Outbound alive state changed, notify the kernel program.")
value := uint32(0)

View File

@ -42,7 +42,6 @@ type ControlPlane struct {
// TODO: add mutex?
outbounds []*outbound.DialerGroup
outboundName2Id map[string]uint8
SimulatedLpmTries [][]netip.Prefix
SimulatedDomainSet []DomainSet
@ -266,12 +265,15 @@ func NewControlPlane(
return nil, fmt.Errorf("too many outbounds")
}
outboundName2Id := make(map[string]uint8)
outboundId2Name := make(map[uint8]string)
for i, o := range outbounds {
if _, exist := outboundName2Id[o.Name]; exist {
return nil, fmt.Errorf("duplicated outbound name: %v", o.Name)
}
outboundName2Id[o.Name] = uint8(i)
outboundId2Name[uint8(i)] = o.Name
}
core.outboundId2Name = outboundId2Name
builder := NewRoutingMatcherBuilder(outboundName2Id, &bpf)
var rules []*config_parser.RoutingRule
if rules, err = routing.ApplyRulesOptimizers(routingA.Rules,
@ -304,7 +306,6 @@ func NewControlPlane(
deferFuncs: nil,
listenIp: "0.0.0.0",
outbounds: outbounds,
outboundName2Id: outboundName2Id,
SimulatedLpmTries: builder.SimulatedLpmTries,
SimulatedDomainSet: builder.SimulatedDomainSet,
Final: routingA.Final,

View File

@ -24,6 +24,7 @@ type ControlPlaneCore struct {
log *logrus.Logger
deferFuncs []func() error
bpf *bpfObjects
outboundId2Name map[uint8]string
kernelVersion *internal.Version
}