mirror of
https://github.com/ngoduykhanh/wireguard-ui
synced 2024-05-19 14:06:37 +02:00
Fix duplicated IP suggestions
This commit is contained in:
parent
9e633014b5
commit
d12ac44fe1
|
@ -1034,6 +1034,9 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
|||
searchCIDRList = append(searchCIDRList, server.Interface.Addresses...)
|
||||
}
|
||||
|
||||
// Save only unique IPs
|
||||
ipSet := make(map[string]struct{})
|
||||
|
||||
for _, cidr := range searchCIDRList {
|
||||
ip, err := util.GetAvailableIP(cidr, allocatedIPs, server.Interface.Addresses)
|
||||
if err != nil {
|
||||
|
@ -1042,9 +1045,9 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
|||
}
|
||||
found = true
|
||||
if strings.Contains(ip, ":") {
|
||||
suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/128", ip))
|
||||
ipSet[fmt.Sprintf("%s/128", ip)] = struct{}{}
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue