From acd704bed4ef65f08a77cf99129aec068c60b520 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Wed, 24 Jan 2024 10:45:40 +0900 Subject: [PATCH] Modifications to egress hook handling --- api/loxinlp/nlp.go | 36 +++++++++++++++++++++++++++++------- loxilb-ebpf | 2 +- loxinet/rules.go | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index b56d66f0..ffd7bd36 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -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 { @@ -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 { @@ -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 @@ -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 } diff --git a/loxilb-ebpf b/loxilb-ebpf index cb447408..afa2e5d4 160000 --- a/loxilb-ebpf +++ b/loxilb-ebpf @@ -1 +1 @@ -Subproject commit cb447408364b886aaa6171d9817313105e9c3522 +Subproject commit afa2e5d4dc003dc59147307bde774654cc54f302 diff --git a/loxinet/rules.go b/loxinet/rules.go index ca68888a..f9503169 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -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()) } } @@ -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