macvlan.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package macvlan
  2. import (
  3. "net"
  4. "sync"
  5. "github.com/docker/libnetwork/datastore"
  6. "github.com/docker/libnetwork/discoverapi"
  7. "github.com/docker/libnetwork/driverapi"
  8. "github.com/docker/libnetwork/osl"
  9. "github.com/docker/libnetwork/types"
  10. )
  11. const (
  12. vethLen = 7
  13. containerVethPrefix = "eth"
  14. vethPrefix = "veth"
  15. macvlanType = "macvlan" // driver type name
  16. modePrivate = "private" // macvlan mode private
  17. modeVepa = "vepa" // macvlan mode vepa
  18. modeBridge = "bridge" // macvlan mode bridge
  19. modePassthru = "passthru" // macvlan mode passthrough
  20. parentOpt = "parent" // parent interface -o parent
  21. modeOpt = "_mode" // macvlan mode ux opt suffix
  22. )
  23. var driverModeOpt = macvlanType + modeOpt // mode --option macvlan_mode
  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. sbox osl.Sandbox
  45. endpoints endpointTable
  46. driver *driver
  47. config *configuration
  48. sync.Mutex
  49. }
  50. // Init initializes and registers the libnetwork macvlan driver
  51. func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
  52. c := driverapi.Capability{
  53. DataScope: datastore.LocalScope,
  54. ConnectivityScope: datastore.GlobalScope,
  55. }
  56. d := &driver{
  57. networks: networkTable{},
  58. }
  59. d.initStore(config)
  60. return dc.RegisterDriver(macvlanType, d, c)
  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{}, 0), nil
  70. }
  71. func (d *driver) Type() string {
  72. return macvlanType
  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. }