2021-08-23 09:14:53 -04:00
|
|
|
//go:build linux
|
2021-05-25 19:48:54 -04:00
|
|
|
// +build linux
|
|
|
|
|
2016-02-16 22:15:18 -05:00
|
|
|
package ipvlan
|
|
|
|
|
|
|
|
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/types"
|
2016-02-16 22:15:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
vethLen = 7
|
|
|
|
containerVethPrefix = "eth"
|
|
|
|
vethPrefix = "veth"
|
|
|
|
|
2022-07-01 05:30:46 -04:00
|
|
|
driverName = "ipvlan" // driver type name
|
2022-06-30 16:20:47 -04:00
|
|
|
parentOpt = "parent" // parent interface -o parent
|
|
|
|
driverModeOpt = "ipvlan_mode" // mode -o ipvlan_mode
|
|
|
|
driverFlagOpt = "ipvlan_flag" // flag -o ipvlan_flag
|
2021-06-19 09:11:14 -04:00
|
|
|
|
|
|
|
modeL2 = "l2" // ipvlan L2 mode (default)
|
|
|
|
modeL3 = "l3" // ipvlan L3 mode
|
|
|
|
modeL3S = "l3s" // ipvlan L3S mode
|
|
|
|
|
|
|
|
flagBridge = "bridge" // ipvlan flag bridge (default)
|
|
|
|
flagPrivate = "private" // ipvlan flag private
|
|
|
|
flagVepa = "vepa" // ipvlan flag vepa
|
|
|
|
)
|
2016-02-16 22:15:18 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
endpoints endpointTable
|
|
|
|
driver *driver
|
|
|
|
config *configuration
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes and registers the libnetwork ipvlan 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{},
|
|
|
|
}
|
2021-05-27 20:15:56 -04:00
|
|
|
if err := d.initStore(config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-03-02 20:13:15 -05:00
|
|
|
|
2022-07-01 05:30:46 -04:00
|
|
|
return dc.RegisterDriver(driverName, d, c)
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-05-27 20:15:56 -04:00
|
|
|
return make(map[string]interface{}), nil
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) Type() string {
|
2022-07-01 05:30:46 -04:00
|
|
|
return driverName
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|