macvlan.go 3.0 KB

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