netmon: Rely on new interface field LinkType

In order to provide the right information about the interface that
needs to be added, kata-netmon provisions the new field LinkType of
the Interface structure.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2018-10-29 09:03:31 -07:00
parent 7bf84d05ad
commit 45b219107c
2 changed files with 13 additions and 8 deletions

View File

@ -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 {

View File

@ -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)
}
@ -268,6 +271,7 @@ func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, types.I
Name: testIfaceName,
Mtu: uint64(testMTU),
HwAddr: testHwAddr,
LinkType: link.Type(),
}
return attrs.Index, iface