mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-07 16:34:28 +01:00
runtime: add a new API for Network interface
Add GetEndpointsNum API for Network Interface to get the number of network endpoints. This is used for caculate the number of pcie root port for QemuVirt. Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
@@ -226,6 +226,9 @@ type Network interface {
|
||||
|
||||
// SetEndpoints sets a sandbox's network endpoints.
|
||||
SetEndpoints([]Endpoint)
|
||||
|
||||
// GetEndpoints number of sandbox's network endpoints.
|
||||
GetEndpointsNum() (int, error)
|
||||
}
|
||||
|
||||
func generateVCNetworkStructures(ctx context.Context, network Network) ([]*pbTypes.Interface, []*pbTypes.Route, []*pbTypes.ARPNeighbor, error) {
|
||||
|
||||
@@ -92,6 +92,10 @@ func (n *DarwinNetwork) SetEndpoints(endpoints []Endpoint) {
|
||||
n.eps = endpoints
|
||||
}
|
||||
|
||||
func (n *DarwinNetwork) GetEndpointsNum() (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func validGuestRoute(route netlink.Route) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -291,6 +291,27 @@ func (n *LinuxNetwork) endpointAlreadyAdded(netInfo *NetworkInfo) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (n *LinuxNetwork) GetEndpointsNum() (int, error) {
|
||||
netnsHandle, err := netns.GetFromPath(n.netNSPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer netnsHandle.Close()
|
||||
|
||||
netlinkHandle, err := netlink.NewHandleAt(netnsHandle)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer netlinkHandle.Close()
|
||||
|
||||
linkList, err := netlinkHandle.LinkList()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return len(linkList), nil
|
||||
}
|
||||
|
||||
// Scan the networking namespace through netlink and then:
|
||||
// 1. Create the endpoints for the relevant interfaces found there.
|
||||
// 2. Attach them to the VM.
|
||||
|
||||
Reference in New Issue
Block a user