ipvlan.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package ipvlan
  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. ipvlanType = "ipvlan" // driver type name
  16. modeL2 = "l2" // ipvlan mode l2 is the default
  17. modeL3 = "l3" // ipvlan L3 mode
  18. parentOpt = "parent" // parent interface -o parent
  19. modeOpt = "_mode" // ipvlan mode ux opt suffix
  20. )
  21. var driverModeOpt = ipvlanType + modeOpt // mode -o ipvlan_mode
  22. type endpointTable map[string]*endpoint
  23. type networkTable map[string]*network
  24. type driver struct {
  25. networks networkTable
  26. sync.Once
  27. sync.Mutex
  28. store datastore.DataStore
  29. }
  30. type endpoint struct {
  31. id string
  32. nid string
  33. mac net.HardwareAddr
  34. addr *net.IPNet
  35. addrv6 *net.IPNet
  36. srcName string
  37. dbIndex uint64
  38. dbExists bool
  39. }
  40. type network struct {
  41. id string
  42. sbox osl.Sandbox
  43. endpoints endpointTable
  44. driver *driver
  45. config *configuration
  46. sync.Mutex
  47. }
  48. // Init initializes and registers the libnetwork ipvlan driver
  49. func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
  50. c := driverapi.Capability{
  51. DataScope: datastore.LocalScope,
  52. ConnectivityScope: datastore.GlobalScope,
  53. }
  54. d := &driver{
  55. networks: networkTable{},
  56. }
  57. d.initStore(config)
  58. return dc.RegisterDriver(ipvlanType, d, c)
  59. }
  60. func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
  61. return nil, types.NotImplementedErrorf("not implemented")
  62. }
  63. func (d *driver) NetworkFree(id string) error {
  64. return types.NotImplementedErrorf("not implemented")
  65. }
  66. func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
  67. return make(map[string]interface{}, 0), nil
  68. }
  69. func (d *driver) Type() string {
  70. return ipvlanType
  71. }
  72. func (d *driver) IsBuiltIn() bool {
  73. return true
  74. }
  75. func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
  76. return nil
  77. }
  78. func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
  79. return nil
  80. }
  81. // DiscoverNew is a notification for a new discovery event.
  82. func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
  83. return nil
  84. }
  85. // DiscoverDelete is a notification for a discovery delete event.
  86. func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
  87. return nil
  88. }
  89. func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
  90. }
  91. func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
  92. return "", nil
  93. }