From ae618e6c6e05ec24fa67042434e013e1904b10a1 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sun, 26 Mar 2023 12:54:12 +0800 Subject: [PATCH] fix: preprocess wan_interface 'auto' before ebpf program loading to avoid to fail to insert filter --- config/patch.go | 21 +++++++++++++++++++++ control/control_plane.go | 14 -------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/config/patch.go b/config/patch.go index d4c7003..e3a4eab 100644 --- a/config/patch.go +++ b/config/patch.go @@ -6,6 +6,8 @@ package config import ( + "fmt" + "github.com/daeuniverse/dae/common" "github.com/daeuniverse/dae/common/consts" ) @@ -13,6 +15,7 @@ type patch func(params *Config) error var patches = []patch{ patchEmptyDns, + patchWanInterfaceAuto, } func patchEmptyDns(params *Config) error { @@ -24,3 +27,21 @@ func patchEmptyDns(params *Config) error { } return nil } + +func patchWanInterfaceAuto(params *Config) error { + // preprocess "auto". + ifs := make([]string, 0, len(params.Global.WanInterface)+2) + for _, ifname := range params.Global.WanInterface { + if ifname == "auto" { + defaultIfs, err := common.GetDefaultIfnames() + if err != nil { + return fmt.Errorf("failed to convert 'auto': %w", err) + } + ifs = append(ifs, defaultIfs...) + } else { + ifs = append(ifs, ifname) + } + } + params.Global.WanInterface = common.Deduplicate(ifs) + return nil +} diff --git a/control/control_plane.go b/control/control_plane.go index fb1b824..a403afb 100644 --- a/control/control_plane.go +++ b/control/control_plane.go @@ -203,20 +203,6 @@ func NewControlPlane( } } // Bind to WAN - // preprocess "auto". - ifs := make([]string, 0, len(global.WanInterface)+2) - for _, ifname := range global.WanInterface { - if ifname == "auto" { - defaultIfs, err := common.GetDefaultIfnames() - if err != nil { - return nil, fmt.Errorf("failed to convert 'auto': %w", err) - } - ifs = append(ifs, defaultIfs...) - } else { - ifs = append(ifs, ifname) - } - } - global.WanInterface = common.Deduplicate(ifs) if len(global.WanInterface) > 0 { if err = core.setupSkPidMonitor(); err != nil { return nil, err