Skip to content

Commit

Permalink
Merge pull request #391 from nik-netlox/main
Browse files Browse the repository at this point in the history
gh-382 : eBPF modules loading verification added
  • Loading branch information
UltraInstinct14 authored Sep 13, 2023
2 parents 762f31e + b6c9f69 commit 34fd714
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
14 changes: 7 additions & 7 deletions api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 34fd714

Please sign in to comment.