github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/daemon/network/settings.go (about) 1 package network 2 3 import ( 4 "net" 5 6 networktypes "github.com/docker/docker/api/types/network" 7 clustertypes "github.com/docker/docker/daemon/cluster/provider" 8 "github.com/docker/go-connections/nat" 9 "github.com/pkg/errors" 10 ) 11 12 // Settings stores configuration details about the daemon network config 13 // TODO Windows. Many of these fields can be factored out., 14 type Settings struct { 15 Bridge string 16 SandboxID string 17 HairpinMode bool 18 LinkLocalIPv6Address string 19 LinkLocalIPv6PrefixLen int 20 Networks map[string]*EndpointSettings 21 Service *clustertypes.ServiceConfig 22 Ports nat.PortMap 23 SandboxKey string 24 SecondaryIPAddresses []networktypes.Address 25 SecondaryIPv6Addresses []networktypes.Address 26 IsAnonymousEndpoint bool 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 } 37 38 // AttachmentStore stores the load balancer IP address for a network id. 39 type AttachmentStore struct { 40 //key: networkd id 41 //value: load balancer ip address 42 networkToNodeLBIP map[string]net.IP 43 } 44 45 // ResetAttachments clears any existing load balancer IP to network mapping and 46 // sets the mapping to the given attachments. 47 func (store *AttachmentStore) ResetAttachments(attachments map[string]string) error { 48 store.ClearAttachments() 49 for nid, nodeIP := range attachments { 50 ip, _, err := net.ParseCIDR(nodeIP) 51 if err != nil { 52 store.networkToNodeLBIP = make(map[string]net.IP) 53 return errors.Wrapf(err, "Failed to parse load balancer address %s", nodeIP) 54 } 55 store.networkToNodeLBIP[nid] = ip 56 } 57 return nil 58 } 59 60 // ClearAttachments clears all the mappings of network to load balancer IP Address. 61 func (store *AttachmentStore) ClearAttachments() { 62 store.networkToNodeLBIP = make(map[string]net.IP) 63 } 64 65 // GetIPForNetwork return the load balancer IP address for the given network. 66 func (store *AttachmentStore) GetIPForNetwork(networkID string) (net.IP, bool) { 67 ip, exists := store.networkToNodeLBIP[networkID] 68 return ip, exists 69 }