diff --git a/pkg/console/install_panels.go b/pkg/console/install_panels.go index 958c7250b..2c75e121c 100644 --- a/pkg/console/install_panels.go +++ b/pkg/console/install_panels.go @@ -42,6 +42,7 @@ const ( ErrMsgVLANShouldBeANumberInRange string = "VLAN ID should be a number 1 ~ 4094." ErrMsgMTUShouldBeANumber string = "MTU should be a number." NtpSettingName string = "ntp-servers" + ErrMsgNoDefaultRoute string = "No default route found. Please check the router setting on the DHCP server." ) var ( @@ -1388,6 +1389,15 @@ func addNetworkPanel(c *Console) error { mgmtNetwork.Gateway = "" mgmtNetwork.MTU = 0 } + + isDefaultRouteExist, err := checkDefaultRoute() + if err != nil { + return fmt.Sprintf("Failed to check default route: %s.", err.Error()), nil + } + if !isDefaultRouteExist { + return ErrMsgNoDefaultRoute, nil + } + return "", nil } @@ -2103,6 +2113,18 @@ func addInstallPanel(c *Console) error { } } + isDefaultRouteExist, err := checkDefaultRoute() + if err != nil { + logrus.Error(err) + printToPanel(c.Gui, "Failed to check default route.", installPanel) + return + } + if !isDefaultRouteExist { + logrus.Error(ErrMsgNoDefaultRoute) + printToPanel(c.Gui, ErrMsgNoDefaultRoute, installPanel) + return + } + // We need ForceGPT because cOS only supports ForceGPT (--force-gpt) flag, not ForceMBR! c.config.ForceGPT = !c.config.ForceMBR diff --git a/pkg/console/network.go b/pkg/console/network.go index b6e3be4ad..1e84f1645 100644 --- a/pkg/console/network.go +++ b/pkg/console/network.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "os/exec" + "syscall" yipSchema "github.com/mudler/yip/pkg/schema" "github.com/sirupsen/logrus" @@ -16,6 +17,24 @@ import ( "github.com/harvester/harvester-installer/pkg/config" ) +func checkDefaultRoute() (bool, error) { + routes, err := netlink.RouteList(nil, syscall.AF_INET) + if err != nil { + logrus.Errorf("Failed to list routes: %s", err.Error()) + return false, err + } + + defaultRouteExists := false + for _, route := range routes { + if route.Dst == nil { + defaultRouteExists = true + break + } + } + + return defaultRouteExists, nil +} + func applyNetworks(network config.Network, hostname string) ([]byte, error) { if err := config.RestoreOriginalNetworkConfig(); err != nil { return nil, err