Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pkg/unikontainers/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ type VMM interface {
}

type NetDevParams struct {
IP string // The veth device IP
Mask string // The veth device mask
Gateway string // The veth device gateway
MAC string // The MAC address of the guest network device
TapDev string // The tap device name
MTU int // The MTU value of the tap device
IP string // The veth device IP
Mask string // The veth device mask
Gateway string // The veth device gateway
MAC string // The MAC address of the guest network device
TapDev string // The tap device name
MTU int // The MTU value of the tap device
DNSServer string // The resolver IP the guest should be configured with, empty if unset
}

type BlockDevParams struct {
Expand Down
14 changes: 11 additions & 3 deletions pkg/unikontainers/unikernels/unikraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
const UnikraftUnikernel string = "unikraft"
const UnikraftCompatVersion string = "0.16.1"

// defaultDNSServer is used when no DNS forwarding resolver IP was set up by
// the network manager.
const defaultDNSServer string = "8.8.8.8"

var ErrUndefinedVersion = errors.New("version is undefined, using default version")
var ErrVersionParsing = errors.New("failed to parse provided version, using default version")

Expand Down Expand Up @@ -107,10 +111,14 @@ func (u *Unikraft) Init(data types.UnikernelParams) error {
u.Monitor = data.Monitor
u.Command = strings.Join(data.CmdLine, " ")

return u.configureUnikraftArgs(data.Rootfs.Type, data.Net.IP, data.Net.Gateway, data.Net.Mask)
return u.configureUnikraftArgs(data.Rootfs.Type, data.Net.IP, data.Net.Gateway, data.Net.Mask, data.Net.DNSServer)
}

func (u *Unikraft) configureUnikraftArgs(rootFsType, ethDeviceIP, ethDeviceGateway, ethDeviceMask string) error {
func (u *Unikraft) configureUnikraftArgs(rootFsType, ethDeviceIP, ethDeviceGateway, ethDeviceMask, dnsServer string) error {
if dnsServer == "" {
dnsServer = defaultDNSServer
}

setCompatArgs := func() {
u.Net.Address = "netdev.ipv4_addr=" + ethDeviceIP
u.Net.Gateway = "netdev.ipv4_gw_addr=" + ethDeviceGateway
Expand All @@ -125,7 +133,7 @@ func (u *Unikraft) configureUnikraftArgs(rootFsType, ethDeviceIP, ethDeviceGatew
}

setCurrentArgs := func() {
u.Net.Address = "netdev.ip=" + ethDeviceIP + "/24:" + ethDeviceGateway + ":8.8.8.8"
u.Net.Address = "netdev.ip=" + ethDeviceIP + "/24:" + ethDeviceGateway + ":" + dnsServer
switch rootFsType {
case "initrd":
// TODO: This needs better handling. We need to revisit this
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/test_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,5 +1241,22 @@ func dockerTestCases() []containerTestArgs {
Skippable: false,
TestFunc: namespaceTest,
},
{
Image: "ghcr.io/alimx07/dns-test-qemu-unikraft-initrd:latest",
Name: "Qemu-unikraft-dns-external",
Devmapper: false,
Seccomp: true,
UID: 0,
GID: 0,
Groups: []int64{},
Memory: "",
Cli: "",
Volumes: []containerVolume{},
StaticNet: false,
SideContainers: []string{},
Skippable: true,
ExpectOut: "Address: 8.8.8.8",
TestFunc: matchTest,
},
}
}
Loading