2016-04-13 20:53:41 -04:00
|
|
|
package libnetwork
|
|
|
|
|
2016-05-25 01:46:18 -04:00
|
|
|
import (
|
2016-06-24 19:37:14 -04:00
|
|
|
"fmt"
|
2016-05-25 01:46:18 -04:00
|
|
|
"net"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// A global monotonic counter to assign firewall marks to
|
|
|
|
// services.
|
|
|
|
fwMarkCtr uint32 = 256
|
|
|
|
fwMarkCtrMu sync.Mutex
|
|
|
|
)
|
2016-05-08 03:48:04 -04:00
|
|
|
|
2016-06-24 19:37:14 -04:00
|
|
|
type portConfigs []*PortConfig
|
|
|
|
|
|
|
|
func (p portConfigs) String() string {
|
|
|
|
if len(p) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
pc := p[0]
|
|
|
|
str := fmt.Sprintf("%d:%d/%s", pc.PublishedPort, pc.TargetPort, PortConfig_Protocol_name[int32(pc.Protocol)])
|
|
|
|
for _, pc := range p[1:] {
|
|
|
|
str = str + fmt.Sprintf(",%d:%d/%s", pc.PublishedPort, pc.TargetPort, PortConfig_Protocol_name[int32(pc.Protocol)])
|
|
|
|
}
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
|
|
|
type serviceKey struct {
|
|
|
|
id string
|
|
|
|
ports string
|
|
|
|
}
|
|
|
|
|
2016-04-13 20:53:41 -04:00
|
|
|
type service struct {
|
2016-05-25 01:46:18 -04:00
|
|
|
name string // Service Name
|
|
|
|
id string // Service ID
|
2016-04-13 20:53:41 -04:00
|
|
|
|
2016-05-25 01:46:18 -04:00
|
|
|
// Map of loadbalancers for the service one-per attached
|
|
|
|
// network. It is keyed with network ID.
|
|
|
|
loadBalancers map[string]*loadBalancer
|
2016-05-31 02:55:51 -04:00
|
|
|
|
|
|
|
// List of ingress ports exposed by the service
|
2016-06-24 19:37:14 -04:00
|
|
|
ingressPorts portConfigs
|
2016-05-31 02:55:51 -04:00
|
|
|
|
2016-08-19 20:50:37 -04:00
|
|
|
// Service aliases
|
|
|
|
aliases []string
|
|
|
|
|
2016-05-25 01:46:18 -04:00
|
|
|
sync.Mutex
|
2016-04-13 20:53:41 -04:00
|
|
|
}
|
|
|
|
|
2016-05-25 01:46:18 -04:00
|
|
|
type loadBalancer struct {
|
|
|
|
vip net.IP
|
|
|
|
fwMark uint32
|
2016-04-13 20:53:41 -04:00
|
|
|
|
2016-05-25 01:46:18 -04:00
|
|
|
// Map of backend IPs backing this loadbalancer on this
|
|
|
|
// network. It is keyed with endpoint ID.
|
|
|
|
backEnds map[string]net.IP
|
2016-05-31 02:55:51 -04:00
|
|
|
|
|
|
|
// Back pointer to service to which the loadbalancer belongs.
|
|
|
|
service *service
|
2016-04-13 20:53:41 -04:00
|
|
|
}
|