chore: core should be created after right bpf loaded

This commit is contained in:
mzz2017 2023-02-09 12:03:29 +08:00
parent 9a840a05a6
commit b34af9c6a4
2 changed files with 13 additions and 12 deletions

View File

@ -29,7 +29,7 @@ func (c *ControlPlaneCore) OutboundAliveChangeCallback(outbound uint8) func(aliv
"alive": alive,
"network": fmt.Sprintf("%v+%v", FormatL4Proto(l4proto), ipversion),
"outbound_id": outbound,
}).Tracef("Outbound alive state changed, notify the kernel program.")
}).Warnf("Outbound alive state changed, notify the kernel program.")
value := uint32(0)
if alive {

View File

@ -122,6 +122,18 @@ func NewControlPlane(
return nil, fmt.Errorf("load eBPF objects: %w", err)
}
core := &ControlPlaneCore{
log: log,
deferFuncs: []func() error{bpf.Close},
bpf: &bpf,
kernelVersion: &kernelVersion,
}
defer func() {
if err != nil {
_ = core.Close()
}
}()
// Write params.
if err = bpf.ParamMap.Update(consts.DisableL4TxChecksumKey, consts.DisableL4ChecksumPolicy_SetZero, ebpf.UpdateAny); err != nil {
return nil, err
@ -150,17 +162,6 @@ func NewControlPlane(
return nil, err
}
core := &ControlPlaneCore{
log: log,
deferFuncs: []func() error{bpf.Close},
bpf: &bpf,
kernelVersion: &kernelVersion,
}
defer func() {
if err != nil {
_ = core.Close()
}
}()
/// Bind to links. Binding should be advance of dialerGroups to avoid un-routable old connection.
// Add clsact qdisc
for _, ifname := range common.Deduplicate(append(append([]string{}, global.LanInterface...), global.WanInterface...)) {