diff --git a/netmon/netmon.go b/netmon/netmon.go index 138cd952e..ab932abc8 100644 --- a/netmon/netmon.go +++ b/netmon/netmon.go @@ -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{} @@ -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") @@ -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 } @@ -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 { diff --git a/netmon/netmon_test.go b/netmon/netmon_test.go index bb5e62ebb..cc5793e12 100644 --- a/netmon/netmon_test.go +++ b/netmon/netmon_test.go @@ -174,6 +174,8 @@ func TestConvertInterface(t *testing.T) { HardwareAddr: hwAddr, } + linkType := "link_type_test" + expected := types.Interface{ Device: testIfaceName, Name: testIfaceName, @@ -186,9 +188,10 @@ func TestConvertInterface(t *testing.T) { 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) } @@ -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