settings.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package network
  2. import (
  3. "net"
  4. networktypes "github.com/docker/docker/api/types/network"
  5. clustertypes "github.com/docker/docker/daemon/cluster/provider"
  6. "github.com/docker/go-connections/nat"
  7. "github.com/pkg/errors"
  8. )
  9. // Settings stores configuration details about the daemon network config
  10. // TODO Windows. Many of these fields can be factored out.,
  11. type Settings struct {
  12. Bridge string
  13. SandboxID string
  14. HairpinMode bool
  15. LinkLocalIPv6Address string
  16. LinkLocalIPv6PrefixLen int
  17. Networks map[string]*EndpointSettings
  18. Service *clustertypes.ServiceConfig
  19. Ports nat.PortMap
  20. SandboxKey string
  21. SecondaryIPAddresses []networktypes.Address
  22. SecondaryIPv6Addresses []networktypes.Address
  23. IsAnonymousEndpoint bool
  24. HasSwarmEndpoint bool
  25. }
  26. // EndpointSettings is a package local wrapper for
  27. // networktypes.EndpointSettings which stores Endpoint state that
  28. // needs to be persisted to disk but not exposed in the api.
  29. type EndpointSettings struct {
  30. *networktypes.EndpointSettings
  31. IPAMOperational bool
  32. }
  33. // AttachmentStore stores the load balancer IP address for a network id.
  34. type AttachmentStore struct {
  35. //key: networkd id
  36. //value: load balancer ip address
  37. networkToNodeLBIP map[string]net.IP
  38. }
  39. // ResetAttachments clears any existing load balancer IP to network mapping and
  40. // sets the mapping to the given attachments.
  41. func (store *AttachmentStore) ResetAttachments(attachments map[string]string) error {
  42. store.ClearAttachments()
  43. for nid, nodeIP := range attachments {
  44. ip, _, err := net.ParseCIDR(nodeIP)
  45. if err != nil {
  46. store.networkToNodeLBIP = make(map[string]net.IP)
  47. return errors.Wrapf(err, "Failed to parse load balancer address %s", nodeIP)
  48. }
  49. store.networkToNodeLBIP[nid] = ip
  50. }
  51. return nil
  52. }
  53. // ClearAttachments clears all the mappings of network to load balancer IP Address.
  54. func (store *AttachmentStore) ClearAttachments() {
  55. store.networkToNodeLBIP = make(map[string]net.IP)
  56. }
  57. // GetIPForNetwork return the load balancer IP address for the given network.
  58. func (store *AttachmentStore) GetIPForNetwork(networkID string) (net.IP, bool) {
  59. ip, exists := store.networkToNodeLBIP[networkID]
  60. return ip, exists
  61. }