Skip to content

Commit

Permalink
Merge pull request #254 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Address formatting
  • Loading branch information
UltraInstinct14 committed Apr 17, 2023
2 parents 5b11ceb + e2970e6 commit 2f4e940
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
18 changes: 12 additions & 6 deletions loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,28 +359,34 @@ func (l3 *L3H) Ifas2String(it IterIntf) error {
}

// IfaMkString - Given an ifa return its string representation
func IfaMkString(ifa *Ifa) string {
func IfaMkString(ifa *Ifa, v4 bool) string {
var str string
for _, ifaEnt := range ifa.Ifas {
var flagStr string
if ifaEnt.Secondary {
flagStr = "Secondary"
flagStr = "S"
} else {
flagStr = "Primary"
flagStr = "P"
}
if !v4 && tk.IsNetIPv4(ifaEnt.IfaAddr.String()) {
continue
}
if v4 && tk.IsNetIPv6(ifaEnt.IfaAddr.String()) {
continue
}
plen, _ := ifaEnt.IfaNet.Mask.Size()
str = fmt.Sprintf("%s/%d - %s", ifaEnt.IfaAddr.String(), plen, flagStr)
str = fmt.Sprintf("%s/%d (%s) ", ifaEnt.IfaAddr.String(), plen, flagStr)
}

return str
}

// IfObjMkString - given an ifa object, get all its member ifa's string rep
func (l3 *L3H) IfObjMkString(obj string) string {
func (l3 *L3H) IfObjMkString(obj string, v4 bool) string {
key := IfaKey{obj}
ifa := l3.IfaMap[key]
if ifa != nil {
return IfaMkString(ifa)
return IfaMkString(ifa, v4)
}

return ""
Expand Down
13 changes: 11 additions & 2 deletions loxinet/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,21 @@ func (P *PortsH) PortsToGet() ([]cmn.PortDump, error) {

routed := false
var addr4 []string
addr4 = append(addr4, zn.L3.IfObjMkString(ports.Name))
addr4 = append(addr4, zn.L3.IfObjMkString(ports.Name, true))
if len(addr4) > 0 {
if addr4[0] != "" {
routed = true
}
}

var addr6 []string
addr6 = append(addr6, zn.L3.IfObjMkString(ports.Name, false))
if len(addr6) > 0 {
if addr6[0] != "" {
routed = true
}
}

ret = append(ret, cmn.PortDump{
Name: ports.Name,
PortNo: ports.PortNo,
Expand Down Expand Up @@ -656,9 +664,10 @@ func (P *PortsH) PortsToGet() ([]cmn.PortDump, error) {
L3: cmn.PortLayer3Info{
//Routed: ports.L3.Routed,
//Ipv4_addrs: ports.L3.Ipv4_addrs,
//Ipv6Addrs: ports.L3.Ipv6Addrs,
Ipv4Addrs: addr4,
Routed: routed,
Ipv6Addrs: ports.L3.Ipv6Addrs,
Ipv6Addrs: addr6,
},
L2: cmn.PortLayer2Info{
IsPvid: ports.L2.IsPvid,
Expand Down

0 comments on commit 2f4e940

Please sign in to comment.