Example #1
1
func (n *network) deleteSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
	c := n.getController()
	c.Lock()
	defer c.Unlock()
	sr, ok := c.svcDb[n.ID()]
	if !ok {
		return
	}

	if ipMapUpdate {
		delete(sr.ipMap, netutils.ReverseIP(epIP.String()))
	}

	ipList := sr.svcMap[name]
	for i, ip := range ipList {
		if ip.Equal(epIP) {
			ipList = append(ipList[:i], ipList[i+1:]...)
			break
		}
	}
	sr.svcMap[name] = ipList

	if len(ipList) == 0 {
		delete(sr.svcMap, name)
	}
}
Example #2
0
func (n *network) deleteSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool) {
	// Do not delete service names from ingress network as this is a
	// routing only network
	if n.ingress {
		return
	}

	c := n.getController()
	c.Lock()
	defer c.Unlock()
	sr, ok := c.svcRecords[n.ID()]
	if !ok {
		return
	}

	if ipMapUpdate {
		delete(sr.ipMap, netutils.ReverseIP(epIP.String()))

		if epIPv6 != nil {
			delete(sr.ipMap, netutils.ReverseIP(epIPv6.String()))
		}
	}

	delNameToIP(sr.svcMap, name, epIP)

	if epIPv6 != nil {
		delNameToIP(sr.svcIPv6Map, name, epIPv6)
	}
}
Example #3
0
func (n *network) addSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
	c := n.getController()
	c.Lock()
	defer c.Unlock()
	sr, ok := c.svcDb[n.ID()]
	if !ok {
		sr = svcInfo{
			svcMap: make(map[string][]net.IP),
			ipMap:  make(map[string]string),
		}
		c.svcDb[n.ID()] = sr
	}

	if ipMapUpdate {
		reverseIP := netutils.ReverseIP(epIP.String())
		if _, ok := sr.ipMap[reverseIP]; !ok {
			sr.ipMap[reverseIP] = name
		}
	}

	ipList := sr.svcMap[name]
	for _, ip := range ipList {
		if ip.Equal(epIP) {
			return
		}
	}
	sr.svcMap[name] = append(sr.svcMap[name], epIP)
}
Example #4
0
func addIPToName(ipMap map[string]*ipInfo, name string, ip net.IP) {
	reverseIP := netutils.ReverseIP(ip.String())
	if _, ok := ipMap[reverseIP]; !ok {
		ipMap[reverseIP] = &ipInfo{
			name: name,
		}
	}
}
Example #5
0
func (n *network) deleteSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool) {
	c := n.getController()
	c.Lock()
	defer c.Unlock()
	sr, ok := c.svcRecords[n.ID()]
	if !ok {
		return
	}

	if ipMapUpdate {
		delete(sr.ipMap, netutils.ReverseIP(epIP.String()))

		if epIPv6 != nil {
			delete(sr.ipMap, netutils.ReverseIP(epIPv6.String()))
		}
	}

	delNameToIP(sr.svcMap, name, epIP)

	if epIPv6 != nil {
		delNameToIP(sr.svcIPv6Map, name, epIPv6)
	}
}
Example #6
0
func (n *network) HandleQueryResp(name string, ip net.IP) {
	c := n.getController()
	c.Lock()
	defer c.Unlock()
	sr, ok := c.svcRecords[n.ID()]

	if !ok {
		return
	}

	ipStr := netutils.ReverseIP(ip.String())

	if ipInfo, ok := sr.ipMap[ipStr]; ok {
		ipInfo.extResolver = true
	}
}
Example #7
0
func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) {
	if ep.isAnonymous() {
		return
	}

	c := n.getController()
	sr, ok := c.svcDb[n.ID()]
	if !ok {
		c.svcDb[n.ID()] = svcInfo{
			svcMap: make(map[string]net.IP),
			ipMap:  make(map[string]string),
		}
		sr = c.svcDb[n.ID()]
	}

	epName := ep.Name()
	n.Lock()
	if iface := ep.Iface(); iface.Address() != nil {

		reverseIP := netutils.ReverseIP(iface.Address().IP.String())
		if isAdd {
			// If we already have this endpoint in service db just return
			if _, ok := sr.svcMap[epName]; ok {
				n.Unlock()
				return
			}

			sr.svcMap[epName] = iface.Address().IP
			sr.ipMap[reverseIP] = epName
		} else {
			delete(sr.svcMap, epName)
			delete(sr.ipMap, reverseIP)
		}
	}
	n.Unlock()
}
Example #8
0
func addIPToName(ipMap map[string]string, name string, ip net.IP) {
	reverseIP := netutils.ReverseIP(ip.String())
	if _, ok := ipMap[reverseIP]; !ok {
		ipMap[reverseIP] = name
	}
}