2015-04-13 18:40:42 +00:00
|
|
|
package driverapi
|
|
|
|
|
2016-01-28 19:54:03 +00:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2021-04-06 00:24:47 +00:00
|
|
|
"github.com/docker/docker/libnetwork/discoverapi"
|
2021-05-28 00:15:56 +00:00
|
|
|
"github.com/docker/docker/pkg/plugingetter"
|
2016-01-28 19:54:03 +00:00
|
|
|
)
|
2015-04-13 18:40:42 +00:00
|
|
|
|
2015-05-16 01:14:36 +00:00
|
|
|
// NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
|
|
|
|
const NetworkPluginEndpointType = "NetworkDriver"
|
|
|
|
|
2015-04-13 18:40:42 +00:00
|
|
|
// Driver is an interface that every plugin driver needs to implement.
|
|
|
|
type Driver interface {
|
2016-01-28 19:54:03 +00:00
|
|
|
discoverapi.Discover
|
|
|
|
|
2016-02-26 19:53:13 +00:00
|
|
|
// NetworkAllocate invokes the driver method to allocate network
|
|
|
|
// specific resources passing network id and network specific config.
|
|
|
|
// It returns a key,value pair of network specific driver allocations
|
2016-02-26 19:54:35 +00:00
|
|
|
// to the caller.
|
|
|
|
NetworkAllocate(nid string, options map[string]string, ipV4Data, ipV6Data []IPAMData) (map[string]string, error)
|
2016-02-26 19:53:13 +00:00
|
|
|
|
|
|
|
// NetworkFree invokes the driver method to free network specific resources
|
|
|
|
// associated with a given network id.
|
|
|
|
NetworkFree(nid string) error
|
|
|
|
|
2016-04-19 02:55:39 +00:00
|
|
|
// CreateNetwork invokes the driver method to create a network
|
|
|
|
// passing the network id and network specific config. The
|
|
|
|
// config mechanism will eventually be replaced with labels
|
|
|
|
// which are yet to be introduced. The driver can return a
|
|
|
|
// list of table names for which it is interested in receiving
|
|
|
|
// notification when a CRUD operation is performed on any
|
|
|
|
// entry in that table. This will be ignored for local scope
|
|
|
|
// drivers.
|
|
|
|
CreateNetwork(nid string, options map[string]interface{}, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error
|
2015-04-13 18:40:42 +00:00
|
|
|
|
|
|
|
// DeleteNetwork invokes the driver method to delete network passing
|
|
|
|
// the network id.
|
2015-07-02 05:00:48 +00:00
|
|
|
DeleteNetwork(nid string) error
|
2015-04-13 18:40:42 +00:00
|
|
|
|
|
|
|
// CreateEndpoint invokes the driver method to create an endpoint
|
2015-05-14 06:23:45 +00:00
|
|
|
// passing the network id, endpoint id endpoint information and driver
|
|
|
|
// specific config. The endpoint information can be either consumed by
|
|
|
|
// the driver or populated by the driver. The config mechanism will
|
|
|
|
// eventually be replaced with labels which are yet to be introduced.
|
2015-10-03 23:11:50 +00:00
|
|
|
CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error
|
2015-04-13 18:40:42 +00:00
|
|
|
|
|
|
|
// DeleteEndpoint invokes the driver method to delete an endpoint
|
|
|
|
// passing the network id and endpoint id.
|
2015-07-02 05:00:48 +00:00
|
|
|
DeleteEndpoint(nid, eid string) error
|
2015-04-22 23:47:07 +00:00
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
// EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
|
2015-07-02 05:00:48 +00:00
|
|
|
EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
|
2015-05-04 18:49:53 +00:00
|
|
|
|
2015-04-30 21:52:46 +00:00
|
|
|
// Join method is invoked when a Sandbox is attached to an endpoint.
|
2015-07-02 05:00:48 +00:00
|
|
|
Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
|
2015-04-30 21:52:46 +00:00
|
|
|
|
|
|
|
// Leave method is invoked when a Sandbox detaches from an endpoint.
|
2015-07-02 05:00:48 +00:00
|
|
|
Leave(nid, eid string) error
|
2015-04-30 21:52:46 +00:00
|
|
|
|
2015-12-07 22:45:51 +00:00
|
|
|
// ProgramExternalConnectivity invokes the driver method which does the necessary
|
|
|
|
// programming to allow the external connectivity dictated by the passed options
|
|
|
|
ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error
|
|
|
|
|
2016-12-27 11:42:32 +00:00
|
|
|
// RevokeExternalConnectivity asks the driver to remove any external connectivity
|
2015-12-07 22:45:51 +00:00
|
|
|
// programming that was done so far
|
|
|
|
RevokeExternalConnectivity(nid, eid string) error
|
|
|
|
|
2016-04-19 02:55:39 +00:00
|
|
|
// EventNotify notifies the driver when a CRUD operation has
|
|
|
|
// happened on a table of its interest as soon as this node
|
|
|
|
// receives such an event in the gossip layer. This method is
|
|
|
|
// only invoked for the global scope driver.
|
|
|
|
EventNotify(event EventType, nid string, tableName string, key string, value []byte)
|
|
|
|
|
2017-03-02 07:57:37 +00:00
|
|
|
// DecodeTableEntry passes the driver a key, value pair from table it registered
|
|
|
|
// with libnetwork. Driver should return {object ID, map[string]string} tuple.
|
|
|
|
// If DecodeTableEntry is called for a table associated with NetworkObject or
|
2017-05-22 02:25:52 +00:00
|
|
|
// EndpointObject the return object ID should be the network id or endpoint id
|
2017-03-02 07:57:37 +00:00
|
|
|
// associated with that entry. map should have information about the object that
|
|
|
|
// can be presented to the user.
|
2017-05-22 02:25:52 +00:00
|
|
|
// For example: overlay driver returns the VTEP IP of the host that has the endpoint
|
2017-03-02 07:57:37 +00:00
|
|
|
// which is shown in 'network inspect --verbose'
|
|
|
|
DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string)
|
|
|
|
|
2016-12-27 11:42:32 +00:00
|
|
|
// Type returns the type of this driver, the network type this driver manages
|
2015-04-22 23:47:07 +00:00
|
|
|
Type() string
|
2016-12-19 03:56:34 +00:00
|
|
|
|
|
|
|
// IsBuiltIn returns true if it is a built-in driver
|
|
|
|
IsBuiltIn() bool
|
2015-04-17 22:42:23 +00:00
|
|
|
}
|
2015-05-03 20:29:43 +00:00
|
|
|
|
2016-04-19 02:55:39 +00:00
|
|
|
// NetworkInfo provides a go interface for drivers to provide network
|
|
|
|
// specific information to libnetwork.
|
|
|
|
type NetworkInfo interface {
|
|
|
|
// TableEventRegister registers driver interest in a given
|
|
|
|
// table name.
|
2017-03-02 07:57:37 +00:00
|
|
|
TableEventRegister(tableName string, objType ObjectType) error
|
2019-08-07 21:28:54 +00:00
|
|
|
|
|
|
|
// UpdateIPamConfig updates the networks IPAM configuration
|
|
|
|
// based on information from the driver. In windows, the OS (HNS) chooses
|
|
|
|
// the IP address space if the user does not specify an address space.
|
|
|
|
UpdateIpamConfig(ipV4Data []IPAMData)
|
2016-04-19 02:55:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 02:25:52 +00:00
|
|
|
// InterfaceInfo provides a go interface for drivers to retrieve
|
2015-05-14 06:23:45 +00:00
|
|
|
// network information to interface resources.
|
|
|
|
type InterfaceInfo interface {
|
2015-10-03 23:11:50 +00:00
|
|
|
// SetMacAddress allows the driver to set the mac address to the endpoint interface
|
|
|
|
// during the call to CreateEndpoint, if the mac address is not already set.
|
|
|
|
SetMacAddress(mac net.HardwareAddr) error
|
|
|
|
|
|
|
|
// SetIPAddress allows the driver to set the ip address to the endpoint interface
|
|
|
|
// during the call to CreateEndpoint, if the address is not already set.
|
|
|
|
// The API is to be used to assign both the IPv4 and IPv6 address types.
|
|
|
|
SetIPAddress(ip *net.IPNet) error
|
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
// MacAddress returns the MAC address.
|
|
|
|
MacAddress() net.HardwareAddr
|
|
|
|
|
|
|
|
// Address returns the IPv4 address.
|
2015-10-03 23:11:50 +00:00
|
|
|
Address() *net.IPNet
|
2015-05-14 06:23:45 +00:00
|
|
|
|
|
|
|
// AddressIPv6 returns the IPv6 address.
|
2015-10-03 23:11:50 +00:00
|
|
|
AddressIPv6() *net.IPNet
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InterfaceNameInfo provides a go interface for the drivers to assign names
|
|
|
|
// to interfaces.
|
|
|
|
type InterfaceNameInfo interface {
|
2015-05-21 18:04:49 +00:00
|
|
|
// SetNames method assigns the srcName and dstPrefix for the interface.
|
|
|
|
SetNames(srcName, dstPrefix string) error
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-05-03 20:29:43 +00:00
|
|
|
// JoinInfo represents a set of resources that the driver has the ability to provide during
|
|
|
|
// join time.
|
2015-05-14 06:23:45 +00:00
|
|
|
type JoinInfo interface {
|
2016-06-02 05:37:39 +00:00
|
|
|
// InterfaceName returns an InterfaceNameInfo go interface to facilitate
|
2015-09-09 23:06:35 +00:00
|
|
|
// setting the names for the interface.
|
|
|
|
InterfaceName() InterfaceNameInfo
|
2015-05-14 06:23:45 +00:00
|
|
|
|
|
|
|
// SetGateway sets the default IPv4 gateway when a container joins the endpoint.
|
|
|
|
SetGateway(net.IP) error
|
|
|
|
|
|
|
|
// SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
|
|
|
|
SetGatewayIPv6(net.IP) error
|
|
|
|
|
2016-02-28 16:34:30 +00:00
|
|
|
// AddStaticRoute adds a route to the sandbox.
|
2016-02-23 21:44:38 +00:00
|
|
|
// It may be used in addition to or instead of a default gateway (as above).
|
2015-09-09 23:06:35 +00:00
|
|
|
AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
|
2015-12-03 02:07:44 +00:00
|
|
|
|
|
|
|
// DisableGatewayService tells libnetwork not to provide Default GW for the container
|
|
|
|
DisableGatewayService()
|
2016-04-19 02:55:39 +00:00
|
|
|
|
|
|
|
// AddTableEntry adds a table entry to the gossip layer
|
|
|
|
// passing the table name, key and an opaque value.
|
|
|
|
AddTableEntry(tableName string, key string, value []byte) error
|
2015-05-03 20:29:43 +00:00
|
|
|
}
|
2015-05-06 23:57:38 +00:00
|
|
|
|
2023-01-24 22:27:22 +00:00
|
|
|
// Registerer provides a way for network drivers to be dynamically registered.
|
|
|
|
type Registerer interface {
|
|
|
|
RegisterDriver(name string, driver Driver, capability Capability) error
|
|
|
|
}
|
|
|
|
|
2015-05-06 23:57:38 +00:00
|
|
|
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
|
|
|
type DriverCallback interface {
|
2023-01-24 22:27:22 +00:00
|
|
|
Registerer
|
2016-09-27 20:54:25 +00:00
|
|
|
// GetPluginGetter returns the pluginv2 getter.
|
2016-10-07 18:58:10 +00:00
|
|
|
GetPluginGetter() plugingetter.PluginGetter
|
2015-06-06 17:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Capability represents the high level capabilities of the drivers which libnetwork can make use of
|
|
|
|
type Capability struct {
|
2017-04-07 20:31:44 +00:00
|
|
|
DataScope string
|
|
|
|
ConnectivityScope string
|
2015-05-06 23:57:38 +00:00
|
|
|
}
|
2015-09-18 19:54:08 +00:00
|
|
|
|
2015-10-03 23:11:50 +00:00
|
|
|
// IPAMData represents the per-network ip related
|
|
|
|
// operational information libnetwork will send
|
|
|
|
// to the network driver during CreateNetwork()
|
|
|
|
type IPAMData struct {
|
|
|
|
AddressSpace string
|
|
|
|
Pool *net.IPNet
|
|
|
|
Gateway *net.IPNet
|
|
|
|
AuxAddresses map[string]*net.IPNet
|
|
|
|
}
|
2016-04-19 02:55:39 +00:00
|
|
|
|
|
|
|
// EventType defines a type for the CRUD event
|
|
|
|
type EventType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Create event is generated when a table entry is created,
|
|
|
|
Create EventType = 1 + iota
|
|
|
|
// Update event is generated when a table entry is updated.
|
|
|
|
Update
|
|
|
|
// Delete event is generated when a table entry is deleted.
|
|
|
|
Delete
|
|
|
|
)
|
2017-03-02 07:57:37 +00:00
|
|
|
|
|
|
|
// ObjectType represents the type of object driver wants to store in libnetwork's networkDB
|
|
|
|
type ObjectType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// EndpointObject should be set for libnetwork endpoint object related data
|
|
|
|
EndpointObject ObjectType = 1 + iota
|
|
|
|
// NetworkObject should be set for libnetwork network object related data
|
|
|
|
NetworkObject
|
|
|
|
// OpaqueObject is for driver specific data with no corresponding libnetwork object
|
|
|
|
OpaqueObject
|
|
|
|
)
|
|
|
|
|
|
|
|
// IsValidType validates the passed in type against the valid object types
|
|
|
|
func IsValidType(objType ObjectType) bool {
|
|
|
|
switch objType {
|
|
|
|
case EndpointObject:
|
|
|
|
fallthrough
|
|
|
|
case NetworkObject:
|
|
|
|
fallthrough
|
|
|
|
case OpaqueObject:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|