From 1e8ccffcaccd90f787d1c178b9234e84c5a463a8 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Fri, 26 Jan 2024 14:17:57 +0900 Subject: [PATCH] Support for ep persistence based on client --- api/loxinlp/ipvs.go | 12 +++++++++++- common/common.go | 2 ++ loxilb-ebpf | 2 +- loxinet/dpbroker.go | 1 + loxinet/dpebpf_linux.go | 2 ++ loxinet/rules.go | 2 ++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/loxinlp/ipvs.go b/api/loxinlp/ipvs.go index ab5f950ab..98ff14f2f 100644 --- a/api/loxinlp/ipvs.go +++ b/api/loxinlp/ipvs.go @@ -77,6 +77,10 @@ func (ctx *IpVSH) BuildIpVSDB() []*ipVSEntry { continue } + if svc.Flags&0x1 == 0x1 { + newEntry.Type = "rrp" + } + proto := "" if svc.Protocol == 1 { proto = "icmp" @@ -137,8 +141,14 @@ func IpVSSync() { } for _, newEnt := range ipVSList { + + sel := cmn.LbSelRr + if newEnt.Type == "rrp" { + sel = cmn.LbSelRrPersist + } + fmt.Printf("Selection %s\n", newEnt.Type) name := fmt.Sprintf("ipvs_%s:%d-%s", newEnt.Key.Address, newEnt.Key.Port, newEnt.Key.Protocol) - lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: newEnt.Key.Address, ServPort: newEnt.Key.Port, Proto: newEnt.Key.Protocol, Sel: cmn.LbSelRr, Name: name}} + lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: newEnt.Key.Address, ServPort: newEnt.Key.Port, Proto: newEnt.Key.Protocol, Sel: sel, Name: name}} for _, ep := range newEnt.EndPoints { lbrule.Eps = append(lbrule.Eps, cmn.LbEndPointArg{EpIP: ep.EpIP, EpPort: ep.EpPort, Weight: 1}) } diff --git a/common/common.go b/common/common.go index 086a835ac..22b028b7e 100644 --- a/common/common.go +++ b/common/common.go @@ -467,6 +467,8 @@ const ( LbSelHash // LbSelPrio - select the lb based on weighted round-robin LbSelPrio + // LbSelRrPersist - persist connectons from same client + LbSelRrPersist ) // LBMode - Variable to define LB mode diff --git a/loxilb-ebpf b/loxilb-ebpf index 08a7b2abb..073e5ed5f 160000 --- a/loxilb-ebpf +++ b/loxilb-ebpf @@ -1 +1 @@ -Subproject commit 08a7b2abbbd53b503a8dd2d6a5732f69d9ff6661 +Subproject commit 073e5ed5fce643c9a71d5e99783bb8a867d8c4d6 diff --git a/loxinet/dpbroker.go b/loxinet/dpbroker.go index 09e2f617d..c86bdfece 100644 --- a/loxinet/dpbroker.go +++ b/loxinet/dpbroker.go @@ -260,6 +260,7 @@ const ( EpRR NatSel = iota + 1 EpHash EpPrio + EpRRPersist ) // NatEP - a nat end-point diff --git a/loxinet/dpebpf_linux.go b/loxinet/dpebpf_linux.go index b0313359c..b0e1f41f7 100644 --- a/loxinet/dpebpf_linux.go +++ b/loxinet/dpebpf_linux.go @@ -925,6 +925,8 @@ func DpNatLbRuleMod(w *NatDpWorkQ) int { dat.sel_type = C.NAT_LB_SEL_RR case w.EpSel == EpHash: dat.sel_type = C.NAT_LB_SEL_HASH + case w.EpSel == EpRRPersist: + dat.sel_type = C.NAT_LB_SEL_RR_PERSIST /* Currently not implemented in DP */ /*case w.EpSel == EP_PRIO: dat.sel_type = C.NAT_LB_SEL_PRIO*/ diff --git a/loxinet/rules.go b/loxinet/rules.go index f9503169d..dd4bb17d9 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -2280,6 +2280,8 @@ func (r *ruleEnt) Nat2DP(work DpWorkT) int { case at.sel == cmn.LbSelPrio: // Note that internally we use RR to achieve wRR nWork.EpSel = EpRR + case at.sel == cmn.LbSelRrPersist: + nWork.EpSel = EpRRPersist default: nWork.EpSel = EpRR }