Skip to content

Commit

Permalink
gh-61 improved code comments and logs patch2
Browse files Browse the repository at this point in the history
  • Loading branch information
PacketCrunch committed Aug 21, 2022
1 parent 7240513 commit 09c6834
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 133 deletions.
45 changes: 23 additions & 22 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func DpEbpfInit() *DpEbpfH {
if intf.Name == "llb0" {
continue
}
tk.LogIt(tk.LOG_INFO, "unloading ebp :%s\n", intf.Name)
tk.LogIt(tk.LOG_INFO, "ebpf unload - %s\n", intf.Name)
ifStr := C.CString(intf.Name)
section := C.CString(string(C.XDP_LL_SEC_DEFAULT))
C.llb_dp_link_attach(ifStr, section, C.LL_BPF_MOUNT_TC, 1)
Expand Down Expand Up @@ -252,7 +252,7 @@ func DpPortPropMod(w *PortDpWorkQ) int {
if w.LoadEbpf != "" && w.LoadEbpf != "lo" {
lRet := loadEbpfPgm(w.LoadEbpf)
if lRet != 0 {
tk.LogIt(tk.LOG_ERROR, "Error in loading ebpf prog for IFidx %d\n", w.PortNum)
tk.LogIt(tk.LOG_ERROR, "ebpf load - %d error\n", w.PortNum,)
return EBPF_ERR_EBFP_LOAD
}
}
Expand All @@ -278,19 +278,20 @@ func DpPortPropMod(w *PortDpWorkQ) int {
unsafe.Pointer(data))

if ret != 0 {
tk.LogIt(tk.LOG_ERROR, "error adding in intf map %d vlan %d\n", w.OsPortNum, w.IngVlan)
tk.LogIt(tk.LOG_ERROR, "ebpf intfmap - %d vlan %d error\n", w.OsPortNum, w.IngVlan)
return EBPF_ERR_PORTPROP_ADD
}

tk.LogIt(tk.LOG_DEBUG, "intf map added idx %d vlan %d\n", w.OsPortNum, w.IngVlan)
tk.LogIt(tk.LOG_DEBUG, "ebpf intfmap added - %d vlan %d -> %d\n", w.OsPortNum, w.IngVlan, w.PortNum)

txV = C.uint(w.OsPortNum)
ret = C.llb_add_table_elem(C.LL_DP_TX_INTF_MAP, unsafe.Pointer(&txK), unsafe.Pointer(&txV))
if ret != 0 {
C.llb_del_table_elem(C.LL_DP_INTF_MAP, unsafe.Pointer(key))
tk.LogIt(tk.LOG_ERROR, "error adding in Intf TX map\n")
tk.LogIt(tk.LOG_ERROR, "ebpf txintfmap - %d error\n", w.OsPortNum)
return EBPF_ERR_PORTPROP_ADD
}
tk.LogIt(tk.LOG_DEBUG, "tx intf map added %d\n", w.PortNum)
tk.LogIt(tk.LOG_DEBUG, "ebpf txintfmap added - %d -> %d\n", w.PortNum, w.OsPortNum)
return 0
} else if w.Work == DP_REMOVE {

Expand All @@ -301,10 +302,10 @@ func DpPortPropMod(w *PortDpWorkQ) int {
if w.LoadEbpf != "" {
lRet := unLoadEbpfPgm(w.LoadEbpf)
if lRet != 0 {
tk.LogIt(tk.LOG_ERROR, "error in unloading ebpf prog for ifi %d\n", w.OsPortNum)
tk.LogIt(tk.LOG_ERROR, "ebpf unload - ifi %d error\n", w.OsPortNum)
return EBPF_ERR_EBFP_LOAD
}
tk.LogIt(tk.LOG_DEBUG, "ebpf prog for ifi %d unloaded\n", w.OsPortNum)
tk.LogIt(tk.LOG_DEBUG, "ebpf unloaded - ifi %d\n", w.OsPortNum)
}

return 0
Expand All @@ -314,12 +315,12 @@ func DpPortPropMod(w *PortDpWorkQ) int {
}

func (e *DpEbpfH) DpPortPropAdd(w *PortDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpPortPropMod(w)
}

func (e *DpEbpfH) DpPortPropDel(w *PortDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpPortPropMod(w)
}

Expand Down Expand Up @@ -388,12 +389,12 @@ func DpL2AddrMod(w *L2AddrDpWorkQ) int {
}

func (e *DpEbpfH) DpL2AddrAdd(w *L2AddrDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpL2AddrMod(w)
}

func (e *DpEbpfH) DpL2AddrDel(w *L2AddrDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpL2AddrMod(w)
}

Expand Down Expand Up @@ -460,12 +461,12 @@ func DpRouterMacMod(w *RouterMacDpWorkQ) int {
}

func (e *DpEbpfH) DpRouterMacAdd(w *RouterMacDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpRouterMacMod(w)
}

func (e *DpEbpfH) DpRouterMacDel(w *RouterMacDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpRouterMacMod(w)
}

Expand Down Expand Up @@ -533,12 +534,12 @@ func DpNextHopMod(w *NextHopDpWorkQ) int {
}

func (e *DpEbpfH) DpNextHopAdd(w *NextHopDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpNextHopMod(w)
}

func (e *DpEbpfH) DpNextHopDel(w *NextHopDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpNextHopMod(w)
}

Expand Down Expand Up @@ -598,12 +599,12 @@ func DpRouteMod(w *RouteDpWorkQ) int {
}

func (e *DpEbpfH) DpRouteAdd(w *RouteDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpRouteMod(w)
}

func (e *DpEbpfH) DpRouteDel(w *RouteDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpRouteMod(w)
}

Expand Down Expand Up @@ -681,12 +682,12 @@ func DpNatLbRuleMod(w *NatDpWorkQ) int {
}

func (e *DpEbpfH) DpNatLbRuleAdd(w *NatDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpNatLbRuleMod(w)
}

func (e *DpEbpfH) DpNatLbRuleDel(w *NatDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return DpNatLbRuleMod(w)
}

Expand Down Expand Up @@ -951,11 +952,11 @@ func (e *DpEbpfH) DpUlClMod(w *UlClDpWorkQ) int {
}

func (e *DpEbpfH) DpUlClAdd(w *UlClDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return e.DpUlClMod(w)
}

func (e *DpEbpfH) DpUlClDel(w *UlClDpWorkQ) int {
fmt.Println(*w)
//fmt.Println(*w)
return e.DpUlClMod(w)
}
22 changes: 17 additions & 5 deletions loxinet/layer2.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func l2FdbAttrCopy(dst *FdbAttr, src *FdbAttr) {
dst.Dst = src.Dst
}

// For TunFDB, try to associate with appropriate neighbor
func (f *FdbEnt) L2FdbResolveNh() (bool, int, error) {
p := f.Port
attr := f.FdbAttr
Expand Down Expand Up @@ -171,20 +172,22 @@ func (l2 *L2H) L2FdbFind(key FdbKey) *FdbEnt {
return nil
}

// Add a l2 forwarding entry
func (l2 *L2H) L2FdbAdd(key FdbKey, attr FdbAttr) (int, error) {

p := l2.Zone.Ports.PortFindByName(attr.Oif)
if p == nil || !p.SInfo.PortActive {
tk.LogIt(tk.LOG_DEBUG, "Fdb port not found %s\n", attr.Oif)
return L2_OIF_ERR, errors.New("No such port")
tk.LogIt(tk.LOG_DEBUG, "fdb port not found %s\n", attr.Oif)
return L2_OIF_ERR, errors.New("no such port")
}

fdb, found := l2.FdbMap[key]

if found == true {
// Check if it is a modify
if l2FdbAttrEqual(&attr, &fdb.FdbAttr) {
return L2_SAMEFDB_ERR, errors.New("Same FDB")
tk.LogIt(tk.LOG_DEBUG, "fdb ent exists, %v", key)
return L2_SAMEFDB_ERR, errors.New("same fdb")
}
// Handle modify by deleting and reinstalling
l2.L2FdbDel(key)
Expand All @@ -201,6 +204,7 @@ func (l2 *L2H) L2FdbAdd(key FdbKey, attr FdbAttr) (int, error) {
if p.SInfo.PortType&cmn.PORT_VXLANBR == cmn.PORT_VXLANBR {
unRch, ret, err := nfdb.L2FdbResolveNh()
if err != nil {
tk.LogIt(tk.LOG_DEBUG, "tun-fdb ent resolve error, %v", key)
return ret, err
}
nfdb.unReach = unRch
Expand All @@ -210,14 +214,18 @@ func (l2 *L2H) L2FdbAdd(key FdbKey, attr FdbAttr) (int, error) {

nfdb.DP(DP_CREATE)

tk.LogIt(tk.LOG_DEBUG, "added fdb ent, %v", key)

return 0, nil
}

// Delete a l2 forwarding entry
func (l2 *L2H) L2FdbDel(key FdbKey) (int, error) {

fdb, found := l2.FdbMap[key]
if found == false {
return L2_NOFDB_ERR, errors.New("No such FDB")
tk.LogIt(tk.LOG_DEBUG, "fdb ent not found, %v", key)
return L2_NOFDB_ERR, errors.New("no such fdb")
}

if fdb.Port.SInfo.PortType == cmn.PORT_VXLANBR {
Expand Down Expand Up @@ -246,6 +254,9 @@ func (l2 *L2H) L2FdbDel(key FdbKey) (int, error) {
fdb.inActive = true

delete(l2.FdbMap, fdb.FdbKey)

tk.LogIt(tk.LOG_DEBUG, "deleted fdb ent, %v", key)

return 0, nil
}

Expand All @@ -257,7 +268,7 @@ func (l2 *L2H) FdbTicker(f *FdbEnt) {
if f.Port.SInfo.PortActive == false {
l2.L2FdbDel(f.FdbKey)
} else if f.unReach == true {
tk.LogIt(tk.LOG_DEBUG, "Unreachable scan %v", f)
tk.LogIt(tk.LOG_DEBUG, "unrch scan - %v", f)
unRch, _, _ := f.L2FdbResolveNh()
if f.unReach != unRch {
f.unReach = unRch
Expand Down Expand Up @@ -313,6 +324,7 @@ func (l2 *L2H) L2DestructAll() {
return
}

// Sync state of L2 entities to data-path
func (f *FdbEnt) DP(work DpWorkT) int {

if work == DP_CREATE && f.unReach == true {
Expand Down
32 changes: 26 additions & 6 deletions loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func L3Init(zone *Zone) *L3H {
return nl3h
}

// Adds an interface IP address (primary or secondary) and associate it with Obj
// Obj can be anything but usually it is the name of a valid interface
func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
var sec bool = false
addr, network, err := net.ParseCIDR(Cidr)
Expand All @@ -80,10 +82,11 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
ifa.Ifas = append(ifa.Ifas, ifaEnt)
l3.IfaMap[key] = ifa

// Add related self-route
// ifa needs related self-routes
ra := RtAttr{0, 0, false}
_, err = mh.zr.Rt.RtAdd(*network, ROOT_ZONE, ra, nil)
if err != nil {
tk.LogIt(tk.LOG_DEBUG, "ifa add - %s:%s self-rt error", addr.String(), Obj)
return L3_ADDR_ERR, errors.New("self-route add error")
}

Expand All @@ -94,9 +97,12 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {

for _, ifaEnt := range ifa.Ifas {
if ifaEnt.IfaAddr.Equal(addr) {
tk.LogIt(tk.LOG_DEBUG, "ifa add - exists %s:%s", addr.String(), Obj)
return L3_ADDR_ERR, errors.New("ip address exists")
}

// if network part of an added ifa is equal to previously
// existing ifa, then it is considered a secondary ifa
if ifaEnt.IfaNet.IP.Equal(network.IP) {
pfxSz1, _ := ifaEnt.IfaNet.Mask.Size()
pfxSz2, _ := network.Mask.Size()
Expand All @@ -114,30 +120,37 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
ifaEnt.Secondary = sec
ifa.Ifas = append(ifa.Ifas, ifaEnt)

// Add related self-route
// ifa needs to related self-routes
// FIXME - Code duplication with primary address route above
ra := RtAttr{0, 0, false}
_, err = mh.zr.Rt.RtAdd(*network, ROOT_ZONE, ra, nil)
if err != nil {
tk.LogIt(tk.LOG_DEBUG, "ifa add - %s:%s self-rt error", addr.String(), Obj)
return L3_ADDR_ERR, errors.New("self-route add error")
}

ifa.DP(DP_CREATE)

tk.LogIt(tk.LOG_DEBUG, "ifa added %s:%s", addr.String(), Obj)

return 0, nil
}

// Deletes an interface IP address (primary or secondary) and de-associate from Obj
// Obj can be anything but usually it is the name of a valid interface
func (l3 *L3H) IfaDelete(Obj string, Cidr string) (int, error) {
var found bool = false
addr, network, err := net.ParseCIDR(Cidr)
if err != nil {
tk.LogIt(tk.LOG_ERROR, "ifa delete - malformed %s:%s", addr.String(), Obj)
return L3_ADDR_ERR, errors.New("ip address parse error")
}

key := IfaKey{Obj}
ifa := l3.IfaMap[key]

if ifa == nil {
tk.LogIt(tk.LOG_ERROR, "ifa delete - no such %s:%s", addr.String(), Obj)
return L3_ADDR_ERR, errors.New("no such ip address")
}

Expand All @@ -157,23 +170,29 @@ func (l3 *L3H) IfaDelete(Obj string, Cidr string) (int, error) {
}

if found == true {
// Delete self-route
// delete self-routes related to this ifa
_, err = mh.zr.Rt.RtDelete(*network, ROOT_ZONE)
if err != nil {
tk.LogIt(tk.LOG_ERROR, "failed to delete self-route %v", *network)
// Continue after logging error
tk.LogIt(tk.LOG_ERROR, "ifa delete %s:%s self-rt error", addr.String(), Obj)
// Continue after logging error because there is noway to fallback
}
if len(ifa.Ifas) == 0 {
delete(l3.IfaMap, ifa.Key)

ifa.DP(DP_REMOVE)

tk.LogIt(tk.LOG_DEBUG, "ifa deleted %s:%s", addr.String(), Obj)
}
return 0, nil
}

return L3_ADDR_ERR, errors.New("no such ip address")
tk.LogIt(tk.LOG_DEBUG, "ifa delete - no such %s:%s", addr.String(), Obj)
return L3_ADDR_ERR, errors.New("no such ifa")
}

// Given any ip address, select optimal ip address from Obj's ifa list
// This is useful to determine source ip address when sending traffic
// to the given ip address
func (l3 *L3H) IfaSelect(Obj string, addr net.IP) (int, net.IP) {

key := IfaKey{Obj}
Expand Down Expand Up @@ -250,6 +269,7 @@ func (l3 *L3H) IfObjMkString(obj string) string {
return ""
}

// Sync state of L3 entities to data-path
func (ifa *Ifa) DP(work DpWorkT) int {
port := ifa.Zone.Ports.PortFindByName(ifa.Key.Obj)

Expand Down
Loading

0 comments on commit 09c6834

Please sign in to comment.