github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/libnetwork/drivers/macvlan/macvlan.go (about) 1 //go:build linux 2 // +build linux 3 4 package macvlan 5 6 import ( 7 "net" 8 "sync" 9 10 "github.com/docker/docker/libnetwork/datastore" 11 "github.com/docker/docker/libnetwork/discoverapi" 12 "github.com/docker/docker/libnetwork/driverapi" 13 "github.com/docker/docker/libnetwork/types" 14 ) 15 16 const ( 17 vethLen = 7 18 containerVethPrefix = "eth" 19 vethPrefix = "veth" 20 driverName = "macvlan" // driver type name 21 modePrivate = "private" // macvlan mode private 22 modeVepa = "vepa" // macvlan mode vepa 23 modeBridge = "bridge" // macvlan mode bridge 24 modePassthru = "passthru" // macvlan mode passthrough 25 parentOpt = "parent" // parent interface -o parent 26 driverModeOpt = "macvlan_mode" // macvlan mode ux opt suffix 27 ) 28 29 type endpointTable map[string]*endpoint 30 31 type networkTable map[string]*network 32 33 type driver struct { 34 networks networkTable 35 sync.Once 36 sync.Mutex 37 store datastore.DataStore 38 } 39 40 type endpoint struct { 41 id string 42 nid string 43 mac net.HardwareAddr 44 addr *net.IPNet 45 addrv6 *net.IPNet 46 srcName string 47 dbIndex uint64 48 dbExists bool 49 } 50 51 type network struct { 52 id string 53 endpoints endpointTable 54 driver *driver 55 config *configuration 56 sync.Mutex 57 } 58 59 // Init initializes and registers the libnetwork macvlan driver 60 func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { 61 c := driverapi.Capability{ 62 DataScope: datastore.LocalScope, 63 ConnectivityScope: datastore.GlobalScope, 64 } 65 d := &driver{ 66 networks: networkTable{}, 67 } 68 if err := d.initStore(config); err != nil { 69 return err 70 } 71 72 return dc.RegisterDriver(driverName, d, c) 73 } 74 75 func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) { 76 return nil, types.NotImplementedErrorf("not implemented") 77 } 78 79 func (d *driver) NetworkFree(id string) error { 80 return types.NotImplementedErrorf("not implemented") 81 } 82 83 func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { 84 return make(map[string]interface{}), nil 85 } 86 87 func (d *driver) Type() string { 88 return driverName 89 } 90 91 func (d *driver) IsBuiltIn() bool { 92 return true 93 } 94 95 func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { 96 return nil 97 } 98 99 func (d *driver) RevokeExternalConnectivity(nid, eid string) error { 100 return nil 101 } 102 103 // DiscoverNew is a notification for a new discovery event 104 func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { 105 return nil 106 } 107 108 // DiscoverDelete is a notification for a discovery delete event 109 func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { 110 return nil 111 } 112 113 func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) { 114 } 115 116 func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) { 117 return "", nil 118 }