From ef10b6a754acd42b188c5a0dab8997a83d61b2e2 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Sun, 17 Sep 2023 14:08:04 +0900 Subject: [PATCH] Auto advertise VIPs in same subnet as local addrs --- loxinet/rules.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/loxinet/rules.go b/loxinet/rules.go index b5661b32a..9013e497f 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -310,6 +310,7 @@ type RuleH struct { cfg RuleCfg tables [RtMax]ruleTable epMap map[string]*epHost + vipMap map[string]int epCs [MaxEndPointCheckers]epChecker wg sync.WaitGroup lepHID uint8 @@ -326,6 +327,7 @@ func RulesInit(zone *Zone) *RuleH { nRh.cfg.RuleInactChkTime = DflLbaCheckTimeout nRh.cfg.RuleInactTries = DflLbaInactiveTries + nRh.vipMap = make(map[string]int) nRh.epMap = make(map[string]*epHost) nRh.tables[RtFw].tableMatch = RmMax - 1 nRh.tables[RtFw].tableType = RtMf @@ -1213,8 +1215,11 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, if r.ruleNum < RtMaximumLbs { R.tables[RtLB].rArr[r.ruleNum] = r } + R.vipMap[sNetAddr.IP.String()]++ - R.AdvRuleVIPIfL2(sNetAddr.IP) + if R.vipMap[sNetAddr.IP.String()] == 1 { + R.AdvRuleVIPIfL2(sNetAddr.IP) + } r.DP(DpCreate) @@ -1274,8 +1279,13 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) { R.tables[RtLB].rArr[rule.ruleNum] = nil } - if IsIPHostAddr(sNetAddr.IP.String()) { - loxinlp.DelAddrNoHook(sNetAddr.IP.String()+"/32", "lo") + R.vipMap[sNetAddr.IP.String()]-- + + if R.vipMap[sNetAddr.IP.String()] == 0 { + if IsIPHostAddr(sNetAddr.IP.String()) { + loxinlp.DelAddrNoHook(sNetAddr.IP.String()+"/32", "lo") + } + delete(R.vipMap, sNetAddr.IP.String()) } tk.LogIt(tk.LogDebug, "nat lb-rule deleted %s-%s\n", rule.tuples.String(), rule.act.String()) @@ -1907,8 +1917,6 @@ func (R *RuleH) RulesSync() { rule.ruleNum, ruleKeys, ruleActs, rule.stat.packets, rule.stat.bytes) - R.AdvRuleVIPIfL2(rule.tuples.l3Dst.addr.IP) - if rule.hChk.actChk == false { continue } @@ -1920,6 +1928,13 @@ func (R *RuleH) RulesSync() { } } + for vip := range R.vipMap { + ip := net.ParseIP(vip) + if ip != nil { + R.AdvRuleVIPIfL2(ip) + } + } + for _, rule := range R.tables[RtFw].eMap { ruleKeys := rule.tuples.String() ruleActs := rule.act.String()