diff --git a/handler/routes.go b/handler/routes.go index 1937985..0358750 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -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) } }