Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: Setup DNS for sandbox
Browse files Browse the repository at this point in the history
Sandbox has network but no dns. Set
dns, if received from runtime as part of
CreateSandboxRequest, in the shared kata
sandbox directory and bind mount it to
`/etc/resolv.conf` present in the VM
rootfs.

Fixes: #635

Signed-off-by: Nitesh Konkar <[email protected]>
  • Loading branch information
nitkon committed Sep 11, 2019
1 parent dfbcc01 commit d733185
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"reflect"
"strings"
"sync"
"syscall"

"golang.org/x/sys/unix"

Expand All @@ -25,11 +26,13 @@ import (
)

var (
errNoHandle = grpcStatus.Errorf(codes.InvalidArgument, "Need network handle")
errNoIF = grpcStatus.Errorf(codes.InvalidArgument, "Need network interface")
errNoLink = grpcStatus.Errorf(codes.InvalidArgument, "Need network link")
errNoMAC = grpcStatus.Errorf(codes.InvalidArgument, "Need hardware address")
errNoRoutes = grpcStatus.Errorf(codes.InvalidArgument, "Need network routes")
errNoHandle = grpcStatus.Errorf(codes.InvalidArgument, "Need network handle")
errNoIF = grpcStatus.Errorf(codes.InvalidArgument, "Need network interface")
errNoLink = grpcStatus.Errorf(codes.InvalidArgument, "Need network link")
errNoMAC = grpcStatus.Errorf(codes.InvalidArgument, "Need hardware address")
errNoRoutes = grpcStatus.Errorf(codes.InvalidArgument, "Need network routes")
guestDNSFile = "/etc/resolv.conf"
kataGuestSandboxDNSFile = "/run/kata-containers/sandbox/resolv.conf"
)

const (
Expand Down Expand Up @@ -609,8 +612,31 @@ func (s *sandbox) updateRoute(netHandle *netlink.Handle, route *types.Route, add
// DNS //
/////////

func setupDNS(dns []string) error {
return nil
func setupDNS(dns []string) (err error) {
var file *os.File

if len(dns) == 0 {
agentLog.Debug("Did not set sandbox DNS as DNS not received as part of grpc request.")
return nil
}
if file, err = os.Create(kataGuestSandboxDNSFile); err != nil {
return err
}
defer file.Close()

for i, line := range dns {
if i == (len(dns) - 1) {
_, err = file.WriteString(strings.TrimSpace(line))
} else {
_, err = file.WriteString(strings.TrimSpace(line) + "\n")
}

if err != nil {
return err
}
}

return mount(kataGuestSandboxDNSFile, guestDNSFile, "bind", syscall.MS_BIND, "")
}

////////////
Expand Down

0 comments on commit d733185

Please sign in to comment.