github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/drivers/macvlan/macvlan.go (about) 1 package macvlan 2 3 import ( 4 "net" 5 "sync" 6 7 "github.com/docker/libnetwork/datastore" 8 "github.com/docker/libnetwork/discoverapi" 9 "github.com/docker/libnetwork/driverapi" 10 "github.com/docker/libnetwork/osl" 11 "github.com/docker/libnetwork/types" 12 ) 13 14 const ( 15 vethLen = 7 16 containerVethPrefix = "eth" 17 vethPrefix = "veth" 18 macvlanType = "macvlan" // driver type name 19 modePrivate = "private" // macvlan mode private 20 modeVepa = "vepa" // macvlan mode vepa 21 modeBridge = "bridge" // macvlan mode bridge 22 modePassthru = "passthru" // macvlan mode passthrough 23 parentOpt = "parent" // parent interface -o parent 24 modeOpt = "_mode" // macvlan mode ux opt suffix 25 ) 26 27 var driverModeOpt = macvlanType + modeOpt // mode --option macvlan_mode 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 sbox osl.Sandbox 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 d.initStore(config) 70 71 return dc.RegisterDriver(macvlanType, d, c) 72 } 73 74 func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) { 75 return nil, types.NotImplementedErrorf("not implemented") 76 } 77 78 func (d *driver) NetworkFree(id string) error { 79 return types.NotImplementedErrorf("not implemented") 80 } 81 82 func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { 83 return make(map[string]interface{}, 0), nil 84 } 85 86 func (d *driver) Type() string { 87 return macvlanType 88 } 89 90 func (d *driver) IsBuiltIn() bool { 91 return true 92 } 93 94 func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { 95 return nil 96 } 97 98 func (d *driver) RevokeExternalConnectivity(nid, eid string) error { 99 return nil 100 } 101 102 // DiscoverNew is a notification for a new discovery event 103 func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { 104 return nil 105 } 106 107 // DiscoverDelete is a notification for a discovery delete event 108 func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { 109 return nil 110 } 111 112 func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) { 113 } 114 115 func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) { 116 return "", nil 117 }