mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-05 21:11:55 +07:00
optimize: not load CO-RE if possible
This commit is contained in:
parent
18e1eeea80
commit
5cbb1f963c
@ -56,7 +56,12 @@ func Run() (err error) {
|
||||
nodeList = append(nodeList, nodes...)
|
||||
}
|
||||
|
||||
if param.Global.LanInterface == "" && param.Global.WanInterface == "" {
|
||||
return fmt.Errorf("LanInterface and WanInterface cannot both be empty")
|
||||
}
|
||||
|
||||
// New ControlPlane.
|
||||
onlyBindLanInterface := param.Global.WanInterface == ""
|
||||
t, err := control.NewControlPlane(
|
||||
log,
|
||||
nodeList,
|
||||
@ -65,15 +70,13 @@ func Run() (err error) {
|
||||
param.Global.DnsUpstream,
|
||||
param.Global.CheckUrl,
|
||||
param.Global.CheckInterval,
|
||||
onlyBindLanInterface,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Bind to links.
|
||||
if param.Global.LanInterface == "" && param.Global.WanInterface == "" {
|
||||
return fmt.Errorf("LanInterface and WanInterface cannot both be empty")
|
||||
}
|
||||
if param.Global.LanInterface != "" {
|
||||
if err = t.BindLan(param.Global.LanInterface); err != nil {
|
||||
return fmt.Errorf("BindLan: %v: %w", param.Global.LanInterface, err)
|
||||
|
@ -65,6 +65,7 @@ func NewControlPlane(
|
||||
dnsUpstream string,
|
||||
checkUrl string,
|
||||
checkInterval time.Duration,
|
||||
onlyBindLanInterface bool,
|
||||
) (c *ControlPlane, err error) {
|
||||
kernelVersion, e := internal.KernelVersion()
|
||||
if e != nil {
|
||||
@ -80,7 +81,6 @@ func NewControlPlane(
|
||||
|
||||
// Load pre-compiled programs and maps into the kernel.
|
||||
var bpf bpfObjects
|
||||
var bpfLan bpfObjectsLan
|
||||
var ProgramOptions ebpf.ProgramOptions
|
||||
if log.IsLevelEnabled(logrus.TraceLevel) {
|
||||
ProgramOptions = ebpf.ProgramOptions{
|
||||
@ -88,9 +88,9 @@ func NewControlPlane(
|
||||
}
|
||||
}
|
||||
var obj interface{} = &bpf
|
||||
if kernelVersion.Less(consts.FtraceFeatureVersion) {
|
||||
if kernelVersion.Less(consts.FtraceFeatureVersion) || onlyBindLanInterface {
|
||||
// Trick. Replace the beams with rotten timbers.
|
||||
obj = &bpfLan
|
||||
obj = &bpfObjectsLan{}
|
||||
}
|
||||
retryLoadBpf:
|
||||
if err = loadBpfObjects(obj, &ebpf.CollectionOptions{
|
||||
@ -123,9 +123,9 @@ retryLoadBpf:
|
||||
}
|
||||
return nil, fmt.Errorf("loading objects: %v", err)
|
||||
}
|
||||
if kernelVersion.Less(consts.FtraceFeatureVersion) {
|
||||
if _, ok := obj.(*bpfObjects); !ok {
|
||||
// Reverse takeover.
|
||||
AssignBpfObjects(&bpf, &bpfLan)
|
||||
AssignBpfObjects(&bpf, obj)
|
||||
}
|
||||
|
||||
// Write params.
|
||||
|
Loading…
Reference in New Issue
Block a user