fix: classic nic dhcp default gateway revisit (#25666)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2026-09-10 21:06:24 +08:00
committed by GitHub
parent 8fdbce23d6
commit 64801c02c1
2 changed files with 16 additions and 4 deletions

View File

@@ -242,6 +242,7 @@ func getGuestConfig(
osName = "Linux" osName = "Linux"
} }
// append default route
if conf.Gateway != nil { if conf.Gateway != nil {
if !strings.HasPrefix(strings.ToLower(osName), "win") { if !strings.HasPrefix(strings.ToLower(osName), "win") {
route4 = append(route4, netutils2.SRouteInfo{ route4 = append(route4, netutils2.SRouteInfo{
@@ -264,6 +265,18 @@ func getGuestConfig(
})*/ })*/
//} //}
} }
// append link-local route
if conf.ServerIP != nil {
route4 = append(route4, netutils2.SRouteInfo{
SPrefixInfo: netutils2.SPrefixInfo{
Prefix: conf.ServerIP,
PrefixLen: uint8(nicdesc.Masklen),
},
// link-local route gateway IP is the nic IP
Gateway: net.ParseIP("0.0.0.0"),
})
}
route4, route6 = netutils2.AddNicRoutes(route4, route6, nicdesc, mainIp, mainIp6, len(guestNics)) route4, route6 = netutils2.AddNicRoutes(route4, route6, nicdesc, mainIp, mainIp6, len(guestNics))
conf.Routes = route4 conf.Routes = route4

View File

@@ -540,11 +540,10 @@ func generateDhcpOptions(ctx context.Context, guestnetwork *agentmodels.Guestnet
mdIp, "0.0.0.0", mdIp, "0.0.0.0",
"0.0.0.0/0", network.GuestGateway, "0.0.0.0/0", network.GuestGateway,
) )
} else {
routes = append(routes,
cidr, "0.0.0.0",
)
} }
routes = append(routes,
cidr, "0.0.0.0",
)
if len(routes) > 0 { if len(routes) > 0 {
dhcpopts.Options["classless_static_route"] = fmt.Sprintf("{%s}", strings.Join(routes, ",")) dhcpopts.Options["classless_static_route"] = fmt.Sprintf("{%s}", strings.Join(routes, ","))
} }