diff --git a/.golangci.yml b/.golangci.yml index 72e0342a8..1dff6b438 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -254,3 +254,11 @@ issues: linters: - funlen text: "Function 'TestConnectServer_Request'" + - path: pkg/registry/common/recvfd/gen.go + linters: + - structcheck + text: "is unused" + - path: pkg/networkservice/common/mechanisms/recvfd/gen.go + linters: + - structcheck + text: "is unused" diff --git a/pkg/networkservice/chains/nsmgr/fd_chains_linux.go b/pkg/networkservice/chains/nsmgr/fd_chains_linux.go deleted file mode 100644 index c6da03b5d..000000000 --- a/pkg/networkservice/chains/nsmgr/fd_chains_linux.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build linux - -package nsmgr - -import ( - "github.com/networkservicemesh/api/pkg/api/networkservice" - "github.com/networkservicemesh/api/pkg/api/registry" - - "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" - - "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd" - recvfdreg "github.com/networkservicemesh/sdk/pkg/registry/common/recvfd" -) - -// newRecvFD - construct a recvfd server -func newRecvFD() networkservice.NetworkServiceServer { - return recvfd.NewServer() -} - -// newSendFDClient - construct a sendfd server -func newSendFDClient() networkservice.NetworkServiceClient { - return sendfd.NewClient() -} - -// newRecvFDEndpointRegistry - construct a registry server -func newRecvFDEndpointRegistry() registry.NetworkServiceEndpointRegistryServer { - return recvfdreg.NewNetworkServiceEndpointRegistryServer() -} diff --git a/pkg/networkservice/chains/nsmgr/server.go b/pkg/networkservice/chains/nsmgr/server.go index f913fed1e..e5c65e69e 100644 --- a/pkg/networkservice/chains/nsmgr/server.go +++ b/pkg/networkservice/chains/nsmgr/server.go @@ -1,6 +1,6 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // -// Copyright (c) 2020 Doc.ai and/or its affiliates. +// Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -24,6 +24,8 @@ import ( "time" "github.com/networkservicemesh/sdk/pkg/networkservice/chains/client" + "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd" + "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" "github.com/networkservicemesh/sdk/pkg/registry/common/expire" "github.com/networkservicemesh/sdk/pkg/registry/common/querycache" "github.com/networkservicemesh/sdk/pkg/registry/core/next" @@ -41,6 +43,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/grpcutils" "github.com/networkservicemesh/sdk/pkg/registry/common/memory" + registry_recvfd "github.com/networkservicemesh/sdk/pkg/registry/common/recvfd" "github.com/networkservicemesh/sdk/pkg/registry/common/setid" "github.com/networkservicemesh/sdk/pkg/registry/common/seturl" chain_registry "github.com/networkservicemesh/sdk/pkg/registry/core/chain" @@ -113,7 +116,7 @@ func NewServer(ctx context.Context, nsmRegistration *registryapi.NetworkServiceE roundrobin.NewServer(), localbypass.NewServer(&localbypassRegistryServer), excludedprefixes.NewServer(ctx), - newRecvFD(), // Receive any files passed + recvfd.NewServer(), // Receive any files passed interpose.NewServer(&interposeRegistry), filtermechanisms.NewServer(&urlsRegistryServer), connect.NewServer(ctx, @@ -121,9 +124,11 @@ func NewServer(ctx context.Context, nsmRegistration *registryapi.NetworkServiceE nsmRegistration.Name, addressof.NetworkServiceClient(adapters.NewServerToClient(rv)), tokenGenerator, - newSendFDClient(), // Send passed files. + recvfd.NewClient(), + sendfd.NewClient(), // Send passed files. ), clientDialOptions...), + sendfd.NewServer(), ) nsChain := chain_registry.NewNamedNetworkServiceRegistryServer(nsmRegistration.Name+".NetworkServiceRegistry", nsRegistry) @@ -131,10 +136,10 @@ func NewServer(ctx context.Context, nsmRegistration *registryapi.NetworkServiceE nseChain := chain_registry.NewNamedNetworkServiceEndpointRegistryServer( nsmRegistration.Name+".NetworkServiceEndpointRegistry", expire.NewNetworkServiceEndpointRegistryServer(time.Minute), - newRecvFDEndpointRegistry(), // Allow to receive a passed files + registry_recvfd.NewNetworkServiceEndpointRegistryServer(), // Allow to receive a passed files urlsRegistryServer, - interposeRegistry, // Store cross connect NSEs - localbypassRegistryServer, // Store endpoint Id to EndpointURL for local access. + interposeRegistry, // Store cross connect NSEs + localbypassRegistryServer, // Store endpoint Id to EndpointURL for local access. seturl.NewNetworkServiceEndpointRegistryServer(nsmRegistration.Url), // Remember endpoint URL nseRegistry, // Register NSE inside Remote registry with ID assigned ) diff --git a/pkg/networkservice/common/mechanisms/recvfd/client.go b/pkg/networkservice/common/mechanisms/recvfd/client.go index 517d4bd64..0c67e84f4 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/client.go +++ b/pkg/networkservice/common/mechanisms/recvfd/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // Copyright (c) 2021 Doc.ai and/or its affiliates. // @@ -16,7 +16,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux package recvfd diff --git a/pkg/networkservice/chains/nsmgr/fd_chains.go b/pkg/networkservice/common/mechanisms/recvfd/client_notlinux.go similarity index 55% rename from pkg/networkservice/chains/nsmgr/fd_chains.go rename to pkg/networkservice/common/mechanisms/recvfd/client_notlinux.go index caf6015da..aaf6d38bb 100644 --- a/pkg/networkservice/chains/nsmgr/fd_chains.go +++ b/pkg/networkservice/common/mechanisms/recvfd/client_notlinux.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. +// Copyright (c) 2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -16,27 +16,16 @@ // +build !linux -package nsmgr +package recvfd import ( "github.com/networkservicemesh/api/pkg/api/networkservice" - "github.com/networkservicemesh/api/pkg/api/registry" "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" - null_registry "github.com/networkservicemesh/sdk/pkg/registry/common/null" ) -// newRecvFD - construct a recvfd server -func newRecvFD() networkservice.NetworkServiceServer { - return null.NewServer() -} - -// newSendFDClient - construct a sendfd server -func newSendFDClient() networkservice.NetworkServiceClient { +// NewClient - returns client chain element to recv FDs over the connection (if possible) for any Mechanism.Parameters[common.InodeURL] +// url of scheme 'inode'. +func NewClient() networkservice.NetworkServiceClient { return null.NewClient() } - -// newRecvFDEndpointRegistry - construct a registry server -func newRecvFDEndpointRegistry() registry.NetworkServiceEndpointRegistryServer { - return null_registry.NewNetworkServiceEndpointRegistryServer() -} diff --git a/pkg/networkservice/common/mechanisms/recvfd/common.go b/pkg/networkservice/common/mechanisms/recvfd/common.go index f0862eeeb..3fc91bc8b 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/common.go +++ b/pkg/networkservice/common/mechanisms/recvfd/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux package recvfd diff --git a/pkg/networkservice/common/mechanisms/recvfd/server.go b/pkg/networkservice/common/mechanisms/recvfd/server.go index a53a04251..ff578653f 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/server.go +++ b/pkg/networkservice/common/mechanisms/recvfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux package recvfd diff --git a/pkg/networkservice/common/mechanisms/recvfd/server_notlinux.go b/pkg/networkservice/common/mechanisms/recvfd/server_notlinux.go new file mode 100644 index 000000000..b1299f32d --- /dev/null +++ b/pkg/networkservice/common/mechanisms/recvfd/server_notlinux.go @@ -0,0 +1,31 @@ +// Copyright (c) 2021 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !linux + +package recvfd + +import ( + "github.com/networkservicemesh/api/pkg/api/networkservice" + + "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" +) + +// NewServer - returns server chain element to recv FDs over the connection (if possible) for any Mechanism.Parameters[common.InodeURL] +// url of scheme 'inode'. +func NewServer() networkservice.NetworkServiceServer { + return null.NewServer() +} diff --git a/pkg/networkservice/common/mechanisms/sendfd/client.go b/pkg/networkservice/common/mechanisms/sendfd/client.go index 01e9e8c6d..40b418dd3 100644 --- a/pkg/networkservice/common/mechanisms/sendfd/client.go +++ b/pkg/networkservice/common/mechanisms/sendfd/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux package sendfd diff --git a/pkg/networkservice/common/mechanisms/sendfd/client_notlinux.go b/pkg/networkservice/common/mechanisms/sendfd/client_notlinux.go new file mode 100644 index 000000000..399e46d5e --- /dev/null +++ b/pkg/networkservice/common/mechanisms/sendfd/client_notlinux.go @@ -0,0 +1,30 @@ +// Copyright (c) 2021 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !linux + +package sendfd + +import ( + "github.com/networkservicemesh/api/pkg/api/networkservice" + + "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" +) + +// NewClient - returns client which sends any "file://" Mechanism.Parameters[common.InodeURLs]s across the connection as fds (if possible) to the server +func NewClient() networkservice.NetworkServiceClient { + return null.NewClient() +} diff --git a/pkg/networkservice/common/mechanisms/sendfd/common.go b/pkg/networkservice/common/mechanisms/sendfd/common.go index ff1b8dc27..92a8e908c 100644 --- a/pkg/networkservice/common/mechanisms/sendfd/common.go +++ b/pkg/networkservice/common/mechanisms/sendfd/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux package sendfd diff --git a/pkg/networkservice/common/mechanisms/sendfd/server.go b/pkg/networkservice/common/mechanisms/sendfd/server.go index 6f4dd3a18..29db6a9be 100644 --- a/pkg/networkservice/common/mechanisms/sendfd/server.go +++ b/pkg/networkservice/common/mechanisms/sendfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux package sendfd diff --git a/pkg/networkservice/common/mechanisms/sendfd/server_notlinux.go b/pkg/networkservice/common/mechanisms/sendfd/server_notlinux.go new file mode 100644 index 000000000..5a98517d9 --- /dev/null +++ b/pkg/networkservice/common/mechanisms/sendfd/server_notlinux.go @@ -0,0 +1,30 @@ +// Copyright (c) 2021 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !linux + +package sendfd + +import ( + "github.com/networkservicemesh/api/pkg/api/networkservice" + + "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" +) + +// NewServer - returns server which sends any "file://" Mechanism.Parameters[common.InodeURLs]s across the connection as fds (if possible) to the client +func NewServer() networkservice.NetworkServiceServer { + return null.NewServer() +} diff --git a/pkg/registry/common/recvfd/server.go b/pkg/registry/common/recvfd/server.go index 8a1b22611..2932a1a76 100644 --- a/pkg/registry/common/recvfd/server.go +++ b/pkg/registry/common/recvfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2021 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !windows +// +build linux // Package recvfd provides an NSE registry server chain element that: // 1. Receives and fd over a unix file socket if the nse.URL is an inode://${dev}/${inode} url diff --git a/pkg/registry/common/recvfd/server_notlinux.go b/pkg/registry/common/recvfd/server_notlinux.go new file mode 100644 index 000000000..d4b5aff83 --- /dev/null +++ b/pkg/registry/common/recvfd/server_notlinux.go @@ -0,0 +1,32 @@ +// Copyright (c) 2021 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !linux + +package recvfd + +import ( + "github.com/networkservicemesh/api/pkg/api/registry" + + "github.com/networkservicemesh/sdk/pkg/registry/common/null" +) + +// NewNetworkServiceEndpointRegistryServer - creates new NSE registry chain element that will: +// 1. Receive and fd over a unix file socket if the nse.URL is an inode://${dev}/${inode} url +// 2. Rewrite the nse.URL to unix:///proc/${pid}/fd/${fd} so it can be used by a normal dialer +func NewNetworkServiceEndpointRegistryServer() registry.NetworkServiceEndpointRegistryServer { + return null.NewNetworkServiceEndpointRegistryServer() +}