feat: support to auto detect WAN interface

This commit is contained in:
mzz2017
2023-03-24 13:30:02 +08:00
parent a3bf4e1ebd
commit a04a6be76b
5 changed files with 53 additions and 4 deletions

View File

@ -186,6 +186,7 @@ func NewControlPlane(
if err = core.setupRoutingPolicy(); err != nil {
return nil, err
}
global.LanInterface = common.Deduplicate(global.LanInterface)
for _, ifname := range global.LanInterface {
if err = core.bindLan(ifname); err != nil {
return nil, fmt.Errorf("bindLan: %v: %w", ifname, err)
@ -193,6 +194,20 @@ 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