mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-07 00:46:58 +03:00
Fix duplicated IP suggestions
This commit is contained in:
parent
9e633014b5
commit
d12ac44fe1
1 changed files with 9 additions and 2 deletions
|
@ -1034,6 +1034,9 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
||||||
searchCIDRList = append(searchCIDRList, server.Interface.Addresses...)
|
searchCIDRList = append(searchCIDRList, server.Interface.Addresses...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save only unique IPs
|
||||||
|
ipSet := make(map[string]struct{})
|
||||||
|
|
||||||
for _, cidr := range searchCIDRList {
|
for _, cidr := range searchCIDRList {
|
||||||
ip, err := util.GetAvailableIP(cidr, allocatedIPs, server.Interface.Addresses)
|
ip, err := util.GetAvailableIP(cidr, allocatedIPs, server.Interface.Addresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1042,9 +1045,9 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
found = true
|
found = true
|
||||||
if strings.Contains(ip, ":") {
|
if strings.Contains(ip, ":") {
|
||||||
suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/128", ip))
|
ipSet[fmt.Sprintf("%s/128", ip)] = struct{}{}
|
||||||
} else {
|
} else {
|
||||||
suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/32", ip))
|
ipSet[fmt.Sprintf("%s/32", ip)] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1055,6 +1058,10 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ip := range ipSet {
|
||||||
|
suggestedIPs = append(suggestedIPs, ip)
|
||||||
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, suggestedIPs)
|
return c.JSON(http.StatusOK, suggestedIPs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue