macvlan.go 2.8 KB

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