|
|
@@ -505,6 +505,7 @@ func (s *Server) validateConfigs(inputs []model.InterfaceConfig) model.ValidateR
|
|
|
return result
|
|
|
}
|
|
|
seen := make(map[string]struct{})
|
|
|
+ defaultRouteInterfaces := make([]string, 0, 1)
|
|
|
managementInterface := s.currentManagementInterface()
|
|
|
for _, input := range inputs {
|
|
|
name := strings.TrimSpace(input.Interface)
|
|
|
@@ -524,6 +525,9 @@ func (s *Server) validateConfigs(inputs []model.InterfaceConfig) model.ValidateR
|
|
|
result.Errors = append(result.Errors, fmt.Sprintf("目标接口不存在:%s", name))
|
|
|
continue
|
|
|
}
|
|
|
+ if hasDefaultRouteConfig(input) {
|
|
|
+ defaultRouteInterfaces = append(defaultRouteInterfaces, name)
|
|
|
+ }
|
|
|
item := s.validatorSvc.Validate(input)
|
|
|
if name == managementInterface {
|
|
|
addManagementAddressWarning(&item, input)
|
|
|
@@ -538,9 +542,25 @@ func (s *Server) validateConfigs(inputs []model.InterfaceConfig) model.ValidateR
|
|
|
result.Warnings = append(result.Warnings, fmt.Sprintf("%s:%s", name, warning))
|
|
|
}
|
|
|
}
|
|
|
+ if len(defaultRouteInterfaces) > 1 {
|
|
|
+ result.Valid = false
|
|
|
+ result.Errors = append(result.Errors, fmt.Sprintf("只能有一个网口配置默认网关,当前检测到多个默认网关:%s。", strings.Join(defaultRouteInterfaces, "、")))
|
|
|
+ }
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
+func hasDefaultRouteConfig(input model.InterfaceConfig) bool {
|
|
|
+ if input.Dhcp4 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for _, route := range input.Routes {
|
|
|
+ if strings.TrimSpace(route.To) == "default" && strings.TrimSpace(route.Via) != "" {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
func (s *Server) addManagementAddressWarning(result *model.ValidateResponse, input model.InterfaceConfig) {
|
|
|
managementInterface := s.currentManagementInterface()
|
|
|
if managementInterface == "" || strings.TrimSpace(input.Interface) != managementInterface {
|