github.com/moby/docker@v26.1.3+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 // DesiredMacAddress is the configured value, it's copied from MacAddress (the 37 // API param field) when the container is created. 38 DesiredMacAddress string 39 } 40 41 // AttachmentStore stores the load balancer IP address for a network id. 42 type AttachmentStore struct { 43 sync.Mutex 44 // key: networkd id 45 // value: load balancer ip address 46 networkToNodeLBIP map[string]net.IP 47 } 48 49 // ResetAttachments clears any existing load balancer IP to network mapping and 50 // sets the mapping to the given attachments. 51 func (store *AttachmentStore) ResetAttachments(attachments map[string]string) error { 52 store.Lock() 53 defer store.Unlock() 54 store.clearAttachments() 55 for nid, nodeIP := range attachments { 56 ip, _, err := net.ParseCIDR(nodeIP) 57 if err != nil { 58 store.networkToNodeLBIP = make(map[string]net.IP) 59 return errors.Wrapf(err, "Failed to parse load balancer address %s", nodeIP) 60 } 61 store.networkToNodeLBIP[nid] = ip 62 } 63 return nil 64 } 65 66 // ClearAttachments clears all the mappings of network to load balancer IP Address. 67 func (store *AttachmentStore) ClearAttachments() { 68 store.Lock() 69 defer store.Unlock() 70 store.clearAttachments() 71 } 72 73 func (store *AttachmentStore) clearAttachments() { 74 store.networkToNodeLBIP = make(map[string]net.IP) 75 } 76 77 // GetIPForNetwork return the load balancer IP address for the given network. 78 func (store *AttachmentStore) GetIPForNetwork(networkID string) (net.IP, bool) { 79 store.Lock() 80 defer store.Unlock() 81 ip, exists := store.networkToNodeLBIP[networkID] 82 return ip, exists 83 }