Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion cli/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"golang.org/x/sys/unix"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/kata-containers/agent/pkg/types"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"golang.org/x/sys/unix"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/kata-containers/agent/pkg/types"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/stretchr/testify/assert"
)

Expand Down
11 changes: 6 additions & 5 deletions netmon/netmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"syscall"
"time"

"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/runtime/pkg/signals"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -259,7 +259,7 @@ func (n *netmon) listenNetlinkEvents() error {
// convertInterface converts a link and its IP addresses as defined by netlink
// package, into the Interface structure format expected by kata-runtime to
// describe an interface and its associated IP addresses.
func convertInterface(linkAttrs *netlink.LinkAttrs, addrs []netlink.Addr) types.Interface {
func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []netlink.Addr) types.Interface {
if linkAttrs == nil {
netmonLog.Warn("Link attributes are nil")
return types.Interface{}
Expand All @@ -275,7 +275,7 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, addrs []netlink.Addr) types.
netMask, _ := addr.Mask.Size()

ipAddr := &types.IPAddress{
Family: types.IPFamily(netlinkFamily),
Family: netlinkFamily,
Address: addr.IP.String(),
Mask: fmt.Sprintf("%d", netMask),
}
Expand All @@ -289,6 +289,7 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, addrs []netlink.Addr) types.
IPAddresses: ipAddrs,
Mtu: uint64(linkAttrs.MTU),
HwAddr: linkAttrs.HardwareAddr.String(),
LinkType: linkType,
}

netmonLog.WithField("interface", iface).Debug("Interface converted")
Expand Down Expand Up @@ -369,7 +370,7 @@ func (n *netmon) scanNetwork() error {
continue
}

iface := convertInterface(linkAttrs, addrs)
iface := convertInterface(linkAttrs, link.Type(), addrs)
n.netIfaces[linkAttrs.Index] = iface
}

Expand Down Expand Up @@ -497,7 +498,7 @@ func (n *netmon) handleRTMNewLink(ev netlink.LinkUpdate) error {
}

// Convert the interfaces in the appropriate structure format.
iface := convertInterface(linkAttrs, addrs)
iface := convertInterface(linkAttrs, ev.Link.Type(), addrs)

// Add the interface through the Kata CLI.
if err := n.addInterfaceCLI(iface); err != nil {
Expand Down
18 changes: 11 additions & 7 deletions netmon/netmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"runtime"
"testing"

"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -174,21 +174,24 @@ func TestConvertInterface(t *testing.T) {
HardwareAddr: hwAddr,
}

linkType := "link_type_test"

expected := types.Interface{
Device: testIfaceName,
Name: testIfaceName,
Mtu: uint64(testMTU),
HwAddr: testHwAddr,
IPAddresses: []*types.IPAddress{
{
Family: types.IPFamily(netlinkFamily),
Family: netlinkFamily,
Address: testIPAddress,
Mask: "0",
},
},
LinkType: linkType,
}

got := convertInterface(linkAttrs, addrs)
got := convertInterface(linkAttrs, linkType, addrs)
assert.True(t, reflect.DeepEqual(expected, got),
"Got %+v\nExpected %+v", got, expected)
}
Expand Down Expand Up @@ -264,10 +267,11 @@ func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, types.I
assert.NotNil(t, attrs)

iface := types.Interface{
Device: testIfaceName,
Name: testIfaceName,
Mtu: uint64(testMTU),
HwAddr: testHwAddr,
Device: testIfaceName,
Name: testIfaceName,
Mtu: uint64(testMTU),
HwAddr: testHwAddr,
LinkType: link.Type(),
}

return attrs.Index, iface
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"fmt"
"syscall"

"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/mitchellh/mapstructure"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"runtime"
"syscall"

"github.com/kata-containers/agent/pkg/types"
deviceApi "github.com/kata-containers/runtime/virtcontainers/device/api"
deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"testing"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/vishvananda/netlink"

proxyClient "github.com/clearcontainers/proxy/client"
"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/pkg/hyperstart"
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"context"
"syscall"

"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"io"
"syscall"

"github.com/kata-containers/agent/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
Expand Down
148 changes: 142 additions & 6 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ import (
"syscall"
"time"

"github.com/kata-containers/agent/pkg/types"
aTypes "github.com/kata-containers/agent/pkg/types"
kataclient "github.com/kata-containers/agent/protocols/client"
"github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/virtcontainers/device/config"
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/kata-containers/runtime/virtcontainers/utils"
opentracing "github.com/opentracing/opentracing-go"

"github.com/gogo/protobuf/proto"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.org/x/net/context"
golangGrpc "google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -387,7 +389,7 @@ func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, erro
func (k *kataAgent) updateInterface(ifc *types.Interface) (*types.Interface, error) {
// send update interface request
ifcReq := &grpc.UpdateInterfaceRequest{
Interface: ifc,
Interface: k.convertToKataAgentInterface(ifc),
}
resultingInterface, err := k.sendReq(ifcReq)
if err != nil {
Expand Down Expand Up @@ -415,7 +417,7 @@ func (k *kataAgent) updateRoutes(routes []*types.Route) ([]*types.Route, error)
if routes != nil {
routesReq := &grpc.UpdateRoutesRequest{
Routes: &grpc.Routes{
Routes: routes,
Routes: k.convertToKataAgentRoutes(routes),
},
}
resultingRoutes, err := k.sendReq(routesReq)
Expand All @@ -427,7 +429,7 @@ func (k *kataAgent) updateRoutes(routes []*types.Route) ([]*types.Route, error)
}
resultRoutes, ok := resultingRoutes.(*grpc.Routes)
if ok && resultRoutes != nil {
return resultRoutes.Routes, err
return k.convertToRoutes(resultRoutes.Routes), err
}
return nil, err
}
Expand All @@ -442,7 +444,7 @@ func (k *kataAgent) listInterfaces() ([]*types.Interface, error) {
}
resultInterfaces, ok := resultingInterfaces.(*grpc.Interfaces)
if ok {
return resultInterfaces.Interfaces, err
return k.convertToInterfaces(resultInterfaces.Interfaces), err
}
return nil, err
}
Expand All @@ -455,7 +457,7 @@ func (k *kataAgent) listRoutes() ([]*types.Route, error) {
}
resultRoutes, ok := resultingRoutes.(*grpc.Routes)
if ok {
return resultRoutes.Routes, err
return k.convertToRoutes(resultRoutes.Routes), err
}
return nil, err
}
Expand Down Expand Up @@ -1549,3 +1551,137 @@ func (k *kataAgent) getGuestDetails(req *grpc.GuestDetailsRequest) (*grpc.GuestD

return resp.(*grpc.GuestDetailsResponse), nil
}

func (k *kataAgent) convertToKataAgentIPFamily(ipFamily int) aTypes.IPFamily {
switch ipFamily {
case netlink.FAMILY_V4:
return aTypes.IPFamily_v4
case netlink.FAMILY_V6:
return aTypes.IPFamily_v6
}

return aTypes.IPFamily_v4
}

func (k *kataAgent) convertToIPFamily(ipFamily aTypes.IPFamily) int {
switch ipFamily {
case aTypes.IPFamily_v4:
return netlink.FAMILY_V4
case aTypes.IPFamily_v6:
return netlink.FAMILY_V6
}

return netlink.FAMILY_V4
}

func (k *kataAgent) convertToKataAgentIPAddresses(ipAddrs []*types.IPAddress) (aIPAddrs []*aTypes.IPAddress) {
for _, ipAddr := range ipAddrs {
if ipAddr == nil {
continue
}

aIPAddr := &aTypes.IPAddress{
Family: k.convertToKataAgentIPFamily(ipAddr.Family),
Address: ipAddr.Address,
Mask: ipAddr.Mask,
}

aIPAddrs = append(aIPAddrs, aIPAddr)
}

return aIPAddrs
}

func (k *kataAgent) convertToIPAddresses(aIPAddrs []*aTypes.IPAddress) (ipAddrs []*types.IPAddress) {
for _, aIPAddr := range aIPAddrs {
if aIPAddr == nil {
continue
}

ipAddr := &types.IPAddress{
Family: k.convertToIPFamily(aIPAddr.Family),
Address: aIPAddr.Address,
Mask: aIPAddr.Mask,
}

ipAddrs = append(ipAddrs, ipAddr)
}

return ipAddrs
}

func (k *kataAgent) convertToKataAgentInterface(iface *types.Interface) *aTypes.Interface {
if iface == nil {
return nil
}

return &aTypes.Interface{
Device: iface.Device,
Name: iface.Name,
IPAddresses: k.convertToKataAgentIPAddresses(iface.IPAddresses),
Mtu: iface.Mtu,
HwAddr: iface.HwAddr,
PciAddr: iface.PciAddr,
}
}

func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) (ifaces []*types.Interface) {
for _, aIface := range aIfaces {
if aIface == nil {
continue
}

iface := &types.Interface{
Device: aIface.Device,
Name: aIface.Name,
IPAddresses: k.convertToIPAddresses(aIface.IPAddresses),
Mtu: aIface.Mtu,
HwAddr: aIface.HwAddr,
PciAddr: aIface.PciAddr,
}

ifaces = append(ifaces, iface)
}

return ifaces
}

func (k *kataAgent) convertToKataAgentRoutes(routes []*types.Route) (aRoutes []*aTypes.Route) {
for _, route := range routes {
if route == nil {
continue
}

aRoute := &aTypes.Route{
Dest: route.Dest,
Gateway: route.Gateway,
Device: route.Device,
Source: route.Source,
Scope: route.Scope,
}

aRoutes = append(aRoutes, aRoute)
}

return aRoutes
}

func (k *kataAgent) convertToRoutes(aRoutes []*aTypes.Route) (routes []*types.Route) {
for _, aRoute := range aRoutes {
if aRoute == nil {
continue
}

route := &types.Route{
Dest: aRoute.Dest,
Gateway: aRoute.Gateway,
Device: aRoute.Device,
Source: aRoute.Source,
Scope: aRoute.Scope,
}

routes = append(routes, route)
}

return routes
}
Loading