|
|
@@ -65,8 +65,9 @@ func SetTimeSyncEnabled(enable bool) {
|
|
|
}
|
|
|
|
|
|
const (
|
|
|
- interval1 = time.Duration(1) * time.Second
|
|
|
- interval2 = time.Duration(3) * time.Second
|
|
|
+ interval1 = time.Duration(1) * time.Second
|
|
|
+ interval2 = time.Duration(3) * time.Second
|
|
|
+ eth0ManagementAddr = "192.168.80.1/24"
|
|
|
)
|
|
|
|
|
|
func ModuleInit() {
|
|
|
@@ -87,7 +88,7 @@ func serviceRun() {
|
|
|
case <-t.C:
|
|
|
// 3.1 切换网络-看情况
|
|
|
eth0CableOK, _ := isEth0CableConnected()
|
|
|
- if !eth0CableOK { // 检测到eth0的网线拔出后, 恢复到降级前状态, 进入下一轮
|
|
|
+ if !eth0CableOK { // 检测到eth0的网线拔出后, 清除降级标记
|
|
|
eth0LinkDegraded.CompareAndSwap(true, false)
|
|
|
}
|
|
|
|
|
|
@@ -149,11 +150,21 @@ func serviceRun() {
|
|
|
}
|
|
|
|
|
|
if time.Since(offlineStartTime) >= (time.Duration(20)*time.Second) &&
|
|
|
- getNetType() == NetEth && !eth0LinkDegraded.Load() { // eth0无法联网时
|
|
|
- baseapp.Logger.Warnf("[%s] 通过eth0无法联网, 将网卡等级降级!", MODULE_NAME)
|
|
|
- eth0LinkDegraded.Store(true) // 开始设置eth0网卡降级使用
|
|
|
- if _, _, err := getEth0Addr(); err != nil { // 当eth0未分配到有效地址时
|
|
|
- SetupEth0ForManagement("192.168.80.1/24") // 给eth0设置一个静态的地址
|
|
|
+ getNetType() == NetEth && !eth0LinkDegraded.Load() { // eth0无法联网
|
|
|
+
|
|
|
+ offlineDur := time.Since(offlineStartTime).Round(time.Second)
|
|
|
+ baseapp.Logger.Warnf(
|
|
|
+ "[%s] eth0链路正常但持续无法访问外网(%v), 标记eth0为Degraded, 后续联网优先级将切换至蜂窝!",
|
|
|
+ MODULE_NAME,
|
|
|
+ offlineDur,
|
|
|
+ )
|
|
|
+
|
|
|
+ eth0LinkDegraded.Store(true) // 开始设置eth0网卡降级使用
|
|
|
+
|
|
|
+ if err := SetupEth0ForManagement(eth0ManagementAddr); err != nil {
|
|
|
+ baseapp.Logger.Errorf("[%s] 设置eth0管理地址失败: %v", MODULE_NAME, err)
|
|
|
+ } else {
|
|
|
+ baseapp.Logger.Infof("[%s] eth0已切换为管理口模式(%s)", MODULE_NAME, eth0ManagementAddr)
|
|
|
}
|
|
|
}
|
|
|
|