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

optimize layer3 code #436

Merged
merged 7 commits into from
Nov 10, 2023
Merged
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
22 changes: 12 additions & 10 deletions loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {

ifa.DP(DpCreate)

tk.LogIt(tk.LogDebug, "ifa added %s:%s\n", addr.String(), Obj)

return 0, nil
}

Expand All @@ -128,7 +130,6 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
}

ifaEnt := new(IfaEnt)
ifa.Key.Obj = Obj
ifaEnt.IfaAddr = addr
ifaEnt.IfaNet = *network
ifaEnt.Secondary = sec
Expand Down Expand Up @@ -156,7 +157,7 @@ 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.LogError, "ifa delete - malformed %s:%s\n", addr.String(), Obj)
tk.LogIt(tk.LogError, "ifa delete - malformed %s:%s\n", Cidr, Obj)
return L3AddrErr, errors.New("ip address parse error")
}

Expand All @@ -178,6 +179,7 @@ func (l3 *L3H) IfaDelete(Obj string, Cidr string) (int, error) {
if pfxSz1 == pfxSz2 {
ifa.Ifas = append(ifa.Ifas[:index], ifa.Ifas[index+1:]...)
found = true
break
}
}
}
Expand Down Expand Up @@ -385,9 +387,8 @@ func Ifa2String(ifa *Ifa, it IterIntf) {
}
plen, _ := ifaEnt.IfaNet.Mask.Size()
str = fmt.Sprintf("%s/%d - %s", ifaEnt.IfaAddr.String(), plen, flagStr)
it.NodeWalker(str)
}

it.NodeWalker(str)
}

// Ifas2String - Format all ifas to string
Expand All @@ -402,20 +403,21 @@ func (l3 *L3H) Ifas2String(it IterIntf) error {
func IfaMkString(ifa *Ifa, v4 bool) string {
var str string
for _, ifaEnt := range ifa.Ifas {
var flagStr string
if ifaEnt.Secondary {
flagStr = "S"
} else {
flagStr = "P"
}
if !v4 && tk.IsNetIPv4(ifaEnt.IfaAddr.String()) {
continue
}
if v4 && tk.IsNetIPv6(ifaEnt.IfaAddr.String()) {
continue
}
var flagStr string
if ifaEnt.Secondary {
flagStr = "S"
} else {
flagStr = "P"
}
plen, _ := ifaEnt.IfaNet.Mask.Size()
str = fmt.Sprintf("%s/%d (%s) ", ifaEnt.IfaAddr.String(), plen, flagStr)
break
}

return str
Expand Down
Loading