ov_endpoint.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package overlay
  2. import (
  3. "fmt"
  4. "net"
  5. "github.com/docker/libnetwork/driverapi"
  6. "github.com/docker/libnetwork/netutils"
  7. )
  8. type endpointTable map[string]*endpoint
  9. type endpoint struct {
  10. id string
  11. mac net.HardwareAddr
  12. addr *net.IPNet
  13. }
  14. func (n *network) endpoint(eid string) *endpoint {
  15. n.Lock()
  16. defer n.Unlock()
  17. return n.endpoints[eid]
  18. }
  19. func (n *network) addEndpoint(ep *endpoint) {
  20. n.Lock()
  21. n.endpoints[ep.id] = ep
  22. n.Unlock()
  23. }
  24. func (n *network) deleteEndpoint(eid string) {
  25. n.Lock()
  26. delete(n.endpoints, eid)
  27. n.Unlock()
  28. }
  29. func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
  30. epOptions map[string]interface{}) error {
  31. if err := validateID(nid, eid); err != nil {
  32. return err
  33. }
  34. n := d.network(nid)
  35. if n == nil {
  36. return fmt.Errorf("network id %q not found", nid)
  37. }
  38. ep := &endpoint{
  39. id: eid,
  40. addr: ifInfo.Address(),
  41. mac: ifInfo.MacAddress(),
  42. }
  43. if ep.addr == nil {
  44. return fmt.Errorf("create endpoint was not passed interface IP address")
  45. }
  46. if ep.mac == nil {
  47. ep.mac = netutils.GenerateMACFromIP(ep.addr.IP)
  48. if err := ifInfo.SetMacAddress(ep.mac); err != nil {
  49. return err
  50. }
  51. }
  52. n.addEndpoint(ep)
  53. return nil
  54. }
  55. func (d *driver) DeleteEndpoint(nid, eid string) error {
  56. if err := validateID(nid, eid); err != nil {
  57. return err
  58. }
  59. n := d.network(nid)
  60. if n == nil {
  61. return fmt.Errorf("network id %q not found", nid)
  62. }
  63. ep := n.endpoint(eid)
  64. if ep == nil {
  65. return fmt.Errorf("endpoint id %q not found", eid)
  66. }
  67. n.deleteEndpoint(eid)
  68. return nil
  69. }
  70. func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
  71. return make(map[string]interface{}, 0), nil
  72. }