Exemplo n.º 1
0
// SVCGet returns a DeepCopied frontend with its backends.
func (d *Daemon) SVCGet(feL3n4 types.L3n4Addr) (*types.LBSVC, error) {
	feL3n4Uniq, err := feL3n4.SHA256Sum()
	if err != nil {
		return nil, err
	}
	return d.SVCGetBySHA256Sum(feL3n4Uniq)
}
Exemplo n.º 2
0
// SVCGet calculates the SHA256Sum from the given frontend and sends a GET request with
// the calculated SHA256Sum to the daemon.
func (cli Client) SVCGet(fe types.L3n4Addr) (*types.LBSVC, error) {
	feSHA256Sum, err := fe.SHA256Sum()
	if err != nil {
		return nil, fmt.Errorf("invalid SHA256Sum for front end %+v: %s", fe, err)
	}
	return cli.SVCGetBySHA256Sum(feSHA256Sum)
}
Exemplo n.º 3
0
// SVCDelete calculates the SHA256Sum from the given frontend and sends a DELETE request
// to the daemon.
func (cli Client) SVCDelete(fe types.L3n4Addr) error {
	feSHA256Sum, err := fe.SHA256Sum()
	if err != nil {
		return fmt.Errorf("invalid SHA256Sum for front end %+v: %s", fe, err)
	}
	return cli.SVCDeleteBySHA256Sum(feSHA256Sum)
}
Exemplo n.º 4
0
// PutL3n4Addr stores the given service in the kvstore and returns the L3n4AddrID
// created for the given l3n4Addr. If baseID is different than 0, it tries to acquire that
// ID to the l3n4Addr.
func (d *Daemon) PutL3n4Addr(l3n4Addr types.L3n4Addr, baseID uint32) (*types.L3n4AddrID, error) {
	log.Debugf("Resolving service %+v", l3n4Addr)

	// Retrieve unique SHA256Sum for service
	sha256Sum, err := l3n4Addr.SHA256Sum()
	if err != nil {
		return nil, err
	}
	svcPath := path.Join(common.ServicesKeyPath, sha256Sum)

	// Lock that sha256Sum
	lockKey, err := d.kvClient.LockPath(svcPath)
	if err != nil {
		return nil, err
	}
	defer lockKey.Unlock()

	// After lock complete, get svc's path
	rmsg, err := d.kvClient.GetValue(svcPath)
	if err != nil {
		return nil, err
	}

	sl4KV := types.L3n4AddrID{}
	if rmsg != nil {
		if err := json.Unmarshal(rmsg, &sl4KV); err != nil {
			return nil, err
		}
	}
	if sl4KV.ID == 0 {
		sl4KV.L3n4Addr = l3n4Addr
		if err := d.gasNewL3n4AddrID(&sl4KV, baseID); err != nil {
			return nil, err
		}
		err = d.kvClient.SetValue(svcPath, sl4KV)
	}

	return &sl4KV, err
}
Exemplo n.º 5
0
// SVCDelete deletes the frontend from the local bpf map.
func (d *Daemon) SVCDelete(feL3n4 types.L3n4Addr) error {
	feL3n4Uniq, err := feL3n4.SHA256Sum()
	if err != nil {
		return err
	}

	var svcKey lbmap.ServiceKey
	if !feL3n4.IsIPv6() {
		svcKey = lbmap.NewService4Key(feL3n4.IP, feL3n4.Port, 0)
	} else {
		svcKey = lbmap.NewService6Key(feL3n4.IP, feL3n4.Port, 0)
	}

	svcKey.SetBackend(0)

	d.loadBalancer.BPFMapMU.Lock()
	defer d.loadBalancer.BPFMapMU.Unlock()
	err = lbmap.DeleteService(svcKey)
	// TODO should we delete even if err is != nil?
	if err == nil {
		delete(d.loadBalancer.SVCMap, feL3n4Uniq)
	}
	return err
}