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