github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/libnetwork/drivers/macvlan/macvlan.go (about) 1 //go:build linux 2 3 package macvlan 4 5 import ( 6 "net" 7 "sync" 8 9 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/datastore" 10 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/driverapi" 11 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/scope" 12 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/types" 13 ) 14 15 const ( 16 containerVethPrefix = "eth" 17 vethPrefix = "veth" 18 vethLen = len(vethPrefix) + 7 19 NetworkType = "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 driverModeOpt = "macvlan_mode" // macvlan mode ux opt suffix 26 ) 27 28 type endpointTable map[string]*endpoint 29 30 type networkTable map[string]*network 31 32 type driver struct { 33 networks networkTable 34 sync.Once 35 sync.Mutex 36 store *datastore.Store 37 } 38 39 type endpoint struct { 40 id string 41 nid string 42 mac net.HardwareAddr 43 addr *net.IPNet 44 addrv6 *net.IPNet 45 srcName string 46 dbIndex uint64 47 dbExists bool 48 } 49 50 type network struct { 51 id string 52 endpoints endpointTable 53 driver *driver 54 config *configuration 55 sync.Mutex 56 } 57 58 // Register initializes and registers the libnetwork macvlan driver 59 func Register(r driverapi.Registerer, config map[string]interface{}) error { 60 d := &driver{ 61 networks: networkTable{}, 62 } 63 if err := d.initStore(config); err != nil { 64 return err 65 } 66 return r.RegisterDriver(NetworkType, d, driverapi.Capability{ 67 DataScope: scope.Local, 68 ConnectivityScope: scope.Global, 69 }) 70 } 71 72 func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) { 73 return nil, types.NotImplementedErrorf("not implemented") 74 } 75 76 func (d *driver) NetworkFree(id string) error { 77 return types.NotImplementedErrorf("not implemented") 78 } 79 80 func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { 81 return make(map[string]interface{}), nil 82 } 83 84 func (d *driver) Type() string { 85 return NetworkType 86 } 87 88 func (d *driver) IsBuiltIn() bool { 89 return true 90 } 91 92 func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { 93 return nil 94 } 95 96 func (d *driver) RevokeExternalConnectivity(nid, eid string) error { 97 return nil 98 } 99 100 func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) { 101 } 102 103 func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) { 104 return "", nil 105 }