Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - Auto advertise VIPs in same subnet as local addrs #398

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
Expand Down