github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/drivers/ipvlan/ipvlan.go (about) 1 package ipvlan 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 ipvlanType = "ipvlan" // driver type name 19 modeL2 = "l2" // ipvlan mode l2 is the default 20 modeL3 = "l3" // ipvlan L3 mode 21 parentOpt = "parent" // parent interface -o parent 22 modeOpt = "_mode" // ipvlan mode ux opt suffix 23 ) 24 25 var driverModeOpt = ipvlanType + modeOpt // mode -o ipvlan_mode 26 27 type endpointTable map[string]*endpoint 28 29 type networkTable map[string]*network 30 31 type driver struct { 32 networks networkTable 33 sync.Once 34 sync.Mutex 35 store datastore.DataStore 36 } 37 38 type endpoint struct { 39 id string 40 nid string 41 mac net.HardwareAddr 42 addr *net.IPNet 43 addrv6 *net.IPNet 44 srcName string 45 dbIndex uint64 46 dbExists bool 47 } 48 49 type network struct { 50 id string 51 sbox osl.Sandbox 52 endpoints endpointTable 53 driver *driver 54 config *configuration 55 sync.Mutex 56 } 57 58 // Init initializes and registers the libnetwork ipvlan driver 59 func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { 60 c := driverapi.Capability{ 61 DataScope: datastore.LocalScope, 62 ConnectivityScope: datastore.GlobalScope, 63 } 64 d := &driver{ 65 networks: networkTable{}, 66 } 67 d.initStore(config) 68 69 return dc.RegisterDriver(ipvlanType, d, c) 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{}, 0), nil 82 } 83 84 func (d *driver) Type() string { 85 return ipvlanType 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 // DiscoverNew is a notification for a new discovery event. 101 func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { 102 return nil 103 } 104 105 // DiscoverDelete is a notification for a discovery delete event. 106 func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { 107 return nil 108 } 109 110 func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) { 111 } 112 113 func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) { 114 return "", nil 115 }