Skip to content

Commit

Permalink
loxilb-io#864 Allow modifications for allowed source for LB
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Nov 20, 2024
1 parent d5d8528 commit 739a3b6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion loxilb-ebpf
50 changes: 44 additions & 6 deletions pkg/loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func (R *RuleH) addAllowedLbSrc(CIDR string, lbMark uint32) *allowedSrcElem {
return nil
}

if lbMark >= 14 {
if lbMark >= 30 {
tk.LogIt(tk.LogError, "allowed-src lbmark out-of-range\n")
return nil
}
Expand Down Expand Up @@ -1080,7 +1080,7 @@ addFw:
R.lbSrcMap[CIDR] = srcElem
}

tk.LogIt(tk.LogInfo, "added allowed-cidr %s: 0x%x\n", srcPref.String(), srcElem.lbmark)
tk.LogIt(tk.LogInfo, "added allowed-cidr %s: 0x%x(%v)\n", srcPref.String(), srcElem.lbmark, srcElem.ref)

return srcElem
}
Expand All @@ -1091,7 +1091,7 @@ func (R *RuleH) deleteAllowedLbSrc(CIDR string, lbMark uint32) error {
return errors.New("no such allowed src prefix")
}

if lbMark >= 14 {
if lbMark >= 30 {
tk.LogIt(tk.LogError, "allowed-src lbmark out-of-range\n")
return nil
}
Expand Down Expand Up @@ -1660,10 +1660,27 @@ func (R *RuleH) AddLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, al
if eRule.hChk.prbType != serv.ProbeType || eRule.hChk.prbPort != serv.ProbePort ||
eRule.hChk.prbReq != serv.ProbeReq || eRule.hChk.prbResp != serv.ProbeResp ||
eRule.pTO != serv.PersistTimeout || eRule.act.action.(*ruleLBActs).sel != lBActs.sel ||
eRule.act.action.(*ruleLBActs).mode != lBActs.mode {
eRule.act.action.(*ruleLBActs).mode != lBActs.mode ||
len(allowedSources) != len(eRule.srcList) {
ruleChg = true
}

if len(allowedSources) == len(eRule.srcList) {
for _, newSrc := range allowedSources {
srcMatch := false
for _, src := range eRule.srcList {
if src.srcPref.String() != newSrc.Prefix {
srcMatch = true
break
}
}
if !srcMatch {
ruleChg = true
break
}
}
}

if !ruleChg {
return RuleExistsErr, errors.New("lbrule-exists error")
}
Expand Down Expand Up @@ -1691,6 +1708,26 @@ func (R *RuleH) AddLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, al
}
}

eSrcList := eRule.srcList
eRule.srcList = nil

for _, allowedSource := range allowedSources {
srcElem := R.addAllowedLbSrc(allowedSource.Prefix, uint32(eRule.ruleNum))
if srcElem == nil {
for _, src := range eRule.srcList {
R.deleteAllowedLbSrc(src.srcPref.String(), uint32(eRule.ruleNum))
}
eRule.srcList = eSrcList
tk.LogIt(tk.LogError, "nat lb-rule - %s:%s allowedSRC error\n", eRule.tuples.String(), eRule.act.String())
return RuleAllocErr, errors.New("rule-allowed-src error")
}
eRule.srcList = append(eRule.srcList, srcElem)
}

for _, srcElem := range eSrcList {
R.deleteAllowedLbSrc(srcElem.srcPref.String(), uint32(eRule.ruleNum))
}

// Update the rule
eRule.hChk.prbType = serv.ProbeType
eRule.hChk.prbPort = serv.ProbePort
Expand Down Expand Up @@ -2004,8 +2041,9 @@ func (R *RuleH) AddFwRule(fwRule cmn.FwRuleArg, fwOptArgs cmn.FwOptArg) (int, er
eFw := R.tables[RtFw].eMap[rt.ruleKey()]

if eFw != nil {
if fwOpts.opt.fwMark != fwOptArgs.Mark {
fwOpts.opt.fwMark = fwOptArgs.Mark
if eFw.act.action.(*ruleFwOpts).opt.fwMark != fwOptArgs.Mark {
eFw.Fw2DP(DpRemove)
eFw.act.action.(*ruleFwOpts).opt.fwMark = fwOptArgs.Mark
eFw.Fw2DP(DpCreate)
}
// If a FW rule already exists
Expand Down

0 comments on commit 739a3b6

Please sign in to comment.