Skip to content

Commit

Permalink
Merge pull request #436 from cybwan/fix-issue
Browse files Browse the repository at this point in the history
optimize layer3 code
  • Loading branch information
UltraInstinct14 authored Nov 10, 2023
2 parents 017130a + 4076633 commit b2061b1
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit b2061b1

Please sign in to comment.