Skip to content

Commit

Permalink
Merge pull request #398 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Auto advertise VIPs in same subnet as local addrs
  • Loading branch information
UltraInstinct14 authored Sep 17, 2023
2 parents 38c9519 + ef10b6a commit 94fc27f
Showing 1 changed file with 20 additions and 5 deletions.
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

0 comments on commit 94fc27f

Please sign in to comment.