mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 11:44:38 +00:00
runtime: issue with non-empty []Endpoint in RemoveEndpoints
In the RemoveEndpoints(), when the endpoints paramete isn't empty, using idx may result in wrong endpoint removals. To improve, directly passing the endpoint parameter helps locate the correct elements within n.eps. Fixes: #7732 Signed-off-by: shixuanqing <1356292400@qq.com> Fixes: #7732 Signed-off-by: shixuanqing <1356292400@qq.com> Update src/runtime/virtcontainers/network_linux.go Co-authored-by: Xuewei Niu <justxuewei@apache.org>
This commit is contained in:
parent
9766f9090c
commit
1636abbe1c
@ -211,12 +211,17 @@ func (n *LinuxNetwork) addSingleEndpoint(ctx context.Context, s *Sandbox, netInf
|
||||
return endpoint, nil
|
||||
}
|
||||
|
||||
func (n *LinuxNetwork) removeSingleEndpoint(ctx context.Context, s *Sandbox, idx int, hotplug bool) error {
|
||||
if idx > len(n.eps)-1 {
|
||||
return fmt.Errorf("Endpoint index overflow")
|
||||
func (n *LinuxNetwork) removeSingleEndpoint(ctx context.Context, s *Sandbox, endpoint Endpoint, hotplug bool) error {
|
||||
var idx int = len(n.eps)
|
||||
for i, val := range n.eps {
|
||||
if val.HardwareAddr() == endpoint.HardwareAddr() {
|
||||
idx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if idx == len(n.eps) {
|
||||
return fmt.Errorf("Endpoint not found")
|
||||
}
|
||||
|
||||
endpoint := n.eps[idx]
|
||||
|
||||
if endpoint.GetRxRateLimiter() {
|
||||
networkLogger().WithField("endpoint-type", endpoint.Type()).Info("Deleting rx rate limiter")
|
||||
@ -384,7 +389,7 @@ func (n *LinuxNetwork) RemoveEndpoints(ctx context.Context, s *Sandbox, endpoint
|
||||
eps = endpoints
|
||||
}
|
||||
|
||||
for idx, ep := range eps {
|
||||
for _, ep := range eps {
|
||||
if endpoints != nil {
|
||||
new_ep, _ := findEndpoint(ep, n.eps)
|
||||
if new_ep == nil {
|
||||
@ -392,7 +397,7 @@ func (n *LinuxNetwork) RemoveEndpoints(ctx context.Context, s *Sandbox, endpoint
|
||||
}
|
||||
}
|
||||
|
||||
if err := n.removeSingleEndpoint(ctx, s, idx, hotplug); err != nil {
|
||||
if err := n.removeSingleEndpoint(ctx, s, ep, hotplug); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user