Skip to content

Commit

Permalink
Convert gateway to IPv4 in DHCP Server
Browse files Browse the repository at this point in the history
To ensure properly formatted packets for IPv4 are emitted, and not IPv6.

Fixes kubevirt#6462

Signed-off-by: Peter Salanki <[email protected]>
  • Loading branch information
salanki authored and kubevirt-bot committed Oct 7, 2021
1 parent baf3c28 commit 4eb40bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/network/dhcp/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pkg/network/dhcp/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4eb40bf

Please sign in to comment.