mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +00:00
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:
parent
7bf84d05ad
commit
45b219107c
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user