Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - Better IFA handling #477

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading