mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-31 01:44:50 +07:00
fix: should probe wan interface after network online
This commit is contained in:
parent
13154d8cea
commit
97a4e956fe
23
cmd/run.go
23
cmd/run.go
@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/daeuniverse/dae/cmd/internal"
|
||||
"github.com/daeuniverse/dae/common"
|
||||
"github.com/daeuniverse/dae/common/subscription"
|
||||
"github.com/daeuniverse/dae/config"
|
||||
"github.com/daeuniverse/dae/control"
|
||||
@ -275,6 +276,10 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c
|
||||
log.Warnln("No interface to bind.")
|
||||
}
|
||||
|
||||
if err = preprocessWanInterfaceAuto(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c, err = control.NewControlPlane(
|
||||
log,
|
||||
bpf,
|
||||
@ -295,6 +300,24 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func preprocessWanInterfaceAuto(params *config.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
|
||||
}
|
||||
|
||||
func readConfig(cfgFile string) (conf *config.Config, includes []string, err error) {
|
||||
merger := config.NewMerger(cfgFile)
|
||||
sections, includes, err := merger.Merge()
|
||||
|
@ -6,8 +6,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/daeuniverse/dae/common"
|
||||
"github.com/daeuniverse/dae/common/consts"
|
||||
)
|
||||
|
||||
@ -15,7 +13,6 @@ type patch func(params *Config) error
|
||||
|
||||
var patches = []patch{
|
||||
patchEmptyDns,
|
||||
patchWanInterfaceAuto,
|
||||
}
|
||||
|
||||
func patchEmptyDns(params *Config) error {
|
||||
@ -27,21 +24,3 @@ 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user