Skip to content

Commit

Permalink
Fix interface cleanup
Browse files Browse the repository at this point in the history
Related issue: networkservicemesh/deployments-k8s#9778

Signed-off-by: Laszlo Kiraly <laszlo.kiraly@est.tech>
  • Loading branch information
ljkiraly committed Oct 19, 2023
1 parent f18cc35 commit 1651451
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pkg/networkservice/l2ovsconnect/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2023 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
9 changes: 8 additions & 1 deletion pkg/networkservice/l2ovsconnect/local.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2023 Nordix Foundation.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
}
10 changes: 7 additions & 3 deletions pkg/networkservice/l2ovsconnect/remote.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2023 Nordix Foundation.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/networkservice/mechanisms/kernel/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 Nordix Foundation.
// Copyright (c) 2021-2023 Nordix Foundation.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 1651451

Please sign in to comment.