From c2e3528842236e59f1cb0a33cf50b9c620559423 Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Tue, 21 Sep 2021 11:20:21 +0200 Subject: [PATCH] use container netns id for connection established check Signed-off-by: Periyasamy Palanisamy --- pkg/kernel/networkservice/inject/client.go | 7 ++++++- pkg/kernel/networkservice/inject/server.go | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/kernel/networkservice/inject/client.go b/pkg/kernel/networkservice/inject/client.go index 73a09644..0ec8f1b0 100644 --- a/pkg/kernel/networkservice/inject/client.go +++ b/pkg/kernel/networkservice/inject/client.go @@ -27,6 +27,8 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" "github.com/networkservicemesh/sdk/pkg/tools/postpone" + + "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/vfconfig" ) type injectClient struct{} @@ -39,7 +41,10 @@ func NewClient() networkservice.NetworkServiceClient { } func (c *injectClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { - isEstablished := request.GetConnection().GetNextPathSegment() != nil + var isEstablished bool + if vfConfig, ok := vfconfig.Load(ctx, metadata.IsClient(c)); ok { + isEstablished = int(vfConfig.ContNetNS) != 0 + } postponeCtxFunc := postpone.ContextWithValues(ctx) diff --git a/pkg/kernel/networkservice/inject/server.go b/pkg/kernel/networkservice/inject/server.go index 41931dea..103e5879 100644 --- a/pkg/kernel/networkservice/inject/server.go +++ b/pkg/kernel/networkservice/inject/server.go @@ -28,6 +28,8 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" "github.com/networkservicemesh/sdk/pkg/tools/postpone" + + "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/vfconfig" ) type injectServer struct{} @@ -44,7 +46,11 @@ func (s *injectServer) Request(ctx context.Context, request *networkservice.Netw return next.Server(ctx).Request(ctx, request) } - isEstablished := request.GetConnection().GetNextPathSegment() != nil + var isEstablished bool + if vfConfig, ok := vfconfig.Load(ctx, metadata.IsClient(s)); ok { + isEstablished = int(vfConfig.ContNetNS) != 0 + } + if !isEstablished { if err := move(ctx, request.GetConnection(), metadata.IsClient(s), false); err != nil { return nil, err