macvlan.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. NetworkType = "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.Store
  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. d := &driver{
  52. networks: networkTable{},
  53. }
  54. if err := d.initStore(config); err != nil {
  55. return err
  56. }
  57. return r.RegisterDriver(NetworkType, d, driverapi.Capability{
  58. DataScope: datastore.LocalScope,
  59. ConnectivityScope: datastore.GlobalScope,
  60. })
  61. }
  62. func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
  63. return nil, types.NotImplementedErrorf("not implemented")
  64. }
  65. func (d *driver) NetworkFree(id string) error {
  66. return types.NotImplementedErrorf("not implemented")
  67. }
  68. func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
  69. return make(map[string]interface{}), nil
  70. }
  71. func (d *driver) Type() string {
  72. return NetworkType
  73. }
  74. func (d *driver) IsBuiltIn() bool {
  75. return true
  76. }
  77. func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
  78. return nil
  79. }
  80. func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
  81. return nil
  82. }
  83. // DiscoverNew is a notification for a new discovery event
  84. func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
  85. return nil
  86. }
  87. // DiscoverDelete is a notification for a discovery delete event
  88. func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
  89. return nil
  90. }
  91. func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
  92. }
  93. func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
  94. return "", nil
  95. }