runtime: consolidate types definition

We do not need the vc types translation for network data structures.
Just use the protocol buffer definitions.

Fixes: #415
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2020-07-15 14:46:36 +08:00
parent b0e5e12a08
commit 5b15e9ef4f
18 changed files with 171 additions and 362 deletions

View File

@ -22,7 +22,9 @@ import (
"time" "time"
"github.com/kata-containers/kata-containers/src/runtime/pkg/signals" "github.com/kata-containers/kata-containers/src/runtime/pkg/signals"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog" lSyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
@ -70,7 +72,7 @@ type netmon struct {
storagePath string storagePath string
sharedFile string sharedFile string
netIfaces map[int]vcTypes.Interface netIfaces map[int]pbTypes.Interface
linkUpdateCh chan netlink.LinkUpdate linkUpdateCh chan netlink.LinkUpdate
linkDoneCh chan struct{} linkDoneCh chan struct{}
@ -151,7 +153,7 @@ func newNetmon(params netmonParams) (*netmon, error) {
netmonParams: params, netmonParams: params,
storagePath: filepath.Join(storageParentPath, params.sandboxID), storagePath: filepath.Join(storageParentPath, params.sandboxID),
sharedFile: filepath.Join(storageParentPath, params.sandboxID, sharedFile), sharedFile: filepath.Join(storageParentPath, params.sandboxID, sharedFile),
netIfaces: make(map[int]vcTypes.Interface), netIfaces: make(map[int]pbTypes.Interface),
linkUpdateCh: make(chan netlink.LinkUpdate), linkUpdateCh: make(chan netlink.LinkUpdate),
linkDoneCh: make(chan struct{}), linkDoneCh: make(chan struct{}),
rtUpdateCh: make(chan netlink.RouteUpdate), rtUpdateCh: make(chan netlink.RouteUpdate),
@ -259,13 +261,13 @@ func (n *netmon) listenNetlinkEvents() error {
// convertInterface converts a link and its IP addresses as defined by netlink // convertInterface converts a link and its IP addresses as defined by netlink
// package, into the Interface structure format expected by kata-runtime to // package, into the Interface structure format expected by kata-runtime to
// describe an interface and its associated IP addresses. // describe an interface and its associated IP addresses.
func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []netlink.Addr) vcTypes.Interface { func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []netlink.Addr) pbTypes.Interface {
if linkAttrs == nil { if linkAttrs == nil {
netmonLog.Warn("Link attributes are nil") netmonLog.Warn("Link attributes are nil")
return vcTypes.Interface{} return pbTypes.Interface{}
} }
var ipAddrs []*vcTypes.IPAddress var ipAddrs []*pbTypes.IPAddress
for _, addr := range addrs { for _, addr := range addrs {
if addr.IPNet == nil { if addr.IPNet == nil {
@ -274,27 +276,27 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []net
netMask, _ := addr.Mask.Size() netMask, _ := addr.Mask.Size()
ipAddr := &vcTypes.IPAddress{ ipAddr := &pbTypes.IPAddress{
Address: addr.IP.String(), Address: addr.IP.String(),
Mask: fmt.Sprintf("%d", netMask), Mask: fmt.Sprintf("%d", netMask),
} }
if addr.IP.To4() != nil { if addr.IP.To4() != nil {
ipAddr.Family = netlink.FAMILY_V4 ipAddr.Family = utils.ConvertNetlinkFamily(netlink.FAMILY_V4)
} else { } else {
ipAddr.Family = netlink.FAMILY_V6 ipAddr.Family = utils.ConvertNetlinkFamily(netlink.FAMILY_V6)
} }
ipAddrs = append(ipAddrs, ipAddr) ipAddrs = append(ipAddrs, ipAddr)
} }
iface := vcTypes.Interface{ iface := pbTypes.Interface{
Device: linkAttrs.Name, Device: linkAttrs.Name,
Name: linkAttrs.Name, Name: linkAttrs.Name,
IPAddresses: ipAddrs, IPAddresses: ipAddrs,
Mtu: uint64(linkAttrs.MTU), Mtu: uint64(linkAttrs.MTU),
HwAddr: linkAttrs.HardwareAddr.String(), HwAddr: linkAttrs.HardwareAddr.String(),
LinkType: linkType, Type: linkType,
} }
netmonLog.WithField("interface", iface).Debug("Interface converted") netmonLog.WithField("interface", iface).Debug("Interface converted")
@ -305,8 +307,8 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []net
// convertRoutes converts a list of routes as defined by netlink package, // convertRoutes converts a list of routes as defined by netlink package,
// into a list of Route structure format expected by kata-runtime to // into a list of Route structure format expected by kata-runtime to
// describe a set of routes. // describe a set of routes.
func convertRoutes(netRoutes []netlink.Route) []vcTypes.Route { func convertRoutes(netRoutes []netlink.Route) []pbTypes.Route {
var routes []vcTypes.Route var routes []pbTypes.Route
for _, netRoute := range netRoutes { for _, netRoute := range netRoutes {
dst := "" dst := ""
@ -348,7 +350,7 @@ func convertRoutes(netRoutes []netlink.Route) []vcTypes.Route {
dev = iface.Name dev = iface.Name
} }
route := vcTypes.Route{ route := pbTypes.Route{
Dest: dst, Dest: dst,
Gateway: gw, Gateway: gw,
Device: dev, Device: dev,
@ -420,7 +422,7 @@ func (n *netmon) execKataCmd(subCmd string) error {
return os.Remove(n.sharedFile) return os.Remove(n.sharedFile)
} }
func (n *netmon) addInterfaceCLI(iface vcTypes.Interface) error { func (n *netmon) addInterfaceCLI(iface pbTypes.Interface) error {
if err := n.storeDataToSend(iface); err != nil { if err := n.storeDataToSend(iface); err != nil {
return err return err
} }
@ -428,7 +430,7 @@ func (n *netmon) addInterfaceCLI(iface vcTypes.Interface) error {
return n.execKataCmd(kataCLIAddIfaceCmd) return n.execKataCmd(kataCLIAddIfaceCmd)
} }
func (n *netmon) delInterfaceCLI(iface vcTypes.Interface) error { func (n *netmon) delInterfaceCLI(iface pbTypes.Interface) error {
if err := n.storeDataToSend(iface); err != nil { if err := n.storeDataToSend(iface); err != nil {
return err return err
} }
@ -436,7 +438,7 @@ func (n *netmon) delInterfaceCLI(iface vcTypes.Interface) error {
return n.execKataCmd(kataCLIDelIfaceCmd) return n.execKataCmd(kataCLIDelIfaceCmd)
} }
func (n *netmon) updateRoutesCLI(routes []vcTypes.Route) error { func (n *netmon) updateRoutesCLI(routes []pbTypes.Route) error {
if err := n.storeDataToSend(routes); err != nil { if err := n.storeDataToSend(routes); err != nil {
return err return err
} }

View File

@ -18,7 +18,9 @@ import (
"testing" "testing"
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
@ -187,24 +189,24 @@ func TestConvertInterface(t *testing.T) {
linkType := "link_type_test" linkType := "link_type_test"
expected := vcTypes.Interface{ expected := pbTypes.Interface{
Device: testIfaceName, Device: testIfaceName,
Name: testIfaceName, Name: testIfaceName,
Mtu: uint64(testMTU), Mtu: uint64(testMTU),
HwAddr: testHwAddr, HwAddr: testHwAddr,
IPAddresses: []*vcTypes.IPAddress{ IPAddresses: []*pbTypes.IPAddress{
{ {
Family: netlink.FAMILY_V4, Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4),
Address: testIPAddress, Address: testIPAddress,
Mask: "0", Mask: "0",
}, },
{ {
Family: netlink.FAMILY_V6, Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V6),
Address: testIP6Address, Address: testIP6Address,
Mask: "0", Mask: "0",
}, },
}, },
LinkType: linkType, Type: linkType,
} }
got := convertInterface(linkAttrs, linkType, addrs) got := convertInterface(linkAttrs, linkType, addrs)
@ -239,7 +241,7 @@ func TestConvertRoutes(t *testing.T) {
}, },
} }
expected := []vcTypes.Route{ expected := []pbTypes.Route{
{ {
Dest: testIPAddressWithMask, Dest: testIPAddressWithMask,
Gateway: testIPAddress, Gateway: testIPAddress,
@ -279,7 +281,7 @@ func testSetupNetwork(t *testing.T) testTeardownNetwork {
} }
} }
func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, vcTypes.Interface) { func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, pbTypes.Interface) {
hwAddr, err := net.ParseMAC(testHwAddr) hwAddr, err := net.ParseMAC(testHwAddr)
assert.Nil(t, err) assert.Nil(t, err)
@ -303,7 +305,7 @@ func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, vcTypes
addrs, err := handler.AddrList(link, netlinkFamily) addrs, err := handler.AddrList(link, netlinkFamily)
assert.Nil(t, err) assert.Nil(t, err)
var ipAddrs []*vcTypes.IPAddress var ipAddrs []*pbTypes.IPAddress
// Scan addresses for ipv6 link local address which is automatically assigned // Scan addresses for ipv6 link local address which is automatically assigned
for _, addr := range addrs { for _, addr := range addrs {
@ -313,26 +315,26 @@ func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, vcTypes
netMask, _ := addr.Mask.Size() netMask, _ := addr.Mask.Size()
ipAddr := &vcTypes.IPAddress{ ipAddr := &pbTypes.IPAddress{
Address: addr.IP.String(), Address: addr.IP.String(),
Mask: fmt.Sprintf("%d", netMask), Mask: fmt.Sprintf("%d", netMask),
} }
if addr.IP.To4() != nil { if addr.IP.To4() != nil {
ipAddr.Family = netlink.FAMILY_V4 ipAddr.Family = utils.ConvertNetlinkFamily(netlink.FAMILY_V4)
} else { } else {
ipAddr.Family = netlink.FAMILY_V6 ipAddr.Family = utils.ConvertNetlinkFamily(netlink.FAMILY_V6)
} }
ipAddrs = append(ipAddrs, ipAddr) ipAddrs = append(ipAddrs, ipAddr)
} }
iface := vcTypes.Interface{ iface := pbTypes.Interface{
Device: testIfaceName, Device: testIfaceName,
Name: testIfaceName, Name: testIfaceName,
Mtu: uint64(testMTU), Mtu: uint64(testMTU),
HwAddr: testHwAddr, HwAddr: testHwAddr,
LinkType: link.Type(), Type: link.Type(),
IPAddresses: ipAddrs, IPAddresses: ipAddrs,
} }
@ -351,7 +353,7 @@ func TestScanNetwork(t *testing.T) {
idx, expected := testCreateDummyNetwork(t, handler) idx, expected := testCreateDummyNetwork(t, handler)
n := &netmon{ n := &netmon{
netIfaces: make(map[int]vcTypes.Interface), netIfaces: make(map[int]pbTypes.Interface),
netHandler: handler, netHandler: handler,
} }
@ -362,9 +364,9 @@ func TestScanNetwork(t *testing.T) {
} }
func TestStoreDataToSend(t *testing.T) { func TestStoreDataToSend(t *testing.T) {
var got vcTypes.Interface var got pbTypes.Interface
expected := vcTypes.Interface{ expected := pbTypes.Interface{
Device: testIfaceName, Device: testIfaceName,
Name: testIfaceName, Name: testIfaceName,
Mtu: uint64(testMTU), Mtu: uint64(testMTU),
@ -461,15 +463,15 @@ func TestActionsCLI(t *testing.T) {
defer os.RemoveAll(testStorageParentPath) defer os.RemoveAll(testStorageParentPath)
// Test addInterfaceCLI // Test addInterfaceCLI
err = n.addInterfaceCLI(vcTypes.Interface{}) err = n.addInterfaceCLI(pbTypes.Interface{})
assert.Nil(t, err) assert.Nil(t, err)
// Test delInterfaceCLI // Test delInterfaceCLI
err = n.delInterfaceCLI(vcTypes.Interface{}) err = n.delInterfaceCLI(pbTypes.Interface{})
assert.Nil(t, err) assert.Nil(t, err)
// Test updateRoutesCLI // Test updateRoutesCLI
err = n.updateRoutesCLI([]vcTypes.Route{}) err = n.updateRoutesCLI([]pbTypes.Route{})
assert.Nil(t, err) assert.Nil(t, err)
tearDownNetworkCb := testSetupNetwork(t) tearDownNetworkCb := testSetupNetwork(t)
@ -527,8 +529,8 @@ func TestHandleRTMNewLink(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// Interface already exist in list // Interface already exist in list
n.netIfaces = make(map[int]vcTypes.Interface) n.netIfaces = make(map[int]pbTypes.Interface)
n.netIfaces[testIfaceIndex] = vcTypes.Interface{} n.netIfaces[testIfaceIndex] = pbTypes.Interface{}
ev = netlink.LinkUpdate{ ev = netlink.LinkUpdate{
Link: &netlink.Dummy{ Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
@ -541,7 +543,7 @@ func TestHandleRTMNewLink(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// Flags are not up and running // Flags are not up and running
n.netIfaces = make(map[int]vcTypes.Interface) n.netIfaces = make(map[int]pbTypes.Interface)
ev = netlink.LinkUpdate{ ev = netlink.LinkUpdate{
Link: &netlink.Dummy{ Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
@ -554,7 +556,7 @@ func TestHandleRTMNewLink(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// Invalid link // Invalid link
n.netIfaces = make(map[int]vcTypes.Interface) n.netIfaces = make(map[int]pbTypes.Interface)
ev = netlink.LinkUpdate{ ev = netlink.LinkUpdate{
Link: &netlink.Dummy{ Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
@ -595,7 +597,7 @@ func TestHandleRTMDelLink(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// Interface does not exist in list // Interface does not exist in list
n.netIfaces = make(map[int]vcTypes.Interface) n.netIfaces = make(map[int]pbTypes.Interface)
ev = netlink.LinkUpdate{ ev = netlink.LinkUpdate{
Link: &netlink.Dummy{ Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
@ -610,7 +612,7 @@ func TestHandleRTMDelLink(t *testing.T) {
func TestHandleRTMNewRouteIfaceNotFound(t *testing.T) { func TestHandleRTMNewRouteIfaceNotFound(t *testing.T) {
n := &netmon{ n := &netmon{
netIfaces: make(map[int]vcTypes.Interface), netIfaces: make(map[int]pbTypes.Interface),
} }
err := n.handleRTMNewRoute(netlink.RouteUpdate{}) err := n.handleRTMNewRoute(netlink.RouteUpdate{})

View File

@ -10,8 +10,8 @@ import (
"time" "time"
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -182,16 +182,16 @@ type agent interface {
reseedRNG(data []byte) error reseedRNG(data []byte) error
// updateInterface will tell the agent to update a nic for an existed Sandbox. // updateInterface will tell the agent to update a nic for an existed Sandbox.
updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) updateInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
// listInterfaces will tell the agent to list interfaces of an existed Sandbox // listInterfaces will tell the agent to list interfaces of an existed Sandbox
listInterfaces() ([]*vcTypes.Interface, error) listInterfaces() ([]*pbTypes.Interface, error)
// updateRoutes will tell the agent to update route table for an existed Sandbox. // updateRoutes will tell the agent to update route table for an existed Sandbox.
updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) updateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
// listRoutes will tell the agent to list routes of an existed Sandbox // listRoutes will tell the agent to list routes of an existed Sandbox
listRoutes() ([]*vcTypes.Route, error) listRoutes() ([]*pbTypes.Route, error)
// getGuestDetails will tell the agent to get some information of guest // getGuestDetails will tell the agent to get some information of guest
getGuestDetails(*grpc.GuestDetailsRequest) (*grpc.GuestDetailsResponse, error) getGuestDetails(*grpc.GuestDetailsRequest) (*grpc.GuestDetailsResponse, error)

View File

@ -14,6 +14,7 @@ import (
deviceApi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" deviceApi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
deviceConfig "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" deviceConfig "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/compatoci" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/compatoci"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
@ -798,7 +799,7 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn
return s.AddDevice(info) return s.AddDevice(info)
} }
func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface, add bool) (*vcTypes.Interface, error) { func toggleInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface, add bool) (*pbTypes.Interface, error) {
if sandboxID == "" { if sandboxID == "" {
return nil, vcTypes.ErrNeedSandboxID return nil, vcTypes.ErrNeedSandboxID
} }
@ -822,7 +823,7 @@ func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa
} }
// AddInterface is the virtcontainers add interface entry point. // AddInterface is the virtcontainers add interface entry point.
func AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { func AddInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
span, ctx := trace(ctx, "AddInterface") span, ctx := trace(ctx, "AddInterface")
defer span.Finish() defer span.Finish()
@ -830,7 +831,7 @@ func AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface)
} }
// RemoveInterface is the virtcontainers remove interface entry point. // RemoveInterface is the virtcontainers remove interface entry point.
func RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { func RemoveInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
span, ctx := trace(ctx, "RemoveInterface") span, ctx := trace(ctx, "RemoveInterface")
defer span.Finish() defer span.Finish()
@ -838,7 +839,7 @@ func RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa
} }
// ListInterfaces is the virtcontainers list interfaces entry point. // ListInterfaces is the virtcontainers list interfaces entry point.
func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) { func ListInterfaces(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error) {
span, ctx := trace(ctx, "ListInterfaces") span, ctx := trace(ctx, "ListInterfaces")
defer span.Finish() defer span.Finish()
@ -861,7 +862,7 @@ func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface
} }
// UpdateRoutes is the virtcontainers update routes entry point. // UpdateRoutes is the virtcontainers update routes entry point.
func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { func UpdateRoutes(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
span, ctx := trace(ctx, "UpdateRoutes") span, ctx := trace(ctx, "UpdateRoutes")
defer span.Finish() defer span.Finish()
@ -884,7 +885,7 @@ func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route
} }
// ListRoutes is the virtcontainers list routes entry point. // ListRoutes is the virtcontainers list routes entry point.
func ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) { func ListRoutes(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error) {
span, ctx := trace(ctx, "ListRoutes") span, ctx := trace(ctx, "ListRoutes")
defer span.Finish() defer span.Finish()

View File

@ -16,20 +16,20 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/containerd/cgroups" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
"github.com/containerd/cgroups"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
) )
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/major.h // https://github.com/torvalds/linux/blob/master/include/uapi/linux/major.h

View File

@ -12,7 +12,7 @@ import (
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -65,11 +65,11 @@ type VCSandbox interface {
AddDevice(info config.DeviceInfo) (api.Device, error) AddDevice(info config.DeviceInfo) (api.Device, error)
AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
ListInterfaces() ([]*vcTypes.Interface, error) ListInterfaces() ([]*pbTypes.Interface, error)
UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
ListRoutes() ([]*vcTypes.Route, error) ListRoutes() ([]*pbTypes.Route, error)
GetOOMEvent() (string, error) GetOOMEvent() (string, error)

View File

@ -21,7 +21,7 @@ import (
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
kataclient "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/client" kataclient "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/client"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
@ -36,7 +36,6 @@ import (
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
@ -565,10 +564,10 @@ func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process
return buildProcessFromExecID(req.ExecId) return buildProcessFromExecID(req.ExecId)
} }
func (k *kataAgent) updateInterface(ifc *vcTypes.Interface) (*vcTypes.Interface, error) { func (k *kataAgent) updateInterface(ifc *pbTypes.Interface) (*pbTypes.Interface, error) {
// send update interface request // send update interface request
ifcReq := &grpc.UpdateInterfaceRequest{ ifcReq := &grpc.UpdateInterfaceRequest{
Interface: k.convertToKataAgentInterface(ifc), Interface: ifc,
} }
resultingInterface, err := k.sendReq(ifcReq) resultingInterface, err := k.sendReq(ifcReq)
if err != nil { if err != nil {
@ -577,13 +576,13 @@ func (k *kataAgent) updateInterface(ifc *vcTypes.Interface) (*vcTypes.Interface,
"resulting-interface": fmt.Sprintf("%+v", resultingInterface), "resulting-interface": fmt.Sprintf("%+v", resultingInterface),
}).WithError(err).Error("update interface request failed") }).WithError(err).Error("update interface request failed")
} }
if resultInterface, ok := resultingInterface.(*vcTypes.Interface); ok { if resultInterface, ok := resultingInterface.(*pbTypes.Interface); ok {
return resultInterface, err return resultInterface, err
} }
return nil, err return nil, err
} }
func (k *kataAgent) updateInterfaces(interfaces []*vcTypes.Interface) error { func (k *kataAgent) updateInterfaces(interfaces []*pbTypes.Interface) error {
for _, ifc := range interfaces { for _, ifc := range interfaces {
if _, err := k.updateInterface(ifc); err != nil { if _, err := k.updateInterface(ifc); err != nil {
return err return err
@ -592,11 +591,11 @@ func (k *kataAgent) updateInterfaces(interfaces []*vcTypes.Interface) error {
return nil return nil
} }
func (k *kataAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { func (k *kataAgent) updateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
if routes != nil { if routes != nil {
routesReq := &grpc.UpdateRoutesRequest{ routesReq := &grpc.UpdateRoutesRequest{
Routes: &grpc.Routes{ Routes: &grpc.Routes{
Routes: k.convertToKataAgentRoutes(routes), Routes: routes,
}, },
} }
resultingRoutes, err := k.sendReq(routesReq) resultingRoutes, err := k.sendReq(routesReq)
@ -608,18 +607,18 @@ func (k *kataAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, err
} }
resultRoutes, ok := resultingRoutes.(*grpc.Routes) resultRoutes, ok := resultingRoutes.(*grpc.Routes)
if ok && resultRoutes != nil { if ok && resultRoutes != nil {
return k.convertToRoutes(resultRoutes.Routes), err return resultRoutes.Routes, err
} }
return nil, err return nil, err
} }
return nil, nil return nil, nil
} }
func (k *kataAgent) addARPNeighbors(neighs []*vcTypes.ARPNeighbor) error { func (k *kataAgent) addARPNeighbors(neighs []*pbTypes.ARPNeighbor) error {
if neighs != nil { if neighs != nil {
neighsReq := &grpc.AddARPNeighborsRequest{ neighsReq := &grpc.AddARPNeighborsRequest{
Neighbors: &grpc.ARPNeighbors{ Neighbors: &grpc.ARPNeighbors{
ARPNeighbors: k.convertToKataAgentNeighbors(neighs), ARPNeighbors: neighs,
}, },
} }
_, err := k.sendReq(neighsReq) _, err := k.sendReq(neighsReq)
@ -639,7 +638,7 @@ func (k *kataAgent) addARPNeighbors(neighs []*vcTypes.ARPNeighbor) error {
return nil return nil
} }
func (k *kataAgent) listInterfaces() ([]*vcTypes.Interface, error) { func (k *kataAgent) listInterfaces() ([]*pbTypes.Interface, error) {
req := &grpc.ListInterfacesRequest{} req := &grpc.ListInterfacesRequest{}
resultingInterfaces, err := k.sendReq(req) resultingInterfaces, err := k.sendReq(req)
if err != nil { if err != nil {
@ -647,12 +646,12 @@ func (k *kataAgent) listInterfaces() ([]*vcTypes.Interface, error) {
} }
resultInterfaces, ok := resultingInterfaces.(*grpc.Interfaces) resultInterfaces, ok := resultingInterfaces.(*grpc.Interfaces)
if ok { if ok {
return k.convertToInterfaces(resultInterfaces.Interfaces), err return resultInterfaces.Interfaces, err
} }
return nil, err return nil, err
} }
func (k *kataAgent) listRoutes() ([]*vcTypes.Route, error) { func (k *kataAgent) listRoutes() ([]*pbTypes.Route, error) {
req := &grpc.ListRoutesRequest{} req := &grpc.ListRoutesRequest{}
resultingRoutes, err := k.sendReq(req) resultingRoutes, err := k.sendReq(req)
if err != nil { if err != nil {
@ -660,7 +659,7 @@ func (k *kataAgent) listRoutes() ([]*vcTypes.Route, error) {
} }
resultRoutes, ok := resultingRoutes.(*grpc.Routes) resultRoutes, ok := resultingRoutes.(*grpc.Routes)
if ok { if ok {
return k.convertToRoutes(resultRoutes.Routes), err return resultRoutes.Routes, err
} }
return nil, err return nil, err
} }
@ -2165,169 +2164,6 @@ func (k *kataAgent) setGuestDateTime(tv time.Time) error {
return err return err
} }
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) convertToKataAgentIPAddress(ipAddr *vcTypes.IPAddress) (aIPAddr *aTypes.IPAddress) {
if ipAddr == nil {
return nil
}
aIPAddr = &aTypes.IPAddress{
Family: k.convertToKataAgentIPFamily(ipAddr.Family),
Address: ipAddr.Address,
Mask: ipAddr.Mask,
}
return aIPAddr
}
func (k *kataAgent) convertToKataAgentIPAddresses(ipAddrs []*vcTypes.IPAddress) (aIPAddrs []*aTypes.IPAddress) {
for _, ipAddr := range ipAddrs {
if ipAddr == nil {
continue
}
aIPAddr := k.convertToKataAgentIPAddress(ipAddr)
aIPAddrs = append(aIPAddrs, aIPAddr)
}
return aIPAddrs
}
func (k *kataAgent) convertToIPAddresses(aIPAddrs []*aTypes.IPAddress) (ipAddrs []*vcTypes.IPAddress) {
for _, aIPAddr := range aIPAddrs {
if aIPAddr == nil {
continue
}
ipAddr := &vcTypes.IPAddress{
Family: k.convertToIPFamily(aIPAddr.Family),
Address: aIPAddr.Address,
Mask: aIPAddr.Mask,
}
ipAddrs = append(ipAddrs, ipAddr)
}
return ipAddrs
}
func (k *kataAgent) convertToKataAgentInterface(iface *vcTypes.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,
RawFlags: iface.RawFlags,
HwAddr: iface.HwAddr,
PciAddr: iface.PciAddr,
}
}
func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) (ifaces []*vcTypes.Interface) {
for _, aIface := range aIfaces {
if aIface == nil {
continue
}
iface := &vcTypes.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 []*vcTypes.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) convertToKataAgentNeighbors(neighs []*vcTypes.ARPNeighbor) (aNeighs []*aTypes.ARPNeighbor) {
for _, neigh := range neighs {
if neigh == nil {
continue
}
aNeigh := &aTypes.ARPNeighbor{
ToIPAddress: k.convertToKataAgentIPAddress(neigh.ToIPAddress),
Device: neigh.Device,
State: int32(neigh.State),
Lladdr: neigh.LLAddr,
}
aNeighs = append(aNeighs, aNeigh)
}
return aNeighs
}
func (k *kataAgent) convertToRoutes(aRoutes []*aTypes.Route) (routes []*vcTypes.Route) {
for _, aRoute := range aRoutes {
if aRoute == nil {
continue
}
route := &vcTypes.Route{
Dest: aRoute.Dest,
Gateway: aRoute.Gateway,
Device: aRoute.Device,
Source: aRoute.Source,
Scope: aRoute.Scope,
}
routes = append(routes, route)
}
return routes
}
func (k *kataAgent) copyFile(src, dst string) error { func (k *kataAgent) copyFile(src, dst string) error {
var st unix.Stat_t var st unix.Stat_t

View File

@ -29,11 +29,11 @@ import (
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols" aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
pb "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc" pb "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
) )
@ -1062,7 +1062,7 @@ func TestAgentNetworkOperation(t *testing.T) {
_, err = k.listInterfaces() _, err = k.listInterfaces()
assert.Nil(err) assert.Nil(err)
_, err = k.updateRoutes([]*vcTypes.Route{}) _, err = k.updateRoutes([]*pbTypes.Route{})
assert.Nil(err) assert.Nil(err)
_, err = k.listRoutes() _, err = k.listRoutes()

View File

@ -10,8 +10,8 @@ import (
"time" "time"
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -111,22 +111,22 @@ func (n *mockAgent) onlineCPUMem(cpus uint32, cpuOnly bool) error {
} }
// updateInterface is the Noop agent Interface update implementation. It does nothing. // updateInterface is the Noop agent Interface update implementation. It does nothing.
func (n *mockAgent) updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (n *mockAgent) updateInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
// listInterfaces is the Noop agent Interfaces list implementation. It does nothing. // listInterfaces is the Noop agent Interfaces list implementation. It does nothing.
func (n *mockAgent) listInterfaces() ([]*vcTypes.Interface, error) { func (n *mockAgent) listInterfaces() ([]*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
// updateRoutes is the Noop agent Routes update implementation. It does nothing. // updateRoutes is the Noop agent Routes update implementation. It does nothing.
func (n *mockAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { func (n *mockAgent) updateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
return nil, nil return nil, nil
} }
// listRoutes is the Noop agent Routes list implementation. It does nothing. // listRoutes is the Noop agent Routes list implementation. It does nothing.
func (n *mockAgent) listRoutes() ([]*vcTypes.Route, error) { func (n *mockAgent) listRoutes() ([]*pbTypes.Route, error) {
return nil, nil return nil, nil
} }

View File

@ -26,8 +26,8 @@ import (
"github.com/vishvananda/netns" "github.com/vishvananda/netns"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
) )
@ -943,19 +943,19 @@ func deleteNetNS(netNSPath string) error {
return nil return nil
} }
func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interface, []*vcTypes.Route, []*vcTypes.ARPNeighbor, error) { func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interface, []*pbTypes.Route, []*pbTypes.ARPNeighbor, error) {
if networkNS.NetNsPath == "" { if networkNS.NetNsPath == "" {
return nil, nil, nil, nil return nil, nil, nil, nil
} }
var routes []*vcTypes.Route var routes []*pbTypes.Route
var ifaces []*vcTypes.Interface var ifaces []*pbTypes.Interface
var neighs []*vcTypes.ARPNeighbor var neighs []*pbTypes.ARPNeighbor
for _, endpoint := range networkNS.Endpoints { for _, endpoint := range networkNS.Endpoints {
var ipAddresses []*vcTypes.IPAddress var ipAddresses []*pbTypes.IPAddress
for _, addr := range endpoint.Properties().Addrs { for _, addr := range endpoint.Properties().Addrs {
// Skip localhost interface // Skip localhost interface
if addr.IP.IsLoopback() { if addr.IP.IsLoopback() {
@ -963,19 +963,19 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
} }
netMask, _ := addr.Mask.Size() netMask, _ := addr.Mask.Size()
ipAddress := vcTypes.IPAddress{ ipAddress := pbTypes.IPAddress{
Family: netlink.FAMILY_V4, Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4),
Address: addr.IP.String(), Address: addr.IP.String(),
Mask: fmt.Sprintf("%d", netMask), Mask: fmt.Sprintf("%d", netMask),
} }
if addr.IP.To4() == nil { if addr.IP.To4() == nil {
ipAddress.Family = netlink.FAMILY_V6 ipAddress.Family = utils.ConvertNetlinkFamily(netlink.FAMILY_V6)
} }
ipAddresses = append(ipAddresses, &ipAddress) ipAddresses = append(ipAddresses, &ipAddress)
} }
noarp := endpoint.Properties().Iface.RawFlags & unix.IFF_NOARP noarp := endpoint.Properties().Iface.RawFlags & unix.IFF_NOARP
ifc := vcTypes.Interface{ ifc := pbTypes.Interface{
IPAddresses: ipAddresses, IPAddresses: ipAddresses,
Device: endpoint.Name(), Device: endpoint.Name(),
Name: endpoint.Name(), Name: endpoint.Name(),
@ -988,7 +988,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
ifaces = append(ifaces, &ifc) ifaces = append(ifaces, &ifc)
for _, route := range endpoint.Properties().Routes { for _, route := range endpoint.Properties().Routes {
var r vcTypes.Route var r pbTypes.Route
if route.Protocol == unix.RTPROT_KERNEL { if route.Protocol == unix.RTPROT_KERNEL {
continue continue
@ -1013,7 +1013,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
} }
for _, neigh := range endpoint.Properties().Neighbors { for _, neigh := range endpoint.Properties().Neighbors {
var n vcTypes.ARPNeighbor var n pbTypes.ARPNeighbor
// We add only static ARP entries // We add only static ARP entries
if neigh.State != netlink.NUD_PERMANENT { if neigh.State != netlink.NUD_PERMANENT {
@ -1021,15 +1021,15 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
} }
n.Device = endpoint.Name() n.Device = endpoint.Name()
n.State = neigh.State n.State = int32(neigh.State)
n.Flags = neigh.Flags n.Flags = int32(neigh.Flags)
if neigh.HardwareAddr != nil { if neigh.HardwareAddr != nil {
n.LLAddr = neigh.HardwareAddr.String() n.Lladdr = neigh.HardwareAddr.String()
} }
n.ToIPAddress = &vcTypes.IPAddress{ n.ToIPAddress = &pbTypes.IPAddress{
Family: netlink.FAMILY_V4, Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4),
Address: neigh.IP.String(), Address: neigh.IP.String(),
} }
if neigh.IP.To4() == nil { if neigh.IP.To4() == nil {

View File

@ -14,7 +14,8 @@ import (
"github.com/containernetworking/plugins/pkg/ns" "github.com/containernetworking/plugins/pkg/ns"
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
) )
@ -96,29 +97,29 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
// //
// Build expected results: // Build expected results:
// //
expectedAddresses := []*vcTypes.IPAddress{ expectedAddresses := []*pbTypes.IPAddress{
{Family: netlink.FAMILY_V4, Address: "172.17.0.2", Mask: "16"}, {Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4), Address: "172.17.0.2", Mask: "16"},
{Family: netlink.FAMILY_V4, Address: "182.17.0.2", Mask: "16"}, {Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4), Address: "182.17.0.2", Mask: "16"},
{Family: netlink.FAMILY_V6, Address: "2001:db8:1::242:ac11:2", Mask: "64"}, {Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V6), Address: "2001:db8:1::242:ac11:2", Mask: "64"},
} }
expectedInterfaces := []*vcTypes.Interface{ expectedInterfaces := []*pbTypes.Interface{
{Device: "eth0", Name: "eth0", IPAddresses: expectedAddresses, Mtu: 1500, HwAddr: "02:00:ca:fe:00:04"}, {Device: "eth0", Name: "eth0", IPAddresses: expectedAddresses, Mtu: 1500, HwAddr: "02:00:ca:fe:00:04"},
} }
expectedRoutes := []*vcTypes.Route{ expectedRoutes := []*pbTypes.Route{
{Dest: "", Gateway: "172.17.0.1", Device: "eth0", Source: "", Scope: uint32(254)}, {Dest: "", Gateway: "172.17.0.1", Device: "eth0", Source: "", Scope: uint32(254)},
{Dest: "172.17.0.0/16", Gateway: "172.17.0.1", Device: "eth0", Source: "172.17.0.2"}, {Dest: "172.17.0.0/16", Gateway: "172.17.0.1", Device: "eth0", Source: "172.17.0.2"},
{Dest: "2001:db8:1::/64", Gateway: "", Device: "eth0", Source: ""}, {Dest: "2001:db8:1::/64", Gateway: "", Device: "eth0", Source: ""},
{Dest: "", Gateway: "2001:db8:1::1", Device: "eth0", Source: ""}, {Dest: "", Gateway: "2001:db8:1::1", Device: "eth0", Source: ""},
} }
expectedNeighs := []*vcTypes.ARPNeighbor{ expectedNeighs := []*pbTypes.ARPNeighbor{
{ {
Device: "eth0", Device: "eth0",
State: netlink.NUD_PERMANENT, State: netlink.NUD_PERMANENT,
LLAddr: "6a:92:3a:59:70:aa", Lladdr: "6a:92:3a:59:70:aa",
ToIPAddress: &vcTypes.IPAddress{Address: "192.168.0.101", Family: netlink.FAMILY_V4}, ToIPAddress: &pbTypes.IPAddress{Address: "192.168.0.101", Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4)},
}, },
} }

View File

@ -1,49 +0,0 @@
// Copyright 2018 Intel Corporation.
//
// SPDX-License-Identifier: Apache-2.0
//
package types
// IPAddress describes an IP address.
type IPAddress struct {
Family int
Address string
Mask string
}
// Interface describes a network interface.
type Interface struct {
Device string
Name string
IPAddresses []*IPAddress
Mtu uint64
RawFlags uint32
HwAddr string
// pciAddr is the PCI address in the format "bridgeAddr/deviceAddr".
// Here, bridgeAddr is the address at which the bridge is attached on the root bus,
// while deviceAddr is the address at which the network device is attached on the bridge.
PciAddr string
// LinkType defines the type of interface described by this structure.
// The expected values are the one that are defined by the netlink
// library, regarding each type of link. Here is a non exhaustive
// list: "veth", "macvtap", "vlan", "macvlan", "tap", ...
LinkType string
}
// Route describes a network route.
type Route struct {
Dest string
Gateway string
Device string
Source string
Scope uint32
}
type ARPNeighbor struct {
ToIPAddress *IPAddress
Device string
LLAddr string
State int
Flags int
}

View File

@ -23,7 +23,7 @@ import (
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -246,7 +246,7 @@ func (m *VCMock) AddDevice(ctx context.Context, sandboxID string, info config.De
} }
// AddInterface implements the VC function of the same name. // AddInterface implements the VC function of the same name.
func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
if m.AddInterfaceFunc != nil { if m.AddInterfaceFunc != nil {
return m.AddInterfaceFunc(ctx, sandboxID, inf) return m.AddInterfaceFunc(ctx, sandboxID, inf)
} }
@ -255,7 +255,7 @@ func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *vcType
} }
// RemoveInterface implements the VC function of the same name. // RemoveInterface implements the VC function of the same name.
func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
if m.RemoveInterfaceFunc != nil { if m.RemoveInterfaceFunc != nil {
return m.RemoveInterfaceFunc(ctx, sandboxID, inf) return m.RemoveInterfaceFunc(ctx, sandboxID, inf)
} }
@ -264,7 +264,7 @@ func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *vcT
} }
// ListInterfaces implements the VC function of the same name. // ListInterfaces implements the VC function of the same name.
func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) { func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error) {
if m.ListInterfacesFunc != nil { if m.ListInterfacesFunc != nil {
return m.ListInterfacesFunc(ctx, sandboxID) return m.ListInterfacesFunc(ctx, sandboxID)
} }
@ -273,7 +273,7 @@ func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTyp
} }
// UpdateRoutes implements the VC function of the same name. // UpdateRoutes implements the VC function of the same name.
func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
if m.UpdateRoutesFunc != nil { if m.UpdateRoutesFunc != nil {
return m.UpdateRoutesFunc(ctx, sandboxID, routes) return m.UpdateRoutesFunc(ctx, sandboxID, routes)
} }
@ -282,7 +282,7 @@ func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*v
} }
// ListRoutes implements the VC function of the same name. // ListRoutes implements the VC function of the same name.
func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) { func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error) {
if m.ListRoutesFunc != nil { if m.ListRoutesFunc != nil {
return m.ListRoutesFunc(ctx, sandboxID) return m.ListRoutesFunc(ctx, sandboxID)
} }

View File

@ -13,7 +13,7 @@ import (
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/factory" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/factory"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -694,7 +694,7 @@ func TestVCMockAddInterface(t *testing.T) {
assert.Error(err) assert.Error(err)
assert.True(IsMockError(err)) assert.True(IsMockError(err))
m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
@ -721,7 +721,7 @@ func TestVCMockRemoveInterface(t *testing.T) {
assert.Error(err) assert.Error(err)
assert.True(IsMockError(err)) assert.True(IsMockError(err))
m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *vcTypes.Interface) (*vcTypes.Interface, error) { m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
@ -748,7 +748,7 @@ func TestVCMockListInterfaces(t *testing.T) {
assert.Error(err) assert.Error(err)
assert.True(IsMockError(err)) assert.True(IsMockError(err))
m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*vcTypes.Interface, error) { m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
@ -775,7 +775,7 @@ func TestVCMockUpdateRoutes(t *testing.T) {
assert.Error(err) assert.Error(err)
assert.True(IsMockError(err)) assert.True(IsMockError(err))
m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) { m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
return nil, nil return nil, nil
} }
@ -802,7 +802,7 @@ func TestVCMockListRoutes(t *testing.T) {
assert.Error(err) assert.Error(err)
assert.True(IsMockError(err)) assert.True(IsMockError(err))
m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*vcTypes.Route, error) { m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*pbTypes.Route, error) {
return nil, nil return nil, nil
} }

View File

@ -13,7 +13,7 @@ import (
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
) )
@ -196,27 +196,27 @@ func (s *Sandbox) AddDevice(info config.DeviceInfo) (api.Device, error) {
} }
// AddInterface implements the VCSandbox function of the same name. // AddInterface implements the VCSandbox function of the same name.
func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (s *Sandbox) AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
// RemoveInterface implements the VCSandbox function of the same name. // RemoveInterface implements the VCSandbox function of the same name.
func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (s *Sandbox) RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
// ListInterfaces implements the VCSandbox function of the same name. // ListInterfaces implements the VCSandbox function of the same name.
func (s *Sandbox) ListInterfaces() ([]*vcTypes.Interface, error) { func (s *Sandbox) ListInterfaces() ([]*pbTypes.Interface, error) {
return nil, nil return nil, nil
} }
// UpdateRoutes implements the VCSandbox function of the same name. // UpdateRoutes implements the VCSandbox function of the same name.
func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { func (s *Sandbox) UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
return nil, nil return nil, nil
} }
// ListRoutes implements the VCSandbox function of the same name. // ListRoutes implements the VCSandbox function of the same name.
func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) { func (s *Sandbox) ListRoutes() ([]*pbTypes.Route, error) {
return nil, nil return nil, nil
} }

View File

@ -13,7 +13,7 @@ import (
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types" pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -59,11 +59,11 @@ type Sandbox struct {
WinsizeProcessFunc func(containerID, processID string, height, width uint32) error WinsizeProcessFunc func(containerID, processID string, height, width uint32) error
IOStreamFunc func(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) IOStreamFunc func(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error)
AddDeviceFunc func(info config.DeviceInfo) (api.Device, error) AddDeviceFunc func(info config.DeviceInfo) (api.Device, error)
AddInterfaceFunc func(inf *vcTypes.Interface) (*vcTypes.Interface, error) AddInterfaceFunc func(inf *pbTypes.Interface) (*pbTypes.Interface, error)
RemoveInterfaceFunc func(inf *vcTypes.Interface) (*vcTypes.Interface, error) RemoveInterfaceFunc func(inf *pbTypes.Interface) (*pbTypes.Interface, error)
ListInterfacesFunc func() ([]*vcTypes.Interface, error) ListInterfacesFunc func() ([]*pbTypes.Interface, error)
UpdateRoutesFunc func(routes []*vcTypes.Route) ([]*vcTypes.Route, error) UpdateRoutesFunc func(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
ListRoutesFunc func() ([]*vcTypes.Route, error) ListRoutesFunc func() ([]*pbTypes.Route, error)
UpdateRuntimeMetricsFunc func() error UpdateRuntimeMetricsFunc func() error
GetAgentMetricsFunc func() (string, error) GetAgentMetricsFunc func() (string, error)
StatsFunc func() (vc.SandboxStats, error) StatsFunc func() (vc.SandboxStats, error)
@ -111,10 +111,10 @@ type VCMock struct {
AddDeviceFunc func(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) AddDeviceFunc func(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error)
AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error)
RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error)
ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error)
UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error)
ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error)
CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error
} }

View File

@ -32,6 +32,7 @@ import (
exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental" exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
@ -846,7 +847,7 @@ func (s *Sandbox) removeNetwork() error {
return s.network.Remove(s.ctx, &s.networkNS, s.hypervisor) return s.network.Remove(s.ctx, &s.networkNS, s.hypervisor)
} }
func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) { func (s *Sandbox) generateNetInfo(inf *pbTypes.Interface) (NetworkInfo, error) {
hw, err := net.ParseMAC(inf.HwAddr) hw, err := net.ParseMAC(inf.HwAddr)
if err != nil { if err != nil {
return NetworkInfo{}, err return NetworkInfo{}, err
@ -870,14 +871,14 @@ func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) {
HardwareAddr: hw, HardwareAddr: hw,
MTU: int(inf.Mtu), MTU: int(inf.Mtu),
}, },
Type: inf.LinkType, Type: inf.Type,
}, },
Addrs: addrs, Addrs: addrs,
}, nil }, nil
} }
// AddInterface adds new nic to the sandbox. // AddInterface adds new nic to the sandbox.
func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (s *Sandbox) AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
netInfo, err := s.generateNetInfo(inf) netInfo, err := s.generateNetInfo(inf)
if err != nil { if err != nil {
return nil, err return nil, err
@ -908,7 +909,7 @@ func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, erro
} }
// RemoveInterface removes a nic of the sandbox. // RemoveInterface removes a nic of the sandbox.
func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) { func (s *Sandbox) RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
for i, endpoint := range s.networkNS.Endpoints { for i, endpoint := range s.networkNS.Endpoints {
if endpoint.HardwareAddr() == inf.HwAddr { if endpoint.HardwareAddr() == inf.HwAddr {
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint") s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint")
@ -928,17 +929,17 @@ func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, e
} }
// ListInterfaces lists all nics and their configurations in the sandbox. // ListInterfaces lists all nics and their configurations in the sandbox.
func (s *Sandbox) ListInterfaces() ([]*vcTypes.Interface, error) { func (s *Sandbox) ListInterfaces() ([]*pbTypes.Interface, error) {
return s.agent.listInterfaces() return s.agent.listInterfaces()
} }
// UpdateRoutes updates the sandbox route table (e.g. for portmapping support). // UpdateRoutes updates the sandbox route table (e.g. for portmapping support).
func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) { func (s *Sandbox) UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
return s.agent.updateRoutes(routes) return s.agent.updateRoutes(routes)
} }
// ListRoutes lists all routes and their configurations in the sandbox. // ListRoutes lists all routes and their configurations in the sandbox.
func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) { func (s *Sandbox) ListRoutes() ([]*pbTypes.Route, error) {
return s.agent.listRoutes() return s.agent.listRoutes()
} }

View File

@ -13,6 +13,10 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"github.com/vishvananda/netlink"
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
) )
const cpBinaryName = "cp" const cpBinaryName = "cp"
@ -318,3 +322,14 @@ func (p *ProgramLogger) StartLogger(output io.ReadCloser) error {
func (p ProgramLogger) String() string { func (p ProgramLogger) String() string {
return p.cmd.Path return p.cmd.Path
} }
func ConvertNetlinkFamily(netlinkFamily int32) pbTypes.IPFamily {
switch netlinkFamily {
case netlink.FAMILY_V6:
return pbTypes.IPFamily_v6
case netlink.FAMILY_V4:
fallthrough
default:
return pbTypes.IPFamily_v4
}
}