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