diff --git a/pkg/network/dhcp/server/server.go b/pkg/network/dhcp/server/server.go index a0765c714d1d..23289b847c7d 100644 --- a/pkg/network/dhcp/server/server.go +++ b/pkg/network/dhcp/server/server.go @@ -114,7 +114,7 @@ func prepareDHCPOptions( dhcpOptions[dhcp.OptionSubnetMask] = clientMask } if len(routerIP) != 0 { - dhcpOptions[dhcp.OptionRouter] = routerIP + dhcpOptions[dhcp.OptionRouter] = routerIP.To4() } netRoutes := formClasslessRoutes(routes) diff --git a/pkg/network/dhcp/server/server_test.go b/pkg/network/dhcp/server/server_test.go index e4823efc5266..20d643bc4c87 100644 --- a/pkg/network/dhcp/server/server_test.go +++ b/pkg/network/dhcp/server/server_test.go @@ -245,6 +245,13 @@ var _ = Describe("DHCP Server", func() { Expect(options[240]).To(Equal([]byte("private.options.kubevirt.io"))) }) + It("expects the gateway as an IPv4 addresses", func() { + gw := net.ParseIP("192.168.2.1") + options, err := prepareDHCPOptions(gw.DefaultMask(), gw, nil, nil, nil, 1500, "myhost", nil) + Expect(err).NotTo(HaveOccurred()) + Expect(options[dhcp4.OptionRouter]).To(Equal([]byte{192, 168, 2, 1})) + }) + Context("Options set to invalid value", func() { var ( err error