1package network
2
3// Address represents an IP address
4type Address struct {
5	Addr      string
6	PrefixLen int
7}
8
9// IPAM represents IP Address Management
10type IPAM struct {
11	Driver  string
12	Options map[string]string //Per network IPAM driver options
13	Config  []IPAMConfig
14}
15
16// IPAMConfig represents IPAM configurations
17type IPAMConfig struct {
18	Subnet     string            `json:",omitempty"`
19	IPRange    string            `json:",omitempty"`
20	Gateway    string            `json:",omitempty"`
21	AuxAddress map[string]string `json:"AuxiliaryAddresses,omitempty"`
22}
23
24// EndpointIPAMConfig represents IPAM configurations for the endpoint
25type EndpointIPAMConfig struct {
26	IPv4Address  string   `json:",omitempty"`
27	IPv6Address  string   `json:",omitempty"`
28	LinkLocalIPs []string `json:",omitempty"`
29}
30
31// Copy makes a copy of the endpoint ipam config
32func (cfg *EndpointIPAMConfig) Copy() *EndpointIPAMConfig {
33	cfgCopy := *cfg
34	cfgCopy.LinkLocalIPs = make([]string, 0, len(cfg.LinkLocalIPs))
35	cfgCopy.LinkLocalIPs = append(cfgCopy.LinkLocalIPs, cfg.LinkLocalIPs...)
36	return &cfgCopy
37}
38
39// PeerInfo represents one peer of an overlay network
40type PeerInfo struct {
41	Name string
42	IP   string
43}
44
45// EndpointSettings stores the network endpoint details
46type EndpointSettings struct {
47	// Configurations
48	IPAMConfig *EndpointIPAMConfig
49	Links      []string
50	Aliases    []string
51	// Operational data
52	NetworkID           string
53	EndpointID          string
54	Gateway             string
55	IPAddress           string
56	IPPrefixLen         int
57	IPv6Gateway         string
58	GlobalIPv6Address   string
59	GlobalIPv6PrefixLen int
60	MacAddress          string
61	DriverOpts          map[string]string
62}
63
64// Task carries the information about one backend task
65type Task struct {
66	Name       string
67	EndpointID string
68	EndpointIP string
69	Info       map[string]string
70}
71
72// ServiceInfo represents service parameters with the list of service's tasks
73type ServiceInfo struct {
74	VIP          string
75	Ports        []string
76	LocalLBIndex int
77	Tasks        []Task
78}
79
80// Copy makes a deep copy of `EndpointSettings`
81func (es *EndpointSettings) Copy() *EndpointSettings {
82	epCopy := *es
83	if es.IPAMConfig != nil {
84		epCopy.IPAMConfig = es.IPAMConfig.Copy()
85	}
86
87	if es.Links != nil {
88		links := make([]string, 0, len(es.Links))
89		epCopy.Links = append(links, es.Links...)
90	}
91
92	if es.Aliases != nil {
93		aliases := make([]string, 0, len(es.Aliases))
94		epCopy.Aliases = append(aliases, es.Aliases...)
95	}
96	return &epCopy
97}
98
99// NetworkingConfig represents the container's networking configuration for each of its interfaces
100// Carries the networking configs specified in the `docker run` and `docker network connect` commands
101type NetworkingConfig struct {
102	EndpointsConfig map[string]*EndpointSettings // Endpoint configs for each connecting network
103}
104
105// ConfigReference specifies the source which provides a network's configuration
106type ConfigReference struct {
107	Network string
108}
109