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
|
// 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, addrs []netlink.Addr) types.Interface {
|
func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []netlink.Addr) types.Interface {
|
||||||
if linkAttrs == nil {
|
if linkAttrs == nil {
|
||||||
netmonLog.Warn("Link attributes are nil")
|
netmonLog.Warn("Link attributes are nil")
|
||||||
return types.Interface{}
|
return types.Interface{}
|
||||||
@ -289,6 +289,7 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, addrs []netlink.Addr) types.
|
|||||||
IPAddresses: ipAddrs,
|
IPAddresses: ipAddrs,
|
||||||
Mtu: uint64(linkAttrs.MTU),
|
Mtu: uint64(linkAttrs.MTU),
|
||||||
HwAddr: linkAttrs.HardwareAddr.String(),
|
HwAddr: linkAttrs.HardwareAddr.String(),
|
||||||
|
LinkType: linkType,
|
||||||
}
|
}
|
||||||
|
|
||||||
netmonLog.WithField("interface", iface).Debug("Interface converted")
|
netmonLog.WithField("interface", iface).Debug("Interface converted")
|
||||||
@ -369,7 +370,7 @@ func (n *netmon) scanNetwork() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
iface := convertInterface(linkAttrs, addrs)
|
iface := convertInterface(linkAttrs, link.Type(), addrs)
|
||||||
n.netIfaces[linkAttrs.Index] = iface
|
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.
|
// 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.
|
// Add the interface through the Kata CLI.
|
||||||
if err := n.addInterfaceCLI(iface); err != nil {
|
if err := n.addInterfaceCLI(iface); err != nil {
|
||||||
|
@ -174,6 +174,8 @@ func TestConvertInterface(t *testing.T) {
|
|||||||
HardwareAddr: hwAddr,
|
HardwareAddr: hwAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkType := "link_type_test"
|
||||||
|
|
||||||
expected := types.Interface{
|
expected := types.Interface{
|
||||||
Device: testIfaceName,
|
Device: testIfaceName,
|
||||||
Name: testIfaceName,
|
Name: testIfaceName,
|
||||||
@ -186,9 +188,10 @@ func TestConvertInterface(t *testing.T) {
|
|||||||
Mask: "0",
|
Mask: "0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
LinkType: linkType,
|
||||||
}
|
}
|
||||||
|
|
||||||
got := convertInterface(linkAttrs, addrs)
|
got := convertInterface(linkAttrs, linkType, addrs)
|
||||||
assert.True(t, reflect.DeepEqual(expected, got),
|
assert.True(t, reflect.DeepEqual(expected, got),
|
||||||
"Got %+v\nExpected %+v", got, expected)
|
"Got %+v\nExpected %+v", got, expected)
|
||||||
}
|
}
|
||||||
@ -268,6 +271,7 @@ func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, types.I
|
|||||||
Name: testIfaceName,
|
Name: testIfaceName,
|
||||||
Mtu: uint64(testMTU),
|
Mtu: uint64(testMTU),
|
||||||
HwAddr: testHwAddr,
|
HwAddr: testHwAddr,
|
||||||
|
LinkType: link.Type(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return attrs.Index, iface
|
return attrs.Index, iface
|
||||||
|
Loading…
Reference in New Issue
Block a user