Skip to content

Commit

Permalink
Merge pull request #853 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR: better support for zone instances
  • Loading branch information
UltraInstinct14 authored Oct 28, 2024
2 parents 3c5216d + dfbd831 commit a952f83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/loxinlp/ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func IPVSSync() {

for _, ent := range ipVSCtx.RMap {
if ent.inValid {
name := fmt.Sprintf("ipvs_%s:%d-%s", ent.key.Address, ent.key.Port, ent.key.Protocol)
name := fmt.Sprintf("ipvs_%s-%d-%s", ent.key.Address, ent.key.Port, ent.key.Protocol)
lbrule := cmn.LbRuleMod{Serv: cmn.LbServiceArg{ServIP: ent.key.Address, ServPort: ent.key.Port, Proto: ent.key.Protocol, Sel: ent.sel, Mode: ent.mode, Name: name, ProbeType: ent.pType}}
_, err := hooks.NetLbRuleDel(&lbrule)
if err != nil {
Expand All @@ -157,7 +157,7 @@ func IPVSSync() {
}

for _, newEnt := range ipVSList {
name := fmt.Sprintf("ipvs_%s:%d-%s", newEnt.key.Address, newEnt.key.Port, newEnt.key.Protocol)
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: newEnt.sel, Mode: newEnt.mode, Name: name, ProbeType: newEnt.pType, PersistTimeout: newEnt.timeout}}
for _, ep := range newEnt.endPoints {
lbrule.Eps = append(lbrule.Eps, cmn.LbEndPointArg{EpIP: ep.EpIP, EpPort: ep.EpPort, Weight: 1})
Expand Down
31 changes: 22 additions & 9 deletions pkg/loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type ruleEnt struct {
secIP []ruleLBSIP
stat ruleStat
name string
inst string
secMode cmn.LBSec
locIPs map[string]struct{}
}
Expand Down Expand Up @@ -330,6 +331,7 @@ type epChecker struct {
type vipElem struct {
ref int
pVIP net.IP
inst string
}

// RuleH - context container
Expand Down Expand Up @@ -1288,11 +1290,11 @@ func (R *RuleH) unFoldRecursiveEPs(r *ruleEnt) {
// addVIPSys - system specific operations for VIPs of a LB rule
func (R *RuleH) addVIPSys(r *ruleEnt) {
if r.act.actType != RtActSnat && !strings.Contains(r.name, "ipvs") && !strings.Contains(r.name, "static") {
R.AddRuleVIP(r.tuples.l3Dst.addr.IP, r.RuleVIP2PrivIP())
R.AddRuleVIP(r.tuples.l3Dst.addr.IP, r.RuleVIP2PrivIP(), r.inst)

// Take care of any secondary VIPs
for _, sVIP := range r.secIP {
R.AddRuleVIP(sVIP.sIP, sVIP.sIP)
R.AddRuleVIP(sVIP.sIP, sVIP.sIP, r.inst)
}
}
}
Expand Down Expand Up @@ -1617,6 +1619,12 @@ func (R *RuleH) AddLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, se
r.tuples = rt
r.zone = R.zone
r.name = serv.Name
names := strings.Split(r.name, ":")
if len(names) >= 2 {
r.inst = names[1]
} else {
r.inst = cmn.CIDefault
}
if serv.Snat {
r.act.actType = RtActSnat
} else if serv.Mode == cmn.LBModeFullNAT || serv.Mode == cmn.LBModeOneArm || serv.Mode == cmn.LBModeHostOneArm {
Expand Down Expand Up @@ -2488,7 +2496,7 @@ func (R *RuleH) RulesSync() {
ip = net.ParseIP(vip)
}
if ip != nil {
R.AdvRuleVIPIfL2(ip, net.ParseIP(vip))
R.AdvRuleVIPIfL2(ip, net.ParseIP(vip), vipElem.inst)
}
}
R.vipST = time.Now()
Expand Down Expand Up @@ -2936,8 +2944,11 @@ func (r *ruleEnt) DP(work DpWorkT) int {

}

func (R *RuleH) AdvRuleVIPIfL2(IP net.IP, eIP net.IP) error {
ciState, _ := mh.has.CIStateGetInst(cmn.CIDefault)
func (R *RuleH) AdvRuleVIPIfL2(IP net.IP, eIP net.IP, inst string) error {
if inst == "" {
inst = cmn.CIDefault
}
ciState, _ := mh.has.CIStateGetInst(inst)
if ciState == "MASTER" {
dev := fmt.Sprintf("llb-rule-%s", IP.String())
ret, _ := R.zone.L3.IfaFind(dev, IP)
Expand Down Expand Up @@ -3000,6 +3011,7 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP, eIP net.IP) error {

func (R *RuleH) RuleVIPSyncToClusterState() {

// For Cloud integrations, there is only default instance
ciState, _ := mh.has.CIStateGetInst(cmn.CIDefault)
if mh.cloudHook != nil {
if ciState == "MASTER" {
Expand All @@ -3015,7 +3027,7 @@ func (R *RuleH) RuleVIPSyncToClusterState() {
ip = net.ParseIP(vip)
}
if ip != nil {
R.AdvRuleVIPIfL2(ip, net.ParseIP(vip))
R.AdvRuleVIPIfL2(ip, net.ParseIP(vip), vipElem.inst)
}
}
}
Expand All @@ -3028,22 +3040,23 @@ func (r *ruleEnt) RuleVIP2PrivIP() net.IP {
}
}

func (R *RuleH) AddRuleVIP(VIP net.IP, pVIP net.IP) {
func (R *RuleH) AddRuleVIP(VIP net.IP, pVIP net.IP, inst string) {
vipEnt := R.vipMap[VIP.String()]
if vipEnt == nil {
vipEnt = new(vipElem)
vipEnt.ref = 1
vipEnt.pVIP = pVIP
vipEnt.inst = inst
R.vipMap[VIP.String()] = vipEnt
} else {
vipEnt.ref++
}

if vipEnt.ref == 1 {
if pVIP == nil {
R.AdvRuleVIPIfL2(VIP, VIP)
R.AdvRuleVIPIfL2(VIP, VIP, inst)
} else {
R.AdvRuleVIPIfL2(pVIP, VIP)
R.AdvRuleVIPIfL2(pVIP, VIP, inst)
}
}
}
Expand Down

0 comments on commit a952f83

Please sign in to comment.