From 814aea01ba8fb6e7e294154a105a997b15d5e437 Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Tue, 31 Aug 2021 09:49:14 +0200 Subject: [PATCH] add mechanism check for close handler Signed-off-by: Periyasamy Palanisamy --- .../mechanisms/kernel/client.go | 28 +++++++++--------- .../mechanisms/kernel/server.go | 29 ++++++++++--------- pkg/networkservice/mechanisms/vxlan/server.go | 17 ++++++----- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/pkg/networkservice/mechanisms/kernel/client.go b/pkg/networkservice/mechanisms/kernel/client.go index 94457e4..1ca30be 100644 --- a/pkg/networkservice/mechanisms/kernel/client.go +++ b/pkg/networkservice/mechanisms/kernel/client.go @@ -88,21 +88,23 @@ func (c *kernelClient) Close(ctx context.Context, conn *networkservice.Connectio logger := log.FromContext(ctx).WithField("kernelClient", "Close") _, err := next.Client(ctx).Close(ctx, conn, opts...) - var kernelMechErr error - ovsPortInfo, exists := ifnames.Load(ctx, metadata.IsClient(c)) - if exists { - if !ovsPortInfo.IsVfRepresentor { - kernelMechErr = resetVeth(ctx, logger, conn, c.bridgeName, metadata.IsClient(c)) - } else { - kernelMechErr = resetVF(logger, ovsPortInfo, c.bridgeName) + if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil { + var kernelMechErr error + ovsPortInfo, exists := ifnames.Load(ctx, metadata.IsClient(c)) + if exists { + if !ovsPortInfo.IsVfRepresentor { + kernelMechErr = resetVeth(ctx, logger, conn, c.bridgeName, metadata.IsClient(c)) + } else { + kernelMechErr = resetVF(logger, ovsPortInfo, c.bridgeName) + } } - } - if err != nil && kernelMechErr != nil { - return nil, errors.Wrap(err, kernelMechErr.Error()) - } - if kernelMechErr != nil { - return nil, kernelMechErr + if err != nil && kernelMechErr != nil { + return nil, errors.Wrap(err, kernelMechErr.Error()) + } + if kernelMechErr != nil { + return nil, kernelMechErr + } } return &empty.Empty{}, err diff --git a/pkg/networkservice/mechanisms/kernel/server.go b/pkg/networkservice/mechanisms/kernel/server.go index e75858c..d19c4eb 100644 --- a/pkg/networkservice/mechanisms/kernel/server.go +++ b/pkg/networkservice/mechanisms/kernel/server.go @@ -23,6 +23,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" "github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/resourcepool" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" @@ -70,21 +71,23 @@ func (k *kernelServer) Close(ctx context.Context, conn *networkservice.Connectio logger := log.FromContext(ctx).WithField("kernelServer", "Close") _, err := next.Server(ctx).Close(ctx, conn) - var kernelServerErr error - ovsPortInfo, exists := ifnames.LoadAndDelete(ctx, metadata.IsClient(k)) - if exists { - if !ovsPortInfo.IsVfRepresentor { - kernelServerErr = resetVeth(ctx, logger, conn, k.bridgeName, metadata.IsClient(k)) - } else { - kernelServerErr = resetVF(logger, ovsPortInfo, k.bridgeName) + if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil { + var kernelServerErr error + ovsPortInfo, exists := ifnames.LoadAndDelete(ctx, metadata.IsClient(k)) + if exists { + if !ovsPortInfo.IsVfRepresentor { + kernelServerErr = resetVeth(ctx, logger, conn, k.bridgeName, metadata.IsClient(k)) + } else { + kernelServerErr = resetVF(logger, ovsPortInfo, k.bridgeName) + } } - } - if err != nil && kernelServerErr != nil { - return nil, errors.Wrap(err, kernelServerErr.Error()) - } - if kernelServerErr != nil { - return nil, kernelServerErr + if err != nil && kernelServerErr != nil { + return nil, errors.Wrap(err, kernelServerErr.Error()) + } + if kernelServerErr != nil { + return nil, kernelServerErr + } } return &empty.Empty{}, err diff --git a/pkg/networkservice/mechanisms/vxlan/server.go b/pkg/networkservice/mechanisms/vxlan/server.go index a4841a6..378d84d 100644 --- a/pkg/networkservice/mechanisms/vxlan/server.go +++ b/pkg/networkservice/mechanisms/vxlan/server.go @@ -32,6 +32,7 @@ import ( "github.com/networkservicemesh/sdk-ovs/pkg/tools/ifnames" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vxlan" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/vxlan/vni" ) @@ -74,14 +75,16 @@ func (v *vxlanServer) Request(ctx context.Context, request *networkservice.Netwo func (v *vxlanServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { _, err := next.Server(ctx).Close(ctx, conn) - vxlanServerErr := remove(conn, v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v)) - ifnames.Delete(ctx, metadata.IsClient(v)) + if mechanism := vxlan.ToMechanism(conn.GetMechanism()); mechanism != nil { + vxlanServerErr := remove(conn, v.bridgeName, v.vxlanInterfacesMutex, v.vxlanInterfacesMap, metadata.IsClient(v)) + ifnames.Delete(ctx, metadata.IsClient(v)) - if err != nil && vxlanServerErr != nil { - return nil, errors.Wrap(err, vxlanServerErr.Error()) - } - if vxlanServerErr != nil { - return nil, vxlanServerErr + if err != nil && vxlanServerErr != nil { + return nil, errors.Wrap(err, vxlanServerErr.Error()) + } + if vxlanServerErr != nil { + return nil, vxlanServerErr + } } return &empty.Empty{}, err }