// L3n4Addr2RevNatKeynValue converts the given L3n4Addr to a RevNatKey and RevNatValue. func L3n4Addr2RevNatKeynValue(svcID types.ServiceID, feL3n4Addr types.L3n4Addr) (RevNatKey, RevNatValue) { if feL3n4Addr.IsIPv6() { return NewRevNat6Key(uint16(svcID)), NewRevNat6Value(feL3n4Addr.IP, feL3n4Addr.Port) } else { return NewRevNat4Key(uint16(svcID)), NewRevNat4Value(feL3n4Addr.IP, feL3n4Addr.Port) } }
// L3n4Addr2ServiceKey converts the given l3n4Addr to a ServiceKey with the slave ID // set to 0. func L3n4Addr2ServiceKey(l3n4Addr types.L3n4Addr) ServiceKey { if l3n4Addr.IsIPv6() { return NewService6Key(l3n4Addr.IP, l3n4Addr.Port, 0) } else { return NewService4Key(l3n4Addr.IP, l3n4Addr.Port, 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 }