diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index d04f8e844..723f68bb0 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -408,17 +408,17 @@ func DelVLANNoHook(vlanid int) int { vlanLink, err := nlp.LinkByName(VlanName) if err != nil { ret = -1 - tk.LogIt(tk.LogWarning, "[NLP] Vlan Bridge get Fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vlan Bridge get Fail: %s\n", err.Error()) } err = nlp.LinkSetDown(vlanLink) if err != nil { ret = -1 - tk.LogIt(tk.LogWarning, "[NLP] Vlan Bridge Link Down Fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vlan Bridge Link Down Fail: %s\n", err.Error()) } err = nlp.LinkDel(vlanLink) if err != nil { ret = -1 - tk.LogIt(tk.LogWarning, "[NLP] Vlan Bridge delete Fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vlan Bridge delete Fail: %s\n", err.Error()) } return ret @@ -535,7 +535,7 @@ func AddVxLANBridgeNoHook(vxlanid int, epIntfName string) int { time.Sleep(1 * time.Second) VxlanDevNonPointer, err := nlp.LinkByName(VxlanBridgeName) if err != nil { - tk.LogIt(tk.LogWarning, "[NLP] Vxlan Interface create fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vxlan Interface create fail: %s\n", err.Error()) return -1 } nlp.LinkSetUp(VxlanDevNonPointer) @@ -554,17 +554,17 @@ func DelVxLANNoHook(vxlanid int) int { vxlanLink, err := nlp.LinkByName(VxlanName) if err != nil { ret = -1 - tk.LogIt(tk.LogWarning, "[NLP] Vxlan Bridge get Fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vxlan Bridge get Fail:%s\n", err.Error()) } err = nlp.LinkSetDown(vxlanLink) if err != nil { ret = -1 - tk.LogIt(tk.LogWarning, "[NLP] Vxlan Bridge Link Down Fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vxlan Bridge Link Down Fail:%s\n", err.Error()) } err = nlp.LinkDel(vxlanLink) if err != nil { ret = -1 - tk.LogIt(tk.LogWarning, "[NLP] Vxlan Bridge delete Fail\n", err.Error()) + tk.LogIt(tk.LogWarning, "[NLP] Vxlan Bridge delete Fail:%s\n", err.Error()) } return ret diff --git a/loxinet/dpebpf_linux.go b/loxinet/dpebpf_linux.go index bf7c3397a..d0ac4d8f9 100644 --- a/loxinet/dpebpf_linux.go +++ b/loxinet/dpebpf_linux.go @@ -50,9 +50,11 @@ import ( "syscall" "time" "unsafe" + "strings" cmn "github.com/loxilb-io/loxilb/common" tk "github.com/loxilb-io/loxilib" + nlp "github.com/vishvananda/netlink" ) // This file implements the interface DpHookInterface @@ -360,12 +362,31 @@ func convDPv6Addr2NetIP(addr unsafe.Pointer) net.IP { func (e *DpEbpfH) loadEbpfPgm(name string) int { ifStr := C.CString(name) xSection := C.CString(string(C.XDP_LL_SEC_DEFAULT)) - + link, err := nlp.LinkByName(name) + if err != nil { + tk.LogIt(tk.LogWarning, "[DP] Port %s not found\n", name) + return -1 + } if e.RssEn { C.llb_dp_link_attach(ifStr, xSection, C.LL_BPF_MOUNT_XDP, 0) } section := C.CString(string(C.TC_LL_SEC_DEFAULT)) ret := C.llb_dp_link_attach(ifStr, section, C.LL_BPF_MOUNT_TC, 0) + + filters, err := nlp.FilterList(link, nlp.HANDLE_MIN_INGRESS) + if err != nil { + tk.LogIt(tk.LogWarning, "[DP] Filter on %s not found\n", name) + return -1 + } + ret = -1 + for _,f := range filters { + if t, ok := f.(*nlp.BpfFilter); ok { + if strings.Contains(t.Name, C.TC_LL_SEC_DEFAULT) { + ret = 0 + break + } + } + } C.free(unsafe.Pointer(ifStr)) C.free(unsafe.Pointer(xSection)) C.free(unsafe.Pointer(section))