Skip to content

Commit

Permalink
Merge pull request #505 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Modifications to egress hook handling
  • Loading branch information
UltraInstinct14 authored Jan 24, 2024
2 parents 4f23e91 + 80f3f3e commit 83f2c44
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
36 changes: 29 additions & 7 deletions api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,12 @@ func AddAddrNoHook(address, ifName string) int {
var ret int
IfName, err := nlp.LinkByName(ifName)
if err != nil {
tk.LogIt(tk.LogWarning, "[NLP] Port %s find Fail\n", ifName)
return -1
_, err := hooks.NetAddrAdd(&cmn.IPAddrMod{Dev: ifName, IP: address})
if err != nil {
tk.LogIt(tk.LogWarning, "[NLP] Hook IPv4 Address %v Port %v Add Fail\n", address, ifName)
return -1
}
return 0
}
Address, err := nlp.ParseAddr(address)
if err != nil {
Expand All @@ -944,8 +948,12 @@ func DelAddrNoHook(address, ifName string) int {
var ret int
IfName, err := nlp.LinkByName(ifName)
if err != nil {
tk.LogIt(tk.LogWarning, "[NLP] Port %s find Fail\n", ifName)
return -1
_, err := hooks.NetAddrDel(&cmn.IPAddrMod{Dev: ifName, IP: address})
if err != nil {
tk.LogIt(tk.LogWarning, "[NLP] Hook IPv4 Address %v Port %v delete Fail\n", address, ifName)
return -1
}
return 0
}
Address, err := nlp.ParseAddr(address)
if err != nil {
Expand Down Expand Up @@ -1247,9 +1255,9 @@ func AUWorkSingle(m nlp.AddrUpdate) int {
return -1
}

if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
return -1
}
//if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
// return -1
//}

attrs := link.Attrs()
name := attrs.Name
Expand Down Expand Up @@ -1421,6 +1429,20 @@ func NlpGet(ch chan bool) int {
for _, link := range links {

if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
// Need addresss to work with
addrs, err := nlp.AddrList(link, nlp.FAMILY_ALL)
if err != nil {
tk.LogIt(tk.LogError, "[NLP] Error getting address list %v for intf %s\n",
err, link.Attrs().Name)
}

if len(addrs) == 0 {
tk.LogIt(tk.LogDebug, "[NLP] No addresses found for intf %s\n", link.Attrs().Name)
} else {
for _, addr := range addrs {
AddAddr(addr, link)
}
}
continue
}

Expand Down
2 changes: 1 addition & 1 deletion loxilb-ebpf
14 changes: 14 additions & 0 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,11 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) {
if IsIPHostAddr(sNetAddr.IP.String()) {
loxinlp.DelAddrNoHook(sNetAddr.IP.String()+"/32", "lo")
}
dev := fmt.Sprintf("llb-rule-%s", sNetAddr.IP.String())
ret, _ := mh.zr.L3.IfaFind(dev, sNetAddr.IP)
if ret != 0 {
mh.zr.L3.IfaDelete(dev, sNetAddr.IP.String()+"/32")
}
delete(R.vipMap, sNetAddr.IP.String())
}
}
Expand Down Expand Up @@ -2562,6 +2567,15 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP) error {
tk.LogIt(tk.LogInfo, "nat lb-rule vip %s:%s deleted\n", IP.String(), "lo")
}
}
} else {
dev := fmt.Sprintf("llb-rule-%s", IP.String())
ret, _ := mh.zr.L3.IfaFind(dev, IP)
if ret != 0 {
_, err := mh.zr.L3.IfaAdd(dev, IP.String()+"/32")
if err != nil {
fmt.Printf("Failed to add IP : %s:%s\n", dev, err)
}
}
}

return nil
Expand Down

0 comments on commit 83f2c44

Please sign in to comment.