2021-05-25 19:48:54 -04:00
|
|
|
// +build linux
|
|
|
|
|
2016-02-16 22:15:18 -05:00
|
|
|
package macvlan
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"sync"
|
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
|
|
"github.com/docker/docker/libnetwork/discoverapi"
|
|
|
|
"github.com/docker/docker/libnetwork/driverapi"
|
|
|
|
"github.com/docker/docker/libnetwork/osl"
|
|
|
|
"github.com/docker/docker/libnetwork/types"
|
2016-02-16 22:15:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
vethLen = 7
|
|
|
|
containerVethPrefix = "eth"
|
|
|
|
vethPrefix = "veth"
|
2016-03-02 20:13:15 -05:00
|
|
|
macvlanType = "macvlan" // driver type name
|
|
|
|
modePrivate = "private" // macvlan mode private
|
|
|
|
modeVepa = "vepa" // macvlan mode vepa
|
|
|
|
modeBridge = "bridge" // macvlan mode bridge
|
|
|
|
modePassthru = "passthru" // macvlan mode passthrough
|
|
|
|
parentOpt = "parent" // parent interface -o parent
|
|
|
|
modeOpt = "_mode" // macvlan mode ux opt suffix
|
2016-02-16 22:15:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var driverModeOpt = macvlanType + modeOpt // mode --option macvlan_mode
|
|
|
|
|
|
|
|
type endpointTable map[string]*endpoint
|
|
|
|
|
|
|
|
type networkTable map[string]*network
|
|
|
|
|
|
|
|
type driver struct {
|
|
|
|
networks networkTable
|
|
|
|
sync.Once
|
|
|
|
sync.Mutex
|
|
|
|
store datastore.DataStore
|
|
|
|
}
|
|
|
|
|
|
|
|
type endpoint struct {
|
2016-06-10 22:54:00 -04:00
|
|
|
id string
|
|
|
|
nid string
|
|
|
|
mac net.HardwareAddr
|
|
|
|
addr *net.IPNet
|
|
|
|
addrv6 *net.IPNet
|
|
|
|
srcName string
|
|
|
|
dbIndex uint64
|
|
|
|
dbExists bool
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type network struct {
|
|
|
|
id string
|
|
|
|
sbox osl.Sandbox
|
|
|
|
endpoints endpointTable
|
|
|
|
driver *driver
|
|
|
|
config *configuration
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes and registers the libnetwork macvlan driver
|
|
|
|
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
|
|
|
|
c := driverapi.Capability{
|
2017-04-07 16:31:44 -04:00
|
|
|
DataScope: datastore.LocalScope,
|
|
|
|
ConnectivityScope: datastore.GlobalScope,
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
d := &driver{
|
|
|
|
networks: networkTable{},
|
|
|
|
}
|
|
|
|
d.initStore(config)
|
2016-03-02 20:13:15 -05:00
|
|
|
|
2016-02-16 22:15:18 -05:00
|
|
|
return dc.RegisterDriver(macvlanType, d, c)
|
|
|
|
}
|
|
|
|
|
2016-02-26 14:54:35 -05:00
|
|
|
func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
|
2016-02-26 14:53:13 -05:00
|
|
|
return nil, types.NotImplementedErrorf("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) NetworkFree(id string) error {
|
|
|
|
return types.NotImplementedErrorf("not implemented")
|
|
|
|
}
|
|
|
|
|
2016-02-16 22:15:18 -05:00
|
|
|
func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
|
|
|
|
return make(map[string]interface{}, 0), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) Type() string {
|
|
|
|
return macvlanType
|
|
|
|
}
|
|
|
|
|
2016-12-18 22:56:34 -05:00
|
|
|
func (d *driver) IsBuiltIn() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:35:44 -05:00
|
|
|
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-16 22:15:18 -05:00
|
|
|
// DiscoverNew is a notification for a new discovery event
|
|
|
|
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiscoverDelete is a notification for a discovery delete event
|
|
|
|
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
2016-04-18 22:55:39 -04:00
|
|
|
|
|
|
|
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
|
|
|
|
}
|
2017-03-02 02:57:37 -05:00
|
|
|
|
|
|
|
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
|
|
|
|
return "", nil
|
|
|
|
}
|