go.ligato.io/vpp-agent/v3@v3.5.0/plugins/linux/nsplugin/ns_plugin_api.go (about)

     1  // Copyright (c) 2018 Cisco and/or its affiliates.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at:
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package nsplugin
    16  
    17  import (
    18  	"github.com/vishvananda/netns"
    19  
    20  	"go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin/linuxcalls"
    21  	linux_namespace "go.ligato.io/vpp-agent/v3/proto/ligato/linux/namespace"
    22  )
    23  
    24  // API defines methods exposed by NsPlugin.
    25  type API interface {
    26  	// SwitchToNamespace switches the network namespace of the current thread.
    27  	// Caller should eventually call the returned "revert" function in order to get back to the original
    28  	// network namespace (for example using "defer revert()").
    29  	SwitchToNamespace(ctx linuxcalls.NamespaceMgmtCtx, ns *linux_namespace.NetNamespace) (revert func(), err error)
    30  
    31  	// GetNamespaceHandle returns low-level run-time handle for the given namespace
    32  	// to be used with Netlink API. Do not forget to eventually close the handle using
    33  	// the netns.NsHandle.Close() method.
    34  	GetNamespaceHandle(ctx linuxcalls.NamespaceMgmtCtx, ns *linux_namespace.NetNamespace) (handle netns.NsHandle, err error)
    35  }