From 1651451f99c6b49e43236aa6fcb72b937f39d0a5 Mon Sep 17 00:00:00 2001 From: Laszlo Kiraly Date: Thu, 19 Oct 2023 18:10:59 +0200 Subject: [PATCH] Fix interface cleanup Related issue: networkservicemesh/deployments-k8s#9778 Signed-off-by: Laszlo Kiraly --- pkg/networkservice/l2ovsconnect/client.go | 4 +++- pkg/networkservice/l2ovsconnect/local.go | 9 ++++++++- pkg/networkservice/l2ovsconnect/remote.go | 10 +++++++--- pkg/networkservice/mechanisms/kernel/common.go | 6 +++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/networkservice/l2ovsconnect/client.go b/pkg/networkservice/l2ovsconnect/client.go index a6081bb..50b9d80 100644 --- a/pkg/networkservice/l2ovsconnect/client.go +++ b/pkg/networkservice/l2ovsconnect/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Nordix Foundation. +// Copyright (c) 2021-2023 Nordix Foundation. // // SPDX-License-Identifier: Apache-2.0 // @@ -23,6 +23,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/vfconfig" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" "github.com/networkservicemesh/sdk/pkg/tools/log" @@ -76,6 +77,7 @@ func (c *l2ConnectClient) Close(ctx context.Context, conn *networkservice.Connec l2ConnectErr := addDel(ctx, logger, conn, c.bridgeName, false) ifnames.Delete(ctx, metadata.IsClient(c)) + vfconfig.Delete(ctx, metadata.IsClient(c)) if err != nil && l2ConnectErr != nil { return nil, errors.Wrap(err, l2ConnectErr.Error()) diff --git a/pkg/networkservice/l2ovsconnect/local.go b/pkg/networkservice/l2ovsconnect/local.go index af8116c..3785dc5 100644 --- a/pkg/networkservice/l2ovsconnect/local.go +++ b/pkg/networkservice/l2ovsconnect/local.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Nordix Foundation. +// Copyright (c) 2021-2023 Nordix Foundation. // // Copyright (c) 2023 Cisco and/or its affiliates. // @@ -53,6 +53,8 @@ func createLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo if stderr != "" { logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr) + } else { + logger.Debugf("Flow added on %s for port %s", bridgeName, endpointOvsPortInfo.PortName) } stdout, stderr, err = util.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleToEndpoint) @@ -65,6 +67,8 @@ func createLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo if stderr != "" { logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s", bridgeName, clientOvsPortInfo.PortName, stdout, stderr) + } else { + logger.Debugf("Flow added on %s for port %s", bridgeName, clientOvsPortInfo.PortName) } endpointOvsPortInfo.IsCrossConnected = true @@ -87,11 +91,14 @@ func deleteLocalCrossConnect(logger log.Logger, bridgeName string, endpointOvsPo "%s, stdout: %q, stderr: %q, error: %v", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr, err) return errors.Wrapf(err, "failed to delete flow on %s for port %s, stdout: %q, stderr: %q", bridgeName, endpointOvsPortInfo.PortName, stdout, stderr) } + logger.Debugf("Flow deleted on %s for port %s", bridgeName, endpointOvsPortInfo.PortName) stdout, stderr, err = util.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, fmt.Sprintf("in_port=%d", clientOvsPortInfo.PortNo)) if err != nil { logger.Errorf("Failed to delete flow on %s for port "+ "%s, stdout: %q, stderr: %q, error: %v", bridgeName, clientOvsPortInfo.PortName, stdout, stderr, err) + } else { + logger.Debugf("Flow deleted on %s for port %s", bridgeName, &clientOvsPortInfo.PortName) } return nil } diff --git a/pkg/networkservice/l2ovsconnect/remote.go b/pkg/networkservice/l2ovsconnect/remote.go index d934169..f2f79ef 100644 --- a/pkg/networkservice/l2ovsconnect/remote.go +++ b/pkg/networkservice/l2ovsconnect/remote.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Nordix Foundation. +// Copyright (c) 2021-2023 Nordix Foundation. // // Copyright (c) 2023 Cisco and/or its affiliates. // @@ -69,6 +69,8 @@ func createRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP if stderr != "" { logger.Errorf("Failed to add flow on %s for port %s stdout: %s"+ " stderr: %s", bridgeName, ovsLocalPort, stdout, stderr) + } else { + logger.Debugf("Flow added on %s for port %s", bridgeName, ovsLocalPort) } stdout, stderr, err = util.RunOVSOfctl("add-flow", "-OOpenflow13", bridgeName, ofRuleTo) @@ -81,6 +83,8 @@ func createRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP if stderr != "" { logger.Errorf("Failed to add tunnel flow on %s for port %s stdout: %s"+ " stderr: %s", bridgeName, ovsTunnelPort, stdout, stderr) + } else { + logger.Debugf("Flow added on %s for port %s", bridgeName, ovsTunnelPort) } endpointOvsPortInfo.IsCrossConnected = true @@ -121,13 +125,13 @@ func deleteRemoteCrossConnect(logger log.Logger, bridgeName string, endpointOvsP "%s, stdout: %q, stderr: %q, error: %v", bridgeName, ovsLocalPort, stdout, stderr, err) return errors.Wrapf(err, "Failed to delete flow on %s for port %s, stdout: %q, stderr: %q", bridgeName, ovsLocalPort, stdout, stderr) } - + logger.Debugf("Flow deleted on %s for port %s", bridgeName, ovsLocalPort) stdout, stderr, err = util.RunOVSOfctl("del-flows", "-OOpenflow13", bridgeName, fmt.Sprintf("in_port=%d,tun_id=%d", ovsTunnelPortNum, vni)) if err != nil { logger.Errorf("Failed to delete flow on %s for port "+ "%s on VNI %d, stdout: %q, stderr: %q, error: %v", bridgeName, ovsTunnelPort, vni, stdout, stderr, err) return errors.Wrapf(err, "failed to delete flow on %s for port %s on VNI %d, stdout: %q, stderr: %q", bridgeName, ovsTunnelPort, vni, stdout, stderr) } - + logger.Debugf("Flow deleted on %s for port %s", bridgeName, ovsTunnelPort) return nil } diff --git a/pkg/networkservice/mechanisms/kernel/common.go b/pkg/networkservice/mechanisms/kernel/common.go index 93a5241..cd4a441 100644 --- a/pkg/networkservice/mechanisms/kernel/common.go +++ b/pkg/networkservice/mechanisms/kernel/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2023 Nordix Foundation. // // Copyright (c) 2023 Cisco and/or its affiliates. // @@ -78,6 +78,7 @@ func setupVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn if err := createInterfaces(contIfName, hostIfName); err != nil { return err } + logger.Debugf("Interface %s created, peername: %s", contIfName, hostIfName) if err := SetInterfacesUp(logger, contIfName, hostIfName); err != nil { return err } @@ -166,11 +167,10 @@ func resetVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn if err := netlink.LinkDel(ifaceLink); err != nil { return errors.Errorf("local: failed to delete the VETH pair - %v", err) } + logger.Debugf("Interface %s deleted", ifaceName) delete(parentIfRefCountMap, ifaceName) delete(serviceToparentIfMap, serviceName) } - - vfconfig.Delete(ctx, isClient) return nil }