Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interface cleanup #275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 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 @@ -14,6 +14,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package l2ovsconnect chain element which cross connects both client and endpoint.
// This suppports both local and remote (vxlan) cross connections.
package l2ovsconnect
Expand All @@ -23,6 +26,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 +80,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
12 changes: 11 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 All @@ -16,6 +16,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package l2ovsconnect

import (
Expand Down Expand Up @@ -53,6 +56,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 +70,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 +94,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
}
13 changes: 10 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 All @@ -16,6 +16,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package l2ovsconnect

import (
Expand Down Expand Up @@ -69,6 +72,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 +86,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 +128,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
}
4 changes: 2 additions & 2 deletions pkg/networkservice/mechanisms/kernel/client.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.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *kernelClient) Close(ctx context.Context, conn *networkservice.Connectio
if exists {
// ovsPortInfo.IsL2Connect is always false for endpoint ovs port
if !ovsPortInfo.IsVfRepresentor {
kernelMechErr = resetVeth(ctx, logger, conn, c.bridgeName, c.parentIfRefCountMap, c.serviceToparentIfMap, ovsPortInfo.IsL2Connect, metadata.IsClient(c))
kernelMechErr = resetVeth(logger, conn, c.bridgeName, c.parentIfRefCountMap, c.serviceToparentIfMap, ovsPortInfo.IsL2Connect, metadata.IsClient(c))
} else {
kernelMechErr = resetVF(logger, ovsPortInfo, c.parentIfRefCountMap, c.bridgeName, ovsPortInfo.IsL2Connect)
}
Expand Down
8 changes: 4 additions & 4 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 @@ -111,7 +112,7 @@ func setupVeth(ctx context.Context, logger log.Logger, conn *networkservice.Conn
return nil
}

func resetVeth(ctx context.Context, logger log.Logger, conn *networkservice.Connection, bridgeName string,
func resetVeth(logger log.Logger, conn *networkservice.Connection, bridgeName string,
parentIfRefCountMap map[string]int, serviceToparentIfMap map[string]string, isL2Connect, isClient bool) error {
var mechanism *kernel.Mechanism
if mechanism = kernel.ToMechanism(conn.GetMechanism()); mechanism == nil {
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
8 changes: 4 additions & 4 deletions pkg/networkservice/mechanisms/kernel/veth_server.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.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -58,7 +58,7 @@ func (k *kernelVethServer) Request(ctx context.Context, request *networkservice.
if !isEstablished {
k.parentIfmutex.Lock()
if err := setupVeth(ctx, logger, request.GetConnection(), k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, metadata.IsClient(k)); err != nil {
_ = resetVeth(ctx, logger, request.GetConnection(), k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, false, metadata.IsClient(k))
_ = resetVeth(logger, request.GetConnection(), k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, false, metadata.IsClient(k))
k.parentIfmutex.Unlock()
return nil, err
}
Expand All @@ -72,7 +72,7 @@ func (k *kernelVethServer) Request(ctx context.Context, request *networkservice.
defer cancelClose()
if _, exists := ifnames.LoadAndDelete(closeCtx, metadata.IsClient(k)); exists {
k.parentIfmutex.Lock()
if kernelServerErr := resetVeth(closeCtx, logger, request.GetConnection(), k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, false, metadata.IsClient(k)); kernelServerErr != nil {
if kernelServerErr := resetVeth(logger, request.GetConnection(), k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, false, metadata.IsClient(k)); kernelServerErr != nil {
err = errors.Wrapf(err, "connection closed with error: %s", kernelServerErr.Error())
}
k.parentIfmutex.Unlock()
Expand All @@ -93,7 +93,7 @@ func (k *kernelVethServer) Close(ctx context.Context, conn *networkservice.Conne
var kernelServerErr error
ovsPortInfo, exists := ifnames.LoadAndDelete(ctx, metadata.IsClient(k))
if exists {
kernelServerErr = resetVeth(ctx, logger, conn, k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, ovsPortInfo.IsL2Connect, metadata.IsClient(k))
kernelServerErr = resetVeth(logger, conn, k.bridgeName, k.parentIfRefCountMap, k.serviceToparentIfMap, ovsPortInfo.IsL2Connect, metadata.IsClient(k))
}
if err != nil && kernelServerErr != nil {
return nil, errors.Wrap(err, kernelServerErr.Error())
Expand Down
Loading