Skip to content

Commit

Permalink
Merge pull request #477 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Better IFA handling
  • Loading branch information
UltraInstinct14 authored Jan 2, 2024
2 parents 2cb9c58 + f518a0d commit 2815358
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
3 changes: 3 additions & 0 deletions api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func NlpRegister(hook cmn.NetHookInterface) {
}

func iSBlackListedIntf(name string, masterIdx int) bool {
if name == "lo" {
return true
}
filter := nNl.BLRgx.MatchString(name)
return filter
}
Expand Down
2 changes: 1 addition & 1 deletion loxilb-ebpf
42 changes: 36 additions & 6 deletions loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
ra := RtAttr{0, 0, false, ifObjID}
_, err = mh.zr.Rt.RtAdd(*network, RootZone, ra, nil)
if err != nil {
tk.LogIt(tk.LogDebug, "ifa add - %s:%s self-rt error\n", addr.String(), Obj)
return L3AddrErr, errors.New("self-route add error")
tk.LogIt(tk.LogDebug, "ifa add - %s:%s subnet-rt error\n", addr.String(), Obj)
return L3AddrErr, errors.New("subnet-route add error")
} else if sz, _ := net.IPMask(network.Mask).Size(); sz != 32 && sz != 128 {
myAddr, myNet, err := net.ParseCIDR(addr.String() + "/32")
if err != nil {
return L3AddrErr, errors.New("myip address parse error")
}
_, err = mh.zr.Rt.RtAdd(*myNet, RootZone, ra, nil)
if err != nil {
tk.LogIt(tk.LogDebug, " - %s:%s my-self-rt error\n", myAddr.String(), Obj)
return L3AddrErr, errors.New("my-self-route add error")
}
}

ifa.DP(DpCreate)
Expand Down Expand Up @@ -140,8 +150,18 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
ra := RtAttr{0, 0, false, ifObjID}
_, err = mh.zr.Rt.RtAdd(*network, RootZone, ra, nil)
if err != nil {
tk.LogIt(tk.LogDebug, " - %s:%s self-rt error\n", addr.String(), Obj)
return L3AddrErr, errors.New("self-route add error")
tk.LogIt(tk.LogDebug, " - %s:%s subnet-rt error\n", addr.String(), Obj)
return L3AddrErr, errors.New("subnet-route add error")
} else if sz, _ := net.IPMask(network.Mask).Size(); sz != 32 && sz != 128 {
myAddr, myNet, err := net.ParseCIDR(addr.String() + "/32")
if err != nil {
return L3AddrErr, errors.New("myip address parse error")
}
_, err = mh.zr.Rt.RtAdd(*myNet, RootZone, ra, nil)
if err != nil {
tk.LogIt(tk.LogDebug, " - %s:%s my-self-rt error\n", myAddr.String(), Obj)
return L3AddrErr, errors.New("my-self-route add error")
}
}

ifa.DP(DpCreate)
Expand Down Expand Up @@ -185,13 +205,23 @@ func (l3 *L3H) IfaDelete(Obj string, Cidr string) (int, error) {
}
}

if found == true {
if found {
// delete self-routes related to this ifa
_, err = mh.zr.Rt.RtDelete(*network, RootZone)
if err != nil {
tk.LogIt(tk.LogError, "ifa delete %s:%s self-rt error\n", addr.String(), Obj)
tk.LogIt(tk.LogError, "ifa delete %s:%s subnet-rt error\n", addr.String(), Obj)
// Continue after logging error because there is noway to fallback
}
if sz, _ := net.IPMask(network.Mask).Size(); sz != 32 && sz != 128 {
myAddr, myNet, err := net.ParseCIDR(addr.String() + "/32")
if err == nil {
_, err = mh.zr.Rt.RtDelete(*myNet, RootZone)
if err != nil {
tk.LogIt(tk.LogError, "ifa delete %s:%s my-self-rt error\n", myAddr.String(), Obj)
// Continue after logging error because there is noway to fallback
}
}
}
if len(ifa.Ifas) == 0 {
delete(l3.IfaMap, ifa.Key)

Expand Down

0 comments on commit 2815358

Please sign in to comment.