From e97b5bed59685bbb91345c1c935eb46c0f28f295 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Thu, 27 Jun 2024 20:48:01 +0700 Subject: [PATCH] important fix Signed-off-by: NikitaSkrynnik --- go.mod | 4 ++ go.sum | 4 -- pkg/networkservice/chains/forwarder/server.go | 53 +++++++++++++++++-- .../mechanisms/kernel/kerneltap/common.go | 2 +- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index d30425c7..d9c216c3 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,10 @@ require ( google.golang.org/protobuf v1.33.0 ) +replace github.com/networkservicemesh/sdk => ../sdk + +replace github.com/networkservicemesh/sdk-kernel => ../sdk-kernel + require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/OneOfOne/xxhash v1.2.8 // indirect diff --git a/go.sum b/go.sum index 21585b3c..a31c4a16 100644 --- a/go.sum +++ b/go.sum @@ -118,10 +118,6 @@ github.com/networkservicemesh/api v1.13.1-0.20240424210452-d0df98851760 h1:EaWGg github.com/networkservicemesh/api v1.13.1-0.20240424210452-d0df98851760/go.mod h1:B8FmS3XZ7NZY7ZEtdcNg2NHYppDHlr4kl4eecdZN9eI= github.com/networkservicemesh/govpp v0.0.0-20240328101142-8a444680fbba h1:7B6X6N7rwJNpnfsUlBavxuZdYqTx8nAKwxVS/AkuX1o= github.com/networkservicemesh/govpp v0.0.0-20240328101142-8a444680fbba/go.mod h1:CwikXQ3p/y3j6+HbQQWXKv0f4LPyUd2vKTiViG93qWA= -github.com/networkservicemesh/sdk v0.5.1-0.20240604143537-e3eed82dc1b4 h1:6FTn6PPMFCF/awAgvzMJwa+WC6wlbveGvGdGKjRXqoM= -github.com/networkservicemesh/sdk v0.5.1-0.20240604143537-e3eed82dc1b4/go.mod h1:soFR6Mg5LTVvEI0zXNcbWoBnn4hqUK7ItZBQJ3Jbszo= -github.com/networkservicemesh/sdk-kernel v0.0.0-20240604150951-293bea632223 h1:1p0VW8jSSYYLdWpcC29lu7wGBcmZf/s/PlLVJi4oGT8= -github.com/networkservicemesh/sdk-kernel v0.0.0-20240604150951-293bea632223/go.mod h1:106yEon0olXuKYX721JqSQycpiuRMeQ/h4WiID2qIHw= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= github.com/open-policy-agent/opa v0.44.0 h1:sEZthsrWBqIN+ShTMJ0Hcz6a3GkYsY4FaB2S/ou2hZk= github.com/open-policy-agent/opa v0.44.0/go.mod h1:YpJaFIk5pq89n/k72c1lVvfvR5uopdJft2tMg1CW/yU= diff --git a/pkg/networkservice/chains/forwarder/server.go b/pkg/networkservice/chains/forwarder/server.go index 54d37892..4063eac9 100644 --- a/pkg/networkservice/chains/forwarder/server.go +++ b/pkg/networkservice/chains/forwarder/server.go @@ -30,8 +30,10 @@ import ( "sync" "time" + "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" "go.fd.io/govpp/api" + "google.golang.org/grpc" "github.com/networkservicemesh/api/pkg/api/networkservice" ipsecapi "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/ipsec" @@ -49,6 +51,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanismtranslation" "github.com/networkservicemesh/sdk/pkg/networkservice/common/roundrobin" + "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/tools/log" authmonitor "github.com/networkservicemesh/sdk/pkg/tools/monitorconnection/authorize" "github.com/networkservicemesh/sdk/pkg/tools/token" @@ -68,7 +71,6 @@ import ( "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vlan" "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vxlan" "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/wireguard" - "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/metrics" "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/nsmonitor" "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/pinhole" "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/tag" @@ -77,6 +79,51 @@ import ( "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/xconnect/l2bridgedomain" ) +type closeServer struct { +} + +// NewServer - returns server chain element to recv FDs over the connection (if possible) for any Mechanism.Parameters[common.InodeURL] +// url of scheme 'inode'. +func NewCloseServer() networkservice.NetworkServiceServer { + return &closeServer{} +} + +func (r *closeServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { + conn, err := next.Server(ctx).Request(ctx, request) + if err != nil || ctx.Err() != nil { + r.Close(context.Background(), request.Connection) + return nil, err + } + + return conn, err +} + +func (r *closeServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { + return next.Server(ctx).Close(ctx, conn) +} + +type closeClient struct { +} + +// NewClient - returns client chain element to recv FDs over the connection (if possible) for any Mechanism.Parameters[common.InodeURL] +// url of scheme 'inode'. +func NewCloseClient() networkservice.NetworkServiceClient { + return &closeClient{} +} + +func (r *closeClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { + conn, err := next.Client(ctx).Request(ctx, request, opts...) + if err != nil || ctx.Err() != nil { + r.Close(context.Background(), request.Connection, opts...) + return nil, err + } + return conn, err +} + +func (r *closeClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { + return next.Client(ctx).Close(ctx, conn, opts...) +} + type xconnectNSServer struct { endpoint.Endpoint } @@ -117,9 +164,9 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn additionalFunctionality := []networkservice.NetworkServiceServer{ recvfd.NewServer(), sendfd.NewServer(), + NewCloseServer(), discover.NewServer(nsClient, nseClient), roundrobin.NewServer(), - metrics.NewServer(ctx, vppConn, opts.statsOpts...), up.NewServer(ctx, vppConn), xconnect.NewServer(vppConn), l2bridgedomain.NewServer(vppConn), @@ -146,10 +193,10 @@ func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, vppConn client.WithDialTimeout(opts.dialTimeout), client.WithAdditionalFunctionality( append([]networkservice.NetworkServiceClient{ + NewCloseClient(), cleanup.NewClient(ctx, opts.cleanupOpts...), mechanismtranslation.NewClient(), connectioncontextkernel.NewClient(), - metrics.NewClient(ctx, vppConn, opts.statsOpts...), up.NewClient(ctx, vppConn), mtu.NewClient(vppConn), tag.NewClient(ctx, vppConn), diff --git a/pkg/networkservice/mechanisms/kernel/kerneltap/common.go b/pkg/networkservice/mechanisms/kernel/kerneltap/common.go index 2dc43aec..3282a03b 100644 --- a/pkg/networkservice/mechanisms/kernel/kerneltap/common.go +++ b/pkg/networkservice/mechanisms/kernel/kerneltap/common.go @@ -147,7 +147,7 @@ func del(ctx context.Context, conn *networkservice.Connection, vppConn api.Conne return nil } now := time.Now() - _, err := tapv2.NewServiceClient(vppConn).TapDeleteV2(ctx, &tapv2.TapDeleteV2{ + _, err := tapv2.NewServiceClient(vppConn).TapDeleteV2(context.Background(), &tapv2.TapDeleteV2{ SwIfIndex: swIfIndex, }) if err != nil {