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

Commit

Permalink
netmon: Rely on new interface field LinkType
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sebastien Boeuf committed Nov 2, 2018
1 parent 7bf84d0 commit 45b2191
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions netmon/netmon.go
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -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
14 changes: 9 additions & 5 deletions netmon/netmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func TestConvertInterface(t *testing.T) {
HardwareAddr: hwAddr,
}

linkType := "link_type_test"

expected := types.Interface{
Device: testIfaceName,
Name: testIfaceName,
Expand All @@ -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)
}
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

0 comments on commit 45b2191

Please sign in to comment.